PageRenderTime 63ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/include/utils.php

https://github.com/vincentamari/SuperSweetAdmin
PHP | 4192 lines | 3577 code | 251 blank | 364 comment | 295 complexity | 1e9d2e6845f607b9386c0f95d3fad748 MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, AGPL-3.0, LGPL-2.1

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

  1. <?php
  2. /*********************************************************************************
  3. * SugarCRM 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 = (isset($sugar_config['use_real_names']) && $sugar_config['use_real_names'] == true) ? true : false;
  598. $userPref = (is_object($current_user)) ? $current_user->getPreference('use_real_names') : null;
  599. if($userPref != null) {
  600. $bool = ($userPref == 'on') ? true : false;
  601. $showFullName = $bool;
  602. } else {
  603. $showFullName = $sysPref;
  604. }
  605. }
  606. return $showFullName;
  607. }
  608. function clean($string, $maxLength)
  609. {
  610. $string = substr($string, 0, $maxLength);
  611. return escapeshellcmd($string);
  612. }
  613. /**
  614. * Copy the specified request variable to the member variable of the specified object.
  615. * Do no copy if the member variable is already set.
  616. * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
  617. * All Rights Reserved.
  618. * Contributor(s): ______________________________________..
  619. */
  620. function safe_map($request_var, & $focus, $always_copy = false)
  621. {
  622. safe_map_named($request_var, $focus, $request_var, $always_copy);
  623. }
  624. /**
  625. * Copy the specified request variable to the member variable of the specified object.
  626. * Do no copy if the member variable is already set.
  627. * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
  628. * All Rights Reserved.
  629. * Contributor(s): ______________________________________..
  630. */
  631. function safe_map_named($request_var, & $focus, $member_var, $always_copy)
  632. {
  633. if (isset($_REQUEST[$request_var]) && ($always_copy || is_null($focus->$member_var))) {
  634. $GLOBALS['log']->debug("safe map named called assigning '{$_REQUEST[$request_var]}' to $member_var");
  635. $focus->$member_var = $_REQUEST[$request_var];
  636. }
  637. }
  638. /**
  639. * This function retrieves an application language file and returns the array of strings included in the $app_list_strings var.
  640. *
  641. * @param string $language specific language to load
  642. * @return array lang strings
  643. */
  644. function return_app_list_strings_language($language)
  645. {
  646. global $app_list_strings;
  647. global $sugar_config;
  648. $cache_key = 'app_list_strings.'.$language;
  649. // Check for cached value
  650. $cache_entry = sugar_cache_retrieve($cache_key);
  651. if(!empty($cache_entry))
  652. {
  653. return $cache_entry;
  654. }
  655. $default_language = $sugar_config['default_language'];
  656. $temp_app_list_strings = $app_list_strings;
  657. $langs = array();
  658. if ($language != 'en_us') {
  659. $langs[] = 'en_us';
  660. }
  661. if ($default_language != 'en_us' && $language != $default_language) {
  662. $langs[] = $default_language;
  663. }
  664. $langs[] = $language;
  665. $app_list_strings_array = array();
  666. foreach ( $langs as $lang ) {
  667. $app_list_strings = array();
  668. if(file_exists("include/language/$lang.lang.php")) {
  669. include("include/language/$lang.lang.php");
  670. $GLOBALS['log']->info("Found language file: $lang.lang.php");
  671. }
  672. if(file_exists("include/language/$lang.lang.override.php")) {
  673. include("include/language/$lang.lang.override.php");
  674. $GLOBALS['log']->info("Found override language file: $lang.lang.override.php");
  675. }
  676. if(file_exists("include/language/$lang.lang.php.override")) {
  677. include("include/language/$lang.lang.php.override");
  678. $GLOBALS['log']->info("Found override language file: $lang.lang.php.override");
  679. }
  680. $app_list_strings_array[] = $app_list_strings;
  681. }
  682. $app_list_strings = array();
  683. foreach ( $app_list_strings_array as $app_list_strings_item ) {
  684. $app_list_strings = sugarArrayMerge($app_list_strings, $app_list_strings_item);
  685. }
  686. foreach ( $langs as $lang ) {
  687. if(file_exists("custom/application/Ext/Language/$lang.lang.ext.php")) {
  688. $app_list_strings = _mergeCustomAppListStrings("custom/application/Ext/Language/$lang.lang.ext.php" , $app_list_strings);
  689. $GLOBALS['log']->info("Found extended language file: $lang.lang.ext.php");
  690. }
  691. if(file_exists("custom/include/language/$lang.lang.php")) {
  692. include("custom/include/language/$lang.lang.php");
  693. $GLOBALS['log']->info("Found custom language file: $lang.lang.php");
  694. }
  695. }
  696. if(!isset($app_list_strings)) {
  697. $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");
  698. return null;
  699. }
  700. $return_value = $app_list_strings;
  701. $app_list_strings = $temp_app_list_strings;
  702. sugar_cache_put($cache_key, $return_value);
  703. return $return_value;
  704. }
  705. /**
  706. * The dropdown items in custom language files is $app_list_strings['$key']['$second_key'] = $value not
  707. * $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.
  708. * @param file string the language that you want include,
  709. * @param app_list_strings array the golbal strings
  710. * @return array
  711. */
  712. //jchi 25347
  713. function _mergeCustomAppListStrings($file , $app_list_strings){
  714. $app_list_strings_original = $app_list_strings;
  715. unset($app_list_strings);
  716. include($file);
  717. if(!isset($app_list_strings) || !is_array($app_list_strings)){
  718. return $app_list_strings_original;
  719. }
  720. //Bug 25347: We should not merge custom dropdown fields unless they relate to parent fields or the module list.
  721. foreach($app_list_strings as $key=>$value)
  722. {
  723. $exemptDropdowns = array("moduleList", "parent_type_display", "record_type_display", "record_type_display_notes");
  724. if (!in_array($key, $exemptDropdowns) && array_key_exists($key, $app_list_strings_original))
  725. {
  726. unset($app_list_strings_original["$key"]);
  727. }
  728. }
  729. $app_list_strings = sugarArrayMergeRecursive($app_list_strings_original , $app_list_strings);
  730. return $app_list_strings;
  731. }
  732. /**
  733. * This function retrieves an application language file and returns the array of strings included.
  734. *
  735. * @param string $language specific language to load
  736. * @return array lang strings
  737. */
  738. function return_application_language($language)
  739. {
  740. global $app_strings, $sugar_config;
  741. $cache_key = 'app_strings.'.$language;
  742. // Check for cached value
  743. $cache_entry = sugar_cache_retrieve($cache_key);
  744. if(!empty($cache_entry))
  745. {
  746. return $cache_entry;
  747. }
  748. $temp_app_strings = $app_strings;
  749. $default_language = $sugar_config['default_language'];
  750. $langs = array();
  751. if ($language != 'en_us') {
  752. $langs[] = 'en_us';
  753. }
  754. if ($default_language != 'en_us' && $language != $default_language) {
  755. $langs[] = $default_language;
  756. }
  757. $langs[] = $language;
  758. $app_strings_array = array();
  759. foreach ( $langs as $lang ) {
  760. $app_strings = array();
  761. if(file_exists("include/language/$lang.lang.php")) {
  762. include("include/language/$lang.lang.php");
  763. $GLOBALS['log']->info("Found language file: $lang.lang.php");
  764. }
  765. if(file_exists("include/language/$lang.lang.override.php")) {
  766. include("include/language/$lang.lang.override.php");
  767. $GLOBALS['log']->info("Found override language file: $lang.lang.override.php");
  768. }
  769. if(file_exists("include/language/$lang.lang.php.override")) {
  770. include("include/language/$lang.lang.php.override");
  771. $GLOBALS['log']->info("Found override language file: $lang.lang.php.override");
  772. }
  773. if(file_exists("custom/application/Ext/Language/$lang.lang.ext.php")) {
  774. include("custom/application/Ext/Language/$lang.lang.ext.php");
  775. $GLOBALS['log']->info("Found extended language file: $lang.lang.ext.php");
  776. }
  777. if(file_exists("custom/include/language/$lang.lang.php")) {
  778. include("custom/include/language/$lang.lang.php");
  779. $GLOBALS['log']->info("Found custom language file: $lang.lang.php");
  780. }
  781. $app_strings_array[] = $app_strings;
  782. }
  783. $app_strings = array();
  784. foreach ( $app_strings_array as $app_strings_item ) {
  785. $app_strings = sugarArrayMerge($app_strings, $app_strings_item);
  786. }
  787. if(!isset($app_strings)) {
  788. $GLOBALS['log']->fatal("Unable to load the application language strings");
  789. return null;
  790. }
  791. // If we are in debug mode for translating, turn on the prefix now!
  792. if($sugar_config['translation_string_prefix']) {
  793. foreach($app_strings as $entry_key=>$entry_value) {
  794. $app_strings[$entry_key] = $language.' '.$entry_value;
  795. }
  796. }
  797. if(isset($_SESSION['show_deleted'])) {
  798. $app_strings['LBL_DELETE_BUTTON'] = $app_strings['LBL_UNDELETE_BUTTON'];
  799. $app_strings['LBL_DELETE_BUTTON_LABEL'] = $app_strings['LBL_UNDELETE_BUTTON_LABEL'];
  800. $app_strings['LBL_DELETE_BUTTON_TITLE'] = $app_strings['LBL_UNDELETE_BUTTON_TITLE'];
  801. $app_strings['LBL_DELETE'] = $app_strings['LBL_UNDELETE'];
  802. }
  803. $app_strings['LBL_ALT_HOT_KEY'] = get_alt_hot_key();
  804. $return_value = $app_strings;
  805. $app_strings = $temp_app_strings;
  806. sugar_cache_put($cache_key, $return_value);
  807. return $return_value;
  808. }
  809. /**
  810. * This function retrieves a module's language file and returns the array of strings included.
  811. *
  812. * @param string $language specific language to load
  813. * @param string $module module name to load strings for
  814. * @param bool $refresh optional, true if you want to rebuild the language strings
  815. * @return array lang strings
  816. */
  817. function return_module_language($language, $module, $refresh=false)
  818. {
  819. global $mod_strings;
  820. global $sugar_config;
  821. global $currentModule;
  822. // Jenny - Bug 8119: Need to check if $module is not empty
  823. if (empty($module)) {
  824. $stack = debug_backtrace();
  825. $GLOBALS['log']->warn("Variable module is not in return_module_language ". var_export($stack, true));
  826. return array();
  827. }
  828. $cache_key = "mod_strings_lang.".$language.$module;
  829. // Check for cached value
  830. $cache_entry = sugar_cache_retrieve($cache_key);
  831. if(!empty($cache_entry))
  832. {
  833. return $cache_entry;
  834. }
  835. // Store the current mod strings for later
  836. $temp_mod_strings = $mod_strings;
  837. $loaded_mod_strings = array();
  838. $language_used = $language;
  839. $default_language = $sugar_config['default_language'];
  840. if(empty($language)) {
  841. $language = $default_language;
  842. }
  843. // Bug 21559 - So we can get all the strings defined in the template, refresh
  844. // the vardefs file if the cached language file doesn't exist.
  845. if(!file_exists($GLOBALS['sugar_config']['cache_dir'].'modules/'. $module . '/language/'.$language.'.lang.php')
  846. && !empty($GLOBALS['beanList'][$module])){
  847. $object = $GLOBALS['beanList'][$module];
  848. if ($object == 'aCase') {
  849. $object = 'Case';
  850. }
  851. VardefManager::refreshVardefs($module,$object);
  852. }
  853. $loaded_mod_strings = LanguageManager::loadModuleLanguage($module, $language,$refresh);
  854. // cn: bug 6048 - merge en_us with requested language
  855. if($language != $sugar_config['default_language'])
  856. $loaded_mod_strings = sugarArrayMerge(
  857. LanguageManager::loadModuleLanguage($module, $sugar_config['default_language'],$refresh),
  858. $loaded_mod_strings
  859. );
  860. // Load in en_us strings by default
  861. if($language != 'en_us' && $sugar_config['default_language'] != 'en_us')
  862. $loaded_mod_strings = sugarArrayMerge(
  863. LanguageManager::loadModuleLanguage($module, 'en_us', $refresh),
  864. $loaded_mod_strings
  865. );
  866. // If we are in debug mode for translating, turn on the prefix now!
  867. if($sugar_config['translation_string_prefix']) {
  868. foreach($loaded_mod_strings as $entry_key=>$entry_value) {
  869. $loaded_mod_strings[$entry_key] = $language_used.' '.$entry_value;
  870. }
  871. }
  872. $return_value = $loaded_mod_strings;
  873. if(!isset($mod_strings)){
  874. $mod_strings = $return_value;
  875. }
  876. else
  877. $mod_strings = $temp_mod_strings;
  878. sugar_cache_put($cache_key, $return_value);
  879. return $return_value;
  880. }
  881. /** This function retrieves an application language file and returns the array of strings included in the $mod_list_strings var.
  882. * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
  883. * All Rights Reserved.
  884. * Contributor(s): ______________________________________..
  885. * If you are using the current language, do not call this function unless you are loading it for the first time */
  886. function return_mod_list_strings_language($language,$module) {
  887. global $mod_list_strings;
  888. global $sugar_config;
  889. global $currentModule;
  890. $cache_key = "mod_list_str_lang.".$language.$module;
  891. // Check for cached value
  892. $cache_entry = sugar_cache_retrieve($cache_key);
  893. if(!empty($cache_entry))
  894. {
  895. return $cache_entry;
  896. }
  897. $language_used = $language;
  898. $temp_mod_list_strings = $mod_list_strings;
  899. $default_language = $sugar_config['default_language'];
  900. if($currentModule == $module && isset($mod_list_strings) && $mod_list_strings != null) {
  901. return $mod_list_strings;
  902. }
  903. // cn: bug 6351 - include en_us if file langpack not available
  904. // cn: bug 6048 - merge en_us with requested language
  905. include("modules/$module/language/en_us.lang.php");
  906. $en_mod_list_strings = array();
  907. if($language_used != $default_language)
  908. $en_mod_list_strings = $mod_list_strings;
  909. if(file_exists("modules/$module/language/$language.lang.php")) {
  910. include("modules/$module/language/$language.lang.php");
  911. }
  912. if(file_exists("modules/$module/language/$language.lang.override.php")){
  913. include("modules/$module/language/$language.lang.override.php");
  914. }
  915. if(file_exists("modules/$module/language/$language.lang.php.override")){
  916. echo 'Please Change:<br>' . "modules/$module/language/$language.lang.php.override" . '<br>to<br>' . 'Please Change:<br>' . "modules/$module/language/$language.lang.override.php";
  917. include("modules/$module/language/$language.lang.php.override");
  918. }
  919. // cn: bug 6048 - merge en_us with requested language
  920. $mod_list_strings = sugarArrayMerge($en_mod_list_strings, $mod_list_strings);
  921. // if we still don't have a language pack, then log an error
  922. if(!isset($mod_list_strings)) {
  923. $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})");
  924. return null;
  925. }
  926. $return_value = $mod_list_strings;
  927. $mod_list_strings = $temp_mod_list_strings;
  928. sugar_cache_put($cache_key, $return_value);
  929. return $return_value;
  930. }
  931. /** This function retrieves a theme's language file and returns the array of strings included.
  932. * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
  933. * All Rights Reserved.
  934. * Contributor(s): ______________________________________..
  935. */
  936. function return_theme_language($language, $theme)
  937. {
  938. global $mod_strings, $sugar_config, $currentModule;
  939. $language_used = $language;
  940. $default_language = $sugar_config['default_language'];
  941. include(SugarThemeRegistry::get($theme)->getFilePath()."/language/$current_language.lang.php");
  942. if(file_exists(SugarThemeRegistry::get($theme)->getFilePath()."/language/$current_language.lang.override.php")){
  943. include(SugarThemeRegistry::get($theme)->getFilePath()."/language/$current_language.lang.override.php");
  944. }
  945. if(file_exists(SugarThemeRegistry::get($theme)->getFilePath()."/language/$current_language.lang.php.override")){
  946. 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";
  947. include(SugarThemeRegistry::get($theme)->getFilePath()."/language/$current_language.lang.php.override");
  948. }
  949. if(!isset($theme_strings))
  950. {
  951. $GLOBALS['log']->warn("Unable to find the theme file for language: ".$language." and theme: ".$theme);
  952. require(SugarThemeRegistry::get($theme)->getFilePath()."/language/$default_language.lang.php");
  953. $language_used = $default_language;
  954. }
  955. if(!isset($theme_strings))
  956. {
  957. $GLOBALS['log']->fatal("Unable to load the theme($theme) language file for the selected language($language) or the default language($default_language)");
  958. return null;
  959. }
  960. // If we are in debug mode for translating, turn on the prefix now!
  961. if($sugar_config['translation_string_prefix'])
  962. {
  963. foreach($theme_strings as $entry_key=>$entry_value)
  964. {
  965. $theme_strings[$entry_key] = $language_used.' '.$entry_value;
  966. }
  967. }
  968. return $theme_strings;
  969. }
  970. /** If the session variable is defined and is not equal to "" then return it. Otherwise, return the default value.
  971. * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
  972. * All Rights Reserved.
  973. * Contributor(s): ______________________________________..
  974. */
  975. function return_session_value_or_default($varname, $default)
  976. {
  977. if(isset($_SESSION[$varname]) && $_SESSION[$varname] != "")
  978. {
  979. return $_SESSION[$varname];
  980. }
  981. return $default;
  982. }
  983. /**
  984. * Creates an array of where restrictions. These are used to construct a where SQL statement on the query
  985. * 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.
  986. * @param &$where_clauses - The array to append the clause to
  987. * @param $variable_name - The name of the variable to look for an add to the where clause if found
  988. * @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.
  989. * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
  990. * All Rights Reserved.
  991. * Contributor(s): ______________________________________..
  992. */
  993. function append_where_clause(&$where_clauses, $variable_name, $SQL_name = null)
  994. {
  995. if($SQL_name == null)
  996. {
  997. $SQL_name = $variable_name;
  998. }
  999. if(isset($_REQUEST[$variable_name]) && $_REQUEST[$variable_name] != "")
  1000. {
  1001. array_push($where_clauses, "$SQL_name like '".$GLOBALS['db']->quote($_REQUEST[$variable_name])."%'");
  1002. }
  1003. }
  1004. /**
  1005. * Generate the appropriate SQL based on the where clauses.
  1006. * @param $where_clauses - An Array of individual where clauses stored as strings
  1007. * @returns string where_clause - The final SQL where clause to be executed.
  1008. * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
  1009. * All Rights Reserved.
  1010. * Contributor(s): ______________________________________..
  1011. */
  1012. function generate_where_statement($where_clauses)
  1013. {
  1014. $where = "";
  1015. foreach($where_clauses as $clause)
  1016. {
  1017. if($where != "")
  1018. $where .= " and ";
  1019. $where .= $clause;
  1020. }
  1021. $GLOBALS['log']->info("Here is the where clause for the list view: $where");
  1022. return $where;
  1023. }
  1024. /**
  1025. * determines if a passed string matches the criteria for a Sugar GUID
  1026. * @param string $guid
  1027. * @return bool False on failure
  1028. */
  1029. function is_guid($guid) {
  1030. if(strlen($guid) != 36) {
  1031. return false;
  1032. }
  1033. if(preg_match("/\w{8}-\w{4}-\w{4}-\w{4}-\w{12}/i", $guid)) {
  1034. return true;
  1035. }
  1036. return true;;
  1037. }
  1038. /**
  1039. * A temporary method of generating GUIDs of the correct format for our DB.
  1040. * @return String contianing a GUID in the format: aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee
  1041. *
  1042. * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
  1043. * All Rights Reserved.
  1044. * Contributor(s): ______________________________________..
  1045. */
  1046. function create_guid()
  1047. {
  1048. $microTime = microtime();
  1049. list($a_dec, $a_sec) = explode(" ", $microTime);
  1050. $dec_hex = dechex($a_dec* 1000000);
  1051. $sec_hex = dechex($a_sec);
  1052. ensure_length($dec_hex, 5);
  1053. ensure_length($sec_hex, 6);
  1054. $guid = "";
  1055. $guid .= $dec_hex;
  1056. $guid .= create_guid_section(3);
  1057. $guid .= '-';
  1058. $guid .= create_guid_section(4);
  1059. $guid .= '-';
  1060. $guid .= create_guid_section(4);
  1061. $guid .= '-';
  1062. $guid .= create_guid_section(4);
  1063. $guid .= '-';
  1064. $guid .= $sec_hex;
  1065. $guid .= create_guid_section(6);
  1066. return $guid;
  1067. }
  1068. function create_guid_section($characters)
  1069. {
  1070. $return = "";
  1071. for($i=0; $i<$characters; $i++)
  1072. {
  1073. $return .= dechex(mt_rand(0,15));
  1074. }
  1075. return $return;
  1076. }
  1077. function ensure_length(&$string, $length)
  1078. {
  1079. $strlen = strlen($string);
  1080. if($strlen < $length)
  1081. {
  1082. $string = str_pad($string,$length,"0");
  1083. }
  1084. else if($strlen > $length)
  1085. {
  1086. $string = substr($string, 0, $length);
  1087. }
  1088. }
  1089. function microtime_diff($a, $b) {
  1090. list($a_dec, $a_sec) = explode(" ", $a);
  1091. list($b_dec, $b_sec) = explode(" ", $b);
  1092. return $b_sec - $a_sec + $b_dec - $a_dec;
  1093. }
  1094. // check if Studio is displayed.
  1095. function displayStudioForCurrentUser()
  1096. {
  1097. if ( is_admin($GLOBALS['current_user']) ) {
  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. global $beanList;
  1110. $admin_modules = array();
  1111. return ($admin_modules);
  1112. }
  1113. function get_workflow_admin_modules_for_user($user){
  1114. if (isset($_SESSION['get_workflow_admin_modules_for_user'])) {
  1115. return $_SESSION['get_workflow_admin_modules_for_user'];
  1116. }
  1117. global $moduleList;
  1118. $workflow_mod_list = array();
  1119. foreach($moduleList as $module){
  1120. $workflow_mod_list[$module] = $module;
  1121. }
  1122. // This list is taken from teh previous version of workflow_utils.php
  1123. $workflow_mod_list['Tasks'] = "Tasks";
  1124. $workflow_mod_list['Calls'] = "Calls";
  1125. $workflow_mod_list['Meetings'] = "Meetings";
  1126. $workflow_mod_list['Notes'] = "Notes";
  1127. $workflow_mod_list['ProjectTask'] = "Project Tasks";
  1128. $workflow_mod_list['Leads'] = "Leads";
  1129. $workflow_mod_list['Opportunities'] = "Opportunities";
  1130. // End of list
  1131. $workflow_admin_modules = array();
  1132. if(empty($user)) {
  1133. return $workflow_admin_modules;
  1134. }
  1135. $actions = ACLAction::getUserActions($user->id);
  1136. //check for ForecastSchedule because it doesn't exist in $workflow_mod_list
  1137. if (isset($actions['ForecastSchedule']['module']['admin']['aclaccess']) && ($actions['ForecastSchedule']['module']['admin']['aclaccess']==ACL_ALLOW_DEV ||
  1138. $actions['ForecastSchedule']['module']['admin']['aclaccess']==ACL_ALLOW_ADMIN_DEV)) {
  1139. $workflow_admin_modules['Forecasts'] = 'Forecasts';
  1140. }
  1141. foreach ($workflow_mod_list as $key=>$val) {
  1142. if(!in_array($val, $workflow_admin_modules) && ($val!='iFrames' && $val!='Feeds' && $val!='Home' && $val!='Dashboard'
  1143. && $val!='Calendar' && $val!='Activities' && $val!='Reports') &&
  1144. (is_admin_for_module($user,$key))) {
  1145. $workflow_admin_modules[$key] = $val;
  1146. }
  1147. }
  1148. $_SESSION['get_workflow_admin_modules_for_user'] = $workflow_admin_modules;
  1149. return ($workflow_admin_modules);
  1150. }
  1151. // Check if user is admin for at least one module.
  1152. function is_admin_for_any_module($user) {
  1153. return false;
  1154. }
  1155. // Check if user is admin for a specific module.
  1156. function is_admin_for_module($user,$module) {
  1157. return false;
  1158. }
  1159. /**
  1160. * Check if user id belongs to a system admin.
  1161. * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
  1162. * All Rights Reserved.
  1163. * Contributor(s): ______________________________________..
  1164. */
  1165. function is_admin($user) {
  1166. if(!empty($user) && ($user->is_admin == '1' || $user->is_admin === 'on')){
  1167. return true;
  1168. }
  1169. return false;
  1170. }
  1171. /**
  1172. * Return the display name for a theme if it exists.
  1173. * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
  1174. * All Rights Reserved.
  1175. * Contributor(s): ______________________________________..
  1176. *
  1177. * @deprecated use SugarThemeRegistry::get($theme)->name instead
  1178. */
  1179. function get_theme_display($theme)
  1180. {
  1181. return SugarThemeRegistry::get($theme)->name;
  1182. }
  1183. /**
  1184. * Return an array of directory names.
  1185. * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
  1186. * All Rights Reserved.
  1187. * Contributor(s): ______________________________________..
  1188. *
  1189. * @deprecated use SugarThemeRegistry::availableThemes() instead.
  1190. */
  1191. function get_themes()
  1192. {
  1193. return SugarThemeRegistry::availableThemes();
  1194. }
  1195. /**
  1196. * THIS FUNCTION IS DEPRECATED AND SHOULD NOT BE USED; USE get_select_options_with_id()
  1197. * Create HTML to display select options in a dropdown list. To be used inside
  1198. * of a select statement in a form.
  1199. * param $option_list - the array of strings to that contains the option list
  1200. * param $selected - the string which contains the default value
  1201. * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
  1202. * All Rights Reserved.
  1203. * Contributor(s): ______________________________________..
  1204. */
  1205. function get_select_options ($option_list, $selected) {
  1206. return get_select_options_with_id($option_list, $selected);
  1207. }
  1208. /**
  1209. * Create HTML to display select options in a dropdown list. To be used inside
  1210. * 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.
  1211. * param $option_list - the array of strings to that contains the option list
  1212. * param $selected - the string which contains the default value
  1213. * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
  1214. * All Rights Reserved.
  1215. * Contributor(s): ______________________________________..
  1216. */
  1217. function get_select_options_with_id ($option_list, $selected_key) {
  1218. return get_select_options_with_id_separate_key($option_list, $option_list, $selected_key);
  1219. }
  1220. /**
  1221. * Create HTML to display select options in a dropdown list. To be used inside
  1222. * 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.
  1223. * param $label_list - the array of strings to that contains the option list
  1224. * param $key_list - the array of strings to that contains the values list
  1225. * param $selected - the string which contains the default value
  1226. * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
  1227. * All Rights Reserved.
  1228. * Contributor(s): ______________________________________..
  1229. */
  1230. function get_select_options_with_id_separate_key ($label_list, $key_list, $selected_key, $massupdate=false) {
  1231. global $app_strings;
  1232. $select_options = "";
  1233. //for setting null selection values to human readable --None--
  1234. $pattern = "/'0?'></";
  1235. $replacement = "''>".$app_strings['LBL_NONE']."<";
  1236. if (empty($key_list)) $key_list = array();
  1237. //create the type dropdown domain and set the selected value if $opp value already exists
  1238. foreach ($key_list as $option_key=>$option_value) {
  1239. $selected_string = '';
  1240. // the system is evaluating $selected_key == 0 || '' to true. Be very careful when changing this. Test all cases.
  1241. // The bug was only happening with one of the users in the drop down. It was being replaced by none.
  1242. if (($option_key != '' && $selected_key == $option_key) || ($selected_key == '' && $option_key == '' && !$massupdate) || (is_array($selected_key) && in_array($option_key, $selected_key)))
  1243. {
  1244. $selected_string = 'selected ';
  1245. }
  1246. $html_value = $option_key;
  1247. $select_options .= "\n<OPTION ".$selected_string."value='$html_value'>$label_list[$option_key]</OPTION>";
  1248. }
  1249. $select_options = preg_replace($pattern, $replacement, $select_options);
  1250. return $select_options;
  1251. }
  1252. /**
  1253. * Call this method instead of die().
  1254. * Then we call the die method with the error message that is passed in.
  1255. */
  1256. function sugar_die($error_message)
  1257. {
  1258. global

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