/**
  * Function to get the list view entries
  * @param Vtiger_Paging_Model $pagingModel
  * @return <Array> - Associative array of record id mapped to Vtiger_Record_Model instance.
  */
 public function getListViewEntries($pagingModel)
 {
     $db = PearDatabase::getInstance();
     $startIndex = $pagingModel->getStartIndex();
     $pageLimit = $pagingModel->getPageLimit();
     $orderBy = $this->getForSql('orderby');
     $sortOrder = $this->getForSql('sortorder');
     $listQuery = $this->getQuery();
     $searchKey = $this->get('search_key');
     $searchValue = $this->get('search_value');
     if (!empty($searchKey) && !empty($searchValue)) {
         $listQuery .= " WHERE {$searchKey} LIKE '{$searchValue}%'";
     }
     if ($orderBy) {
         $listQuery .= " ORDER BY {$orderBy} {$sortOrder}";
     }
     $listQuery .= " LIMIT {$startIndex}," . ($pageLimit + 1);
     $result = $db->pquery($listQuery, array());
     $num_rows = $db->num_rows($result);
     $listViewRecordModels = array();
     for ($i = 0; $i < $num_rows; $i++) {
         $recordModel = new EmailTemplates_Record_Model();
         $recordModel->setModule('EmailTemplates');
         $row = $db->query_result_rowdata($result, $i);
         $listViewRecordModels[$row['templateid']] = $recordModel->setData($row);
     }
     $pagingModel->calculatePageRange($listViewRecordModels);
     if ($num_rows > $pageLimit) {
         array_pop($listViewRecordModels);
         $pagingModel->set('nextPageExists', true);
     } else {
         $pagingModel->set('nextPageExists', false);
     }
     return $listViewRecordModels;
 }
 /**
  * Function to get the instance
  * @param <String> $moduleName - module name
  * @param <String> $recordId - record id
  * @return <Vtiger_DetailView_Model>
  */
 public static function getInstance($moduleName, $recordId)
 {
     $modelClassName = Vtiger_Loader::getComponentClassName('Model', 'DetailView', $moduleName);
     $instance = new $modelClassName();
     $moduleModel = EmailTemplates_Module_Model::getInstance($moduleName);
     $recordModel = EmailTemplates_Record_Model::getInstanceById($recordId, $moduleName);
     return $instance->setModule($moduleModel)->setRecord($recordModel);
 }
Beispiel #3
0
 /**
  * Funtioin to process the Edit view
  * @param Vtiger_Request $request
  */
 public function process(Vtiger_Request $request)
 {
     $viewer = $this->getViewer($request);
     $moduleName = $request->getModule();
     $record = $request->get('record');
     if (!empty($record)) {
         $recordModel = EmailTemplates_Record_Model::getInstanceById($record);
         $viewer->assign('RECORD_ID', $record);
         $viewer->assign('MODE', 'edit');
     } else {
         $recordModel = new EmailTemplates_Record_Model();
         $viewer->assign('MODE', '');
         $recordModel->set('templatename', '');
         $recordModel->set('description', '');
         $recordModel->set('subject', '');
         $recordModel->set('body', '');
     }
     $recordModel->setModule('EmailTemplates');
     if (!$this->record) {
         $this->record = $recordModel;
     }
     $allFiledsOptions = $this->record->getEmailTemplateFields();
     $moduleModel = $recordModel->getModule();
     $viewer->assign('RECORD', $this->record);
     $viewer->assign('MODULE', $moduleName);
     $viewer->assign('BLOCK_LIST', $moduleModel->getBlocks());
     $viewer->assign('CURRENTDATE', date('Y-n-j'));
     $viewer->assign('USER_MODEL', Users_Record_Model::getCurrentUserModel());
     $viewer->assign('ALL_FIELDS', $allFiledsOptions);
     $viewer->view('EditView.tpl', $moduleName);
 }
Beispiel #4
0
 public function process(Vtiger_Request $request)
 {
     $moduleName = $request->getModule();
     $record = $request->get('record');
     $recordModel = new EmailTemplates_Record_Model();
     $recordModel->setModule($moduleName);
     if (!empty($record)) {
         $recordModel->setId($record);
     }
     $recordModel->set('templatename', $request->get('templatename'));
     $recordModel->set('description', $request->get('description'));
     $recordModel->set('subject', $request->get('subject'));
     $recordModel->set('body', $request->get('templatecontent'));
     $recordModel->save();
     $loadUrl = $recordModel->getDetailViewUrl();
     header("Location: {$loadUrl}");
 }
Beispiel #5
0
 function process(Vtiger_Request $request)
 {
     $moduleName = $request->getModule();
     $record = $request->get('record');
     $viewer = $this->getViewer($request);
     $recordModel = EmailTemplates_Record_Model::getInstanceById($record);
     $recordModel->setModule($moduleName);
     $viewer->assign('RECORD', $recordModel);
     $viewer->assign('USER_MODEL', Users_Record_Model::getCurrentUserModel());
     $viewer->assign('MODULE_NAME', $moduleName);
     $viewer->view('DetailViewFullContents.tpl', $moduleName);
 }
Beispiel #6
0
 public function process(Vtiger_Request $request)
 {
     $moduleName = $request->getModule();
     $recordId = $request->get('record');
     $recordModel = EmailTemplates_Record_Model::getInstanceById($recordId);
     $recordModel->setModule($moduleName);
     $recordModel->delete();
     $cvId = $request->get('viewname');
     $response = new Vtiger_Response();
     $response->setResult(array('viewname' => $cvId, 'module' => $moduleName));
     $response->emit();
 }
Beispiel #7
0
 public function process(Vtiger_Request $request)
 {
     $moduleName = $request->getModule();
     $recordId = $request->get('record');
     $ajaxDelete = $request->get('ajaxDelete');
     $recordModel = EmailTemplates_Record_Model::getInstanceById($recordId);
     $moduleModel = $recordModel->getModule();
     $recordModel->delete($recordId);
     $listViewUrl = $moduleModel->getListViewUrl();
     if ($ajaxDelete) {
         $response = new Vtiger_Response();
         $response->setResult($listViewUrl);
         return $response;
     } else {
         header("Location: {$listViewUrl}");
     }
 }
Beispiel #8
0
 public function process(Vtiger_Request $request)
 {
     $moduleName = $request->getModule();
     $recordModel = new EmailTemplates_Record_Model();
     $recordModel->setModule($moduleName);
     $selectedIds = $request->get('selected_ids');
     $excludedIds = $request->get('excluded_ids');
     if ($selectedIds == 'all' && empty($excludedIds)) {
         $recordModel->deleteAllRecords();
     } else {
         $recordIds = $this->getRecordsListFromRequest($request, $recordModel);
         foreach ($recordIds as $recordId) {
             $recordModel = EmailTemplates_Record_Model::getInstanceById($recordId);
             $recordModel->delete();
         }
     }
     $response = new Vtiger_Response();
     $response->setResult(array('module' => $moduleName));
     $response->emit();
 }
Beispiel #9
0
 /**
  * Function to get the list view entries
  * @param Vtiger_Paging_Model $pagingModel
  * @return <Array> - Associative array of record id mapped to Vtiger_Record_Model instance.
  */
 public function getListViewEntries($pagingModel)
 {
     $db = PearDatabase::getInstance();
     $startIndex = $pagingModel->getStartIndex();
     $pageLimit = $pagingModel->getPageLimit();
     $orderBy = $this->getForSql('orderby');
     $sortOrder = $this->getForSql('sortorder');
     $listQuery = $this->getQuery();
     $searchKey = $this->get('search_key');
     $searchValue = $this->get('search_value');
     if (!empty($searchKey) && !empty($searchValue)) {
         $listQuery .= " WHERE {$searchKey} LIKE '{$searchValue}%'";
     }
     if (!empty($orderBy) && $orderBy === 'smownerid') {
         $fieldModel = Vtiger_Field_Model::getInstance('assigned_user_id', $moduleModel);
         if ($fieldModel->getFieldDataType() == 'owner') {
             $orderBy = 'COALESCE(CONCAT(vtiger_users.first_name,vtiger_users.last_name),vtiger_groups.groupname)';
         }
     }
     if ($orderBy) {
         $listQuery .= " ORDER BY {$orderBy} {$sortOrder}";
     }
     $listQuery .= " LIMIT {$startIndex}," . ($pageLimit + 1);
     $result = $db->pquery($listQuery, array());
     $num_rows = $db->num_rows($result);
     $listViewRecordModels = array();
     for ($i = 0; $i < $num_rows; $i++) {
         $recordModel = new EmailTemplates_Record_Model();
         $recordModel->setModule('EmailTemplates');
         $row = $db->query_result_rowdata($result, $i);
         $listViewRecordModels[$row['templateid']] = $recordModel->setData($row);
     }
     $pagingModel->calculatePageRange($listViewRecordModels);
     if ($num_rows > $pageLimit) {
         array_pop($listViewRecordModels);
         $pagingModel->set('nextPageExists', true);
     } else {
         $pagingModel->set('nextPageExists', false);
     }
     return $listViewRecordModels;
 }
Beispiel #10
0
 /**
  * Function to delete the email template
  * @param type $recordIds
  */
 public function deleteRecord(EmailTemplates_Record_Model $recordModel)
 {
     $recordId = $recordModel->getId();
     $db = PearDatabase::getInstance();
     $db->pquery('DELETE FROM vtiger_emailtemplates WHERE templateid = ? ', array($recordId));
 }