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