public function process(Vtiger_Request $request) { $moduleSettingsName = $request->getModule(false); $moduleName = $request->getModule(); $baseModule = $request->get('module_name'); $idTpl = $request->get('tpl_id'); $viewer = $this->getViewer($request); if ($idTpl) { $docInfo = Settings_OSSDocumentControl_Module_Model::getDocInfo($idTpl); $viewer->assign('BASE_INFO', $docInfo['basic_info']); //var_dump($docInfo['required_conditions']); for ($i = 0; $i < count($docInfo['required_conditions']); $i++) { $fieldModel = Vtiger_Field_Model::getInstance($docInfo['required_conditions'][$i]['fieldname'], Vtiger_Module_Model::getInstance($baseModule)); $docInfo['required_conditions'][$i]['info'] = $fieldModel->getFieldInfo(); } $viewer->assign('REQUIRED_CONDITIONS', $docInfo['required_conditions']); for ($i = 0; $i < count($docInfo['optional_conditions']); $i++) { $fieldModel = Vtiger_Field_Model::getInstance($docInfo['optional_conditions'][$i]['fieldname'], Vtiger_Module_Model::getInstance($baseModule)); $docInfo['optional_conditions'][$i]['info'] = $fieldModel->getFieldInfo(); } $viewer->assign('OPTIONAL_CONDITIONS', $docInfo['optional_conditions']); $viewer->assign('TPL_ID', $idTpl); //$fieldModel = Vtiger_Field_Model::getInstance($value->get('name'), $baseModuleModel); } $viewer->assign('MODULE_NAME', $moduleName); $viewer->assign('SUMMARY', $request->get('summary')); $viewer->assign('BASE_MODULE', $baseModule); $viewer->assign('QUALIFIED_MODULE', $moduleSettingsName); $viewer->assign('FIELD_LIST', Settings_OSSDocumentControl_Module_Model::getListBaseModuleField($baseModule)); //$viewer->assign('FOLDER_LIST', Documents_Module_Model::getAllFolders()); $viewer->assign('CONDITION_BY_TYPE', Settings_OSSDocumentControl_Module_Model::getConditionByType()); echo $viewer->view('Edit2.tpl', $moduleSettingsName, true); }
/** * Funtion that returns fields that will be showed in the record selection popup * @return <Array of fields> */ public function getPopupViewFieldsList($sourceModule = false) { if (!empty($sourceModule)) { $parentRecordModel = Vtiger_Module_Model::getInstance($sourceModule); $relationModel = Vtiger_Relation_Model::getInstance($parentRecordModel, $this); } $popupFields = array(); if ($relationModel) { $popupFields = $relationModel->getRelationFields(true); } if (count($popupFields) == 0) { $popupFileds = $this->getSummaryViewFieldsList(); foreach ($popupFileds as $fieldName => $fieldModel) { if ($fieldName === 'folderid' || $fieldName === 'modifiedtime') { unset($popupFileds[$fieldName]); } } $reqPopUpFields = array('File Status' => 'filestatus', 'File Size' => 'filesize', 'File Location Type' => 'filelocationtype'); foreach ($reqPopUpFields as $fieldLabel => $fieldName) { $fieldModel = Vtiger_Field_Model::getInstance($fieldName, $this); if ($fieldModel->getPermissions('readwrite')) { $popupFileds[$fieldName] = $fieldModel; } } $popupFields = array_keys($popupFileds); } return $popupFields; }
public function process(Vtiger_Request $request) { $qualifiedModuleName = $request->getModule(false); $moduleName = $request->getModule(); $baseModule = $request->get('base_module'); $idTpl = $request->get('tpl_id'); $viewer = $this->getViewer($request); if ($idTpl && $baseModule != 'All') { $docInfo = Settings_DataAccess_Module_Model::getDataAccessInfo($idTpl); $viewer->assign('BASE_INFO', $docInfo['basic_info']); for ($i = 0; $i < count($docInfo['required_conditions']); $i++) { $fieldModel = Vtiger_Field_Model::getInstance($docInfo['required_conditions'][$i]['fieldname'], Vtiger_Module_Model::getInstance($baseModule)); $docInfo['required_conditions'][$i]['info'] = $fieldModel->getFieldInfo(); } $viewer->assign('REQUIRED_CONDITIONS', $docInfo['required_conditions']); for ($i = 0; $i < count($docInfo['optional_conditions']); $i++) { $fieldModel = Vtiger_Field_Model::getInstance($docInfo['optional_conditions'][$i]['fieldname'], Vtiger_Module_Model::getInstance($baseModule)); $docInfo['optional_conditions'][$i]['info'] = $fieldModel->getFieldInfo(); } $viewer->assign('OPTIONAL_CONDITIONS', $docInfo['optional_conditions']); $viewer->assign('TPL_ID', $idTpl); } $viewer->assign('STEP', 2); $viewer->assign('MODULE_NAME', $moduleName); $viewer->assign('REQUEST', $request); $viewer->assign('SUMMARY', $request->get('summary')); $viewer->assign('BASE_MODULE', $baseModule); $viewer->assign('QUALIFIED_MODULE', $qualifiedModuleName); $viewer->assign('FIELD_LIST', Settings_DataAccess_Module_Model::getListBaseModuleField($baseModule)); $viewer->assign('CONDITION_BY_TYPE', Settings_DataAccess_Module_Model::getConditionByType()); echo $viewer->view('Step2.tpl', $qualifiedModuleName, true); }
/** * 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(); $module = $this->getModule(); $moduleName = $module->getName(); $parentModuleName = $module->getParentName(); $qualifiedModuleName = $moduleName; if (!empty($parentModuleName)) { $qualifiedModuleName = $parentModuleName . ':' . $qualifiedModuleName; } $recordModelClass = Vtiger_Loader::getComponentClassName('Model', 'Record', $qualifiedModuleName); $listQuery = $this->getBasicListQuery(); $startIndex = $pagingModel->getStartIndex(); $pageLimit = $pagingModel->getPageLimit(); $orderBy = $this->getForSql('orderby'); if (!empty($orderBy) && $orderBy === 'smownerid') { $fieldModel = Vtiger_Field_Model::getInstance('assigned_user_id', $moduleModel); if ($fieldModel->getFieldDataType() == 'owner') { $orderBy = 'COALESCE(' . getSqlForNameInDisplayFormat(['first_name' => 'vtiger_users.first_name', 'last_name' => 'vtiger_users.last_name'], 'Users') . ',vtiger_groups.groupname)'; } } if (!empty($orderBy)) { $listQuery .= ' ORDER BY ' . $orderBy . ' ' . $this->getForSql('sortorder'); } if ($module->isPagingSupported()) { $nextListQuery = $listQuery . ' LIMIT ' . ($startIndex + $pageLimit) . ',1'; $listQuery .= " LIMIT $startIndex, $pageLimit"; } $listResult = $db->pquery($listQuery, array()); $noOfRecords = $db->num_rows($listResult); $listViewRecordModels = array(); for ($i = 0; $i < $noOfRecords; ++$i) { $row = $db->query_result_rowdata($listResult, $i); $record = new $recordModelClass(); $record->setData($row); if (method_exists($record, 'getModule') && method_exists($record, 'setModule')) { $moduleModel = Settings_Vtiger_Module_Model::getInstance($qualifiedModuleName); $record->setModule($moduleModel); } $listViewRecordModels[$record->getId()] = $record; } if ($module->isPagingSupported()) { $pagingModel->calculatePageRange($listViewRecordModels); $nextPageResult = $db->pquery($nextListQuery, array()); $nextPageNumRows = $db->num_rows($nextPageResult); if ($nextPageNumRows <= 0) { $pagingModel->set('nextPageExists', false); } } return $listViewRecordModels; }
function process(Vtiger_Request $request) { $currentUserPriviligeModel = Users_Privileges_Model::getCurrentUserPrivilegesModel(); $viewer = $this->getViewer($request); $recordId = $request->get('record'); $moduleName = $request->getModule(); $recordModel = Vtiger_Record_Model::getInstanceById($recordId); $moduleModel = $recordModel->getModule(); $viewer->assign('MODULE', $moduleName); $viewer->assign('USER_MODEL', Users_Record_Model::getCurrentUserModel()); $viewer->assign('CURRENT_USER_PRIVILEGE', $currentUserPriviligeModel); $viewer->assign('RECORD', $recordModel); $viewer->assign('CONVERT_LEAD_FIELDS', $recordModel->getConvertLeadFields()); $assignedToFieldModel = $moduleModel->getField('assigned_user_id'); $assignedToFieldModel->set('fieldvalue', $recordModel->get('assigned_user_id')); $viewer->assign('ASSIGN_TO', $assignedToFieldModel); $potentialModuleModel = Vtiger_Module_Model::getInstance('Potentials'); $accountField = Vtiger_Field_Model::getInstance('related_to', $potentialModuleModel); $contactField = Vtiger_Field_Model::getInstance('contact_id', $potentialModuleModel); $viewer->assign('ACCOUNT_FIELD_MODEL', $accountField); $viewer->assign('CONTACT_FIELD_MODEL', $contactField); $contactsModuleModel = Vtiger_Module_Model::getInstance('Contacts'); $accountField = Vtiger_Field_Model::getInstance('parent_id', $contactsModuleModel); $viewer->assign('CONTACT_ACCOUNT_FIELD_MODEL', $accountField); $state = Settings_Leads_ConvertToAccount_Model::getState(); $viewer->assign('STATE', $state); $viewer->view('ConvertLead.tpl', $moduleName); }
public function save(Vtiger_Request $request) { $fieldId = $request->get('fieldid'); $fieldInstance = Vtiger_Field_Model::getInstance($fieldId); $fields = ['presence', 'quickcreate', 'summaryfield', 'helpinfo', 'generatedtype', 'masseditable', 'displaytype']; foreach ($request->getAll() as $key => $value) { if ($key == 'mandatory') { $fieldInstance->updateTypeofDataFromMandatory($value); } if (in_array($key, $fields)) { $fieldInstance->set($key, $value); } } $defaultValue = $request->get('fieldDefaultValue'); if ($fieldInstance->getFieldDataType() == 'date') { $dateInstance = new Vtiger_Date_UIType(); $defaultValue = $dateInstance->getDBInsertedValue($defaultValue); } if ($request->has('fieldMask')) { $fieldInstance->set('fieldparams', $request->get('fieldMask')); } if (is_array($defaultValue)) { $defaultValue = implode(' |##| ', $defaultValue); } $fieldInstance->set('defaultvalue', $defaultValue); $response = new Vtiger_Response(); try { $fieldInstance->save(); $response->setResult(array('success' => true, 'presence' => $request->get('presence'), 'mandatory' => $fieldInstance->isMandatory(), 'label' => vtranslate($fieldInstance->get('label'), $request->get('sourceModule')))); } catch (Exception $e) { $response->setError($e->getCode(), $e->getMessage()); } $response->emit(); }
public function process(Vtiger_Request $request) { $moduleName = $request->getModule(); $recordId = $request->get('record'); $recordModel = $this->record; if (!$recordModel) { if (!empty($recordId)) { $recordModel = Vtiger_Record_Model::getInstanceById($recordId, $moduleName); } else { $recordModel = Vtiger_Record_Model::getCleanInstance($moduleName); } $this->record = $recordModel; } $viewer = $this->getViewer($request); $viewer->assign('IMAGE_DETAILS', $recordModel->getImageDetails()); $salutationFieldModel = Vtiger_Field_Model::getInstance('salutationtype', $recordModel->getModule()); // Fix for http://trac.vtiger.com/cgi-bin/trac.cgi/ticket/7851 $salutationType = $request->get('salutationtype'); if (!empty($salutationType)) { $salutationFieldModel->set('fieldvalue', $request->get('salutationtype')); } else { $salutationFieldModel->set('fieldvalue', $recordModel->get('salutationtype')); } $viewer->assign('SALUTATION_FIELD_MODEL', $salutationFieldModel); parent::process($request); }
/** * Function to get instance * @param <String> $value - fieldname or fieldid * @param <type> $module - optional - module instance * @return <Vtiger_Field_Model> */ public static function getInstance($value, $module = false) { $fieldObject = parent::getInstance($value, $module); if ($fieldObject) { return self::getInstanceFromFieldObject($fieldObject); } return false; }
public function process(Vtiger_Request $request) { $viewer = $this->getViewer($request); $moduleName = $request->getModule(); $moduleModel = Vtiger_Module_Model::getInstance($moduleName); $salutationFieldModel = Vtiger_Field_Model::getInstance('salutationtype', $moduleModel); $viewer->assign('SALUTATION_FIELD_MODEL', $salutationFieldModel); parent::process($request); }
/** * Function to search emails for send email * @param <String> $searchValue * @return <Array> Result of searched emails */ public function searchEmails($searchValue) { $emailsResult = array(); $db = PearDatabase::getInstance(); $currentUserModel = Users_Record_Model::getCurrentUserModel(); $emailSupportedModulesList = $this->getEmailRelatedModules(); foreach ($emailSupportedModulesList as $moduleName) { $searchFields = array(); $moduleModel = Vtiger_Module_Model::getInstance($moduleName); $emailFieldModels = $moduleModel->getFieldsByType('email'); foreach ($emailFieldModels as $fieldName => $fieldModel) { if ($fieldModel->isViewable()) { $searchFields[] = $fieldName; } } $emailFields = $searchFields; $nameFields = $moduleModel->getNameFields(); foreach ($nameFields as $fieldName) { $fieldModel = Vtiger_Field_Model::getInstance($fieldName, $moduleModel); if ($fieldModel->isViewable()) { $searchFields[] = $fieldName; } } if ($emailFields) { $moduleInstance = CRMEntity::getInstance($moduleName); $queryGenerator = new QueryGenerator($moduleName, $currentUserModel); $listFields = $searchFields; $listFields[] = 'id'; $queryGenerator->setFields($listFields); //Opensource fix for showing up deleted records on email search $queryGenerator->startGroup(""); foreach ($searchFields as $key => $emailField) { $queryGenerator->addCondition($emailField, trim($searchValue), 'c', 'OR'); } $queryGenerator->endGroup(); $result = $db->pquery($queryGenerator->getQuery(), array()); $numOfRows = $db->num_rows($result); for ($i = 0; $i < $numOfRows; $i++) { $row = $db->query_result_rowdata($result, $i); foreach ($emailFields as $emailField) { $emailFieldValue = $row[$emailField]; if ($emailFieldValue) { //SalesPlatform.ru begin $recordLabel = decode_html(getEntityFieldNameDisplay($moduleName, $nameFields, $row)); //$recordLabel = getEntityFieldNameDisplay($moduleName, $nameFields, $row); //SalesPlatform.ru end if (strpos($emailFieldValue, $searchValue) !== false || strpos($recordLabel, $searchValue) !== false) { $emailsResult[vtranslate($moduleName, $moduleName)][$row[$moduleInstance->table_index]][] = array('value' => $emailFieldValue, 'label' => $recordLabel . ' <b>(' . $emailFieldValue . ')</b>'); } } } } } } return $emailsResult; }
/** * Function to get instance * @param <String/Integer> $value * @param <String> $module * @return <Settings_Leads_Field_Model> field model */ public static function getInstance($value, $module) { $fieldModel = parent::getInstance($value, $module); $objectProperties = get_object_vars($fieldModel); $fieldModel = new self(); foreach ($objectProperties as $properName => $propertyValue) { $fieldModel->{$properName} = $propertyValue; } return $fieldModel; }
public function checkLimits(Vtiger_Request $request) { $moduleName = $request->getModule(); $record = $request->get('record'); $currency = $request->get('currency'); $price = $request->get('price'); $limitConfig = $request->get('limitConfig'); $limitFieldName = 'creditlimit'; $balanceFieldName = 'inventorybalance'; $moduleInstance = Vtiger_Module_Model::getInstance('Accounts'); $limitField = Vtiger_Field_Model::getInstance($limitFieldName, $moduleInstance); $balanceField = Vtiger_Field_Model::getInstance($balanceFieldName, $moduleInstance); if (!$limitField->isActiveField() || !$balanceField->isActiveField()) { $response = new Vtiger_Response(); $response->setResult(['status' => true]); $response->emit(); return; } $recordModel = Vtiger_Record_Model::getInstanceById($record, 'Accounts'); $limitID = $recordModel->get($limitFieldName); $balance = $recordModel->get($balanceFieldName); $limit = reset(Vtiger_InventoryLimit_UIType::getValues($limitID))['value']; $baseCurrency = Vtiger_Util_Helper::getBaseCurrency(); $symbol = $baseCurrency['currency_symbol']; if ($baseCurrency['id'] != $currency) { $selectedCurrency = Vtiger_Functions::getCurrencySymbolandRate($currency); $price = floatval($price) * $selectedCurrency['rate']; $symbol = $selectedCurrency['symbol']; } $totalPrice = $price + $balance; $status = $totalPrice > $limit ? false : true; if (!$status) { $viewer = new Vtiger_Viewer(); $viewer->assign('PRICE', $price); $viewer->assign('BALANCE', $balance); $viewer->assign('SYMBOL', $symbol); $viewer->assign('LIMIT', $limit); $viewer->assign('TOTALS', $totalPrice); $viewer->assign('LIMIT_CONFIG', $limitConfig); $html = $viewer->view('InventoryLimitAlert.tpl', $moduleName, true); } $response = new Vtiger_Response(); $response->setResult([ 'status' => $status, 'html' => $html ]); $response->emit(); }
/** * Funtion that returns fields that will be showed in the record selection popup * @return <Array of fields> */ public function getPopupViewFieldsList() { $popupFileds = $this->getSummaryViewFieldsList(); foreach ($popupFileds as $fieldName => $fieldModel) { if ($fieldName === 'folderid' || $fieldName === 'modifiedtime') { unset($popupFileds[$fieldName]); } } $reqPopUpFields = array('File Status' => 'filestatus', 'File Size' => 'filesize', 'File Location Type' => 'filelocationtype'); foreach ($reqPopUpFields as $fieldLabel => $fieldName) { $fieldModel = Vtiger_Field_Model::getInstance($fieldName, $this); if ($fieldModel->getPermissions('readwrite')) { $popupFileds[$fieldName] = $fieldModel; } } return array_keys($popupFileds); }
public function process(Vtiger_Request $request) { $moduleName = $request->getModule(); $recordId = $request->get('record'); $recordModel = $this->record; if (!$recordModel) { if (!empty($recordId)) { $recordModel = Vtiger_Record_Model::getInstanceById($recordId, $moduleName); } else { $recordModel = Vtiger_Record_Model::getCleanInstance($moduleName); } } $viewer = $this->getViewer($request); $salutationFieldModel = Vtiger_Field_Model::getInstance('salutationtype', $recordModel->getModule()); $salutationFieldModel->set('fieldvalue', $recordModel->get('salutationtype')); $viewer->assign('SALUTATION_FIELD_MODEL', $salutationFieldModel); parent::process($request); }
/** * Function to set data of parent record model to this record * @param Vtiger_Record_Model $parentRecordModel * @return Inventory_Record_Model */ public function setParentRecordData(Vtiger_Record_Model $parentRecordModel) { $userModel = Users_Privileges_Model::getCurrentUserPrivilegesModel(); $moduleName = $parentRecordModel->getModuleName(); $data = array(); $fieldMappingList = $parentRecordModel->getInventoryMappingFields(); foreach ($fieldMappingList as $fieldMapping) { $parentField = $fieldMapping['parentField']; $inventoryField = $fieldMapping['inventoryField']; $fieldModel = Vtiger_Field_Model::getInstance($parentField, Vtiger_Module_Model::getInstance($moduleName)); if ($fieldModel->getPermissions()) { $data[$inventoryField] = $parentRecordModel->get($parentField); } else { $data[$inventoryField] = $fieldMapping['defaultValue']; } } return $this->setData($data); }
/** * 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) { $reportFolderModel = Reports_Folder_Model::getInstance(); $reportFolderModel->set('folderid', $this->get('folderid')); $orderBy = $this->get('orderby'); 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 (!empty($orderBy)) { $reportFolderModel->set('orderby', $orderBy); $reportFolderModel->set('sortby', $this->get('sortorder')); } $reportRecordModels = $reportFolderModel->getReports($pagingModel); $pagingModel->calculatePageRange($reportRecordModels); return $reportRecordModels; }
/** * 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; }
/** * Function to set todo fields for export */ public function setTodoFieldsForExport() { $moduleFields = array_flip($this->getColumnFieldMapping()); $userModel = Users_Privileges_Model::getCurrentUserPrivilegesModel(); $keysToReplace = array('taskpriority', 'taskstatus'); $keysValuesToReplace = array('taskpriority' => 'priority', 'taskstatus' => 'status'); foreach ($moduleFields as $fieldName => $fieldValue) { $fieldModel = Vtiger_Field_Model::getInstance($fieldName, $this); if ($fieldName != 'id' && $fieldModel->getPermissions()) { if (!in_array($fieldName, $keysToReplace)) { $todoFields[$fieldName] = 'yes'; } else { $todoFields[$keysValuesToReplace[$fieldName]] = 'yes'; } } } $this->set('todoFields', $todoFields); }
function getFieldInstances() { $id = $this->get('id'); $db = PearDatabase::getInstance(); $fieldInstances = array(); if ($this->isCreate() || $this->isUpdate()) { $result = $db->pquery('SELECT * FROM vtiger_modtracker_detail WHERE id = ?', array($id)); $rows = $db->num_rows($result); for ($i = 0; $i < $rows; $i++) { $data = $db->query_result_rowdata($result, $i); $row = array_map('html_entity_decode', $data); if ($row['fieldname'] == 'record_id' || $row['fieldname'] == 'record_module') { continue; } $fieldModel = Vtiger_Field_Model::getInstance($row['fieldname'], $this->getParent()->getModule()); if (!$fieldModel) { continue; } $fieldInstance = new ModTracker_Field_Model(); $fieldInstance->setData($row)->setParent($this)->setFieldInstance($fieldModel); $fieldInstances[] = $fieldInstance; } } return $fieldInstances; }
/** * 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(); $moduleName = $this->getModule()->get('name'); $moduleFocus = CRMEntity::getInstance($moduleName); $moduleModel = Vtiger_Module_Model::getInstance($moduleName); $queryGenerator = $this->get('query_generator'); $listViewContoller = $this->get('listview_controller'); $orderBy = $this->getForSql('orderby'); $sortOrder = $this->getForSql('sortorder'); if(!empty($orderBy)){ $columnFieldMapping = $moduleModel->getColumnFieldMapping(); $orderByFieldName = $columnFieldMapping[$orderBy]; $orderByFieldModel = $moduleModel->getField($orderByFieldName); if($orderByFieldModel && $orderByFieldModel->getFieldDataType() == Vtiger_Field_Model::REFERENCE_TYPE){ //IF it is reference add it in the where fields so that from clause will be having join of the table $queryGenerator = $this->get('query_generator'); $queryGenerator->addWhereField($orderByFieldName); } } if (!empty($orderBy) && $orderBy === 'smownerid') { $fieldModel = Vtiger_Field_Model::getInstance('assigned_user_id', $moduleModel); if ($fieldModel->getFieldDataType() == 'owner') { $orderBy = 'COALESCE(' . getSqlForNameInDisplayFormat(['first_name' => 'vtiger_users.first_name', 'last_name' => 'vtiger_users.last_name'], 'Users') . ',vtiger_groups.groupname)'; } } $listQuery = $this->getQuery(); $listQuery = preg_replace("/vtiger_crmentity.deleted\s*=\s*0/i", 'vtiger_crmentity.deleted = 1', $listQuery); $startIndex = $pagingModel->getStartIndex(); $pageLimit = $pagingModel->getPageLimit(); if(!empty($orderBy)) { if($orderByFieldModel && $orderByFieldModel->isReferenceField()){ $referenceModules = $orderByFieldModel->getReferenceList(); $referenceNameFieldOrderBy = array(); foreach($referenceModules as $referenceModuleName) { $referenceModuleModel = Vtiger_Module_Model::getInstance($referenceModuleName); $referenceNameFields = $referenceModuleModel->getNameFields(); $columnList = array(); foreach($referenceNameFields as $nameField) { $fieldModel = $referenceModuleModel->getField($nameField); $columnList[] = $fieldModel->get('table').'.'.$fieldModel->get('column'); } if(count($columnList) > 1) { $referenceNameFieldOrderBy[] = getSqlForNameInDisplayFormat(array('first_name'=>$columnList[0],'last_name'=>$columnList[1]),'Users').' '.$sortOrder; } else { $referenceNameFieldOrderBy[] = implode('', $columnList).' '.$sortOrder ; } } $listQuery .= ' ORDER BY '. implode(',',$referenceNameFieldOrderBy); }else{ $listQuery .= ' ORDER BY '. $orderBy . ' ' .$sortOrder; } } $listQuery .= " LIMIT $startIndex,".($pageLimit+1); $listResult = $db->pquery($listQuery, array()); $listViewRecordModels = array(); $listViewEntries = $listViewContoller->getListViewRecords($moduleFocus,$moduleName, $listResult); $pagingModel->calculatePageRange($listViewEntries); if($db->num_rows($listResult) > $pageLimit){ array_pop($listViewEntries); $pagingModel->set('nextPageExists', true); }else{ $pagingModel->set('nextPageExists', false); } $index = 0; foreach($listViewEntries as $recordId => $record) { $rawData = $db->query_result_rowdata($listResult, $index++); $record['id'] = $recordId; $listViewRecordModels[$recordId] = $moduleModel->getRecordFromArray($record, $rawData); $listViewRecordModels[$recordId]->lockEditView = Users_Privileges_Model::checkLockEdit($moduleName, $recordId); $listViewRecordModels[$recordId]->isPermittedToEditView = Users_Privileges_Model::isPermitted($moduleName, 'EditView', $recordId); $listViewRecordModels[$recordId]->colorList = Settings_DataAccess_Module_Model::executeColorListHandlers( $moduleName, $recordId, $listViewRecordModels[$recordId] ); } return $listViewRecordModels; }
public static function getListBaseModuleField($baseModule) { if ($baseModule === 'All') { return $baseModule; } $baseModuleModel = Vtiger_Module_Model::getInstance($baseModule); $list = $baseModuleModel->getFields(); $output = array(); if (count($list)) { $num = 0; foreach ($list as $key => $value) { if (in_array($value->get('displaytype'), array('1', '2'))) { $output[$baseModule][$num]['name'] = $value->get('name'); $output[$baseModule][$num]['uitype'] = $value->get('uitype'); $output[$baseModule][$num]['label'] = $value->get('label'); $fieldModel = Vtiger_Field_Model::getInstance($value->get('name'), $baseModuleModel); $output[$baseModule][$num]['info'] = $fieldModel->getFieldInfo(); $num++; } } } return $output; }
/** * Function returns Top Potentials * @return <Array of Vtiger_Record_Model> */ function getTopPotentials($pagingModel) { $currentUser = Users_Record_Model::getCurrentUserModel(); $db = PearDatabase::getInstance(); $moduleModel = Vtiger_Module_Model::getInstance('Potentials'); $fieldsToDisplay = array("sum_invoices", "related_to"); $query = "SELECT crmid , potentialname "; foreach ($fieldsToDisplay as $value) { $fieldInstance = Vtiger_Field_Model::getInstance($value, $moduleModel); if ($fieldInstance->isViewable()) { $query = $query . ', ' . $value; } } $query = $query . ' FROM vtiger_potential INNER JOIN vtiger_crmentity ON vtiger_potential.potentialid = vtiger_crmentity.crmid AND deleted = 0 ' . Users_Privileges_Model::getNonAdminAccessControlQuery($this->getName()) . "\n\t\t\t\t\t\tWHERE sales_stage NOT IN ('Closed Won', 'Closed Lost') AND sum_invoices > 0\n\t\t\t\t\t\tORDER BY sum_invoices DESC LIMIT " . $pagingModel->getStartIndex() . ', ' . $pagingModel->getPageLimit(); $result = $db->pquery($query, []); $models = array(); for ($i = 0; $i < $db->num_rows($result); $i++) { $modelInstance = Vtiger_Record_Model::getCleanInstance('Potentials'); $modelInstance->setId($db->query_result($result, $i, 'crmid')); $modelInstance->set('sum_invoices', $db->query_result($result, $i, 'sum_invoices')); $modelInstance->set('potentialname', $db->query_result($result, $i, 'potentialname')); $modelInstance->set('related_to', $db->query_result($result, $i, 'related_to')); $models[] = $modelInstance; } return $models; }
public function getPicklist(Vtiger_Request $request) { $response = new Vtiger_Response(); $fieldName = $request->get('rfield'); $moduleName = $request->get('rmodule'); $picklistValues = []; if (!empty($fieldName) && !empty($moduleName) && $fieldName != '-') { $moduleModel = Vtiger_Module_Model::getInstance($moduleName); $fieldInstance = Vtiger_Field_Model::getInstance($fieldName, $moduleModel); $picklistValues = $fieldInstance->getPicklistValues(); if ($picklistValues == NULL) { $picklistValues = []; } } $response->setResult($picklistValues); $response->emit(); }
/** * Funtion that returns fields that will be showed in the record selection popup * @return <Array of fields> */ public function getPopupViewFieldsList() { $popupFileds = $this->getSummaryViewFieldsList(); $reqPopUpFields = array('Currency' => 'currency_id'); foreach ($reqPopUpFields as $fieldLabel => $fieldName) { $fieldModel = Vtiger_Field_Model::getInstance($fieldName, $this); if ($fieldModel->getPermissions('readwrite')) { $popupFileds[$fieldName] = $fieldModel; } } return array_keys($popupFileds); }
/** * Function to get the field mode * @param <String> $fieldName - field name * @return <Vtiger_Field_Model> */ public function getField($fieldName) { return Vtiger_Field_Model::getInstance($fieldName, $this); }
public function getProfileTabFieldModel($module, $field) { $profileTabModel = $this->getProfileTabModel($module); $fieldId = false; if (is_object($field) && is_a($field, 'Vtiger_Field_Model')) { $fieldId = $field->getId(); } else { $field = Vtiger_Field_Model::getInstance($field, $profileTabModel); $fieldId = $field->getId(); } if (!$fieldId) { return false; } $moduleFields = $profileTabModel->getFields(); $fieldModel = $moduleFields[$field->getName()]; return $fieldModel; }
public function process(Vtiger_Request $request) { PDFMaker_Debugger_Model::GetInstance()->Init(); $PDFMaker = new PDFMaker_PDFMaker_Model(); if ($PDFMaker->CheckPermissions("EDIT") == false) { $PDFMaker->DieDuePermission(); } $viewer = $this->getViewer($request); if ($request->has('templateid') && !$request->isEmpty('templateid')) { $templateid = $request->get('templateid'); $pdftemplateResult = $PDFMaker->GetEditViewData($templateid); $select_module = $pdftemplateResult["module"]; $select_format = $pdftemplateResult["format"]; $select_orientation = $pdftemplateResult["orientation"]; } else { $templateid = ""; if ($request->has("return_module") && !$request->isEmpty("return_module")) { $select_module = $request->get("return_module"); } else { $select_module = ""; } $select_format = "A4"; $select_orientation = "portrait"; } $PDFMaker->CheckTemplatePermissions($select_module, $templateid); $viewer->assign("EMODE", "edit"); $viewer->assign("TEMPLATEID", $templateid); $viewer->assign("MODULENAME", vtranslate($select_module, $select_module)); $viewer->assign("SELECTMODULE", $select_module); $viewer->assign("BODY", $pdftemplateResult["body"]); $cu_model = Users_Record_Model::getCurrentUserModel(); $this->cu_language = $cu_model->get('language'); $viewer->assign("THEME", $theme); $viewer->assign("IMAGE_PATH", $image_path); $app_strings_big = Vtiger_Language_Handler::getModuleStringsFromFile($this->cu_language); $app_strings = $app_strings_big['languageStrings']; $viewer->assign("APP", $app_strings); $viewer->assign("PARENTTAB", getParentTab()); $modArr = $PDFMaker->GetAllModules(); $Modulenames = $modArr[0]; $ModuleIDS = $modArr[1]; // ****************************************** Company and User information: ********************************** $CUI_BLOCKS["Account"] = vtranslate("LBL_COMPANY_INFO", 'PDFMaker'); $CUI_BLOCKS["Assigned"] = vtranslate("LBL_USER_INFO", 'PDFMaker'); $CUI_BLOCKS["Logged"] = vtranslate("LBL_LOGGED_USER_INFO", 'PDFMaker'); $viewer->assign("CUI_BLOCKS", $CUI_BLOCKS); $adb = PearDatabase::getInstance(); $sql = "SELECT * FROM vtiger_organizationdetails"; $result = $adb->pquery($sql, array()); $organization_logoname = decode_html($adb->query_result($result, 0, 'logoname')); $organization_header = decode_html($adb->query_result($result, 0, 'headername')); $organization_stamp_signature = $adb->query_result($result, 0, 'stamp_signature'); global $site_URL; $path = $site_URL . "/test/logo/"; if (isset($organization_logoname)) { $organization_logo_img = "<img src=\"" . $path . $organization_logoname . "\">"; $viewer->assign("COMPANYLOGO", $organization_logo_img); } if (isset($organization_stamp_signature)) { $organization_stamp_signature_img = "<img src=\"" . $path . $organization_stamp_signature . "\">"; $viewer->assign("COMPANY_STAMP_SIGNATURE", $organization_stamp_signature_img); } if (isset($organization_header)) { $organization_header_img = "<img src=\"" . $path . $organization_header . "\">"; $viewer->assign("COMPANY_HEADER_SIGNATURE", $organization_header_img); } $Acc_Info = array('' => vtranslate("LBL_PLS_SELECT", 'PDFMaker'), "COMPANY_NAME" => vtranslate("LBL_COMPANY_NAME", 'PDFMaker'), "COMPANY_LOGO" => vtranslate("LBL_COMPANY_LOGO", 'PDFMaker'), "COMPANY_ADDRESS" => vtranslate("LBL_COMPANY_ADDRESS", 'PDFMaker'), "COMPANY_CITY" => vtranslate("LBL_COMPANY_CITY", 'PDFMaker'), "COMPANY_STATE" => vtranslate("LBL_COMPANY_STATE", 'PDFMaker'), "COMPANY_ZIP" => vtranslate("LBL_COMPANY_ZIP", 'PDFMaker'), "COMPANY_COUNTRY" => vtranslate("LBL_COMPANY_COUNTRY", 'PDFMaker'), "COMPANY_PHONE" => vtranslate("LBL_COMPANY_PHONE", "PDFMaker"), "COMPANY_FAX" => vtranslate("LBL_COMPANY_FAX", 'PDFMaker'), "COMPANY_WEBSITE" => vtranslate("LBL_COMPANY_WEBSITE", 'PDFMaker')); $viewer->assign("ACCOUNTINFORMATIONS", $Acc_Info); $sql_user_block = "SELECT blockid, blocklabel FROM vtiger_blocks WHERE tabid=29 ORDER BY sequence ASC"; $res_user_block = $adb->query($sql_user_block); $user_block_info_arr = array(); while ($row_user_block = $adb->fetch_array($res_user_block)) { $sql_user_field = "SELECT fieldid, uitype FROM vtiger_field WHERE block=" . $row_user_block['blockid'] . " and (displaytype != 3 OR uitype = 55) ORDER BY sequence ASC"; $res_user_field = $adb->query($sql_user_field); $num_user_field = $adb->num_rows($res_user_field); if ($num_user_field > 0) { $user_field_id_array = array(); while ($row_user_field = $adb->fetch_array($res_user_field)) { $user_field_id_array[] = $row_user_field['fieldid']; // print_r($user_field_id_array); } $user_block_info_arr[$row_user_block['blocklabel']] = $user_field_id_array; } } $user_mod_strings = $this->getModuleLanguageArray("Users"); $b = 0; foreach ($user_block_info_arr as $block_label => $block_fields) { $b++; if (isset($user_mod_strings[$block_label]) and $user_mod_strings[$block_label] != "") { $optgroup_value = $user_mod_strings[$block_label]; } else { $optgroup_value = vtranslate($block_label, 'PDFMaker'); } if (count($block_fields) > 0) { $field_ids = implode(",", $block_fields); $sql1 = "SELECT * FROM vtiger_field WHERE fieldid IN (" . $field_ids . ")"; $result1 = $adb->query($sql1); while ($row1 = $adb->fetchByAssoc($result1)) { $fieldname = $row1['fieldname']; $fieldlabel = $row1['fieldlabel']; $option_key = strtoupper("Users" . "_" . $fieldname); if (isset($current_mod_strings[$fieldlabel]) and $current_mod_strings[$fieldlabel] != "") { $option_value = $current_mod_strings[$fieldlabel]; } elseif (isset($app_strings[$fieldlabel]) and $app_strings[$fieldlabel] != "") { $option_value = $app_strings[$fieldlabel]; } else { $option_value = $fieldlabel; } $User_Info[$optgroup_value][$option_key] = $option_value; $Logged_User_Info[$optgroup_value]["R_" . $option_key] = $option_value; } } //variable RECORD ID added if ($b == 1) { $option_value = "Record ID"; $option_key = strtoupper("USERS_CRMID"); $User_Info[$optgroup_value][$option_key] = $option_value; $Logged_User_Info[$optgroup_value]["R_" . $option_key] = $option_value; } //end } // ****************************************** END: Company and User information ********************************** $viewer->assign("USERINFORMATIONS", $User_Info); $viewer->assign("LOGGEDUSERINFORMATION", $Logged_User_Info); $Invterandcon = array("" => vtranslate("LBL_PLS_SELECT", 'PDFMaker'), "TERMS_AND_CONDITIONS" => vtranslate("LBL_TERMS_AND_CONDITIONS", 'PDFMaker')); $viewer->assign("INVENTORYTERMSANDCONDITIONS", $Invterandcon); //labels $global_lang_labels = @array_flip($app_strings); $global_lang_labels = @array_flip($global_lang_labels); asort($global_lang_labels); $viewer->assign("GLOBAL_LANG_LABELS", $global_lang_labels); $module_lang_labels = array(); if ($select_module != "") { $mod_lang = $this->getModuleLanguageArray($select_module); $module_lang_labels = @array_flip($mod_lang); $module_lang_labels = @array_flip($module_lang_labels); asort($module_lang_labels); } else { $module_lang_labels[""] = vtranslate("LBL_SELECT_MODULE_FIELD", 'PDFMaker'); } $viewer->assign("MODULE_LANG_LABELS", $module_lang_labels); $Header_Footer_Strings = array("" => vtranslate("LBL_PLS_SELECT", 'PDFMaker'), "PAGE" => $app_strings["Page"], "PAGES" => $app_strings["Pages"]); $viewer->assign("HEADER_FOOTER_STRINGS", $Header_Footer_Strings); //PDF FORMAT SETTINGS $Formats = array("A3" => "A3", "A4" => "A4", "A5" => "A5", "A6" => "A6", "Letter" => "Letter", "Legal" => "Legal", "Custom" => "Custom"); // ITS4YOU VlZa $viewer->assign("FORMATS", $Formats); if (strpos($select_format, ";") > 0) { $tmpArr = explode(";", $select_format); $select_format = "Custom"; $custom_format["width"] = $tmpArr[0]; $custom_format["height"] = $tmpArr[1]; $viewer->assign("CUSTOM_FORMAT", $custom_format); } $viewer->assign("SELECT_FORMAT", $select_format); //PDF ORIENTATION SETTINGS $Orientations = array("portrait" => vtranslate("portrait", 'PDFMaker'), "landscape" => vtranslate("landscape", 'PDFMaker')); $viewer->assign("ORIENTATIONS", $Orientations); $viewer->assign("SELECT_ORIENTATION", $select_orientation); //PDF MARGIN SETTINGS if ($request->has("templateid") && !$request->isEmpty("templateid")) { $Margins = array("top" => $pdftemplateResult["margin_top"], "bottom" => $pdftemplateResult["margin_bottom"], "left" => $pdftemplateResult["margin_left"], "right" => $pdftemplateResult["margin_right"]); $Decimals = array("point" => $pdftemplateResult["decimal_point"], "decimals" => $pdftemplateResult["decimals"], "thousands" => $pdftemplateResult["thousands_separator"] != "sp" ? $pdftemplateResult["thousands_separator"] : " "); } else { $Margins = array("top" => "2", "bottom" => "2", "left" => "2", "right" => "2"); $Decimals = array("point" => ",", "decimals" => "2", "thousands" => " "); } $viewer->assign("MARGINS", $Margins); $viewer->assign("DECIMALS", $Decimals); //PDF HEADER / FOOTER $header = ""; $footer = ""; if ($request->has("templateid") && !$request->isEmpty("templateid")) { $header = $pdftemplateResult["header"]; $footer = $pdftemplateResult["footer"]; } $viewer->assign("HEADER", $header); $viewer->assign("FOOTER", $footer); $hfVariables = array("##PAGE##" => vtranslate("LBL_CURRENT_PAGE", 'PDFMaker'), "##PAGES##" => vtranslate("LBL_ALL_PAGES", 'PDFMaker'), "##PAGE##/##PAGES##" => vtranslate("LBL_PAGE_PAGES", 'PDFMaker')); $viewer->assign("HEAD_FOOT_VARS", $hfVariables); $dateVariables = array("##DD.MM.YYYY##" => vtranslate("LBL_DATE_DD.MM.YYYY", 'PDFMaker'), "##DD-MM-YYYY##" => vtranslate("LBL_DATE_DD-MM-YYYY", 'PDFMaker'), "##MM-DD-YYYY##" => vtranslate("LBL_DATE_MM-DD-YYYY", 'PDFMaker'), "##YYYY-MM-DD##" => vtranslate("LBL_DATE_YYYY-MM-DD", 'PDFMaker')); $viewer->assign("DATE_VARS", $dateVariables); $cmod = $this->getModuleLanguageArray("Settings"); //$cmod = return_specified_module_language($current_language, "Settings"); $viewer->assign("CMOD", $cmod); //Ignored picklist values $pvsql = "SELECT value FROM vtiger_pdfmaker_ignorepicklistvalues"; $pvresult = $adb->query($pvsql); $pvvalues = ""; while ($pvrow = $adb->fetchByAssoc($pvresult)) { $pvvalues .= $pvrow["value"] . ", "; } $viewer->assign("IGNORE_PICKLIST_VALUES", rtrim($pvvalues, ", ")); $More_Fields = array("CURRENCYNAME" => vtranslate("LBL_CURRENCY_NAME", 'PDFMaker'), "CURRENCYSYMBOL" => vtranslate("LBL_CURRENCY_SYMBOL", 'PDFMaker'), "CURRENCYCODE" => vtranslate("LBL_CURRENCY_CODE", 'PDFMaker'), "TOTALWITHOUTVAT" => vtranslate("LBL_VARIABLE_SUMWITHOUTVAT", 'PDFMaker'), "TOTALDISCOUNT" => vtranslate("LBL_VARIABLE_TOTALDISCOUNT", 'PDFMaker'), "TOTALDISCOUNTPERCENT" => vtranslate("LBL_VARIABLE_TOTALDISCOUNT_PERCENT", 'PDFMaker'), "TOTALAFTERDISCOUNT" => vtranslate("LBL_VARIABLE_TOTALAFTERDISCOUNT", 'PDFMaker'), "VAT" => vtranslate("LBL_VARIABLE_VAT", 'PDFMaker'), "VATPERCENT" => vtranslate("LBL_VARIABLE_VAT_PERCENT", 'PDFMaker'), "VATBLOCK" => vtranslate("LBL_VARIABLE_VAT_BLOCK", 'PDFMaker'), "TOTALWITHVAT" => vtranslate("LBL_VARIABLE_SUMWITHVAT", 'PDFMaker'), "SHTAXTOTAL" => vtranslate("LBL_SHTAXTOTAL", 'PDFMaker'), "SHTAXAMOUNT" => vtranslate("LBL_SHTAXAMOUNT", 'PDFMaker'), "ADJUSTMENT" => vtranslate("LBL_ADJUSTMENT", 'PDFMaker'), "TOTAL" => vtranslate("LBL_VARIABLE_TOTALSUM", 'PDFMaker')); //formatable VATBLOCK content $vatblock_table = '<table border="1" cellpadding="3" cellspacing="0" style="border-collapse:collapse;"> <tr> <td>' . $app_strings["Name"] . '</td> <td>' . vtranslate("LBL_VATBLOCK_VAT_PERCENT", 'PDFMaker') . '</td> <td>' . vtranslate("LBL_VATBLOCK_SUM", 'PDFMaker') . '</td> <td>' . vtranslate("LBL_VATBLOCK_VAT_VALUE", 'PDFMaker') . '</td> </tr> <tr> <td colspan="4">#VATBLOCK_START#</td> </tr> <tr> <td>$VATBLOCK_LABEL$</td> <td>$VATBLOCK_VALUE$</td> <td>$VATBLOCK_NETTO$</td> <td>$VATBLOCK_VAT$</td> </tr> <tr> <td colspan="4">#VATBLOCK_END#</td> </tr> </table>'; $vatblock_table = str_replace(array("\r\n", "\r", "\n", "\t"), "", $vatblock_table); $vatblock_table = ereg_replace(" {2,}", ' ', $vatblock_table); $viewer->assign("VATBLOCK_TABLE", $vatblock_table); $ModCommentsModules = array(); foreach ($ModuleIDS as $module => $IDS) { if ($module == 'Calendar') { $sql1 = "SELECT blockid, blocklabel FROM vtiger_blocks WHERE tabid IN (9,16) ORDER BY sequence ASC"; } elseif ($module == "Quotes" || $module == "Invoice" || $module == "SalesOrder" || $module == "PurchaseOrder" || $module == "Issuecards" || $module == "Receiptcards" || $module == "Creditnote" || $module == "StornoInvoice") { $sql1 = "SELECT blockid, blocklabel FROM vtiger_blocks WHERE tabid=" . $IDS . " AND blocklabel != 'LBL_DETAILS_BLOCK' AND blocklabel != 'LBL_ITEM_DETAILS' ORDER BY sequence ASC"; } else { $sql1 = "SELECT blockid, blocklabel FROM vtiger_blocks WHERE tabid=" . $IDS . " ORDER BY sequence ASC"; } $res1 = $adb->query($sql1); $block_info_arr = array(); while ($row = $adb->fetch_array($res1)) { if ($row['blockid'] == '41' && $row['blocklabel'] == '') { $row['blocklabel'] = 'LBL_EVENT_INFORMATION'; } $sql2 = "SELECT fieldid, uitype, columnname, fieldlabel\n FROM vtiger_field\n WHERE block=" . $row['blockid'] . "\n AND (displaytype != 3 OR uitype = 55)\n ORDER BY sequence ASC"; $res2 = $adb->query($sql2); $num_rows2 = $adb->num_rows($res2); if ($num_rows2 > 0) { $field_id_array = array(); while ($row2 = $adb->fetch_array($res2)) { $field_id_array[] = $row2['fieldid']; $tmpArr = array($row2["columnname"], $row2["fieldlabel"]); switch ($row2['uitype']) { case "51": $All_Related_Modules[$module][] = array_merge($tmpArr, (array) "Accounts"); break; case "57": $All_Related_Modules[$module][] = array_merge($tmpArr, (array) "Contacts"); break; case "58": $All_Related_Modules[$module][] = array_merge($tmpArr, (array) "Campaigns"); break; case "59": $All_Related_Modules[$module][] = array_merge($tmpArr, (array) "Products"); break; case "73": $All_Related_Modules[$module][] = array_merge($tmpArr, (array) "Accounts"); break; case "75": $All_Related_Modules[$module][] = array_merge($tmpArr, (array) "Vendors"); break; case "81": $All_Related_Modules[$module][] = array_merge($tmpArr, (array) "Vendors"); break; case "76": $All_Related_Modules[$module][] = array_merge($tmpArr, (array) "Potentials"); break; case "78": $All_Related_Modules[$module][] = array_merge($tmpArr, (array) "Quotes"); break; case "80": $All_Related_Modules[$module][] = array_merge($tmpArr, (array) "SalesOrder"); break; case "68": $All_Related_Modules[$module][] = array_merge($tmpArr, (array) "Accounts"); $All_Related_Modules[$module][] = array_merge($tmpArr, (array) "Contacts"); break; case "10": $fmrs = $adb->query('SELECT relmodule FROM vtiger_fieldmodulerel WHERE fieldid=' . $row2['fieldid']); while ($rm = $adb->fetch_array($fmrs)) { $All_Related_Modules[$module][] = array_merge($tmpArr, (array) $rm['relmodule']); } break; } } // ITS4YOU MaJu //$block_info_arr[$row['blocklabel']] = $field_id_array; if (!empty($block_info_arr[$row['blocklabel']])) { foreach ($field_id_array as $field_id_array_value) { $block_info_arr[$row['blocklabel']][] = $field_id_array_value; } } else { $block_info_arr[$row['blocklabel']] = $field_id_array; } // ITS4YOU-END } } if ($module == "Quotes" || $module == "Invoice" || $module == "SalesOrder" || $module == "PurchaseOrder") { $block_info_arr["LBL_DETAILS_BLOCK"] = array(); } //ModComments support //if (in_array($module, $ModCommentsModules)) { // $block_info_arr["TEMP_MODCOMMENTS_BLOCK"] = array(); //} $ModuleFields[$module] = $block_info_arr; } //Permissions are taken into consideration when dealing with realted modules $AllowedRelMods = array(); if (count($All_Related_Modules) > 0) { foreach ($All_Related_Modules as $Mod => $RelMods) { foreach ($RelMods as $RelModKey => $RelMod) { $RelModName = $RelMod[2]; if (isPermitted($RelModName, '') == "yes") { $AllowedRelMods[$Mod][$RelModKey] = $RelMod; } } } } $All_Related_Modules = $AllowedRelMods; // Fix of emtpy selectbox in case of selected module does not have any related modules foreach ($Modulenames as $key => $value) { if (!isset($All_Related_Modules[$key])) { $All_Related_Modules[$key] = array(); } } $viewer->assign("ALL_RELATED_MODULES", $All_Related_Modules); if ($select_module != "" && count($All_Related_Modules[$select_module]) > 0) { foreach ($All_Related_Modules[$select_module] as $RelModArr) { $Related_Modules[$RelModArr[2] . "|" . $RelModArr[0]] = vtranslate($RelModArr[2]) . " (" . $RelModArr[1] . ")"; } } $viewer->assign("RELATED_MODULES", $Related_Modules); $tacModules = array(); $tac4you = is_numeric(getTabId("Tac4you")); if ($tac4you == true) { $sql = "SELECT tac4you_module FROM vtiger_tac4you_module WHERE presence = 1"; $result = $adb->query($sql); while ($row = $adb->fetchByAssoc($result)) { $tacModules[$row["tac4you_module"]] = $row["tac4you_module"]; } } $desc4youModules = array(); $desc4you = is_numeric(getTabId("Descriptions4you")); if ($desc4you == true) { $sql = "SELECT b.name FROM vtiger_links AS a\n INNER JOIN vtiger_tab AS b USING (tabid)\n WHERE linktype = 'DETAILVIEWWIDGET'\n AND linkurl = 'block://ModDescriptions4you:modules/Descriptions4you/ModDescriptions4you.php'"; $result = $adb->query($sql); while ($row = $adb->fetchByAssoc($result)) { $desc4youModules[$row["name"]] = $row["name"]; } } $Settings_Profiles_Record_Model = new Settings_Profiles_Record_Model(); foreach ($ModuleFields as $module => $Blocks) { $Optgroupts = array(); $current_mod_strings = $this->getModuleLanguageArray($module); $moduleModel = Vtiger_Module_Model::getInstance($module); $b = 0; if ($module == 'Calendar') { $b++; $Optgroupts[] = '"' . vtranslate('Calendar') . '","' . $b . '"'; $Convert_ModuleFields['Calendar|1'] .= ',"Record ID","CALENDAR_CRMID"'; $SelectModuleFields['Calendar'][vtranslate('Calendar')]["CALENDAR_CRMID"] = "Record ID"; $EventModel = Vtiger_Module_Model::getInstance('Events'); } foreach ($Blocks as $block_label => $block_fields) { $b++; $Options = array(); if ($block_label != "TEMP_MODCOMMENTS_BLOCK") { $optgroup_value = vtranslate($block_label, $module); if ($optgroup_value == $block_label) { $optgroup_value = vtranslate($block_label, 'PDFMaker'); } } else { $optgroup_value = vtranslate("LBL_MODCOMMENTS_INFORMATION", 'PDFMaker'); } $Optgroupts[] = '"' . $optgroup_value . '","' . $b . '"'; if (count($block_fields) > 0) { $field_ids = implode(",", $block_fields); $sql1 = "SELECT * FROM vtiger_field WHERE fieldid IN (" . $field_ids . ")"; $result1 = $adb->query($sql1); while ($row1 = $adb->fetchByAssoc($result1)) { $fieldname = $row1['fieldname']; $fieldlabel = $row1['fieldlabel']; $fieldModel = Vtiger_Field_Model::getInstance($fieldname, $moduleModel); if (!$fieldModel || !$fieldModel->getPermissions('readonly')) { if ($module == 'Calendar') { $eventFieldModel = Vtiger_Field_Model::getInstance($fieldname, $EventModel); if (!$eventFieldModel || !$eventFieldModel->getPermissions('readonly')) { continue; } } else { continue; } } $option_key = strtoupper($module . "_" . $fieldname); if (isset($current_mod_strings[$fieldlabel]) and $current_mod_strings[$fieldlabel] != "") { $option_value = $current_mod_strings[$fieldlabel]; } elseif (isset($app_strings[$fieldlabel]) and $app_strings[$fieldlabel] != "") { $option_value = $app_strings[$fieldlabel]; } else { $option_value = $fieldlabel; } if ($module == 'Calendar') { if ($option_key == 'CALENDAR_ACTIVITYTYPE' || $option_key == 'CALENDAR_DUE_DATE') { $Convert_ModuleFields['Calendar|1'] .= ',"' . $option_value . '","' . $option_key . '"'; $SelectModuleFields['Calendar'][vtranslate('Calendar')][$option_key] = $option_value; continue; } elseif (!isset($Existing_ModuleFields[$option_key])) { $Existing_ModuleFields[$option_key] = $optgroup_value; } else { $Convert_ModuleFields['Calendar|1'] .= ',"' . $option_value . '","' . $option_key . '"'; $SelectModuleFields['Calendar'][vtranslate('Calendar')][$option_key] = $option_value; $Unset_Module_Fields[] = '"' . $option_value . '","' . $option_key . '"'; unset($SelectModuleFields['Calendar'][$Existing_ModuleFields[$option_key]][$option_key]); continue; } } $Options[] = '"' . $option_value . '","' . $option_key . '"'; $SelectModuleFields[$module][$optgroup_value][$option_key] = $option_value; } } //variable RECORD ID added if ($b == 1) { $option_value = "Record ID"; $option_key = strtoupper($module . "_CRMID"); $Options[] = '"' . $option_value . '","' . $option_key . '"'; $SelectModuleFields[$module][$optgroup_value][$option_key] = $option_value; $option_value = vtranslate('Created Time') . ' (' . vtranslate('Due Date & Time') . ')'; $option_key = strtoupper($module . "_CREATEDTIME_DATETIME"); $Options[] = '"' . $option_value . '","' . $option_key . '"'; $SelectModuleFields[$module][$optgroup_value][$option_key] = $option_value; $option_value = vtranslate('Modified Time') . ' (' . vtranslate('Due Date & Time') . ')'; $option_key = strtoupper($module . "_MODIFIEDTIME_DATETIME"); $Options[] = '"' . $option_value . '","' . $option_key . '"'; $SelectModuleFields[$module][$optgroup_value][$option_key] = $option_value; } //end if ($block_label == "LBL_TERMS_INFORMATION" && isset($tacModules[$module])) { $option_value = vtranslate("LBL_TAC4YOU", 'PDFMaker'); $option_key = strtoupper($module . "_TAC4YOU"); $Options[] = '"' . $option_value . '","' . $option_key . '"'; $SelectModuleFields[$module][$optgroup_value][$option_key] = $option_value; } if ($block_label == "LBL_DESCRIPTION_INFORMATION" && isset($desc4youModules[$module])) { $option_value = vtranslate("LBL_DESC4YOU", 'PDFMaker'); $option_key = strtoupper($module . "_DESC4YOU"); $Options[] = '"' . $option_value . '","' . $option_key . '"'; $SelectModuleFields[$module][$optgroup_value][$option_key] = $option_value; } //ModComments support if ($block_label == "TEMP_MODCOMMENTS_BLOCK" && in_array($module, $ModCommentsModules) == true) { $option_value = vtranslate("LBL_MODCOMMENTS", 'PDFMaker'); $option_key = strtoupper($module . "_MODCOMMENTS"); $Options[] = '"' . $option_value . '","' . $option_key . '"'; $SelectModuleFields[$module][$optgroup_value][$option_key] = $option_value; } $Convert_RelatedModuleFields[$module . "|" . $b] = implode(",", $Options); $OptionsRelMod = array(); if (($block_label == "LBL_DETAILS_BLOCK" || $block_label == "LBL_ITEM_DETAILS") && ($module == "Quotes" || $module == "Invoice" || $module == "SalesOrder" || $module == "PurchaseOrder" || $module == "Issuecards" || $module == "Receiptcards" || $module == "Creditnote" || $module == "StornoInvoice")) { foreach ($More_Fields as $variable => $variable_name) { $variable_key = strtoupper($variable); $Options[] = '"' . $variable_name . '","' . $variable_key . '"'; $SelectModuleFields[$module][$optgroup_value][$variable_key] = $variable_name; if ($variable_key != "VATBLOCK") { $OptionsRelMod[] = '"' . $variable_name . '","' . strtoupper($module) . '_' . $variable_key . '"'; } } } //this concatenation is because of need to have extra Details block in Inventory modules which are as related modules $Convert_RelatedModuleFields[$module . "|" . $b] .= implode(',', $OptionsRelMod); $Convert_ModuleFields[$module . "|" . $b] = implode(",", $Options); } if ($module == 'Calendar') { $Convert_ModuleFields['Calendar|1'] = str_replace(',"Record ID","CALENDAR_CRMID",', "", $Convert_ModuleFields['Calendar|1']); $Convert_ModuleFields['Calendar|1'] .= ',"Record ID","CALENDAR_CRMID"'; unset($SelectModuleFields['Calendar'][vtranslate('Calendar')]["CALENDAR_CRMID"]); $SelectModuleFields['Calendar'][vtranslate('Calendar')]["CALENDAR_CRMID"] = "Record ID"; } $Convert_ModuleBlocks[$module] = implode(",", $Optgroupts); } foreach ($Convert_ModuleFields as $cmf_key => $cmf_value) { if (substr($cmf_key, 0, 9) == 'Calendar|' && $cmf_key != 'Calendar|1') { foreach ($Unset_Module_Fields as $to_unset) { $cmf_value = str_replace($to_unset, '', $cmf_value); $cmf_value = str_replace(",,", ',', $cmf_value); $Convert_ModuleFields[$cmf_key] = trim($cmf_value, ','); } } } $viewer->assign("MODULE_BLOCKS", $Convert_ModuleBlocks); $viewer->assign("RELATED_MODULE_FIELDS", $Convert_RelatedModuleFields); $viewer->assign("MODULE_FIELDS", $Convert_ModuleFields); //Product block fields start // Product bloc templates $sql = "SELECT * FROM vtiger_pdfmaker_productbloc_tpl"; $result = $adb->query($sql); $Productbloc_tpl[""] = vtranslate("LBL_PLS_SELECT", 'PDFMaker'); while ($row = $adb->fetchByAssoc($result)) { $Productbloc_tpl[$row["body"]] = $row["name"]; } $viewer->assign("PRODUCT_BLOC_TPL", $Productbloc_tpl); $ProductBlockFields = $PDFMaker->GetProductBlockFields(); foreach ($ProductBlockFields as $viewer_key => $pbFields) { $viewer->assign($viewer_key, $pbFields); } //Product block fields end $viewer->assign("SELECT_MODULE_FIELD", $SelectModuleFields[$select_module]); $smf_filename = $SelectModuleFields[$select_module]; unset($smf_filename["Details"]); $viewer->assign("SELECT_MODULE_FIELD_FILENAME", $smf_filename); $version_type = ucfirst($PDFMaker->GetVersionType()); $viewer->assign("VERSION", $version_type . " " . PDFMaker_Version_Helper::$version); $category = getParentTab(); $viewer->assign("CATEGORY", $category); $viewer->view('Edit.tpl', 'PDFMaker'); }
/** * Whether the module should be turned on Wysiwyg * @param string $moduleName Module Name * @return boolean|int */ public function isWysiwygType($moduleName) { if (!$moduleName) { return false; } $cache = Vtiger_Cache::get('InventoryIsWysiwygType', $moduleName); if ($cache) { return $cache; } $return = 0; $moduleModel = Vtiger_Module_Model::getInstance($moduleName); $fieldModel = Vtiger_Field_Model::getInstance('description', $moduleModel); if ($fieldModel && $fieldModel->get('uitype') == '300') { $return = 1; } Vtiger_Cache::set('InventoryIsWysiwygType', $moduleName, $return); return $return; }
/** * 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(); $moduleName = $this->getModule()->get('name'); $moduleFocus = CRMEntity::getInstance($moduleName); $moduleModel = Vtiger_Module_Model::getInstance($moduleName); $queryGenerator = $this->get('query_generator'); $listViewContoller = $this->get('listview_controller'); $searchParams = $this->get('search_params'); if (empty($searchParams)) { $searchParams = array(); } $glue = ""; if (count($queryGenerator->getWhereFields()) > 0 && (count($searchParams)) > 0) { $glue = QueryGenerator::$AND; } $queryGenerator->parseAdvFilterList($searchParams, $glue); $searchKey = $this->get('search_key'); $searchValue = $this->get('search_value'); $operator = $this->get('operator'); if (!empty($searchKey)) { $queryGenerator->addUserSearchConditions(array('search_field' => $searchKey, 'search_text' => $searchValue, 'operator' => $operator)); } $orderBy = $this->getForSql('orderby'); $sortOrder = $this->getForSql('sortorder'); //List view will be displayed on recently created/modified records if (empty($orderBy) && empty($sortOrder) && $moduleName != "Users") { $orderBy = 'modifiedtime'; $sortOrder = 'DESC'; } if (!empty($orderBy)) { $columnFieldMapping = $moduleModel->getColumnFieldMapping(); $orderByFieldName = $columnFieldMapping[$orderBy]; $orderByFieldModel = $moduleModel->getField($orderByFieldName); if ($orderByFieldModel && ($orderByFieldModel->isReferenceField() || $orderByFieldModel->getFieldDataType() == Vtiger_Field_Model::CURRENCY_LIST)) { //IF it is reference add it in the where fields so that from clause will be having join of the table $queryGenerator = $this->get('query_generator'); $queryGenerator->addWhereField($orderByFieldName); //$queryGenerator->whereFields[] = $orderByFieldName; } } if (!empty($orderBy) && $orderBy === 'smownerid') { $fieldModel = Vtiger_Field_Model::getInstance('assigned_user_id', $moduleModel); if ($fieldModel->getFieldDataType() == 'owner') { $orderBy = 'COALESCE(' . getSqlForNameInDisplayFormat(['first_name' => 'vtiger_users.first_name', 'last_name' => 'vtiger_users.last_name'], 'Users') . ',vtiger_groups.groupname)'; } } $listQuery = $this->getQuery(); $sourceModule = $this->get('src_module'); $sourceField = $this->get('src_field'); if (!empty($sourceModule)) { if (method_exists($moduleModel, 'getQueryByModuleField')) { $overrideQuery = $moduleModel->getQueryByModuleField($sourceModule, $this->get('src_field'), $this->get('src_record'), $listQuery, $this->get('currency_id')); if (!empty($overrideQuery)) { $listQuery = $overrideQuery; } } } $startIndex = $pagingModel->getStartIndex(); $pageLimit = $pagingModel->getPageLimit(); if (!empty($orderBy)) { if ($orderByFieldModel && $orderByFieldModel->isReferenceField()) { $referenceModules = $orderByFieldModel->getReferenceList(); $referenceNameFieldOrderBy = array(); foreach ($referenceModules as $referenceModuleName) { $referenceModuleModel = Vtiger_Module_Model::getInstance($referenceModuleName); $referenceNameFields = $referenceModuleModel->getNameFields(); $columnList = array(); foreach ($referenceNameFields as $nameField) { $fieldModel = $referenceModuleModel->getField($nameField); $columnList[] = $fieldModel->get('table') . $orderByFieldModel->getName() . '.' . $fieldModel->get('column'); } if (count($columnList) > 1) { $referenceNameFieldOrderBy[] = getSqlForNameInDisplayFormat(array('first_name' => $columnList[0], 'last_name' => $columnList[1]), 'Users') . ' ' . $sortOrder; } else { $referenceNameFieldOrderBy[] = implode('', $columnList) . ' ' . $sortOrder; } } $listQuery .= ' ORDER BY ' . implode(',', $referenceNameFieldOrderBy); } else if ($orderByFieldModel && $orderByFieldModel->getFieldDataType() == Vtiger_Field_Model::CURRENCY_LIST) { $listQuery .= ' ORDER BY ' . $orderByFieldModel->getUITypeModel()->getCurrenyListReferenceFieldName() . ' ' . $sortOrder; } else { $listQuery .= ' ORDER BY ' . $orderBy . ' ' . $sortOrder; } } $viewid = ListViewSession::getCurrentView($moduleName); if (empty($viewid)) { $viewid = $pagingModel->get('viewid'); } $_SESSION['lvs'][$moduleName][$viewid]['start'] = $pagingModel->get('page'); ListViewSession::setSessionQuery($moduleName, $listQuery, $viewid); //For Pricebooks popup in Products and Services Related list if ($sourceField !== 'productsRelatedList') { $listQuery .= " LIMIT $startIndex," . ($pageLimit + 1); } $listResult = $db->pquery($listQuery, array()); $listViewRecordModels = array(); $listViewEntries = $listViewContoller->getListViewRecords($moduleFocus, $moduleName, $listResult); $pagingModel->calculatePageRange($listViewEntries); //To check if next page if ($db->num_rows($listResult) > $pageLimit && $sourceField !== 'productsRelatedList') { array_pop($listViewEntries); $pagingModel->set('nextPageExists', true); } else { $pagingModel->set('nextPageExists', false); } $index = 0; foreach ($listViewEntries as $recordId => $record) { $rawData = $db->query_result_rowdata($listResult, $index++); $record['id'] = $recordId; // Pass through the src_record state to dependent model if ($this->has('src_record')) { $rawData['src_record'] = $this->get('src_record'); } $listViewRecordModels[$recordId] = $moduleModel->getRecordFromArray($record, $rawData); $listViewRecordModels[$recordId]->lockEditView = Users_Privileges_Model::checkLockEdit($moduleName, $recordId); $listViewRecordModels[$recordId]->isPermittedToEditView = Users_Privileges_Model::isPermitted($moduleName, 'EditView', $recordId); $listViewRecordModels[$recordId]->colorList = Settings_DataAccess_Module_Model::executeColorListHandlers($moduleName, $recordId, $listViewRecordModels[$recordId]); } return $listViewRecordModels; }
/** * Function which will give the picklist values for a recurrence field * @param type $fieldName -- string * @return type -- array of values */ public static function getReccurencePicklistValues() { $currentUser = Users_Record_Model::getCurrentUserModel(); $fieldModel = Vtiger_Field_Model::getInstance('recurringtype', Vtiger_Module_Model::getInstance('Events')); if ($fieldModel->isRoleBased() && !$currentUser->isAdminUser()) { $userModel = Users_Record_Model::getCurrentUserModel(); $picklistValues = Vtiger_Util_Helper::getRoleBasedPicklistValues('recurringtype', $userModel->get('roleid')); } else { $picklistValues = Vtiger_Util_Helper::getPickListValues('recurringtype'); } foreach ($picklistValues as $value) { $fieldPickListValues[$value] = vtranslate($value, 'Events'); } return $fieldPickListValues; }