PageRenderTime 67ms CodeModel.GetById 25ms RepoModel.GetById 1ms app.codeStats 1ms

/include/utils.php

https://github.com/nerdystudmuffin/dashlet-subpanels
PHP | 4311 lines | 3516 code | 444 blank | 351 comment | 279 complexity | e92a0ef36a5ca6eb88da8674370551ee MD5 | raw file
Possible License(s): LGPL-2.1, MPL-2.0-no-copyleft-exception

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

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