Index: trunk/prototype/modules/calendar/interceptors/DBMapping.php
===================================================================
--- trunk/prototype/modules/calendar/interceptors/DBMapping.php	(revision 5741)
+++ trunk/prototype/modules/calendar/interceptors/DBMapping.php	(revision 5746)
@@ -150,6 +150,5 @@
 
 public function saveOccurrences( &$uri , &$result , &$criteria , $original ){
-
-	$ranges = Controller::find( array( 'concept' => 'repeatRange' ), array( 'rangeStart', 'rangeEnd' ),  array( 'filter' => array( '=', 'user', Config::me("uidNumber") ) ) );
+        $ranges = Controller::find( array( 'concept' => 'repeatRange' ), array( 'rangeStart', 'rangeEnd' ),  array( 'filter' => array( '=', 'user', Config::me("uidNumber") ) ) );
 
 	if( !is_array( $ranges ) || !isset( $ranges[0]['rangeStart'] ) || !isset( $ranges[0]['rangeEnd'] ) )
@@ -168,17 +167,23 @@
 	$exceptions = array();
 
-	if( isset( $repeat['exceptions'] ) )
+	if( isset( $original['properties']['exceptions'] ) )
 	{
-	    $exceptions = explode( ',', $repeat['exceptions'] );
+	    $exceptions = explode( ',', $original['properties']['exceptions'] );
 	    unset( $repeat['exceptions'] );
 	}
-
+        
+        $lastExceptions = Controller::find( array( 'concept' => 'repeatOccurrence' ), array("occurrence") , array( 'filter' => array('AND', array( '=', 'repeat', $id ) , array( '=', 'exception', 1 ) ) ));
+
+        //Recurepa as execeções anteriores caso exista
+        if(isset($lastExceptions) && count($lastExceptions))
+            foreach($lastExceptions as $key => $value)
+                array_push($exceptions, $lastExceptions[$key]['occurrence']);
+        
 	$params = array_diff( self::decodeRepeat( $repeat, $ranges[0]['rangeStart'], $ranges[0]['rangeEnd'] ), $exceptions );
-
+        
 	Controller::delete( array( 'concept' => 'repeatOccurrence' ), false, array( 'filter' => array( '=', 'repeat', $id ) ) );
 
 	if( !empty($params) )
-	    Controller::service('PostgreSQL')->execResultSql( "INSERT INTO calendar_repeat_occurrence(repeat_id,exception,occurrence)VALUES('".$id."','0','".implode( "'),('".$id."','0','", $params )."')".( empty($exceptions) ? "" : ",('".$id."','1','".implode( "'),('".$id."','0','", $exceptions )."')" ) );
-
+	    Controller::service('PostgreSQL')->execResultSql( "INSERT INTO calendar_repeat_occurrence(repeat_id,exception,occurrence)VALUES('".$id."','0','".implode( "'),('".$id."','0','", $params )."')".( empty($exceptions) ? "" : ",('".$id."','1','".implode( "'),('".$id."','1','", $exceptions )."')" ) );
     }
 
@@ -467,11 +472,10 @@
  
     //TODO: Remover apos suporte a deepness na api 
-    public function deepnessFindEvent( &$uri , &$result , &$criteria , $original ){		
-
+    public function deepnessFindEvent( &$uri , &$result , &$criteria , $original ){
        if(isset($original['criteria']['deepness']) && $original['criteria']['deepness'] != 0)
        {
 			
-			$Time = new DateTime( 'now', new DateTimeZone('UTC') );
-			$DayLigth = array();
+            $Time = new DateTime( 'now', new DateTimeZone('UTC') );
+            $DayLigth = array();
            foreach ($result as $i => $v)
            {
@@ -888,87 +892,4 @@
     }
 
-    public function createSchedulableMails( &$uri , &$result , &$criteria , $original ){
-	
-        require_once (ROOTPATH.'/plugins/icalcreator/iCalcreator.class.php' );
-        require_once (ROOTPATH.'/api/parseTPL.php' );
-        $schedulable = Controller::read( array( 'concept' => 'schedulable' , 'id' => $result['id'] )); 
-        $participants = Controller::find( array( 'concept' => 'participant' ) , false ,array( 'filter' => array('=', 'schedulable' ,  $result['id']) )) ; 
-        
-        
-	if(is_array($participants) && count($participants) > 0) //Caso exista participants
-	{
-            $att = array();
-            $attList = '<UL> ';
-            $organizer = array();
-            foreach ($participants as $i => $v)
-			{
-              	if($part['isExternal'] == 1)
-                    $att[$i] =  Controller::read( array( 'concept' => 'user' , 'id' => $v['user'] , 'service' => 'PostgreSQL' ) );
-                else
-                    $att[$i] = Controller::read( array( 'concept' => 'user' , 'id' => $v['user'] ));
-            
-               $attList .= '<LI> '.$att[$i]['name'] .'</LI> ';
-               
-               if( isset($v['isOrganizer']) && $v['isOrganizer'] == 1)
-                   $organizer = $att[$i];
-               
-            }
-            $attList .= '</UL>';
-            
-            foreach ($participants as $i => $v)
-			{				
-                
-                if($v === $organizer) //Organizador ? 
-                    continue;
-                
-                //Criação do ical
-                $ical = null;
-              	$ical = new vcalendar();
-				$ical->setProperty( 'method' , 'REQUEST' );			
-				$vschedulable = &$ical->newComponent( 'vschedulable' );
-				$vschedulable->setProperty( 'uid' , $schedulable['uid'] );
-				$vschedulable->setProperty( 'dtstart', gmdate( DATE_RFC822 , (int)($schedulable['startTime'] / 1000)));
-				$vschedulable->setProperty( 'dtend', gmdate( DATE_RFC822 , (int)($schedulable['endTime'] / 1000)));
-				$vschedulable->setProperty( 'summary',( $schedulable['summary'] ));
-				$vschedulable->setProperty( 'description', $schedulable['description']);
-                $vschedulable->setProperty( 'location', $schedulable['location']);
-                $params = array();
-                $params['CN'] = $att[$i]['name'];
-                $params['RSVP'] = 'TRUE';
-                $params['ROLE'] = 'REQ-PARTICIPANT';
-                if(isset($att[$i]['mail']))
-                    $vschedulable->setProperty( 'attendee', $att[$i]['mail'] , $params);
-                
-                $vschedulable->setProperty( 'organizer', $organizer['mail'] , array('CN' => $organizer['name']) );
-				///////////////////////////////////////////////////////////////////////////
-                
-                //Criação do E-mail
-                $mail = array();
-                $mail['isHtml'] = true;  
-                
-                $timzone = new DateTimeZone('UTC');
-                $sTime = new DateTime( '@'.(int)($schedulable['startTime'] / 1000) , $timzone );
-                $eTime =  new DateTime( '@'.(int)($schedulable['endTime'] / 1000) , $timzone );
-                
-                $mail['body'] = parseTPL::load_tpl(array( 'startDate' =>  date_format( $sTime , 'd/m/Y') ,
-                                                          'startTime' =>  date_format( $sTime , 'H:i') ,
-                                                          'endDate' =>  date_format( $eTime , 'd/m/Y') ,
-                                                          'endTime' =>  date_format( $eTime , 'H:i') ,
-                                                          'schedulableTitle' =>  $schedulable['summary'],
-                                                          'schedulableLocation' =>  $schedulable['location'],
-                                                          'participants' =>  $attList
-                                                        ),ROOTPATH.'/api/templates/notify_create_body.tpl');
-                
-                //TODO: Internacionalização do Subject
-                $mail['subject'] = 'Schedulable do Calendário : '.$schedulable['summary'] .' @ '.date_format( $sTime , 'd/m/Y H:i') . ' - ' .  date_format( $eTime , 'd/m/Y H:i');
-                $mail['from'] =  $organizer['mail'];
-                $mail['to'] = $att[$i]['mail'];
-                $mail['attachments'][] = array('source' => $ical->createCalendar(), 'type' => 'text/calendar' ,'disposition' => 'inline' ,'name' => 'external.ics');
-                $result['participants'][$i]['sendInvite'] = Controller::create( array( 'service' => 'SMTP' ), $mail );   
-	
-			}         
-        }
-	}
-
     public function davcalCreateCollection( &$uri , &$params , &$criteria , $original ){	
         if( Config::module('useCaldav') )
