Index: /trunk/expressoCalendar/setup/tables_current.inc.php
===================================================================
--- /trunk/expressoCalendar/setup/tables_current.inc.php	(revision 5715)
+++ /trunk/expressoCalendar/setup/tables_current.inc.php	(revision 5741)
@@ -229,4 +229,5 @@
                 'bysetpos' => array(  'type' => 'varchar','precision' => '50', 'nullable' => True),
                 'wkst' => array(  'type' => 'varchar','precision' => '50', 'nullable' => True),
+		'exceptions' => array(  'type' => 'varchar','precision' => '50', 'nullable' => True),
                 'interval' => array(  'type' => 'int', 'precision' => '8', 'nullable' => True)
             ),
@@ -254,5 +255,6 @@
                 'id' => array( 'type' => 'auto', 'nullable' => False),
                 'occurrence' => array(  'type' => 'bigint','precision' => '16', 'nullable' => False),
-                'repeat_id' => array(  'type' => 'int', 'precision' => '8', 'nullable' => False)
+                'exception' => array(  'type' => 'smallint','precision' => '1', 'nullable' => False),
+		'repeat_id' => array(  'type' => 'int', 'precision' => '8', 'nullable' => False)
             ),
 
Index: /trunk/expressoCalendar/setup/tables_update.inc.php
===================================================================
--- /trunk/expressoCalendar/setup/tables_update.inc.php	(revision 5715)
+++ /trunk/expressoCalendar/setup/tables_update.inc.php	(revision 5741)
@@ -70,8 +70,19 @@
 		);
 
-		$oProc->query("ALTER TABLE calendar_repeat_occurrence ADD CONSTRAINT fk_calendar_repeat_to_calendar_repeat_occurrence FOREIGN KEY (repeat_id) REFERENCES calendar_repeat (id) MATCH SIMPLE ON UPDATE CASCADE ON DELETE CASCADE;");	
+		$oProc->query("ALTER TABLE calendar_participant ADD COLUMN receive_notification smallint not null DEFAULT 1 ");	
 
 		$GLOBALS['setup_info']['expressoCalendar']['currentver'] = '1.002';
         return $GLOBALS['setup_info']['expressoCalendar']['currentver'];
 	}
+
+	$test[] = '1.002';
+	function expressoCalendar_upgrade1_002() {
+
+		$oProc = $GLOBALS['phpgw_setup']->oProc;
+
+		$oProc->query("ALTER TABLE calendar_repeat_occurrence ADD COLUMN exception smallint DEFAULT 0;");
+
+		$GLOBALS['setup_info']['expressoCalendar']['currentver'] = '1.003';
+        return $GLOBALS['setup_info']['expressoCalendar']['currentver'];
+	}
 ?>
Index: /trunk/expressoCalendar/setup/setup.inc.php
===================================================================
--- /trunk/expressoCalendar/setup/setup.inc.php	(revision 5715)
+++ /trunk/expressoCalendar/setup/setup.inc.php	(revision 5741)
@@ -13,5 +13,5 @@
 	$setup_info['expressoCalendar']['title']     	= 'Expresso Calendar';
 	/* Ao incrementar versão, não esquecer de declarar função do tables_update.inc.php*/
-	$setup_info['expressoCalendar']['version']   	= '1.002';
+	$setup_info['expressoCalendar']['version']   	= '1.003';
 	$setup_info['expressoCalendar']['app_order']	= 10;
         
Index: /trunk/prototype/config/repeatOccurrence.ini
===================================================================
--- /trunk/prototype/config/repeatOccurrence.ini	(revision 5715)
+++ /trunk/prototype/config/repeatOccurrence.ini	(revision 5741)
@@ -8,3 +8,4 @@
 occurrence = occurrence
 repeat = repeat_id
+exception = exception
 id = id
Index: /trunk/prototype/modules/calendar/interceptors/DBMapping.php
===================================================================
--- /trunk/prototype/modules/calendar/interceptors/DBMapping.php	(revision 5737)
+++ /trunk/prototype/modules/calendar/interceptors/DBMapping.php	(revision 5741)
@@ -120,7 +120,7 @@
 
 	 $params = Controller::service('PostgreSQL')->execResultSql($sql);
+
+	 $params = array_merge( $params, $occ );
          $params = self::deepnessFindEvent( &$uri , &$params , &$criteria , $original);
- 
-	 $params = array_merge( $params, $occ );
 
          return false;
@@ -166,10 +166,18 @@
 	unset( $repeat['id'] );
 
-	$params = self::decodeRepeat( $repeat, $ranges[0]['rangeStart'], $ranges[0]['rangeEnd'] );
+	$exceptions = array();
+
+	if( isset( $repeat['exceptions'] ) )
+	{
+	    $exceptions = explode( ',', $repeat['exceptions'] );
+	    unset( $repeat['exceptions'] );
+	}
+
+	$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,occurrence)VALUES('".$id."', '".implode( "'),('".$id."','", $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 )."')" ) );
 
     }
@@ -244,5 +252,7 @@
 	}
 
-	$return = Controller::find( array( 'concept' => 'repeatOccurrence' ), false, array( 'filter' => array( 'AND', array( '>=', 'occurrence', $origStart ), array( '<=', 'occurrence', $origEnd ), array( 'IN', 'repeat', $ids ) ), 'deepness' => $deep ) );
+// 	$return = Controller::find( array( 'concept' => 'repeatOccurrence' ), false, array( 'filter' => array( 'AND', array( '>=', 'occurrence', $origStart ), array( '<=', 'occurrence', $origEnd ), array( 'IN', 'repeat', $ids ) ), 'deepness' => $deep ) );
+
+	$return = Controller::service('PostgreSQL')->execResultSql( 'SELECT calendar_repeat_occurrence.occurrence as "occurrence", calendar_repeat.object_id as "schedulable" FROM calendar_repeat, calendar_repeat_occurrence WHERE calendar_repeat_occurrence.occurrence >= \''.$origStart.'\' AND calendar_repeat_occurrence.occurrence <= \''.$origEnd.'\' AND calendar_repeat_occurrence.repeat_id IN (\''.implode( '\',\'', $ids ).'\') AND calendar_repeat.id = calendar_repeat_occurrence.repeat_id AND calendar_repeat_occurrence.exception != 1' );
 
 	if( !is_array( $return ) )
@@ -254,16 +264,13 @@
 	foreach( $return as $ret )
 	{
-	      $currentId = $ret['repeat']['schedulable']['id'];
+	      $currentId = $ret['schedulable'];
 
 	      if( !isset( $result[ $currentId ] ) )
 	      {
-		    $result[ $currentId ] = $ret['repeat']['schedulable'];
-		    $result[ $currentId ]['repeat']['schedulable'] = $currentId;
-
+		    $result[ $currentId ] = Controller::read( array( 'concept' => 'schedulable', 'id' => $currentId ) );
 		    $result[ $currentId ][ 'occurrences' ] = array();
 
 		    $calendarToCalendarObj = self::schedulable2calendarToObject( $currentId );
-
-		    $result[ $currentId ]['calendar'] = $calendarToCalendarObj[0]['calendar_id'];  
+		    $result[ $currentId ]['calendar'] = $calendarToCalendarObj[0]['calendar_id'];
 	      }
       
@@ -527,4 +534,6 @@
 		    $repeat = Controller::find( array( 'concept' => 'repeat' ), false, array( 'filter' => array( '=', 'schedulable', $v['id'] ) ) );
 
+		    unset( $result[$i]['repeat'] );
+
 		    if( is_array($repeat) )
 			$result[$i]['repeat'] = $repeat[0];
