$concept) { if ($concept['concept'] === 'participant') { if ($concept['method'] == 'create') $created[] = $concept['id']; else if ($concept['method'] == 'update') $updated[] = $concept['id']; } else if ($concept['concept'] === 'schedulable') { //Caso exista schedulable no commit antecipa o carregamento do owner $schedulables[$concept['id']] = Controller::read(array('concept' => 'schedulable', 'id' => $concept['id']), false, array('deepness' => '2')); foreach ($schedulables[$concept['id']]['participants'] as $i => $v) //salva em $organizers as informações do organizador if (($v['isOrganizer'] === '1') && ($organizers[$concept['id']] = $v)) break; }else if ($concept['concept'] === 'schedulableToAttachment') { $relationAttachment = Controller::find(array('concept' => 'schedulableToAttachment'), false, array('filter' => array('=', 'id', $concept['id']))); foreach ($relationAttachment as $key => $value) { if (!array_key_exists('attachments', $schedulables[$value['schedulable']])) $schedulables[$value['schedulable']]['attachments'] = array(); $temp = Controller::find(array('concept' => 'attachment'), false, array('filter' => array('=', 'id', $value['attachment']))); array_push($schedulables[$value['schedulable']]['attachments'], $temp[0]); } } } if (isset($created)) { $psCreated = Controller::find(array('concept' => 'participant'), false, array('deepness' => '1', 'filter' => array('IN', 'id', $created))); foreach ($psCreated as $i => $pCreated) { if ($pCreated['isOrganizer'] == '1') continue; //escapa organizador $schedulable = isset($schedulables[$pCreated['schedulable']]) ? $schedulables[$pCreated['schedulable']] : Controller::read(array('concept' => 'schedulable', 'id' => $pCreated['schedulable']), false, array('deepness' => '2')); if (!self::futureEvent($schedulable['startTime'], $schedulable['rangeEnd'], $schedulable['id'])) continue; //Escapa eventos do passado $organizer = isset($organizers[$pCreated['schedulable']]) ? $organizers[$pCreated['schedulable']] : self::getOrganizer($pCreated['schedulable']); if ($pCreated['delegatedFrom'] != 0) { self::participantDelegated($pCreated, $schedulable, $organizer); continue; } switch ($pCreated['status']) { case STATUS_CONFIRMED: self::participantStatusChange($pCreated['id'], $schedulable, $organizer, STATUS_ACCEPTED); break; case STATUS_UNANSWERED: self::participantCreated($pCreated['id'], $schedulable, false, false, $organizer); break; } } } if (isset($updated)) { $psUpdated = Controller::find(array('concept' => 'participant'), false, array('deepness' => '1', 'filter' => array('IN', 'id', $updated))); foreach ($psUpdated as $i => $pUpdated) { if ($pUpdated['isOrganizer'] == '1') continue; //escapa organizador $schedulable = isset($schedulables[$pUpdated['schedulable']]) ? $schedulables[$pUpdated['schedulable']] : Controller::read(array('concept' => 'schedulable', 'id' => $pUpdated['schedulable']), false, array('deepness' => '2')); if (!self::futureEvent($schedulable['startTime'], $schedulable['rangeEnd'], $schedulable['id'])) continue; //Escapa eventos do passado foreach ($schedulable['participants'] as $i => $v) //salva em $organizer as informações do organizador if (($v['isOrganizer'] === '1') && ($organizer = $v)) break; if ($pUpdated['delegatedFrom'] != 0) { self::participantDelegatedStatusChange($pUpdated, $schedulable, $organizer, $pUpdated['status']); } else if ($pUpdated['status'] != STATUS_UNANSWERED && $pUpdated['status'] != STATUS_DELEGATED) self::participantStatusChange($pUpdated['id'], $schedulable, $organizer, $pUpdated['status']); } } } public function formatSuggestion(&$params) { $schedulable = Controller::read(array('concept' => 'schedulable', 'id' => $params['schedulable']), null, array('deepness' => '2')); foreach ($schedulable['participants'] as $i => $v) //salva em $organizer as informações do organizador if (($v['isOrganizer'] === '1') && ($organizer = $v)) break; $method = 'COUNTER'; $notificationType = 'Sugestão de horário'; $part = 'other'; $schedulableReference = $schedulable; $referenceSuggestion = array('startTime' => strtotime($params['startTime'] . ' ' . $schedulable['timezone']) . '000', 'endTime' => strtotime($params['endTime'] . ' ' . $schedulable['timezone']) . '000', 'allDay' => $params['allDay'] ); $schedulable = array_merge($schedulable, $referenceSuggestion); self::mountStruture(false, $schedulable, false, $data, $subject, $ical, $part, $method, $notificationType); $timezone = new DateTimeZone('UTC'); $sTime = new DateTime('@' . (int) ($schedulableReference['startTime'] / 1000), $timezone); $eTime = new DateTime('@' . (int) ($schedulableReference['endTime'] / 1000), $timezone); if (isset($schedulableReference['timezone'])) { $sTime->setTimezone(new DateTimeZone($schedulableReference['timezone'])); $eTime->setTimezone(new DateTimeZone($schedulableReference['timezone'])); } $data['nowStartDate'] = date_format($sTime, 'd/m/Y'); $data['nowStartTime'] = ($schedulableReference['allDay']) ? '' : date_format($sTime, 'H:i'); $data['nowEndDate'] = date_format($eTime, 'd/m/Y'); $data['nowEndTime'] = ($schedulableReference['allDay']) ? '' : date_format($eTime, 'H:i'); $data['userRequest'] = Config::me('uid'); $ical2 = $ical; $ical2['type'] = 'text/calendar'; $ical2['name'] = 'thunderbird.ics'; $params['attachments'][] = $ical2; $params['attachments'][] = $ical; $params['isHtml'] = true; $params['body'] = parseTPL::load_tpl($data, ROOTPATH . '/modules/calendar/templates/notify_suggestion_body.tpl'); $params['subject'] = parseTPL::load_tpl($subject, ROOTPATH . '/modules/calendar/templates/notify_subject.tpl'); ; $params['from'] = '"' . Config::me('cn') . '" <' . Config::me('mail') . '>'; $params['to'] = $organizer['user']['mail']; } public function formatSuggestionResponse(&$params) { $schedulable = $params['schedulable']; foreach ($schedulable['participants'] as $i => $v) {//salva em $organizer as informações do organizador if ($v['isOrganizer'] === '1') $organizer = $v; if ($v['user']['mail'] == Config::me('mail')) $me = $v; } $method = 'DECLINECOUNTER'; $notificationType = 'Sugestão de horário'; $part = 'other'; $schedulable['participants'] = array(); array_push($schedulable['participants'], $me, $organizer); self::mountStruture(false, $schedulable, false, $data, $subject, $ical, $part, $method, $notificationType); if ($params['status'] == 'DECLINECOUNTER') $data['status'] = 'não pode ser aceito'; $ical2 = $ical; $ical2['type'] = 'text/calendar'; $ical2['name'] = 'thunderbird.ics'; $params['attachments'][] = $ical2; $params['attachments'][] = $ical; $params['isHtml'] = true; $params['body'] = parseTPL::load_tpl($data, ROOTPATH . '/modules/calendar/templates/notify_suggestion_response_body.tpl'); $params['subject'] = parseTPL::load_tpl($subject, ROOTPATH . '/modules/calendar/templates/notify_subject.tpl'); ; $params['to'] = $params['from']; $params['from'] = $params['from'] = '"' . Config::me('cn') . '" <' . Config::me('mail') . '>'; } public static function _getAttendeeById($attendeId, $schedulable) { foreach ($schedulable['participants'] as $id => $dv) if ($dv['id'] == $attendeId) return $dv; } /** * Prepara para criação de email de delegação * * @license http://www.gnu.org/copyleft/gpl.html GPL * @author Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) * @sponsor Caixa Econômica Federal * @author Adriano Coutinho da Silva * @return void * @access public */ public static function participantDelegated(&$partID, &$schedulable, &$organizer) { $delegatedParams = array(); $delegatedFrom = self::_getAttendeeById($partID['delegatedFrom'], $schedulable); $delegatedParams['delegatedFrom'] = $delegatedFrom['user']['uid']; self::participantCreated($partID['id'], $schedulable, STATUS_DELEGATED, $delegatedParams); $delegatedTo = self::_getAttendeeById($partID['id'], $schedulable); $delegatedParams['delegated'] = $delegatedTo['user']['uid']; self::participantStatusChange($partID['delegatedFrom'], $schedulable, $organizer, STATUS_DELEGATED, $delegatedParams); } /** * Monta o email de resposta que sera enviado ao delegatedFrom * * @license http://www.gnu.org/copyleft/gpl.html GPL * @author Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) * @sponsor Caixa Econômica Federal * @author Cristiano Corrêa Schmidt * @return void * @access public */ public static function participantDelegatedStatusChange(&$partID, &$schedulable, $organizer, &$type = false) { $delegatedParams = array(); $delegated = self::_getAttendeeById($partID['id'], $schedulable); $delegatedParams['delegated'] = $delegated['user']['uid']; switch ($partID['status']) { case STATUS_ACCEPTED: $delegatedParams['status'] = 'aceitou'; break; case STATUS_TENTATIVE: $delegatedParams['status'] = 'marcou como tentativa'; break; case STATUS_CANCELLED: $delegatedParams['status'] = 'rejeitou'; break; case STATUS_DELEGATED: $delegatedParams['status'] = 'delegou para um novo participante'; break; } //notifica o organizador a resposta do delegado self::participantStatusChange($partID['delegatedFrom'], $schedulable, $organizer, $type, $delegatedParams); $method = 'REQUEST'; $notificationType = 'Resposta Delegação'; $part = 'attendees'; self::mountStruture($partID['delegatedFrom'], $schedulable, $type, $data, $subject, $ical, $part, $method, $notificationType); $data = array_merge($data, $delegatedParams); self::sendMail($data, $ical, $part['user']['mail'], $subject, 'notify_response_delegated_status_body'); } 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 = ''; $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'] = '