/**
  * Formats any date needed for accessible email.
  *
  * @param int $dateParam             timestamp int.
  * @param boolean $setCompleteFormat specify a format.
  * @return string                    formatted date.
  */
 public static function getFormattedDate($dateParam, $setCompleteFormat = false)
 {
     if (!isset($dateParam) || !is_int($dateParam)) {
         return '';
     }
     $timeReceived = date('H:i', $dateParam);
     $dayReceived = date('d/m/Y', $dateParam);
     $weekDayReceived = DateUtils::getWeekdayName($dateParam);
     if ($setCompleteFormat) {
         return $weekDayReceived . ', ' . $dayReceived . ', ' . $timeReceived;
     }
     if ($dateParam >= strtotime('today 00:00')) {
         return date('\\h\\o\\j\\e, H:i', $dateParam);
     } else {
         if ($dateParam >= strtotime('yesterday 00:00')) {
             return 'ontem, ' . $timeReceived;
         } else {
             if ($dateParam >= strtotime('-6 day 00:00')) {
                 return $weekDayReceived . ', ' . $timeReceived;
             } else {
                 return date('d/m/Y', $dateParam);
             }
         }
     }
 }
 /**
  * @see Accessible\Handler::execute
  */
 public function execute($params)
 {
     $liteRequestProcessor = new LiteRequestProcessor();
     $message = $liteRequestProcessor->executeRequest('GetMessage', (object) array('id' => $params->messageId));
     $markAsRead = $liteRequestProcessor->executeRequest('MarkAsRead', (object) array('ids' => $params->messageId, 'asRead' => '1'));
     if ($message->subject == '') {
         $message->subject = '(sem assunto)';
     }
     $attachments = $this->formatAttachments($message->attachments, $params->messageId);
     $this->showTemplate('OpenMessageTemplate', (object) array('folderName' => $params->folderName, 'message' => $message, 'bodyMessage' => MessageUtils::getSanitizedBodyContent($message->body->message), 'quotedMessage' => MessageUtils::getSanitizedBodyContent($message->body->quoted), 'formattedDate' => DateUtils::getFormattedDate(strtotime($message->received), true), 'page' => $params->page, 'lnkBack' => $this->makeUrl('Mail.Main', array('folderId' => $params->folderId, 'page' => $params->page)), 'lnkDelete' => $this->makeUrl('Mail.DeleteMessage', array('folderName' => $params->folderName, 'messageIds' => $params->messageId, 'folderId' => $params->folderId)), 'lnkMark' => $this->makeUrl('Mail.MarkMessageAsUnread', array('folderName' => $params->folderName, 'messageIds' => $params->messageId, 'folderId' => $params->folderId)), 'lnkReply' => $this->makeUrl('Mail.ComposeMessage', array('folderId' => $params->folderId, 'folderName' => $params->folderName, 'page' => $params->page, 'messageId' => $params->messageId, 'reply' => 'yes', 'attachments' => urlencode(json_encode($attachments)))), 'lnkReplyAll' => $this->makeUrl('Mail.ComposeMessage', array('folderId' => $params->folderId, 'folderName' => $params->folderName, 'page' => $params->page, 'messageId' => $params->messageId, 'replyAll' => 'yes', 'attachments' => urlencode(json_encode($attachments)))), 'lnkForward' => $this->makeUrl('Mail.ComposeMessage', array('folderId' => $params->folderId, 'folderName' => $params->folderName, 'page' => $params->page, 'messageId' => $params->messageId, 'forward' => 'yes', 'attachments' => urlencode(json_encode($attachments)))), 'attachmentsForExhibition' => $attachments, 'lnkMoveMsgToFolder' => $this->makeUrl('Mail.OpenFolder', array('folderId' => $params->folderId, 'folderName' => $params->folderName, 'page' => $params->page, 'messageIds' => $params->messageId, 'isMsgBeingMoved' => true))));
 }
 /**
  * Check whether an event has not occurred.
  *
  * @param string $strTime Information about date and time in the following
  *                        format '2016-01-30 01:50'
  * @return boolean True if the event has not occurred, false otherwise
  */
 public static function checkEventHasNotOccurred($strTime)
 {
     return DateUtils::compareToCurrentDate($strTime);
 }
 /**
  * Returns an array containing headlines information and links for actions
  *
  * @param string $curFolder
  * @param int $curPage The current page of headlines pagination
  * @return array of headlines
  */
 private function retrieveHeadlines($curFolder, $curPage)
 {
     $liteRequestProcessor = new LiteRequestProcessor();
     $headlines = $liteRequestProcessor->executeRequest('SearchHeadlines', (object) array('folderIds' => $curFolder->id, 'start' => ($curPage - 1) * self::REQUEST_LIMIT, 'limit' => self::REQUEST_LIMIT));
     foreach ($headlines as &$headl) {
         $headl->received = DateUtils::getFormattedDate($headl->received);
         $headl->subject = trim($headl->subject);
         if ($headl->subject === '') {
             $headl->subject = '(sem assunto)';
         }
         $headl->lnkOpen = $this->makeUrl('Mail.OpenMessage', array('messageId' => $headl->id, 'folderId' => $curFolder->id, 'folderName' => $curFolder->localName, 'page' => $curPage));
     }
     return $headlines;
 }
 /**
  * Format links for calendar navigation.
  *
  * @param int $calendarId The id of the current calendar in use
  * @param array $eventDateRange An array of prepared event date range objects
  * @return array Formatted link objects to calendar navigation, each element
  *               contains a link to navigate through calendar (->lnk), the text
  *               of the link (->lnkText) and a title for the link (->lnkTitle)
  */
 private function formatCalendarNavigationLinks($calendarId, $eventDateRange)
 {
     $calendarNavigationLinks = array();
     // Formatting links
     foreach ($eventDateRange as $edr) {
         $monthName = DateUtils::getMonthName($edr->month);
         $calendarNavigationLinks[] = (object) array('lnk' => $this->makeUrl('Calendar.Main', array('month' => $edr->month, 'year' => $edr->year, 'calendarId' => $calendarId)), 'lnkText' => $edr->order . ' - ' . $monthName . ' de ' . $edr->year, 'lnkTitle' => EventUtils::EVENTS_CALENDAR_NAME . ' de ' . $monthName . ' de ' . $edr->year);
     }
     return $calendarNavigationLinks;
 }
 /**
  * Format information about a particular calendar event to be viewed.
  *
  * @param stdClass $event The Event object
  * @return stdClass An object containning formatted event information like date (->date),
  *                  time (->schedule), the organizer's name (->organizerName), organization
  *                  unit and region (->orgUnitRegion), the total count of attendees
  *                  (->countAttendees), the list of attendees (->attendees), the event's
  *                  summary (->summary) and the description about the event (->description)
  */
 private function formatEventInformation($event)
 {
     $fromInfo = DateUtils::getInfomationAboutDate($event->from);
     $untilInfo = DateUtils::getInfomationAboutDate($event->until);
     return (object) array('schedule' => $fromInfo->timeVal . ' às ' . $untilInfo->timeVal, 'date' => $fromInfo->weekdayName . ', ' . $fromInfo->dayVal . ' de ' . $fromInfo->monthName . ' de ' . $fromInfo->yearVal . '.', 'attendees' => $event->attendees, 'organizerName' => $event->organizer->name, 'organizerOrgUnitRegion' => $event->organizer->orgUnit . ', ' . $event->organizer->region, 'summary' => empty($event->summary) ? EventUtils::EVENTS_WITHOUT_SUMMARY : $event->summary, 'location' => empty($event->location) ? EventUtils::EVENTS_WITHOUT_LOCATION : $event->location, 'description' => empty($event->description) ? EventUtils::EVENTS_WITHOUT_DESCRIPTION : nl2br($event->description));
 }