Index: /trunk/prototype/modules/calendar/alarms.php
===================================================================
--- /trunk/prototype/modules/calendar/alarms.php	(revision 6111)
+++ /trunk/prototype/modules/calendar/alarms.php	(revision 6378)
@@ -10,13 +10,13 @@
 $target = (gmdate('U') - 300 ).'000';
 
-$parts = Controller::service('PostgreSQL')->execSql("SELECT calendar_participant.user_info_id as user, co.id as schedulable, co.dtend as endTime, co.dtstart as startTime, co.summary as summary, co.tzid as timezone, co.location as location, al.id as id ".
-						      "FROM calendar_participant, calendar_alarm as al, calendar_object as co, calendar_repeat as rep WHERE ".
-						      "al.participant_id = calendar_participant.id AND ".
-						      "calendar_participant.object_id = co.id AND ".
-						      "al.action_id = '".ALARM_MAIL."' AND ".
-						      "al.sent = '0' AND ".
-						      "CASE WHEN rep.object_id = co.id ".
-						      "THEN  ( select count(occurrence) FROM calendar_repeat_occurrence WHERE rep.object_id = co.id AND rep.id = calendar_repeat_occurrence.repeat_id AND occurrence - al.alarm_offset >= '$target' ) > 0 ".
-						      "ELSE co.range_start - al.alarm_offset >= '$target' END");
+$parts = Controller::service('PostgreSQL')->execSql('SELECT DISTINCT calendar_participant.user_info_id as "user", co.id as "schedulable", co.allDay as "allDay" ,co.dtend as "endTime", co.dtstart as "startTime", co.summary as "summary", co.tzid as "timezone", co.location as "location", al.id as "id" '.
+                            'FROM calendar_participant, calendar_alarm as "al", calendar_object as "co", calendar_repeat as "rep" WHERE ('.
+                            "al.participant_id = calendar_participant.id AND ".
+                            "calendar_participant.object_id = co.id AND ".
+                            "al.action_id = '".ALARM_MAIL."' AND ".
+                            "al.sent = '0' AND ".
+                            "CASE WHEN rep.object_id = co.id ".
+                            "THEN  ( select count(occurrence) FROM calendar_repeat_occurrence WHERE rep.object_id = co.id AND rep.id = calendar_repeat_occurrence.repeat_id AND ((occurrence - al.alarm_offset) >= '$target') AND  ((occurrence - al.alarm_offset) >= '".($target + 360000)."') ) > 0 ".
+                            "ELSE (co.range_start - al.alarm_offset >= '$target') AND (co.range_start - al.alarm_offset < '".($target + 360000)."') END )");
 
 if(!is_array($parts))
@@ -41,14 +41,16 @@
 	}
 
-      /////////////////////////
+        $timezone = new DateTimeZone('UTC');
+	$sTime = new DateTime('@' . (int) ($part['startTime'] / 1000), $timezone);
+	$eTime = new DateTime('@' . (int) ($part['endTime'] / 1000), $timezone);
 
-	$timezone = ($part['timezone']) ? $part['timezone'] : 'UTC';
-	$sTime = new DateTime( '@'.(int)($part['startTime'] / 1000) , new DateTimeZone($timezone) );
-	$eTime =  new DateTime( '@'.(int)($part['endTime'] / 1000) , new DateTimeZone($timezone) );
-
+        $timezone = $part['timezone'];
+        $sTime->setTimezone(new DateTimeZone($part['timezone']));
+        $eTime->setTimezone(new DateTimeZone($part['timezone']));
+        
 	$data = array('startDate' =>  date_format( $sTime , 'd/m/Y') ,
-		      'startTime' =>  date_format( $sTime , 'H:i') ,
+		      'startTime' =>  $part['allDay'] ? '' : date_format( $sTime , 'H:i'),
 		      'endDate' =>  date_format( $eTime , 'd/m/Y') ,
-		      'endTime' =>  date_format( $eTime , 'H:i') ,
+		      'endTime' =>  $part['allDay'] ? '' : date_format( $eTime , 'H:i'),
 		      'eventTitle' =>  $part['summary'],
 		      'eventLocation' =>  $part['location'],
@@ -62,10 +64,10 @@
 								  'to' => $part['mail'] ) );
 
-	Config::regSet('noAlarm', TRUE); //Evita o envio de notificaÃ§Ã£o ?????
+	Config::regSet('noAlarm', TRUE); //Evita o envio de notificação ?????
 	$ids[] = $part['id'];
 }
 
 if( !empty( $ids ) )
-    Controller::update( array( 'concept' => 'alarm' ) , array('sent' => '1'), array( 'IN', 'id', $ids ) );
+    Controller::update( array( 'concept' => 'alarm' ) , array('sent' => '1'), array('filter' => array( 'IN', 'id', $ids ) ));
 
 ?>
