/** * Function adds Products/Services-PriceBooks Relation * @param type $request */ function addListPrice($request) { $sourceModule = $request->getModule(); $sourceRecordId = $request->get('src_record'); $relatedModule = $request->get('related_module'); $relInfos = $request->get('relinfo'); $sourceModuleModel = Vtiger_Module_Model::getInstance($sourceModule); $relatedModuleModel = Vtiger_Module_Model::getInstance($relatedModule); $relationModel = Vtiger_Relation_Model::getInstance($sourceModuleModel, $relatedModuleModel); foreach ($relInfos as $relInfo) { $price = CurrencyField::convertToDBFormat($relInfo['price'], null, true); $relationModel->addListPrice($sourceRecordId, $relInfo['id'], $price); } }
/** * Function to save the custom view record */ public function save() { $db = PearDatabase::getInstance(); $currentUserModel = Users_Record_Model::getCurrentUserModel(); $cvId = $this->getId(); $moduleModel = $this->getModule(); $moduleName = $moduleModel->get('name'); $viewName = $this->get('viewname'); $setDefault = $this->get('setdefault'); $setMetrics = $this->get('setmetrics'); $status = $this->get('status'); if ($status == self::CV_STATUS_PENDING) { if ($currentUserModel->isAdminUser()) { $status = self::CV_STATUS_PUBLIC; } } if (!$cvId) { $cvId = $db->getUniqueID("vtiger_customview"); $this->set('cvid', $cvId); $sql = 'INSERT INTO vtiger_customview(cvid, viewname, setdefault, setmetrics, entitytype, status, userid) VALUES (?,?,?,?,?,?,?)'; $params = array($cvId, $viewName, $setDefault, $setMetrics, $moduleName, $status, $currentUserModel->getId()); $db->pquery($sql, $params); } else { $sql = 'UPDATE vtiger_customview SET viewname=?, setdefault=?, setmetrics=?, status=? WHERE cvid=?'; $params = array($viewName, $setDefault, $setMetrics, $status, $cvId); $db->pquery($sql, $params); $db->pquery('DELETE FROM vtiger_cvcolumnlist WHERE cvid = ?', array($cvId)); $db->pquery('DELETE FROM vtiger_cvstdfilter WHERE cvid = ?', array($cvId)); $db->pquery('DELETE FROM vtiger_cvadvfilter WHERE cvid = ?', array($cvId)); $db->pquery('DELETE FROM vtiger_cvadvfilter_grouping WHERE cvid = ?', array($cvId)); } if ($setDefault == 1) { $query = 'SELECT 1 FROM vtiger_user_module_preferences WHERE userid = ? AND tabid = ?'; $queryParams = array($currentUserModel->getId(), $moduleModel->getId()); $queryResult = $db->pquery($query, $queryParams); if ($db->num_rows($queryResult) > 0) { $updateSql = 'UPDATE vtiger_user_module_preferences SET default_cvid = ? WHERE userid = ? AND tabid = ?'; $updateParams = array($cvId, $currentUserModel->getId(), $moduleModel->getId()); $db->pquery($updateSql, $updateParams); } else { $insertSql = 'INSERT INTO vtiger_user_module_preferences(userid, tabid, default_cvid) VALUES (?,?,?)'; $insertParams = array($currentUserModel->getId(), $moduleModel->getId(), $cvId); $db->pquery($insertSql, $insertParams); } } else { $deleteSql = 'DELETE FROM vtiger_user_module_preferences WHERE userid = ? AND tabid = ? AND default_cvid = ?'; $deleteParams = array($currentUserModel->getId(), $moduleModel->getId(), $cvId); $db->pquery($deleteSql, $deleteParams); } $selectedColumnsList = $this->get('columnslist'); if (!empty($selectedColumnsList)) { $noOfColumns = count($selectedColumnsList); for ($i = 0; $i < $noOfColumns; $i++) { $columnSql = 'INSERT INTO vtiger_cvcolumnlist (cvid, columnindex, columnname) VALUES (?,?,?)'; $columnParams = array($cvId, $i, $selectedColumnsList[$i]); $db->pquery($columnSql, $columnParams); } } else { //no fields were sent so add default All filter columns $defaultModuleFilter = $db->pquery('SELECT cvid FROM vtiger_customview WHERE setdefault = 1 AND entitytype = ?', array($moduleName)); $defaultViewId = $db->query_result($defaultModuleFilter, 0, 'cvid'); //User Specific filterId if (empty($defaultViewId)) { $userDefaultModuleFilter = $db->pquery('SELECT default_cvid FROM vtiger_user_module_preferences WHERE userid = ? AND tabid = ?', array($currentUserModel->id, $moduleModel->getId())); $defaultViewId = $db->query_result($userDefaultModuleFilter, 0, 'default_cvid'); } //First filterid of module if (empty($defaultViewId)) { $firstDefaultFilter = $db->pquery('SELECT cvid FROM vtiger_customview WHERE entitytype = ?', array($moduleName)); $defaultViewId = $db->query_result($firstDefaultFilter, 0, 'cvid'); } // Get the defaults filters columnlist $columnSql = "INSERT INTO vtiger_cvcolumnlist (cvid, columnindex, columnname)\n\t\t\t\t\t\t\tSELECT ?, columnindex, columnname FROM vtiger_cvcolumnlist WHERE cvid = ?"; $db->pquery($columnSql, array($cvId, $defaultViewId)); } $stdFilterList = $this->get('stdfilterlist'); if (!empty($stdFilterList) && !empty($stdFilterList['columnname'])) { $stdFilterSql = 'INSERT INTO vtiger_cvstdfilter(cvid,columnname,stdfilter,startdate,enddate) VALUES (?,?,?,?,?)'; $stdFilterParams = array($cvId, $stdFilterList['columnname'], $stdFilterList['stdfilter'], $db->formatDate($stdFilterList['startdate'], true), $db->formatDate($stdFilterList['enddate'], true)); $db->pquery($stdFilterSql, $stdFilterParams); } $advFilterList = $this->get('advfilterlist'); if (!empty($advFilterList)) { foreach ($advFilterList as $groupIndex => $groupInfo) { if (empty($groupInfo)) { continue; } $groupColumns = $groupInfo['columns']; $groupCondition = $groupInfo['condition']; foreach ($groupColumns as $columnIndex => $columnCondition) { if (empty($columnCondition)) { continue; } $advFilterColumn = $columnCondition['columnname']; $advFilterComparator = $columnCondition['comparator']; $advFitlerValue = $columnCondition['value']; $advFilterColumnCondition = $columnCondition['column_condition']; $columnInfo = explode(":", $advFilterColumn); $fieldName = $columnInfo[2]; $fieldModel = $moduleModel->getField($fieldName); //Required if Events module fields are selected for the condition if (!$fieldModel) { $modulename = $moduleModel->get('name'); if ($modulename == 'Calendar') { $eventModuleModel = Vtiger_Module_model::getInstance('Events'); $fieldModel = $eventModuleModel->getField($fieldName); } } $fieldType = $fieldModel->getFieldDataType(); if ($fieldType == 'currency') { if ($fieldModel->get('uitype') == '72') { // Some of the currency fields like Unit Price, Totoal , Sub-total - doesn't need currency conversion during save $advFitlerValue = CurrencyField::convertToDBFormat($advFitlerValue, null, true); } else { $advFitlerValue = CurrencyField::convertToDBFormat($advFitlerValue); } } $temp_val = explode(",", $advFitlerValue); if (($fieldType == 'date' || $fieldType == 'time' && $fieldName != 'time_start' && $fieldName != 'time_end' || $fieldType == 'datetime') && ($fieldType != '' && $advFitlerValue != '')) { $val = array(); for ($x = 0; $x < count($temp_val); $x++) { //if date and time given then we have to convert the date and //leave the time as it is, if date only given then temp_time //value will be empty if (trim($temp_val[$x]) != '') { $date = new DateTimeField(trim($temp_val[$x])); if ($fieldType == 'date') { $val[$x] = DateTimeField::convertToDBFormat(trim($temp_val[$x])); } elseif ($fieldType == 'datetime') { $val[$x] = $date->getDBInsertDateTimeValue(); } else { $val[$x] = $date->getDBInsertTimeValue(); } } } $advFitlerValue = implode(",", $val); } $advCriteriaSql = 'INSERT INTO vtiger_cvadvfilter(cvid,columnindex,columnname,comparator,value,groupid,column_condition) values (?,?,?,?,?,?,?)'; $advCriteriaParams = array($cvId, $columnIndex, $advFilterColumn, $advFilterComparator, $advFitlerValue, $groupIndex, $advFilterColumnCondition); $db->pquery($advCriteriaSql, $advCriteriaParams); // Update the condition expression for the group to which the condition column belongs $groupConditionExpression = ''; if (!empty($advFilterList[$groupIndex]["conditionexpression"])) { $groupConditionExpression = $advFilterList[$groupIndex]["conditionexpression"]; } $groupConditionExpression = $groupConditionExpression . ' ' . $columnIndex . ' ' . $advFilterColumnCondition; $advFilterList[$groupIndex]["conditionexpression"] = $groupConditionExpression; } $groupConditionExpression = $advFilterList[$groupIndex]["conditionexpression"]; if (empty($groupConditionExpression)) { continue; } // Case when the group doesn't have any column criteria $advGroupSql = 'INSERT INTO vtiger_cvadvfilter_grouping(groupid,cvid,group_condition,condition_expression) VALUES (?,?,?,?)'; $advGroupParams = array($groupIndex, $cvId, $groupCondition, $groupConditionExpression); $db->pquery($advGroupSql, $advGroupParams); } } }
public function addUserSearchConditions($input) { global $log, $default_charset; if ($input['searchtype'] == 'advance') { $json = new Zend_Json(); $advft_criteria = $_REQUEST['advft_criteria']; if (!empty($advft_criteria)) { $advft_criteria = $json->decode($advft_criteria); } $advft_criteria_groups = $_REQUEST['advft_criteria_groups']; if (!empty($advft_criteria_groups)) { $advft_criteria_groups = $json->decode($advft_criteria_groups); } if (empty($advft_criteria) || count($advft_criteria) <= 0) { return; } $advfilterlist = getAdvancedSearchCriteriaList($advft_criteria, $advft_criteria_groups, $this->getModule()); if (empty($advfilterlist) || count($advfilterlist) <= 0) { return; } if ($this->conditionInstanceCount > 0) { $this->startGroup(self::$AND); } else { $this->startGroup(''); } foreach ($advfilterlist as $groupindex => $groupcolumns) { $filtercolumns = $groupcolumns['columns']; if (count($filtercolumns) > 0) { $this->startGroup(''); foreach ($filtercolumns as $index => $filter) { $name = explode(':', $filter['columnname']); if (empty($name[2]) && $name[1] == 'crmid' && $name[0] == 'vtiger_crmentity') { $name = $this->getSQLColumn('id'); } else { $name = $name[2]; } $this->addCondition($name, $filter['value'], $filter['comparator']); $columncondition = $filter['column_condition']; if (!empty($columncondition)) { $this->addConditionGlue($columncondition); } } $this->endGroup(); $groupConditionGlue = $groupcolumns['condition']; if (!empty($groupConditionGlue)) { $this->addConditionGlue($groupConditionGlue); } } } $this->endGroup(); } elseif ($input['type'] == 'dbrd') { if ($this->conditionInstanceCount > 0) { $this->startGroup(self::$AND); } else { $this->startGroup(''); } $allConditionsList = $this->getDashBoardConditionList(); $conditionList = $allConditionsList['conditions']; $relatedConditionList = $allConditionsList['relatedConditions']; $noOfConditions = count($conditionList); $noOfRelatedConditions = count($relatedConditionList); foreach ($conditionList as $index => $conditionInfo) { $this->addCondition($conditionInfo['fieldname'], $conditionInfo['value'], $conditionInfo['operator']); if ($index < $noOfConditions - 1 || $noOfRelatedConditions > 0) { $this->addConditionGlue(self::$AND); } } foreach ($relatedConditionList as $index => $conditionInfo) { $this->addRelatedModuleCondition($conditionInfo['relatedModule'], $conditionInfo['conditionModule'], $conditionInfo['finalValue'], $conditionInfo['SQLOperator']); if ($index < $noOfRelatedConditions - 1) { $this->addConditionGlue(self::$AND); } } $this->endGroup(); } else { if (isset($input['search_field']) && $input['search_field'] != "") { $fieldName = vtlib_purify($input['search_field']); } else { return; } if ($this->conditionInstanceCount > 0) { $this->startGroup(self::$AND); } else { $this->startGroup(''); } $moduleFields = $this->getModuleFields(); $field = $moduleFields[$fieldName]; $type = $field->getFieldDataType(); if (isset($input['search_text']) && $input['search_text'] != "") { // search other characters like "|, ?, ?" by jagi $value = $input['search_text']; $stringConvert = function_exists(iconv) ? @iconv("UTF-8", $default_charset, $value) : $value; if (!$this->isStringType($type)) { $value = trim($stringConvert); } if ($type == 'picklist') { global $mod_strings; // Get all the keys for the for the Picklist value $mod_keys = array_keys($mod_strings, $value); if (sizeof($mod_keys) >= 1) { // Iterate on the keys, to get the first key which doesn't start with LBL_ (assuming it is not used in PickList) foreach ($mod_keys as $mod_idx => $mod_key) { $stridx = strpos($mod_key, 'LBL_'); // Use strict type comparision, refer strpos for more details if ($stridx !== 0) { $value = $mod_key; break; } } } } if ($type == 'currency') { // Some of the currency fields like Unit Price, Total, Sub-total etc of Inventory modules, do not need currency conversion if ($field->getUIType() == '72') { $value = CurrencyField::convertToDBFormat($value, null, true); } else { $currencyField = new CurrencyField($value); $value = $currencyField->getDBInsertedValue(); } } } if (!empty($input['operator'])) { $operator = $input['operator']; } elseif (trim(strtolower($value)) == 'null') { $operator = 'e'; } else { if (!$this->isNumericType($type) && !$this->isDateType($type)) { $operator = 'c'; } else { $operator = 'h'; } } $this->addCondition($fieldName, $value, $operator); $this->endGroup(); } }
$value = explode("=", $fieldvalue); $field_name_val = $value[0]; $field_value = urldecode($value[1]); $finfo = VTCacheUtils::lookupFieldInfo($tabid, $field_name_val); if ($finfo !== false) { switch ($finfo['uitype']) { case '56': $field_value = $field_value == 'on' ? '1' : '0'; break; case '7': case '9': case '72': $field_value = CurrencyField::convertToDBFormat($field_value, null, true); break; case '71': $field_value = CurrencyField::convertToDBFormat($field_value); break; case '33': case '3313': if (is_array($field_value)) { $field_value = implode(' |##| ', $field_value); } break; } } $focus->column_fields[$field_name_val] = $field_value; } } $errormessageclass = isset($_REQUEST['error_msgclass']) ? vtlib_purify($_REQUEST['error_msgclass']) : ''; $errormessage = isset($_REQUEST['error_msg']) ? vtlib_purify($_REQUEST['error_msg']) : ''; $smarty->assign('ERROR_MESSAGE_CLASS', $errormessageclass);
/** * Get the value to save * @param Vtiger_Request $request * @param string $field Field name * @param int $i Sequence number * @return string */ public function getValueForSave($request, $field, $i) { $value = ''; if ($request->has($field . $i)) { $value = $request->get($field . $i); } else { if ($request->has($field)) { $value = $request->get($field); } } if (in_array($field, $this->jsonFields) && $value != '') { $value = json_encode($value); } if (in_array($field, ['price', 'gross', 'net', 'discount', 'purchase', 'margin', 'marginp', 'tax', 'total'])) { $value = CurrencyField::convertToDBFormat($value, null, true); } return $value; }
<?php /*+******************************************************************************** * The contents of this file are subject to the vtiger CRM Public License Version 1.0 * ("License"); You may not use this file except in compliance with the License * The Original Code is: vtiger CRM Open Source * The Initial Developer of the Original Code is vtiger. * Portions created by vtiger are Copyright (C) vtiger. * All Rights Reserved. *********************************************************************************/ global $adb, $log; $record = vtlib_purify($_REQUEST['record']); $pricebook_id = vtlib_purify($_REQUEST['pricebook_id']); $product_id = vtlib_purify($_REQUEST['product_id']); $listprice = vtlib_purify($_REQUEST['list_price']); $return_action = vtlib_purify($_REQUEST['return_action']); $return_module = vtlib_purify($_REQUEST['return_module']); $log->debug("Update ListPrice in (modules/Products/UpdateListPrice.php): {$pricebook_id} {$product_id} {$listprice}"); $query = 'update vtiger_pricebookproductrel set listprice=? where pricebookid=? and productid=?'; $listprice = CurrencyField::convertToDBFormat($listprice, null, true); $adb->pquery($query, array($listprice, $pricebook_id, $product_id)); header("Location: index.php?module={$return_module}&action=" . $return_module . "Ajax&file={$return_action}&ajax=true&record={$record}");
public function transformForImport($fieldData, $moduleMeta, $fillDefault = true, $checkMandatoryFieldValues = true) { $moduleFields = $moduleMeta->getModuleFields(); $defaultFieldValues = $this->getDefaultFieldValues($moduleMeta); foreach ($fieldData as $fieldName => $fieldValue) { $fieldInstance = $moduleFields[$fieldName]; if ($fieldInstance->getFieldDataType() == 'owner') { $ownerId = getUserId_Ol(trim($fieldValue)); if (empty($ownerId)) { $ownerId = getGrpId($fieldValue); } if (empty($ownerId) && isset($defaultFieldValues[$fieldName])) { $ownerId = $defaultFieldValues[$fieldName]; } if (empty($ownerId) || !Import_Utils_Helper::hasAssignPrivilege($moduleMeta->getEntityName(), $ownerId)) { $ownerId = $this->user->id; } $fieldData[$fieldName] = $ownerId; } elseif ($fieldInstance->getFieldDataType() == 'multipicklist') { $trimmedValue = trim($fieldValue); if (!$trimmedValue && isset($defaultFieldValues[$fieldName])) { $explodedValue = explode(',', $defaultFieldValues[$fieldName]); } else { $explodedValue = explode(' |##| ', $trimmedValue); } foreach ($explodedValue as $key => $value) { $explodedValue[$key] = trim($value); } $implodeValue = implode(' |##| ', $explodedValue); $fieldData[$fieldName] = $implodeValue; } elseif ($fieldInstance->getFieldDataType() == 'reference') { $entityId = false; if (!empty($fieldValue)) { if (strpos($fieldValue, '::::') > 0) { $fieldValueDetails = explode('::::', $fieldValue); } else { if (strpos($fieldValue, ':::') > 0) { $fieldValueDetails = explode(':::', $fieldValue); } else { $fieldValueDetails = $fieldValue; } } if (count($fieldValueDetails) > 1) { $referenceModuleName = trim($fieldValueDetails[0]); $entityLabel = trim($fieldValueDetails[1]); $entityId = getEntityId($referenceModuleName, $entityLabel); } else { $referencedModules = $fieldInstance->getReferenceList(); $entityLabel = $fieldValue; foreach ($referencedModules as $referenceModule) { $referenceModuleName = $referenceModule; if ($referenceModule == 'Users') { $referenceEntityId = getUserId_Ol($entityLabel); if (empty($referenceEntityId) || !Import_Utils_Helper::hasAssignPrivilege($moduleMeta->getEntityName(), $referenceEntityId)) { $referenceEntityId = $this->user->id; } } elseif ($referenceModule == 'Currency') { $referenceEntityId = getCurrencyId($entityLabel); } else { $referenceEntityId = getEntityId($referenceModule, $entityLabel); } if ($referenceEntityId != 0) { $entityId = $referenceEntityId; break; } } } if ((empty($entityId) || $entityId == 0) && !empty($referenceModuleName)) { if (isPermitted($referenceModuleName, 'EditView') == 'yes') { try { $wsEntityIdInfo = $this->createEntityRecord($referenceModuleName, $entityLabel); $wsEntityId = $wsEntityIdInfo['id']; $entityIdComponents = vtws_getIdComponents($wsEntityId); $entityId = $entityIdComponents[1]; } catch (Exception $e) { $entityId = false; } } } $fieldData[$fieldName] = $entityId; } else { $referencedModules = $fieldInstance->getReferenceList(); if ($referencedModules[0] == 'Users') { if (isset($defaultFieldValues[$fieldName])) { $fieldData[$fieldName] = $defaultFieldValues[$fieldName]; } if (empty($fieldData[$fieldName]) || !Import_Utils_Helper::hasAssignPrivilege($moduleMeta->getEntityName(), $fieldData[$fieldName])) { $fieldData[$fieldName] = $this->user->id; } } else { $fieldData[$fieldName] = ''; } } } elseif ($fieldInstance->getFieldDataType() == 'picklist') { $fieldValue = trim($fieldValue); global $default_charset; if (empty($fieldValue) && isset($defaultFieldValues[$fieldName])) { $fieldData[$fieldName] = $fieldValue = $defaultFieldValues[$fieldName]; } $olderCacheEnable = Vtiger_Cache::$cacheEnable; Vtiger_Cache::$cacheEnable = false; if (!isset($this->allPicklistValues[$fieldName])) { $this->allPicklistValues[$fieldName] = $fieldInstance->getPicklistDetails(); } $allPicklistDetails = $this->allPicklistValues[$fieldName]; $allPicklistValues = array(); foreach ($allPicklistDetails as $picklistDetails) { $allPicklistValues[] = $picklistDetails['value']; } $picklistValueInLowerCase = strtolower(htmlentities($fieldValue, ENT_QUOTES, $default_charset)); $allPicklistValuesInLowerCase = array_map('strtolower', $allPicklistValues); $picklistDetails = array_combine($allPicklistValuesInLowerCase, $allPicklistValues); if (!in_array($picklistValueInLowerCase, $allPicklistValuesInLowerCase)) { $moduleObject = Vtiger_Module::getInstance($moduleMeta->getEntityName()); $fieldObject = Vtiger_Field::getInstance($fieldName, $moduleObject); $fieldObject->setPicklistValues(array($fieldValue)); unset($this->allPicklistValues[$fieldName]); } else { $fieldData[$fieldName] = $picklistDetails[$picklistValueInLowerCase]; } Vtiger_Cache::$cacheEnable = $olderCacheEnable; } else { if ($fieldInstance->getFieldDataType() == 'currency') { // While exporting we are exporting as user format, we should import as db format while importing $fieldData[$fieldName] = CurrencyField::convertToDBFormat($fieldValue, $current_user, false); } else { if ($fieldInstance->getFieldDataType() == 'datetime' && !empty($fieldValue)) { if ($fieldValue == null || $fieldValue == '0000-00-00 00:00:00') { $fieldValue = ''; } $valuesList = explode(' ', $fieldValue); if (count($valuesList) == 1) { $fieldValue = ''; } $fieldValue = getValidDBInsertDateTimeValue($fieldValue); if (preg_match("/^[0-9]{2,4}[-][0-1]{1,2}?[0-9]{1,2}[-][0-3]{1,2}?[0-9]{1,2} ([0-1][0-9]|[2][0-3])([:][0-5][0-9]){1,2}\$/", $fieldValue) == 0) { $fieldValue = ''; } $fieldData[$fieldName] = $fieldValue; } if ($fieldInstance->getFieldDataType() == 'date' && !empty($fieldValue)) { if ($fieldValue == null || $fieldValue == '0000-00-00') { $fieldValue = ''; } $fieldValue = getValidDBInsertDateValue($fieldValue); if (preg_match("/^[0-9]{2,4}[-][0-1]{1,2}?[0-9]{1,2}[-][0-3]{1,2}?[0-9]{1,2}\$/", $fieldValue) == 0) { $fieldValue = ''; } $fieldData[$fieldName] = $fieldValue; } if (empty($fieldValue) && isset($defaultFieldValues[$fieldName])) { $fieldData[$fieldName] = $fieldValue = $defaultFieldValues[$fieldName]; } } } } if ($fillDefault) { foreach ($defaultFieldValues as $fieldName => $fieldValue) { if (!isset($fieldData[$fieldName])) { $fieldData[$fieldName] = $defaultFieldValues[$fieldName]; } } } // We should sanitizeData before doing final mandatory check below. $fieldData = DataTransform::sanitizeData($fieldData, $moduleMeta); if ($fieldData != null && $checkMandatoryFieldValues) { foreach ($moduleFields as $fieldName => $fieldInstance) { if (empty($fieldData[$fieldName]) && $fieldInstance->isMandatory()) { return null; } } } return $fieldData; }
/** Function to insert values in the specifed table for the specified module * @param $table_name -- table name:: Type varchar * @param $module -- module:: Type varchar */ function insertIntoEntityTable($table_name, $module, $fileid = '') { global $log; global $current_user, $app_strings; $log->info("function insertIntoEntityTable " . $module . ' vtiger_table name ' . $table_name); global $adb; $insertion_mode = $this->mode; //Checkin whether an entry is already is present in the vtiger_table to update if ($insertion_mode == 'edit') { $tablekey = $this->tab_name_index[$table_name]; // Make selection on the primary key of the module table to check. $check_query = "select {$tablekey} from {$table_name} where {$tablekey}=?"; $check_result = $adb->pquery($check_query, array($this->id)); $num_rows = $adb->num_rows($check_result); if ($num_rows <= 0) { $insertion_mode = ''; } } $tabid = getTabid($module); if ($module == 'Calendar' && $this->column_fields["activitytype"] != null && $this->column_fields["activitytype"] != 'Task') { $tabid = getTabid('Events'); } if ($insertion_mode == 'edit') { $update = array(); $update_params = array(); checkFileAccessForInclusion('user_privileges/user_privileges_' . $current_user->id . '.php'); require 'user_privileges/user_privileges_' . $current_user->id . '.php'; if ($is_admin == true || $profileGlobalPermission[1] == 0 || $profileGlobalPermission[2] == 0) { $sql = "select * from vtiger_field where tabid in (" . generateQuestionMarks($tabid) . ") and tablename=? and displaytype in (1,3) and presence in (0,2) group by columnname"; $params = array($tabid, $table_name); } else { $profileList = getCurrentUserProfileList(); if (count($profileList) > 0) { $sql = "SELECT *\n\t\t\t \t\t\tFROM vtiger_field\n\t\t\t \t\t\tINNER JOIN vtiger_profile2field\n\t\t\t \t\t\tON vtiger_profile2field.fieldid = vtiger_field.fieldid\n\t\t\t \t\t\tINNER JOIN vtiger_def_org_field\n\t\t\t \t\t\tON vtiger_def_org_field.fieldid = vtiger_field.fieldid\n\t\t\t \t\t\tWHERE vtiger_field.tabid = ?\n\t\t\t \t\t\tAND vtiger_profile2field.visible = 0 AND vtiger_profile2field.readonly = 0\n\t\t\t \t\t\tAND vtiger_profile2field.profileid IN (" . generateQuestionMarks($profileList) . ")\n\t\t\t \t\t\tAND vtiger_def_org_field.visible = 0 and vtiger_field.tablename=? and vtiger_field.displaytype in (1,3) and vtiger_field.presence in (0,2) group by columnname"; $params = array($tabid, $profileList, $table_name); } else { $sql = "SELECT *\n\t\t\t \t\t\tFROM vtiger_field\n\t\t\t \t\t\tINNER JOIN vtiger_profile2field\n\t\t\t \t\t\tON vtiger_profile2field.fieldid = vtiger_field.fieldid\n\t\t\t \t\t\tINNER JOIN vtiger_def_org_field\n\t\t\t \t\t\tON vtiger_def_org_field.fieldid = vtiger_field.fieldid\n\t\t\t \t\t\tWHERE vtiger_field.tabid = ?\n\t\t\t \t\t\tAND vtiger_profile2field.visible = 0 AND vtiger_profile2field.readonly = 0\n\t\t\t \t\t\tAND vtiger_def_org_field.visible = 0 and vtiger_field.tablename=? and vtiger_field.displaytype in (1,3) and vtiger_field.presence in (0,2) group by columnname"; $params = array($tabid, $table_name); } } } else { $table_index_column = $this->tab_name_index[$table_name]; if ($table_index_column == 'id' && $table_name == 'vtiger_users') { $currentuser_id = $adb->getUniqueID("vtiger_users"); $this->id = $currentuser_id; } $column = array($table_index_column); $value = array($this->id); $sql = "select * from vtiger_field where tabid=? and tablename=? and displaytype in (1,3,4) and vtiger_field.presence in (0,2)"; $params = array($tabid, $table_name); } // Attempt to re-use the quer-result to avoid reading for every save operation // TODO Need careful analysis on impact ... MEMORY requirement might be more static $_privatecache = array(); $cachekey = "{$insertion_mode}-" . implode(',', $params); if (!isset($_privatecache[$cachekey])) { $result = $adb->pquery($sql, $params); $noofrows = $adb->num_rows($result); if (CRMEntity::isBulkSaveMode()) { $cacheresult = array(); for ($i = 0; $i < $noofrows; ++$i) { $cacheresult[] = $adb->fetch_array($result); } $_privatecache[$cachekey] = $cacheresult; } } else { // Useful when doing bulk save $result = $_privatecache[$cachekey]; $noofrows = count($result); } for ($i = 0; $i < $noofrows; $i++) { $fieldname = $this->resolve_query_result_value($result, $i, "fieldname"); $columname = $this->resolve_query_result_value($result, $i, "columnname"); $uitype = $this->resolve_query_result_value($result, $i, "uitype"); $generatedtype = $this->resolve_query_result_value($result, $i, "generatedtype"); $typeofdata = $this->resolve_query_result_value($result, $i, "typeofdata"); $typeofdata_array = explode("~", $typeofdata); $datatype = $typeofdata_array[0]; $ajaxSave = false; if ($_REQUEST['file'] == 'DetailViewAjax' && $_REQUEST['ajxaction'] == 'DETAILVIEW' && isset($_REQUEST["fldName"]) && $_REQUEST["fldName"] != $fieldname || $_REQUEST['action'] == 'MassEditSave' && !isset($_REQUEST[$fieldname . "_mass_edit_check"])) { $ajaxSave = true; } if ($uitype == 4 && $insertion_mode != 'edit') { $fldvalue = ''; // Bulk Save Mode: Avoid generation of module sequence number, take care later. // SalesPlatform.ru begin: Added separate numbering for self organizations if (!CRMEntity::isBulkSaveMode()) { $modules = array('Invoice', 'Act', 'Consignment'); if (in_array($module, $modules) && isset($this->column_fields['spcompany'])) { $fldvalue = $this->setModuleSeqNumber("increment", $module, '', '', $this->column_fields['spcompany']); } else { $fldvalue = $this->setModuleSeqNumber("increment", $module); } //$fldvalue = $this->setModuleSeqNumber("increment", $module); } // SalesPlatform.ru end $this->column_fields[$fieldname] = $fldvalue; } if (isset($this->column_fields[$fieldname])) { if ($uitype == 56) { if ($this->column_fields[$fieldname] == 'on' || $this->column_fields[$fieldname] == 1) { $fldvalue = '1'; } else { $fldvalue = '0'; } } elseif ($uitype == 15 || $uitype == 16) { if ($this->column_fields[$fieldname] == $app_strings['LBL_NOT_ACCESSIBLE']) { //If the value in the request is Not Accessible for a picklist, the existing value will be replaced instead of Not Accessible value. $sql = "select {$columname} from {$table_name} where " . $this->tab_name_index[$table_name] . "=?"; $res = $adb->pquery($sql, array($this->id)); $pick_val = $adb->query_result($res, 0, $columname); $fldvalue = $pick_val; } else { $fldvalue = $this->column_fields[$fieldname]; } } elseif ($uitype == 33) { if (is_array($this->column_fields[$fieldname])) { $field_list = implode(' |##| ', $this->column_fields[$fieldname]); } else { $field_list = $this->column_fields[$fieldname]; } if ($field_list == '') { $fldvalue = NULL; } else { $fldvalue = $field_list; } } elseif ($uitype == 5 || $uitype == 6 || $uitype == 23) { //Added to avoid function call getDBInsertDateValue in ajax save if (isset($current_user->date_format) && !$ajaxSave) { $fldvalue = getValidDBInsertDateValue($this->column_fields[$fieldname]); } else { $fldvalue = $this->column_fields[$fieldname]; } } elseif ($uitype == 7) { //strip out the spaces and commas in numbers if given ie., in amounts there may be , $fldvalue = str_replace(",", "", $this->column_fields[$fieldname]); //trim($this->column_fields[$fieldname],","); } elseif ($uitype == 26) { if (empty($this->column_fields[$fieldname])) { $fldvalue = 1; //the documents will stored in default folder } else { $fldvalue = $this->column_fields[$fieldname]; } } elseif ($uitype == 28) { if ($this->column_fields[$fieldname] == null) { $fileQuery = $adb->pquery("SELECT filename from vtiger_notes WHERE notesid = ?", array($this->id)); $fldvalue = null; if (isset($fileQuery)) { $rowCount = $adb->num_rows($fileQuery); if ($rowCount > 0) { $fldvalue = decode_html($adb->query_result($fileQuery, 0, 'filename')); } } } else { $fldvalue = decode_html($this->column_fields[$fieldname]); } } elseif ($uitype == 8) { $this->column_fields[$fieldname] = rtrim($this->column_fields[$fieldname], ','); $ids = explode(',', $this->column_fields[$fieldname]); $json = new Zend_Json(); $fldvalue = $json->encode($ids); } elseif ($uitype == 12) { // Bulk Sae Mode: Consider the FROM email address as specified, if not lookup $fldvalue = $this->column_fields[$fieldname]; if (empty($fldvalue)) { $query = "SELECT email1 FROM vtiger_users WHERE id = ?"; $res = $adb->pquery($query, array($current_user->id)); $rows = $adb->num_rows($res); if ($rows > 0) { $fldvalue = $adb->query_result($res, 0, 'email1'); } } // END } elseif ($uitype == 72 && !$ajaxSave) { // Some of the currency fields like Unit Price, Totoal , Sub-total - doesn't need currency conversion during save $fldvalue = CurrencyField::convertToDBFormat($this->column_fields[$fieldname], null, true); } elseif ($uitype == 71 && !$ajaxSave) { $fldvalue = CurrencyField::convertToDBFormat($this->column_fields[$fieldname]); } else { $fldvalue = $this->column_fields[$fieldname]; } if ($uitype != 33 && $uitype != 8) { $fldvalue = from_html($fldvalue, $insertion_mode == 'edit' ? true : false); } } else { $fldvalue = ''; } if ($fldvalue == '') { $fldvalue = $this->get_column_value($columname, $fldvalue, $fieldname, $uitype, $datatype); } if ($insertion_mode == 'edit') { if ($table_name != 'vtiger_ticketcomments' && $uitype != 4) { array_push($update, $columname . "=?"); array_push($update_params, $fldvalue); } } else { array_push($column, $columname); array_push($value, $fldvalue); } } if ($insertion_mode == 'edit') { if ($module == 'Potentials') { $dbquery = 'select sales_stage from vtiger_potential where potentialid = ?'; $sales_stage = $adb->query_result($adb->pquery($dbquery, array($this->id)), 0, 'sales_stage'); if ($sales_stage != $_REQUEST['sales_stage'] && $_REQUEST['sales_stage'] != '') { $date_var = date("Y-m-d H:i:s"); $closingDateField = new DateTimeField($this->column_fields['closingdate']); $closingdate = $_REQUEST['ajxaction'] == 'DETAILVIEW' ? $this->column_fields['closingdate'] : $closingDateField->getDBInsertDateValue(); $sql = "insert into vtiger_potstagehistory values(?,?,?,?,?,?,?,?)"; $params = array('', $this->id, $this->column_fields['amount'], decode_html($sales_stage), $this->column_fields['probability'], 0, $adb->formatDate($closingdate, true), $adb->formatDate($date_var, true)); $adb->pquery($sql, $params); } } elseif ($module == 'PurchaseOrder' || $module == 'SalesOrder' || $module == 'Quotes' || $module == 'Invoice' || $module == 'Act' || $module == 'Consignment') { //elseif ($module == 'PurchaseOrder' || $module == 'SalesOrder' || $module == 'Quotes' || $module == 'Invoice') { // SalesPlatform.ru end //added to update the history for PO, SO, Quotes and Invoice $history_field_array = array("Act" => "sp_actstatus", "Consignment" => "sp_consignmentstatus", "PurchaseOrder" => "postatus", "SalesOrder" => "sostatus", "Quotes" => "quotestage", "Invoice" => "invoicestatus"); $inventory_module = $module; if ($_REQUEST['ajxaction'] == 'DETAILVIEW') { //if we use ajax edit if ($inventory_module == "PurchaseOrder") { $relatedname = getVendorName($this->column_fields['vendor_id']); } else { $relatedname = getAccountName($this->column_fields['account_id']); } $total = $this->column_fields['hdnGrandTotal']; } else { //using edit button and save if ($inventory_module == "PurchaseOrder") { $relatedname = $_REQUEST["vendor_name"]; } else { $relatedname = $_REQUEST["account_name"]; } $total = $_REQUEST['total']; } if ($this->column_fields["{$history_field_array[$inventory_module]}"] == $app_strings['LBL_NOT_ACCESSIBLE']) { //If the value in the request is Not Accessible for a picklist, the existing value will be replaced instead of Not Accessible value. $his_col = $history_field_array[$inventory_module]; $his_sql = "select {$his_col} from {$this->table_name} where " . $this->table_index . "=?"; $his_res = $adb->pquery($his_sql, array($this->id)); $status_value = $adb->query_result($his_res, 0, $his_col); $stat_value = $status_value; } else { $stat_value = $this->column_fields["{$history_field_array[$inventory_module]}"]; } $oldvalue = getSingleFieldValue($this->table_name, $history_field_array[$inventory_module], $this->table_index, $this->id); if ($this->column_fields["{$history_field_array[$inventory_module]}"] != '' && $oldvalue != $stat_value) { addInventoryHistory($inventory_module, $this->id, $relatedname, $total, $stat_value); } } //Check done by Don. If update is empty the the query fails if (count($update) > 0) { $sql1 = "update {$table_name} set " . implode(",", $update) . " where " . $this->tab_name_index[$table_name] . "=?"; array_push($update_params, $this->id); $adb->pquery($sql1, $update_params); } } else { $sql1 = "insert into {$table_name}(" . implode(",", $column) . ") values(" . generateQuestionMarks($value) . ")"; $adb->pquery($sql1, $value); } }
public static function transferListSearchParamsToFilterCondition($listSearchParams, $moduleModel) { if(empty($listSearchParams)) { $listSearchParams = array(); } $advFilterConditionFormat = array(); $glueOrder = array('and','or'); $groupIterator = 0; foreach($listSearchParams as $groupInfo){ if(empty($groupInfo)){ continue; } $groupConditionInfo = array(); $groupColumnsInfo = array(); $groupConditionGlue = $glueOrder[$groupIterator]; foreach($groupInfo as $fieldSearchInfo){ $advFilterFieldInfoFormat = array(); $fieldName = $fieldSearchInfo[0]; $operator = $fieldSearchInfo[1]; $fieldValue = $fieldSearchInfo[2]; $fieldInfo = $moduleModel->getField($fieldName); //Request will be having in terms of AM and PM but the database will be having in 24 hr format so converting //Database format if($fieldInfo->getFieldDataType() == "time") { $fieldValue = Vtiger_Time_UIType::getTimeValueWithSeconds($fieldValue); } if($fieldName == 'amount' && $fieldInfo->getFieldDataType() == 'currency'){ $fieldValue = CurrencyField::convertToDBFormat($fieldValue); } if($fieldName == 'date_start' || $fieldName == 'due_date' || $fieldInfo->getFieldDataType() == "datetime" ) { $dateValues = explode(',', $fieldValue); //Indicate whether it is fist date in the between condition $isFirstDate = true; foreach($dateValues as $key => $dateValue) { $dateTimeCompoenents = explode(' ', $dateValue); if(empty($dateTimeCompoenents[1])) { if($isFirstDate) $dateTimeCompoenents[1] = '00:00:00'; else $dateTimeCompoenents[1] = '23:59:59'; } $dateValue = implode(' ',$dateTimeCompoenents); $dateValues[$key] = $dateValue; $isFirstDate = false; } $fieldValue = implode(',',$dateValues); } $advFilterFieldInfoFormat['columnname'] = $fieldInfo->getCustomViewColumnName(); $advFilterFieldInfoFormat['comparator'] = $operator; $advFilterFieldInfoFormat['value'] = $fieldValue; $advFilterFieldInfoFormat['column_condition'] = $groupConditionGlue; $groupColumnsInfo[] = $advFilterFieldInfoFormat; } $noOfConditions = count($groupColumnsInfo); //to remove the last column condition $groupColumnsInfo[$noOfConditions-1]['column_condition'] = ''; $groupConditionInfo['columns'] = $groupColumnsInfo; $groupConditionInfo['condition'] = 'and'; $advFilterConditionFormat[] = $groupConditionInfo; $groupIterator++; } //We aer removing last condition since this condition if there is next group and this is the last group unset($advFilterConditionFormat[count($advFilterConditionFormat)-1]['condition']); return $advFilterConditionFormat; }
} $adv_filter_column = $column_condition["columnname"]; $adv_filter_comparator = $column_condition["comparator"]; $adv_filter_value = $column_condition["value"]; $adv_filter_column_condition = $column_condition["columncondition"]; $adv_filter_groupid = $column_condition["groupid"]; $column_info = explode(":", $adv_filter_column); $fieldName = $column_info[2]; $fieldObj = $moduleFields[$fieldName]; $fieldType = $fieldObj->getFieldDataType(); if ($fieldType == 'currency') { // Some of the currency fields like Unit Price, Total, Sub-total etc of Inventory modules, do not need currency conversion if ($fieldObj->getUIType() == '72') { $adv_filter_value = CurrencyField::convertToDBFormat($adv_filter_value, null, true); } else { $adv_filter_value = CurrencyField::convertToDBFormat($adv_filter_value); } } $temp_val = explode(",", $adv_filter_value); if (($fieldType == 'date' || $fieldType == 'time' && $fieldName != 'time_start' && $fieldName != 'time_end' || $fieldType == 'datetime') && ($fieldType != '' && $adv_filter_value != '')) { $val = array(); for ($x = 0; $x < count($temp_val); $x++) { //if date and time given then we have to convert the date and //leave the time as it is, if date only given then temp_time //value will be empty if (trim($temp_val[$x]) != '') { $date = new DateTimeField(trim($temp_val[$x])); if ($fieldType == 'date') { $val[$x] = DateTimeField::convertToUserFormat(trim($temp_val[$x])); } elseif ($fieldType == 'datetime') { $val[$x] = $date->getDBInsertDateTimeValue();
foreach ($storearray as $id) { if ($id != '') { $lp_name = $id . '_listprice'; $list_price = CurrencyField::convertToDBFormat($_REQUEST[$lp_name], null, false); //Updating the vtiger_pricebook product rel vtiger_table $log->info("Products :: Inserting vtiger_products to price book"); $query = "insert into vtiger_pricebookproductrel (pricebookid,productid,listprice,usedcurrency) values(?,?,?,?)"; $adb->pquery($query, array($pricebook_id, $id, $list_price, $currency_id)); } } if ($singlepane_view == 'true') { header("Location: index.php?module=PriceBooks&action=DetailView&record={$pricebook_id}&parenttab={$parenttab}"); } else { header("Location: index.php?module=PriceBooks&action=CallRelatedList&record={$pricebook_id}&parenttab={$parenttab}"); } } elseif (isset($_REQUEST['product_id']) && $_REQUEST['product_id'] != '') { //split the string and store in an array $storearray = explode(";", $idlist); foreach ($storearray as $id) { if ($id != '') { $currency_id = getPriceBookCurrency($id); $lp_name = $id . '_listprice'; $list_price = CurrencyField::convertToDBFormat($_REQUEST[$lp_name], null, false); //Updating the vtiger_pricebook product rel vtiger_table $log->info("Products :: Inserting PriceBooks to Product"); $query = "insert into vtiger_pricebookproductrel (pricebookid,productid,listprice,usedcurrency) values(?,?,?,?)"; $adb->pquery($query, array($id, $productid, $list_price, $currency_id)); } } header("Location: index.php?module={$returnmodule}&action={$returnaction}&record={$productid}&parenttab={$parenttab}"); }
/** * Function converts User currency format to database format * @param <Object> $value - Currency value * @param <User Object> $user * @param <Boolean> $skipConversion */ public static function convertToDBFormat($value, $user = null, $skipConversion = false) { return CurrencyField::convertToDBFormat($value, $user, $skipConversion); }
/** * Function converts User currency format to database format * @param <Object> $value - Currency value * @param <User Object> $user * @param <Boolean> $skipConversion */ public static function convertToDBFormat($value, $user = null, $skipConversion = false) { global $log; $log->debug("Entering ./uitypes/Currency.php::staticconvertToDBFormat"); return CurrencyField::convertToDBFormat($value, $user, $skipConversion); }
/** Function to get the RunTime Advanced filter conditions * @ param $advft_criteria : Type Array * @ param $advft_criteria_groups : Type Array * This function returns $advfiltersql * */ function RunTimeAdvFilter($advft_criteria, $advft_criteria_groups) { $adb = PearDatabase::getInstance(); $advfilterlist = array(); $advfiltersql = ''; if (!empty($advft_criteria)) { foreach ($advft_criteria as $column_index => $column_condition) { if (empty($column_condition)) { continue; } $adv_filter_column = $column_condition["columnname"]; $adv_filter_comparator = $column_condition["comparator"]; $adv_filter_value = $column_condition["value"]; $adv_filter_column_condition = $column_condition["columncondition"]; $adv_filter_groupid = $column_condition["groupid"]; $column_info = explode(":", $adv_filter_column); $moduleFieldLabel = $column_info[2]; $fieldName = $column_info[3]; list($module, $fieldLabel) = explode('__', $moduleFieldLabel, 2); $fieldInfo = getFieldByReportLabel($module, $fieldLabel); $fieldType = null; if (!empty($fieldInfo)) { $field = WebserviceField::fromArray($adb, $fieldInfo); $fieldType = $field->getFieldDataType(); } if ($fieldType == 'currency') { // Some of the currency fields like Unit Price, Total, Sub-total etc of Inventory modules, do not need currency conversion if ($field->getUIType() == '72') { $adv_filter_value = CurrencyField::convertToDBFormat($adv_filter_value, null, true); } else { $adv_filter_value = CurrencyField::convertToDBFormat($adv_filter_value); } } $temp_val = explode(",", $adv_filter_value); if (($column_info[4] == 'D' || $column_info[4] == 'T' && $column_info[1] != 'time_start' && $column_info[1] != 'time_end' || $column_info[4] == 'DT') && ($column_info[4] != '' && $adv_filter_value != '')) { $val = array(); for ($x = 0; $x < count($temp_val); $x++) { if ($column_info[4] == 'D') { $date = new DateTimeField(trim($temp_val[$x])); $val[$x] = $date->getDBInsertDateValue(); } elseif ($column_info[4] == 'DT') { $date = new DateTimeField(trim($temp_val[$x])); $val[$x] = $date->getDBInsertDateTimeValue(); } else { $date = new DateTimeField(trim($temp_val[$x])); $val[$x] = $date->getDBInsertTimeValue(); } } $adv_filter_value = implode(",", $val); } $criteria = array(); $criteria['columnname'] = $adv_filter_column; $criteria['comparator'] = $adv_filter_comparator; $criteria['value'] = $adv_filter_value; $criteria['column_condition'] = $adv_filter_column_condition; $advfilterlist[$adv_filter_groupid]['columns'][] = $criteria; } foreach ($advft_criteria_groups as $group_index => $group_condition_info) { if (empty($group_condition_info)) { continue; } if (empty($advfilterlist[$group_index])) { continue; } $advfilterlist[$group_index]['condition'] = $group_condition_info["groupcondition"]; $noOfGroupColumns = count($advfilterlist[$group_index]['columns']); if (!empty($advfilterlist[$group_index]['columns'][$noOfGroupColumns - 1]['column_condition'])) { $advfilterlist[$group_index]['columns'][$noOfGroupColumns - 1]['column_condition'] = ''; } } $noOfGroups = count($advfilterlist); if (!empty($advfilterlist[$noOfGroups]['condition'])) { $advfilterlist[$noOfGroups]['condition'] = ''; } $advfiltersql = $this->generateAdvFilterSql($advfilterlist); } return $advfiltersql; }
function insertIntoEntityTable($table_name, $module, $fileid = '') { global $log; global $current_user, $app_strings; global $adb; $log->debug("Entering PaymentManagement::insertIntoEntityTable(" . $table_name . ", " . $module . ", " . $fileid . ") method ..."); $value_table = array(); $insertion_mode = $this->mode; //Checkin whether an entry is already is present in the vtiger_table to update if ($insertion_mode == 'edit') { $tablekey = $this->tab_name_index[$table_name]; // Make selection on the primary key of the module table to check. $check_query = "select {$tablekey} from {$table_name} where {$tablekey}=?"; $check_result = $adb->pquery($check_query, array($this->id)); $num_rows = $adb->num_rows($check_result); if ($num_rows <= 0) { $insertion_mode = ''; } } $tabid = getTabid($module); if ($insertion_mode == 'edit') { $update = array(); $update_params = array(); checkFileAccessForInclusion('user_privileges/user_privileges_' . $current_user->id . '.php'); require 'user_privileges/user_privileges_' . $current_user->id . '.php'; if ($is_admin == true || $profileGlobalPermission[1] == 0 || $profileGlobalPermission[2] == 0) { $sql = "select * from vtiger_field where tabid in (" . generateQuestionMarks($tabid) . ") and tablename=? and displaytype in (1,3) and presence in (0,2) group by columnname"; $params = array($tabid, $table_name); } else { $profileList = getCurrentUserProfileList(); if (count($profileList) > 0) { $sql = "SELECT *\n\t\t\t \t\t\tFROM vtiger_field\n\t\t\t \t\t\tINNER JOIN vtiger_profile2field\n\t\t\t \t\t\tON vtiger_profile2field.fieldid = vtiger_field.fieldid\n\t\t\t \t\t\tINNER JOIN vtiger_def_org_field\n\t\t\t \t\t\tON vtiger_def_org_field.fieldid = vtiger_field.fieldid\n\t\t\t \t\t\tWHERE vtiger_field.tabid = ?\n\t\t\t \t\t\tAND vtiger_profile2field.visible = 0 AND vtiger_profile2field.readonly = 0\n\t\t\t \t\t\tAND vtiger_profile2field.profileid IN (" . generateQuestionMarks($profileList) . ")\n\t\t\t \t\t\tAND vtiger_def_org_field.visible = 0 and vtiger_field.tablename=? and vtiger_field.displaytype in (1,3) and vtiger_field.presence in (0,2) group by columnname"; $params = array($tabid, $profileList, $table_name); } else { $sql = "SELECT *\n\t\t\t \t\t\tFROM vtiger_field\n\t\t\t \t\t\tINNER JOIN vtiger_profile2field\n\t\t\t \t\t\tON vtiger_profile2field.fieldid = vtiger_field.fieldid\n\t\t\t \t\t\tINNER JOIN vtiger_def_org_field\n\t\t\t \t\t\tON vtiger_def_org_field.fieldid = vtiger_field.fieldid\n\t\t\t \t\t\tWHERE vtiger_field.tabid = ?\n\t\t\t \t\t\tAND vtiger_profile2field.visible = 0 AND vtiger_profile2field.readonly = 0\n\t\t\t \t\t\tAND vtiger_def_org_field.visible = 0 and vtiger_field.tablename=? and vtiger_field.displaytype in (1,3) and vtiger_field.presence in (0,2) group by columnname"; $params = array($tabid, $table_name); } } } else { $table_index_column = $this->tab_name_index[$table_name]; if ($table_index_column == 'id' && $table_name == 'vtiger_users') { $currentuser_id = $adb->getUniqueID("vtiger_users"); $this->id = $currentuser_id; } $columname = $table_index_column; $fldvalue = $this->id; $column = array($table_index_column); $value = array($this->id); // vtiger_payment_management のインデックスを登録 (2015/11/26) $columname = $table_index_column; // tao $fldvalue = $this->id; // tao $value_table[$columname] = $fldvalue; // tao $sql = "select * from vtiger_field where tabid=? and tablename=? and displaytype in (1,3,4) and vtiger_field.presence in (0,2)"; $params = array($tabid, $table_name); } // Attempt to re-use the quer-result to avoid reading for every save operation // TODO Need careful analysis on impact ... MEMORY requirement might be more static $_privatecache = array(); $cachekey = "{$insertion_mode}-" . implode(',', $params); if (!isset($_privatecache[$cachekey])) { $result = $adb->pquery($sql, $params); $noofrows = $adb->num_rows($result); if (CRMEntity::isBulkSaveMode()) { $cacheresult = array(); for ($i = 0; $i < $noofrows; ++$i) { $cacheresult[] = $adb->fetch_array($result); } $_privatecache[$cachekey] = $cacheresult; } } else { // Useful when doing bulk save $result = $_privatecache[$cachekey]; $noofrows = count($result); } for ($i = 0; $i < $noofrows; $i++) { $fieldname = $this->resolve_query_result_value($result, $i, "fieldname"); $columname = $this->resolve_query_result_value($result, $i, "columnname"); $uitype = $this->resolve_query_result_value($result, $i, "uitype"); $generatedtype = $this->resolve_query_result_value($result, $i, "generatedtype"); $typeofdata = $this->resolve_query_result_value($result, $i, "typeofdata"); $typeofdata_array = explode("~", $typeofdata); $datatype = $typeofdata_array[0]; $ajaxSave = false; // uitype == 2 if ($_REQUEST['file'] == 'DetailViewAjax' && $_REQUEST['ajxaction'] == 'DETAILVIEW' && isset($_REQUEST["fldName"]) && $_REQUEST["fldName"] != $fieldname || $_REQUEST['action'] == 'MassEditSave' && !isset($_REQUEST[$fieldname . "_mass_edit_check"])) { $ajaxSave = true; } if ($uitype == 4 && $insertion_mode != 'edit') { $fldvalue = ''; // Bulk Save Mode: Avoid generation of module sequence number, take care later. if (!CRMEntity::isBulkSaveMode()) { $fldvalue = $this->setModuleSeqNumber("increment", $module); } $this->column_fields[$fieldname] = $fldvalue; } if (isset($this->column_fields[$fieldname])) { if ($uitype == 56) { if ($this->column_fields[$fieldname] == 'on' || $this->column_fields[$fieldname] == 1) { $fldvalue = '1'; } else { $fldvalue = '0'; } } elseif ($uitype == 15 || $uitype == 16) { if ($this->column_fields[$fieldname] == $app_strings['LBL_NOT_ACCESSIBLE']) { //If the value in the request is Not Accessible for a picklist, //the existing value will be replaced instead of Not Accessible value. $sql = "select {$columname} from {$table_name} where " . $this->tab_name_index[$table_name] . "=?"; $res = $adb->pquery($sql, array($this->id)); $pick_val = $adb->query_result($res, 0, $columname); $fldvalue = $pick_val; } else { $fldvalue = $this->column_fields[$fieldname]; } } elseif ($uitype == 33) { if (is_array($this->column_fields[$fieldname])) { $field_list = implode(' |##| ', $this->column_fields[$fieldname]); } else { $field_list = $this->column_fields[$fieldname]; } $fldvalue = $field_list; } elseif ($uitype == 5 || $uitype == 6 || $uitype == 23) { //Added to avoid function call getDBInsertDateValue in ajax save if (isset($current_user->date_format) && !$ajaxSave) { $fldvalue = getValidDBInsertDateValue($this->column_fields[$fieldname]); } else { $fldvalue = $this->column_fields[$fieldname]; } } elseif ($uitype == 7) { //strip out the spaces and commas in numbers if given ie., in amounts there may be , $fldvalue = str_replace(",", "", $this->column_fields[$fieldname]); //trim($this->column_fields[$fieldname],","); } elseif ($uitype == 26) { if (empty($this->column_fields[$fieldname])) { $fldvalue = 1; //the documents will stored in default folder } else { $fldvalue = $this->column_fields[$fieldname]; } } elseif ($uitype == 28) { if ($this->column_fields[$fieldname] == null) { $fileQuery = $adb->pquery("SELECT filename from vtiger_notes WHERE notesid = ?", array($this->id)); $fldvalue = null; if (isset($fileQuery)) { $rowCount = $adb->num_rows($fileQuery); if ($rowCount > 0) { $fldvalue = decode_html($adb->query_result($fileQuery, 0, 'filename')); } } } else { $fldvalue = decode_html($this->column_fields[$fieldname]); } } elseif ($uitype == 8) { $this->column_fields[$fieldname] = rtrim($this->column_fields[$fieldname], ','); $ids = explode(',', $this->column_fields[$fieldname]); $json = new Zend_Json(); $fldvalue = $json->encode($ids); } elseif ($uitype == 12) { // Bulk Sae Mode: Consider the FROM email address as specified, if not lookup $fldvalue = $this->column_fields[$fieldname]; if (empty($fldvalue)) { $query = "SELECT email1 FROM vtiger_users WHERE id = ?"; $res = $adb->pquery($query, array($current_user->id)); $rows = $adb->num_rows($res); if ($rows > 0) { $fldvalue = $adb->query_result($res, 0, 'email1'); } } // END } elseif ($uitype == 72 && !$ajaxSave) { // Some of the currency fields like Unit Price, Totoal , Sub-total - doesn't need currency conversion during save $fldvalue = CurrencyField::convertToDBFormat($this->column_fields[$fieldname], null, true); } elseif ($uitype == 71 && !$ajaxSave) { $fldvalue = CurrencyField::convertToDBFormat($this->column_fields[$fieldname]); } else { $fldvalue = $this->column_fields[$fieldname]; } if ($uitype != 33 && $uitype != 8) { $fldvalue = from_html($fldvalue, $insertion_mode == 'edit' ? true : false); } } else { $fldvalue = ''; } if ($fldvalue == '') { $fldvalue = $this->get_column_value($columname, $fldvalue, $fieldname, $uitype, $datatype); } // key-value 配列にキーと値の組を登録する $value_table[$columname] = $fldvalue; // tao if ($insertion_mode == 'edit') { if ($table_name != 'vtiger_ticketcomments' && $uitype != 4) { array_push($update, $columname . "=?"); array_push($update_params, $fldvalue); } } else { array_push($column, $columname); array_push($value, $fldvalue); } } if ($insertion_mode == 'edit') { // ADDED by tao on 15/12/04 -- begin if ($table_name == 'vtiger_payment_management') { // 顧客名が指定されていない場合は、カナ名から顧客名を類推する。 */ $value_table = $this->insertClientName($value_table); $update_params = PaymentManagement::generateValues($value_table); if ($value_table['accountname'] != '') { $sql = 'update vtiger_crmentityrel set crmid=? where relcrmid=?'; $param = array($value_table['accountname'], $this->id); $adb->pquery($sql, $param); } } // ADDED by tao on 15/12/04 -- end //Check done by Don. If update is empty the the query fails if (count($update) > 0) { $sql1 = "update {$table_name} set " . implode(",", $update) . " where " . $this->tab_name_index[$table_name] . "=?"; array_push($update_params, $this->id); $adb->pquery($sql1, $update_params, true); } } else { // Added by 田尾 (tao) on 15/11/25 -- begin if ($module == 'PaymentManagement' && $table_name == 'vtiger_payment_management') { $value_table = $this->insertClientName($value_table); if ($value_table['accountname'] != '') { $this->save_related_module('Account', $value_table['accountname'], 'PaymentManagement', $value_table['payment_management_id']); } } $value = PaymentManagement::generateValues($value_table); // Added by 田尾 (tao) on 15/11/25 -- end $sql1 = "insert into {$table_name}(" . implode(",", $column) . ") values(" . generateQuestionMarks($value) . ")"; $adb->pquery($sql1, $value); } $log->debug("Exting PaymentManagement::insertIntoEntityTable(" . $table_name . ", " . $module . ", " . $fileid . ") method ..."); }
function updateAdvancedCriteria($reportid, $advft_criteria, $advft_criteria_groups) { global $adb, $log; $idelrelcriteriasql = "delete from vtiger_relcriteria where queryid=?"; $idelrelcriteriasqlresult = $adb->pquery($idelrelcriteriasql, array($reportid)); $idelrelcriteriagroupsql = "delete from vtiger_relcriteria_grouping where queryid=?"; $idelrelcriteriagroupsqlresult = $adb->pquery($idelrelcriteriagroupsql, array($reportid)); if (empty($advft_criteria)) { return; } foreach ($advft_criteria as $column_index => $column_condition) { if (empty($column_condition)) { continue; } $adv_filter_column = $column_condition["columnname"]; $adv_filter_comparator = $column_condition["comparator"]; $adv_filter_value = $column_condition["value"]; $adv_filter_column_condition = $column_condition["columncondition"]; $adv_filter_groupid = $column_condition["groupid"]; $column_info = explode(":", $adv_filter_column); $moduleFieldLabel = $column_info[2]; $fieldName = $column_info[3]; list($module, $fieldLabel) = explode('__', $moduleFieldLabel, 2); $fieldInfo = getFieldByReportLabel($module, $fieldLabel); $fieldType = null; if (!empty($fieldInfo)) { $field = WebserviceField::fromArray($adb, $fieldInfo); $fieldType = $field->getFieldDataType(); } if ($fieldType == 'currency') { // Some of the currency fields like Unit Price, Total, Sub-total etc of Inventory modules, do not need currency conversion if ($field->getUIType() == '72') { $adv_filter_value = CurrencyField::convertToDBFormat($adv_filter_value, null, true); } else { $adv_filter_value = CurrencyField::convertToDBFormat($adv_filter_value); } } $temp_val = explode(",", $adv_filter_value); if (($column_info[4] == 'D' || $column_info[4] == 'T' && $column_info[1] != 'time_start' && $column_info[1] != 'time_end' || $column_info[4] == 'DT') && ($column_info[4] != '' && $adv_filter_value != '')) { $val = array(); for ($x = 0; $x < count($temp_val); $x++) { if (trim($temp_val[$x]) != '') { $date = new DateTimeField(trim($temp_val[$x])); if ($column_info[4] == 'D') { $val[$x] = DateTimeField::convertToUserFormat(trim($temp_val[$x])); } elseif ($column_info[4] == 'DT') { $val[$x] = $date->getDBInsertDateTimeValue(); } else { $val[$x] = $date->getDBInsertTimeValue(); } } } $adv_filter_value = implode(",", $val); } $irelcriteriasql = "insert into vtiger_relcriteria(QUERYID,COLUMNINDEX,COLUMNNAME,COMPARATOR,VALUE,GROUPID,COLUMN_CONDITION) values (?,?,?,?,?,?,?)"; $irelcriteriaresult = $adb->pquery($irelcriteriasql, array($reportid, $column_index, $adv_filter_column, $adv_filter_comparator, $adv_filter_value, $adv_filter_groupid, $adv_filter_column_condition)); // Update the condition expression for the group to which the condition column belongs $groupConditionExpression = ''; if (!empty($advft_criteria_groups[$adv_filter_groupid]["conditionexpression"])) { $groupConditionExpression = $advft_criteria_groups[$adv_filter_groupid]["conditionexpression"]; } $groupConditionExpression = $groupConditionExpression . ' ' . $column_index . ' ' . $adv_filter_column_condition; $advft_criteria_groups[$adv_filter_groupid]["conditionexpression"] = $groupConditionExpression; } foreach ($advft_criteria_groups as $group_index => $group_condition_info) { if (empty($group_condition_info)) { continue; } if (empty($group_condition_info["conditionexpression"])) { continue; } // Case when the group doesn't have any column criteria $irelcriteriagroupsql = "insert into vtiger_relcriteria_grouping(GROUPID,QUERYID,GROUP_CONDITION,CONDITION_EXPRESSION) values (?,?,?,?)"; $irelcriteriagroupresult = $adb->pquery($irelcriteriagroupsql, array($group_index, $reportid, $group_condition_info["groupcondition"], $group_condition_info["conditionexpression"])); } }
function getAdvancedSearchCriteriaList($advft_criteria, $advft_criteria_groups, $module = '') { global $currentModule, $current_user; if (empty($module)) { $module = $currentModule; } $advfilterlist = array(); $moduleHandler = vtws_getModuleHandlerFromName($module, $current_user); $moduleMeta = $moduleHandler->getMeta(); $moduleFields = $moduleMeta->getModuleFields(); foreach ($advft_criteria as $column_index => $column_condition) { if (empty($column_condition)) { continue; } $adv_filter_column = $column_condition["columnname"]; $adv_filter_comparator = $column_condition["comparator"]; $adv_filter_value = $column_condition["value"]; $adv_filter_column_condition = $column_condition["columncondition"]; $adv_filter_groupid = $column_condition["groupid"]; $column_info = explode(":", $adv_filter_column); $fieldName = $column_info[2]; $fieldObj = $moduleFields[$fieldName]; $fieldType = $fieldObj->getFieldDataType(); if ($fieldType == 'currency') { // Some of the currency fields like Unit Price, Total, Sub-total etc of Inventory modules, do not need currency conversion if ($fieldObj->getUIType() == '72') { $adv_filter_value = CurrencyField::convertToDBFormat($adv_filter_value, null, true); } else { $currencyField = new CurrencyField($adv_filter_value); if ($module == 'Potentials' && $fieldName == 'amount') { $currencyField->setNumberofDecimals(2); } $adv_filter_value = $currencyField->getDBInsertedValue(); } } $criteria = array(); $criteria['columnname'] = $adv_filter_column; $criteria['comparator'] = $adv_filter_comparator; $criteria['value'] = $adv_filter_value; $criteria['column_condition'] = $adv_filter_column_condition; $advfilterlist[$adv_filter_groupid]['columns'][] = $criteria; } foreach ($advft_criteria_groups as $group_index => $group_condition_info) { if (empty($group_condition_info)) { continue; } if (empty($advfilterlist[$group_index])) { continue; } $advfilterlist[$group_index]['condition'] = $group_condition_info["groupcondition"]; $noOfGroupColumns = count($advfilterlist[$group_index]['columns']); if (!empty($advfilterlist[$group_index]['columns'][$noOfGroupColumns - 1]['column_condition'])) { $advfilterlist[$group_index]['columns'][$noOfGroupColumns - 1]['column_condition'] = ''; } } $noOfGroups = count($advfilterlist); if (!empty($advfilterlist[$noOfGroups]['condition'])) { $advfilterlist[$noOfGroups]['condition'] = ''; } return $advfilterlist; }
/** function to save the service price information in vtiger_servicecurrencyrel table * @param string $tablename - vtiger_tablename to save the service currency relationship (servicecurrencyrel) * @param string $module - current module name * $return void */ function insertPriceInformation($tablename, $module) { global $adb, $log, $current_user; $log->debug("Entering into insertPriceInformation({$tablename}, {$module}) method ..."); //removed the update of currency_id based on the logged in user's preference : fix 6490 $currency_details = getAllCurrencies('all'); //Delete the existing currency relationship if any if ($this->mode == 'edit' && $_REQUEST['action'] != 'MassEditSave' && $_REQUEST['action'] != 'ProcessDuplicates') { for ($i = 0; $i < count($currency_details); $i++) { $curid = $currency_details[$i]['curid']; $sql = "delete from vtiger_productcurrencyrel where productid=? and currencyid=?"; $adb->pquery($sql, array($this->id, $curid)); } } $service_base_conv_rate = getBaseConversionRateForProduct($this->id, $this->mode, $module); //Save the Product - Currency relationship if corresponding currency check box is enabled for ($i = 0; $i < count($currency_details); $i++) { $curid = $currency_details[$i]['curid']; $curname = $currency_details[$i]['currencylabel']; $cur_checkname = 'cur_' . $curid . '_check'; $cur_valuename = 'curname' . $curid; $base_currency_check = 'base_currency' . $curid; $requestPrice = CurrencyField::convertToDBFormat($_REQUEST['unit_price'], null, true); $actualPrice = CurrencyField::convertToDBFormat($_REQUEST[$cur_valuename], null, true); if ($_REQUEST[$cur_checkname] == 'on' || $_REQUEST[$cur_checkname] == 1) { $conversion_rate = $currency_details[$i]['conversionrate']; $actual_conversion_rate = $service_base_conv_rate * $conversion_rate; $converted_price = $actual_conversion_rate * $requestPrice; $log->debug("Going to save the Product - {$curname} currency relationship"); $query = "insert into vtiger_productcurrencyrel values(?,?,?,?)"; $adb->pquery($query, array($this->id, $curid, $converted_price, $actualPrice)); // Update the Product information with Base Currency choosen by the User. if ($_REQUEST['base_currency'] == $cur_valuename) { $adb->pquery("update vtiger_service set currency_id=?, unit_price=? where serviceid=?", array($curid, $actualPrice, $this->id)); } } } $log->debug("Exiting from insertPriceInformation({$tablename}, {$module}) method ..."); }
/** Function to get the RunTime Advanced filter conditions * @ param $advft_criteria : Type Array * @ param $advft_criteria_groups : Type Array * This function returns $advfiltersql */ function RunTimeAdvFilter($advft_criteria, $advft_criteria_groups) { $adb = PearDatabase::getInstance(); $advfilterlist = array(); if (!empty($advft_criteria)) { foreach ($advft_criteria as $column_index => $column_condition) { if (empty($column_condition)) { continue; } $adv_filter_column = $column_condition["columnname"]; $adv_filter_comparator = $column_condition["comparator"]; $adv_filter_value = $column_condition["value"]; $adv_filter_column_condition = $column_condition["columncondition"]; $adv_filter_groupid = $column_condition["groupid"]; $column_info = explode(":", $adv_filter_column); $moduleFieldLabel = $column_info[2]; $fieldName = $column_info[3]; list($module, $fieldLabel) = explode('_', $moduleFieldLabel, 2); $fieldInfo = getFieldByReportLabel($module, $fieldLabel); $fieldType = null; if (!empty($fieldInfo)) { $field = WebserviceField::fromArray($adb, $fieldInfo); $fieldType = $field->getFieldDataType(); } if ($fieldType == 'currency' or $fieldType == 'double') { $flduitype = $fieldInfo['uitype']; if ($flduitype == '72' or $flduitype == 9 or $flduitype == 7) { $adv_filter_value = CurrencyField::convertToDBFormat($adv_filter_value, null, true); } else { $adv_filter_value = CurrencyField::convertToDBFormat($adv_filter_value); } } $temp_val = explode(",", $adv_filter_value); if (($column_info[4] == 'D' || $column_info[4] == 'T' && $column_info[1] != 'time_start' && $column_info[1] != 'time_end' || $column_info[4] == 'DT') && ($column_info[4] != '' && $adv_filter_value != '')) { $val = array(); for ($x = 0; $x < count($temp_val); $x++) { if ($column_info[4] == 'D') { $date = new DateTimeField(trim($temp_val[$x])); $val[$x] = $date->getDBInsertDateValue(); } elseif ($column_info[4] == 'DT') { $date = new DateTimeField(trim($temp_val[$x])); $val[$x] = $date->getDBInsertDateTimeValue(); } else { $date = new DateTimeField(trim($temp_val[$x])); $val[$x] = $date->getDBInsertTimeValue(); } } $adv_filter_value = implode(",", $val); } if ($fieldType == 'picklist' || $fieldType == 'multipicklist') { if (!isValueInPicklist($adv_filter_value, $fieldName)) { $adv_filter_value = getTranslationKeyFromTranslatedValue($module, $adv_filter_value); } } $criteria = array(); $criteria['columnname'] = $adv_filter_column; $criteria['comparator'] = $adv_filter_comparator; $criteria['value'] = $adv_filter_value; $criteria['column_condition'] = $adv_filter_column_condition; $advfilterlist[$adv_filter_groupid]['columns'][] = $criteria; } foreach ($advft_criteria_groups as $group_index => $group_condition_info) { if (empty($group_condition_info)) { continue; } if (empty($advfilterlist[$group_index])) { continue; } $advfilterlist[$group_index]['condition'] = $group_condition_info["groupcondition"]; $noOfGroupColumns = count($advfilterlist[$group_index]['columns']); if (!empty($advfilterlist[$group_index]['columns'][$noOfGroupColumns - 1]['column_condition'])) { $advfilterlist[$group_index]['columns'][$noOfGroupColumns - 1]['column_condition'] = ''; } } $noOfGroups = count($advfilterlist); if (!empty($advfilterlist[$noOfGroups]['condition'])) { $advfilterlist[$noOfGroups]['condition'] = ''; } $advfiltersql = $this->generateAdvFilterSql($advfilterlist); } return $advfiltersql; }
$encode_val = vtlib_purify($_REQUEST['encode_val']); $decode_val = base64_decode($encode_val); $explode_decode_val = explode('&', trim($decode_val, '&')); $tabid = getTabid($currentModule); foreach ($explode_decode_val as $fieldvalue) { $value = explode("=", $fieldvalue); $field_name_val = $value[0]; $field_value = urldecode($value[1]); $finfo = VTCacheUtils::lookupFieldInfo($tabid, $field_name_val); if ($finfo !== false) { if ($finfo['uitype'] == '56') { $field_value = $field_value == 'on' ? '1' : '0'; } if ($finfo['uitype'] == '71' or $finfo['uitype'] == '72') { $currencyField = new CurrencyField($field_value); $field_value = CurrencyField::convertToDBFormat($field_value, $current_user); } if ($finfo['uitype'] == '33' or $finfo['uitype'] == '3313') { if (is_array($field_value)) { $field_value = implode(' |##| ', $field_value); } } } $focus->column_fields[$field_name_val] = $field_value; } } $errormessageclass = isset($_REQUEST['error_msgclass']) ? vtlib_purify($_REQUEST['error_msgclass']) : ''; $errormessage = isset($_REQUEST['error_msg']) ? vtlib_purify($_REQUEST['error_msg']) : ''; $smarty->assign('ERROR_MESSAGE_CLASS', $errormessageclass); $smarty->assign('ERROR_MESSAGE', $errormessage); } elseif (empty($_REQUEST['record']) && $focus->mode != 'edit') {
public function addUserSearchConditions($input) { global $log, $default_charset; if ($input['searchtype'] == 'advance') { $json = new Zend_Json(); $advft_criteria = empty($input['advft_criteria']) ? $_REQUEST['advft_criteria'] : $input['advft_criteria']; if (!empty($advft_criteria)) { $advft_criteria = $json->decode($advft_criteria); } $advft_criteria_groups = empty($input['advft_criteria_groups']) ? $_REQUEST['advft_criteria_groups'] : $input['advft_criteria_groups']; if (!empty($advft_criteria_groups)) { $advft_criteria_groups = $json->decode($advft_criteria_groups); } if (empty($advft_criteria) || count($advft_criteria) <= 0) { return; } $advfilterlist = getAdvancedSearchCriteriaList($advft_criteria, $advft_criteria_groups, $this->getModule()); if (empty($advfilterlist) || count($advfilterlist) <= 0) { return; } if ($this->conditionInstanceCount > 0) { $this->startGroup(self::$AND); } else { $this->startGroup(''); } foreach ($advfilterlist as $groupindex => $groupcolumns) { $filtercolumns = $groupcolumns['columns']; if (count($filtercolumns) > 0) { $this->startGroup(''); foreach ($filtercolumns as $index => $filter) { $name = explode(':', $filter['columnname']); if (empty($name[2]) && $name[1] == 'crmid' && $name[0] == 'vtiger_crmentity') { $name = $this->getSQLColumn('id'); } else { $name = $name[2]; } $this->addCondition($name, $filter['value'], $filter['comparator']); $columncondition = $filter['column_condition']; if (!empty($columncondition)) { $this->addConditionGlue($columncondition); } } $this->endGroup(); $groupConditionGlue = $groupcolumns['condition']; if (!empty($groupConditionGlue)) { $this->addConditionGlue($groupConditionGlue); } } } $this->endGroup(); } elseif ($input['type'] == 'dbrd') { if ($this->conditionInstanceCount > 0) { $this->startGroup(self::$AND); } else { $this->startGroup(''); } $allConditionsList = $this->getDashBoardConditionList(); $conditionList = $allConditionsList['conditions']; $relatedConditionList = $allConditionsList['relatedConditions']; $noOfConditions = count($conditionList); $noOfRelatedConditions = count($relatedConditionList); foreach ($conditionList as $index => $conditionInfo) { $this->addCondition($conditionInfo['fieldname'], $conditionInfo['value'], $conditionInfo['operator']); if ($index < $noOfConditions - 1 || $noOfRelatedConditions > 0) { $this->addConditionGlue(self::$AND); } } foreach ($relatedConditionList as $index => $conditionInfo) { $this->addRelatedModuleCondition($conditionInfo['relatedModule'], $conditionInfo['conditionModule'], $conditionInfo['finalValue'], $conditionInfo['SQLOperator']); if ($index < $noOfRelatedConditions - 1) { $this->addConditionGlue(self::$AND); } } $this->endGroup(); } else { if (isset($input['search_field']) && $input['search_field'] != "") { $fieldName = vtlib_purify($input['search_field']); } else { return; } if ($this->conditionInstanceCount > 0) { $this->startGroup(self::$AND); } else { $this->startGroup(''); } $moduleFields = $this->getModuleFields(); $field = $moduleFields[$fieldName]; $type = $field->getFieldDataType(); if (isset($input['search_text']) && $input['search_text'] != "") { // search other characters like "|, ?, ?" by jagi $value = $input['search_text']; $stringConvert = function_exists(iconv) ? @iconv("UTF-8", $default_charset, $value) : $value; if (!$this->isStringType($type)) { $value = trim($stringConvert); } if ($type == 'picklist') { global $currentModule; if (!isValueInPicklist($value, $field->getFieldName())) { $value = getTranslationKeyFromTranslatedValue($currentModule, $value); } } if ($type == 'currency') { // Some of the currency fields like Unit Price, Total, Sub-total etc of Inventory modules, do not need currency conversion if ($field->getUIType() == '72') { $value = CurrencyField::convertToDBFormat($value, null, true); } else { $currencyField = new CurrencyField($value); if ($this->getModule() == 'Potentials' && $fieldName == 'amount') { $currencyField->setNumberofDecimals(2); } $value = $currencyField->getDBInsertedValue(); } } } if (!empty($input['operator'])) { $operator = $input['operator']; } elseif (trim(strtolower($value)) == 'null') { $operator = 'e'; } else { if (!$this->isNumericType($type) && !$this->isDateType($type)) { $operator = 'c'; } else { $operator = 'h'; } } $this->addCondition($fieldName, $value, $operator); $this->endGroup(); } }