/**
  * @see Accessible\Handler::execute
  */
 public function execute($params)
 {
     $lrp = new LiteRequestProcessor();
     // Gets personals and shared calendars
     $calendars = $lrp->executeRequest('GetCalendars', (object) array());
     $this->showTemplate('OpenCalendarTemplate', (object) array('calendars' => self::formatCalendarTree($calendars, $params), 'lnkBack' => $this->makeUrl('Calendar.Main', array('calendarId' => $params->calendarId, 'month' => $params->month, 'years' => $params->year))));
 }
 /**
  * @see ExpressoLite\Backend\Request\LiteRequest::execute
  */
 public function execute()
 {
     if (!$this->isParamSet('user') || !$this->isParamSet('pwd')) {
         $this->httpError(400, 'É necessário informar login e senha.');
     }
     try {
         $this->resetTineSession();
         $result = $this->tineSession->login($this->param('user'), $this->param('pwd'), $this->isParamSet('captcha') ? $this->param('captcha') : null);
     } catch (PasswordExpiredException $pe) {
         return (object) array('success' => false, 'expired' => true);
     } catch (CaptchaRequiredException $cre) {
         return (object) array('success' => false, 'captcha' => $cre->getCaptcha());
     }
     if ($result) {
         $cookiePath = str_replace('accessible/', '', $_SERVER['REQUEST_URI']);
         //we remove 'accessible/' suffix from current path.
         //This way, the cookie will always be set to all modules,
         //even if it was started by the accessible module
         setrawcookie('user', $this->param('user'), time() + 60 * 60 * 24 * 30, $cookiePath);
         $_COOKIE['user'] = $this->param('user');
         //setrawcookie() does not update the $_COOKIE array with the new cookie.
         //So, we do this manually to avoid problems with checkIfSessionUserIsValid
         //later on
     }
     $this->checkIfSessionUserIsValid();
     // Its better to check if the tine user matches Expresso Lite user
     // right away
     $lrp = new LiteRequestProcessor();
     $userInfoData = $lrp->executeRequest('GetUserInfo');
     return (object) array('success' => $result, 'userInfo' => $userInfoData);
 }
 /**
  * @see ExpressoLite\Backend\Request\LiteRequest::execute
  */
 public function execute($params)
 {
     $liteRequestProcessor = new LiteRequestProcessor();
     $message = $liteRequestProcessor->executeRequest('MoveMessages', (object) array('folder' => $params->folderId, 'messages' => $params->messageIds));
     $outMsg = count(explode(',', $params->messageIds)) > 1 ? count(explode(',', $params->messageIds)) . ' mensagens movidas para a pasta ' . $params->folderName . ' com sucesso.' : count(explode(',', $params->messageIds)) . ' mensagem movida para a pasta ' . $params->folderName . ' com sucesso.';
     Dispatcher::processRequest('Core.ShowFeedback', (object) array('typeMsg' => ShowFeedback::MSG_SUCCESS, 'message' => $outMsg, 'destinationText' => 'Voltar para ' . $params->currentFolderName, 'destinationUrl' => (object) array('action' => 'Mail.Main', 'params' => array('folderId' => $params->currentFolderId))));
 }
 /**
  * @see Accessible\Handler::execute
  */
 public function execute($params)
 {
     if (TineSessionRepository::getTineSession()->isLoggedIn()) {
         $liteRequestProcessor = new LiteRequestProcessor();
         $liteRequestProcessor->executeRequest('Logoff', (object) array());
     }
     Dispatcher::processRequest('Core.ShowFeedback', (object) array('typeMsg' => ShowFeedback::MSG_SUCCESS, 'message' => 'Saída realizada com sucesso.', 'destinationText' => 'Acessar a página de login', 'destinationUrl' => (object) array('action' => 'Login.Main')));
 }
 /**
  * @see Accessible\Handler::execute
  */
 public function execute($params)
 {
     $liteRequestProcessor = new LiteRequestProcessor();
     $response = $liteRequestProcessor->executeRequest('SearchFolders', (object) array('recursive' => true));
     $folders = $this->flatFolderTree($response, $params);
     TineSessionRepository::getTineSession()->setAttribute('folders', $folders);
     $this->showTemplate('OpenFolderTemplate', (object) array('folders' => $folders, 'folderName' => $params->folderName, 'lnkRefreshFolder' => $this->makeUrl('Mail.Main', array('folderName' => $params->folderName, 'folderId' => $params->folderId, 'page' => $params->page)), 'lnkRefreshMessage' => $this->makeUrl('Mail.OpenMessage', array('folderName' => $params->folderName, 'folderId' => $params->folderId, 'page' => $params->page, 'messageId' => isset($params->messageIds) ? $params->messageIds : '')), 'isMsgBeingMoved' => isset($params->isMsgBeingMoved) ? true : false));
 }
 /**
  * @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))));
 }
 /**
  * @see Accessible\Handler::execute
  */
 public function execute($params)
 {
     // Retrieve original message, if replying or forwarding.
     if (isset($params->reply) || isset($params->replyAll) || isset($params->forward)) {
         $lrp = new LiteRequestProcessor();
         $msg = $lrp->executeRequest('GetMessage', (object) array('id' => $params->messageId));
     } else {
         $msg = null;
         // compose new mail, not reply/forward
     }
     $this->showTemplate('ComposeMessageTemplate', (object) array('folderId' => $params->folderId, 'folderName' => $params->folderName, 'page' => isset($params->page) ? $params->page : '1', 'actionText' => $this->actionText($params), 'subject' => $this->formatSubject($params, $msg), 'to' => isset($params->reply) || isset($params->replyAll) ? $msg->from_email : '', 'cc' => isset($params->replyAll) ? $this->formatCcAddresses($params, $msg) : '', 'replyToId' => isset($params->reply) || isset($params->replyAll) ? $params->messageId : '', 'forwardFromId' => isset($params->forward) ? $params->messageId : '', 'signature' => TineSessionRepository::getTineSession()->getAttribute('Expressomail.signature'), 'quotedBody' => $this->prepareQuotedMessage($params, $msg), 'lnkBackText' => isset($params->reply) || isset($params->replyAll) || isset($params->forward) ? 'mensagem de origem' : $params->folderName, 'lnkBackUrl' => $this->returnLink($params), 'lnkSendMessageAction' => $this->makeUrl('Mail.SendMessage'), 'existingAttachments' => isset($params->attachments) ? json_decode($params->attachments) : array()));
 }
 /**
  * @see Accessible\Handler::execute
  */
 public function execute($params)
 {
     $user = $params->user;
     $password = $params->pwd;
     $liteRequestProcessor = new LiteRequestProcessor();
     $response = $liteRequestProcessor->executeRequest('Login', (object) array('user' => $user, 'pwd' => $password));
     if ($response->success === true) {
         Dispatcher::processRequest('Mail.Main', $params);
     } else {
         Dispatcher::processRequest('Core.ShowFeedback', (object) array('typeMsg' => ShowFeedback::MSG_ERROR, 'message' => 'Login falhou! Usuário ou senha inválidos.', 'destinationText' => 'Voltar para página de login', 'destinationUrl' => (object) array('action' => 'Login.Main')));
     }
 }
 /**
  * Retrieve the calendar event object.
  *
  * @param stdClass $params Contains the request's parameters to calendar module. The information
  *                         about date and time in from value (->from) and until value (->until);
  *                         also, it must be informed the id of the current calendar (->calendarId)
  * @return stdClass The Event object if it possible to retrieve the event data, null otherwise
  */
 private function retrieveCalendarEvent($params)
 {
     $foundEvent = null;
     $liteRequestProcessor = new LiteRequestProcessor();
     $message = $liteRequestProcessor->executeRequest('SearchEvents', (object) array('from' => $params->from, 'until' => $params->until, 'calendarId' => $params->calendarId, 'timeZone' => TineSessionRepository::getTineSession()->getAttribute('Tinebase.timeZone')));
     foreach ($message->events as $event) {
         if ($params->idEvent === $event->id) {
             $foundEvent = $event;
             break;
         }
     }
     return $foundEvent;
 }
 /**
  * @see Accessible\Handler::execute
  */
 public function execute($params)
 {
     $liteRequestProcessor = new LiteRequestProcessor();
     $message = $liteRequestProcessor->executeRequest('setEventConfirmation', (object) array('id' => $params->idEvent, 'confirmation' => $params->confirmation));
     if (isset($message->eventId) && isset($message->confirmation)) {
         $outMsg = 'Confirmação de evento realizada com sucesso.';
         $feedbackType = ShowFeedback::MSG_SUCCESS;
     } else {
         $outMsg = 'Não foi possível realizar a confirmação do evento.';
         $feedbackType = ShowFeedback::MSG_SUCCESS;
     }
     Dispatcher::processRequest('Core.ShowFeedback', (object) array('typeMsg' => $feedbackType, 'message' => $outMsg, 'destinationText' => 'Voltar para o evento', 'destinationUrl' => (object) array('action' => 'Calendar.OpenEvent', 'params' => array('from' => $params->from, 'until' => $params->until, 'idEvent' => $params->idEvent, 'calendarId' => $params->calendarId, 'monthVal' => $params->month, 'yearVal' => $params->year))));
 }
 /**
  * @see Accessible\Handler::execute
  */
 public function execute($params)
 {
     $liteRequestProcessor = new LiteRequestProcessor();
     $response = $liteRequestProcessor->executeRequest('EmptyTrash', (object) array('trashId' => $params->folderId));
     if ($response->status) {
         $typeMsg = ShowFeedback::MSG_SUCCESS;
         $feedbackMsg = self::EMPTY_TRASH_SUCCESS;
     } else {
         $typeMsg = ShowFeedback::MSG_ERROR;
         $feedbackMsg = $response->message;
     }
     Dispatcher::processRequest('Core.ShowFeedback', (object) array('typeMsg' => $typeMsg, 'message' => $feedbackMsg, 'destinationText' => 'Voltar para ' . $params->folderName, 'destinationUrl' => (object) array('action' => 'Mail.Main', 'params' => array('folderId' => $params->folderId, 'page' => 1))));
 }
 public function execute($params)
 {
     $folders = TineSessionRepository::getTineSession()->getAttribute('folders');
     $isTrashFolder = FALSE;
     foreach ($folders as $fol) {
         if ($fol->id === $params->folderId) {
             $isTrashFolder = $fol->globalName === self::TRASH_FOLDER;
             break;
         }
     }
     $liteRequestProcessor = new LiteRequestProcessor();
     $message = $liteRequestProcessor->executeRequest('DeleteMessages', (object) array('messages' => $params->messageIds, 'forever' => $isTrashFolder ? '1' : '0'));
     $outMsg = $this->getFormattedFeedbackMsg($params->messageIds, $isTrashFolder);
     Dispatcher::processRequest('Core.ShowFeedback', (object) array('typeMsg' => ShowFeedback::MSG_SUCCESS, 'message' => $outMsg, 'destinationText' => 'Voltar para ' . $params->folderName, 'destinationUrl' => (object) array('action' => 'Mail.Main', 'params' => array('folderId' => $params->folderId))));
 }
 /**
  * @see Accessible\Handler::execute
  */
 public function execute($params)
 {
     if ($params->messageIds === '') {
         // No message id was specified
         $typeMsg = ShowFeedback::MSG_ERROR;
         $outMsg = 'Não foi possível marcar mensagem como não lida';
     } else {
         $liteRequestProcessor = new LiteRequestProcessor();
         $message = $liteRequestProcessor->executeRequest('MarkAsRead', (object) array('ids' => $params->messageIds, 'asRead' => '0'));
         $typeMsg = ShowFeedback::MSG_SUCCESS;
         $msgCount = MessageIds::messageCount($params->messageIds);
         $outMsg = $msgCount == 1 ? '1 mensagem marcada como não lida com sucesso.' : "{$msgCount} mensagens marcadas como não lida com sucesso.";
     }
     Dispatcher::processRequest('Core.ShowFeedback', (object) array('typeMsg' => $typeMsg, 'message' => $outMsg, 'destinationText' => 'Voltar para ' . $params->folderName, 'destinationUrl' => (object) array('action' => 'Mail.Main', 'params' => array('folderId' => $params->folderId))));
 }
 /**
  * @see Accessible\Handler::execute
  */
 public function execute($params)
 {
     // Treat uploaded files, if any.
     $upFiles = array();
     foreach ($_FILES as $upf) {
         $processed = $this->uploadFile($upf);
         if ($processed !== null) {
             $upFiles[] = $processed;
         }
     }
     // Retrieve original message, if replying or forwarding.
     $lrp = new LiteRequestProcessor();
     if (!empty($params->replyToId) || !empty($params->forwardFromId)) {
         $msg = $lrp->executeRequest('GetMessage', (object) array('id' => !empty($params->replyToId) ? $params->replyToId : $params->forwardFromId));
     } else {
         $msg = null;
         // compose new mail, not reply/forward
     }
     $lrp->executeRequest('SaveMessage', (object) array('subject' => $params->subject, 'body' => $this->prepareMessageBody($params, $msg), 'to' => $params->addrTo, 'cc' => $params->addrCc, 'bcc' => $params->addrBcc, 'isImportant' => isset($params->important) ? '1' : '0', 'attachs' => empty($upFiles) && (!is_null($msg) && !$msg->has_attachment) ? '' : $this->formatAllAttachs($params, $msg, $upFiles), 'replyToId' => $params->replyToId, 'forwardFromId' => $params->forwardFromId, 'origDraftId' => ''));
     Dispatcher::processRequest('Core.ShowFeedback', (object) array('typeMsg' => ShowFeedback::MSG_SUCCESS, 'message' => 'Mensagem enviada com sucesso.', 'destinationText' => 'Voltar para ' . $params->folderName, 'destinationUrl' => (object) array('action' => 'Mail.Main', 'params' => array('folderId' => $params->folderId, 'page' => $params->page))));
 }
 /**
  * Processes an AJAX request and outputs its response.
  * $httpRequest['r'] will
  * be considered the request name, and other $httpRequest entries the request
  * parameters.
  *
  * @param $httpRequest Should
  *            always be $_REQUEST
  *
  */
 public function processHttpRequest($httpRequest)
 {
     if (!isset($httpRequest['r'])) {
         $this->echoResult($this->createHttpError(400, 'request function [\'r\'] is not defined'));
     } else {
         $requestName = $httpRequest['r'];
         $params = $this->getParamsFromHttpRequest($httpRequest);
         try {
             $liteRequestProcessor = new LiteRequestProcessor();
             $result = $liteRequestProcessor->executeRequest($requestName, $params);
         } catch (LiteException $le) {
             $result = $this->createHttpError($le->getHttpCode(), $le->getMessage());
         } catch (Exception $e) {
             $msg = "Error executing {$requestName}. Message: " . $e->getMessage();
             $result = $this->createHttpError(500, $msg);
             error_log($msg);
             // TODO: improve exception logging
             // Important: DO NOT PRINT THE STACK TRACE HERE, as it may include
             // sensible user information (password, for instance)
         }
         $this->echoResult($result);
     }
 }
 /**
  * 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;
 }
 /**
  * Returns an ordered listing of events according to the provided events
  * date range and to the currently selected user calendar.
  *
  * @param string $calendarId Current calendar to be used
  * @param StdClass $currDateRange Formatted date range with month and year values
  *                                to use as the event date range
  * @return StdClass Event listing content (->listing) and a boolean (->hasEvents)
  *                  indicating whether or not there are calendar events
  */
 private function getEventListing($calendarId, $currDateRange)
 {
     // Setting properly the correct timezone based on login user timezone
     $timeZone = TineSessionRepository::getTineSession()->getAttribute('Tinebase.timeZone');
     $lrp = new LiteRequestProcessor();
     $preparedEventDateRange = EventUtils::prepareEventsDateRange($currDateRange);
     $message = $lrp->executeRequest('SearchEvents', (object) array('from' => $preparedEventDateRange->from, 'until' => $preparedEventDateRange->until, 'timeZone' => $timeZone, 'calendarId' => $calendarId));
     // Sorts the event list comparing each event start time (->from)
     usort($message->events, function ($e1, $e2) {
         return strcmp($e1->from, $e2->from);
     });
     return (object) array('hasEvents' => count($message->events) > 0, 'listing' => (object) $message->events);
 }