示例#1
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);
     }
 }
示例#2
0
 /**
  * Function to returns all skins(themes)
  * @return <Array>
  */
 public static function getAllSkins()
 {
     return Vtiger_Util_Helper::getAllSkins();
 }