public function create($elementType, $element)
 {
     $crmObject = new VtigerCRMObject($elementType, false);
     $element = DataTransform::sanitizeForInsert($element, $this->meta);
     $error = $crmObject->create($element);
     if (!$error) {
         throw new WebServiceException(WebServiceErrorCode::$DATABASEQUERYERROR, vtws_getWebserviceTranslatedString('LBL_' . WebServiceErrorCode::$DATABASEQUERYERROR));
     }
     $id = $crmObject->getObjectId();
     // Bulk Save Mode
     if (CRMEntity::isBulkSaveMode()) {
         // Avoiding complete read, as during bulk save mode, $result['id'] is enough
         return array('id' => vtws_getId($this->meta->getEntityId(), $id));
     }
     $error = $crmObject->read($id);
     if (!$error) {
         throw new WebServiceException(WebServiceErrorCode::$DATABASEQUERYERROR, vtws_getWebserviceTranslatedString('LBL_' . WebServiceErrorCode::$DATABASEQUERYERROR));
     }
     return DataTransform::filterAndSanitize($crmObject->getFields(), $this->meta);
 }
 /** 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);
     }
 }
Exemplo n.º 3
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 ...");
 }
Exemplo n.º 4
0
function vtws_listtypes($fieldTypeList, $user)
{
    // Bulk Save Mode: For re-using information
    static $webserviceEntities = false;
    // END
    static $types = array();
    if (!empty($fieldTypeList)) {
        $fieldTypeList = array_map(strtolower, $fieldTypeList);
        sort($fieldTypeList);
        $fieldTypeString = implode(',', $fieldTypeList);
    } else {
        $fieldTypeString = 'all';
    }
    if (!empty($types[$user->id][$fieldTypeString])) {
        return $types[$user->id][$fieldTypeString];
    }
    try {
        global $log;
        /**
         * @var PearDatabase
         */
        $db = PearDatabase::getInstance();
        vtws_preserveGlobal('current_user', $user);
        //get All the modules the current user is permitted to Access.
        $allModuleNames = getPermittedModuleNames();
        if (array_search('Calendar', $allModuleNames) !== false) {
            array_push($allModuleNames, 'Events');
        }
        if (!empty($fieldTypeList)) {
            $sql = "SELECT distinct(vtiger_field.tabid) as tabid FROM vtiger_field LEFT JOIN vtiger_ws_fieldtype ON " . "vtiger_field.uitype=vtiger_ws_fieldtype.uitype\n\t\t\t\t INNER JOIN vtiger_profile2field ON vtiger_field.fieldid = vtiger_profile2field.fieldid\n\t\t\t\t INNER JOIN vtiger_def_org_field ON vtiger_def_org_field.fieldid = vtiger_field.fieldid\n\t\t\t\t INNER JOIN vtiger_role2profile ON vtiger_profile2field.profileid = vtiger_role2profile.profileid\n\t\t\t\t INNER JOIN vtiger_user2role ON vtiger_user2role.roleid = vtiger_role2profile.roleid\n\t\t\t\t where vtiger_profile2field.visible=0 and vtiger_def_org_field.visible = 0\n\t\t\t\t and vtiger_field.presence in (0,2)\n\t\t\t\t and vtiger_user2role.userid=? and fieldtype in (" . generateQuestionMarks($fieldTypeList) . ')';
            $params = array();
            $params[] = $user->id;
            foreach ($fieldTypeList as $fieldType) {
                $params[] = $fieldType;
            }
            $result = $db->pquery($sql, $params);
            $it = new SqlResultIterator($db, $result);
            $moduleList = array();
            foreach ($it as $row) {
                $moduleList[] = getTabModuleName($row->tabid);
            }
            $allModuleNames = array_intersect($moduleList, $allModuleNames);
            $params = $fieldTypeList;
            $sql = "select name from vtiger_ws_entity inner join vtiger_ws_entity_tables on " . "vtiger_ws_entity.id=vtiger_ws_entity_tables.webservice_entity_id inner join " . "vtiger_ws_entity_fieldtype on vtiger_ws_entity_fieldtype.table_name=" . "vtiger_ws_entity_tables.table_name where fieldtype=(" . generateQuestionMarks($fieldTypeList) . ')';
            $result = $db->pquery($sql, $params);
            $it = new SqlResultIterator($db, $result);
            $entityList = array();
            foreach ($it as $row) {
                $entityList[] = $row->name;
            }
        }
        //get All the CRM entity names.
        if ($webserviceEntities === false || !CRMEntity::isBulkSaveMode()) {
            // Bulk Save Mode: For re-using information
            $webserviceEntities = vtws_getWebserviceEntities();
        }
        $accessibleModules = array_values(array_intersect($webserviceEntities['module'], $allModuleNames));
        $entities = $webserviceEntities['entity'];
        $accessibleEntities = array();
        if (empty($fieldTypeList)) {
            foreach ($entities as $entity) {
                $webserviceObject = VtigerWebserviceObject::fromName($db, $entity);
                $handlerPath = $webserviceObject->getHandlerPath();
                $handlerClass = $webserviceObject->getHandlerClass();
                require_once $handlerPath;
                $handler = new $handlerClass($webserviceObject, $user, $db, $log);
                $meta = $handler->getMeta();
                if ($meta->hasAccess() === true) {
                    array_push($accessibleEntities, $entity);
                }
            }
        }
    } catch (WebServiceException $exception) {
        throw $exception;
    } catch (Exception $exception) {
        throw new WebServiceException(WebServiceErrorCode::$DATABASEQUERYERROR, "An Database error occured while performing the operation");
    }
    $default_language = VTWS_PreserveGlobal::getGlobal('default_language');
    global $current_language;
    if (empty($current_language)) {
        $current_language = $default_language;
    }
    $current_language = vtws_preserveGlobal('current_language', $current_language);
    $appStrings = return_application_language($current_language);
    $appListString = return_app_list_strings_language($current_language);
    vtws_preserveGlobal('app_strings', $appStrings);
    vtws_preserveGlobal('app_list_strings', $appListString);
    $informationArray = array();
    foreach ($accessibleModules as $module) {
        $vtigerModule = $module == 'Events' ? 'Calendar' : $module;
        $informationArray[$module] = array('isEntity' => true, 'label' => getTranslatedString($module, $vtigerModule), 'singular' => getTranslatedString('SINGLE_' . $module, $vtigerModule));
    }
    foreach ($accessibleEntities as $entity) {
        $label = isset($appStrings[$entity]) ? $appStrings[$entity] : $entity;
        $singular = isset($appStrings['SINGLE_' . $entity]) ? $appStrings['SINGLE_' . $entity] : $entity;
        $informationArray[$entity] = array('isEntity' => false, 'label' => $label, 'singular' => $singular);
    }
    VTWS_PreserveGlobal::flush();
    $types[$user->id][$fieldTypeString] = array("types" => array_merge($accessibleModules, $accessibleEntities), 'information' => $informationArray);
    return $types[$user->id][$fieldTypeString];
}
 private function retrieveMetaForBlock($block)
 {
     global $adb;
     $tabid = $this->getTabId();
     require 'user_privileges/user_privileges_' . $this->user->id . '.php';
     if ($is_admin == true || $profileGlobalPermission[1] == 0 || $profileGlobalPermission[2] == 0) {
         $sql = "select *, '0' as readonly from vtiger_field where tabid =? and block in (" . generateQuestionMarks($block) . ") and displaytype in (1,2,3,4)";
         $params = array($tabid, $block);
     } else {
         $profileList = getCurrentUserProfileList();
         if (count($profileList) > 0) {
             $sql = "SELECT vtiger_field.*, vtiger_profile2field.readonly\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 =? AND 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.block in (" . generateQuestionMarks($block) . ") and vtiger_field.displaytype in (1,2,3,4) and vtiger_field.presence in (0,2) group by columnname";
             $params = array($tabid, $profileList, $block);
         } else {
             $sql = "SELECT vtiger_field.*, vtiger_profile2field.readonly\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.block in (" . generateQuestionMarks($block) . ") and vtiger_field.displaytype in (1,2,3,4) and vtiger_field.presence in (0,2) group by columnname";
             $params = array($tabid, $block);
         }
     }
     // Bulk Save Mode: Group by is not required!?
     if (CRMEntity::isBulkSaveMode()) {
         $sql = preg_replace("/group by [^ ]*/", " ", $sql);
     }
     // END
     $result = $adb->pquery($sql, $params);
     $noofrows = $adb->num_rows($result);
     $referenceArray = array();
     $knownFieldArray = array();
     for ($i = 0; $i < $noofrows; $i++) {
         $fieldname = $adb->query_result($result, $i, "fieldname");
         if (strcasecmp($fieldname, 'imagename') === 0) {
             continue;
         }
         $webserviceField = WebserviceField::fromQueryResult($adb, $result, $i);
         $this->moduleFields[$webserviceField->getFieldName()] = $webserviceField;
     }
 }
Exemplo n.º 6
0
 /**
  * Save the inventory data
  */
 public function saveInventoryData()
 {
     //Event triggering code
     require_once "include/events/include.inc";
     $db = PearDatabase::getInstance();
     $log = vglobal('log');
     $log->debug('Entering ' . __CLASS__ . '::' . __METHOD__);
     $moduleName = $this->getModuleName();
     $inventory = Vtiger_InventoryField_Model::getInstance($moduleName);
     $table = $inventory->getTableName('data');
     if ($this->has('inventoryData')) {
         $request = $this->get('inventoryData');
     } else {
         $request = new Vtiger_Request($_REQUEST, $_REQUEST);
     }
     $numRow = $request->get('inventoryItemsNo');
     //In Bulk mode stop triggering events
     if (!CRMEntity::isBulkSaveMode()) {
         $em = new VTEventsManager($adb);
         // Initialize Event trigger cache
         $em->initTriggerCache();
         $em->triggerEvent('entity.inventory.beforesave', [$this, $inventory, $this->inventoryData]);
     }
     $db->delete($table, 'id = ?', [$this->getId()]);
     foreach ($this->inventoryData as $insertData) {
         $insertData['id'] = $this->getId();
         $db->insert($table, $insertData);
     }
     if ($em) {
         //Event triggering code
         $em->triggerEvent('entity.inventory.aftersave', [$this, $inventory, $this->inventoryData]);
     }
     $log->debug('Exiting ' . __CLASS__ . '::' . __METHOD__);
 }
Exemplo n.º 7
0
 /**
  * Save the inventory data
  */
 public function saveInventoryData()
 {
     //Event triggering code
     require_once "include/events/include.inc";
     $db = PearDatabase::getInstance();
     $log = vglobal('log');
     $log->debug('Entering ' . __CLASS__ . '::' . __METHOD__);
     $moduleName = $this->getModuleName();
     $inventory = Vtiger_InventoryField_Model::getInstance($moduleName);
     $fields = $inventory->getColumns();
     $table = $inventory->getTableName('data');
     $summaryFields = $inventory->getSummaryFields();
     $insertDataTemp = $summary = [];
     $request = new Vtiger_Request($_REQUEST, $_REQUEST);
     $numRow = $request->get('inventoryItemsNo');
     //In Bulk mode stop triggering events
     if (!CRMEntity::isBulkSaveMode()) {
         $em = new VTEventsManager($adb);
         // Initialize Event trigger cache
         $em->initTriggerCache();
         $em->triggerEvent('entity.inventory.beforesave', [$this, $inventory]);
     }
     $db->pquery("delete from {$table} where id = ?", [$this->getId()]);
     for ($i = 1; $i <= $numRow; $i++) {
         if (!$request->has(reset($fields)) && !$request->has(reset($fields) . $i)) {
             continue;
         }
         $insertData = ['id' => $this->getId(), 'seq' => $request->get('seq' . $i)];
         foreach ($fields as $field) {
             $value = $insertData[$field] = $inventory->getValueForSave($request, $field, $i);
             if (in_array($field, $summaryFields)) {
                 $summary[$field] += $value;
             }
         }
         $db->insert($table, $insertData);
         $insertDataTemp[] = $insertData;
     }
     foreach ($summary as $fieldName => $fieldValue) {
         if ($this->has($fieldName)) {
             $this->set($fieldName, CurrencyField::convertToUserFormat($fieldValue, null, true));
         }
     }
     if ($em) {
         //Event triggering code
         $em->triggerEvent('entity.inventory.aftersave', [$this, $inventory, $insertDataTemp, $summary]);
     }
     $log->debug('Exiting ' . __CLASS__ . '::' . __METHOD__);
 }