source: trunk/prototype/modules/calendar/alarms.php @ 6378

Revision 6378, 3.3 KB checked in by acoutinho, 12 years ago (diff)

Ticket #2826 - Inconsistências na notificação nos eventos agendado com alarmes via email

Line 
1<?php
2
3if(!defined('ROOTPATH'))
4    define('ROOTPATH', dirname(__FILE__).'/../..');
5
6require_once ROOTPATH.'/api/controller.php';
7require_once ROOTPATH.'/modules/calendar/constants.php';
8require_once ROOTPATH.'/api/parseTPL.php';
9
10$target = (gmdate('U') - 300 ).'000';
11
12$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" '.
13                            'FROM calendar_participant, calendar_alarm as "al", calendar_object as "co", calendar_repeat as "rep" WHERE ('.
14                            "al.participant_id = calendar_participant.id AND ".
15                            "calendar_participant.object_id = co.id AND ".
16                            "al.action_id = '".ALARM_MAIL."' AND ".
17                            "al.sent = '0' AND ".
18                            "CASE WHEN rep.object_id = co.id ".
19                            "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 ".
20                            "ELSE (co.range_start - al.alarm_offset >= '$target') AND (co.range_start - al.alarm_offset < '".($target + 360000)."') END )");
21
22if(!is_array($parts))
23  return;
24
25$ids = array();
26
27foreach ($parts as $i => $part)
28{
29        ///Montando lista de participantes
30
31        $users = Controller::find( array( 'concept' => 'participant' ) , array( 'user', 'id', 'isExternal' ) ,array('filter' => array ('=', 'schedulable' , $part['schedulable'] ), 'deepness' => 1 ) );
32
33        $attList = array();
34
35        foreach( $users as $user )
36        {
37            if( $part['user'] === $user['user']['id'] )
38                $part['mail'] = $user['user']['mail'];
39
40            $attList[] = $user['user']['name'];
41        }
42
43        $timezone = new DateTimeZone('UTC');
44        $sTime = new DateTime('@' . (int) ($part['startTime'] / 1000), $timezone);
45        $eTime = new DateTime('@' . (int) ($part['endTime'] / 1000), $timezone);
46
47        $timezone = $part['timezone'];
48        $sTime->setTimezone(new DateTimeZone($part['timezone']));
49        $eTime->setTimezone(new DateTimeZone($part['timezone']));
50       
51        $data = array('startDate' =>  date_format( $sTime , 'd/m/Y') ,
52                      'startTime' =>  $part['allDay'] ? '' : date_format( $sTime , 'H:i'),
53                      'endDate' =>  date_format( $eTime , 'd/m/Y') ,
54                      'endTime' =>  $part['allDay'] ? '' : date_format( $eTime , 'H:i'),
55                      'eventTitle' =>  $part['summary'],
56                      'eventLocation' =>  $part['location'],
57                      'timezone' => $timezone,
58                      'participants' =>  '<UL> <LI> '.implode( '<LI></LI> ', $attList ).'</LI> </UL>');
59
60        Controller::create( array( 'service' => 'SMTP' ), array( 'body' => parseTPL::load_tpl( $data, ROOTPATH.'/modules/calendar/templates/notify_alarm_body.tpl' ),
61                                                                  'isHtml' => true,
62                                                                  'subject' => 'Alarme de Calendario',
63                                                                  'from' => $part['mail'],
64                                                                  'to' => $part['mail'] ) );
65
66        Config::regSet('noAlarm', TRUE); //Evita o envio de notificação ?????
67        $ids[] = $part['id'];
68}
69
70if( !empty( $ids ) )
71    Controller::update( array( 'concept' => 'alarm' ) , array('sent' => '1'), array('filter' => array( 'IN', 'id', $ids ) ));
72
73?>
Note: See TracBrowser for help on using the repository browser.