[ Index ] |
PHP Cross Reference of vtigercrm-6.1.0 |
[Summary view] [Print] [Text view]
1 <?php 2 /*+******************************************************************************** 3 * The contents of this file are subject to the vtiger CRM Public License Version 1.0 4 * ("License"); You may not use this file except in compliance with the License 5 * The Original Code is: vtiger CRM Open Source 6 * The Initial Developer of the Original Code is vtiger. 7 * Portions created by vtiger are Copyright (C) vtiger. 8 * All Rights Reserved. 9 *********************************************************************************/ 10 require_once 'includes/runtime/Cache.php'; 11 /** 12 * this file will be used to store the functions to be used in the picklist module 13 */ 14 15 /** 16 * Function to get picklist fields for the given module 17 * @ param $fld_module 18 * It gets the picklist details array for the given module in the given format 19 * $fieldlist = Array(Array('fieldlabel'=>$fieldlabel,'generatedtype'=>$generatedtype,'columnname'=>$columnname,'fieldname'=>$fieldname,'value'=>picklistvalues)) 20 */ 21 function getUserFldArray($fld_module,$roleid){ 22 global $adb, $log; 23 $user_fld = Array(); 24 $tabid = getTabid($fld_module); 25 26 $query="select vtiger_field.fieldlabel,vtiger_field.columnname,vtiger_field.fieldname, vtiger_field.uitype" . 27 " FROM vtiger_field inner join vtiger_picklist on vtiger_field.fieldname = vtiger_picklist.name" . 28 " where (displaytype=1 and vtiger_field.tabid=? and vtiger_field.uitype in ('15','55','33','16') " . 29 " or (vtiger_field.tabid=? and fieldname='salutationtype' and fieldname !='vendortype')) " . 30 " and vtiger_field.presence in (0,2) ORDER BY vtiger_picklist.picklistid ASC"; 31 32 $result = $adb->pquery($query, array($tabid, $tabid)); 33 $noofrows = $adb->num_rows($result); 34 35 if($noofrows > 0){ 36 $fieldlist = array(); 37 for($i=0; $i<$noofrows; $i++){ 38 $user_fld = array(); 39 $fld_name = $adb->query_result($result,$i,"fieldname"); 40 41 $user_fld['fieldlabel'] = $adb->query_result($result,$i,"fieldlabel"); 42 $user_fld['generatedtype'] = $adb->query_result($result,$i,"generatedtype"); 43 $user_fld['columnname'] = $adb->query_result($result,$i,"columnname"); 44 $user_fld['fieldname'] = $adb->query_result($result,$i,"fieldname"); 45 $user_fld['uitype'] = $adb->query_result($result,$i,"uitype"); 46 $user_fld['value'] = getAssignedPicklistValues($user_fld['fieldname'], $roleid, $adb); 47 $fieldlist[] = $user_fld; 48 } 49 } 50 return $fieldlist; 51 } 52 53 /** 54 * Function to get modules which has picklist values 55 * It gets the picklist modules and return in an array in the following format 56 * $modules = Array($tabid=>$tablabel,$tabid1=>$tablabel1,$tabid2=>$tablabel2,-------------,$tabidn=>$tablabeln) 57 */ 58 function getPickListModules(){ 59 global $adb; 60 // vtlib customization: Ignore disabled modules. 61 $query = 'select distinct vtiger_field.fieldname,vtiger_field.tabid,vtiger_tab.tablabel, vtiger_tab.name as tabname,uitype from vtiger_field inner join vtiger_tab on vtiger_tab.tabid=vtiger_field.tabid where uitype IN (15,33) and vtiger_field.tabid != 29 and vtiger_tab.presence != 1 and vtiger_field.presence in (0,2) order by vtiger_field.tabid ASC'; 62 // END 63 $result = $adb->pquery($query, array()); 64 while($row = $adb->fetch_array($result)){ 65 $modules[$row['tablabel']] = $row['tabname']; 66 } 67 return $modules; 68 } 69 70 /** 71 * this function returns all the roles present in the CRM so that they can be displayed in the picklist module 72 * @return array $role - the roles present in the CRM in the array format 73 */ 74 function getrole2picklist(){ 75 global $adb; 76 $query = "select rolename,roleid from vtiger_role where roleid not in('H1') order by roleid"; 77 $result = $adb->pquery($query, array()); 78 while($row = $adb->fetch_array($result)){ 79 $role[$row['roleid']] = $row['rolename']; 80 } 81 return $role; 82 83 } 84 85 /** 86 * this function returns the picklists available for a module 87 * @param array $picklist_details - the details about the picklists in the module 88 * @return array $module_pick - the picklists present in the module in an array format 89 */ 90 function get_available_module_picklist($picklist_details){ 91 $avail_pick_values = $picklist_details; 92 foreach($avail_pick_values as $key => $val){ 93 $module_pick[$avail_pick_values[$key]['fieldname']] = getTranslatedString($avail_pick_values[$key]['fieldlabel']); 94 } 95 return $module_pick; 96 } 97 98 /** 99 * this function returns all the picklist values that are available for a given 100 * @param string $fieldName - the name of the field 101 * @return array $arr - the array containing the picklist values 102 */ 103 function getAllPickListValues($fieldName,$lang = Array() ){ 104 global $adb; 105 $sql = 'SELECT * FROM vtiger_'.$adb->sql_escape_string($fieldName); 106 $result = $adb->query($sql); 107 $count = $adb->num_rows($result); 108 109 $arr = array(); 110 for($i=0;$i<$count;$i++){ 111 $pick_val = decode_html($adb->query_result($result, $i, $fieldName)); 112 if($lang[$pick_val] != ''){ 113 $arr[$pick_val] = $lang[$pick_val]; 114 } 115 else{ 116 $arr[$pick_val] = $pick_val; 117 } 118 } 119 return $arr; 120 } 121 122 123 /** 124 * this function accepts the fieldname and the language string array and returns all the editable picklist values for that fieldname 125 * @param string $fieldName - the name of the picklist 126 * @param array $lang - the language string array 127 * @param object $adb - the peardatabase object 128 * @return array $pick - the editable picklist values 129 */ 130 function getEditablePicklistValues($fieldName, $lang= array(), $adb){ 131 $values = array(); 132 $fieldName = $adb->sql_escape_string($fieldName); 133 $sql="select $fieldName from vtiger_$fieldName where presence=1 and $fieldName <> '--None--'"; 134 $res = $adb->query($sql); 135 $RowCount = $adb->num_rows($res); 136 if($RowCount > 0){ 137 for($i=0;$i<$RowCount;$i++){ 138 $pick_val = $adb->query_result($res,$i,$fieldName); 139 if($lang[$pick_val] != ''){ 140 $values[$pick_val]=$lang[$pick_val]; 141 }else{ 142 $values[$pick_val]=$pick_val; 143 } 144 } 145 } 146 return $values; 147 } 148 149 /** 150 * this function accepts the fieldname and the language string array and returns all the non-editable picklist values for that fieldname 151 * @param string $fieldName - the name of the picklist 152 * @param array $lang - the language string array 153 * @param object $adb - the peardatabase object 154 * @return array $pick - the no-editable picklist values 155 */ 156 function getNonEditablePicklistValues($fieldName, $lang=array(), $adb){ 157 $values = array(); 158 $fieldName = $adb->sql_escape_string($fieldName); 159 $sql = "select $fieldName from vtiger_$fieldName where presence=0"; 160 $result = $adb->query($sql); 161 $count = $adb->num_rows($result); 162 for($i=0;$i<$count;$i++){ 163 $non_val = $adb->query_result($result,$i,$fieldName); 164 if($lang[$non_val] != ''){ 165 $values[]=$lang[$non_val]; 166 }else{ 167 $values[]=$non_val; 168 } 169 } 170 if(count($values)==0){ 171 $values = ""; 172 } 173 return $values; 174 } 175 176 /** 177 * this function returns all the assigned picklist values for the given tablename for the given roleid 178 * @param string $tableName - the picklist tablename 179 * @param integer $roleid - the roleid of the role for which you want data 180 * @param object $adb - the peardatabase object 181 * @return array $val - the assigned picklist values in array format 182 */ 183 function getAssignedPicklistValues($tableName, $roleid, $adb, $lang=array()){ 184 $cache = Vtiger_Cache::getInstance(); 185 if($cache->hasAssignedPicklistValues($tableName,$roleid)) { 186 return $cache->getAssignedPicklistValues($tableName,$roleid); 187 } else { 188 $arr = array(); 189 190 $sql = "select picklistid from vtiger_picklist where name = ?"; 191 $result = $adb->pquery($sql, array($tableName)); 192 if($adb->num_rows($result)){ 193 $picklistid = $adb->query_result($result, 0, "picklistid"); 194 195 $sub = getSubordinateRoleAndUsers($roleid); 196 $subRoles = array($roleid); 197 $subRoles = array_merge($subRoles, array_keys($sub)); 198 199 $roleids = array(); 200 foreach($subRoles as $role){ 201 $roleids[] = $role; 202 } 203 204 $sql = "SELECT distinct ".$adb->sql_escape_string($tableName)." FROM ". $adb->sql_escape_string("vtiger_$tableName") 205 . " inner join vtiger_role2picklist on ".$adb->sql_escape_string("vtiger_$tableName").".picklist_valueid=vtiger_role2picklist.picklistvalueid" 206 . " and roleid in (".generateQuestionMarks($roleids).") order by sortid"; 207 $result = $adb->pquery($sql, $roleids); 208 $count = $adb->num_rows($result); 209 210 if($count) { 211 while($resultrow = $adb->fetch_array($result)) { 212 /** Earlier we used to save picklist values by encoding it. Now, we are directly saving those(getRaw()). 213 * If value in DB is like "test1 & test2" then $abd->fetch_array() is giving it as 214 * "test1 &$amp; test2" which we should decode two time to get result 215 */ 216 $pick_val = decode_html(decode_html($resultrow[$tableName])); 217 if($lang[$pick_val] != '') { 218 $arr[$pick_val] = $lang[$pick_val]; 219 } 220 else { 221 $arr[$pick_val] = $pick_val; 222 } 223 } 224 } 225 } 226 // END 227 $cache->setAssignedPicklistValues($tableName,$roleid,$arr); 228 return $arr; 229 } 230 } 231 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 20:08:37 2014 | Cross-referenced by PHPXref 0.7.1 |