示例#1
0
 /**
  * Returns a Connector to either MailBox or Internal Drafts
  * @param String $folder - Name of the folder
  * @return MailManager_Connector
  */
 protected function getConnector($folder = '')
 {
     if (!$this->mConnector || $this->mFolder != $folder) {
         if ($folder == "__vt_drafts") {
             $draftController = new MailManager_Draft_View();
             $this->mConnector = $draftController->connectorWithModel();
         } else {
             if ($this->mConnector) {
                 $this->mConnector->close();
             }
             $model = $this->getMailboxModel();
             $this->mConnector = MailManager_Connector_Connector::connectorWithModel($model, $folder);
         }
         $this->mFolder = $folder;
     }
     return $this->mConnector;
 }
示例#2
0
 /**
  * Process the request for Folder opertions
  * @global <type> $maxEntriesPerPage
  * @param Vtiger_Request $request
  * @return MailManager_Response
  */
 public function process(Vtiger_Request $request)
 {
     $currentUserModel = Users_Record_Model::getCurrentUserModel();
     $maxEntriesPerPage = vglobal('list_max_entries_per_page');
     $response = new Vtiger_Response();
     $moduleName = $request->getModule();
     if ('open' == $this->getOperationArg($request)) {
         $q = $request->get('q');
         $foldername = $request->get('_folder');
         $type = $request->get('type');
         $connector = $this->getConnector($foldername);
         $folder = $connector->folderInstance($foldername);
         if (empty($q)) {
             $connector->folderMails($folder, intval($request->get('_page', 0)), $maxEntriesPerPage);
         } else {
             if (empty($type)) {
                 $type = 'ALL';
             }
             if ($type == 'ON') {
                 $dateFormat = $currentUserModel->get('date_format');
                 if ($dateFormat == 'mm-dd-yyyy') {
                     $dateArray = explode('-', $q);
                     $temp = $dateArray[0];
                     $dateArray[0] = $dateArray[1];
                     $dateArray[1] = $temp;
                     $q = implode('-', $dateArray);
                 }
                 $query = date('d M Y', strtotime($q));
                 $q = '' . $type . ' "' . vtlib_purify($query) . '"';
             } else {
                 $q = '' . $type . ' "' . vtlib_purify($q) . '"';
             }
             $connector->searchMails($q, $folder, intval($request->get('_page', 0)), $maxEntriesPerPage);
         }
         $folderList = $connector->getFolderList();
         $viewer = $this->getViewer($request);
         $viewer->assign('TYPE', $type);
         $viewer->assign('QUERY', $request->get('q'));
         $viewer->assign('FOLDER', $folder);
         $viewer->assign('FOLDERLIST', $folderList);
         $viewer->assign('SEARCHOPTIONS', self::getSearchOptions());
         $viewer->assign("JS_DATEFORMAT", parse_calendardate(getTranslatedString('NTC_DATE_FORMAT')));
         $viewer->assign('USER_DATE_FORMAT', $currentUserModel->get('date_format'));
         $viewer->assign('MODULE', $moduleName);
         $response->setResult($viewer->view('FolderOpen.tpl', $moduleName, true));
     } elseif ('drafts' == $this->getOperationArg($request)) {
         $q = $request->get('q');
         $type = $request->get('type');
         $page = intval($request->get('_page', 0));
         $connector = $this->getConnector('__vt_drafts');
         $folder = $connector->folderInstance();
         if (empty($q)) {
             $draftMails = $connector->getDrafts($page, $maxEntriesPerPage, $folder);
         } else {
             $draftMails = $connector->searchDraftMails($q, $type, $page, $maxEntriesPerPage, $folder);
         }
         $viewer = $this->getViewer($request);
         $viewer->assign('MAILS', $draftMails);
         $viewer->assign('FOLDER', $folder);
         $viewer->assign('SEARCHOPTIONS', MailManager_Draft_View::getSearchOptions());
         $viewer->assign('USER_DATE_FORMAT', $currentUserModel->get('date_format'));
         $viewer->assign('MODULE', $moduleName);
         $response->setResult($viewer->view('FolderDrafts.tpl', 'MailManager', true));
     } else {
         if ('getFoldersList' == $this->getOperationArg($request)) {
             $viewer = $this->getViewer($request);
             if ($this->hasMailboxModel()) {
                 $connector = $this->getConnector();
                 if (!$connector->hasError()) {
                     $folders = $connector->folders();
                     $connector->updateFolders();
                     $viewer->assign('FOLDERS', $folders);
                 }
                 $this->closeConnector();
             }
             $viewer->assign('MODULE', $request->getModule());
             $response->setResult($viewer->view('FolderList.tpl', $moduleName, true));
         }
     }
     return $response;
 }