Example #1
0
 static function initSessionVars($vars)
 {
     session_start();
     $_SESSION['wallet'] = $vars;
     $_SESSION['config']['expressoCalendar']['useCaldav'] = FALSE;
     $_SESSION['flags']['currentapp'] = 'expressoCalendar';
     Config::regSet('noAlarm', true);
 }
Example #2
0
 public function parse($data, $params = false)
 {
     Config::regSet('noAlarm', TRUE);
     //Evita o envio de notificação
     $vcalendar = new icalCreatorVcalendar();
     $vcalendar->parse(trim($data));
     $vcalendar->sort();
     $return = array();
     $method = $vcalendar->getProperty('method', FALSE, FALSE);
     $params['prodid'] = $vcalendar->getProperty('prodid', false, false);
     $params['X-WR-TIMEZONE'] = ($xrTimezone = $vcalendar->getProperty('X-WR-TIMEZONE', false, false)) ? self::nomalizeTZID($xrTimezone[1]) : false;
     while ($component = $vcalendar->getComponent()) {
         $interation = array();
         $uid = $component->getProperty('uid', false, false);
         //Resgata o uid do componente
         switch (strtoupper($component->objName)) {
             case 'VEVENT':
                 switch ($method) {
                     case 'PUBLISH':
                         //Caso o evento não exista o mesmo cria um novo evento, se já existir o mesmo referencia o evento com agenda
                         if (!($schedulable = self::_getSchedulable($uid))) {
                             $interation = self::_makeVEVENT($schedulable, $component, $params);
                         } else {
                             $links = Controller::read(array('concept' => 'calendarToSchedulable'), array('id'), array('filter' => array('AND', array('=', 'calendar', $params['calendar']), array('=', 'schedulable', $schedulable['id']))));
                             if (!$links && !isset($links[0])) {
                                 Controller::create(array('concept' => 'calendarToSchedulable'), array('calendar' => $params['calendar'], 'schedulable' => $schedulable['id']));
                             }
                         }
                         break;
                     case 'REQUEST':
                         $schedulable = self::_getSchedulable($uid);
                         $calendar = false;
                         $accpeted = true;
                         if ($schedulable) {
                             ///Verifica se o usuario e um participante e se este aceitou o pedido.
                             foreach ($schedulable['participants'] as $value) {
                                 if ($value['user']['id'] == $params['owner'] && ($value['status'] == STATUS_UNANSWERED || $value['status'] == STATUS_DECLINED)) {
                                     $accpeted = false;
                                 }
                             }
                             //Caso o evento exista
                             if (!($calendar = self::_existInMyCalendars($schedulable['id'], $params['owner'])) || !$accpeted) {
                                 $calendarToSchedulable = array();
                                 $calendarToSchedulable['calendar'] = $params['calendar'];
                                 $calendarToSchedulable['schedulable'] = $schedulable['id'];
                                 $interation['calendarToSchedulable://' . mt_rand() . '(Formatter)'] = $calendarToSchedulable;
                                 if (isset($params['status'])) {
                                     if ($params['owner'] != Config::me("uidNumber")) {
                                         $user = Controller::Read(array('concept' => 'user'), false, array('filter' => array('=', 'id', $params['owner'])));
                                         $pID = self::_getParticipantByMail($user[0]['mail'], $schedulable['participants']);
                                     } else {
                                         $pID = self::_getParticipantByMail(Config::me('mail'), $schedulable['participants']);
                                     }
                                     //caso nõa seja participante adiciona a lista de participantes
                                     if (!$pID) {
                                         $pID = mt_rand() . '2(Formatter)';
                                         $interation['participant://' . $pID]['status'] = $params['status'];
                                         $interation['participant://' . $pID]['user'] = $params['owner'];
                                         $interation['participant://' . $pID]['isOrganizer'] = '0';
                                         $interation['participant://' . $pID]['schedulable'] = $schedulable['id'];
                                     } else {
                                         $interation['participant://' . $pID]['status'] = $params['status'];
                                     }
                                 }
                                 Config::regSet('noAlarm', FALSE);
                                 //reativa notificação
                             } else {
                                 if (self::_getTime($component, 'dtstamp') > $schedulable['dtstamp'] || $component->getProperty('sequence', false, false) > $schedulable['sequence']) {
                                     //Organizador esta requisitando que você atualize o evento
                                     $params['calendar'] = $params['calendar'] == 'true' ? $calendar : $params['calendar'];
                                     $interation = self::_makeVEVENT($schedulable, $component, $params);
                                 } else {
                                     if ($component->getProperty('sequence', false, false) === $schedulable['sequence']) {
                                         //Ler melhor rfc sobre isto 3.2.2.2
                                         //Aparentemente é para retornar um ical com o evento atualizado para o attende
                                     }
                                 }
                                 if (isset($params['status'])) {
                                     if ($params['owner'] != Config::me("uidNumber")) {
                                         $user = Controller::Read(array('concept' => 'user'), false, array('filter' => array('=', 'id', $params['owner'])));
                                         $pID = self::_getParticipantByMail($user[0]['mail'], $schedulable['participants']);
                                     } else {
                                         $pID = self::_getParticipantByMail(Config::me('mail'), $schedulable['participants']);
                                     }
                                     //Verifica a importação de eventos em que não participo
                                     if ($pID) {
                                         $interation['participant://' . $pID]['status'] = $params['status'];
                                     }
                                 }
                             }
                         } else {
                             // Importar evento
                             $interation = self::_makeVEVENT(array(), $component, $params);
                             if (strpos($params['prodid'], 'kigkonsult.se') !== false) {
                                 //envia notificação para fora
                                 /* Data de Inicio */
                                 $startTime = $component->getProperty('dtstart', false, true);
                                 $tzid = isset($startTime['params']['TZID']) ? $startTime['params']['TZID'] : $params['X-WR-TIMEZONE'];
                                 /* Tiem zone do evento */
                                 if ($tzid) {
                                     $sc['timezone'] = self::nomalizeTZID($tzid);
                                 } else {
                                     $sc['timezone'] = isset($params['calendar_timezone']) ? $params['calendar_timezone'] : 'America/Sao_Paulo';
                                 }
                                 $objTimezone = new DateTimeZone($sc['timezone']);
                                 if (isset($startTime['params']['VALUE']) && $startTime['params']['VALUE'] === 'DATE' && isset($params['calendar_timezone'])) {
                                     $sc['allDay'] = 1;
                                     $sc['startTime'] = self::date2timestamp($startTime['value']) - self::_getTzOffset('UTC', $sc['timezone']) . '000';
                                 } elseif (isset($startTime['params']['TZID']) && !isset($startTime['value']['tz'])) {
                                     /* Caso não tenha um tz na data mais exista um parametro TZID deve ser aplicado o timezone do TZID a data */
                                     $sc['startTime'] = self::date2timestamp($startTime['value']) - self::_getTzOffset('UTC', $startTime['params']['TZID']) . '000';
                                 } else {
                                     $sc['startTime'] = self::date2timestamp($startTime['value']) . '000';
                                     if (strpos($params['prodid'], 'Outlook') !== false) {
                                         //Se o ics veio em utc não aplicar horario de verão
                                         $sTime = new DateTime('@' . (int) ($sc['startTime'] / 1000), new DateTimeZone('UTC'));
                                         $sTime->setTimezone($objTimezone);
                                         if ($sTime->format('I')) {
                                             //Se o ics veio em utc não aplicar horario de verão
                                             $sc['startTime'] = $sc['startTime'] - 3600000;
                                         }
                                     }
                                 }
                                 /* Data de Termino */
                                 $endTime = $component->getProperty('dtend', false, true);
                                 if (isset($endTime['params']['VALUE']) && $endTime['params']['VALUE'] === 'DATE') {
                                     $sc['endTime'] = self::date2timestamp($endTime['value']) - self::_getTzOffset('UTC', $sc['timezone']) . '000';
                                 } else {
                                     if (isset($endTime['params']['TZID']) && !isset($endTime['value']['tz'])) {
                                         /* Caso não tenha um tz na data mais exista um parametro TZID deve ser aplicado o timezone do TZID a data */
                                         $sc['endTime'] = self::date2timestamp($endTime['value']) - self::_getTzOffset('UTC', $endTime['params']['TZID']) . '000';
                                     } else {
                                         $sc['endTime'] = self::date2timestamp($endTime['value']) . '000';
                                         if (strpos($params['prodid'], 'Outlook') !== false) {
                                             //Se o ics veio em utc não aplicar horario de verão
                                             $eTime = new DateTime('@' . (int) ($sc['endTime'] / 1000), new DateTimeZone('UTC'));
                                             $eTime->setTimezone($objTimezone);
                                             if ($eTime->format('I')) {
                                                 $sc['endTime'] = $sc['endTime'] - 3600000;
                                             }
                                         }
                                     }
                                 }
                                 if ($uid = $component->getProperty('uid', false, false)) {
                                 }
                                 $sc['uid'] = $uid;
                                 $sc['summary'] = mb_convert_encoding($component->getProperty('summary', false, false), 'UTF-8', 'UTF-8,ISO-8859-1');
                                 /* Definindo Description */
                                 if ($desc = $component->getProperty('description', false, false)) {
                                     $sc['description'] = mb_convert_encoding(str_ireplace(array('\\n', '\\t'), array("\n", "\t"), $desc), 'UTF-8', 'UTF-8,ISO-8859-1');
                                 }
                                 /* Definindo location */
                                 if ($location = $component->getProperty('location', false, false)) {
                                     $sc['location'] = mb_convert_encoding($location, 'UTF-8', 'UTF-8,ISO-8859-1');
                                 }
                                 if ($property = $component->getProperty('organizer', FALSE, TRUE)) {
                                     $participant = array();
                                     $mailUser = trim(str_replace('MAILTO:', '', $property['value']));
                                     $participantID = mt_rand() . '2(Formatter)';
                                     $participant['isOrganizer'] = '1';
                                     $user = null;
                                     $participant['isExternal'] = 1;
                                     /* Gera um randon id para o contexto formater */
                                     $userID = mt_rand() . '4(Formatter)';
                                     $user['mail'] = $mailUser;
                                     $organizerMail = $mailUser;
                                     $user['name'] = isset($property['params']['CN']) ? $property['params']['CN'] : '';
                                     $user['isExternal'] = '1';
                                     $participant['user'] = $user;
                                     $sc['participants'][] = $participant;
                                 }
                                 $participant['status'] = isset($params['status']) ? $params['status'] : STATUS_ACCEPTED;
                                 $participant['isOrganizer'] = '0';
                                 $participant['isExternal'] = 0;
                                 $user = false;
                                 if ($params['owner'] != Config::me("uidNumber")) {
                                     $user = Controller::Read(array('concept' => 'user'), false, array('filter' => array('=', 'id', $params['owner'])));
                                 }
                                 $participant['user'] = $user ? array('mail' => $user['mail'], 'name' => $user['name']) : array('mail' => Config::me('mail'), 'name' => Config::me('cn'));
                                 $sc['participants'][] = $participant;
                                 $sc['type'] = EVENT_ID;
                                 $ical['source'] = Controller::format(array('service' => 'iCal'), array($sc), array('method' => 'REPLY'));
                                 $ical['type'] = 'application/ics';
                                 $ical['name'] = 'outlook.ics';
                                 $ical2['source'] = $ical['source'];
                                 $ical2['type'] = 'text/calendar; method=REPLY';
                                 $ical2['name'] = 'thunderbird.ics';
                                 $timezone = new DateTimeZone('UTC');
                                 $sTime = new DateTime('@' . (int) ($sc['startTime'] / 1000), $timezone);
                                 $eTime = new DateTime('@' . (int) ($sc['endTime'] / 1000), $timezone);
                                 if (isset($sc['timezone'])) {
                                     $sTime->setTimezone(new DateTimeZone($sc['timezone']));
                                     $eTime->setTimezone(new DateTimeZone($sc['timezone']));
                                 }
                                 $data = array('startDate' => date_format($sTime, 'd/m/Y'), 'startTime' => isset($sc['allDay']) && $sc['allDay'] ? '' : date_format($sTime, 'H:i'), 'endDate' => date_format($eTime, 'd/m/Y'), 'endTime' => isset($sc['allDay']) ? '' : date_format($eTime, 'H:i'), 'eventTitle' => $sc['summary'], 'eventLocation' => isset($sc['location']) ? $sc['location'] : '', 'timezone' => $sc['timezone'] ? $sc['timezone'] : 'UTC', 'participant' => isset($part['user']['name']) ? $part['user']['name'] : $part['user']['mail']);
                                 $subject['notificationType'] = 'Convite Aceito';
                                 $subject['eventTitle'] = mb_convert_encoding($sc['summary'], 'ISO-8859-1', 'ISO-8859-1,UTF-8');
                                 $subject['startDate'] = date_format($sTime, 'd/m/Y');
                                 $subject['startTime'] = $sc['allDay'] ? '' : date_format($sTime, 'H:i');
                                 $subject['endDate'] = date_format($eTime, 'd/m/Y');
                                 $subject['endTime'] = $sc['allDay'] ? '' : date_format($eTime, 'H:i');
                                 $subject['participant'] = Config::me('uid');
                                 $params['status'] = isset($params['status']) ? $params['status'] : STATUS_ACCEPTED;
                                 switch ($params['status']) {
                                     case STATUS_ACCEPTED:
                                         $tpl = 'notify_accept_body';
                                         $subject['notificationType'] = 'Convite Aceito';
                                         break;
                                     case STATUS_TENTATIVE:
                                         $tpl = 'notify_attempt_body';
                                         $subject['notificationType'] = 'Convite  aceito provisoriamente';
                                         break;
                                     case STATUS_CANCELLED:
                                         $tpl = 'notify_reject_body';
                                         $subject['notificationType'] = 'Convite rejeitado';
                                         break;
                                 }
                                 require_once ROOTPATH . '/api/parseTPL.php';
                                 $mail = array();
                                 $mail['attachments'][] = $ical;
                                 $mail['attachments'][] = $ical2;
                                 $mail['isHtml'] = true;
                                 $mail['body'] = parseTPL::load_tpl($data, ROOTPATH . '/modules/calendar/templates/' . $tpl . '.tpl');
                                 $mail['subject'] = parseTPL::load_tpl($subject, ROOTPATH . '/modules/calendar/templates/notify_subject.tpl');
                                 $mail['from'] = $user ? '"' . $user['name'] . '" <' . $user['mail'] . '>' : '"' . Config::me('cn') . '" <' . Config::me('mail') . '>';
                                 $mail['to'] = $organizerMail;
                                 Controller::create(array('service' => 'SMTP'), $mail);
                             }
                         }
                         break;
                     case 'REFRESH':
                         break;
                     case 'CANCEL':
                         if ($schedulable = self::_getSchedulable($uid)) {
                             $interation['schedulable://' . $schedulable['id']] = false;
                         }
                         break;
                     case 'ADD':
                         break;
                     case 'REPLY':
                         if ($schedulable = self::_getSchedulable($uid)) {
                             while ($property = $component->getProperty('attendee', FALSE, TRUE)) {
                                 if ($pID = self::_getParticipantByMail(str_replace('MAILTO:', '', $property['value']), $schedulable['participants'])) {
                                     $interation['participant://' . $pID] = array('id' => $pID, 'status' => constant('STATUS_' . strtoupper($property['params']['PARTSTAT'])));
                                 }
                             }
                             $interation['schedulable://' . $schedulable['id']]['sequence'] = $schedulable['sequence'] + 1;
                         }
                         break;
                     case 'COUNTER':
                         if ($params['acceptedSuggestion'] !== 'false') {
                             $schedulable = self::_getSchedulable($uid);
                             $params['calendar'] = self::_existInMyCalendars($schedulable['id'], $params['owner']);
                             $interation = self::_makeCOUNTER($schedulable, $component, $params);
                             Config::regSet('noAlarm', FALSE);
                         } else {
                             $response = array();
                             $response['from'] = $params['from'];
                             $response['type'] = 'suggestionResponse';
                             $response['status'] = 'DECLINECOUNTER';
                             $response['schedulable'] = self::_getSchedulable($uid);
                             Controller::create(array('concept' => 'notification'), $response);
                         }
                         break;
                     case 'DECLINECOUNTER':
                         break;
                     default:
                         $schedulable = self::_getSchedulable($uid);
                         if ($schedulable && (self::_getTime($component, 'dtstamp') > $schedulable['dtstamp'] || $component->getProperty('sequence', false, false) > $schedulable['sequence'])) {
                             //Caso o evento exista
                             $interation = self::_makeVEVENT($schedulable, $component, $params);
                             if (!self::_existInMyCalendars($schedulable['id'], $params['owner'])) {
                                 $calendarToSchedulable = array();
                                 $calendarToSchedulable['calendar'] = $params['calendar'];
                                 $calendarToSchedulable['schedulable'] = $schedulable['id'];
                                 $interation['calendarToSchedulable://' . mt_rand() . '(Formatter)'] = $calendarToSchedulable;
                             }
                         } else {
                             // Importar evento
                             $interation = self::_makeVEVENT(array(), $component, $params);
                         }
                         break;
                 }
                 $return[] = $interation;
                 break;
                 /***********************************************************************TODO*******************************************************************************/
             /***********************************************************************TODO*******************************************************************************/
             case 'VTODO':
                 switch ($method) {
                     case 'PUBLISH':
                         //Caso a tarefa não exista o mesmo cria um novo evento, se já existir o mesmo referencia o evento com agenda
                         if (!($schedulable = self::_getSchedulable($uid))) {
                             $interation = self::_makeVTODO($schedulable, $component, $params);
                         } else {
                             $links = Controller::read(array('concept' => 'calendarToSchedulable'), array('id'), array('filter' => array('AND', array('=', 'calendar', $params['calendar']), array('=', 'schedulable', $schedulable['id']))));
                             if (!$links && !isset($links[0])) {
                                 Controller::create(array('concept' => 'calendarToSchedulable'), array('calendar' => $params['calendar'], 'schedulable' => $schedulable['id']));
                             }
                         }
                         break;
                     case 'REQUEST':
                         $schedulable = self::_getSchedulable($uid);
                         if ($schedulable) {
                             //Caso tarefa exista
                             if (!self::_existInMyCalendars($schedulable['id'], $params['owner'])) {
                                 $calendarToSchedulable = array();
                                 $calendarToSchedulable['calendar'] = $params['calendar'];
                                 $calendarToSchedulable['schedulable'] = $schedulable['id'];
                                 $interation['calendarToSchedulable://' . mt_rand() . '(Formatter)'] = $calendarToSchedulable;
                                 if (isset($params['status'])) {
                                     if ($params['owner'] != Config::me("uidNumber")) {
                                         $user = Controller::Read(array('concept' => 'user'), false, array('filter' => array('=', 'id', $params['owner'])));
                                         $pID = self::_getParticipantByMail($user[0]['mail'], $schedulable['participants']);
                                     } else {
                                         $pID = self::_getParticipantByMail(Config::me('mail'), $schedulable['participants']);
                                     }
                                     $interation['participant://' . $pID]['status'] = $params['status'];
                                 }
                                 Config::regSet('noAlarm', FALSE);
                                 //reativa notificação
                             } else {
                                 if (self::_getTime($component, 'dtstamp') > $schedulable['dtstamp'] || $component->getProperty('sequence', false, false) > $schedulable['sequence']) {
                                     //Organizador esta requisitando que você atualize o evento
                                     $interation = self::_makeVEVENT($schedulable, $component, $params);
                                 } else {
                                     if ($component->getProperty('sequence', false, false) === $schedulable['sequence']) {
                                         //Ler melhor rfc sobre isto 3.2.2.2
                                         //Aparentemente é para retornar um ical com o evento atualizado para o attende
                                     }
                                 }
                                 if (isset($params['status'])) {
                                     if ($params['owner'] != Config::me("uidNumber")) {
                                         $user = Controller::Read(array('concept' => 'user'), false, array('filter' => array('=', 'id', $params['owner'])));
                                         $pID = self::_getParticipantByMail($user[0]['mail'], $schedulable['participants']);
                                     } else {
                                         $pID = self::_getParticipantByMail(Config::me('mail'), $schedulable['participants']);
                                         //Verifica a importação de tarefas em que não participo
                                         if ($pID) {
                                             $pID = mt_rand() . '2(Formatter)';
                                             $interation['participant://' . $pID]['status'] = $params['status'];
                                             $interation['participant://' . $pID]['user'] = $params['owner'];
                                             $interation['participant://' . $pID]['isOrganizer'] = '0';
                                             $interation['participant://' . $pID]['schedulable'] = $schedulable['id'];
                                         } else {
                                             $interation['participant://' . $pID]['status'] = $params['status'];
                                         }
                                     }
                                 }
                             }
                         } else {
                             // Importar tarefa
                             $interation = self::_makeVTODO(array(), $component, $params);
                             if (strpos($params['prodid'], 'kigkonsult.se') !== false) {
                                 //envia notificação para fora
                                 /* Data de Inicio */
                                 $startTime = $component->getProperty('dtstart', false, true);
                                 $tzid = isset($startTime['params']['TZID']) ? $startTime['params']['TZID'] : $params['X-WR-TIMEZONE'];
                                 /* Tiem zone do evento */
                                 if ($tzid) {
                                     $sc['timezone'] = self::nomalizeTZID($tzid);
                                 } else {
                                     $sc['timezone'] = isset($params['calendar_timezone']) ? $params['calendar_timezone'] : 'America/Sao_Paulo';
                                 }
                                 $objTimezone = new DateTimeZone($sc['timezone']);
                                 if (isset($startTime['params']['VALUE']) && $startTime['params']['VALUE'] === 'DATE' && isset($params['calendar_timezone'])) {
                                     $sc['allDay'] = 1;
                                     $sc['startTime'] = self::date2timestamp($startTime['value']) - self::_getTzOffset('UTC', $sc['timezone']) . '000';
                                 } elseif (isset($startTime['params']['TZID']) && !isset($startTime['value']['tz'])) {
                                     /* Caso não tenha um tz na data mais exista um parametro TZID deve ser aplicado o timezone do TZID a data */
                                     $sc['startTime'] = self::date2timestamp($startTime['value']) - self::_getTzOffset('UTC', $startTime['params']['TZID']) . '000';
                                 } else {
                                     $sc['startTime'] = self::date2timestamp($startTime['value']) . '000';
                                     if (strpos($params['prodid'], 'Outlook') !== false) {
                                         //Se o ics veio em utc não aplicar horario de verão
                                         $sTime = new DateTime('@' . (int) ($sc['startTime'] / 1000), new DateTimeZone('UTC'));
                                         $sTime->setTimezone($objTimezone);
                                         if ($sTime->format('I')) {
                                             //Se o ics veio em utc não aplicar horario de verão
                                             $sc['startTime'] = $sc['startTime'] - 3600000;
                                         }
                                     }
                                 }
                                 /* Data de Termino */
                                 $endTime = $component->getProperty('dtend', false, true);
                                 if (isset($endTime['params']['VALUE']) && $endTime['params']['VALUE'] === 'DATE') {
                                     $sc['endTime'] = self::date2timestamp($endTime['value']) - self::_getTzOffset('UTC', $sc['timezone']) . '000';
                                 } else {
                                     if (isset($endTime['params']['TZID']) && !isset($endTime['value']['tz'])) {
                                         /* Caso não tenha um tz na data mais exista um parametro TZID deve ser aplicado o timezone do TZID a data */
                                         $sc['endTime'] = self::date2timestamp($endTime['value']) - self::_getTzOffset('UTC', $endTime['params']['TZID']) . '000';
                                     } else {
                                         $sc['endTime'] = self::date2timestamp($endTime['value']) . '000';
                                         if (strpos($params['prodid'], 'Outlook') !== false) {
                                             //Se o ics veio em utc não aplicar horario de verão
                                             $eTime = new DateTime('@' . (int) ($sc['endTime'] / 1000), new DateTimeZone('UTC'));
                                             $eTime->setTimezone($objTimezone);
                                             if ($eTime->format('I')) {
                                                 $sc['endTime'] = $sc['endTime'] - 3600000;
                                             }
                                         }
                                     }
                                 }
                                 if ($uid = $component->getProperty('uid', false, false)) {
                                     $sc['uid'] = $uid;
                                 }
                                 $sc['summary'] = mb_convert_encoding($component->getProperty('summary', false, false), 'UTF-8', 'UTF-8,ISO-8859-1');
                                 /* Definindo Description */
                                 if ($desc = $component->getProperty('description', false, false)) {
                                     $sc['description'] = mb_convert_encoding(str_ireplace(array('\\n', '\\t'), array("\n", "\t"), $desc), 'UTF-8', 'UTF-8,ISO-8859-1');
                                 }
                                 if ($priority = $component->getProperty('priority', false, false)) {
                                     $sc['priority'] = mb_convert_encoding(str_ireplace(array('\\n', '\\t'), array("\n", "\t"), $priority), 'UTF-8', 'UTF-8,ISO-8859-1');
                                 }
                                 if ($status = $component->getProperty('status', false, false)) {
                                     $sc['status'] = $this->decodeStatusTodo(mb_convert_encoding(str_ireplace(array('\\n', '\\t'), array("\n", "\t"), $status), 'UTF-8', 'UTF-8,ISO-8859-1'));
                                 }
                                 if ($percentage = $component->getProperty('percent-complete', false, false)) {
                                     $sc['percentage'] = mb_convert_encoding(str_ireplace(array('\\n', '\\t'), array("\n", "\t"), $percentage), 'UTF-8', 'UTF-8,ISO-8859-1');
                                 }
                                 /* Definindo location */
                                 if ($location = $component->getProperty('location', false, false)) {
                                     $sc['location'] = mb_convert_encoding($location, 'UTF-8', 'UTF-8,ISO-8859-1');
                                 }
                                 if ($property = $component->getProperty('organizer', FALSE, TRUE)) {
                                     $participant = array();
                                     $mailUser = trim(str_replace('MAILTO:', '', $property['value']));
                                     $participantID = mt_rand() . '2(Formatter)';
                                     $participant['isOrganizer'] = '1';
                                     $user = null;
                                     $participant['isExternal'] = 1;
                                     /* Gera um randon id para o contexto formater */
                                     $userID = mt_rand() . '4(Formatter)';
                                     $user['mail'] = $mailUser;
                                     $organizerMail = $mailUser;
                                     $user['name'] = isset($property['params']['CN']) ? $property['params']['CN'] : '';
                                     $user['isExternal'] = '1';
                                     $participant['user'] = $user;
                                     $sc['participants'][] = $participant;
                                 }
                                 $participant['status'] = isset($params['status']) ? $params['status'] : STATUS_ACCEPTED;
                                 $participant['isOrganizer'] = '0';
                                 $participant['isExternal'] = 0;
                                 $participant['user'] = array('mail' => Config::me('mail'), 'name' => Config::me('cn'));
                                 $sc['participants'][] = $participant;
                                 $sc['type'] = TODO_ID;
                                 $ical['source'] = Controller::format(array('service' => 'iCal'), array($sc), array('method' => 'REPLY'));
                                 $ical['type'] = 'application/ics';
                                 $ical['name'] = 'outlook.ics';
                                 $ical2['source'] = $ical['source'];
                                 $ical2['type'] = 'text/calendar; method=REPLY';
                                 $ical2['name'] = 'thunderbird.ics';
                                 $timezone = new DateTimeZone('UTC');
                                 $sTime = new DateTime('@' . (int) ($sc['startTime'] / 1000), $timezone);
                                 $eTime = new DateTime('@' . (int) ($sc['endTime'] / 1000), $timezone);
                                 if (isset($sc['timezone'])) {
                                     $sTime->setTimezone(new DateTimeZone($sc['timezone']));
                                     $eTime->setTimezone(new DateTimeZone($sc['timezone']));
                                 }
                                 $data = array('startDate' => date_format($sTime, 'd/m/Y'), 'startTime' => isset($sc['allDay']) && $sc['allDay'] ? '' : date_format($sTime, 'H:i'), 'endDate' => date_format($eTime, 'd/m/Y'), 'endTime' => isset($sc['allDay']) ? '' : date_format($eTime, 'H:i'), 'eventTitle' => $sc['summary'], 'eventLocation' => isset($sc['location']) ? $sc['location'] : '', 'timezone' => $sc['timezone'] ? $sc['timezone'] : 'UTC', 'participant' => isset($part['user']['name']) ? $part['user']['name'] : $part['user']['mail']);
                                 $subject['notificationType'] = 'Convite Aceito';
                                 $subject['eventTitle'] = mb_convert_encoding($sc['summary'], 'ISO-8859-1', 'ISO-8859-1,UTF-8');
                                 $subject['startDate'] = date_format($sTime, 'd/m/Y');
                                 $subject['startTime'] = $sc['allDay'] ? '' : date_format($sTime, 'H:i');
                                 $subject['endDate'] = date_format($eTime, 'd/m/Y');
                                 $subject['endTime'] = $sc['allDay'] ? '' : date_format($eTime, 'H:i');
                                 $subject['participant'] = Config::me('uid');
                                 $params['status'] = isset($params['status']) ? $params['status'] : STATUS_ACCEPTED;
                                 switch ($params['status']) {
                                     case STATUS_ACCEPTED:
                                         $tpl = 'notify_accept_body';
                                         $subject['notificationType'] = 'Convite Aceito';
                                         break;
                                     case STATUS_TENTATIVE:
                                         $tpl = 'notify_attempt_body';
                                         $subject['notificationType'] = 'Convite  aceito provisoriamente';
                                         break;
                                     case STATUS_CANCELLED:
                                         $tpl = 'notify_reject_body';
                                         $subject['notificationType'] = 'Convite rejeitado';
                                         break;
                                 }
                                 require_once ROOTPATH . '/api/parseTPL.php';
                                 $mail = array();
                                 $mail['attachments'][] = $ical;
                                 $mail['attachments'][] = $ical2;
                                 $mail['isHtml'] = true;
                                 $mail['body'] = parseTPL::load_tpl($data, ROOTPATH . '/modules/calendar/templates/' . $tpl . '.tpl');
                                 $mail['subject'] = parseTPL::load_tpl($subject, ROOTPATH . '/modules/calendar/templates/notify_subject.tpl');
                                 $mail['from'] = '"' . Config::me('cn') . '" <' . Config::me('mail') . '>';
                                 $mail['to'] = $organizerMail;
                                 Controller::create(array('service' => 'SMTP'), $mail);
                             }
                         }
                         break;
                     case 'REFRESH':
                         break;
                     case 'CANCEL':
                         if ($schedulable = self::_getSchedulable($uid)) {
                             $interation['schedulable://' . $schedulable['id']] = false;
                         }
                         break;
                     case 'ADD':
                         break;
                     case 'REPLY':
                         if ($schedulable = self::_getSchedulable($uid)) {
                             while ($property = $component->getProperty('attendee', FALSE, TRUE)) {
                                 if ($pID = self::_getParticipantByMail(str_replace('MAILTO:', '', $property['value']), $schedulable['participants'])) {
                                     $interation['participant://' . $pID] = array('id' => $pID, 'status' => constant('STATUS_' . strtoupper($property['params']['PARTSTAT'])));
                                 }
                             }
                             $interation['schedulable://' . $schedulable['id']]['sequence'] = $schedulable['sequence'] + 1;
                         }
                         break;
                     case 'COUNTER':
                         if ($params['acceptedSuggestion'] !== 'false') {
                             $schedulable = self::_getSchedulable($uid);
                             $params['calendar'] = self::_existInMyCalendars($schedulable['id'], $params['owner']);
                             $interation = self::_makeCOUNTER($schedulable, $component, $params);
                             Config::regSet('noAlarm', FALSE);
                         } else {
                             $response = array();
                             $response['from'] = $params['from'];
                             $response['type'] = 'suggestionResponse';
                             $response['status'] = 'DECLINECOUNTER';
                             $response['schedulable'] = self::_getSchedulable($uid);
                             Controller::create(array('concept' => 'notification'), $response);
                         }
                         break;
                     case 'DECLINECOUNTER':
                         break;
                     default:
                         $schedulable = self::_getSchedulable($uid);
                         if ($schedulable && (self::_getTime($component, 'dtstamp') > $schedulable['dtstamp'] || $component->getProperty('sequence', false, false) > $schedulable['sequence'])) {
                             //Caso o evento exista
                             $interation = self::_makeVEVENT($schedulable, $component, $params);
                             if (!self::_existInMyCalendars($schedulable['id'], $params['owner'])) {
                                 $calendarToSchedulable = array();
                                 $calendarToSchedulable['calendar'] = $params['calendar'];
                                 $calendarToSchedulable['schedulable'] = $schedulable['id'];
                                 $interation['calendarToSchedulable://' . mt_rand() . '(Formatter)'] = $calendarToSchedulable;
                             }
                         } else {
                             // Importar evento
                             $interation = self::_makeVEVENT(array(), $component, $params);
                         }
                         break;
                 }
                 $return[] = $interation;
                 break;
                 /***********************************************************************TODO*******************************************************************************/
             /***********************************************************************TODO*******************************************************************************/
             case 'VTIMEZONE':
                 break;
         }
     }
     return $return;
 }
Example #3
0
$target = gmdate('U') - 300 . '000';
$parts = Controller::service('PostgreSQL')->execSql('SELECT part.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" FROM calendar_object as co INNER JOIN calendar_alarm al ON co.id = al.object_id JOIN calendar_participant part  ON part.id = al.participant_id LEFT JOIN calendar_repeat rep ON  rep.object_id = co.id  LEFT JOIN calendar_repeat_occurrence occ ON occ.repeat_id = rep.id WHERE ( al.action_id = \'' . ALARM_MAIL . '\' AND al.sent = \'0\' AND CASE WHEN occ.occurrence > 0 THEN occ.occurrence - al.alarm_offset ELSE co.dtstart - al.alarm_offset END BETWEEN \'' . $target . '\' AND \'' . ($target + 360000) . '\') ');
if (!is_array($parts)) {
    return;
}
$ids = array();
foreach ($parts as $i => $part) {
    ///Montando lista de participantes
    $users = Controller::find(array('concept' => 'participant'), array('user', 'id', 'isExternal'), array('filter' => array('=', 'schedulable', $part['schedulable']), 'deepness' => 1));
    $attList = array();
    foreach ($users as $user) {
        if ($part['user'] === $user['user']['id']) {
            $part['mail'] = $user['user']['mail'];
        }
        $attList[] = $user['user']['name'];
    }
    $timezone = new DateTimeZone('UTC');
    $sTime = new DateTime('@' . (int) ($part['startTime'] / 1000), $timezone);
    $eTime = new DateTime('@' . (int) ($part['endTime'] / 1000), $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' => $part['allDay'] ? '' : date_format($sTime, 'H:i'), 'endDate' => date_format($eTime, 'd/m/Y'), 'endTime' => $part['allDay'] ? '' : date_format($eTime, 'H:i'), 'eventTitle' => $part['summary'], 'eventLocation' => $part['location'], 'timezone' => $timezone, 'participants' => '<UL> <LI> ' . implode('<LI></LI> ', $attList) . '</LI> </UL>');
    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')), 'isHtml' => true, 'subject' => 'Alarme de Calendario', 'from' => $part['mail'], 'to' => $part['mail']));
    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('filter' => array('IN', 'id', $ids)));
}
Example #4
0
 public static function mountStruture(&$partID, &$schedulable, $type = false, &$data, &$subject, &$ical, &$part = false, &$method, &$notificationType, $regSet = false)
 {
     if (Config::regGet('ical://' . $schedulable['id'] . '/' . $method) === false || $method == 'CANCEL') {
         //Verifica se o ical ja não esta no reg
         $schedulable['URI']['concept'] = 'schedulable';
         $ical = Controller::format(array('service' => 'iCal'), array($schedulable), array('method' => $method, 'compatible' => true));
         if ($regSet) {
             Config::regSet('ical://' . $schedulable['id'] . '/' . $method, $ical);
         }
     } else {
         $ical = Config::regGet('ical://' . $schedulable['id'] . '/' . $method);
     }
     if (!is_numeric($schedulable['endTime'])) {
         $schedulable['startTime'] = self::parseTimeDate($schedulable['startTime'], $schedulable['timezone']);
     }
     if (!is_numeric($schedulable['endTime'])) {
         $schedulable['endTime'] = self::parseTimeDate($schedulable['endTime'], $schedulable['timezone']);
         if ($schedulable['allDay']) {
             $schedulable['endTime'] = $schedulable['endTime'] + 86400000;
         }
     }
     $timezone = new DateTimeZone('UTC');
     $sTime = new DateTime('@' . (int) ($schedulable['startTime'] / 1000), $timezone);
     $eTime = new DateTime('@' . (int) ($schedulable['endTime'] / 1000), $timezone);
     if (isset($schedulable['timezone'])) {
         $sTime->setTimezone(new DateTimeZone($schedulable['timezone']));
         $eTime->setTimezone(new DateTimeZone($schedulable['timezone']));
     }
     $data = array('startDate' => date_format($sTime, 'd/m/Y'), 'startTime' => $schedulable['allDay'] ? '' : date_format($sTime, 'H:i'), 'endDate' => date_format($eTime, 'd/m/Y'), 'endTime' => $schedulable['allDay'] ? '' : date_format($eTime, 'H:i'), 'eventTitle' => $schedulable['summary'], 'eventLocation' => $schedulable['location'], 'timezone' => $schedulable['timezone'] ? $schedulable['timezone'] : 'UTC');
     $temp = $part;
     $part = false;
     switch ($temp) {
         case 'attendees':
             $attList = '<UL> ';
             foreach ($schedulable['participants'] as $i => $v) {
                 if ($part === false && $v['id'] == $partID) {
                     $part = $v;
                 }
                 $attList .= ' <LI> ' . (isset($v['user']['name']) ? $v['user']['name'] : $v['user']['mail']);
             }
             $attList .= '</UL>';
             $data['participants'] = $attList;
             break;
         case 'me':
             $part = self::_getAttendeeById($partID, $schedulable);
             $data['participant'] = isset($part['user']['name']) ? $part['user']['name'] : $part['user']['mail'];
             $partID = $part;
             break;
         case 'othersAttendees':
             $data['participants'] = '<UL> ';
             foreach ($schedulable['participants'] as $ii => $participant) {
                 if ($participant['isOrganizer'] != '1') {
                     $part[] = $participant['user']['mail'];
                 }
                 $data['participants'] .= ' <LI> ' . (isset($participant['user']['name']) ? $participant['user']['name'] : $participant['user']['mail']);
             }
             break;
     }
     $subject['notificationType'] = $notificationType;
     $subject['eventTitle'] = mb_convert_encoding($schedulable['summary'], 'ISO-8859-1', 'ISO-8859-1,UTF-8');
     $subject['startDate'] = date_format($sTime, 'd/m/Y');
     $subject['startTime'] = $schedulable['allDay'] ? '' : date_format($sTime, 'H:i');
     $subject['endDate'] = date_format($eTime, 'd/m/Y');
     $subject['endTime'] = $schedulable['allDay'] ? '' : date_format($eTime, 'H:i');
     $subject['participant'] = is_array($partID) && isset($partID['user']) ? $partID['user']['uid'] : Config::me('uid');
 }