PageRenderTime 53ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 1ms

/include/utils.php

https://github.com/mikmagic/sugarcrm_dev
PHP | 4325 lines | 3681 code | 258 blank | 386 comment | 304 complexity | 88daed9f46940b94fdfe45feae42cb08 MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, LGPL-2.1, BSD-3-Clause, AGPL-3.0

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

  1. <?php
  2. /*********************************************************************************
  3. * SugarCRM Community Edition is a customer relationship management program developed by
  4. * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
  5. *
  6. * This program is free software; you can redistribute it and/or modify it under
  7. * the terms of the GNU Affero General Public License version 3 as published by the
  8. * Free Software Foundation with the addition of the following permission added
  9. * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
  10. * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
  11. * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
  12. *
  13. * This program is distributed in the hope that it will be useful, but WITHOUT
  14. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  15. * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
  16. * details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public License along with
  19. * this program; if not, see http://www.gnu.org/licenses or write to the Free
  20. * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  21. * 02110-1301 USA.
  22. *
  23. * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
  24. * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
  25. *
  26. * The interactive user interfaces in modified source and object code versions
  27. * of this program must display Appropriate Legal Notices, as required under
  28. * Section 5 of the GNU Affero General Public License version 3.
  29. *
  30. * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
  31. * these Appropriate Legal Notices must retain the display of the "Powered by
  32. * SugarCRM" logo. If the display of the logo is not reasonably feasible for
  33. * technical reasons, the Appropriate Legal Notices must display the words
  34. * "Powered by SugarCRM".
  35. ********************************************************************************/
  36. /*********************************************************************************
  37. * Description: Includes generic helper functions used throughout the application.
  38. * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
  39. * All Rights Reserved.
  40. * Contributor(s): ______________________________________..
  41. ********************************************************************************/
  42. require_once('include/SugarObjects/SugarConfig.php');
  43. require_once('include/utils/security_utils.php');
  44. function make_sugar_config(&$sugar_config)
  45. {
  46. /* used to convert non-array config.php file to array format */
  47. global $admin_export_only;
  48. global $cache_dir;
  49. global $calculate_response_time;
  50. global $create_default_user;
  51. global $dateFormats;
  52. global $dbconfig;
  53. global $dbconfigoption;
  54. global $default_action;
  55. global $default_charset;
  56. global $default_currency_name;
  57. global $default_currency_symbol;
  58. global $default_currency_iso4217;
  59. global $defaultDateFormat;
  60. global $default_language;
  61. global $default_module;
  62. global $default_password;
  63. global $default_permission_mode;
  64. global $default_theme;
  65. global $defaultTimeFormat;
  66. global $default_user_is_admin;
  67. global $default_user_name;
  68. global $disable_export;
  69. global $disable_persistent_connections;
  70. global $display_email_template_variable_chooser;
  71. global $display_inbound_email_buttons;
  72. global $history_max_viewed;
  73. global $host_name;
  74. global $import_dir;
  75. global $languages;
  76. global $list_max_entries_per_page;
  77. global $lock_default_user_name;
  78. global $log_memory_usage;
  79. global $requireAccounts;
  80. global $RSS_CACHE_TIME;
  81. global $session_dir;
  82. global $site_URL;
  83. global $site_url;
  84. global $sugar_version;
  85. global $timeFormats;
  86. global $tmp_dir;
  87. global $translation_string_prefix;
  88. global $unique_key;
  89. global $upload_badext;
  90. global $upload_dir;
  91. global $upload_maxsize;
  92. global $import_max_execution_time;
  93. global $list_max_entries_per_subpanel;
  94. global $passwordsetting;
  95. // assumes the following variables must be set:
  96. // $dbconfig, $dbconfigoption, $cache_dir, $import_dir, $session_dir, $site_URL, $tmp_dir, $upload_dir
  97. $sugar_config = array (
  98. 'admin_export_only' => empty($admin_export_only) ? false : $admin_export_only,
  99. 'export_delimiter' => empty($export_delimiter) ? ',' : $export_delimiter,
  100. 'cache_dir' => empty($cache_dir) ? 'cache/' : $cache_dir,
  101. 'calculate_response_time' => empty($calculate_response_time) ? true : $calculate_response_time,
  102. 'create_default_user' => empty($create_default_user) ? false : $create_default_user,
  103. 'chartEngine' => 'Jit',
  104. 'date_formats' => empty($dateFormats) ? array(
  105. 'Y-m-d'=>'2010-12-23',
  106. 'd-m-Y' => '23-12-2010',
  107. 'm-d-Y'=>'12-23-2010',
  108. 'Y/m/d'=>'2010/12/23',
  109. 'd/m/Y' => '23/12/2010',
  110. 'm/d/Y'=>'12/23/2010',
  111. 'Y.m.d' => '2010.12.23',
  112. 'd.m.Y' => '23.12.2010',
  113. 'm.d.Y' => '12.23.2010'
  114. ) : $dateFormats,
  115. 'dbconfig' => $dbconfig, // this must be set!!
  116. 'dbconfigoption' => $dbconfigoption, // this must be set!!
  117. 'default_action' => empty($default_action) ? 'index' : $default_action,
  118. 'default_charset' => empty($default_charset) ? 'UTF-8' : $default_charset,
  119. 'default_currency_name' => empty($default_currency_name) ? 'US Dollar' : $default_currency_name,
  120. 'default_currency_symbol' => empty($default_currency_symbol) ? '$' : $default_currency_symbol,
  121. 'default_currency_iso4217' => empty($default_currency_iso4217) ? '$' : $default_currency_iso4217,
  122. 'default_date_format' => empty($defaultDateFormat) ? 'm/d/Y' : $defaultDateFormat,
  123. 'default_export_charset' => 'UTF-8',
  124. 'default_language' => empty($default_language) ? 'en_us' : $default_language,
  125. 'default_module' => empty($default_module) ? 'Home' : $default_module,
  126. 'default_password' => empty($default_password) ? '' : $default_password,
  127. 'default_permissions' => array (
  128. 'dir_mode' => 02770,
  129. 'file_mode' => 0660,
  130. 'chown' => '',
  131. 'chgrp' => '',
  132. ),
  133. 'default_theme' => empty($default_theme) ? 'Sugar5' : $default_theme,
  134. 'default_time_format' => empty($defaultTimeFormat) ? 'h:ia' : $defaultTimeFormat,
  135. 'default_user_is_admin' => empty($default_user_is_admin) ? false : $default_user_is_admin,
  136. 'default_user_name' => empty($default_user_name) ? '' : $default_user_name,
  137. 'disable_export' => empty($disable_export) ? false : $disable_export,
  138. 'disable_persistent_connections' => empty($disable_persistent_connections) ? false : $disable_persistent_connections,
  139. 'display_email_template_variable_chooser' => empty($display_email_template_variable_chooser) ? false : $display_email_template_variable_chooser,
  140. 'display_inbound_email_buttons' => empty($display_inbound_email_buttons) ? false : $display_inbound_email_buttons,
  141. 'history_max_viewed' => empty($history_max_viewed) ? 50 : $history_max_viewed,
  142. 'host_name' => empty($host_name) ? 'localhost' : $host_name,
  143. 'import_dir' => $import_dir, // this must be set!!
  144. 'import_max_records_per_file' => 100,
  145. 'languages' => empty($languages) ? array('en_us' => 'English (US)') : $languages,
  146. 'list_max_entries_per_page' => empty($list_max_entries_per_page) ? 20 : $list_max_entries_per_page,
  147. 'list_max_entries_per_subpanel' => empty($list_max_entries_per_subpanel) ? 10 : $list_max_entries_per_subpanel,
  148. 'lock_default_user_name' => empty($lock_default_user_name) ? false : $lock_default_user_name,
  149. 'log_memory_usage' => empty($log_memory_usage) ? false : $log_memory_usage,
  150. 'portal_view' => 'single_user',
  151. 'resource_management' => array (
  152. 'special_query_limit' => 50000,
  153. 'special_query_modules' => array('Reports', 'Export', 'Import', 'Administration', 'Sync'),
  154. 'default_limit' => 1000,
  155. ),
  156. 'require_accounts' => empty($requireAccounts) ? true : $requireAccounts,
  157. 'rss_cache_time' => empty($RSS_CACHE_TIME) ? '10800' : $RSS_CACHE_TIME,
  158. 'session_dir' => $session_dir, // this must be set!!
  159. 'site_url' => empty($site_URL) ? $site_url : $site_URL, // this must be set!!
  160. 'showDetailData' => true, // if true, read-only ACL fields will still appear on EditViews as non-editable
  161. 'showThemePicker' => true,
  162. 'sugar_version' => empty($sugar_version) ? 'unknown' : $sugar_version,
  163. 'time_formats' => empty($timeFormats) ? array (
  164. 'H:i'=>'23:00', 'h:ia'=>'11:00 pm', 'h:iA'=>'11:00PM',
  165. 'H.i'=>'23.00', 'h.ia'=>'11.00 pm', 'h.iA'=>'11.00PM' ) : $timeFormats,
  166. 'tmp_dir' => $tmp_dir, // this must be set!!
  167. 'translation_string_prefix' => empty($translation_string_prefix) ? false : $translation_string_prefix,
  168. 'unique_key' => empty($unique_key) ? md5(create_guid()) : $unique_key,
  169. 'upload_badext' => empty($upload_badext) ? array (
  170. 'php', 'php3', 'php4', 'php5', 'pl', 'cgi', 'py',
  171. 'asp', 'cfm', 'js', 'vbs', 'html', 'htm' ) : $upload_badext,
  172. 'upload_dir' => $upload_dir, // this must be set!!
  173. 'upload_maxsize' => empty($upload_maxsize) ? 3000000 : $upload_maxsize,
  174. 'import_max_execution_time' => empty($import_max_execution_time) ? 3600 : $import_max_execution_time,
  175. 'lock_homepage' => false,
  176. 'lock_subpanels' => false,
  177. 'max_dashlets_homepage' => 15,
  178. 'dashlet_display_row_options' => array('1','3','5','10'),
  179. 'default_max_tabs' => empty($max_tabs) ? '7' : $max_tabs,
  180. 'default_subpanel_tabs' => empty($subpanel_tabs) ? true : $subpanel_tabs,
  181. 'default_subpanel_links' => empty($subpanel_links) ? false : $subpanel_links,
  182. 'default_swap_last_viewed' => empty($swap_last_viewed) ? false : $swap_last_viewed,
  183. 'default_swap_shortcuts' => empty($swap_shortcuts) ? false : $swap_shortcuts,
  184. 'default_navigation_paradigm' => empty($navigation_paradigm) ? 'gm' : $navigation_paradigm,
  185. 'default_call_status' => 'Planned',
  186. 'js_lang_version' => 1,
  187. 'passwordsetting' => empty($passwordsetting) ? array (
  188. 'SystemGeneratedPasswordON' => '',
  189. 'generatepasswordtmpl' => '',
  190. 'lostpasswordtmpl' => '',
  191. 'forgotpasswordON' => true,
  192. 'linkexpiration' => '1',
  193. 'linkexpirationtime' => '30',
  194. 'linkexpirationtype' => '1',
  195. 'systexpiration' => '0',
  196. 'systexpirationtime' => '',
  197. 'systexpirationtype' => '0',
  198. 'systexpirationlogin' => '',
  199. ) : $passwordsetting,
  200. );
  201. }
  202. function get_sugar_config_defaults() {
  203. global $locale;
  204. /**
  205. * used for getting base values for array style config.php. used by the
  206. * installer and to fill in new entries on upgrades. see also:
  207. * sugar_config_union
  208. */
  209. $sugar_config_defaults = array (
  210. 'admin_export_only' => false,
  211. 'export_delimiter' => ',',
  212. 'cache_dir' => 'cache/',
  213. 'calculate_response_time' => true,
  214. 'create_default_user' => false,
  215. 'chartEngine' => 'Jit',
  216. 'date_formats' => array (
  217. 'Y-m-d' => '2010-12-23', 'm-d-Y' => '12-23-2010', 'd-m-Y' => '23-12-2010',
  218. 'Y/m/d' => '2010/12/23', 'm/d/Y' => '12/23/2010', 'd/m/Y' => '23/12/2010',
  219. 'Y.m.d' => '2010.12.23', 'd.m.Y' => '23.12.2010', 'm.d.Y' => '12.23.2010',),
  220. 'dbconfigoption' => array (
  221. 'persistent' => true,
  222. 'autofree' => false,
  223. 'debug' => 0,
  224. 'seqname_format' => '%s_seq',
  225. 'portability' => 0,
  226. 'ssl' => false ),
  227. 'default_action' => 'index',
  228. 'default_charset' => return_session_value_or_default('default_charset',
  229. 'UTF-8'),
  230. 'default_currency_name' => return_session_value_or_default('default_currency_name', 'US Dollar'),
  231. 'default_currency_symbol' => return_session_value_or_default('default_currency_symbol', '$'),
  232. 'default_currency_iso4217' => return_session_value_or_default('default_currency_iso4217', 'USD'),
  233. 'default_currency_significant_digits' => return_session_value_or_default('default_currency_significant_digits', 2),
  234. 'default_number_grouping_seperator' => return_session_value_or_default('default_number_grouping_seperator', ','),
  235. 'default_decimal_seperator' => return_session_value_or_default('default_decimal_seperator', '.'),
  236. 'default_date_format' => 'm/d/Y',
  237. 'default_export_charset' => 'UTF-8',
  238. 'default_language' => return_session_value_or_default('default_language',
  239. 'en_us'),
  240. 'default_module' => 'Home',
  241. 'default_password' => '',
  242. 'default_permissions' => array (
  243. 'dir_mode' => 02770,
  244. 'file_mode' => 0660,
  245. 'user' => '',
  246. 'group' => '',
  247. ),
  248. 'default_theme' => return_session_value_or_default('site_default_theme', 'Sugar5'),
  249. 'default_time_format' => 'h:ia',
  250. 'default_user_is_admin' => false,
  251. 'default_user_name' => '',
  252. 'disable_export' => false,
  253. 'disable_persistent_connections' =>
  254. return_session_value_or_default('disable_persistent_connections',
  255. 'false'),
  256. 'display_email_template_variable_chooser' => false,
  257. 'display_inbound_email_buttons' => false,
  258. 'dump_slow_queries' => false,
  259. 'email_default_editor' => 'html',
  260. 'email_default_client' => 'sugar',
  261. 'email_default_delete_attachments' => true,
  262. 'history_max_viewed' => 50,
  263. 'installer_locked' => true,
  264. 'import_max_records_per_file' => 100,
  265. 'languages' => array('en_us' => 'English (US)'),
  266. 'large_scale_test' => false,
  267. 'list_max_entries_per_page' => 20,
  268. 'list_max_entries_per_subpanel' => 10,
  269. 'lock_default_user_name' => false,
  270. 'log_memory_usage' => false,
  271. 'portal_view' => 'single_user',
  272. 'resource_management' => array (
  273. 'special_query_limit' => 50000,
  274. 'special_query_modules' => array('Reports', 'Export', 'Import', 'Administration', 'Sync'),
  275. 'default_limit' => 1000,
  276. ),
  277. 'require_accounts' => true,
  278. 'rss_cache_time' => return_session_value_or_default('rss_cache_time',
  279. '10800'),
  280. 'save_query' => 'all',
  281. 'showDetailData' => true, // if true, read-only ACL fields will still appear on EditViews as non-editable
  282. 'showThemePicker' => true,
  283. 'slow_query_time_msec' => '100',
  284. 'sugarbeet' => true,
  285. 'time_formats' => array (
  286. 'H:i'=>'23:00', 'h:ia'=>'11:00pm', 'h:iA'=>'11:00PM',
  287. 'H.i'=>'23.00', 'h.ia'=>'11.00pm', 'h.iA'=>'11.00PM' ),
  288. 'tracker_max_display_length' => 15,
  289. 'translation_string_prefix' =>
  290. return_session_value_or_default('translation_string_prefix', false),
  291. 'upload_badext' => array (
  292. 'php', 'php3', 'php4', 'php5', 'pl', 'cgi', 'py',
  293. 'asp', 'cfm', 'js', 'vbs', 'html', 'htm' ),
  294. 'upload_maxsize' => 3000000,
  295. 'import_max_execution_time' => 3600,
  296. // 'use_php_code_json' => returnPhpJsonStatus(),
  297. 'verify_client_ip' => true,
  298. 'js_custom_version' => '',
  299. 'js_lang_version' => 1,
  300. 'default_number_grouping_seperator' => ',',
  301. 'default_decimal_seperator' => '.',
  302. 'lock_homepage' => false,
  303. 'lock_subpanels' => false,
  304. 'max_dashlets_homepage' => '15',
  305. 'default_max_tabs' => '7',
  306. 'dashlet_display_row_options' => array('1','3','5','10'),
  307. 'default_subpanel_tabs' => true,
  308. 'default_subpanel_links' => false,
  309. 'default_swap_last_viewed' => false,
  310. 'default_swap_shortcuts' => false,
  311. 'default_navigation_paradigm' => 'gm',
  312. 'admin_access_control' => false,
  313. 'use_common_ml_dir' => false,
  314. 'common_ml_dir' => '',
  315. 'vcal_time' => '2',
  316. 'passwordsetting' => empty($passwordsetting) ? array (
  317. 'SystemGeneratedPasswordON' => '',
  318. 'generatepasswordtmpl' => '',
  319. 'lostpasswordtmpl' => '',
  320. 'forgotpasswordON' => false,
  321. 'linkexpiration' => '1',
  322. 'linkexpirationtime' => '30',
  323. 'linkexpirationtype' => '1',
  324. 'systexpiration' => '0',
  325. 'systexpirationtime' => '',
  326. 'systexpirationtype' => '0',
  327. 'systexpirationlogin' => '',
  328. ) : $passwordsetting,
  329. 'use_real_names' => true,
  330. );
  331. if(!is_object($locale)) {
  332. $locale = new Localization();
  333. }
  334. $sugar_config_defaults['default_currencies'] = $locale->getDefaultCurrencies();
  335. $sugar_config_defaults = sugarArrayMerge($locale->getLocaleConfigDefaults(), $sugar_config_defaults);
  336. return( $sugar_config_defaults );
  337. }
  338. /**
  339. * @deprecated use SugarView::getMenu() instead
  340. */
  341. function load_menu($path){
  342. global $module_menu;
  343. if(file_exists($path . 'Menu.php'))
  344. {
  345. require($path . 'Menu.php');
  346. }
  347. if(file_exists('custom/' . $path . 'Ext/Menus/menu.ext.php'))
  348. {
  349. require('custom/' . $path . 'Ext/Menus/menu.ext.php');
  350. }
  351. if(file_exists('custom/application/Ext/Menus/menu.ext.php'))
  352. {
  353. require('custom/application/Ext/Menus/menu.ext.php');
  354. }
  355. return $module_menu;
  356. }
  357. /**
  358. * get_notify_template_file
  359. * This function will return the location of the email notifications template to use
  360. *
  361. * @return string relative file path to email notifications template file
  362. */
  363. function get_notify_template_file($language){
  364. /*
  365. * Order of operation:
  366. * 1) custom version of specified language
  367. * 2) stock version of specified language
  368. * 3) custom version of en_us template
  369. * 4) stock en_us template
  370. */
  371. // set $file to the base code template so it's set if none of the conditions pass
  372. $file = "include/language/en_us.notify_template.html";
  373. if(file_exists("custom/include/language/{$language}.notify_template.html")){
  374. $file = "custom/include/language/{$language}.notify_template.html";
  375. }
  376. else if(file_exists("include/language/{$language}.notify_template.html")){
  377. $file = "include/language/{$language}.notify_template.html";
  378. }
  379. else if(file_exists("custom/include/language/en_us.notify_template.html")){
  380. $file = "custom/include/language/en_us.notify_template.html";
  381. }
  382. return $file;
  383. }
  384. function sugar_config_union( $default, $override ){
  385. // a little different then array_merge and array_merge_recursive. we want
  386. // the second array to override the first array if the same value exists,
  387. // otherwise merge the unique keys. it handles arrays of arrays recursively
  388. // might be suitable for a generic array_union
  389. if( !is_array( $override ) ){
  390. $override = array();
  391. }
  392. foreach( $default as $key => $value ){
  393. if( !array_key_exists($key, $override) ){
  394. $override[$key] = $value;
  395. }
  396. else if( is_array( $key ) ){
  397. $override[$key] = sugar_config_union( $value, $override[$key] );
  398. }
  399. }
  400. return( $override );
  401. }
  402. function make_not_writable( $file ){
  403. // Returns true if the given file/dir has been made not writable
  404. $ret_val = false;
  405. if( is_file($file) || is_dir($file) ){
  406. if( !is_writable($file) ){
  407. $ret_val = true;
  408. }
  409. else {
  410. $original_fileperms = fileperms($file);
  411. // take away writable permissions
  412. $new_fileperms = $original_fileperms & ~0x0092;
  413. @sugar_chmod($file, $new_fileperms);
  414. if( !is_writable($file) ){
  415. $ret_val = true;
  416. }
  417. }
  418. }
  419. return $ret_val;
  420. }
  421. /** This function returns the name of the person.
  422. * It currently returns "first last". It should not put the space if either name is not available.
  423. * It should not return errors if either name is not available.
  424. * If no names are present, it will return ""
  425. * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
  426. * All Rights Reserved.
  427. * Contributor(s): ______________________________________..
  428. */
  429. function return_name($row, $first_column, $last_column)
  430. {
  431. $first_name = "";
  432. $last_name = "";
  433. $full_name = "";
  434. if(isset($row[$first_column]))
  435. {
  436. $first_name = stripslashes($row[$first_column]);
  437. }
  438. if(isset($row[$last_column]))
  439. {
  440. $last_name = stripslashes($row[$last_column]);
  441. }
  442. $full_name = $first_name;
  443. // If we have a first name and we have a last name
  444. if($full_name != "" && $last_name != "")
  445. {
  446. // append a space, then the last name
  447. $full_name .= " ".$last_name;
  448. }
  449. // If we have no first name, but we have a last name
  450. else if($last_name != "")
  451. {
  452. // append the last name without the space.
  453. $full_name .= $last_name;
  454. }
  455. return $full_name;
  456. }
  457. function get_languages()
  458. {
  459. global $sugar_config;
  460. $lang = $sugar_config['languages'];
  461. if(!empty($sugar_config['disabled_languages'])){
  462. foreach(explode(',', $sugar_config['disabled_languages']) as $disable) {
  463. unset($lang[$disable]);
  464. }
  465. }
  466. return $lang;
  467. }
  468. function get_all_languages()
  469. {
  470. global $sugar_config;
  471. return $sugar_config['languages'];
  472. }
  473. function get_language_display($key)
  474. {
  475. global $sugar_config;
  476. return $sugar_config['languages'][$key];
  477. }
  478. function get_assigned_user_name($assigned_user_id, $is_group = '') {
  479. static $saved_user_list = null;
  480. if(empty($saved_user_list)) {
  481. $saved_user_list = get_user_array(false, '', '', false, null, $is_group);
  482. }
  483. if(isset($saved_user_list[$assigned_user_id])) {
  484. return $saved_user_list[$assigned_user_id];
  485. }
  486. return '';
  487. }
  488. /**
  489. * retrieves the user_name column value (login)
  490. * @param string id GUID of user
  491. * @return string
  492. */
  493. function get_user_name($id) {
  494. global $db;
  495. if(empty($db))
  496. $db = DBManagerFactory::getInstance();
  497. $q = "SELECT user_name FROM users WHERE id='{$id}'";
  498. $r = $db->query($q);
  499. $a = $db->fetchByAssoc($r);
  500. return (empty($a)) ? '' : $a['user_name'];
  501. }
  502. //TODO Update to use global cache
  503. function get_user_array($add_blank=true, $status="Active", $assigned_user="", $use_real_name=false, $user_name_begins = null, $is_group=' AND portal_only=0 ', $from_cache = true) {
  504. global $locale;
  505. global $sugar_config;
  506. if(empty($locale)) {
  507. $locale = new Localization();
  508. }
  509. if($from_cache)
  510. $user_array = get_register_value('user_array', $add_blank. $status . $assigned_user);
  511. if(!isset($user_array)) {
  512. $db = DBManagerFactory::getInstance();
  513. $temp_result = Array();
  514. // Including deleted users for now.
  515. if (empty($status)) {
  516. $query = "SELECT id, first_name, last_name, user_name from users WHERE 1=1".$is_group;
  517. }
  518. else {
  519. $query = "SELECT id, first_name, last_name, user_name from users WHERE status='$status'".$is_group;
  520. }
  521. if (!empty($user_name_begins)) {
  522. $query .= " AND user_name LIKE '$user_name_begins%' ";
  523. }
  524. if (!empty($assigned_user)) {
  525. $query .= " OR id='$assigned_user'";
  526. }
  527. $query = $query.' ORDER BY user_name ASC';
  528. $GLOBALS['log']->debug("get_user_array query: $query");
  529. $result = $db->query($query, true, "Error filling in user array: ");
  530. if ($add_blank==true) {
  531. // Add in a blank row
  532. $temp_result[''] = '';
  533. }
  534. // Get the id and the name.
  535. while($row = $db->fetchByAssoc($result)) {
  536. if($use_real_name == true || showFullName()) {
  537. if(isset($row['last_name'])) { // cn: we will ALWAYS have both first_name and last_name (empty value if blank in db)
  538. $temp_result[$row['id']] = $locale->getLocaleFormattedName($row['first_name'],$row['last_name']);
  539. } else {
  540. $temp_result[$row['id']] = $row['user_name'];
  541. }
  542. } else {
  543. $temp_result[$row['id']] = $row['user_name'];
  544. }
  545. }
  546. $user_array = $temp_result;
  547. if($from_cache)
  548. set_register_value('user_array', $add_blank. $status . $assigned_user, $temp_result);
  549. }
  550. return $user_array;
  551. }
  552. /**
  553. * uses a different query to return a list of users than get_user_array()
  554. * @param args string where clause entry
  555. * @return array Array of Users' details that match passed criteria
  556. */
  557. function getUserArrayFromFullName($args, $hide_portal_users = false) {
  558. global $locale;
  559. $db = DBManagerFactory::getInstance();
  560. $argArray = array();
  561. if(strpos($args, " ")) {
  562. $argArray = explode(" ", $args);
  563. } else {
  564. $argArray[] = $args;
  565. }
  566. $inClause = '';
  567. foreach($argArray as $arg) {
  568. if(!empty($inClause)) {
  569. $inClause .= ' OR ';
  570. }
  571. if(empty($arg))
  572. continue;
  573. $inClause .= "(first_name LIKE '{$arg}%' OR last_name LIKE '{$arg}%')";
  574. }
  575. $query = "SELECT id, first_name, last_name, user_name FROM users WHERE status='Active' AND deleted=0 AND ";
  576. if ( $hide_portal_users ) {
  577. $query .= " portal_only=0 AND ";
  578. }
  579. $query .= $inClause;
  580. $query .= " ORDER BY last_name ASC";
  581. $r = $db->query($query);
  582. $ret = array();
  583. while($a = $db->fetchByAssoc($r)) {
  584. $ret[$a['id']] = $locale->getLocaleFormattedName($a['first_name'], $a['last_name']);
  585. }
  586. return $ret;
  587. }
  588. /**
  589. *
  590. * based on user pref then system pref
  591. */
  592. function showFullName() {
  593. global $sugar_config;
  594. global $current_user;
  595. static $showFullName = null;
  596. if (is_null($showFullName)) {
  597. $sysPref = !empty($sugar_config['use_real_names']);
  598. $userPref = (is_object($current_user)) ? $current_user->getPreference('use_real_names') : null;
  599. if($userPref != null) {
  600. $showFullName = ($userPref == 'on');
  601. } else {
  602. $showFullName = $sysPref;
  603. }
  604. }
  605. return $showFullName;
  606. }
  607. function clean($string, $maxLength)
  608. {
  609. $string = substr($string, 0, $maxLength);
  610. return escapeshellcmd($string);
  611. }
  612. /**
  613. * Copy the specified request variable to the member variable of the specified object.
  614. * Do no copy if the member variable is already set.
  615. * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
  616. * All Rights Reserved.
  617. * Contributor(s): ______________________________________..
  618. */
  619. function safe_map($request_var, & $focus, $always_copy = false)
  620. {
  621. safe_map_named($request_var, $focus, $request_var, $always_copy);
  622. }
  623. /**
  624. * Copy the specified request variable to the member variable of the specified object.
  625. * Do no copy if the member variable is already set.
  626. * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
  627. * All Rights Reserved.
  628. * Contributor(s): ______________________________________..
  629. */
  630. function safe_map_named($request_var, & $focus, $member_var, $always_copy)
  631. {
  632. if (isset($_REQUEST[$request_var]) && ($always_copy || is_null($focus->$member_var))) {
  633. $GLOBALS['log']->debug("safe map named called assigning '{$_REQUEST[$request_var]}' to $member_var");
  634. $focus->$member_var = $_REQUEST[$request_var];
  635. }
  636. }
  637. /**
  638. * This function retrieves an application language file and returns the array of strings included in the $app_list_strings var.
  639. *
  640. * @param string $language specific language to load
  641. * @return array lang strings
  642. */
  643. function return_app_list_strings_language($language)
  644. {
  645. global $app_list_strings;
  646. global $sugar_config;
  647. $cache_key = 'app_list_strings.'.$language;
  648. // Check for cached value
  649. $cache_entry = sugar_cache_retrieve($cache_key);
  650. if(!empty($cache_entry))
  651. {
  652. return $cache_entry;
  653. }
  654. $default_language = $sugar_config['default_language'];
  655. $temp_app_list_strings = $app_list_strings;
  656. $langs = array();
  657. if ($language != 'en_us') {
  658. $langs[] = 'en_us';
  659. }
  660. if ($default_language != 'en_us' && $language != $default_language) {
  661. $langs[] = $default_language;
  662. }
  663. $langs[] = $language;
  664. $app_list_strings_array = array();
  665. foreach ( $langs as $lang ) {
  666. $app_list_strings = array();
  667. if(file_exists("include/language/$lang.lang.php")) {
  668. include("include/language/$lang.lang.php");
  669. $GLOBALS['log']->info("Found language file: $lang.lang.php");
  670. }
  671. if(file_exists("include/language/$lang.lang.override.php")) {
  672. include("include/language/$lang.lang.override.php");
  673. $GLOBALS['log']->info("Found override language file: $lang.lang.override.php");
  674. }
  675. if(file_exists("include/language/$lang.lang.php.override")) {
  676. include("include/language/$lang.lang.php.override");
  677. $GLOBALS['log']->info("Found override language file: $lang.lang.php.override");
  678. }
  679. $app_list_strings_array[] = $app_list_strings;
  680. }
  681. $app_list_strings = array();
  682. foreach ( $app_list_strings_array as $app_list_strings_item ) {
  683. $app_list_strings = sugarArrayMerge($app_list_strings, $app_list_strings_item);
  684. }
  685. foreach ( $langs as $lang ) {
  686. if(file_exists("custom/application/Ext/Language/$lang.lang.ext.php")) {
  687. $app_list_strings = _mergeCustomAppListStrings("custom/application/Ext/Language/$lang.lang.ext.php" , $app_list_strings);
  688. $GLOBALS['log']->info("Found extended language file: $lang.lang.ext.php");
  689. }
  690. if(file_exists("custom/include/language/$lang.lang.php")) {
  691. include("custom/include/language/$lang.lang.php");
  692. $GLOBALS['log']->info("Found custom language file: $lang.lang.php");
  693. }
  694. }
  695. if(!isset($app_list_strings)) {
  696. $GLOBALS['log']->fatal("Unable to load the application language file for the selected language ($language) or the default language ($default_language) or the en_us language");
  697. return null;
  698. }
  699. $return_value = $app_list_strings;
  700. $app_list_strings = $temp_app_list_strings;
  701. sugar_cache_put($cache_key, $return_value);
  702. return $return_value;
  703. }
  704. /**
  705. * The dropdown items in custom language files is $app_list_strings['$key']['$second_key'] = $value not
  706. * $GLOBALS['app_list_strings']['$key'] = $value, so we have to delete the original ones in app_list_strings and relace it with the custom ones.
  707. * @param file string the language that you want include,
  708. * @param app_list_strings array the golbal strings
  709. * @return array
  710. */
  711. //jchi 25347
  712. function _mergeCustomAppListStrings($file , $app_list_strings){
  713. $app_list_strings_original = $app_list_strings;
  714. unset($app_list_strings);
  715. include($file);
  716. if(!isset($app_list_strings) || !is_array($app_list_strings)){
  717. return $app_list_strings_original;
  718. }
  719. //Bug 25347: We should not merge custom dropdown fields unless they relate to parent fields or the module list.
  720. foreach($app_list_strings as $key=>$value)
  721. {
  722. $exemptDropdowns = array("moduleList", "parent_type_display", "record_type_display", "record_type_display_notes");
  723. if (!in_array($key, $exemptDropdowns) && array_key_exists($key, $app_list_strings_original))
  724. {
  725. unset($app_list_strings_original["$key"]);
  726. }
  727. }
  728. $app_list_strings = sugarArrayMergeRecursive($app_list_strings_original , $app_list_strings);
  729. return $app_list_strings;
  730. }
  731. /**
  732. * This function retrieves an application language file and returns the array of strings included.
  733. *
  734. * @param string $language specific language to load
  735. * @return array lang strings
  736. */
  737. function return_application_language($language)
  738. {
  739. global $app_strings, $sugar_config;
  740. $cache_key = 'app_strings.'.$language;
  741. // Check for cached value
  742. $cache_entry = sugar_cache_retrieve($cache_key);
  743. if(!empty($cache_entry))
  744. {
  745. return $cache_entry;
  746. }
  747. $temp_app_strings = $app_strings;
  748. $default_language = $sugar_config['default_language'];
  749. $langs = array();
  750. if ($language != 'en_us') {
  751. $langs[] = 'en_us';
  752. }
  753. if ($default_language != 'en_us' && $language != $default_language) {
  754. $langs[] = $default_language;
  755. }
  756. $langs[] = $language;
  757. $app_strings_array = array();
  758. foreach ( $langs as $lang ) {
  759. $app_strings = array();
  760. if(file_exists("include/language/$lang.lang.php")) {
  761. include("include/language/$lang.lang.php");
  762. $GLOBALS['log']->info("Found language file: $lang.lang.php");
  763. }
  764. if(file_exists("include/language/$lang.lang.override.php")) {
  765. include("include/language/$lang.lang.override.php");
  766. $GLOBALS['log']->info("Found override language file: $lang.lang.override.php");
  767. }
  768. if(file_exists("include/language/$lang.lang.php.override")) {
  769. include("include/language/$lang.lang.php.override");
  770. $GLOBALS['log']->info("Found override language file: $lang.lang.php.override");
  771. }
  772. if(file_exists("custom/application/Ext/Language/$lang.lang.ext.php")) {
  773. include("custom/application/Ext/Language/$lang.lang.ext.php");
  774. $GLOBALS['log']->info("Found extended language file: $lang.lang.ext.php");
  775. }
  776. if(file_exists("custom/include/language/$lang.lang.php")) {
  777. include("custom/include/language/$lang.lang.php");
  778. $GLOBALS['log']->info("Found custom language file: $lang.lang.php");
  779. }
  780. $app_strings_array[] = $app_strings;
  781. }
  782. $app_strings = array();
  783. foreach ( $app_strings_array as $app_strings_item ) {
  784. $app_strings = sugarArrayMerge($app_strings, $app_strings_item);
  785. }
  786. if(!isset($app_strings)) {
  787. $GLOBALS['log']->fatal("Unable to load the application language strings");
  788. return null;
  789. }
  790. // If we are in debug mode for translating, turn on the prefix now!
  791. if($sugar_config['translation_string_prefix']) {
  792. foreach($app_strings as $entry_key=>$entry_value) {
  793. $app_strings[$entry_key] = $language.' '.$entry_value;
  794. }
  795. }
  796. if(isset($_SESSION['show_deleted'])) {
  797. $app_strings['LBL_DELETE_BUTTON'] = $app_strings['LBL_UNDELETE_BUTTON'];
  798. $app_strings['LBL_DELETE_BUTTON_LABEL'] = $app_strings['LBL_UNDELETE_BUTTON_LABEL'];
  799. $app_strings['LBL_DELETE_BUTTON_TITLE'] = $app_strings['LBL_UNDELETE_BUTTON_TITLE'];
  800. $app_strings['LBL_DELETE'] = $app_strings['LBL_UNDELETE'];
  801. }
  802. $app_strings['LBL_ALT_HOT_KEY'] = get_alt_hot_key();
  803. $return_value = $app_strings;
  804. $app_strings = $temp_app_strings;
  805. sugar_cache_put($cache_key, $return_value);
  806. return $return_value;
  807. }
  808. /**
  809. * This function retrieves a module's language file and returns the array of strings included.
  810. *
  811. * @param string $language specific language to load
  812. * @param string $module module name to load strings for
  813. * @param bool $refresh optional, true if you want to rebuild the language strings
  814. * @return array lang strings
  815. */
  816. function return_module_language($language, $module, $refresh=false)
  817. {
  818. global $mod_strings;
  819. global $sugar_config;
  820. global $currentModule;
  821. // Jenny - Bug 8119: Need to check if $module is not empty
  822. if (empty($module)) {
  823. $stack = debug_backtrace();
  824. $GLOBALS['log']->warn("Variable module is not in return_module_language ". var_export($stack, true));
  825. return array();
  826. }
  827. $cache_key = LanguageManager::getLanguageCacheKey($module, $language);
  828. // Check for cached value
  829. $cache_entry = sugar_cache_retrieve($cache_key);
  830. if(!empty($cache_entry))
  831. {
  832. return $cache_entry;
  833. }
  834. // Store the current mod strings for later
  835. $temp_mod_strings = $mod_strings;
  836. $loaded_mod_strings = array();
  837. $language_used = $language;
  838. $default_language = $sugar_config['default_language'];
  839. if(empty($language)) {
  840. $language = $default_language;
  841. }
  842. // Bug 21559 - So we can get all the strings defined in the template, refresh
  843. // the vardefs file if the cached language file doesn't exist.
  844. if(!file_exists($GLOBALS['sugar_config']['cache_dir'].'modules/'. $module . '/language/'.$language.'.lang.php')
  845. && !empty($GLOBALS['beanList'][$module])){
  846. $object = $GLOBALS['beanList'][$module];
  847. if ($object == 'aCase') {
  848. $object = 'Case';
  849. }
  850. VardefManager::refreshVardefs($module,$object);
  851. }
  852. $loaded_mod_strings = LanguageManager::loadModuleLanguage($module, $language,$refresh);
  853. // cn: bug 6048 - merge en_us with requested language
  854. if($language != $sugar_config['default_language'])
  855. $loaded_mod_strings = sugarArrayMerge(
  856. LanguageManager::loadModuleLanguage($module, $sugar_config['default_language'],$refresh),
  857. $loaded_mod_strings
  858. );
  859. // Load in en_us strings by default
  860. if($language != 'en_us' && $sugar_config['default_language'] != 'en_us')
  861. $loaded_mod_strings = sugarArrayMerge(
  862. LanguageManager::loadModuleLanguage($module, 'en_us', $refresh),
  863. $loaded_mod_strings
  864. );
  865. // If we are in debug mode for translating, turn on the prefix now!
  866. if($sugar_config['translation_string_prefix']) {
  867. foreach($loaded_mod_strings as $entry_key=>$entry_value) {
  868. $loaded_mod_strings[$entry_key] = $language_used.' '.$entry_value;
  869. }
  870. }
  871. $return_value = $loaded_mod_strings;
  872. if(!isset($mod_strings)){
  873. $mod_strings = $return_value;
  874. }
  875. else
  876. $mod_strings = $temp_mod_strings;
  877. sugar_cache_put($cache_key, $return_value);
  878. return $return_value;
  879. }
  880. /** This function retrieves an application language file and returns the array of strings included in the $mod_list_strings var.
  881. * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
  882. * All Rights Reserved.
  883. * Contributor(s): ______________________________________..
  884. * If you are using the current language, do not call this function unless you are loading it for the first time */
  885. function return_mod_list_strings_language($language,$module) {
  886. global $mod_list_strings;
  887. global $sugar_config;
  888. global $currentModule;
  889. $cache_key = "mod_list_str_lang.".$language.$module;
  890. // Check for cached value
  891. $cache_entry = sugar_cache_retrieve($cache_key);
  892. if(!empty($cache_entry))
  893. {
  894. return $cache_entry;
  895. }
  896. $language_used = $language;
  897. $temp_mod_list_strings = $mod_list_strings;
  898. $default_language = $sugar_config['default_language'];
  899. if($currentModule == $module && isset($mod_list_strings) && $mod_list_strings != null) {
  900. return $mod_list_strings;
  901. }
  902. // cn: bug 6351 - include en_us if file langpack not available
  903. // cn: bug 6048 - merge en_us with requested language
  904. include("modules/$module/language/en_us.lang.php");
  905. $en_mod_list_strings = array();
  906. if($language_used != $default_language)
  907. $en_mod_list_strings = $mod_list_strings;
  908. if(file_exists("modules/$module/language/$language.lang.php")) {
  909. include("modules/$module/language/$language.lang.php");
  910. }
  911. if(file_exists("modules/$module/language/$language.lang.override.php")){
  912. include("modules/$module/language/$language.lang.override.php");
  913. }
  914. if(file_exists("modules/$module/language/$language.lang.php.override")){
  915. echo 'Please Change:<br>' . "modules/$module/language/$language.lang.php.override" . '<br>to<br>' . 'Please Change:<br>' . "modules/$module/language/$language.lang.override.php";
  916. include("modules/$module/language/$language.lang.php.override");
  917. }
  918. // cn: bug 6048 - merge en_us with requested language
  919. $mod_list_strings = sugarArrayMerge($en_mod_list_strings, $mod_list_strings);
  920. // if we still don't have a language pack, then log an error
  921. if(!isset($mod_list_strings)) {
  922. $GLOBALS['log']->fatal("Unable to load the application list language file for the selected language($language) or the default language($default_language) for module({$module})");
  923. return null;
  924. }
  925. $return_value = $mod_list_strings;
  926. $mod_list_strings = $temp_mod_list_strings;
  927. sugar_cache_put($cache_key, $return_value);
  928. return $return_value;
  929. }
  930. /** This function retrieves a theme's language file and returns the array of strings included.
  931. * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
  932. * All Rights Reserved.
  933. * Contributor(s): ______________________________________..
  934. */
  935. function return_theme_language($language, $theme)
  936. {
  937. global $mod_strings, $sugar_config, $currentModule;
  938. $language_used = $language;
  939. $default_language = $sugar_config['default_language'];
  940. include(SugarThemeRegistry::get($theme)->getFilePath()."/language/$current_language.lang.php");
  941. if(file_exists(SugarThemeRegistry::get($theme)->getFilePath()."/language/$current_language.lang.override.php")){
  942. include(SugarThemeRegistry::get($theme)->getFilePath()."/language/$current_language.lang.override.php");
  943. }
  944. if(file_exists(SugarThemeRegistry::get($theme)->getFilePath()."/language/$current_language.lang.php.override")){
  945. echo 'Please Change:<br>' . SugarThemeRegistry::get($theme)->getFilePath()."/language/$current_language.lang.php.override" . '<br>to<br>' . 'Please Change:<br>' . SugarThemeRegistry::get($theme)->getFilePath()."/language/$current_language.lang.override.php";
  946. include(SugarThemeRegistry::get($theme)->getFilePath()."/language/$current_language.lang.php.override");
  947. }
  948. if(!isset($theme_strings))
  949. {
  950. $GLOBALS['log']->warn("Unable to find the theme file for language: ".$language." and theme: ".$theme);
  951. require(SugarThemeRegistry::get($theme)->getFilePath()."/language/$default_language.lang.php");
  952. $language_used = $default_language;
  953. }
  954. if(!isset($theme_strings))
  955. {
  956. $GLOBALS['log']->fatal("Unable to load the theme($theme) language file for the selected language($language) or the default language($default_language)");
  957. return null;
  958. }
  959. // If we are in debug mode for translating, turn on the prefix now!
  960. if($sugar_config['translation_string_prefix'])
  961. {
  962. foreach($theme_strings as $entry_key=>$entry_value)
  963. {
  964. $theme_strings[$entry_key] = $language_used.' '.$entry_value;
  965. }
  966. }
  967. return $theme_strings;
  968. }
  969. /** If the session variable is defined and is not equal to "" then return it. Otherwise, return the default value.
  970. * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
  971. * All Rights Reserved.
  972. * Contributor(s): ______________________________________..
  973. */
  974. function return_session_value_or_default($varname, $default)
  975. {
  976. if(isset($_SESSION[$varname]) && $_SESSION[$varname] != "")
  977. {
  978. return $_SESSION[$varname];
  979. }
  980. return $default;
  981. }
  982. /**
  983. * Creates an array of where restrictions. These are used to construct a where SQL statement on the query
  984. * 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.
  985. * @param &$where_clauses - The array to append the clause to
  986. * @param $variable_name - The name of the variable to look for an add to the where clause if found
  987. * @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.
  988. * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
  989. * All Rights Reserved.
  990. * Contributor(s): ______________________________________..
  991. */
  992. function append_where_clause(&$where_clauses, $variable_name, $SQL_name = null)
  993. {
  994. if($SQL_name == null)
  995. {
  996. $SQL_name = $variable_name;
  997. }
  998. if(isset($_REQUEST[$variable_name]) && $_REQUEST[$variable_name] != "")
  999. {
  1000. array_push($where_clauses, "$SQL_name like '".$GLOBALS['db']->quote($_REQUEST[$variable_name])."%'");
  1001. }
  1002. }
  1003. /**
  1004. * Generate the appropriate SQL based on the where clauses.
  1005. * @param $where_clauses - An Array of individual where clauses stored as strings
  1006. * @returns string where_clause - The final SQL where clause to be executed.
  1007. * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
  1008. * All Rights Reserved.
  1009. * Contributor(s): ______________________________________..
  1010. */
  1011. function generate_where_statement($where_clauses)
  1012. {
  1013. $where = "";
  1014. foreach($where_clauses as $clause)
  1015. {
  1016. if($where != "")
  1017. $where .= " and ";
  1018. $where .= $clause;
  1019. }
  1020. $GLOBALS['log']->info("Here is the where clause for the list view: $where");
  1021. return $where;
  1022. }
  1023. /**
  1024. * determines if a passed string matches the criteria for a Sugar GUID
  1025. * @param string $guid
  1026. * @return bool False on failure
  1027. */
  1028. function is_guid($guid) {
  1029. if(strlen($guid) != 36) {
  1030. return false;
  1031. }
  1032. if(preg_match("/\w{8}-\w{4}-\w{4}-\w{4}-\w{12}/i", $guid)) {
  1033. return true;
  1034. }
  1035. return true;;
  1036. }
  1037. /**
  1038. * A temporary method of generating GUIDs of the correct format for our DB.
  1039. * @return String contianing a GUID in the format: aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee
  1040. *
  1041. * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
  1042. * All Rights Reserved.
  1043. * Contributor(s): ______________________________________..
  1044. */
  1045. function create_guid()
  1046. {
  1047. $microTime = microtime();
  1048. list($a_dec, $a_sec) = explode(" ", $microTime);
  1049. $dec_hex = dechex($a_dec* 1000000);
  1050. $sec_hex = dechex($a_sec);
  1051. ensure_length($dec_hex, 5);
  1052. ensure_length($sec_hex, 6);
  1053. $guid = "";
  1054. $guid .= $dec_hex;
  1055. $guid .= create_guid_section(3);
  1056. $guid .= '-';
  1057. $guid .= create_guid_section(4);
  1058. $guid .= '-';
  1059. $guid .= create_guid_section(4);
  1060. $guid .= '-';
  1061. $guid .= create_guid_section(4);
  1062. $guid .= '-';
  1063. $guid .= $sec_hex;
  1064. $guid .= create_guid_section(6);
  1065. return $guid;
  1066. }
  1067. function create_guid_section($characters)
  1068. {
  1069. $return = "";
  1070. for($i=0; $i<$characters; $i++)
  1071. {
  1072. $return .= dechex(mt_rand(0,15));
  1073. }
  1074. return $return;
  1075. }
  1076. function ensure_length(&$string, $length)
  1077. {
  1078. $strlen = strlen($string);
  1079. if($strlen < $length)
  1080. {
  1081. $string = str_pad($string,$length,"0");
  1082. }
  1083. else if($strlen > $length)
  1084. {
  1085. $string = substr($string, 0, $length);
  1086. }
  1087. }
  1088. function microtime_diff($a, $b) {
  1089. list($a_dec, $a_sec) = explode(" ", $a);
  1090. list($b_dec, $b_sec) = explode(" ", $b);
  1091. return $b_sec - $a_sec + $b_dec - $a_dec;
  1092. }
  1093. // check if Studio is displayed.
  1094. function displayStudioForCurrentUser()
  1095. {
  1096. global $current_user;
  1097. if ( $current_user->isAdmin() ) {
  1098. return true;
  1099. }
  1100. return true;
  1101. }
  1102. function displayWorkflowForCurrentUser()
  1103. {
  1104. $_SESSION['display_workflow_for_user'] = false;
  1105. return false;
  1106. }
  1107. // return an array with all modules where the user is an admin.
  1108. function get_admin_modules_for_user($user) {
  1109. $GLOBALS['log']->deprecated("get_admin_modules_for_user() is deprecated as of 6.2.2 and may disappear in the future, use Users->getDeveloperModules() instead");
  1110. if(!isset($user)){
  1111. $modules = array();
  1112. return $modules;
  1113. }
  1114. return($user->getDeveloperModules());
  1115. }
  1116. function get_workflow_admin_modules_for_user($user){
  1117. if (isset($_SESSION['get_workflow_admin_modules_for_user'])) {
  1118. return $_SESSION['get_workflow_admin_modules_for_user'];
  1119. }
  1120. global $moduleList;
  1121. $workflow_mod_list = array();
  1122. foreach($moduleList as $module){
  1123. $workflow_mod_list[$module] = $module;
  1124. }
  1125. // This list is taken from teh previous version of workflow_utils.php
  1126. $workflow_mod_list['Tasks'] = "Tasks";
  1127. $workflow_mod_list['Calls'] = "Calls";
  1128. $workflow_mod_list['Meetings'] = "Meetings";
  1129. $workflow_mod_list['Notes'] = "Notes";
  1130. $workflow_mod_list['ProjectTask'] = "Project Tasks";
  1131. $workflow_mod_list['Leads'] = "Leads";
  1132. $workflow_mod_list['Opportunities'] = "Opportunities";
  1133. // End of list
  1134. $workflow_admin_modules = array();
  1135. if(empty($user)) {
  1136. return $workflow_admin_modules;
  1137. }
  1138. $actions = ACLAction::getUserActions($user->id);
  1139. //check for ForecastSchedule because it doesn't exist in $workflow_mod_list
  1140. if (isset($actions['ForecastSchedule']['module']['admin']['aclaccess']) && ($actions['ForecastSchedule']['module']['admin']['aclaccess']==ACL_ALLOW_DEV ||
  1141. $actions['ForecastSchedule']['module']['admin']['aclaccess']==ACL_ALLOW_ADMIN_DEV)) {
  1142. $workflow_admin_modules['Forecasts'] = 'Forecasts';
  1143. }
  1144. foreach ($workflow_mod_list as $key=>$val) {
  1145. if(!in_array($val, $workflow_admin_modules) && ($val!='iFrames' && $val!='Feeds' && $val!='Home' && $val!='Dashboard'
  1146. && $val!='Calendar' && $val!='Activities' && $val!='Reports') &&
  1147. ($user->isDeveloperForModule($key))) {
  1148. $workflow_admin_modules[$key] = $val;
  1149. }
  1150. }
  1151. $_SESSION['get_workflow_admin_modules_for_user'] = $workflow_admin_modules;
  1152. return ($workflow_admin_modules);
  1153. }
  1154. // Check if user is admin for at least one module.
  1155. function is_admin_for_any_module($user) {
  1156. if (!isset($user)){
  1157. return false;
  1158. }
  1159. if($user->isAdmin()) {
  1160. return true;
  1161. }
  1162. return false;
  1163. }
  1164. // Check if user is admin for a specific module.
  1165. function is_admin_for_module($user,$module) {
  1166. if (!isset($user)) {
  1167. return false;
  1168. }
  1169. if ($user->isAdmin()) {
  1170. return true;
  1171. }
  1172. return false;
  1173. }
  1174. /**
  1175. * Check if user id belongs to a system admin.
  1176. * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
  1177. * All Rights Reserved.
  1178. * Contributor(s): ______________________________________..
  1179. */
  1180. function is_admin($user) {
  1181. if(empty($user)) {
  1182. return false;
  1183. }
  1184. return $user->isAdmin();
  1185. }
  1186. /**
  1187. * Return the display name for a theme if it exists.
  1188. * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
  1189. * All Rights Reserved.
  1190. * Contributor(s): ______________________________________..
  1191. *
  1192. * @deprecated use SugarThemeRegistry::get($theme)->name instead
  1193. */
  1194. function get_theme_display($theme)
  1195. {
  1196. return SugarThemeRegistry::get($theme)->name;
  1197. }
  1198. /**
  1199. * Return an array of directory names.
  1200. * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
  1201. * All Rights Reserved.
  1202. * Contributor(s): ______________________________________..
  1203. *
  1204. * @deprecated use SugarThemeRegistry::availableThemes() instead.
  1205. */
  1206. function get_themes()
  1207. {
  1208. return SugarThemeRegistry::availableThemes();
  1209. }
  1210. /**
  1211. * THIS FUNCTION IS DEPRECATED AND SHOULD NOT BE USED; USE get_select_options_with_id()
  1212. * Create HTML to display select options in a dropdown list. To be used inside
  1213. * of a select statement in a form.
  1214. * param $option_list - the array of strings to that contains the option list
  1215. * param $selected - the string which contains the default value
  1216. * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
  1217. * All Rights Reserved.
  1218. * Contributor(s): ______________________________________..
  1219. */
  1220. function get_select_options ($option_list, $selected) {
  1221. return get_select_options_with_id($option_list, $selected);
  1222. }
  1223. /**
  1224. * Create HTML to display select options in a dropdown list. To be used inside
  1225. * of a select statement in a form. This method expects the option list to have keys and values. The keys are the ids. The values are the display strings.
  1226. * param $option_list - the array of strings to that contains the option list
  1227. * param $selected - the string which contains the default value
  1228. * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
  1229. * All Rights Reserved.
  1230. * Contributor(s): ______________________________________..
  1231. */
  1232. function get_select_options_with_id ($option_list, $selected_key) {
  1233. return get_select_options_with_id_separate_key($option_list, $option_list, $selected_key);
  1234. }
  1235. /**
  1236. * Create HTML to display select options in a dropdown list. To be used inside
  1237. * of a select statement in a form. This method expects the option list to have keys and values. The keys are the ids. The values are the display strings.
  1238. * param $label_list - the array of strings to that contains the option list
  1239. * param $key_list - the array of strings to that contains the values list
  1240. * param $selected - the string which contains the default value
  1241. * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
  1242. * All Rights Reserved.
  1243. * Contributor(s): ______________________________________..
  1244. */
  1245. function get_select_options_with_id_separate_key ($label_list, $key_list, $selected_key, $massupdate=false) {
  1246. global $app_strings;
  1247. $select_options = "";
  1248. //for setting null selection values to human readable --None--
  1249. $pattern = "/'0?'></";
  1250. $replacement = "''>".$app_strings['LBL_NONE']."<";
  1251. if (empty($key_list)) $key_list = array();
  1252. //create the type dropdown domain and set the selected value if $opp value already exists
  1253. foreach ($key_list as $option_key=>$option_value) {
  1254. $selected_string = '';
  1255. // the system is evaluating $selected_key == 0 || '' to true. Be very careful when changing this. Test all cases.
  1256. // The bug was only happening with one of the users in the drop down. It was being replaced by none.
  1257. if (($option_key != '' && $selected_key == $option_key) || ($selected_key == '' && $option_key == '' && !$massupdate) || (is_array($selected_key) && in_array($option_key, $selected_key)))
  1258. {
  1259. $selected_string = 'selected ';
  1260. }
  1261. $html_value = $option_key;
  1262. $select_options .= "\n<OP…

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