PageRenderTime 62ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 1ms

/include/utils/utils.php

https://bitbucket.org/thomashii/vtigercrm-5.4-for-postgresql
PHP | 5134 lines | 3858 code | 546 blank | 730 comment | 627 complexity | fbcd1419ab8f4fb67eff80d6c2581f21 MD5 | raw file
Possible License(s): LGPL-2.1, GPL-2.0

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /*********************************************************************************
  3. * The contents of this file are subject to the SugarCRM Public License Version 1.1.2
  4. * ("License"); You may not use this file except in compliance with the
  5. * License. You may obtain a copy of the License at http://www.sugarcrm.com/SPL
  6. * Software distributed under the License is distributed on an "AS IS" basis,
  7. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
  8. * the specific language governing rights and limitations under the License.
  9. * The Original Code is: SugarCRM Open Source
  10. * The Initial Developer of the Original Code is SugarCRM, Inc.
  11. * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.;
  12. * All Rights Reserved.
  13. * Contributor(s): ______________________________________.
  14. ********************************************************************************/
  15. /*********************************************************************************
  16. * $Header$
  17. * Description: Includes generic helper functions used throughout the application.
  18. * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
  19. * All Rights Reserved.
  20. * Contributor(s): ______________________________________..
  21. ********************************************************************************/
  22. /** This function returns the name of the person.
  23. * It currently returns "first last". It should not put the space if either name is not available.
  24. * It should not return errors if either name is not available.
  25. * If no names are present, it will return ""
  26. * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
  27. * All Rights Reserved.
  28. * Contributor(s): ______________________________________..
  29. */
  30. require_once('include/database/PearDatabase.php');
  31. require_once('include/ComboUtil.php'); //new
  32. require_once('include/utils/ListViewUtils.php');
  33. require_once('include/utils/EditViewUtils.php');
  34. require_once('include/utils/DetailViewUtils.php');
  35. require_once('include/utils/CommonUtils.php');
  36. require_once('include/utils/InventoryUtils.php');
  37. require_once('include/utils/SearchUtils.php');
  38. require_once('include/FormValidationUtil.php');
  39. require_once('include/DatabaseUtil.php');
  40. require_once('include/events/SqlResultIterator.inc');
  41. require_once('include/fields/DateTimeField.php');
  42. require_once('include/fields/CurrencyField.php');
  43. require_once('data/CRMEntity.php');
  44. require_once 'vtlib/Vtiger/Language.php';
  45. // Constants to be defined here
  46. // For Migration status.
  47. define("MIG_CHARSET_PHP_UTF8_DB_UTF8", 1);
  48. define("MIG_CHARSET_PHP_NONUTF8_DB_NONUTF8", 2);
  49. define("MIG_CHARSET_PHP_NONUTF8_DB_UTF8", 3);
  50. define("MIG_CHARSET_PHP_UTF8_DB_NONUTF8", 4);
  51. // For Customview status.
  52. define("CV_STATUS_DEFAULT", 0);
  53. define("CV_STATUS_PRIVATE", 1);
  54. define("CV_STATUS_PENDING", 2);
  55. define("CV_STATUS_PUBLIC", 3);
  56. // For Restoration.
  57. define("RB_RECORD_DELETED", 'delete');
  58. define("RB_RECORD_INSERTED", 'insert');
  59. define("RB_RECORD_UPDATED", 'update');
  60. /** Function to return a full name
  61. * @param $row -- row:: Type integer
  62. * @param $first_column -- first column:: Type string
  63. * @param $last_column -- last column:: Type string
  64. * @returns $fullname -- fullname:: Type string
  65. *
  66. */
  67. function return_name(&$row, $first_column, $last_column)
  68. {
  69. global $log;
  70. $log->debug("Entering return_name(".$row.",".$first_column.",".$last_column.") method ...");
  71. $first_name = "";
  72. $last_name = "";
  73. $full_name = "";
  74. if(isset($row[$first_column]))
  75. {
  76. $first_name = stripslashes($row[$first_column]);
  77. }
  78. if(isset($row[$last_column]))
  79. {
  80. $last_name = stripslashes($row[$last_column]);
  81. }
  82. $full_name = $first_name;
  83. // If we have a first name and we have a last name
  84. if($full_name != "" && $last_name != "")
  85. {
  86. // append a space, then the last name
  87. $full_name .= " ".$last_name;
  88. }
  89. // If we have no first name, but we have a last name
  90. else if($last_name != "")
  91. {
  92. // append the last name without the space.
  93. $full_name .= $last_name;
  94. }
  95. $log->debug("Exiting return_name method ...");
  96. return $full_name;
  97. }
  98. /** Function to return language
  99. * @returns $languages -- languages:: Type string
  100. *
  101. */
  102. function get_languages()
  103. {
  104. global $log;
  105. $log->debug("Entering get_languages() method ...");
  106. global $languages;
  107. $log->debug("Exiting get_languages method ...");
  108. return $languages;
  109. }
  110. /** Function to return language
  111. * @param $key -- key:: Type string
  112. * @returns $languages -- languages:: Type string
  113. *
  114. */
  115. //seems not used
  116. function get_language_display($key)
  117. {
  118. global $log;
  119. $log->debug("Entering get_language_display(".$key.") method ...");
  120. global $languages;
  121. $log->debug("Exiting get_language_display method ...");
  122. return $languages[$key];
  123. }
  124. /** Function returns the user array
  125. * @param $assigned_user_id -- assigned_user_id:: Type string
  126. * @returns $user_list -- user list:: Type array
  127. *
  128. */
  129. function get_assigned_user_name(&$assigned_user_id)
  130. {
  131. global $log;
  132. $log->debug("Entering get_assigned_user_name(".$assigned_user_id.") method ...");
  133. $user_list = &get_user_array(false,"");
  134. if(isset($user_list[$assigned_user_id]))
  135. {
  136. $log->debug("Exiting get_assigned_user_name method ...");
  137. return $user_list[$assigned_user_id];
  138. }
  139. $log->debug("Exiting get_assigned_user_name method ...");
  140. return "";
  141. }
  142. /** Function returns the user key in user array
  143. * @param $add_blank -- boolean:: Type boolean
  144. * @param $status -- user status:: Type string
  145. * @param $assigned_user -- user id:: Type string
  146. * @param $private -- sharing type:: Type string
  147. * @returns $user_array -- user array:: Type array
  148. *
  149. */
  150. //used in module file
  151. function get_user_array($add_blank=true, $status="Active", $assigned_user="",$private="")
  152. {
  153. global $log;
  154. $log->debug("Entering get_user_array(".$add_blank.",". $status.",".$assigned_user.",".$private.") method ...");
  155. global $current_user;
  156. if(isset($current_user) && $current_user->id != '')
  157. {
  158. require('user_privileges/sharing_privileges_'.$current_user->id.'.php');
  159. require('user_privileges/user_privileges_'.$current_user->id.'.php');
  160. }
  161. static $user_array = null;
  162. $module=$_REQUEST['module'];
  163. if($user_array == null)
  164. {
  165. require_once('include/database/PearDatabase.php');
  166. $db = PearDatabase::getInstance();
  167. $temp_result = Array();
  168. // Including deleted vtiger_users for now.
  169. if (empty($status)) {
  170. $query = "SELECT id, user_name from vtiger_users";
  171. $params = array();
  172. }
  173. else {
  174. if($private == 'private')
  175. {
  176. $log->debug("Sharing is Private. Only the current user should be listed");
  177. $query = "select id as id,user_name as user_name,first_name,last_name from vtiger_users where id=? and status='Active' union select vtiger_user2role.userid as id,vtiger_users.user_name as user_name ,
  178. vtiger_users.first_name as first_name ,vtiger_users.last_name as last_name
  179. from vtiger_user2role inner join vtiger_users on vtiger_users.id=vtiger_user2role.userid inner join vtiger_role on vtiger_role.roleid=vtiger_user2role.roleid where vtiger_role.parentrole like ? and status='Active' union
  180. select shareduserid as id,vtiger_users.user_name as user_name ,
  181. vtiger_users.first_name as first_name ,vtiger_users.last_name as last_name from vtiger_tmp_write_user_sharing_per inner join vtiger_users on vtiger_users.id=vtiger_tmp_write_user_sharing_per.shareduserid where status='Active' and vtiger_tmp_write_user_sharing_per.userid=? and vtiger_tmp_write_user_sharing_per.tabid=?";
  182. $params = array($current_user->id, $current_user_parent_role_seq."::%", $current_user->id, getTabid($module));
  183. }
  184. else
  185. {
  186. $log->debug("Sharing is Public. All vtiger_users should be listed");
  187. $query = "SELECT id, user_name,first_name,last_name from vtiger_users WHERE status=?";
  188. $params = array($status);
  189. }
  190. }
  191. if (!empty($assigned_user)) {
  192. $query .= " OR id=?";
  193. array_push($params, $assigned_user);
  194. }
  195. $query .= " order by user_name ASC";
  196. $result = $db->pquery($query, $params, true, "Error filling in user array: ");
  197. if ($add_blank==true){
  198. // Add in a blank row
  199. $temp_result[''] = '';
  200. }
  201. // Get the id and the name.
  202. while($row = $db->fetchByAssoc($result))
  203. {
  204. $temp_result[$row['id']] = getFullNameFromArray('Users', $row);
  205. }
  206. $user_array = &$temp_result;
  207. }
  208. $log->debug("Exiting get_user_array method ...");
  209. return $user_array;
  210. }
  211. function get_group_array($add_blank=true, $status="Active", $assigned_user="",$private="")
  212. {
  213. global $log;
  214. $log->debug("Entering get_user_array(".$add_blank.",". $status.",".$assigned_user.",".$private.") method ...");
  215. global $current_user;
  216. if(isset($current_user) && $current_user->id != '')
  217. {
  218. require('user_privileges/sharing_privileges_'.$current_user->id.'.php');
  219. require('user_privileges/user_privileges_'.$current_user->id.'.php');
  220. }
  221. static $group_array = null;
  222. $module=$_REQUEST['module'];
  223. if($group_array == null)
  224. {
  225. require_once('include/database/PearDatabase.php');
  226. $db = PearDatabase::getInstance();
  227. $temp_result = Array();
  228. // Including deleted vtiger_users for now.
  229. $log->debug("Sharing is Public. All vtiger_users should be listed");
  230. $query = "SELECT groupid, groupname from vtiger_groups";
  231. $params = array();
  232. if($private == 'private'){
  233. $query .= " WHERE groupid=?";
  234. $params = array( $current_user->id);
  235. if(count($current_user_groups) != 0) {
  236. $query .= " OR vtiger_groups.groupid in (".generateQuestionMarks($current_user_groups).")";
  237. array_push($params, $current_user_groups);
  238. }
  239. $log->debug("Sharing is Private. Only the current user should be listed");
  240. $query .= " union select vtiger_group2role.groupid as groupid,vtiger_groups.groupname as groupname from vtiger_group2role inner join vtiger_groups on vtiger_groups.groupid=vtiger_group2role.groupid inner join vtiger_role on vtiger_role.roleid=vtiger_group2role.roleid where vtiger_role.parentrole like ?";
  241. array_push($params, $current_user_parent_role_seq."::%");
  242. if(count($current_user_groups) != 0) {
  243. $query .= " union select vtiger_groups.groupid as groupid,vtiger_groups.groupname as groupname from vtiger_groups inner join vtiger_group2rs on vtiger_groups.groupid=vtiger_group2rs.groupid where vtiger_group2rs.roleandsubid in (".generateQuestionMarks($parent_roles).")";
  244. array_push($params, $parent_roles);
  245. }
  246. $query .= " union select sharedgroupid as groupid,vtiger_groups.groupname as groupname from vtiger_tmp_write_group_sharing_per inner join vtiger_groups on vtiger_groups.groupid=vtiger_tmp_write_group_sharing_per.sharedgroupid where vtiger_tmp_write_group_sharing_per.userid=?";
  247. array_push($params, $current_user->id);
  248. $query .= " and vtiger_tmp_write_group_sharing_per.tabid=?";
  249. array_push($params, getTabid($module));
  250. }
  251. $query .= " order by groupname ASC";
  252. $result = $db->pquery($query, $params, true, "Error filling in user array: ");
  253. if ($add_blank==true){
  254. // Add in a blank row
  255. $temp_result[''] = '';
  256. }
  257. // Get the id and the name.
  258. while($row = $db->fetchByAssoc($result))
  259. {
  260. $temp_result[$row['groupid']] = $row['groupname'];
  261. }
  262. $group_array = &$temp_result;
  263. }
  264. $log->debug("Exiting get_user_array method ...");
  265. return $group_array;
  266. }
  267. /** Function skips executing arbitary commands given in a string
  268. * @param $string -- string:: Type string
  269. * @param $maxlength -- maximun length:: Type integer
  270. * @returns $string -- escaped string:: Type string
  271. *
  272. */
  273. function clean($string, $maxLength)
  274. {
  275. global $log;
  276. $log->debug("Entering clean(".$string.",". $maxLength.") method ...");
  277. $string = substr($string, 0, $maxLength);
  278. $log->debug("Exiting clean method ...");
  279. return escapeshellcmd($string);
  280. }
  281. /**
  282. * Copy the specified request variable to the member variable of the specified object.
  283. * Do no copy if the member variable is already set.
  284. * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
  285. * All Rights Reserved.
  286. * Contributor(s): ______________________________________..
  287. */
  288. function safe_map($request_var, & $focus, $always_copy = false)
  289. {
  290. global $log;
  291. $log->debug("Entering safe_map(".$request_var.",".get_class($focus).",".$always_copy.") method ...");
  292. safe_map_named($request_var, $focus, $request_var, $always_copy);
  293. $log->debug("Exiting safe_map method ...");
  294. }
  295. /**
  296. * Copy the specified request variable to the member variable of the specified object.
  297. * Do no copy if the member variable is already set.
  298. * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
  299. * All Rights Reserved.
  300. * Contributor(s): ______________________________________..
  301. */
  302. function safe_map_named($request_var, & $focus, $member_var, $always_copy)
  303. {
  304. global $log;
  305. $log->debug("Entering safe_map_named(".$request_var.",".get_class($focus).",".$member_var.",".$always_copy.") method ...");
  306. if (isset($_REQUEST[$request_var]) && ($always_copy || is_null($focus->$member_var))) {
  307. $log->debug("safe map named called assigning '{$_REQUEST[$request_var]}' to $member_var");
  308. $focus->$member_var = $_REQUEST[$request_var];
  309. }
  310. $log->debug("Exiting safe_map_named method ...");
  311. }
  312. /** This function retrieves an application language file and returns the array of strings included in the $app_list_strings var.
  313. * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
  314. * All Rights Reserved.
  315. * Contributor(s): ______________________________________..
  316. * If you are using the current language, do not call this function unless you are loading it for the first time */
  317. function return_app_list_strings_language($language)
  318. {
  319. global $log;
  320. $log->debug("Entering return_app_list_strings_language(".$language.") method ...");
  321. global $app_list_strings, $default_language, $log, $translation_string_prefix;
  322. $temp_app_list_strings = $app_list_strings;
  323. $language_used = $language;
  324. @include("include/language/$language.lang.php");
  325. if(!isset($app_list_strings))
  326. {
  327. $log->warn("Unable to find the application language file for language: ".$language);
  328. require("include/language/$default_language.lang.php");
  329. $language_used = $default_language;
  330. }
  331. if(!isset($app_list_strings))
  332. {
  333. $log->fatal("Unable to load the application language file for the selected language($language) or the default language($default_language)");
  334. $log->debug("Exiting return_app_list_strings_language method ...");
  335. return null;
  336. }
  337. $return_value = $app_list_strings;
  338. $app_list_strings = $temp_app_list_strings;
  339. $log->debug("Exiting return_app_list_strings_language method ...");
  340. return $return_value;
  341. }
  342. /**
  343. * Retrieve the app_currency_strings for the required language.
  344. */
  345. function return_app_currency_strings_language($language) {
  346. global $log;
  347. $log->debug("Entering return_app_currency_strings_language(".$language.") method ...");
  348. global $app_currency_strings, $default_language, $log, $translation_string_prefix;
  349. // Backup the value first
  350. $temp_app_currency_strings = $app_currency_strings;
  351. @include("include/language/$language.lang.php");
  352. if(!isset($app_currency_strings))
  353. {
  354. $log->warn("Unable to find the application language file for language: ".$language);
  355. require("include/language/$default_language.lang.php");
  356. $language_used = $default_language;
  357. }
  358. if(!isset($app_currency_strings))
  359. {
  360. $log->fatal("Unable to load the application language file for the selected language($language) or the default language($default_language)");
  361. $log->debug("Exiting return_app_currency_strings_language method ...");
  362. return null;
  363. }
  364. $return_value = $app_currency_strings;
  365. // Restore the value back
  366. $app_currency_strings = $temp_app_currency_strings;
  367. $log->debug("Exiting return_app_currency_strings_language method ...");
  368. return $return_value;
  369. }
  370. /** This function retrieves an application language file and returns the array of strings included.
  371. * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
  372. * All Rights Reserved.
  373. * Contributor(s): ______________________________________..
  374. * If you are using the current language, do not call this function unless you are loading it for the first time */
  375. function return_application_language($language)
  376. {
  377. global $log;
  378. $log->debug("Entering return_application_language(".$language.") method ...");
  379. global $app_strings, $default_language, $log, $translation_string_prefix;
  380. $temp_app_strings = $app_strings;
  381. $language_used = $language;
  382. checkFileAccessForInclusion("include/language/$language.lang.php");
  383. @include("include/language/$language.lang.php");
  384. if(!isset($app_strings))
  385. {
  386. $log->warn("Unable to find the application language file for language: ".$language);
  387. require("include/language/$default_language.lang.php");
  388. $language_used = $default_language;
  389. }
  390. if(!isset($app_strings))
  391. {
  392. $log->fatal("Unable to load the application language file for the selected language($language) or the default language($default_language)");
  393. $log->debug("Exiting return_application_language method ...");
  394. return null;
  395. }
  396. // If we are in debug mode for translating, turn on the prefix now!
  397. if($translation_string_prefix)
  398. {
  399. foreach($app_strings as $entry_key=>$entry_value)
  400. {
  401. $app_strings[$entry_key] = $language_used.' '.$entry_value;
  402. }
  403. }
  404. $return_value = $app_strings;
  405. $app_strings = $temp_app_strings;
  406. $log->debug("Exiting return_application_language method ...");
  407. return $return_value;
  408. }
  409. /** This function retrieves a module's language file and returns the array of strings included.
  410. * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
  411. * All Rights Reserved.
  412. * Contributor(s): ______________________________________..
  413. * If you are in the current module, do not call this function unless you are loading it for the first time */
  414. function return_module_language($language, $module)
  415. {
  416. global $log;
  417. $log->debug("Entering return_module_language(".$language.",". $module.") method ...");
  418. global $mod_strings, $default_language, $log, $currentModule, $translation_string_prefix;
  419. static $cachedModuleStrings = array();
  420. if(!empty($cachedModuleStrings[$module])) {
  421. $log->debug("Exiting return_module_language method ...");
  422. return $cachedModuleStrings[$module];
  423. }
  424. $temp_mod_strings = $mod_strings;
  425. $language_used = $language;
  426. @include("modules/$module/language/$language.lang.php");
  427. if(!isset($mod_strings))
  428. {
  429. $log->warn("Unable to find the module language file for language: ".$language." and module: ".$module);
  430. if($default_language == 'en_us') {
  431. require("modules/$module/language/$default_language.lang.php");
  432. $language_used = $default_language;
  433. } else {
  434. @include("modules/$module/language/$default_language.lang.php");
  435. if(!isset($mod_strings)) {
  436. require("modules/$module/language/en_us.lang.php");
  437. $language_used = 'en_us';
  438. } else {
  439. $language_used = $default_language;
  440. }
  441. }
  442. }
  443. if(!isset($mod_strings))
  444. {
  445. $log->fatal("Unable to load the module($module) language file for the selected language($language) or the default language($default_language)");
  446. $log->debug("Exiting return_module_language method ...");
  447. return null;
  448. }
  449. // If we are in debug mode for translating, turn on the prefix now!
  450. if($translation_string_prefix)
  451. {
  452. foreach($mod_strings as $entry_key=>$entry_value)
  453. {
  454. $mod_strings[$entry_key] = $language_used.' '.$entry_value;
  455. }
  456. }
  457. $return_value = $mod_strings;
  458. $mod_strings = $temp_mod_strings;
  459. $log->debug("Exiting return_module_language method ...");
  460. $cachedModuleStrings[$module] = $return_value;
  461. return $return_value;
  462. }
  463. /*This function returns the mod_strings for the current language and the specified module
  464. */
  465. function return_specified_module_language($language, $module)
  466. {
  467. global $log;
  468. global $default_language, $translation_string_prefix;
  469. @include("modules/$module/language/$language.lang.php");
  470. if(!isset($mod_strings))
  471. {
  472. $log->warn("Unable to find the module language file for language: ".$language." and module: ".$module);
  473. require("modules/$module/language/$default_language.lang.php");
  474. $language_used = $default_language;
  475. }
  476. if(!isset($mod_strings))
  477. {
  478. $log->fatal("Unable to load the module($module) language file for the selected language($language) or the default language($default_language)");
  479. $log->debug("Exiting return_module_language method ...");
  480. return null;
  481. }
  482. $return_value = $mod_strings;
  483. $log->debug("Exiting return_module_language method ...");
  484. return $return_value;
  485. }
  486. /** This function retrieves an application language file and returns the array of strings included in the $mod_list_strings var.
  487. * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
  488. * All Rights Reserved.
  489. * Contributor(s): ______________________________________..
  490. * If you are using the current language, do not call this function unless you are loading it for the first time */
  491. function return_mod_list_strings_language($language,$module)
  492. {
  493. global $log;
  494. $log->debug("Entering return_mod_list_strings_language(".$language.",".$module.") method ...");
  495. global $mod_list_strings, $default_language, $log, $currentModule,$translation_string_prefix;
  496. $language_used = $language;
  497. $temp_mod_list_strings = $mod_list_strings;
  498. if($currentModule == $module && isset($mod_list_strings) && $mod_list_strings != null)
  499. {
  500. $log->debug("Exiting return_mod_list_strings_language method ...");
  501. return $mod_list_strings;
  502. }
  503. @include("modules/$module/language/$language.lang.php");
  504. if(!isset($mod_list_strings))
  505. {
  506. $log->fatal("Unable to load the application list language file for the selected language($language) or the default language($default_language)");
  507. $log->debug("Exiting return_mod_list_strings_language method ...");
  508. return null;
  509. }
  510. $return_value = $mod_list_strings;
  511. $mod_list_strings = $temp_mod_list_strings;
  512. $log->debug("Exiting return_mod_list_strings_language method ...");
  513. return $return_value;
  514. }
  515. /** This function retrieves a theme's language file and returns the array of strings included.
  516. * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
  517. * All Rights Reserved.
  518. * Contributor(s): ______________________________________..
  519. */
  520. function return_theme_language($language, $theme)
  521. {
  522. global $log;
  523. $log->debug("Entering return_theme_language(".$language.",". $theme.") method ...");
  524. global $mod_strings, $default_language, $log, $currentModule, $translation_string_prefix;
  525. $language_used = $language;
  526. @include("themes/$theme/language/$current_language.lang.php");
  527. if(!isset($theme_strings))
  528. {
  529. $log->warn("Unable to find the theme file for language: ".$language." and theme: ".$theme);
  530. require("themes/$theme/language/$default_language.lang.php");
  531. $language_used = $default_language;
  532. }
  533. if(!isset($theme_strings))
  534. {
  535. $log->fatal("Unable to load the theme($theme) language file for the selected language($language) or the default language($default_language)");
  536. $log->debug("Exiting return_theme_language method ...");
  537. return null;
  538. }
  539. // If we are in debug mode for translating, turn on the prefix now!
  540. if($translation_string_prefix)
  541. {
  542. foreach($theme_strings as $entry_key=>$entry_value)
  543. {
  544. $theme_strings[$entry_key] = $language_used.' '.$entry_value;
  545. }
  546. }
  547. $log->debug("Exiting return_theme_language method ...");
  548. return $theme_strings;
  549. }
  550. /** If the session variable is defined and is not equal to "" then return it. Otherwise, return the default value.
  551. * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
  552. * All Rights Reserved.
  553. * Contributor(s): ______________________________________..
  554. */
  555. function return_session_value_or_default($varname, $default)
  556. {
  557. global $log;
  558. $log->debug("Entering return_session_value_or_default(".$varname.",". $default.") method ...");
  559. if(isset($_SESSION[$varname]) && $_SESSION[$varname] != "")
  560. {
  561. $log->debug("Exiting return_session_value_or_default method ...");
  562. return $_SESSION[$varname];
  563. }
  564. $log->debug("Exiting return_session_value_or_default method ...");
  565. return $default;
  566. }
  567. /**
  568. * Creates an array of where restrictions. These are used to construct a where SQL statement on the query
  569. * It looks for the variable in the $_REQUEST array. If it is set and is not "" it will create a where clause out of it.
  570. * @param &$where_clauses - The array to append the clause to
  571. * @param $variable_name - The name of the variable to look for an add to the where clause if found
  572. * @param $SQL_name - [Optional] If specified, this is the SQL column name that is used. If not specified, the $variable_name is used as the SQL_name.
  573. * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
  574. * All Rights Reserved.
  575. * Contributor(s): ______________________________________..
  576. */
  577. function append_where_clause(&$where_clauses, $variable_name, $SQL_name = null)
  578. {
  579. global $log;
  580. $log->debug("Entering append_where_clause(".$where_clauses.",".$variable_name.",".$SQL_name.") method ...");
  581. if($SQL_name == null)
  582. {
  583. $SQL_name = $variable_name;
  584. }
  585. if(isset($_REQUEST[$variable_name]) && $_REQUEST[$variable_name] != "")
  586. {
  587. array_push($where_clauses, "$SQL_name like '$_REQUEST[$variable_name]%'");
  588. }
  589. $log->debug("Exiting append_where_clause method ...");
  590. }
  591. /**
  592. * Generate the appropriate SQL based on the where clauses.
  593. * @param $where_clauses - An Array of individual where clauses stored as strings
  594. * @returns string where_clause - The final SQL where clause to be executed.
  595. * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
  596. * All Rights Reserved.
  597. * Contributor(s): ______________________________________..
  598. */
  599. function generate_where_statement($where_clauses)
  600. {
  601. global $log;
  602. $log->debug("Entering generate_where_statement(".$where_clauses.") method ...");
  603. $where = "";
  604. foreach($where_clauses as $clause)
  605. {
  606. if($where != "")
  607. $where .= " and ";
  608. $where .= $clause;
  609. }
  610. $log->info("Here is the where clause for the list view: $where");
  611. $log->debug("Exiting generate_where_statement method ...");
  612. return $where;
  613. }
  614. /**
  615. * A temporary method of generating GUIDs of the correct format for our DB.
  616. * @return String contianing a GUID in the format: aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee
  617. *
  618. * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
  619. * All Rights Reserved.
  620. * Contributor(s): ______________________________________..
  621. */
  622. function create_guid()
  623. {
  624. global $log;
  625. $log->debug("Entering create_guid() method ...");
  626. $microTime = microtime();
  627. list($a_dec, $a_sec) = explode(" ", $microTime);
  628. $dec_hex = sprintf("%x", $a_dec* 1000000);
  629. $sec_hex = sprintf("%x", $a_sec);
  630. ensure_length($dec_hex, 5);
  631. ensure_length($sec_hex, 6);
  632. $guid = "";
  633. $guid .= $dec_hex;
  634. $guid .= create_guid_section(3);
  635. $guid .= '-';
  636. $guid .= create_guid_section(4);
  637. $guid .= '-';
  638. $guid .= create_guid_section(4);
  639. $guid .= '-';
  640. $guid .= create_guid_section(4);
  641. $guid .= '-';
  642. $guid .= $sec_hex;
  643. $guid .= create_guid_section(6);
  644. $log->debug("Exiting create_guid method ...");
  645. return $guid;
  646. }
  647. /** Function to create guid section for a given character
  648. * @param $characters -- characters:: Type string
  649. * @returns $return -- integer:: Type integer``
  650. */
  651. function create_guid_section($characters)
  652. {
  653. global $log;
  654. $log->debug("Entering create_guid_section(".$characters.") method ...");
  655. $return = "";
  656. for($i=0; $i<$characters; $i++)
  657. {
  658. $return .= sprintf("%x", rand(0,15));
  659. }
  660. $log->debug("Exiting create_guid_section method ...");
  661. return $return;
  662. }
  663. /** Function to ensure length
  664. * @param $string -- string:: Type string
  665. * @param $length -- length:: Type string
  666. */
  667. function ensure_length(&$string, $length)
  668. {
  669. global $log;
  670. $log->debug("Entering ensure_length(".$string.",". $length.") method ...");
  671. $strlen = strlen($string);
  672. if($strlen < $length)
  673. {
  674. $string = str_pad($string,$length,"0");
  675. }
  676. else if($strlen > $length)
  677. {
  678. $string = substr($string, 0, $length);
  679. }
  680. $log->debug("Exiting ensure_length method ...");
  681. }
  682. /*
  683. function microtime_diff($a, $b) {
  684. global $log;
  685. $log->debug("Entering microtime_diff(".$a.",". $b.") method ...");
  686. list($a_dec, $a_sec) = explode(" ", $a);
  687. list($b_dec, $b_sec) = explode(" ", $b);
  688. $log->debug("Exiting microtime_diff method ...");
  689. return $b_sec - $a_sec + $b_dec - $a_dec;
  690. }
  691. */
  692. /**
  693. * Return the display name for a theme if it exists.
  694. * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
  695. * All Rights Reserved.
  696. * Contributor(s): ______________________________________..
  697. */
  698. function get_theme_display($theme) {
  699. global $log;
  700. $log->debug("Entering get_theme_display(".$theme.") method ...");
  701. global $theme_name, $theme_description;
  702. $temp_theme_name = $theme_name;
  703. $temp_theme_description = $theme_description;
  704. if (is_file("./themes/$theme/config.php")) {
  705. @include("./themes/$theme/config.php");
  706. $return_theme_value = $theme_name;
  707. }
  708. else {
  709. $return_theme_value = $theme;
  710. }
  711. $theme_name = $temp_theme_name;
  712. $theme_description = $temp_theme_description;
  713. $log->debug("Exiting get_theme_display method ...");
  714. return $return_theme_value;
  715. }
  716. /**
  717. * Return an array of directory names.
  718. * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
  719. * All Rights Reserved.
  720. * Contributor(s): ______________________________________..
  721. */
  722. function get_themes() {
  723. global $log;
  724. $log->debug("Entering get_themes() method ...");
  725. if ($dir = @opendir("./themes")) {
  726. while (($file = readdir($dir)) !== false) {
  727. if ($file != ".." && $file != "." && $file != "CVS" && $file != "Attic" && $file != "akodarkgem" && $file != "bushtree" && $file != "coolblue" && $file != "Amazon" && $file != "busthree" && $file != "Aqua" && $file != "nature" && $file != "orange" && $file != "blue") {
  728. if(is_dir("./themes/".$file)) {
  729. if(!($file[0] == '.')) {
  730. // set the initial theme name to the filename
  731. $name = $file;
  732. // if there is a configuration class, load that.
  733. if(is_file("./themes/$file/config.php"))
  734. {
  735. require_once("./themes/$file/config.php");
  736. }
  737. if(is_file("./themes/$file/style.css"))
  738. {
  739. $filelist[$file] = $name;
  740. }
  741. }
  742. }
  743. }
  744. }
  745. closedir($dir);
  746. }
  747. ksort($filelist);
  748. $log->debug("Exiting get_themes method ...");
  749. return $filelist;
  750. }
  751. /**
  752. * Create javascript to clear values of all elements in a form.
  753. * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
  754. * All Rights Reserved.
  755. * Contributor(s): ______________________________________..
  756. */
  757. function get_clear_form_js () {
  758. global $log;
  759. $log->debug("Entering get_clear_form_js () method ...");
  760. $the_script = <<<EOQ
  761. <script type="text/javascript" language="JavaScript">
  762. <!-- Begin
  763. function clear_form(form) {
  764. for (j = 0; j < form.elements.length; j++) {
  765. if (form.elements[j].type == 'text' || form.elements[j].type == 'select-one') {
  766. form.elements[j].value = '';
  767. }
  768. }
  769. }
  770. // End -->
  771. </script>
  772. EOQ;
  773. $log->debug("Exiting get_clear_form_js method ...");
  774. return $the_script;
  775. }
  776. /**
  777. * Create javascript to set the cursor focus to specific vtiger_field in a form
  778. * when the screen is rendered. The vtiger_field name is currently hardcoded into the
  779. * the function.
  780. * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
  781. * All Rights Reserved.
  782. * Contributor(s): ______________________________________..
  783. */
  784. function get_set_focus_js () {
  785. global $log;
  786. $log->debug("Entering set_focus() method ...");
  787. //TODO Clint 5/20 - Make this function more generic so that it can take in the target form and vtiger_field names as variables
  788. $the_script = <<<EOQ
  789. <script type="text/javascript" language="JavaScript">
  790. <!-- Begin
  791. function set_focus() {
  792. if (document.forms.length > 0) {
  793. for (i = 0; i < document.forms.length; i++) {
  794. for (j = 0; j < document.forms[i].elements.length; j++) {
  795. var vtiger_field = document.forms[i].elements[j];
  796. if ((vtiger_field.type == "text" || vtiger_field.type == "textarea" || vtiger_field.type == "password") &&
  797. !field.disabled && (vtiger_field.name == "first_name" || vtiger_field.name == "name")) {
  798. vtiger_field.focus();
  799. if (vtiger_field.type == "text") {
  800. vtiger_field.select();
  801. }
  802. break;
  803. }
  804. }
  805. }
  806. }
  807. }
  808. // End -->
  809. </script>
  810. EOQ;
  811. $log->debug("Exiting get_set_focus_js method ...");
  812. return $the_script;
  813. }
  814. /**
  815. * Very cool algorithm for sorting multi-dimensional arrays. Found at http://us2.php.net/manual/en/function.array-multisort.php
  816. * Syntax: $new_array = array_csort($array [, 'col1' [, SORT_FLAG [, SORT_FLAG]]]...);
  817. * Explanation: $array is the array you want to sort, 'col1' is the name of the column
  818. * you want to sort, SORT_FLAGS are : SORT_ASC, SORT_DESC, SORT_REGULAR, SORT_NUMERIC, SORT_STRING
  819. * you can repeat the 'col',FLAG,FLAG, as often you want, the highest prioritiy is given to
  820. * the first - so the array is sorted by the last given column first, then the one before ...
  821. * Example: $array = array_csort($array,'town','age',SORT_DESC,'name');
  822. * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
  823. * All Rights Reserved.
  824. * Contributor(s): ______________________________________..
  825. */
  826. function array_csort() {
  827. global $log;
  828. $log->debug("Entering array_csort() method ...");
  829. $args = func_get_args();
  830. $marray = array_shift($args);
  831. $i = 0;
  832. $msortline = "return(array_multisort(";
  833. foreach ($args as $arg) {
  834. $i++;
  835. if (is_string($arg)) {
  836. foreach ($marray as $row) {
  837. $sortarr[$i][] = $row[$arg];
  838. }
  839. } else {
  840. $sortarr[$i] = $arg;
  841. }
  842. $msortline .= "\$sortarr[".$i."],";
  843. }
  844. $msortline .= "\$marray));";
  845. eval($msortline);
  846. $log->debug("Exiting array_csort method ...");
  847. return $marray;
  848. }
  849. /** Function to set default varibles on to the global variable
  850. * @param $defaults -- default values:: Type array
  851. */
  852. function set_default_config(&$defaults)
  853. {
  854. global $log;
  855. $log->debug("Entering set_default_config(".$defaults.") method ...");
  856. foreach ($defaults as $name=>$value)
  857. {
  858. if ( ! isset($GLOBALS[$name]) )
  859. {
  860. $GLOBALS[$name] = $value;
  861. }
  862. }
  863. $log->debug("Exiting set_default_config method ...");
  864. }
  865. $toHtml = array(
  866. '"' => '&quot;',
  867. '<' => '&lt;',
  868. '>' => '&gt;',
  869. '& ' => '&amp; ',
  870. "'" => '&#039;',
  871. '' => '\r',
  872. '\r\n'=>'\n',
  873. );
  874. /** Function to convert the given string to html
  875. * @param $string -- string:: Type string
  876. * @param $ecnode -- boolean:: Type boolean
  877. * @returns $string -- string:: Type string
  878. *
  879. */
  880. function to_html($string, $encode=true)
  881. {
  882. global $log,$default_charset;
  883. //$log->debug("Entering to_html(".$string.",".$encode.") method ...");
  884. global $toHtml;
  885. $action = $_REQUEST['action'];
  886. $search = $_REQUEST['search'];
  887. $doconvert = false;
  888. if($_REQUEST['module'] != 'Settings' && $_REQUEST['file'] != 'ListView' && $_REQUEST['module'] != 'Portal' && $_REQUEST['module'] != "Reports")// && $_REQUEST['module'] != 'Emails')
  889. $ajax_action = $_REQUEST['module'].'Ajax';
  890. if(is_string($string))
  891. {
  892. if($action != 'CustomView' && $action != 'Export' && $action != $ajax_action && $action != 'LeadConvertToEntities' && $action != 'CreatePDF' && $action != 'ConvertAsFAQ' && $_REQUEST['module'] != 'Dashboard' && $action != 'CreateSOPDF' && $action != 'SendPDFMail' && (!isset($_REQUEST['submode'])) )
  893. {
  894. $doconvert = true;
  895. }
  896. else if($search == true)
  897. {
  898. // Fix for tickets #4647, #4648. Conversion required in case of search results also.
  899. $doconvert = true;
  900. }
  901. if ($doconvert == true)
  902. {
  903. if(strtolower($default_charset) == 'utf-8')
  904. $string = htmlentities($string, ENT_QUOTES, $default_charset);
  905. else
  906. $string = preg_replace(array('/</', '/>/', '/"/'), array('&lt;', '&gt;', '&quot;'), $string);
  907. }
  908. }
  909. //$log->debug("Exiting to_html method ...");
  910. return $string;
  911. }
  912. /** Function to get the tablabel for a given id
  913. * @param $tabid -- tab id:: Type integer
  914. * @returns $string -- string:: Type string
  915. */
  916. function getTabname($tabid)
  917. {
  918. global $log;
  919. $log->debug("Entering getTabname(".$tabid.") method ...");
  920. $log->info("tab id is ".$tabid);
  921. global $adb;
  922. $sql = "select tablabel from vtiger_tab where tabid=?";
  923. $result = $adb->pquery($sql, array($tabid));
  924. $tabname= $adb->query_result($result,0,"tablabel");
  925. $log->debug("Exiting getTabname method ...");
  926. return $tabname;
  927. }
  928. /** Function to get the tab module name for a given id
  929. * @param $tabid -- tab id:: Type integer
  930. * @returns $string -- string:: Type string
  931. *
  932. */
  933. function getTabModuleName($tabid)
  934. {
  935. global $log;
  936. $log->debug("Entering getTabModuleName(".$tabid.") method ...");
  937. // Lookup information in cache first
  938. $tabname = VTCacheUtils::lookupModulename($tabid);
  939. if($tabname === false) {
  940. if (file_exists('tabdata.php') && (filesize('tabdata.php') != 0)) {
  941. include('tabdata.php');
  942. $tabname = array_search($tabid,$tab_info_array);
  943. if($tabname == false) {
  944. global $adb;
  945. $sql = "select name from vtiger_tab where tabid=?";
  946. $result = $adb->pquery($sql, array($tabid));
  947. $tabname= $adb->query_result($result,0,"name");
  948. }
  949. // Update information to cache for re-use
  950. VTCacheUtils::updateTabidInfo($tabid, $tabname);
  951. } else {
  952. $log->info("tab id is ".$tabid);
  953. global $adb;
  954. $sql = "select name from vtiger_tab where tabid=?";
  955. $result = $adb->pquery($sql, array($tabid));
  956. $tabname= $adb->query_result($result,0,"name");
  957. // Update information to cache for re-use
  958. VTCacheUtils::updateTabidInfo($tabid, $tabname);
  959. }
  960. }
  961. $log->debug("Exiting getTabModuleName method ...");
  962. return $tabname;
  963. }
  964. /** Function to get column fields for a given module
  965. * @param $module -- module:: Type string
  966. * @returns $column_fld -- column field :: Type array
  967. *
  968. */
  969. function getColumnFields($module)
  970. {
  971. global $log;
  972. $log->debug("Entering getColumnFields(".$module.") method ...");
  973. $log->debug("in getColumnFields ".$module);
  974. // Lookup in cache for information
  975. $cachedModuleFields = VTCacheUtils::lookupFieldInfo_Module($module);
  976. if($cachedModuleFields === false) {
  977. global $adb;
  978. $tabid = getTabid($module);
  979. if ($module == 'Calendar') {
  980. $tabid = array('9','16');
  981. }
  982. // Let us pick up all the fields first so that we can cache information
  983. $sql = "SELECT tabid, fieldname, fieldid, fieldlabel, columnname, tablename, uitype, typeofdata, presence
  984. FROM vtiger_field WHERE tabid in (" . generateQuestionMarks($tabid) . ")";
  985. $result = $adb->pquery($sql, array($tabid));
  986. $noofrows = $adb->num_rows($result);
  987. if($noofrows) {
  988. while($resultrow = $adb->fetch_array($result)) {
  989. // Update information to cache for re-use
  990. VTCacheUtils::updateFieldInfo(
  991. $resultrow['tabid'], $resultrow['fieldname'], $resultrow['fieldid'],
  992. $resultrow['fieldlabel'], $resultrow['columnname'], $resultrow['tablename'],
  993. $resultrow['uitype'], $resultrow['typeofdata'], $resultrow['presence']
  994. );
  995. }
  996. }
  997. // For consistency get information from cache
  998. $cachedModuleFields = VTCacheUtils::lookupFieldInfo_Module($module);
  999. }
  1000. if($module == 'Calendar') {
  1001. $cachedEventsFields = VTCacheUtils::lookupFieldInfo_Module('Events');
  1002. if($cachedModuleFields == false) $cachedModuleFields = $cachedEventsFields;
  1003. else $cachedModuleFields = array_merge($cachedModuleFields, $cachedEventsFields);
  1004. }
  1005. $column_fld = array();
  1006. if($cachedModuleFields) {
  1007. foreach($cachedModuleFields as $fieldinfo) {
  1008. $column_fld[$fieldinfo['fieldname']] = '';
  1009. }
  1010. }
  1011. $log->debug("Exiting getColumnFields method ...");
  1012. return $column_fld;
  1013. }
  1014. /** Function to get a users's mail id
  1015. * @param $userid -- userid :: Type integer
  1016. * @returns $email -- email :: Type string
  1017. *
  1018. */
  1019. function getUserEmail($userid)
  1020. {
  1021. global $log;
  1022. $log->debug("Entering getUserEmail(".$userid.") method ...");
  1023. $log->info("in getUserEmail ".$userid);
  1024. global $adb;
  1025. if($userid != '')
  1026. {
  1027. $sql = "select email1 from vtiger_users where id=?";
  1028. $result = $adb->pquery($sql, array($userid));
  1029. $email = $adb->query_result($result,0,"email1");
  1030. }
  1031. $log->debug("Exiting getUserEmail method ...");
  1032. return $email;
  1033. }
  1034. /** Function to get a userid for outlook
  1035. * @param $username -- username :: Type string
  1036. * @returns $user_id -- user id :: Type integer
  1037. */
  1038. //outlook security
  1039. function getUserId_Ol($username)
  1040. {
  1041. global $log;
  1042. $log->debug("Entering getUserId_Ol(".$username.") method ...");
  1043. $log->info("in getUserId_Ol ".$username);
  1044. global $adb;
  1045. $sql = "select id from vtiger_users where user_name=?";
  1046. $result = $adb->pquery($sql, array($username));
  1047. $num_rows = $adb->num_rows($result);
  1048. if($num_rows > 0)
  1049. {
  1050. $user_id = $adb->query_result($result,0,"id");
  1051. }
  1052. else
  1053. {
  1054. $user_id = 0;
  1055. }
  1056. $log->debug("Exiting getUserId_Ol method ...");
  1057. return $user_id;
  1058. }
  1059. /** Function to get a action id for a given action name
  1060. * @param $action -- action name :: Type string
  1061. * @returns $actionid -- action id :: Type integer
  1062. */
  1063. //outlook security
  1064. function getActionid($action)
  1065. {
  1066. global $log;
  1067. $log->debug("Entering getActionid(".$action.") method ...");
  1068. global $adb;
  1069. $log->info("get Actionid ".$action);
  1070. $actionid = '';
  1071. if(file_exists('tabdata.php') && (filesize('tabdata.php') != 0))
  1072. {
  1073. include('tabdata.php');
  1074. $actionid= $action_id_array[$action];
  1075. }
  1076. else
  1077. {
  1078. $query="select * from vtiger_actionmapping where actionname=?";
  1079. $result =$adb->pquery($query, array($action));
  1080. $actionid=$adb->query_result($result,0,'actionid');
  1081. }
  1082. $log->info("action id selected is ".$actionid );
  1083. $log->debug("Exiting getActionid method ...");
  1084. return $actionid;
  1085. }
  1086. /** Function to get a action for a given action id
  1087. * @param $action id -- action id :: Type integer
  1088. * @returns $actionname-- action name :: Type string
  1089. */
  1090. function getActionname($actionid)
  1091. {
  1092. global $log;
  1093. $log->debug("Entering getActionname(".$actionid.") method ...");
  1094. global $adb;
  1095. $actionname='';
  1096. if (file_exists('tabdata.php') && (filesize('tabdata.php') != 0))
  1097. {
  1098. include('tabdata.php');
  1099. $actionname= $action_name_array[$actionid];
  1100. }
  1101. else
  1102. {
  1103. $query="select * from vtiger_actionmapping where actionid=? and securitycheck=0";
  1104. $result =$adb->pquery($query, array($actionid));
  1105. $actionname=$adb->query_result($result,0,"actionname");
  1106. }
  1107. $log->debug("Exiting getActionname method ...");
  1108. return $actionname;
  1109. }
  1110. /** Function to get a assigned user id for a given entity
  1111. * @param $record -- entity id :: Type integer
  1112. * @returns $user_id -- user id :: Type integer
  1113. */
  1114. function getUserId($record)
  1115. {
  1116. global $log;
  1117. $log->debug("Entering getUserId(".$record.") method ...");
  1118. $log->info("in getUserId ".$record);
  1119. global $adb;
  1120. $user_id=$adb->query_result($adb->pquery("select * from vtiger_crmentity where crmid = ?", array($record)),0,'smownerid');
  1121. $log->debug("Exiting getUserId method ...");
  1122. return $user_id;
  1123. }
  1124. /** Function to get a user id or group id for a given entity
  1125. * @param $record -- entity id :: Type integer
  1126. * @returns $ownerArr -- owner id :: Type array
  1127. */
  1128. function getRecordOwnerId($record)
  1129. {
  1130. global $log;
  1131. $log->debug("Entering getRecordOwnerId(".$record.") method ...");
  1132. global $adb;
  1133. $ownerArr=Array();
  1134. $query="select smownerid from vtiger_crmentity where crmid = ?";
  1135. $result=$adb->pquery($query, array($record));
  1136. if($adb->num_rows($result) > 0)
  1137. {
  1138. $ownerId=$adb->query_result($result,0,'smownerid');
  1139. $sql_result = $adb->pquery("select count(*) as count from vtiger_users where id = ?",array($ownerId));
  1140. if($adb->query_result($sql_result,0,'count') > 0)
  1141. $ownerArr['Users'] = $ownerId;
  1142. else
  1143. $ownerArr['Groups'] = $ownerId;
  1144. }
  1145. $log->debug("Exiting getRecordOwnerId method ...");
  1146. return $ownerArr;
  1147. }
  1148. /** Function to insert value to profile2field table
  1149. * @param $profileid -- profileid :: Type integer
  1150. */
  1151. function insertProfile2field($profileid)
  1152. {
  1153. global $log;
  1154. $log->debug("Entering insertProfile2field(".$profileid.") method ...");
  1155. $log->info("in insertProfile2field ".$profileid);
  1156. global $adb;
  1157. $adb->database->SetFetchMode(ADODB_FETCH_ASSOC);
  1158. $fld_result = $adb->pquery("select * from vtiger_field where generatedtype=1 and displaytype in (1,2,3) and vtiger_field.presence in (0,2) and tabid != 29", array());
  1159. $num_rows = $adb->num_rows($fld_result);
  1160. for($i=0; $i<$num_rows; $i++) {
  1161. $tab_id = $adb->query_result($fld_result,$i,'tabid');
  1162. $field_id = $adb->query_result($fld_result,$i,'fieldid');
  1163. $params = array($profileid, $tab_id, $field_id, 0, 0);
  1164. $adb->pquery("insert into vtiger_profile2field values (?,?,?,?,?)", $params);
  1165. }
  1166. $log->debug("Exiting insertProfile2field method ...");
  1167. }
  1168. /** Function to insert into default org field
  1169. */
  1170. function insert_def_org_field()
  1171. {
  1172. global $log;
  1173. $log->debug("Entering insert_def_org_field() method ...");
  1174. global $adb;
  1175. $adb->database->SetFetchMode(ADODB_FETCH_ASSOC);
  1176. $fld_result = $adb->pquery("select * from vtiger_field where generatedtype=1 and displaytype in (1,2,3) and vtiger_field.presence in (0,2) and tabid != 29", array());
  1177. $num_rows = $adb->num_rows($fld_result);
  1178. for($i=0; $i<$num_rows; $i++)
  1179. {
  1180. $tab_id = $adb->query_result($fld_result,$i,'tabid');
  1181. $field_id = $adb->query_result($fld_result,$i,'fieldid');
  1182. $params = array($tab_id, $field_id, 0, 0);
  1183. $adb->pquery("insert into vtiger_def_org_field values (?,?,?,?)", $params);
  1184. }
  1185. $log->debug("Exiting insert_def_org_field() method ...");
  1186. }
  1187. /** Function to insert value to profile2field table
  1188. * @param $fld_module -- field module :: Type string
  1189. * @param $profileid -- profileid :: Type integer
  1190. * @returns $result -- result :: Type string
  1191. */
  1192. function getProfile2FieldList($fld_module, $profileid)
  1193. {
  1194. global $log;
  1195. $log->debug("Entering getProfile2FieldList(".$fld_module.",". $profileid.") method ...");
  1196. $log->info("in getProfile2FieldList ".$fld_module. ' vtiger_profile id is '.$profileid);
  1197. global $adb;
  1198. $tabid = getTabid($fld_module);
  1199. $query = "select vtiger_profile2field.visible,vtiger_field.* from vtiger_profile2field inner join vtiger_field on vtiger_field.fieldid=vtiger_profile2field.fieldid where vtiger_profile2field.profileid=? and vtiger_profile2field.tabid=? and vtiger_field.presence in (0,1,2)";
  1200. $result = $adb->pquery($query, array($profileid, $tabid));
  1201. $log->debug("Exiting getProfile2FieldList method ...");
  1202. return $result;
  1203. }
  1204. /** Function to insert value to profile2fieldPermissions table
  1205. * @param $fld_module -- field module :: Type string
  1206. * @param $profileid -- profileid :: Type integer
  1207. * @returns $return_data -- return_data :: Type string
  1208. */
  1209. //added by jeri
  1210. function getProfile2FieldPermissionList($fld_module, $profileid)
  1211. {
  1212. global $log;
  1213. $log->debug("Entering getProfile2FieldPermissionList(".$fld_module.",". $profileid.") method ...");
  1214. $log->info("in getProfile2FieldList ".$fld_module. ' vtiger_profile id is '.$profileid);
  1215. // Cache information to re-use
  1216. static $_module_fieldpermission_cache = array();
  1217. if(!isset($_module_fieldpermission_cache[$fld_module])) {
  1218. $_module_fieldpermission_cache[$fld_module] = array();
  1219. }
  1220. // Lookup cache first
  1221. $return_data = VTCacheUtils::lookupProfile2FieldPermissionList($fld_module, $profileid);
  1222. if($return_data === false) {
  1223. $return_data = array();
  1224. global $adb;
  1225. $tabid = getTabid($fld_module);
  1226. $query = "SELECT vtiger_profile2field.visible, vtiger_profile2field.readonly, vtiger_field.fieldlabel, vtiger_field.uitype,
  1227. vtiger_field.fieldid, vtiger_field.displaytype, vtiger_field.typeofdata
  1228. FROM vtiger_profile2field INNER JOIN vtiger_field ON vtiger_field.fieldid=vtiger_profile2field.fieldid
  1229. WHERE vtiger_profile2field.profileid=? and vtiger_profile2field.tabid=? and vtiger_field.presence in (0,2)";
  1230. $qparams = array($profileid, $tabid);
  1231. $result = $adb->pquery($query, $qparams);
  1232. for($i=0; $i<$adb->num_rows($result); $i++) {
  1233. $return_data[]=array(
  1234. $adb->query_result($result,$i,"fieldlabel"),
  1235. $adb->query_result($result,$i,"visible"), // From vtiger_profile2field.visible
  1236. $adb->query_result($result,$i,"uitype"),
  1237. $adb->query_result($result,$i,"readonly"),
  1238. $adb->query_result($result,$i,"fieldid"),
  1239. $adb->query_result($result,$i,"displaytype"),
  1240. $adb->query_result($result,$i,"typeofdata")
  1241. );
  1242. }
  1243. // Update information to cache for re-use
  1244. VTCacheUtils::updateProfile2FieldPermissionList($fld_module, $profileid, $return_data);
  1245. }
  1246. $log->debug("Exiting getProfile2FieldPermissionList method ...");
  1247. return $return_data;
  1248. }
  1249. /** Function to insert value to profile2fieldPermissions table
  1250. * @param $fld_module -- field module :: Type string
  1251. * @param $profileid -- profileid :: Type integer
  1252. * @returns $return_data -- return_data :: Type string
  1253. */
  1254. function getProfile2ModuleFieldPermissionList($fld_module, $profileid) {
  1255. global $log;
  1256. $log->debug("Entering getProfile2ModuleFieldPermissionList(".$fld_module.",". $profileid.") method ...");
  1257. $log->info("in getProfile2ModuleFieldList ".$fld_module. ' vtiger_profile id is '.$profileid);
  1258. // Cache information to re-use
  1259. static $_module_fieldpermission_cache = array();
  1260. if(!isset($_module_fieldpermission_cache[$fld_module])) {
  1261. $_module_fieldpermission_cache[$fld_module] = array();
  1262. }
  1263. $return_data = array();
  1264. global $adb;
  1265. $tabid = getTabid($fld_module);
  1266. $query = "SELECT vtiger_profile2tab.tabid, vtiger_profile2tab.permissions, vtiger_field.fieldlabel, vtiger_field.uitype,
  1267. vtiger_field.fieldid, vtiger_field.displaytype, vtiger_field.typeofdata
  1268. FROM vtiger_profile2tab INNER JOIN vtiger_field ON vtiger_field.tabid=vtiger_profile2tab.tabid
  1269. WHERE vtiger_profile2tab.profileid=? AND vtiger_profile2tab.tabid=? AND vtiger_field.presence in (0,2)";
  1270. $qparams = array($profileid, $tabid);
  1271. $result = $adb->pquery($query, $qparams);
  1272. for($i=0; $i<$adb->num_rows($res

Large files files are truncated, but you can click here to view the full file