[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 | |
---|
[6111] | 10 | $target = (gmdate('U') - 300 ).'000'; |
---|
[5341] | 11 | |
---|
[6111] | 12 | $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 ". |
---|
| 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' ) > 0 ". |
---|
| 20 | "ELSE co.range_start - al.alarm_offset >= '$target' END"); |
---|
[5341] | 21 | |
---|
[6111] | 22 | if(!is_array($parts)) |
---|
| 23 | return; |
---|
| 24 | |
---|
| 25 | $ids = array(); |
---|
| 26 | |
---|
| 27 | foreach ($parts as $i => $part) |
---|
[5341] | 28 | { |
---|
[6111] | 29 | ///Montando lista de participantes |
---|
[5341] | 30 | |
---|
[6111] | 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 ) |
---|
[5341] | 36 | { |
---|
[6111] | 37 | if( $part['user'] === $user['user']['id'] ) |
---|
| 38 | $part['mail'] = $user['user']['mail']; |
---|
[5341] | 39 | |
---|
[6111] | 40 | $attList[] = $user['user']['name']; |
---|
| 41 | } |
---|
[5341] | 42 | |
---|
[6111] | 43 | ///////////////////////// |
---|
[5341] | 44 | |
---|
[6111] | 45 | $timezone = ($part['timezone']) ? $part['timezone'] : 'UTC'; |
---|
| 46 | $sTime = new DateTime( '@'.(int)($part['startTime'] / 1000) , new DateTimeZone($timezone) ); |
---|
| 47 | $eTime = new DateTime( '@'.(int)($part['endTime'] / 1000) , new DateTimeZone($timezone) ); |
---|
[5341] | 48 | |
---|
[6111] | 49 | $data = array('startDate' => date_format( $sTime , 'd/m/Y') , |
---|
| 50 | 'startTime' => date_format( $sTime , 'H:i') , |
---|
| 51 | 'endDate' => date_format( $eTime , 'd/m/Y') , |
---|
| 52 | 'endTime' => date_format( $eTime , 'H:i') , |
---|
| 53 | 'eventTitle' => $part['summary'], |
---|
| 54 | 'eventLocation' => $part['location'], |
---|
| 55 | 'timezone' => $timezone, |
---|
| 56 | 'participants' => '<UL> <LI> '.implode( '<LI></LI> ', $attList ).'</LI> </UL>'); |
---|
| 57 | |
---|
| 58 | Controller::create( array( 'service' => 'SMTP' ), array( 'body' => parseTPL::load_tpl( $data, ROOTPATH.'/modules/calendar/templates/notify_alarm_body.tpl' ), |
---|
| 59 | 'isHtml' => true, |
---|
| 60 | 'subject' => 'Alarme de Calendario', |
---|
| 61 | 'from' => $part['mail'], |
---|
| 62 | 'to' => $part['mail'] ) ); |
---|
| 63 | |
---|
| 64 | Config::regSet('noAlarm', TRUE); //Evita o envio de notificação ????? |
---|
| 65 | $ids[] = $part['id']; |
---|
[5341] | 66 | } |
---|
| 67 | |
---|
[6111] | 68 | if( !empty( $ids ) ) |
---|
| 69 | Controller::update( array( 'concept' => 'alarm' ) , array('sent' => '1'), array( 'IN', 'id', $ids ) ); |
---|
[5341] | 70 | |
---|
| 71 | ?> |
---|