PageRenderTime 71ms CodeModel.GetById 31ms RepoModel.GetById 0ms app.codeStats 1ms

/include/utils.php

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

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