/include/utils.php
https://github.com/AUTOPLANNING/SuiteCRM · PHP · 5365 lines · 3578 code · 649 blank · 1138 comment · 822 complexity · a66930d1e9f4fbcefc534aa3d1972608 MD5 · raw file
Large files are truncated click here to view the full file
- <?php
- /*
- *
- * SugarCRM Community Edition is a customer relationship management program developed by
- * SugarCRM, Inc. Copyright (C) 2004-2013 SugarCRM Inc.
- *
- * SuiteCRM is an extension to SugarCRM Community Edition developed by SalesAgility Ltd.
- * Copyright (C) 2011 - 2016 SalesAgility Ltd.
- *
- * This program is free software; you can redistribute it and/or modify it under
- * the terms of the GNU Affero General Public License version 3 as published by the
- * Free Software Foundation with the addition of the following permission added
- * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
- * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
- * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
- * details.
- *
- * You should have received a copy of the GNU Affero General Public License along with
- * this program; if not, see http://www.gnu.org/licenses or write to the Free
- * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- *
- * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
- * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
- *
- * The interactive user interfaces in modified source and object code versions
- * of this program must display Appropriate Legal Notices, as required under
- * Section 5 of the GNU Affero General Public License version 3.
- *
- * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
- * these Appropriate Legal Notices must retain the display of the "Powered by
- * SugarCRM" logo and "Supercharged by SuiteCRM" logo. If the display of the logos is not
- * reasonably feasible for technical reasons, the Appropriate Legal Notices must
- * display the words "Powered by SugarCRM" and "Supercharged by SuiteCRM".
- */
- /*********************************************************************************
- * Description: Includes generic helper functions used throughout the application.
- * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
- * All Rights Reserved.
- * Contributor(s): ______________________________________..
- ********************************************************************************/
- require_once 'include/SugarObjects/SugarConfig.php';
- require_once 'include/utils/security_utils.php';
- function make_sugar_config(&$sugar_config)
- {
- /* used to convert non-array config.php file to array format */
- global $admin_export_only;
- global $cache_dir;
- global $calculate_response_time;
- global $create_default_user;
- global $dateFormats;
- global $dbconfig;
- global $dbconfigoption;
- global $default_action;
- global $default_charset;
- global $default_currency_name;
- global $default_currency_symbol;
- global $default_currency_iso4217;
- global $defaultDateFormat;
- global $default_language;
- global $default_module;
- global $default_password;
- global $default_theme;
- global $defaultTimeFormat;
- global $default_user_is_admin;
- global $default_user_name;
- global $disable_export;
- global $disable_persistent_connections;
- global $display_email_template_variable_chooser;
- global $display_inbound_email_buttons;
- global $history_max_viewed;
- global $host_name;
- global $import_dir;
- global $languages;
- global $list_max_entries_per_page;
- global $lock_default_user_name;
- global $log_memory_usage;
- global $nameFormats;
- global $requireAccounts;
- global $RSS_CACHE_TIME;
- global $session_dir;
- global $site_URL;
- global $site_url;
- global $sugar_version;
- global $timeFormats;
- global $tmp_dir;
- global $translation_string_prefix;
- global $unique_key;
- global $upload_badext;
- global $upload_dir;
- global $upload_maxsize;
- global $import_max_execution_time;
- global $list_max_entries_per_subpanel;
- global $passwordsetting;
- // assumes the following variables must be set:
- // $dbconfig, $dbconfigoption, $cache_dir, $session_dir, $site_URL, $upload_dir
- $sugar_config = array(
- 'admin_export_only' => empty($admin_export_only) ? false : $admin_export_only,
- 'export_delimiter' => empty($export_delimiter) ? ',' : $export_delimiter,
- 'cache_dir' => empty($cache_dir) ? 'cache/' : $cache_dir,
- 'calculate_response_time' => empty($calculate_response_time) ? true : $calculate_response_time,
- 'create_default_user' => empty($create_default_user) ? false : $create_default_user,
- 'chartEngine' => 'Jit',
- 'date_formats' => empty($dateFormats) ? array(
- 'Y-m-d' => '2010-12-23',
- 'd-m-Y' => '23-12-2010',
- 'm-d-Y' => '12-23-2010',
- 'Y/m/d' => '2010/12/23',
- 'd/m/Y' => '23/12/2010',
- 'm/d/Y' => '12/23/2010',
- 'Y.m.d' => '2010.12.23',
- 'd.m.Y' => '23.12.2010',
- 'm.d.Y' => '12.23.2010',
- ) : $dateFormats,
- 'dbconfig' => $dbconfig, // this must be set!!
- 'dbconfigoption' => $dbconfigoption, // this must be set!!
- 'default_action' => empty($default_action) ? 'index' : $default_action,
- 'default_charset' => empty($default_charset) ? 'UTF-8' : $default_charset,
- 'default_currency_name' => empty($default_currency_name) ? 'US Dollar' : $default_currency_name,
- 'default_currency_symbol' => empty($default_currency_symbol) ? '$' : $default_currency_symbol,
- 'default_currency_iso4217' => empty($default_currency_iso4217) ? '$' : $default_currency_iso4217,
- 'default_date_format' => empty($defaultDateFormat) ? 'm/d/Y' : $defaultDateFormat,
- 'default_locale_name_format' => empty($defaultNameFormat) ? 's f l' : $defaultNameFormat,
- 'default_export_charset' => 'UTF-8',
- 'default_language' => empty($default_language) ? 'en_us' : $default_language,
- 'default_module' => empty($default_module) ? 'Home' : $default_module,
- 'default_password' => empty($default_password) ? '' : $default_password,
- 'default_permissions' => array(
- 'dir_mode' => 02770,
- 'file_mode' => 0755,
- 'chown' => '',
- 'chgrp' => '',
- ),
- 'default_theme' => empty($default_theme) ? 'Sugar5' : $default_theme,
- 'default_time_format' => empty($defaultTimeFormat) ? 'h:ia' : $defaultTimeFormat,
- 'default_user_is_admin' => empty($default_user_is_admin) ? false : $default_user_is_admin,
- 'default_user_name' => empty($default_user_name) ? '' : $default_user_name,
- 'disable_export' => empty($disable_export) ? false : $disable_export,
- 'disable_persistent_connections' => empty($disable_persistent_connections) ? false : $disable_persistent_connections,
- 'display_email_template_variable_chooser' => empty($display_email_template_variable_chooser) ? false : $display_email_template_variable_chooser,
- 'display_inbound_email_buttons' => empty($display_inbound_email_buttons) ? false : $display_inbound_email_buttons,
- 'history_max_viewed' => empty($history_max_viewed) ? 50 : $history_max_viewed,
- 'host_name' => empty($host_name) ? 'localhost' : $host_name,
- 'import_dir' => $import_dir, // this must be set!!
- 'import_max_records_per_file' => 100,
- 'import_max_records_total_limit' => '',
- 'languages' => empty($languages) ? array('en_us' => 'English (US)') : $languages,
- 'list_max_entries_per_page' => empty($list_max_entries_per_page) ? 20 : $list_max_entries_per_page,
- 'list_max_entries_per_subpanel' => empty($list_max_entries_per_subpanel) ? 10 : $list_max_entries_per_subpanel,
- 'lock_default_user_name' => empty($lock_default_user_name) ? false : $lock_default_user_name,
- 'log_memory_usage' => empty($log_memory_usage) ? false : $log_memory_usage,
- 'name_formats' => empty($nameFormats) ? array(
- 's f l' => 's f l', 'f l' => 'f l', 's l' => 's l', 'l, s f' => 'l, s f',
- 'l, f' => 'l, f', 's l, f' => 's l, f', 'l s f' => 'l s f', 'l f s' => 'l f s',
- ) : $nameFormats,
- 'portal_view' => 'single_user',
- 'resource_management' => array(
- 'special_query_limit' => 50000,
- 'special_query_modules' => array('Reports', 'Export', 'Import', 'Administration', 'Sync'),
- 'default_limit' => 1000,
- ),
- 'require_accounts' => empty($requireAccounts) ? true : $requireAccounts,
- 'rss_cache_time' => empty($RSS_CACHE_TIME) ? '10800' : $RSS_CACHE_TIME,
- 'session_dir' => $session_dir, // this must be set!!
- 'site_url' => empty($site_URL) ? $site_url : $site_URL, // this must be set!!
- 'showDetailData' => true, // if true, read-only ACL fields will still appear on EditViews as non-editable
- 'showThemePicker' => true,
- 'sugar_version' => empty($sugar_version) ? 'unknown' : $sugar_version,
- 'time_formats' => empty($timeFormats) ? array(
- 'H:i' => '23:00', 'h:ia' => '11:00 pm', 'h:iA' => '11:00PM',
- 'H.i' => '23.00', 'h.ia' => '11.00 pm', 'h.iA' => '11.00PM', ) : $timeFormats,
- 'tmp_dir' => $tmp_dir, // this must be set!!
- 'translation_string_prefix' => empty($translation_string_prefix) ? false : $translation_string_prefix,
- 'unique_key' => empty($unique_key) ? md5(create_guid()) : $unique_key,
- 'upload_badext' => empty($upload_badext) ? array(
- 'php', 'php3', 'php4', 'php5', 'pl', 'cgi', 'py',
- 'asp', 'cfm', 'js', 'vbs', 'html', 'htm', ) : $upload_badext,
- 'upload_dir' => $upload_dir, // this must be set!!
- 'upload_maxsize' => empty($upload_maxsize) ? 30000000 : $upload_maxsize,
- 'import_max_execution_time' => empty($import_max_execution_time) ? 3600 : $import_max_execution_time,
- 'lock_homepage' => false,
- 'lock_subpanels' => false,
- 'max_dashlets_homepage' => 15,
- 'dashlet_display_row_options' => array('1', '3', '5', '10'),
- 'default_max_tabs' => empty($max_tabs) ? '7' : $max_tabs,
- 'default_subpanel_tabs' => empty($subpanel_tabs) ? true : $subpanel_tabs,
- 'default_subpanel_links' => empty($subpanel_links) ? false : $subpanel_links,
- 'default_swap_last_viewed' => empty($swap_last_viewed) ? false : $swap_last_viewed,
- 'default_swap_shortcuts' => empty($swap_shortcuts) ? false : $swap_shortcuts,
- 'default_navigation_paradigm' => empty($navigation_paradigm) ? 'gm' : $navigation_paradigm,
- 'default_call_status' => 'Planned',
- 'js_lang_version' => 1,
- 'passwordsetting' => empty($passwordsetting) ? array(
- 'SystemGeneratedPasswordON' => '',
- 'generatepasswordtmpl' => '',
- 'lostpasswordtmpl' => '',
- 'forgotpasswordON' => true,
- 'linkexpiration' => '1',
- 'linkexpirationtime' => '30',
- 'linkexpirationtype' => '1',
- 'systexpiration' => '0',
- 'systexpirationtime' => '',
- 'systexpirationtype' => '0',
- 'systexpirationlogin' => '',
- ) : $passwordsetting,
- 'use_sprites' => function_exists('imagecreatetruecolor'),
- 'search_wildcard_infront' => false,
- 'search_wildcard_char' => '%',
- 'jobs' => array(
- 'min_retry_interval' => 60, // minimal job retry delay
- 'max_retries' => 5, // how many times to retry the job
- 'timeout' => 86400, // how long a job may spend as running before being force-failed
- 'soft_lifetime' => 7, // how many days until job record will be soft deleted after completion
- 'hard_lifetime' => 21, // how many days until job record will be purged from DB
- ),
- 'cron' => array(
- 'max_cron_jobs' => 10, // max jobs per cron schedule run
- 'max_cron_runtime' => 60, // max runtime for cron jobs
- 'min_cron_interval' => 30, // minimal interval between cron jobs
- ),
- );
- }
- function get_sugar_config_defaults()
- {
- global $locale;
- /*
- * used for getting base values for array style config.php. used by the
- * installer and to fill in new entries on upgrades. see also:
- * sugar_config_union
- */
- $sugar_config_defaults = array(
- 'admin_export_only' => false,
- 'export_delimiter' => ',',
- 'export_excel_compatible' => false,
- 'cache_dir' => 'cache/',
- 'calculate_response_time' => true,
- 'create_default_user' => false,
- 'chartEngine' => 'Jit',
- 'date_formats' => array(
- 'Y-m-d' => '2010-12-23', 'm-d-Y' => '12-23-2010', 'd-m-Y' => '23-12-2010',
- 'Y/m/d' => '2010/12/23', 'm/d/Y' => '12/23/2010', 'd/m/Y' => '23/12/2010',
- 'Y.m.d' => '2010.12.23', 'd.m.Y' => '23.12.2010', 'm.d.Y' => '12.23.2010', ),
- 'name_formats' => array(
- 's f l' => 's f l', 'f l' => 'f l', 's l' => 's l', 'l, s f' => 'l, s f',
- 'l, f' => 'l, f', 's l, f' => 's l, f', 'l s f' => 'l s f', 'l f s' => 'l f s',
- ),
- 'dbconfigoption' => array(
- 'persistent' => true,
- 'autofree' => false,
- 'debug' => 0,
- 'ssl' => false, ),
- 'default_action' => 'index',
- 'default_charset' => return_session_value_or_default('default_charset',
- 'UTF-8'),
- 'default_currency_name' => return_session_value_or_default('default_currency_name', 'US Dollar'),
- 'default_currency_symbol' => return_session_value_or_default('default_currency_symbol', '$'),
- 'default_currency_iso4217' => return_session_value_or_default('default_currency_iso4217', 'USD'),
- 'default_currency_significant_digits' => return_session_value_or_default('default_currency_significant_digits', 2),
- 'default_number_grouping_seperator' => return_session_value_or_default('default_number_grouping_seperator', ','),
- 'default_decimal_seperator' => return_session_value_or_default('default_decimal_seperator', '.'),
- 'default_date_format' => 'm/d/Y',
- 'default_locale_name_format' => 's f l',
- 'default_export_charset' => 'UTF-8',
- 'default_language' => return_session_value_or_default('default_language',
- 'en_us'),
- 'default_module' => 'Home',
- 'default_password' => '',
- 'default_permissions' => array(
- 'dir_mode' => 02770,
- 'file_mode' => 0755,
- 'user' => '',
- 'group' => '',
- ),
- 'default_theme' => return_session_value_or_default('site_default_theme', 'Sugar5'),
- 'default_time_format' => 'h:ia',
- 'default_user_is_admin' => false,
- 'default_user_name' => '',
- 'disable_export' => false,
- 'disable_persistent_connections' => return_session_value_or_default('disable_persistent_connections',
- 'false'),
- 'display_email_template_variable_chooser' => false,
- 'display_inbound_email_buttons' => false,
- 'dump_slow_queries' => false,
- 'email_address_separator' => ',', // use RFC2368 spec unless we have a noncompliant email client
- 'email_default_editor' => 'html',
- 'email_default_client' => 'sugar',
- 'email_default_delete_attachments' => true,
- 'history_max_viewed' => 50,
- 'installer_locked' => true,
- 'import_max_records_per_file' => 100,
- 'import_max_records_total_limit' => '',
- 'languages' => array('en_us' => 'English (US)'),
- 'large_scale_test' => false,
- 'list_max_entries_per_page' => 20,
- 'list_max_entries_per_subpanel' => 10,
- 'lock_default_user_name' => false,
- 'log_memory_usage' => false,
- 'portal_view' => 'single_user',
- 'resource_management' => array(
- 'special_query_limit' => 50000,
- 'special_query_modules' => array('Reports', 'Export', 'Import', 'Administration', 'Sync'),
- 'default_limit' => 1000,
- ),
- 'require_accounts' => true,
- 'rss_cache_time' => return_session_value_or_default('rss_cache_time',
- '10800'),
- 'save_query' => 'all',
- 'showDetailData' => true, // if true, read-only ACL fields will still appear on EditViews as non-editable
- 'showThemePicker' => true,
- 'slow_query_time_msec' => '100',
- 'sugarbeet' => true,
- 'time_formats' => array(
- 'H:i' => '23:00', 'h:ia' => '11:00pm', 'h:iA' => '11:00PM', 'h:i a' => '11:00 pm', 'h:i A' => '11:00 PM',
- 'H.i' => '23.00', 'h.ia' => '11.00pm', 'h.iA' => '11.00PM', 'h.i a' => '11.00 pm', 'h.i A' => '11.00 PM', ),
- 'tracker_max_display_length' => 15,
- 'translation_string_prefix' => return_session_value_or_default('translation_string_prefix', false),
- 'upload_badext' => array(
- 'php', 'php3', 'php4', 'php5', 'pl', 'cgi', 'py',
- 'asp', 'cfm', 'js', 'vbs', 'html', 'htm', 'phtml', ),
- 'upload_maxsize' => 30000000,
- 'import_max_execution_time' => 3600,
- // 'use_php_code_json' => returnPhpJsonStatus(),
- 'verify_client_ip' => true,
- 'js_custom_version' => '',
- 'js_lang_version' => 1,
- 'lead_conv_activity_opt' => 'donothing',
- 'lock_homepage' => false,
- 'lock_subpanels' => false,
- 'max_dashlets_homepage' => '15',
- 'default_max_tabs' => '7',
- 'dashlet_display_row_options' => array('1', '3', '5', '10'),
- 'default_subpanel_tabs' => true,
- 'default_subpanel_links' => false,
- 'default_swap_last_viewed' => false,
- 'default_swap_shortcuts' => false,
- 'default_navigation_paradigm' => 'gm',
- 'admin_access_control' => false,
- 'use_common_ml_dir' => false,
- 'common_ml_dir' => '',
- 'vcal_time' => '2',
- 'calendar' => array(
- 'default_view' => 'week',
- 'show_calls_by_default' => true,
- 'show_tasks_by_default' => true,
- 'show_completed_by_default' => true,
- 'editview_width' => 990,
- 'editview_height' => 485,
- 'day_timestep' => 15,
- 'week_timestep' => 30,
- 'items_draggable' => true,
- 'items_resizable' => true,
- 'enable_repeat' => true,
- 'max_repeat_count' => 1000,
- ),
- 'passwordsetting' => empty($passwordsetting) ? array(
- 'SystemGeneratedPasswordON' => '',
- 'generatepasswordtmpl' => '',
- 'lostpasswordtmpl' => '',
- 'forgotpasswordON' => false,
- 'linkexpiration' => '1',
- 'linkexpirationtime' => '30',
- 'linkexpirationtype' => '1',
- 'systexpiration' => '0',
- 'systexpirationtime' => '',
- 'systexpirationtype' => '0',
- 'systexpirationlogin' => '',
- ) : $passwordsetting,
- 'use_real_names' => true,
- 'search_wildcard_infront' => false,
- 'search_wildcard_char' => '%',
- 'jobs' => array(
- 'min_retry_interval' => 30, // 30 seconds minimal job retry
- 'max_retries' => 5, // how many times to retry the job
- 'timeout' => 86400, // how long a job may spend as running before being force-failed
- ),
- 'cron' => array(
- 'max_cron_jobs' => 10, // max jobs per cron schedule run
- 'max_cron_runtime' => 30, // max runtime for cron jobs
- 'min_cron_interval' => 30, // minimal interval between cron jobs
- ),
- );
- if (!is_object($locale)) {
- $locale = new Localization();
- }
- $sugar_config_defaults['default_currencies'] = $locale->getDefaultCurrencies();
- $sugar_config_defaults = sugarArrayMerge($locale->getLocaleConfigDefaults(), $sugar_config_defaults);
- return $sugar_config_defaults;
- }
- /**
- * @deprecated use SugarView::getMenu() instead
- */
- function load_menu($path)
- {
- global $module_menu;
- if (file_exists($path.'Menu.php')) {
- require $path.'Menu.php';
- }
- if (file_exists('custom/'.$path.'Ext/Menus/menu.ext.php')) {
- require 'custom/'.$path.'Ext/Menus/menu.ext.php';
- }
- if (file_exists('custom/application/Ext/Menus/menu.ext.php')) {
- require 'custom/application/Ext/Menus/menu.ext.php';
- }
- return $module_menu;
- }
- /**
- * get_notify_template_file
- * This function will return the location of the email notifications template to use.
- *
- * @return string relative file path to email notifications template file
- */
- function get_notify_template_file($language)
- {
- /*
- * Order of operation:
- * 1) custom version of specified language
- * 2) stock version of specified language
- * 3) custom version of en_us template
- * 4) stock en_us template
- */
- // set $file to the base code template so it's set if none of the conditions pass
- $file = 'include/language/en_us.notify_template.html';
- if (file_exists("custom/include/language/{$language}.notify_template.html")) {
- $file = "custom/include/language/{$language}.notify_template.html";
- } elseif (file_exists("include/language/{$language}.notify_template.html")) {
- $file = "include/language/{$language}.notify_template.html";
- } elseif (file_exists('custom/include/language/en_us.notify_template.html')) {
- $file = 'custom/include/language/en_us.notify_template.html';
- }
- return $file;
- }
- function sugar_config_union($default, $override)
- {
- // a little different then array_merge and array_merge_recursive. we want
- // the second array to override the first array if the same value exists,
- // otherwise merge the unique keys. it handles arrays of arrays recursively
- // might be suitable for a generic array_union
- if (!is_array($override)) {
- $override = array();
- }
- foreach ($default as $key => $value) {
- if (!array_key_exists($key, $override)) {
- $override[$key] = $value;
- } elseif (is_array($key)) {
- $override[$key] = sugar_config_union($value, $override[$key]);
- }
- }
- return $override;
- }
- function make_not_writable($file)
- {
- // Returns true if the given file/dir has been made not writable
- $ret_val = false;
- if (is_file($file) || is_dir($file)) {
- if (!is_writable($file)) {
- $ret_val = true;
- } else {
- $original_fileperms = fileperms($file);
- // take away writable permissions
- $new_fileperms = $original_fileperms & ~0x0092;
- @sugar_chmod($file, $new_fileperms);
- if (!is_writable($file)) {
- $ret_val = true;
- }
- }
- }
- return $ret_val;
- }
- /** This function returns the name of the person.
- * It currently returns "first last". It should not put the space if either name is not available.
- * It should not return errors if either name is not available.
- * If no names are present, it will return ""
- * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
- * All Rights Reserved.
- * Contributor(s): ______________________________________..
- */
- function return_name($row, $first_column, $last_column)
- {
- $first_name = '';
- $last_name = '';
- $full_name = '';
- if (isset($row[$first_column])) {
- $first_name = stripslashes($row[$first_column]);
- }
- if (isset($row[$last_column])) {
- $last_name = stripslashes($row[$last_column]);
- }
- $full_name = $first_name;
- // If we have a first name and we have a last name
- if ($full_name != '' && $last_name != '') {
- // append a space, then the last name
- $full_name .= ' '.$last_name;
- } // If we have no first name, but we have a last name
- elseif ($last_name != '') {
- // append the last name without the space.
- $full_name .= $last_name;
- }
- return $full_name;
- }
- function get_languages()
- {
- global $sugar_config;
- $lang = $sugar_config['languages'];
- if (!empty($sugar_config['disabled_languages'])) {
- foreach (explode(',', $sugar_config['disabled_languages']) as $disable) {
- unset($lang[$disable]);
- }
- }
- return $lang;
- }
- function get_all_languages()
- {
- global $sugar_config;
- return $sugar_config['languages'];
- }
- function get_language_display($key)
- {
- global $sugar_config;
- return $sugar_config['languages'][$key];
- }
- function get_assigned_user_name($assigned_user_id, $is_group = '')
- {
- static $saved_user_list = null;
- if (empty($saved_user_list)) {
- $saved_user_list = get_user_array(false, '', '', false, null, $is_group);
- }
- if (isset($saved_user_list[$assigned_user_id])) {
- return $saved_user_list[$assigned_user_id];
- }
- return '';
- }
- /**
- * retrieves the user_name column value (login).
- *
- * @param string id GUID of user
- *
- * @return string
- */
- function get_user_name($id)
- {
- global $db;
- if (empty($db)) {
- $db = DBManagerFactory::getInstance();
- }
- $q = "SELECT user_name FROM users WHERE id='{$id}'";
- $r = $db->query($q);
- $a = $db->fetchByAssoc($r);
- return (empty($a)) ? '' : $a['user_name'];
- }
- //TODO Update to use global cache
- /**
- * get_user_array.
- *
- * This is a helper function to return an Array of users depending on the parameters passed into the function.
- * This function uses the get_register_value function by default to use a caching layer where supported.
- * This function has been updated return the array sorted by user preference of name display (bug 62712)
- *
- * @param bool $add_blank Boolean value to add a blank entry to the array results, true by default
- * @param string $status String value indicating the status to filter users by, "Active" by default
- * @param string $user_id String value to specify a particular user id value (searches the id column of users table), blank by default
- * @param bool $use_real_name Boolean value indicating whether or not results should include the full name or just user_name, false by default
- * @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
- * @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
- * @param bool $from_cache Boolean value indicating whether or not to use the get_register_value function for caching, true by default
- *
- * @return array Array of users matching the filter criteria that may be from cache (if similar search was previously run)
- */
- 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)
- {
- global $locale, $sugar_config, $current_user;
- if (empty($locale)) {
- $locale = new Localization();
- }
- if ($from_cache) {
- $key_name = $add_blank.$status.$user_id.$use_real_name.$user_name_filter.$portal_filter;
- $user_array = get_register_value('user_array', $key_name);
- }
- if (empty($user_array)) {
- $db = DBManagerFactory::getInstance();
- $temp_result = array();
- // Including deleted users for now.
- if (empty($status)) {
- $query = 'SELECT id, first_name, last_name, user_name FROM users WHERE 1=1'.$portal_filter;
- } else {
- $query = "SELECT id, first_name, last_name, user_name from users WHERE status='$status'".$portal_filter;
- }
- /* BEGIN - SECURITY GROUPS */
- global $current_user, $sugar_config;
- if (!is_admin($current_user)
- && isset($sugar_config['securitysuite_filter_user_list'])
- && $sugar_config['securitysuite_filter_user_list'] == true
- && (empty($_REQUEST['module']) || $_REQUEST['module'] != 'Home')
- && (empty($_REQUEST['action']) || $_REQUEST['action'] != 'DynamicAction')
- ) {
- require_once 'modules/SecurityGroups/SecurityGroup.php';
- global $current_user;
- $group_where = SecurityGroup::getGroupUsersWhere($current_user->id);
- $query .= ' AND ('.$group_where.') ';
- }
- /* END - SECURITY GROUPS */
- if (!empty($user_name_filter)) {
- $user_name_filter = $db->quote($user_name_filter);
- $query .= " AND user_name LIKE '$user_name_filter%' ";
- }
- if (!empty($user_id)) {
- $query .= " OR id='{$user_id}'";
- }
- //get the user preference for name formatting, to be used in order by
- $order_by_string = ' user_name ASC ';
- if (!empty($current_user) && !empty($current_user->id)) {
- $formatString = $current_user->getPreference('default_locale_name_format');
- //create the order by string based on position of first and last name in format string
- $order_by_string = ' user_name ASC ';
- $firstNamePos = strpos($formatString, 'f');
- $lastNamePos = strpos($formatString, 'l');
- if ($firstNamePos !== false || $lastNamePos !== false) {
- //its possible for first name to be skipped, check for this
- if ($firstNamePos === false) {
- $order_by_string = 'last_name ASC';
- } else {
- $order_by_string = ($lastNamePos < $firstNamePos) ? 'last_name, first_name ASC' : 'first_name, last_name ASC';
- }
- }
- }
- $query = $query.' ORDER BY '.$order_by_string;
- $GLOBALS['log']->debug("get_user_array query: $query");
- $result = $db->query($query, true, 'Error filling in user array: ');
- if ($add_blank == true) {
- // Add in a blank row
- $temp_result[''] = '';
- }
- // Get the id and the name.
- while ($row = $db->fetchByAssoc($result)) {
- if ($use_real_name == true || showFullName()) {
- if (isset($row['last_name'])) { // cn: we will ALWAYS have both first_name and last_name (empty value if blank in db)
- $temp_result[$row['id']] = $locale->getLocaleFormattedName($row['first_name'], $row['last_name']);
- } else {
- $temp_result[$row['id']] = $row['user_name'];
- }
- } else {
- $temp_result[$row['id']] = $row['user_name'];
- }
- }
- $user_array = $temp_result;
- if ($from_cache) {
- set_register_value('user_array', $key_name, $temp_result);
- }
- }
- return $user_array;
- }
- /**
- * uses a different query to return a list of users than get_user_array()
- * Used from QuickSearch.php.
- *
- * @param args string where clause entry
- *
- * @return array Array of Users' details that match passed criteria
- */
- function getUserArrayFromFullName($args, $hide_portal_users = false)
- {
- global $locale;
- $db = DBManagerFactory::getInstance();
- // jmorais@dri - Bug #51411
- //
- // Refactor the code responsible for parsing supplied $args, this way we
- // ensure that if $args has at least one space (after trim), the $inClause
- // will be composed by several clauses ($inClauses) inside parenthesis.
- //
- // Ensuring that operator precedence is respected, and avoiding
- // inactive/deleted users to be retrieved.
- //
- $args = trim($args);
- if (strpos($args, ' ')) {
- $inClauses = array();
- $argArray = explode(' ', $args);
- foreach ($argArray as $arg) {
- $arg = $db->quote($arg);
- $inClauses[] = "(first_name LIKE '{$arg}%' OR last_name LIKE '{$arg}%')";
- }
- $inClause = '('.implode('OR ', $inClauses).')';
- } else {
- $args = $db->quote($args);
- $inClause = "(first_name LIKE '{$args}%' OR last_name LIKE '{$args}%')";
- }
- // ~jmorais@dri
- $query = "SELECT id, first_name, last_name, user_name FROM users WHERE status='Active' AND deleted=0 AND ";
- if ($hide_portal_users) {
- $query .= ' portal_only=0 AND ';
- }
- $query .= $inClause;
- /* BEGIN - SECURITY GROUPS */
- global $current_user, $sugar_config;
- if (!is_admin($current_user)
- && isset($sugar_config['securitysuite_filter_user_list'])
- && $sugar_config['securitysuite_filter_user_list'] == true
- ) {
- require_once 'modules/SecurityGroups/SecurityGroup.php';
- global $current_user;
- $group_where = SecurityGroup::getGroupUsersWhere($current_user->id);
- $query .= ' AND ('.$group_where.') ';
- }
- /* END - SECURITY GROUPS */
- $query .= ' ORDER BY last_name ASC';
- $r = $db->query($query);
- $ret = array();
- while ($a = $db->fetchByAssoc($r)) {
- $ret[$a['id']] = $locale->getLocaleFormattedName($a['first_name'], $a['last_name']);
- }
- return $ret;
- }
- /**
- * based on user pref then system pref.
- */
- function showFullName()
- {
- global $sugar_config;
- global $current_user;
- static $showFullName = null;
- if (is_null($showFullName)) {
- $sysPref = !empty($sugar_config['use_real_names']);
- $userPref = (is_object($current_user)) ? $current_user->getPreference('use_real_names') : null;
- if ($userPref != null) {
- $showFullName = ($userPref == 'on');
- } else {
- $showFullName = $sysPref;
- }
- }
- return $showFullName;
- }
- function clean($string, $maxLength)
- {
- $string = substr($string, 0, $maxLength);
- return escapeshellcmd($string);
- }
- /**
- * Copy the specified request variable to the member variable of the specified object.
- * Do no copy if the member variable is already set.
- * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
- * All Rights Reserved.
- * Contributor(s): ______________________________________..
- */
- function safe_map($request_var, &$focus, $always_copy = false)
- {
- safe_map_named($request_var, $focus, $request_var, $always_copy);
- }
- /**
- * Copy the specified request variable to the member variable of the specified object.
- * Do no copy if the member variable is already set.
- * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
- * All Rights Reserved.
- * Contributor(s): ______________________________________..
- */
- function safe_map_named($request_var, &$focus, $member_var, $always_copy)
- {
- if (isset($_REQUEST[$request_var]) && ($always_copy || is_null($focus->$member_var))) {
- $GLOBALS['log']->debug("safe map named called assigning '{$_REQUEST[$request_var]}' to $member_var");
- $focus->$member_var = $_REQUEST[$request_var];
- }
- }
- /**
- * This function retrieves an application language file and returns the array of strings included in the $app_list_strings var.
- *
- * @param string $language specific language to load
- *
- * @return array lang strings
- */
- function return_app_list_strings_language($language)
- {
- global $app_list_strings;
- global $sugar_config;
- $cache_key = 'app_list_strings.'.$language;
- // Check for cached value
- $cache_entry = sugar_cache_retrieve($cache_key);
- if (!empty($cache_entry)) {
- return $cache_entry;
- }
- $default_language = isset($sugar_config['default_language']) ? $sugar_config['default_language'] : 'en_us';
- $temp_app_list_strings = $app_list_strings;
- $langs = array();
- if ($language != 'en_us') {
- $langs[] = 'en_us';
- }
- if ($default_language != 'en_us' && $language != $default_language) {
- $langs[] = $default_language;
- }
- $langs[] = $language;
- $app_list_strings_array = array();
- foreach ($langs as $lang) {
- $app_list_strings = array();
- if (file_exists("include/language/$lang.lang.php")) {
- include "include/language/$lang.lang.php";
- $GLOBALS['log']->info("Found language file: $lang.lang.php");
- }
- if (file_exists("include/language/$lang.lang.override.php")) {
- include "include/language/$lang.lang.override.php";
- $GLOBALS['log']->info("Found override language file: $lang.lang.override.php");
- }
- if (file_exists("include/language/$lang.lang.php.override")) {
- include "include/language/$lang.lang.php.override";
- $GLOBALS['log']->info("Found override language file: $lang.lang.php.override");
- }
- $app_list_strings_array[] = $app_list_strings;
- }
- $app_list_strings = array();
- foreach ($app_list_strings_array as $app_list_strings_item) {
- $app_list_strings = sugarLangArrayMerge($app_list_strings, $app_list_strings_item);
- }
- foreach ($langs as $lang) {
- if (file_exists("custom/application/Ext/Language/$lang.lang.ext.php")) {
- $app_list_strings = _mergeCustomAppListStrings("custom/application/Ext/Language/$lang.lang.ext.php", $app_list_strings);
- $GLOBALS['log']->info("Found extended language file: $lang.lang.ext.php");
- }
- if (file_exists("custom/include/language/$lang.lang.php")) {
- include "custom/include/language/$lang.lang.php";
- $GLOBALS['log']->info("Found custom language file: $lang.lang.php");
- }
- }
- if (!isset($app_list_strings)) {
- $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");
- return;
- }
- $return_value = $app_list_strings;
- $app_list_strings = $temp_app_list_strings;
- sugar_cache_put($cache_key, $return_value);
- return $return_value;
- }
- /**
- * The dropdown items in custom language files is $app_list_strings['$key']['$second_key'] = $value not
- * $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.
- *
- * @param file string the language that you want include,
- * @param app_list_strings array the golbal strings
- *
- * @return array
- */
- //jchi 25347
- function _mergeCustomAppListStrings($file, $app_list_strings)
- {
- $app_list_strings_original = $app_list_strings;
- unset($app_list_strings);
- // FG - bug 45525 - $exemptDropdown array is defined (once) here, not inside the foreach
- // This way, language file can add items to save specific standard codelist from being overwritten
- $exemptDropdowns = array();
- include $file;
- if (!isset($app_list_strings) || !is_array($app_list_strings)) {
- return $app_list_strings_original;
- }
- //Bug 25347: We should not merge custom dropdown fields unless they relate to parent fields or the module list.
- // FG - bug 45525 - Specific codelists must NOT be overwritten
- $exemptDropdowns[] = 'moduleList';
- $exemptDropdowns[] = 'moduleListSingular';
- $exemptDropdowns = array_merge($exemptDropdowns, getTypeDisplayList());
- foreach ($app_list_strings as $key => $value) {
- if (!in_array($key, $exemptDropdowns) && array_key_exists($key, $app_list_strings_original)) {
- unset($app_list_strings_original["$key"]);
- }
- }
- $app_list_strings = sugarArrayMergeRecursive($app_list_strings_original, $app_list_strings);
- return $app_list_strings;
- }
- /**
- * This function retrieves an application language file and returns the array of strings included.
- *
- * @param string $language specific language to load
- *
- * @return array lang strings
- */
- function return_application_language($language)
- {
- global $app_strings, $sugar_config;
- $cache_key = 'app_strings.'.$language;
- // Check for cached value
- $cache_entry = sugar_cache_retrieve($cache_key);
- if (!empty($cache_entry)) {
- return $cache_entry;
- }
- $temp_app_strings = $app_strings;
- $default_language = $sugar_config['default_language'];
- $langs = array();
- if ($language != 'en_us') {
- $langs[] = 'en_us';
- }
- if ($default_language != 'en_us' && $language != $default_language) {
- $langs[] = $default_language;
- }
- $langs[] = $language;
- $app_strings_array = array();
- foreach ($langs as $lang) {
- $app_strings = array();
- if (file_exists("include/language/$lang.lang.php")) {
- include "include/language/$lang.lang.php";
- $GLOBALS['log']->info("Found language file: $lang.lang.php");
- }
- if (file_exists("include/language/$lang.lang.override.php")) {
- include "include/language/$lang.lang.override.php";
- $GLOBALS['log']->info("Found override language file: $lang.lang.override.php");
- }
- if (file_exists("include/language/$lang.lang.php.override")) {
- include "include/language/$lang.lang.php.override";
- $GLOBALS['log']->info("Found override language file: $lang.lang.php.override");
- }
- if (file_exists("custom/application/Ext/Language/$lang.lang.ext.php")) {
- include "custom/application/Ext/Language/$lang.lang.ext.php";
- $GLOBALS['log']->info("Found extended language file: $lang.lang.ext.php");
- }
- if (file_exists("custom/include/language/$lang.lang.php")) {
- include "custom/include/language/$lang.lang.php";
- $GLOBALS['log']->info("Found custom language file: $lang.lang.php");
- }
- $app_strings_array[] = $app_strings;
- }
- $app_strings = array();
- foreach ($app_strings_array as $app_strings_item) {
- $app_strings = sugarLangArrayMerge($app_strings, $app_strings_item);
- }
- if (!isset($app_strings)) {
- $GLOBALS['log']->fatal('Unable to load the application language strings');
- return;
- }
- // If we are in debug mode for translating, turn on the prefix now!
- if (!empty($sugar_config['translation_string_prefix'])) {
- foreach ($app_strings as $entry_key => $entry_value) {
- $app_strings[$entry_key] = $language.' '.$entry_value;
- }
- }
- if (isset($_SESSION['show_deleted'])) {
- $app_strings['LBL_DELETE_BUTTON'] = $app_strings['LBL_UNDELETE_BUTTON'];
- $app_strings['LBL_DELETE_BUTTON_LABEL'] = $app_strings['LBL_UNDELETE_BUTTON_LABEL'];
- $app_strings['LBL_DELETE_BUTTON_TITLE'] = $app_strings['LBL_UNDELETE_BUTTON_TITLE'];
- $app_strings['LBL_DELETE'] = $app_strings['LBL_UNDELETE'];
- }
- $app_strings['LBL_ALT_HOT_KEY'] = get_alt_hot_key();
- $return_value = $app_strings;
- $app_strings = $temp_app_strings;
- sugar_cache_put($cache_key, $return_value);
- return $return_value;
- }
- /**
- * This function retrieves a module's language file and returns the array of strings included.
- *
- * @param string $language specific language to load
- * @param string $module module name to load strings for
- * @param bool $refresh optional, true if you want to rebuild the language strings
- *
- * @return array lang strings
- */
- function return_module_language($language, $module, $refresh = false)
- {
- global $mod_strings;
- global $sugar_config;
- global $currentModule;
- // Jenny - Bug 8119: Need to check if $module is not empty
- if (empty($module)) {
- $stack = debug_backtrace();
- $GLOBALS['log']->warn('Variable module is not in return_module_language '.var_export($stack, true));
- return array();
- }
- if (!$refresh) {
- $cache_key = LanguageManager::getLanguageCacheKey($module, $language);
- // Check for cached value
- $cache_entry = sugar_cache_retrieve($cache_key);
- if (!empty($cache_entry) && is_array($cache_entry)) {
- return $cache_entry;
- }
- }
- // Store the current mod strings for later
- $temp_mod_strings = $mod_strings;
- $loaded_mod_strings = array();
- $language_used = $language;
- $default_language = $sugar_config['default_language'];
- if (empty($language)) {
- $language = $default_language;
- }
- // Bug 21559 - So we can get all the strings defined in the template, refresh
- // the vardefs file if the cached language file doesn't exist.
- if (!file_exists(sugar_cached('modules/').$module.'/language/'.$language.'.lang.php')
- && !empty($GLOBALS['beanList'][$module])
- ) {
- $object = BeanFactory::getObjectName($module);
- VardefManager::refreshVardefs($module, $object);
- }
- $loaded_mod_strings = LanguageManager::loadModuleLanguage($module, $language, $refresh);
- // cn: bug 6048 - merge en_us with requested language
- if ($language != $sugar_config['default_language']) {
- $loaded_mod_strings = sugarLangArrayMerge(
- LanguageManager::loadModuleLanguage($module, $sugar_config['default_language'], $refresh),
- $loaded_mod_strings
- );
- }
- // Load in en_us strings by default
- if ($language != 'en_us' && $sugar_config['default_language'] != 'en_us') {
- $loaded_mod_strings = sugarLangArrayMerge(
- LanguageManager::loadModuleLanguage($module, 'en_us', $refresh),
- $loaded_mod_strings
- );
- }
- // If we are in debug mode for translating, turn on the prefix now!
- if ($sugar_config['translation_string_prefix']) {
- foreach ($loaded_mod_strings as $entry_key => $entry_value) {
- $loaded_mod_strings[$entry_key] = $language_used.' '.$entry_value;
- }
- }
- $return_value = $loaded_mod_strings;
- if (!isset($mod_strings)) {
- $mod_strings = $return_value;
- } else {
- $mod_strings = $temp_mod_strings;
- }
- $cache_key = LanguageManager::getLanguageCacheKey($module, $language);
- sugar_cache_put($cache_key, $return_value);
- return $return_value;
- }
- /** This function retrieves an application language file and returns the array of strings included in the $mod_list_strings var.
- * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
- * All Rights Reserved.
- * Contributor(s): ______________________________________..
- * If you are using the current language, do not call this function unless you are loading it for the first time */
- function return_mod_list_strings_language($language, $module)
- {
- global $mod_list_strings;
- global $sugar_config;
- global $currentModule;
- $cache_key = 'mod_list_str_lang.'.$language.$module;
- // Check for cached value
- $cache_entry = sugar_cache_retrieve($cache_key);
- if (!empty($cache_entry)) {
- return $cache_entry;
- }
- $language_used = $language;
- $temp_mod_list_strings = $mod_list_strings;
- $default_language = $sugar_config['default_language'];
- if ($currentModule == $module && isset($mod_list_strings) && $mod_list_strings != null) {
- return $mod_list_strings;
- }
- // cn: bug 6351 - include en_us if file langpack not available
- // cn: bug 6048 - merge en_us with requested language
- include "modules/$module/language/en_us.lang.php";
- $en_mod_list_strings = array();
- if ($language_used != $default_language) {
- $en_mod_list_strings = $mod_list_strings;
- }
- if (file_exists("modules/$module/language/$language.lang.php")) {
- include "modules/$module/language/$language.lang.php";
- }
- if (file_exists("modules/$module/language/$language.lang.override.php")) {
- include "modules/$module/language/$language.lang.override.php";
- }
- if (file_exists("modules/$module/language/$language.lang.php.override")) {
- echo 'Please Change:<br>'."modules/$module/language/$language.lang.php.override".'<br>to<br>'.'Please Change:<br>'."modules/$module/language/$language.lang.override.php";
- include "modules/$module/language/$language.lang.php.override";
- }
- // cn: bug 6048 - merge en_us with requested language
- $mod_list_strings = sugarLangArrayMerge($en_mod_list_strings, $mod_list_strings);
- // if we still don't have a language pack, then log an error
- if (!isset($mod_list_strings)) {
- $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})");
- return;
- }
- $return_value = $mod_list_strings;
- $mod_list_strings = $temp_mod_list_strings;
- sugar_cache_put($cache_key, $return_value);
- return $return_value;
- }
- /** This function retrieves a theme's language file and returns the array of strings included.
- * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
- * All Rights Reserved.
- * Contributor(s): ______________________________________..
- */
- function return_theme_language($language, $theme)
- {
- global $mod_strings, $sugar_config, $current_language;
- $language_used = $language;
- $default_language = $sugar_config['default_language'];
- include SugarThemeRegistry::get($theme)->getFilePath()."/language/$current_language.lang.php";
- if (file_exists(SugarThemeRegistry::get($theme)->getFilePath()."/language/$current_language.lang.override.php")) {
- include SugarThemeRegistry::get($theme)->getFilePath()."/language/$current_language.lang.override.php";
- }
- if (file_exists(SugarThemeRegistry::get($theme)->getFilePath()."/language/$current_language.lang.php.override")) {
- 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";
- include SugarThemeRegistry::get($theme)->getFilePath()."/language/$current_language.lang.php.override";
- }
- if (!isset($theme_strings)) {
- $GLOBALS['log']->warn('Unable to find the theme file for language: '.$language.' and theme: '.$theme);
- require SugarThemeRegistry::get($theme)->getFilePath()."/language/$default_language.lang.php";…