=' , 'rangeStart' ,(gmdate('U') - 300 ).'000') ,
array( '<=' , 'rangeEnd' , (gmdate('U') + 86400).'000')
);
//Busca os Alarmes no Range
$al = Controller::find( array('concept' => 'alarm'), false ,array( 'filter' => $filter));
if(is_array($al))
foreach ($al as $i => $v)
{
$ev = Controller::read( array( 'concept' => 'schedulable' , 'id' => $v['schedulable']) ) ;
$unit = 0;
switch ($v['unit']) {
case 'm': $unit = 60; break;
case 'H': $unit = 3600; break;
case 'd': $unit = 86400; break; }
if( strtotime($v['rangeEnd']) >= time() ) // Evento Recursivo ?
{
//TODO: Fazer Acontecer
}
else
{
if((((int)( $ev['startTime'] / 1000 )) - ( $v['time'] * $unit )) < gmmktime() ) //ja esta na hora de mandar o alarme ?
{
require_once (ROOTPATH.'/api/parseTPL.php' );
switch ($v['type']) {
case 'mail':
$part = Controller::read( array( 'concept' => 'participant' , 'id' => $v['participant']) );
$participants = Controller::find( array( 'concept' => 'participant' ) , false ,array('filter' => array ('=', 'schedulable' , $part['schedulable'] )) );
if($part['isExternal'] == 1)
$user = Controller::read( array( 'concept' => 'user' , 'id' => $part['user'] , 'service' => 'PostgreSQL' ) );
else
$user = Controller::read( array( 'concept' => 'user' , 'id' => $part['user'] ) );
///Montando lista de participantes
$attList = '
';
$organizer = array();
foreach ($participants as $ii => $participant)
{
if($participant['isExternal'] == 1)
$att[$ii] = Controller::read( array( 'concept' => 'user' , 'id' => $participant['user'] , 'service' => 'PostgreSQL' ) );
else
$att[$ii] = Controller::read( array( 'concept' => 'user' , 'id' => $participant['user'] ));
$attList .= '- '.$att[$ii]['name'] .'
';
}
$attList .= '
';
/////////////////////////
$timezone = new DateTimeZone('UTC');
$sTime = new DateTime( '@'.(int)($ev['startTime'] / 1000) , $timezone );
$eTime = new DateTime( '@'.(int)($ev['endTime'] / 1000) , $timezone );
if($ev['timezone'])
{
$sTime->setTimezone(new DateTimeZone($ev['timezone']));
$eTime->setTimezone(new DateTimeZone($ev['timezone']));
}
$data = array('startDate' => date_format( $sTime , 'd/m/Y') ,
'startTime' => date_format( $sTime , 'H:i') ,
'endDate' => date_format( $eTime , 'd/m/Y') ,
'endTime' => date_format( $eTime , 'H:i') ,
'eventTitle' => $ev['summary'],
'eventLocation' => $ev['location'],
'timezone' => ($ev['timezone']) ? $ev['timezone'] : 'UTC' ,
'participants' => $attList
);
$mail['isHtml'] = true;
$mail['body'] = parseTPL::load_tpl($data,ROOTPATH.'/modules/calendar/templates/notify_alarm_body.tpl');
$mail['subject'] = 'Alarme de Calendario';
$mail['from'] = $user['mail'];
$mail['to'] = $user['mail'];
Controller::create( array( 'service' => 'SMTP' ), $mail );
Config::regSet('noAlarm', TRUE); //Evita o envio de notificação
Controller::update( array( 'concept' => 'alarm' , 'id' => $v['id']) , array('sent' => '1'));
break;
case 'sms':
//Sem suporte atualmente
break;
}
}
}
}
?>