/include/utils.php

https://github.com/AUTOPLANNING/SuiteCRM · PHP · 5365 lines · 3578 code · 649 blank · 1138 comment · 822 complexity · a66930d1e9f4fbcefc534aa3d1972608 MD5 · raw file

Large files are truncated click here to view the full file

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