PageRenderTime 12ms CodeModel.GetById 21ms app.highlight 32ms RepoModel.GetById 7ms app.codeStats 2ms

/include/utils.php

https://github.com/AUTOPLANNING/SuiteCRM
PHP | 5365 lines | 3664 code | 616 blank | 1085 comment | 793 complexity | a66930d1e9f4fbcefc534aa3d1972608 MD5 | raw file

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

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