PageRenderTime 50ms CodeModel.GetById 30ms RepoModel.GetById 0ms app.codeStats 1ms

/SugarCE-6.5.4/SugarCE-Full-6.5.4/include/utils.php

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

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