public function handleEvent($handlerType, $entityData)
 {
     $adb = PearDatabase::getInstance();
     $log = vglobal('log');
     $moduleName = $entityData->getModuleName();
     if ($moduleName == 'SalesOrder') {
         $soId = $entityData->getId();
         $data = $entityData->getData();
         if ($data['enable_recurring'] == 'on' || $data['enable_recurring'] == 1) {
             $frequency = $data['recurring_frequency'];
             $startPeriod = getValidDBInsertDateValue($data['start_period']);
             $endPeriod = getValidDBInsertDateValue($data['end_period']);
             $paymentDuration = $data['payment_duration'];
             $invoiceStatus = $data['invoicestatus'];
             if (isset($frequency) && $frequency != '' && $frequency != '--None--') {
                 $check_query = "SELECT * FROM vtiger_invoice_recurring_info WHERE salesorderid=?";
                 $check_res = $adb->pquery($check_query, array($soId));
                 $noofrows = $adb->num_rows($check_res);
                 if ($noofrows > 0) {
                     $row = $adb->query_result_rowdata($check_res, 0);
                     $query = "UPDATE vtiger_invoice_recurring_info SET recurring_frequency=?, start_period=?, end_period=?, payment_duration=?, invoice_status=? WHERE salesorderid=?";
                     $params = array($frequency, $startPeriod, $endPeriod, $paymentDuration, $invoiceStatus, $soId);
                 } else {
                     $query = "INSERT INTO vtiger_invoice_recurring_info VALUES (?,?,?,?,?,?,?)";
                     $params = array($soId, $frequency, $startPeriod, $endPeriod, $startPeriod, $paymentDuration, $invoiceStatus);
                 }
                 $adb->pquery($query, $params);
             }
         } else {
             $query = "DELETE FROM vtiger_invoice_recurring_info WHERE salesorderid = ?";
             $adb->pquery($query, array($soId));
         }
     }
 }
예제 #2
0
 function datefmt($date, $outFormat = "d.m.Y")
 {
     if (strlen($date) > 10) {
         $date = substr($date, 0, 10);
     }
     $sql_format_date = getValidDBInsertDateValue($date);
     $date = new DateTime($sql_format_date);
     return $date->format($outFormat);
 }
예제 #3
0
 /** 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)
 {
     $log = vglobal('log');
     $log->info("function insertIntoEntityTable " . $module . ' vtiger_table name ' . $table_name);
     $adb = PearDatabase::getInstance();
     $current_user = vglobal('current_user');
     $insertion_mode = $this->mode;
     //Checkin whether an entry is already is present in the vtiger_table to update
     if ($insertion_mode == 'edit') {
         $check_query = "select * from " . $table_name . " where " . $this->tab_name_index[$table_name] . "=?";
         $check_result = $this->db->pquery($check_query, array($this->id));
         $num_rows = $this->db->num_rows($check_result);
         if ($num_rows <= 0) {
             $insertion_mode = '';
         }
     }
     // We will set the crypt_type based on the insertion_mode
     $crypt_type = '';
     if ($insertion_mode == 'edit') {
         $update = '';
         $update_params = array();
         $tabid = getTabid($module);
         $sql = "select * from vtiger_field where tabid=? and tablename=? and displaytype in (1,3,5) and vtiger_field.presence in (0,2)";
         $params = array($tabid, $table_name);
     } else {
         $column = $this->tab_name_index[$table_name];
         if ($column == 'id' && $table_name == 'vtiger_users') {
             $currentuser_id = $this->db->getUniqueID("vtiger_users");
             $this->id = $currentuser_id;
         }
         $qparams = array($this->id);
         $tabid = getTabid($module);
         $sql = "select * from vtiger_field where tabid=? and tablename=? and displaytype in (1,3,4,5) and vtiger_field.presence in (0,2)";
         $params = array($tabid, $table_name);
         $crypt_type = $this->DEFAULT_PASSWORD_CRYPT_TYPE;
     }
     $result = $this->db->pquery($sql, $params);
     $noofrows = $this->db->num_rows($result);
     for ($i = 0; $i < $noofrows; $i++) {
         $fieldname = $this->db->query_result($result, $i, "fieldname");
         $columname = $this->db->query_result($result, $i, "columnname");
         $uitype = $this->db->query_result($result, $i, "uitype");
         $typeofdata = $adb->query_result($result, $i, "typeofdata");
         $typeofdata_array = explode("~", $typeofdata);
         $datatype = $typeofdata_array[0];
         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) {
                 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 == 5 || $uitype == 6 || $uitype == 23) {
                 if (isset($current_user->date_format)) {
                     $fldvalue = getValidDBInsertDateValue($this->column_fields[$fieldname]);
                 } 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 == 99) {
                 $plain_text = $this->column_fields[$fieldname];
                 $fldvalue = $this->encrypt_password($plain_text, $crypt_type);
                 // Update the plain-text value with encrypted value and dependent fields
                 $this->column_fields[$fieldname] = $fldvalue;
                 $this->column_fields['crypt_type'] = $crypt_type;
                 $this->column_fields['user_hash'] = $this->get_user_hash($plain_text);
             } else {
                 $fldvalue = $this->column_fields[$fieldname];
                 $fldvalue = stripslashes($fldvalue);
             }
             $fldvalue = from_html($fldvalue, $insertion_mode == 'edit' ? true : false);
         } else {
             $fldvalue = '';
         }
         if ($uitype == 31) {
             $themeList = array_keys(Vtiger_Util_Helper::getAllSkins());
             if (!in_array($fldvalue, $themeList) || $fldvalue == '') {
                 global $default_theme;
                 if (!empty($default_theme) && in_array($default_theme, $themeList)) {
                     $fldvalue = $default_theme;
                 } else {
                     $fldvalue = $themeList[0];
                 }
             }
             if ($current_user->id == $this->id) {
                 $_SESSION['vtiger_authenticated_user_theme'] = $fldvalue;
             }
         } elseif ($uitype == 32) {
             $languageList = Vtiger_Language::getAll();
             $languageList = array_keys($languageList);
             if (!in_array($fldvalue, $languageList) || $fldvalue == '') {
                 $default_language = vglobal('default_language');
                 if (!empty($default_language) && in_array($default_language, $languageList)) {
                     $fldvalue = vglobal('default_language');
                 } else {
                     $fldvalue = $languageList[0];
                 }
             }
             if ($current_user->id == $this->id) {
                 $_SESSION['authenticated_user_language'] = $fldvalue;
             }
         }
         if ($fldvalue == '') {
             $fldvalue = $this->get_column_value($columname, $fldvalue, $fieldname, $uitype, $datatype);
             //$fldvalue =null;
         }
         if ($insertion_mode == 'edit') {
             if ($i == 0) {
                 $update = $columname . "=?";
             } else {
                 $update .= ', ' . $columname . "=?";
             }
             array_push($update_params, $fldvalue);
         } else {
             $column .= ", " . $columname;
             array_push($qparams, $fldvalue);
         }
     }
     if ($insertion_mode == 'edit') {
         //Check done by Don. If update is empty the the query fails
         if (trim($update) != '') {
             $sql1 = "update {$table_name} set {$update} where " . $this->tab_name_index[$table_name] . "=?";
             array_push($update_params, $this->id);
             $this->db->pquery($sql1, $update_params);
         }
     } else {
         // Set the crypt_type being used, to override the DB default constraint as it is not in vtiger_field
         if ($table_name == 'vtiger_users' && strpos('crypt_type', $column) === false) {
             $column .= ', crypt_type';
             $qparams[] = $crypt_type;
         }
         // END
         if ($table_name == 'vtiger_users' && strpos('user_hash', $column) === false) {
             $column .= ', user_hash';
             $qparams[] = $this->column_fields['user_hash'];
         }
         $sql1 = "insert into {$table_name} ({$column}) values(" . generateQuestionMarks($qparams) . ")";
         $this->db->pquery($sql1, $qparams);
     }
 }
 public function transformForImport($fieldData, $moduleMeta, $fillDefault = true, $mergeMode = false)
 {
     $moduleFields = $moduleMeta->getModuleFields();
     $defaultFieldValues = $this->getDefaultFieldValues($moduleMeta);
     foreach ($fieldData as $fieldName => $fieldValue) {
         $fieldInstance = $moduleFields[$fieldName];
         if (!is_object($fieldInstance)) {
             continue;
         }
         // specially for Inventory module import which has virtual item line fields
         if ($fieldInstance->getFieldDataType() == 'owner') {
             global $adb;
             if (strpos($fieldValue, '::::') > 0) {
                 $fieldValueDetails = explode('::::', $fieldValue);
             } else {
                 $fieldValueDetails = explode(':::', $fieldValue);
             }
             if (count($fieldValueDetails) == 2) {
                 $fieldValue = $fieldValueDetails[1];
             }
             if (count($fieldValueDetails) == 3) {
                 $user_qry = 'select vtiger_users.id from vtiger_users where ' . $fieldValueDetails[2] . ' = ?';
                 $res = $adb->pquery($user_qry, array($fieldValueDetails[1]));
                 $ownerId = 0;
                 if ($res and $adb->num_rows($res) > 0) {
                     $ownerId = $adb->query_result($res, 0, 'id');
                 }
             } else {
                 $ownerId = getUserId_Ol($fieldValue);
                 if (empty($ownerId)) {
                     $ownerId = getGrpId($fieldValue);
                 }
             }
             if (empty($ownerId) && isset($defaultFieldValues[$fieldName])) {
                 $ownerId = $defaultFieldValues[$fieldName];
             }
             if (empty($ownerId) || !Import_Utils::hasAssignPrivilege($moduleMeta->getEntityName(), $ownerId)) {
                 $ownerId = $this->user->id;
             }
             $fieldData[$fieldName] = $ownerId;
         } elseif ($fieldInstance->getFieldDataType() == 'reference') {
             $entityId = false;
             if (!empty($fieldValue)) {
                 if (strpos($fieldValue, '::::') > 0) {
                     $fieldValueDetails = explode('::::', $fieldValue);
                 } else {
                     $fieldValueDetails = explode(':::', $fieldValue);
                 }
                 if (count($fieldValueDetails) > 1) {
                     $referenceModuleName = trim($fieldValueDetails[0]);
                     $entityLabel = trim($fieldValueDetails[1]);
                     if (!empty($fieldValueDetails[2])) {
                         $entityId = getEntityId($referenceModuleName, $entityLabel, $fieldValueDetails[2]);
                     } else {
                         $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::hasAssignPrivilege($moduleMeta->getEntityName(), $referenceEntityId)) {
                                 $referenceEntityId = $this->user->id;
                             }
                         } else {
                             $referenceEntityId = getEntityId($referenceModule, $entityLabel);
                         }
                         if ($referenceEntityId != 0) {
                             $entityId = $referenceEntityId;
                             break;
                         }
                     }
                 }
                 if ((empty($entityId) || $entityId == 0) && (!empty($referenceModuleName) and !in_array($referenceModuleName, getInventoryModules()))) {
                     if (isPermitted($referenceModuleName, 'EditView') == 'yes') {
                         $wsEntityIdInfo = $this->createEntityRecord($referenceModuleName, $entityLabel);
                         $wsEntityId = $wsEntityIdInfo['id'];
                         $entityIdComponents = vtws_getIdComponents($wsEntityId);
                         $entityId = $entityIdComponents[1];
                     }
                 }
                 $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::hasAssignPrivilege($moduleMeta->getEntityName(), $fieldData[$fieldName])) {
                         $fieldData[$fieldName] = $this->user->id;
                     }
                 } else {
                     $fieldData[$fieldName] = '';
                 }
             }
         } elseif ($fieldInstance->getFieldDataType() == 'picklist') {
             global $default_charset;
             if (empty($fieldValue) && isset($defaultFieldValues[$fieldName])) {
                 $fieldData[$fieldName] = $fieldValue = $defaultFieldValues[$fieldName];
             }
             $allPicklistDetails = $fieldInstance->getPicklistDetails();
             $allPicklistValues = array();
             foreach ($allPicklistDetails as $picklistDetails) {
                 $allPicklistValues[] = $picklistDetails['value'];
             }
             $encodePicklistValue = $fieldValue;
             if (!in_array($encodePicklistValue, $allPicklistValues)) {
                 $moduleObject = Vtiger_Module::getInstance($moduleMeta->getEntityName());
                 $fieldObject = Vtiger_Field::getInstance($fieldName, $moduleObject);
                 $fieldObject->setPicklistValues(array($fieldValue));
             }
         } 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]) && !$mergeMode) {
                 $fieldData[$fieldName] = $fieldValue = $defaultFieldValues[$fieldName];
             }
         }
     }
     if ($fillDefault) {
         foreach ($defaultFieldValues as $fieldName => $fieldValue) {
             if (!isset($fieldData[$fieldName])) {
                 $fieldData[$fieldName] = $defaultFieldValues[$fieldName];
             }
         }
     }
     if (!$mergeMode) {
         //Do not check mandatory fields on merge !
         foreach ($moduleFields as $fieldName => $fieldInstance) {
             if (empty($fieldData[$fieldName]) && $fieldInstance->isMandatory()) {
                 return null;
             }
         }
     }
     return DataTransform::sanitizeData($fieldData, $moduleMeta);
 }
예제 #5
0
 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 ...");
 }
예제 #6
0
 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;
 }
예제 #7
0
 /** 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();
         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 \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 \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);
     }
     $result = $adb->pquery($sql, $params);
     $noofrows = $adb->num_rows($result);
     for ($i = 0; $i < $noofrows; $i++) {
         $fieldname = $adb->query_result($result, $i, "fieldname");
         $columname = $adb->query_result($result, $i, "columnname");
         $uitype = $adb->query_result($result, $i, "uitype");
         $generatedtype = $adb->query_result($result, $i, "generatedtype");
         $typeofdata = $adb->query_result($result, $i, "typeofdata");
         $typeofdata_array = explode("~", $typeofdata);
         $datatype = $typeofdata_array[0];
         if ($uitype == 4 && $insertion_mode != 'edit') {
             $this->column_fields[$fieldname] = $this->setModuleSeqNumber("increment", $module);
             $fldvalue = $this->column_fields[$fieldname];
         }
         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) {
                 if ($_REQUEST['action'] == 'Import') {
                     $fldvalue = $this->column_fields[$fieldname];
                 } else {
                     //Added to avoid function call getDBInsertDateValue in ajax save
                     if (isset($current_user->date_format)) {
                         $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 = $adb->query_result($fileQuery, 0, 'filename');
                         }
                     }
                 } else {
                     $fldvalue = $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) {
                 $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');
                 }
             } elseif ($uitype == 71 && $generatedtype == 2) {
                 // Convert currency to base currency value before saving for custom fields of type currency
                 $currency_id = $current_user->currency_id;
                 $curSymCrate = getCurrencySymbolandCRate($currency_id);
                 $fldvalue = convertToDollar($this->column_fields[$fieldname], $curSymCrate['rate']);
             } 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 ($_REQUEST['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('YmdHis');
                 $closingdate = $_REQUEST['ajxaction'] == 'DETAILVIEW' ? $this->column_fields['closingdate'] : getDBInsertDateValue($this->column_fields['closingdate']);
                 $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 ($_REQUEST['module'] == 'PurchaseOrder' || $_REQUEST['module'] == 'SalesOrder' || $_REQUEST['module'] == 'Quotes' || $_REQUEST['module'] == 'Invoice') {
             //added to update the history for PO, SO, Quotes and Invoice
             $history_field_array = array("PurchaseOrder" => "postatus", "SalesOrder" => "sostatus", "Quotes" => "quotestage", "Invoice" => "invoicestatus");
             $inventory_module = $_REQUEST['module'];
             if ($_REQUEST['ajxaction'] == 'DETAILVIEW') {
                 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 {
                 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);
     }
 }
예제 #8
0
function updateFieldProperties()
{
    global $adb, $smarty, $log;
    $fieldid = vtlib_purify($_REQUEST['fieldid']);
    $req_sql = "select * from vtiger_field where fieldid = ? and fieldname not in('salutationtype') and vtiger_field.presence in (0,2)";
    $req_result = $adb->pquery($req_sql, array($fieldid));
    $typeofdata = $adb->query_result($req_result, 0, 'typeofdata');
    $tabid = $adb->query_result($req_result, 0, 'tabid');
    $fieldname = $adb->query_result($req_result, 0, 'fieldname');
    $uitype = $adb->query_result($req_result, 0, 'uitype');
    $oldfieldlabel = $adb->query_result($req_result, 0, 'fieldlabel');
    $tablename = $adb->query_result($req_result, 0, 'tablename');
    $columnname = $adb->query_result($req_result, 0, 'columnname');
    $oldquickcreate = $adb->query_result($req_result, 0, 'quickcreate');
    $oldmassedit = $adb->query_result($req_result, 0, 'masseditable');
    $oldpresence = $adb->query_result($req_result, 0, 'presence');
    if (!empty($_REQUEST['fld_module'])) {
        $fld_module = vtlib_purify($_REQUEST['fld_module']);
    } else {
        $fld_module = getTabModuleName($tabid);
    }
    $focus = CRMEntity::getInstance($fld_module);
    $fieldtype = explode("~", $typeofdata);
    $mandatory_checked = vtlib_purify($_REQUEST['ismandatory']);
    $quickcreate_checked = vtlib_purify($_REQUEST['quickcreate']);
    $presence_check = vtlib_purify($_REQUEST['isPresent']);
    $massedit_check = vtlib_purify($_REQUEST['massedit']);
    $defaultvalue = vtlib_purify($_REQUEST['defaultvalue']);
    if (!empty($defaultvalue)) {
        if ($uitype == 56) {
            if ($defaultvalue == 'on' || $defaultvalue == '1') {
                $defaultvalue = '1';
            } elseif ($defaultvalue == 'off' || $defaultvalue == '0') {
                $defaultvalue = '0';
            } else {
                $defaultvalue = '';
            }
        } elseif ($uitype == 5 || $uitype == 6 || $uitype == 23) {
            $defaultvalue = getValidDBInsertDateValue($defaultvalue);
        }
    }
    if (isset($focus->mandatory_fields) && !empty($focus->mandatory_fields) && in_array($fieldname, $focus->mandatory_fields)) {
        $fieldtype[1] = 'M';
    } elseif ($mandatory_checked == 'true' || $mandatory_checked == '') {
        $fieldtype[1] = 'M';
    } else {
        $fieldtype[1] = 'O';
    }
    $datatype = implode('~', $fieldtype);
    $maxseq = '';
    if ($oldquickcreate != 3) {
        if ($quickcreate_checked == 'true' || $quickcreate_checked == '') {
            $qcdata = 2;
            $quickcreateseq_Query = 'select max(quickcreatesequence) as maxseq from vtiger_field where tabid = ?';
            $res = $adb->pquery($quickcreateseq_Query, array($tabid));
            $maxseq = $adb->query_result($res, 0, 'maxseq');
        } else {
            $qcdata = 1;
        }
    }
    if ($oldpresence != 3) {
        if ($presence_check == 'true' || $presence_check == '') {
            $presence = 2;
        } else {
            $presence = 1;
        }
    } else {
        $presence = 1;
    }
    if ($oldmassedit != 3) {
        if ($massedit_check == 'true' || $massedit_check == '') {
            $massedit = 1;
        } else {
            $massedit = 2;
        }
    } else {
        $massedit = 1;
    }
    if (isset($focus->mandatory_fields) && !empty($focus->mandatory_fields)) {
        $fieldname_list = implode(',', $focus->mandatory_fields);
    } else {
        $fieldname_list = '';
    }
    $mandatory_query = "update vtiger_field set typeofdata=? where fieldid=? and fieldname not in (?) AND displaytype != 2";
    $mandatory_params = array($datatype, $fieldid, $fieldname_list);
    $adb->pquery($mandatory_query, $mandatory_params);
    if (!empty($qcdata)) {
        $quickcreate_query = "update vtiger_field set quickcreate = ? ,quickcreatesequence = ? where fieldid = ? and quickcreate not in (0,3) AND displaytype != 2";
        $quickcreate_params = array($qcdata, $maxseq + 1, $fieldid);
        $adb->pquery($quickcreate_query, $quickcreate_params);
    }
    $presence_query = "update vtiger_field set presence = ? where fieldid = ? and presence not in (0,3) and quickcreate != 0";
    $quickcreate_params = array($presence, $fieldid);
    $adb->pquery($presence_query, $quickcreate_params);
    $massedit_query = "update vtiger_field set masseditable = ? where fieldid = ? and masseditable not in (0,3) AND displaytype != 2";
    $massedit_params = array($massedit, $fieldid);
    $adb->pquery($massedit_query, $massedit_params);
    $defaultvalue_query = "update vtiger_field set defaultvalue=? where fieldid = ? and fieldname not in (?) AND displaytype != 2";
    $defaultvalue_params = array($defaultvalue, $fieldid, $fieldname_list);
    $adb->pquery($defaultvalue_query, $defaultvalue_params);
}
$recordId = vtlib_purify($_REQUEST["record"]);
$leadId = vtws_getWebserviceEntityId('Leads', $recordId);
$assigned_to = $_REQUEST["assigntype"];
if ($assigned_to == "U") {
    $assigned_user_id = $_REQUEST["assigned_user_id"];
    $assignedTo = vtws_getWebserviceEntityId('Users', $assigned_user_id);
} else {
    $assigned_user_id = $_REQUEST["assigned_group_id"];
    $assignedTo = vtws_getWebserviceEntityId('Groups', $assigned_user_id);
}
$accountName = $_REQUEST['account_name'];
$createPotential = $_REQUEST["createpotential"];
$avoidPotential = isset($createPotential) && $createPotential == "on" ? true : false;
$potential = array();
$potential['potentialname'] = vtlib_purify($_REQUEST["potential_name"]);
$potential['closingdate'] = getValidDBInsertDateValue($_REQUEST["closedate"]);
$potential['amount'] = vtlib_purify($_REQUEST['potential_amount']);
$potential['sales_stage'] = vtlib_purify($_REQUEST['potential_sales_stage']);
$transferRelatedRecordsTo = $_REQUEST['transfer_related_records_to'];
if (empty($transferRelatedRecordsTo)) {
    $transferRelatedRecordsTo = 'Contacts';
}
$result = vtws_convertlead($leadId, $assignedTo, $accountName, $avoidPotential, $potential, $transferRelatedRecordsTo, $current_user);
$accountIdComponents = vtws_getIdComponents($result['accountId']);
$accountId = $accountIdComponents[1];
$contactIdComponents = vtws_getIdComponents($result['contactId']);
$contactId = $contactIdComponents[1];
$potentialIdComponents = vtws_getIdComponents($result['potentialId']);
$potentialId = $potentialIdComponents[1];
if (!empty($accountId)) {
    header("Location: index.php?action=DetailView&module=Accounts&record={$accountId}&parenttab={$category}");
예제 #10
0
 /** Function to insert values in vtiger_activity_reminder_popup table for the specified module
  * @param $cbmodule -- module:: Type varchar
  */
 function insertIntoActivityReminderPopup($cbmodule)
 {
     $adb = PearDatabase::getInstance();
     $cbrecord = $this->id;
     unset($_SESSION['next_reminder_time']);
     if (isset($cbmodule) && isset($cbrecord)) {
         $cbdate = getValidDBInsertDateValue($this->column_fields['date_start']);
         $cbtime = $this->column_fields['time_start'];
         $reminderQuery = 'SELECT reminderid FROM vtiger_activity_reminder_popup WHERE semodule = ? and recordid = ?';
         $reminderParams = [$cbmodule, $cbrecord];
         $reminderidres = $adb->pquery($reminderQuery, $reminderParams);
         $reminderid = null;
         if ($reminderidres->rowCount() > 0) {
             $reminderid = $adb->query_result($reminderidres, 0, 'reminderid');
         }
         $currentStates = Calendar_Module_Model::getComponentActivityStateLabel('current');
         $state = Calendar_Module_Model::getCalendarState($this->column_fields);
         if (in_array($state, $currentStates)) {
             $status = 0;
         } else {
             $status = 1;
         }
         if (isset($reminderid)) {
             $adb->update('vtiger_activity_reminder_popup', ['date_start' => $cbdate, 'time_start' => $cbtime, 'status' => $status], 'reminderid = ?', [$reminderid]);
         } else {
             $adb->insert('vtiger_activity_reminder_popup', ['recordid' => $cbrecord, 'semodule' => $cbmodule, 'date_start' => $cbdate, 'time_start' => $cbtime, 'status' => $status]);
         }
     }
 }
예제 #11
0
 /** Function to insert values in vtiger_activity_reminder_popup table for the specified module
  * @param $cbmodule -- module:: Type varchar
  */
 function insertIntoActivityReminderPopup($cbmodule)
 {
     $adb = PearDatabase::getInstance();
     $cbrecord = $this->id;
     unset($_SESSION['next_reminder_time']);
     if (isset($cbmodule) && isset($cbrecord)) {
         $cbdate = getValidDBInsertDateValue($this->column_fields['date_start']);
         $cbtime = $this->column_fields['time_start'];
         $reminder_query = "SELECT reminderid FROM vtiger_activity_reminder_popup WHERE semodule = ? and recordid = ?";
         $reminder_params = array($cbmodule, $cbrecord);
         $reminderidres = $adb->pquery($reminder_query, $reminder_params);
         $reminderid = null;
         if ($adb->num_rows($reminderidres) > 0) {
             $reminderid = $adb->query_result($reminderidres, 0, "reminderid");
         }
         if (isset($reminderid)) {
             $current_date = new DateTime();
             $record_date = new DateTime($cbdate . ' ' . $cbtime);
             $current = $current_date->format('Y-m-d H:i:s');
             $record = $record_date->format('Y-m-d H:i:s');
             if (strtotime($record) > strtotime($current)) {
                 $callback_query = "UPDATE vtiger_activity_reminder_popup set status = 0, date_start = ?, time_start = ? WHERE reminderid = ?";
                 $callback_params = array($cbdate, $cbtime, $reminderid);
             }
         } else {
             $callback_query = "INSERT INTO vtiger_activity_reminder_popup (recordid, semodule, date_start, time_start) VALUES (?,?,?,?)";
             $callback_params = array($cbrecord, $cbmodule, $cbdate, $cbtime);
         }
         if ($callback_query) {
             $adb->pquery($callback_query, $callback_params);
         }
     }
 }
예제 #12
0
	public function transformForImport($fieldData, $moduleMeta, $fillDefault=true) {
		$moduleFields = $moduleMeta->getModuleFields();
		$defaultFieldValues = $this->getDefaultFieldValues($moduleMeta);
		foreach ($fieldData as $fieldName => $fieldValue) {
			$fieldInstance = $moduleFields[$fieldName];
			if ($fieldInstance->getFieldDataType() == 'owner') {
				$ownerId = getUserId_Ol($fieldValue);
				if (empty($ownerId)) {
					$ownerId = getGrpId($fieldValue);
				}
				if (empty($ownerId) && isset($defaultFieldValues[$fieldName])) {
					$ownerId = $defaultFieldValues[$fieldName];
				}
				if(empty($ownerId) ||
							!Import_Utils::hasAssignPrivilege($moduleMeta->getEntityName(), $ownerId)) {
					$ownerId = $this->user->id;
				}
				$fieldData[$fieldName] = $ownerId;

			} elseif ($fieldInstance->getFieldDataType() == 'reference') {
				$entityId = false;
				if (!empty($fieldValue)) {
					if(strpos($fieldValue, '::::') > 0) {
						$fieldValueDetails = explode('::::', $fieldValue);
					} else {
						$fieldValueDetails = explode(':::', $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::hasAssignPrivilege($moduleMeta->getEntityName(), $referenceEntityId)) {
									$referenceEntityId = $this->user->id;
								}
							} else {
								$referenceEntityId = getEntityId($referenceModule, $entityLabel);
							}
							if ($referenceEntityId != 0) {
								$entityId = $referenceEntityId;
								break;
							}
						}
					}
					if ((empty($entityId) || $entityId == 0) && !empty($referenceModuleName)) {
						if(isPermitted($referenceModuleName, 'EditView') == 'yes') {
							$wsEntityIdInfo = $this->createEntityRecord($referenceModuleName, $entityLabel);
							$wsEntityId = $wsEntityIdInfo['id'];
							$entityIdComponents = vtws_getIdComponents($wsEntityId);
							$entityId = $entityIdComponents[1];
						}
					}
					$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::hasAssignPrivilege($moduleMeta->getEntityName(), $fieldData[$fieldName])) {
							$fieldData[$fieldName] = $this->user->id;
						}
					} else {
						$fieldData[$fieldName] = '';
					}
				}

			} elseif ($fieldInstance->getFieldDataType() == 'picklist') {
				global $default_charset;
				if (empty($fieldValue) && isset($defaultFieldValues[$fieldName])) {
					$fieldData[$fieldName] = $fieldValue = $defaultFieldValues[$fieldName];
				}
				$allPicklistDetails = $fieldInstance->getPicklistDetails();
				$allPicklistValues = array();
				foreach ($allPicklistDetails as $picklistDetails) {
					$allPicklistValues[] = $picklistDetails['value'];
				}
				$encodePicklistValue = htmlentities($fieldValue,ENT_QUOTES,$default_charset);
				if (!in_array($encodePicklistValue, $allPicklistValues)) {
					$moduleObject = Vtiger_Module::getInstance($moduleMeta->getEntityName());
					$fieldObject = Vtiger_Field::getInstance($fieldName, $moduleObject);
					$fieldObject->setPicklistValues(array($fieldValue));
				}
			} 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];
				}
			}
		}

		foreach ($moduleFields as $fieldName => $fieldInstance) {
			if(empty($fieldData[$fieldName]) && $fieldInstance->isMandatory()) {
				return null;
			}
		}

		return DataTransform::sanitizeData($fieldData, $moduleMeta);
	}
예제 #13
0
 /**
  *
  * @param mixed $value
  * @param String $operator
  * @param WebserviceField $field
  */
 private function getConditionValue($value, $operator, $field)
 {
     $operator = strtolower($operator);
     $db = PearDatabase::getInstance();
     if (is_string($value)) {
         $valueArray = explode(',', $value);
     } elseif (is_array($value)) {
         $valueArray = $value;
     } else {
         $valueArray = array($value);
     }
     $sql = array();
     if ($operator == 'between') {
         if ($field->getFieldName() == 'birthday') {
             $sql[] = "BETWEEN DATE_FORMAT(" . $db->quote($valueArray[0]) . ", '%m%d') AND " . "DATE_FORMAT(" . $db->quote($valueArray[1]) . ", '%m%d')";
         } else {
             $sql[] = "BETWEEN " . $db->quote($valueArray[0]) . " AND " . $db->quote($valueArray[1]);
         }
         return $sql;
     }
     foreach ($valueArray as $value) {
         if (!$this->isStringType($field->getFieldDataType())) {
             $value = trim($value);
         }
         if (strtolower(trim($value)) == 'null' || trim($value) == '' && !$this->isStringType($field->getFieldDataType()) && ($operator == 'e' || $operator == 'n')) {
             if ($operator == 'e') {
                 $sql[] = "IS NULL";
                 continue;
             }
             $sql[] = "IS NOT NULL";
             continue;
         } elseif ($field->getFieldDataType() == 'boolean') {
             $value = strtolower($value);
             if ($value == 'yes') {
                 $value = 1;
             } elseif ($value == 'no') {
                 $value = 0;
             }
         } elseif ($this->isDateType($field->getFieldDataType())) {
             if ($field->getFieldDataType() == 'datetime') {
                 $valueList = explode(' ', $value);
                 $value = $valueList[0];
             }
             $value = getValidDBInsertDateValue($value);
             if ($field->getFieldDataType() == 'datetime') {
                 $value .= ' ' . $valueList[1];
             }
         }
         if ($field->getFieldName() == 'birthday' && !$this->isRelativeSearchOperators($operator)) {
             $value = "DATE_FORMAT(" . $db->quote($value) . ", '%m%d')";
         } else {
             $value = $db->sql_escape_string($value);
         }
         if (trim($value) == '' && ($operator == 's' || $operator == 'ew' || $operator == 'c') && ($this->isStringType($field->getFieldDataType()) || $field->getFieldDataType() == 'picklist' || $field->getFieldDataType() == 'multipicklist')) {
             $sql[] = "LIKE ''";
             continue;
         }
         if (trim($value) == '' && $operator == 'k' && $this->isStringType($field->getFieldDataType())) {
             $sql[] = "NOT LIKE ''";
             continue;
         }
         switch ($operator) {
             case 'e':
                 $sqlOperator = "=";
                 break;
             case 'n':
                 $sqlOperator = "<>";
                 break;
             case 's':
                 $sqlOperator = "LIKE";
                 $value = "{$value}%";
                 break;
             case 'ew':
                 $sqlOperator = "LIKE";
                 $value = "%{$value}";
                 break;
             case 'c':
                 $sqlOperator = "LIKE";
                 $value = "%{$value}%";
                 break;
             case 'k':
                 $sqlOperator = "NOT LIKE";
                 $value = "%{$value}%";
                 break;
             case 'l':
                 $sqlOperator = "<";
                 break;
             case 'g':
                 $sqlOperator = ">";
                 break;
             case 'm':
                 $sqlOperator = "<=";
                 break;
             case 'h':
                 $sqlOperator = ">=";
                 break;
         }
         if (!$this->isNumericType($field->getFieldDataType()) && ($field->getFieldName() != 'birthday' || $field->getFieldName() == 'birthday' && $this->isRelativeSearchOperators($operator))) {
             $value = "'{$value}'";
         }
         $sql[] = "{$sqlOperator} {$value}";
     }
     return $sql;
 }
 /** 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);
     }
 }
예제 #15
0
 /**
  * Process the request to perform relationship operations
  * @global Users Instance $current_user
  * @global PearDataBase Instance $adb
  * @global String $currentModule
  * @param MailManager_Request $request
  * @return boolean
  */
 function process(MailManager_Request $request)
 {
     global $current_user, $adb;
     $response = new MailManager_Response(true);
     $viewer = $this->getViewer();
     if ('find' == $request->getOperationArg()) {
         $this->skipConnection = true;
         // No need to connect to mailbox here, improves performance
         // Check if the message is already linked.
         //$linkedto = MailManager_RelationControllerAction::associatedLink($request->get('_msguid'));
         // If the message was not linked, lookup for matching records, using FROM address
         //if (empty($linkedto)) {
         $msguid = $request->get('_msguid');
         $results = array();
         $modules = array();
         $allowedModules = $this->getCurrentUserMailManagerAllowedModules();
         foreach (self::$MODULES as $MODULE) {
             if (!in_array($MODULE, $allowedModules)) {
                 continue;
             }
             $from = $request->get('_mfrom');
             if (empty($from)) {
                 continue;
             }
             $results[$MODULE] = $this->lookupModuleRecordsWithEmail($MODULE, $from, $msguid);
             $describe = $this->ws_describe($MODULE);
             $modules[$MODULE] = array('label' => $describe['label'], 'name' => textlength_check($describe['name']), 'id' => $describe['idPrefix']);
             // If look is found in a module, skip rest. - for performance
             //if (!empty($results[$MODULE])) break;
         }
         $viewer->assign('LOOKUPS', $results);
         $viewer->assign('MODULES', $modules);
         //} else {
         //	$viewer->assign('LINKEDTO', $linkedto);
         //}
         $viewer->assign('LinkToAvailableActions', $this->linkToAvailableActions());
         $viewer->assign('AllowedModules', $allowedModules);
         $viewer->assign('MSGNO', $request->get('_msgno'));
         $viewer->assign('FOLDER', $request->get('_folder'));
         $response->setResult(array('ui' => $viewer->fetch($this->getModuleTpl('Relationship.tpl'))));
     } else {
         if ('link' == $request->getOperationArg()) {
             $linkto = $request->get('_mlinkto');
             $foldername = $request->get('_folder');
             $connector = $this->getConnector($foldername);
             // This is to handle larger uploads
             $memory_limit = ConfigPrefs::get('MEMORY_LIMIT');
             ini_set('memory_limit', $memory_limit);
             $mail = $connector->openMail($request->get('_msgno'));
             $mail->attachments();
             // Initialize attachments
             $linkedto = MailManager_RelationControllerAction::associate($mail, $linkto);
             $viewer->assign('LinkToAvailableActions', $this->linkToAvailableActions());
             $viewer->assign('AllowedModules', $this->getCurrentUserMailManagerAllowedModules());
             $viewer->assign('LINKEDTO', $linkedto);
             $viewer->assign('MSGNO', $request->get('_msgno'));
             $viewer->assign('FOLDER', $foldername);
             $response->setResult(array('ui' => $viewer->fetch($this->getModuleTpl('Relationship.tpl'))));
         } else {
             if ('create_wizard' == $request->getOperationArg()) {
                 global $currentModule;
                 $moduleName = $request->get('_mlinktotype');
                 $parent = $request->get('_mlinkto');
                 $foldername = $request->get('_folder');
                 $connector = $this->getConnector($foldername);
                 $mail = $connector->openMail($request->get('_msgno'));
                 $qcreate_array = QuickCreate($moduleName);
                 $validationData = $qcreate_array['data'];
                 $data = split_validationdataArray($validationData);
                 $qcreate_array['form'] = $this->processFormData($qcreate_array['form'], $mail);
                 $viewer->assign("QUICKCREATE", $qcreate_array['form']);
                 if ($moduleName == 'Calendar') {
                     $viewer->assign("QCMODULE", getTranslatedString('Todo', 'Calendar'));
                 } elseif ($moduleName == "HelpDesk") {
                     $viewer->assign("QCMODULE", getTranslatedString('Ticket', 'HelpDesk'));
                 } else {
                     $viewer->assign("QCMODULE", getTranslatedString("SINGLE_" . $moduleName, $moduleName));
                 }
                 $viewer->assign("PARENT", $parent);
                 $viewer->assign("MODULE", $moduleName);
                 $viewer->assign('MSGNO', $request->get('_msgno'));
                 $viewer->assign('FOLDER', $foldername);
                 $viewer->assign("VALIDATION_DATA_FIELDNAME", $data['fieldname']);
                 $viewer->assign("VALIDATION_DATA_FIELDDATATYPE", $data['datatype']);
                 $viewer->assign("VALIDATION_DATA_FIELDLABEL", $data['fieldlabel']);
                 $viewer->display($this->getModuleTpl('Relationship.CreateWizard.tpl'));
                 $response = false;
             } else {
                 if ('create' == $request->getOperationArg()) {
                     $linkModule = $request->get('_mlinktotype');
                     $parent = $request->get('_mlinkto');
                     $focus = CRMEntity::getInstance($linkModule);
                     // This is added as ModComments module has a bug that will not initialize column_fields
                     // Basically $currentModule is set to MailManager, so the fields are not set properly.
                     if (empty($focus->column_fields)) {
                         $focus->column_fields = getColumnFields($linkModule);
                     }
                     setObjectValuesFromRequest($focus);
                     if ($request->get('assigntype') == 'U') {
                         $focus->column_fields['assigned_user_id'] = $request->get('assigned_user_id');
                     } elseif ($request->get('assigntype') == 'T') {
                         $focus->column_fields['assigned_user_id'] = $request->get('assigned_group_id');
                     }
                     $foldername = $request->get('_folder');
                     if (!empty($foldername)) {
                         // This is to handle larger uploads
                         $memory_limit = ConfigPrefs::get('MEMORY_LIMIT');
                         ini_set('memory_limit', $memory_limit);
                         $connector = $this->getConnector($foldername);
                         $mail = $connector->openMail($request->get('_msgno'));
                         $attachments = $mail->attachments();
                         // Initialize attachments
                     }
                     $linkedto = MailManager_RelationControllerAction::getSalesEntityInfo($parent);
                     switch ($linkModule) {
                         case 'Calendar':
                             if (empty($focus->column_fields['activitytype'])) {
                                 $focus->column_fields['activitytype'] = 'Task';
                             }
                             if (empty($focus->column_fields['due_date'])) {
                                 if (!empty($focus->column_fields['date_start'])) {
                                     $dateStart = getValidDBInsertDateValue($focus->column_fields['date_start']);
                                     $focus->column_fields['due_date'] = date("Y-m-d", strtotime(date("Y-m-d", strtotime($dateStart)) . " +1 day"));
                                 } else {
                                     $focus->column_fields['due_date'] = date('Y-m-d', strtotime("+1 day"));
                                 }
                             }
                             if (!empty($parent)) {
                                 if ($linkedto['module'] == 'Contacts') {
                                     $focus->column_fields['contact_id'] = $parent;
                                 } else {
                                     $focus->column_fields['parent_id'] = $parent;
                                 }
                             }
                             break;
                         case 'HelpDesk':
                             $from = $mail->from();
                             $focus->column_fields['parent_id'] = $this->setParentForHelpDesk($parent, $from);
                             break;
                         case 'ModComments':
                             $focus->column_fields['assigned_user_id'] = $current_user->id;
                             $focus->column_fields['creator'] = $current_user->id;
                             $focus->column_fields['related_to'] = $parent;
                             break;
                     }
                     try {
                         $focus->save($linkModule);
                         // This condition is added so that emails are not created for Todo without Parent,
                         // as there is no way to relate them
                         if (empty($parent) && $linkModule != 'Calendar') {
                             $linkedto = MailManager_RelationControllerAction::associate($mail, $focus->id);
                         }
                         // add attachments to the tickets as Documents
                         if (in_array($linkModule, array('HelpDesk', 'Potentials', 'Project', 'ProjectTask')) && !empty($attachments)) {
                             $relationController = new MailManager_RelationControllerAction();
                             $relationController->__SaveAttachements($mail, $linkModule, $focus);
                         }
                         $viewer->assign('MSGNO', $request->get('_msgno'));
                         $viewer->assign('LINKEDTO', $linkedto);
                         $viewer->assign('AllowedModules', $this->getCurrentUserMailManagerAllowedModules());
                         $viewer->assign('LinkToAvailableActions', $this->linkToAvailableActions());
                         $viewer->assign('FOLDER', $foldername);
                         $response->setResult(array('ui' => $viewer->fetch($this->getModuleTpl('Relationship.tpl'))));
                     } catch (Exception $e) {
                         $response->setResult(array('ui' => '', 'error' => $e));
                     }
                 } else {
                     if ('savedraft' == $request->getOperationArg()) {
                         $connector = $this->getConnector('__vt_drafts');
                         $draftResponse = $connector->saveDraft($request);
                         $response->setResult($draftResponse);
                     } else {
                         if ('saveattachment' == $request->getOperationArg()) {
                             $connector = $this->getConnector('__vt_drafts');
                             $uploadResponse = $connector->saveAttachment($request);
                             $response->setResult($uploadResponse);
                         } else {
                             if ('commentwidget' == $request->getOperationArg()) {
                                 $viewer->assign('LINKMODULE', $request->get('_mlinktotype'));
                                 $viewer->assign('PARENT', $request->get('_mlinkto'));
                                 $viewer->assign('MSGNO', $request->get('_msgno'));
                                 $viewer->assign('FOLDER', $request->get('_folder'));
                                 $viewer->display($this->getModuleTpl('MailManager.CommentWidget.tpl'));
                                 $response = false;
                             }
                         }
                     }
                 }
             }
         }
     }
     return $response;
 }
예제 #16
0
파일: utils.php 프로젝트: yunter/crm
function getValidDBInsertDateTimeValue($value)
{
    $value = trim($value);
    $valueList = explode(' ', $value);
    if (count($valueList) == 2) {
        $dbDateValue = getValidDBInsertDateValue($valueList[0]);
        $dbTimeValue = $valueList[1];
        if (!empty($dbTimeValue) && strpos($dbTimeValue, ':') === false) {
            $dbTimeValue = $dbTimeValue . ':';
        }
        $timeValueLength = strlen($dbTimeValue);
        if (!empty($dbTimeValue) && strrpos($dbTimeValue, ':') == $timeValueLength - 1) {
            $dbTimeValue = $dbTimeValue . '00';
        }
        try {
            $dateTime = new DateTimeField($dbDateValue . ' ' . $dbTimeValue);
            return $dateTime->getDBInsertDateTimeValue();
        } catch (Exception $ex) {
            return '';
        }
    } elseif (count($valueList == 1)) {
        return getValidDBInsertDateValue($value);
    }
}
예제 #17
0
        $focus->retrieve_entity_info($_REQUEST['record'], "SalesOrder");
        $focus->name = $focus->column_fields['subject'];
    }
} else {
    if (isset($_REQUEST['convertmode']) && $_REQUEST['convertmode'] == 'update_quote_val') {
        //Updating the Select Quote Value in Create Mode
        foreach ($focus->column_fields as $fieldname => $val) {
            if (isset($_REQUEST[$fieldname])) {
                $value = $_REQUEST[$fieldname];
                $focus->column_fields[$fieldname] = $value;
            }
        }
        //Handling for dateformat in due_date vtiger_field
        if ($focus->column_fields['duedate'] != '') {
            $curr_due_date = $focus->column_fields['duedate'];
            $focus->column_fields['duedate'] = getValidDBInsertDateValue($curr_due_date);
        }
        $quoteid = $focus->column_fields['quote_id'];
        $quote_focus = new Quotes();
        $quote_focus->id = $quoteid;
        $quote_focus->retrieve_entity_info($quoteid, "Quotes");
        $focus = getConvertQuoteToSoObject($focus, $quote_focus, $quoteid);
        // Reset the value w.r.t Quote Selected
        $currencyid = $quote_focus->column_fields['currency_id'];
        $rate = $quote_focus->column_fields['conversion_rate'];
        //Added to display the Quotes's associated vtiger_products -- when we select Quote in New SO page
        if (isset($_REQUEST['quote_id']) && $_REQUEST['quote_id'] != '') {
            $associated_prod = getAssociatedProducts("Quotes", $quote_focus, $focus->column_fields['quote_id']);
        }
        $smarty->assign("QUOTE_ID", $focus->column_fields['quote_id']);
        $smarty->assign("ASSOCIATEDPRODUCTS", $associated_prod);
예제 #18
0
 /** Function to insert values in vtiger_activity_reminder_popup table for the specified module
  * @param $cbmodule -- module:: Type varchar
  */
 function insertIntoActivityReminderPopup($cbmodule)
 {
     global $adb;
     $cbrecord = $this->id;
     unset($_SESSION['next_reminder_time']);
     if (isset($cbmodule) && isset($cbrecord)) {
         $cbdate = getValidDBInsertDateValue($this->column_fields['date_start']);
         $cbtime = $this->column_fields['time_start'];
         $reminder_query = "SELECT reminderid FROM vtiger_activity_reminder_popup WHERE recordid = ?";
         $reminder_params = array($cbrecord);
         $reminderidres = $adb->pquery($reminder_query, $reminder_params);
         $reminderid = null;
         if ($adb->num_rows($reminderidres) > 0) {
             $reminderid = $adb->query_result($reminderidres, 0, "reminderid");
         }
         if (isset($reminderid)) {
             $callback_query = "UPDATE vtiger_activity_reminder_popup set status = 0, date_start = ?, time_start = ? WHERE reminderid = ?";
             $callback_params = array($cbdate, $cbtime, $reminderid);
         } else {
             $callback_query = "INSERT INTO vtiger_activity_reminder_popup (recordid, semodule, date_start, time_start, status) VALUES (?,?,?,?,0)";
             $callback_params = array($cbrecord, $cbmodule, $cbdate, $cbtime);
         }
         $adb->pquery($callback_query, $callback_params);
     }
 }
예제 #19
0
 /**
  * Process the request to perform relationship operations
  * @global Users Instance $current_user
  * @global PearDataBase Instance $adb
  * @global String $currentModule
  * @param Vtiger_Request $request
  * @return boolean
  */
 function process(Vtiger_Request $request)
 {
     global $current_user, $adb;
     $response = new Vtiger_Response(true);
     $viewer = $this->getViewer($request);
     if ('find' == $this->getOperationArg($request)) {
         $this->skipConnection = true;
         // No need to connect to mailbox here, improves performance
         // Check if the message is already linked.
         $linkedto = MailManager_Relate_Action::associatedLink($request->get('_msguid'));
         // If the message was not linked, lookup for matching records, using FROM address
         if (empty($linkedto)) {
             $results = array();
             $modules = array();
             $allowedModules = $this->getCurrentUserMailManagerAllowedModules();
             foreach (self::$MODULES as $MODULE) {
                 if (!in_array($MODULE, $allowedModules)) {
                     continue;
                 }
                 $from = $request->get('_mfrom');
                 if (empty($from)) {
                     continue;
                 }
                 $results[$MODULE] = $this->lookupModuleRecordsWithEmail($MODULE, $from);
                 $describe = $this->ws_describe($MODULE);
                 $modules[$MODULE] = array('label' => $describe['label'], 'name' => textlength_check($describe['name']), 'id' => $describe['idPrefix']);
                 // If look is found in a module, skip rest. - for performance
                 //if (!empty($results[$MODULE])) break;
             }
             $viewer->assign('LOOKUPS', $results);
             $viewer->assign('MODULES', $modules);
         } else {
             $viewer->assign('LINKEDTO', $linkedto);
         }
         $viewer->assign('LinkToAvailableActions', $this->linkToAvailableActions());
         $viewer->assign('AllowedModules', $allowedModules);
         $viewer->assign('MSGNO', $request->get('_msgno'));
         $viewer->assign('FOLDER', $request->get('_folder'));
         $response->setResult(array('ui' => $viewer->view('Relationship.tpl', 'MailManager', true)));
     } else {
         if ('link' == $this->getOperationArg($request)) {
             $linkto = $request->get('_mlinkto');
             $foldername = $request->get('_folder');
             $connector = $this->getConnector($foldername);
             // This is to handle larger uploads
             $memory_limit = MailManager_Config::get('MEMORY_LIMIT');
             ini_set('memory_limit', $memory_limit);
             $mail = $connector->openMail($request->get('_msgno'));
             $mail->attachments();
             // Initialize attachments
             $linkedto = MailManager_Relate_Action::associate($mail, $linkto);
             $viewer->assign('LinkToAvailableActions', $this->linkToAvailableActions());
             $viewer->assign('AllowedModules', $this->getCurrentUserMailManagerAllowedModules());
             $viewer->assign('LINKEDTO', $linkedto);
             $viewer->assign('MSGNO', $request->get('_msgno'));
             $viewer->assign('FOLDER', $foldername);
             $response->setResult(array('ui' => $viewer->view('Relationship.tpl', 'MailManager', true)));
         } else {
             if ('create_wizard' == $this->getOperationArg($request)) {
                 global $currentModule;
                 $moduleName = $request->get('_mlinktotype');
                 $parent = $request->get('_mlinkto');
                 $foldername = $request->get('_folder');
                 $connector = $this->getConnector($foldername);
                 $mail = $connector->openMail($request->get('_msgno'));
                 $formData = $this->processFormData($mail);
                 foreach ($formData as $key => $value) {
                     $request->set($key, $value);
                 }
                 $request->set('module', $moduleName);
                 // Delegate QuickCreate FormUI to the target view controller of module.
                 $quickCreateviewClassName = $moduleName . '_QuickCreateAjax_View';
                 if (!class_exists($quickCreateviewClassName)) {
                     $quickCreateviewClassName = 'Vtiger_QuickCreateAjax_View';
                 }
                 $quickCreateViewController = new $quickCreateviewClassName();
                 $quickCreateViewController->process($request);
                 // UI already sent
                 $response = false;
             } else {
                 if ('create' == $this->getOperationArg($request)) {
                     $linkModule = $request->get('_mlinktotype');
                     $parent = $request->get('_mlinkto');
                     $focus = CRMEntity::getInstance($linkModule);
                     // This is added as ModComments module has a bug that will not initialize column_fields
                     // Basically $currentModule is set to MailManager, so the fields are not set properly.
                     if (empty($focus->column_fields)) {
                         $focus->column_fields = getColumnFields($linkModule);
                     }
                     foreach ($focus->column_fields as $fieldname => $val) {
                         if ($request->has($fieldname)) {
                             $focus->column_fields[$fieldname] = $request->get($fieldname);
                         }
                     }
                     $foldername = $request->get('_folder');
                     if (!empty($foldername)) {
                         // This is to handle larger uploads
                         $memory_limit = MailManager_Config::get('MEMORY_LIMIT');
                         ini_set('memory_limit', $memory_limit);
                         $connector = $this->getConnector($foldername);
                         $mail = $connector->openMail($request->get('_msgno'));
                         $attachments = $mail->attachments();
                         // Initialize attachments
                     }
                     $linkedto = MailManager_Relate_Action::getSalesEntityInfo($parent);
                     switch ($linkModule) {
                         case 'Calendar':
                             if (empty($focus->column_fields['activitytype'])) {
                                 $focus->column_fields['activitytype'] = 'Task';
                             }
                             if (empty($focus->column_fields['due_date'])) {
                                 if (!empty($focus->column_fields['date_start'])) {
                                     $dateStart = getValidDBInsertDateValue($focus->column_fields['date_start']);
                                     $focus->column_fields['due_date'] = date("Y-m-d", strtotime(date("Y-m-d", strtotime($dateStart)) . " +1 day"));
                                 } else {
                                     $focus->column_fields['due_date'] = date('Y-m-d', strtotime("+1 day"));
                                 }
                             }
                             if (!empty($parent)) {
                                 if ($linkedto['module'] == 'Contacts') {
                                     $focus->column_fields['contact_id'] = $parent;
                                 } else {
                                     $focus->column_fields['parent_id'] = $parent;
                                 }
                             }
                             break;
                         case 'HelpDesk':
                             $from = $mail->from();
                             $focus->column_fields['parent_id'] = $this->setParentForHelpDesk($parent, $from);
                             break;
                         case 'ModComments':
                             $focus->column_fields['assigned_user_id'] = $current_user->id;
                             $focus->column_fields['creator'] = $current_user->id;
                             $focus->column_fields['related_to'] = $parent;
                             break;
                     }
                     try {
                         $focus->save($linkModule);
                         // This condition is added so that emails are not created for Tickets and Todo without Parent,
                         // as there is no way to relate them
                         if (empty($parent) && $linkModule != 'HelpDesk' && $linkModule != 'Calendar') {
                             $linkedto = MailManager_Relate_Action::associate($mail, $focus->id);
                         }
                         // add attachments to the tickets as Documents
                         if ($linkModule == 'HelpDesk' && !empty($attachments)) {
                             $relationController = new MailManager_Relate_Action();
                             $relationController->__SaveAttachements($mail, $linkModule, $focus);
                         }
                         $viewer->assign('MSGNO', $request->get('_msgno'));
                         $viewer->assign('LINKEDTO', $linkedto);
                         $viewer->assign('AllowedModules', $this->getCurrentUserMailManagerAllowedModules());
                         $viewer->assign('LinkToAvailableActions', $this->linkToAvailableActions());
                         $viewer->assign('FOLDER', $foldername);
                         $response->setResult(array('ui' => $viewer->view('Relationship.tpl', 'MailManager', true)));
                     } catch (Exception $e) {
                         $response->setResult(array('ui' => '', 'error' => $e));
                     }
                 } else {
                     if ('savedraft' == $this->getOperationArg($request)) {
                         $connector = $this->getConnector('__vt_drafts');
                         $draftResponse = $connector->saveDraft($request);
                         $response->setResult($draftResponse);
                     } else {
                         if ('saveattachment' == $this->getOperationArg($request)) {
                             $connector = $this->getConnector('__vt_drafts');
                             $uploadResponse = $connector->saveAttachment($request);
                             $response->setResult($uploadResponse);
                         } else {
                             if ('commentwidget' == $this->getOperationArg($request)) {
                                 $viewer->assign('LINKMODULE', $request->get('_mlinktotype'));
                                 $viewer->assign('PARENT', $request->get('_mlinkto'));
                                 $viewer->assign('MSGNO', $request->get('_msgno'));
                                 $viewer->assign('FOLDER', $request->get('_folder'));
                                 $viewer->view('MailManagerCommentWidget.tpl', 'MailManager');
                                 $response = false;
                             }
                         }
                     }
                 }
             }
         }
     }
     return $response;
 }