Example #1
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;
 }