function LoadCachedArray($module_dir, $module, $key) { global $moduleDefs, $fileName; $cache_key = "load_cached_array.{$module_dir}.{$module}.{$key}"; $result = sugar_cache_retrieve($cache_key); if (!empty($result)) { // Use EXTERNAL_CACHE_NULL_VALUE to store null values in the cache. if ($result == EXTERNAL_CACHE_NULL_VALUE) { return null; } return $result; } if (file_exists('modules/' . $module_dir . '/' . $fileName)) { // If the data was not loaded, try loading again.... if (!isset($moduleDefs[$module])) { include 'modules/' . $module_dir . '/' . $fileName; $moduleDefs[$module] = $fields_array; } // Now that we have tried loading, make sure it was loaded if (empty($moduleDefs[$module]) || empty($moduleDefs[$module][$module][$key])) { // It was not loaded.... Fail. Cache null to prevent future repeats of this calculation sugar_cache_put($cache_key, EXTERNAL_CACHE_NULL_VALUE); return null; } // It has been loaded, cache the result. sugar_cache_put($cache_key, $moduleDefs[$module][$module][$key]); return $moduleDefs[$module][$module][$key]; } // It was not loaded.... Fail. Cache null to prevent future repeats of this calculation sugar_cache_put($cache_key, EXTERNAL_CACHE_NULL_VALUE); return null; }
/** * Load the view_<view>_config.php file which holds options used by the view. */ function _loadConfig(&$view, $type) { $view_config_custom = array(); $view_config_module = array(); $view_config_root_cstm = array(); $view_config_root = array(); $view_config_app = array(); $config_file_name = 'view.' . $type . '.config.php'; $view_config = sugar_cache_retrieve("VIEW_CONFIG_FILE_" . $view->module . "_TYPE_" . $type); if (!$view_config) { $view_config_all = array('actions' => array(), 'req_params' => array()); foreach (SugarAutoLoader::existingCustom('include/MVC/View/views/view.config.php', 'include/MVC/View/views/' . $config_file_name, 'modules/' . $view->module . '/views/' . $config_file_name) as $file) { $view_config = array(); require $file; if (!empty($view_config['actions'])) { $view_config_all['actions'] = array_merge($view_config_all['actions'], $view_config['actions']); } if (!empty($view_config['req_params'])) { $view_config_all['req_params'] = array_merge($view_config_all['req_params'], $view_config['req_params']); } } $view_config = $view_config_all; sugar_cache_put("VIEW_CONFIG_FILE_" . $view->module . "_TYPE_" . $type, $view_config); } $action = strtolower($view->action); $config = null; if (!empty($view_config['req_params'])) { //try the params first foreach ($view_config['req_params'] as $key => $value) { if (!empty($_REQUEST[$key]) && $_REQUEST[$key] == "false") { $_REQUEST[$key] = false; } if (!empty($_REQUEST[$key])) { if (!is_array($value['param_value'])) { if ($value['param_value'] == $_REQUEST[$key]) { $config = $value['config']; break; } } else { foreach ($value['param_value'] as $v) { if ($v == $_REQUEST[$key]) { $config = $value['config']; break; } } } } } } if ($config == null && !empty($view_config['actions']) && !empty($view_config['actions'][$action])) { $config = $view_config['actions'][$action]; } if ($config != null) { $view->options = $config; } }
function retrieveSettings($category = FALSE, $clean = false) { // declare a cache for all settings $settings_cache = sugar_cache_retrieve('admin_settings_cache'); if ($clean) { $settings_cache = array(); } // Check for a cache hit if (!empty($settings_cache)) { $this->settings = $settings_cache; if (!empty($this->settings[$category])) { return $this; } } if (!empty($category)) { $query = "SELECT category, name, value FROM {$this->table_name} WHERE category = '{$category}'"; } else { $query = "SELECT category, name, value FROM {$this->table_name}"; } $result = $this->db->query($query, true, "Unable to retrieve system settings"); if (empty($result)) { return NULL; } while ($row = $this->db->fetchByAssoc($result)) { if ($row['category'] . "_" . $row['name'] == 'ldap_admin_password' || $row['category'] . "_" . $row['name'] == 'proxy_password') { $this->settings[$row['category'] . "_" . $row['name']] = $this->decrypt_after_retrieve($row['value']); } else { $this->settings[$row['category'] . "_" . $row['name']] = $row['value']; } $this->settings[$row['category']] = true; } $this->settings[$category] = true; if (!isset($this->settings["mail_sendtype"])) { // outbound email settings $oe = new OutboundEmail(); $oe->getSystemMailerSettings(); foreach ($oe->field_defs as $def) { if (strpos($def, "mail_") !== false) { $this->settings[$def] = $oe->{$def}; } } } // At this point, we have built a new array that should be cached. sugar_cache_put('admin_settings_cache', $this->settings); return $this; }
/** * Checks cache for cached response else invoke api using makeRequest * @param $cacheKey String * @param $endPoint String * @param $requestType String possible values GET or POST * @return array */ private function dnbServiceRequest($cacheKey, $endPoint, $requestType) { $apiResponse = sugar_cache_retrieve($cacheKey); //obtain results from dnb service if cache does not contain result if (empty($apiResponse) || $apiResponse === SugarCache::EXTERNAL_CACHE_NULL_VALUE) { $this->logger->debug('Cache does not contain' . $cacheKey); $apiResponse = $this->makeRequest($requestType, $endPoint); if (!$apiResponse['success']) { $this->logger->error('D&B failed, reply said: ' . print_r($apiResponse, true)); return $apiResponse; } else { //cache the result if the dnb service response was a success sugar_cache_put($cacheKey, $apiResponse, $this->cacheTTL); $this->logger->debug('Cached ' . $cacheKey); } } else { $this->logger->debug('Getting cached results for ' . $cacheKey); } return $apiResponse; }
/** * Get user datetime format. * * @param User $user user object, current user if not specified * @return string */ public function get_date_time_format($user = null) { // BC fix - had (bool, user) signature before if (!$user instanceof User) { if (func_num_args() > 1) { $user = func_get_arg(1); if (!$user instanceof User) { $user = null; } } else { $user = null; } } $cacheKey = $this->get_date_time_format_cache_key($user); $cachedValue = sugar_cache_retrieve($cacheKey); if (!empty($cachedValue)) { return $cachedValue; } else { $value = $this->merge_date_time($this->get_date_format($user), $this->get_time_format($user)); sugar_cache_put($cacheKey, $value, 0); return $value; } }
function getMeetingsExternalApiDropDown($focus = null, $name = null, $value = null, $view = null) { global $dictionary, $app_list_strings; $cacheKeyName = 'meetings_type_drop_down'; $apiList = sugar_cache_retrieve($cacheKeyName); if ($apiList === null) { require_once 'include/externalAPI/ExternalAPIFactory.php'; $apiList = ExternalAPIFactory::getModuleDropDown('Meetings'); $apiList = array_merge(array('Sugar' => $GLOBALS['app_list_strings']['eapm_list']['Sugar']), $apiList); sugar_cache_put($cacheKeyName, $apiList); } if (!empty($value) && empty($apiList[$value])) { $apiList[$value] = $value; } //bug 46294: adding list of options to dropdown list (if it is not the default list) if ($dictionary['Meeting']['fields']['type']['options'] != "eapm_list") { $apiList = array_merge(getMeetingTypeOptions($dictionary, $app_list_strings), $apiList); } return $apiList; }
function get_register_value($category, $name) { return sugar_cache_retrieve("{$category}:{$name}"); }
/** * Retrieve CSS files in cache. This method actually does: * - Get file hashes from the cache. * - If file hashes are found verify that the file exists. * - If file hashes are not found try to retrieve some css files from the file system * * @return array Css files found in cache */ private function retrieveCssFilesInCache() { $filesInCache = array(); //First check if the file hashes are cached so we don't have to load the metadata manually to calculate it $hashKey = $this->paths['hashKey']; $hashArray = sugar_cache_retrieve($hashKey); if (is_array($hashArray) && count($hashArray) === count($this->lessFilesToCompile)) { foreach ($hashArray as $lessFile => $hash) { $file = $this->getCssFileLocation($lessFile, $hash); if (file_exists($file)) { $filesInCache[$lessFile] = $hash; } } } else { /** * Checks the filesystem for a generated css file * This is useful on systems without a php memory cache * or if the memory cache is filled */ $files = glob($this->paths['cache'] . '*.css', GLOB_NOSORT); foreach ($files as $file) { $nameParts = explode('_', pathinfo($file, PATHINFO_FILENAME)); $filesInCache[$nameParts[0]] = $nameParts[1]; } } return $filesInCache; }
/** * Saves the created strings * * Here, we cheat the system by storing our string overrides in the sugar_cache where * we normally stored the cached language strings. */ public function save() { $language = $GLOBALS['current_language']; if (isset($this->_strings['app_strings'])) { $cache_key = 'app_strings.' . $language; $app_strings = sugar_cache_retrieve($cache_key); if (empty($app_strings)) { $app_strings = return_application_language($language); } foreach ($this->_strings['app_strings'] as $key => $value) { $app_strings[$key] = $value; } sugar_cache_put($cache_key, $app_strings); $GLOBALS['app_strings'] = $app_strings; } if (isset($this->_strings['app_list_strings'])) { $cache_key = 'app_list_strings.' . $language; $app_list_strings = sugar_cache_retrieve($cache_key); if (empty($app_list_strings)) { $app_list_strings = return_app_list_strings_language($language); } foreach ($this->_strings['app_list_strings'] as $key => $value) { $app_list_strings[$key] = $value; } sugar_cache_put($cache_key, $app_list_strings); $GLOBALS['app_list_strings'] = $app_list_strings; } if (isset($this->_strings['mod_strings'])) { foreach ($this->_strings['mod_strings'] as $module => $strings) { $cache_key = LanguageManager::getLanguageCacheKey($module, $language); $mod_strings = sugar_cache_retrieve($cache_key); if (empty($mod_strings)) { $mod_strings = return_module_language($language, $module); } foreach ($strings as $key => $value) { $mod_strings[$key] = $value; } sugar_cache_put($cache_key, $mod_strings); $GLOBALS['mod_strings'] = $mod_strings; } } }
/** * Generic load method to load mapping arrays. */ private function loadMapping($var, $merge = false) { ${$var} = sugar_cache_retrieve("CONTROLLER_" . $var . "_" . $this->module); if (!${$var}) { if ($merge && !empty($this->{$var})) { ${$var} = $this->{$var}; } else { ${$var} = []; } if (file_exists($path = DOCROOT . "include/MVC/Controller/{$var}.php")) { require $path; } if (file_exists($path = DOCROOT . "modules/{$this->module}/{$var}'.php")) { require $path; } if (file_exists($path = DOCROOT . "custom/modules/{$this->module}/{$var}.php")) { require $path; } if (file_exists($path = DOCROOT . "custom/include/MVC/Controller/{$var}.php")) { require $path; } $varname = str_replace(" ", "", ucwords(str_replace("_", " ", $var))); if (file_exists($path = DOCROOT . "custom/application/Ext/{$varname}/{$var}.ext.php")) { require $path; } if (file_exists($path = DOCROOT . "custom/modules/{$this->module}/Ext/{$varname}/{$var}.ext.php")) { require $path; } sugar_cache_put("CONTROLLER_" . $var . "_" . $this->module, ${$var}); } $this->{$var} = ${$var}; }
/** * Generic load method to load mapping arrays. */ private function loadMapping($var, $merge = false) { ${$var} = sugar_cache_retrieve("CONTROLLER_" . $var . "_" . $this->module); if (!${$var}) { if ($merge && !empty($this->{$var})) { ${$var} = $this->{$var}; } else { ${$var} = array(); } if (file_exists('include/MVC/Controller/' . $var . '.php')) { require 'include/MVC/Controller/' . $var . '.php'; } if (file_exists('modules/' . $this->module . '/' . $var . '.php')) { require 'modules/' . $this->module . '/' . $var . '.php'; } if (file_exists('custom/modules/' . $this->module . '/' . $var . '.php')) { require 'custom/modules/' . $this->module . '/' . $var . '.php'; } if (file_exists('custom/include/MVC/Controller/' . $var . '.php')) { require 'custom/include/MVC/Controller/' . $var . '.php'; } // entry_point_registry -> EntryPointRegistry $varname = str_replace(" ", "", ucwords(str_replace("_", " ", $var))); if (file_exists("custom/application/Ext/{$varname}/{$var}.ext.php")) { require "custom/application/Ext/{$varname}/{$var}.ext.php"; } if (file_exists("custom/modules/{$this->module}/Ext/{$varname}/{$var}.ext.php")) { require "custom/modules/{$this->module}/Ext/{$varname}/{$var}.ext.php"; } sugar_cache_put("CONTROLLER_" . $var . "_" . $this->module, ${$var}); } $this->{$var} = ${$var}; }
/** * checkDatabaseVersion * Check the db version sugar_version.php and compare to what the version is stored in the config table. * Ensure that both are the same. */ function checkDatabaseVersion($dieOnFailure = true) { $row_count = sugar_cache_retrieve('checkDatabaseVersion_row_count'); if (empty($row_count)) { global $sugar_db_version; $version_query = 'SELECT count(*) as the_count FROM config WHERE category=\'info\' AND name=\'sugar_version\''; if ($GLOBALS['db']->dbType == 'oci8') { } else { if ($GLOBALS['db']->dbType == 'mssql') { $version_query .= " AND CAST(value AS varchar(8000)) = '{$sugar_db_version}'"; } else { $version_query .= " AND value = '{$sugar_db_version}'"; } } $result = $GLOBALS['db']->query($version_query); $row = $GLOBALS['db']->fetchByAssoc($result, -1, true); $row_count = $row['the_count']; sugar_cache_put('checkDatabaseVersion_row_count', $row_count); } if ($row_count == 0 && empty($GLOBALS['sugar_config']['disc_client'])) { $sugar_version = $GLOBALS['sugar_version']; if ($dieOnFailure) { sugar_die("Sugar CRM {$sugar_version} Files May Only Be Used With A Sugar CRM {$sugar_db_version} Database."); } else { return false; } } return true; }
static function getLinkTypes() { static $linkTypeList = null; // Fastest, already stored in the static variable if ($linkTypeList != null) { return $linkTypeList; } // Second fastest, stored in a cache somewhere $linkTypeList = sugar_cache_retrieve('SugarFeedLinkType'); if ($linkTypeList != null) { return $linkTypeList; } // Third fastest, already stored in a file if (file_exists($GLOBALS['sugar_config']['cache_dir'] . 'modules/SugarFeed/linkTypeCache.php')) { require_once $GLOBALS['sugar_config']['cache_dir'] . 'modules/SugarFeed/linkTypeCache.php'; sugar_cache_put('SugarFeedLinkType', $linkTypeList); return $linkTypeList; } // Slow, have to actually collect the data $baseDirs = array('custom/modules/SugarFeed/linkHandlers/', 'modules/SugarFeed/linkHandlers'); $linkTypeList = array(); foreach ($baseDirs as $dirName) { if (!file_exists($dirName)) { continue; } $d = dir($dirName); while ($file = $d->read()) { if ($file[0] == '.') { continue; } if (substr($file, -4) == '.php') { // We found one $typeName = substr($file, 0, -4); $linkTypeList[$typeName] = $typeName; } } } sugar_cache_put('SugarFeedLinkType', $linkTypeList); if (!file_exists($GLOBALS['sugar_config']['cache_dir'] . 'modules/SugarFeed')) { mkdir_recursive($GLOBALS['sugar_config']['cache_dir'] . 'modules/SugarFeed'); } $fd = fopen($GLOBALS['sugar_config']['cache_dir'] . 'modules/SugarFeed/linkTypeCache.php', 'w'); fwrite($fd, '<' . "?php\n\n" . '$linkTypeList = ' . var_export($linkTypeList, true) . ';'); fclose($fd); return $linkTypeList; }
/** * Displays the header on section of the page; basically everything before the content */ public function displayHeader() { global $theme; global $max_tabs; global $app_strings; global $current_user; global $sugar_config; global $app_list_strings; global $mod_strings; global $current_language; $GLOBALS['app']->headerDisplayed = true; $themeObject = SugarThemeRegistry::current(); $theme = $themeObject->__toString(); $ss = new Sugar_Smarty(); $ss->assign("APP", $app_strings); $ss->assign("THEME", $theme); $ss->assign("THEME_IE6COMPAT", $themeObject->ie6compat ? 'true' : 'false'); $ss->assign("MODULE_NAME", $this->module); // get browser title $ss->assign("SYSTEM_NAME", $this->getBrowserTitle()); // get css $css = $themeObject->getCSS(); if ($this->_getOption('view_print')) { $css .= '<link rel="stylesheet" type="text/css" href="' . $themeObject->getCSSURL('print.css') . '" media="all" />'; } $ss->assign("SUGAR_CSS", $css); // get javascript ob_start(); $this->renderJavascript(); $ss->assign("SUGAR_JS", ob_get_contents() . $themeObject->getJS()); ob_end_clean(); // get favicon if (isset($GLOBALS['sugar_config']['default_module_favicon'])) { $module_favicon = $GLOBALS['sugar_config']['default_module_favicon']; } else { $module_favicon = false; } $favicon = ''; if ($module_favicon) { $favicon = $themeObject->getImageURL($this->module . '.gif', false); } if (!sugar_is_file($favicon) || !$module_favicon) { $favicon = $themeObject->getImageURL('sugar_icon.ico', false); } $ss->assign('FAVICON_URL', getJSPath($favicon)); // build the shortcut menu $shortcut_menu = array(); foreach ($this->getMenu() as $key => $menu_item) { $shortcut_menu[$key] = array("URL" => $menu_item[0], "LABEL" => $menu_item[1], "MODULE_NAME" => $menu_item[2], "IMAGE" => $themeObject->getImage($menu_item[2], "alt='" . $menu_item[1] . "' border='0' align='absmiddle'")); } $ss->assign("SHORTCUT_MENU", $shortcut_menu); // handle rtl text direction if (isset($_REQUEST['RTL']) && $_REQUEST['RTL'] == 'RTL') { $_SESSION['RTL'] = true; } if (isset($_REQUEST['LTR']) && $_REQUEST['LTR'] == 'LTR') { unset($_SESSION['RTL']); } if (isset($_SESSION['RTL']) && $_SESSION['RTL']) { $ss->assign("DIR", 'dir="RTL"'); } // handle resizing of the company logo correctly on the fly $companyLogoURL = $themeObject->getImageURL('company_logo.png'); $companyLogoURL_arr = explode('?', $companyLogoURL); $companyLogoURL = $companyLogoURL_arr[0]; $company_logo_attributes = sugar_cache_retrieve('company_logo_attributes'); if (!empty($company_logo_attributes)) { $ss->assign("COMPANY_LOGO_MD5", $company_logo_attributes[0]); $ss->assign("COMPANY_LOGO_WIDTH", $company_logo_attributes[1]); $ss->assign("COMPANY_LOGO_HEIGHT", $company_logo_attributes[2]); } else { // Always need to md5 the file $ss->assign("COMPANY_LOGO_MD5", md5_file($companyLogoURL)); list($width, $height) = getimagesize($companyLogoURL); if ($width > 212 || $height > 40) { $resizePctWidth = ($width - 212) / 212; $resizePctHeight = ($height - 40) / 40; if ($resizePctWidth > $resizePctHeight) { $resizeAmount = $width / 212; } else { $resizeAmount = $height / 40; } $ss->assign("COMPANY_LOGO_WIDTH", round($width * (1 / $resizeAmount))); $ss->assign("COMPANY_LOGO_HEIGHT", round($height * (1 / $resizeAmount))); } else { $ss->assign("COMPANY_LOGO_WIDTH", $width); $ss->assign("COMPANY_LOGO_HEIGHT", $height); } // Let's cache the results sugar_cache_put('company_logo_attributes', array($ss->get_template_vars("COMPANY_LOGO_MD5"), $ss->get_template_vars("COMPANY_LOGO_WIDTH"), $ss->get_template_vars("COMPANY_LOGO_HEIGHT"))); } $ss->assign("COMPANY_LOGO_URL", getJSPath($companyLogoURL) . "&logo_md5=" . $ss->get_template_vars("COMPANY_LOGO_MD5")); // get the global links $gcls = array(); $global_control_links = array(); require "include/globalControlLinks.php"; foreach ($global_control_links as $key => $value) { if ($key == 'users') { //represents logout link. $ss->assign("LOGOUT_LINK", $value['linkinfo'][key($value['linkinfo'])]); $ss->assign("LOGOUT_LABEL", key($value['linkinfo'])); //key value for first element. continue; } foreach ($value as $linkattribute => $attributevalue) { // get the main link info if ($linkattribute == 'linkinfo') { $gcls[$key] = array("LABEL" => key($attributevalue), "URL" => current($attributevalue), "SUBMENU" => array()); if (substr($gcls[$key]["URL"], 0, 11) == "javascript:") { $gcls[$key]["ONCLICK"] = substr($gcls[$key]["URL"], 11); $gcls[$key]["URL"] = "#"; } } // and now the sublinks if ($linkattribute == 'submenu' && is_array($attributevalue)) { foreach ($attributevalue as $submenulinkkey => $submenulinkinfo) { $gcls[$key]['SUBMENU'][$submenulinkkey] = array("LABEL" => key($submenulinkinfo), "URL" => current($submenulinkinfo)); } if (substr($gcls[$key]['SUBMENU'][$submenulinkkey]["URL"], 0, 11) == "javascript:") { $gcls[$key]['SUBMENU'][$submenulinkkey]["ONCLICK"] = substr($gcls[$key]['SUBMENU'][$submenulinkkey]["URL"], 11); $gcls[$key]['SUBMENU'][$submenulinkkey]["URL"] = "#"; } } } } $ss->assign("GCLS", $gcls); $ss->assign("SEARCH", isset($_REQUEST['query_string']) ? $_REQUEST['query_string'] : ''); if ($this->action == "EditView" || $this->action == "Login") { $ss->assign("ONLOAD", 'onload="set_focus()"'); } $ss->assign("AUTHENTICATED", isset($_SESSION["authenticated_user_id"])); // get other things needed for page style popup if (isset($_SESSION["authenticated_user_id"])) { // get the current user name and id $ss->assign("CURRENT_USER", $current_user->full_name == '' || !showFullName() ? $current_user->user_name : $current_user->full_name); $ss->assign("CURRENT_USER_ID", $current_user->id); // get the last viewed records $tracker = new Tracker(); $history = $tracker->get_recently_viewed($current_user->id); foreach ($history as $key => $row) { $history[$key]['item_summary_short'] = getTrackerSubstring($row['item_summary']); $history[$key]['image'] = SugarThemeRegistry::current()->getImage($row['module_name'], 'border="0" align="absmiddle" alt="' . $row['item_summary'] . '"'); } $ss->assign("recentRecords", $history); } $bakModStrings = $mod_strings; if (isset($_SESSION["authenticated_user_id"])) { // get the module list $moduleTopMenu = array(); $max_tabs = $current_user->getPreference('max_tabs'); // Attempt to correct if max tabs count is waaay too high. if (!isset($max_tabs) || $max_tabs <= 0 || $max_tabs > 10) { $max_tabs = $GLOBALS['sugar_config']['default_max_tabs']; $current_user->setPreference('max_tabs', $max_tabs, 0, 'global'); } $moduleTab = $this->_getModuleTab(); $ss->assign('MODULE_TAB', $moduleTab); // See if they are using grouped tabs or not (removed in 6.0, returned in 6.1) $user_navigation_paradigm = $current_user->getPreference('navigation_paradigm'); if (!isset($user_navigation_paradigm)) { $user_navigation_paradigm = $GLOBALS['sugar_config']['default_navigation_paradigm']; } // Get the full module list for later use foreach (query_module_access_list($current_user) as $module) { // Bug 25948 - Check for the module being in the moduleList if (isset($app_list_strings['moduleList'][$module])) { $fullModuleList[$module] = $app_list_strings['moduleList'][$module]; } } if (!should_hide_iframes()) { $iFrame = new iFrame(); $frames = $iFrame->lookup_frames('tab'); foreach ($frames as $key => $values) { $fullModuleList[$key] = $values; } } elseif (isset($fullModuleList['iFrames'])) { unset($fullModuleList['iFrames']); } if ($user_navigation_paradigm == 'gm' && isset($themeObject->group_tabs) && $themeObject->group_tabs) { // We are using grouped tabs require_once 'include/GroupedTabs/GroupedTabStructure.php'; $groupedTabsClass = new GroupedTabStructure(); $modules = query_module_access_list($current_user); //handle with submoremodules $max_tabs = $current_user->getPreference('max_tabs'); // If the max_tabs isn't set incorrectly, set it within the range, to the default max sub tabs size if (!isset($max_tabs) || $max_tabs <= 0 || $max_tabs > 10) { // We have a default value. Use it if (isset($GLOBALS['sugar_config']['default_max_tabs'])) { $max_tabs = $GLOBALS['sugar_config']['default_max_tabs']; } else { $max_tabs = 8; } } $subMoreModules = false; $groupTabs = $groupedTabsClass->get_tab_structure(get_val_array($modules)); // We need to put this here, so the "All" group is valid for the user's preference. $groupTabs[$app_strings['LBL_TABGROUP_ALL']]['modules'] = $fullModuleList; // Setup the default group tab. $allGroup = $app_strings['LBL_TABGROUP_ALL']; $ss->assign('currentGroupTab', $allGroup); $currentGroupTab = $allGroup; $usersGroup = $current_user->getPreference('theme_current_group'); // Figure out which tab they currently have selected (stored as a user preference) if (!empty($usersGroup) && isset($groupTabs[$usersGroup])) { $currentGroupTab = $usersGroup; } else { $current_user->setPreference('theme_current_group', $currentGroupTab); } $ss->assign('currentGroupTab', $currentGroupTab); $usingGroupTabs = true; } else { // Setup the default group tab. $ss->assign('currentGroupTab', $app_strings['LBL_TABGROUP_ALL']); $usingGroupTabs = false; $groupTabs[$app_strings['LBL_TABGROUP_ALL']]['modules'] = $fullModuleList; } $topTabList = array(); // Now time to go through each of the tab sets and fix them up. foreach ($groupTabs as $tabIdx => $tabData) { $topTabs = $tabData['modules']; if (!is_array($topTabs)) { $topTabs = array(); } $extraTabs = array(); // Split it in to the tabs that go across the top, and the ones that are on the extra menu. if (count($topTabs) > $max_tabs) { $extraTabs = array_splice($topTabs, $max_tabs); } // Make sure the current module is accessable through one of the top tabs if (!isset($topTabs[$moduleTab])) { // Nope, we need to add it. // First, take it out of the extra menu, if it's there if (isset($extraTabs[$moduleTab])) { unset($extraTabs[$moduleTab]); } if (count($topTabs) >= $max_tabs - 1) { // We already have the maximum number of tabs, so we need to shuffle the last one // from the top to the first one of the extras $lastElem = array_splice($topTabs, $max_tabs - 1); $extraTabs = $lastElem + $extraTabs; } if (!empty($moduleTab)) { $topTabs[$moduleTab] = $app_list_strings['moduleList'][$moduleTab]; } } /* // This was removed, but I like the idea, so I left the code in here in case we decide to turn it back on // If we are using group tabs, add all the "hidden" tabs to the end of the extra menu if ( $usingGroupTabs ) { foreach($fullModuleList as $moduleKey => $module ) { if ( !isset($topTabs[$moduleKey]) && !isset($extraTabs[$moduleKey]) ) { $extraTabs[$moduleKey] = $module; } } } */ // Get a unique list of the top tabs so we can build the popup menus for them foreach ($topTabs as $moduleKey => $module) { $topTabList[$moduleKey] = $module; } $groupTabs[$tabIdx]['modules'] = $topTabs; $groupTabs[$tabIdx]['extra'] = $extraTabs; } } if (isset($topTabList) && is_array($topTabList)) { // Adding shortcuts array to menu array for displaying shortcuts associated with each module $shortcutTopMenu = array(); foreach ($topTabList as $module_key => $label) { global $mod_strings; $mod_strings = return_module_language($current_language, $module_key); foreach ($this->getMenu($module_key) as $key => $menu_item) { $shortcutTopMenu[$module_key][$key] = array("URL" => $menu_item[0], "LABEL" => $menu_item[1], "MODULE_NAME" => $menu_item[2], "IMAGE" => $themeObject->getImage($menu_item[2], "alt='" . $menu_item[1] . "' border='0' align='absmiddle'")); } } $ss->assign("groupTabs", $groupTabs); $ss->assign("shortcutTopMenu", $shortcutTopMenu); $ss->assign('USE_GROUP_TABS', $usingGroupTabs); // This is here for backwards compatibility, someday, somewhere, it will be able to be removed $ss->assign("moduleTopMenu", $groupTabs[$app_strings['LBL_TABGROUP_ALL']]['modules']); $ss->assign("moduleExtraMenu", $groupTabs[$app_strings['LBL_TABGROUP_ALL']]['extra']); } global $mod_strings; $mod_strings = $bakModStrings; $headerTpl = $themeObject->getTemplate('header.tpl'); if (isset($GLOBALS['sugar_config']['developerMode']) && $GLOBALS['sugar_config']['developerMode']) { $ss->clear_compiled_tpl($headerTpl); } $ss->display($headerTpl); $this->includeClassicFile('modules/Administration/DisplayWarnings.php'); $errorMessages = SugarApplication::getErrorMessages(); if (!empty($errorMessages)) { foreach ($errorMessages as $error_message) { echo '<p class="error">' . $error_message . '</p>'; } } }
/** * Generic load method to load mapping arrays. */ private function loadMapping($var, $merge = false) { ${$var} = sugar_cache_retrieve("CONTROLLER_" . $var . "_" . $this->module); if (!${$var}) { if ($merge && !empty($this->{$var})) { ${$var} = $this->{$var}; } else { ${$var} = array(); } if (file_exists('include/MVC/Controller/' . $var . '.php')) { require 'include/MVC/Controller/' . $var . '.php'; } if (file_exists('modules/' . $this->module . '/' . $var . '.php')) { require 'modules/' . $this->module . '/' . $var . '.php'; } if (file_exists('custom/modules/' . $this->module . '/' . $var . '.php')) { require 'custom/modules/' . $this->module . '/' . $var . '.php'; } if (file_exists('custom/include/MVC/Controller/' . $var . '.php')) { require 'custom/include/MVC/Controller/' . $var . '.php'; } sugar_cache_put("CONTROLLER_" . $var . "_" . $this->module, ${$var}); } $this->{$var} = ${$var}; }
/** * wrapper for whatever currency system we implement */ function loadCurrencies() { // trying to use DBManagerFactory here fails in install.php, // so leaving this as global $db. //$db = DBManagerFactory::getInstance(); global $db; global $sugar_config; if (empty($db)) { return array(); } $load = sugar_cache_retrieve('currency_list'); if (!is_array($load)) { // load default from config.php $this->currencies['-99'] = array('name' => $sugar_config['default_currency_name'], 'symbol' => $sugar_config['default_currency_symbol'], 'conversion_rate' => 1); $q = "SELECT id, name, symbol, conversion_rate FROM currencies WHERE status = 'Active' and deleted = 0"; $r = $db->query($q); while ($a = $db->fetchByAssoc($r)) { $load = array(); $load['name'] = $a['name']; $load['symbol'] = $a['symbol']; $load['conversion_rate'] = $a['conversion_rate']; $this->currencies[$a['id']] = $load; } sugar_cache_put('currency_list', $this->currencies); } else { $this->currencies = $load; } }
/** * wrapper for whatever currency system we implement */ function loadCurrencies() { // doing it dirty here global $db; global $sugar_config; if (empty($db)) { return array(); } $load = sugar_cache_retrieve('currency_list'); if (!is_array($load)) { // load default from config.php $this->currencies['-99'] = array('name' => $sugar_config['default_currency_name'], 'symbol' => $sugar_config['default_currency_symbol'], 'conversion_rate' => 1); $q = "SELECT id, name, symbol, conversion_rate FROM currencies WHERE status = 'Active' and deleted = 0"; $r = $db->query($q); while ($a = $db->fetchByAssoc($r)) { $load = array(); $load['name'] = $a['name']; $load['symbol'] = $a['symbol']; $load['conversion_rate'] = $a['conversion_rate']; $this->currencies[$a['id']] = $load; } sugar_cache_put('currency_list', $this->currencies); } else { $this->currencies = $load; } }
public function testBuildMergeLink() { $this->_lvd->seed = new stdClass(); $this->_lvd->seed->module_dir = 'foobarfoobar'; $GLOBALS['current_user']->setPreference('mailmerge_on', 'on'); $settings_cache = sugar_cache_retrieve('admin_settings_cache'); if (empty($settings_cache)) { $settings_cache = array(); } $settings_cache['system_mailmerge_on'] = true; sugar_cache_put('admin_settings_cache', $settings_cache); $output = $this->_lvd->buildMergeLink(array('foobarfoobar' => 'foobarfoobar')); $this->assertContains("index.php?action=index&module=MailMerge&entire=true", $output); sugar_cache_clear('admin_settings_cache'); }
/** * load the vardefs for a given module and object * @param string $module the given module we want to load the vardefs for * @param string $object the given object we wish to load the vardefs for * @param bool $refresh whether or not we wish to refresh the cache file. */ static function loadVardef($module, $object, $refresh = false, $params = array()) { //here check if the cache file exists, if it does then load it, if it doesn't //then call refreshVardef //if either our session or the system is set to developerMode then refresh is set to true if (inDeveloperMode() || !empty($_SESSION['developerMode'])) { $refresh = true; } // Retrieve the vardefs from cache. $key = "VardefManager.{$module}.{$object}"; if (!$refresh) { $return_result = sugar_cache_retrieve($key); $return_result = self::applyGlobalAccountRequirements($return_result); if (!empty($return_result)) { $GLOBALS['dictionary'][$object] = $return_result; return; } } // Some of the vardefs do not correctly define dictionary as global. Declare it first. global $dictionary; if (empty($GLOBALS['dictionary'][$object]) || $refresh) { //if the consumer has demanded a refresh or the cache/modules... file //does not exist, then we should do out and try to reload things $cachedfile = sugar_cached('modules/') . $module . '/' . $object . 'vardefs.php'; if ($refresh || !file_exists($cachedfile)) { VardefManager::refreshVardefs($module, $object, null, true, $params); } //at this point we should have the cache/modules/... file //which was created from the refreshVardefs so let's try to load it. if (file_exists($cachedfile)) { if (is_readable($cachedfile)) { include $cachedfile; } // now that we hae loaded the data from disk, put it in the cache. if (!empty($GLOBALS['dictionary'][$object])) { $GLOBALS['dictionary'][$object] = self::applyGlobalAccountRequirements($GLOBALS['dictionary'][$object]); sugar_cache_put($key, $GLOBALS['dictionary'][$object]); } } } }
function loadModuleLanguage($module, $lang, $refresh = false) { //here check if the cache file exists, if it does then load it, if it doesn't //then call refreshVardef //if either our session or the system is set to developerMode then refresh is set to true // Retrieve the vardefs from cache. $key = self::getLanguageCacheKey($module, $lang); if (!$refresh) { $return_result = sugar_cache_retrieve($key); if (!empty($return_result) && is_array($return_result)) { return $return_result; } } // Some of the vardefs do not correctly define dictionary as global. Declare it first. $cachedfile = sugar_cached('modules/') . $module . '/language/' . $lang . '.lang.php'; if ($refresh || !file_exists($cachedfile)) { LanguageManager::refreshLanguage($module, $lang); } //at this point we should have the cache/modules/... file //which was created from the refreshVardefs so let's try to load it. if (file_exists($cachedfile)) { global $mod_strings; require $cachedfile; // now that we hae loaded the data from disk, put it in the cache. if (!empty($mod_strings)) { sugar_cache_put($key, $mod_strings); } if (!empty($_SESSION['translation_mode'])) { $mod_strings = array_map('translated_prefix', $mod_strings); } return $mod_strings; } }
/** * checkDatabaseVersion * Check the db version sugar_version.php and compare to what the version is stored in the config table. * Ensure that both are the same. */ function checkDatabaseVersion($dieOnFailure = true) { $row_count = sugar_cache_retrieve('checkDatabaseVersion_row_count'); if (empty($row_count)) { $version_query = "SELECT count(*) as the_count FROM config WHERE category='info' AND name='sugar_version' AND " . $GLOBALS['db']->convert('value', 'text2char') . " = " . $GLOBALS['db']->quoted($GLOBALS['sugar_db_version']); $result = $GLOBALS['db']->query($version_query); $row = $GLOBALS['db']->fetchByAssoc($result); $row_count = $row['the_count']; sugar_cache_put('checkDatabaseVersion_row_count', $row_count); } if ($row_count == 0 && empty($GLOBALS['sugar_config']['disc_client'])) { if ($dieOnFailure) { $replacementStrings = array(0 => $GLOBALS['sugar_version'], 1 => $GLOBALS['sugar_db_version']); sugar_die(string_format($GLOBALS['app_strings']['ERR_DB_VERSION'], $replacementStrings)); } else { return false; } } return true; }
/** * Get system status from cache or settings or calculate it * @param string $forceReload * @return array|boolean */ function apiLoadSystemStatus($forceReload = false) { $systemStatus = null; $oldSystemStatus = null; // First try from SugarCache $systemStatus = sugar_cache_retrieve('api_system_status'); if (empty($systemStatus)) { // No luck, try the database $administration = Administration::getSettings('system'); // key defined in Adminitration::retrieveSettings(): $key = $row['category'] . '_' . $row['name']; if (!empty($administration->settings['system_api_system_status'])) { $systemStatus = unserialize(base64_decode($administration->settings['system_api_system_status'])); } } else { // if it's not an array and is truthy, comvert it to true // See BR-1150 if ($systemStatus && !is_array($systemStatus)) { $systemStatus = true; } } if (!empty($systemStatus)) { // Save the old system status, so if the new one is the same // even on a force reload, we don't update it. $oldSystemStatus = $systemStatus; } if ($forceReload) { $systemStatus = null; } if (empty($systemStatus)) { $systemStatus = apiActualLoadSystemStatus(); } $serializedStatus = serialize($systemStatus); if ($serializedStatus != serialize($oldSystemStatus)) { sugar_cache_put('api_system_status', $systemStatus); if (!isset($administration)) { $administration = Administration::getSettings('system'); } $administration->saveSetting('system', 'api_system_status', base64_encode($serializedStatus)); } return $systemStatus; }
function getArrowImageSize() { // just get the non-sort image's size.. the up and down have be the same. $image = SugarThemeRegistry::current()->getImageURL("arrow.gif", false); $cache_key = 'arrow_size.' . $image; // Check the cache $result = sugar_cache_retrieve($cache_key); if (!empty($result)) { return $result; } // No cache hit. Calculate the value and return. $result = getimagesize($image); sugar_cache_put($cache_key, $result); return $result; }
/** * @ticket 40797 */ public function testRetrieveNonExistantKeyReturnsNull() { $this->assertNull(sugar_cache_retrieve('iamlookingforakeythatainthere')); }
/** * Called from process(). This method will display the footer on the page. */ public function displayFooter() { if (empty($this->responseTime)) { $this->_calculateFooterMetrics(); } global $sugar_config; global $app_strings; global $mod_strings; $themeObject = SugarThemeRegistry::current(); //decide whether or not to show themepicker, default is to show $showThemePicker = true; if (isset($sugar_config['showThemePicker'])) { $showThemePicker = $sugar_config['showThemePicker']; } echo "<!-- crmprint -->"; $jsalerts = new jsAlerts(); if (!isset($_SESSION['isMobile'])) { echo $jsalerts->getScript(); } $ss = new Sugar_Smarty(); $ss->assign("AUTHENTICATED", isset($_SESSION["authenticated_user_id"])); $ss->assign('MOD', return_module_language($GLOBALS['current_language'], 'Users')); $bottomLinkList = array(); if (isset($this->action) && $this->action != "EditView") { $bottomLinkList['print'] = array($app_strings['LNK_PRINT'] => getPrintLink()); } $bottomLinkList['backtotop'] = array($app_strings['LNK_BACKTOTOP'] => 'javascript:SUGAR.util.top();'); $bottomLinksStr = ""; foreach ($bottomLinkList as $key => $value) { foreach ($value as $text => $link) { $href = $link; if (substr($link, 0, 11) == "javascript:") { $onclick = " onclick=\"" . substr($link, 11) . "\""; $href = "javascript:void(0)"; } else { $onclick = ""; } $imageURL = SugarThemeRegistry::current()->getImageURL($key . '.gif'); $bottomLinksStr .= "<a href=\"{$href}\""; $bottomLinksStr .= isset($onclick) ? $onclick : ""; $bottomLinksStr .= "><img src='{$imageURL}' alt=''>"; //keeping alt blank on purpose for 508 (text will be read instead) $bottomLinksStr .= " " . $text . "</a>"; } } $ss->assign("BOTTOMLINKS", $bottomLinksStr); if (SugarConfig::getInstance()->get('calculate_response_time', false)) { $ss->assign('STATISTICS', $this->_getStatistics()); } // Under the License referenced above, you are required to leave in all copyright statements in both // the code and end-user application. $copyright = '© 2004-2012 SugarCRM Inc. The Program is provided AS IS, without warranty. Licensed under <a href="LICENSE.txt" target="_blank" class="copyRightLink">AGPLv3</a>.<br>This program is free software; you can redistribute it and/or modify it under the terms of the <br><a href="LICENSE.txt" target="_blank" class="copyRightLink"> GNU Affero General Public License version 3</a> as published by the Free Software Foundation, including the additional permission set forth in the source code header.<br>'; // 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 General Public License version // 3. In accordance with Section 7(b) of the GNU General Public License // version 3, these Appropriate Legal Notices must retain the display // of the "Powered by SugarCRM" logo. If the display of the logo is // not reasonably feasible for technical reasons, the Appropriate // Legal Notices must display the words "Powered by SugarCRM". $attribLinkImg = "<img style='margin-top: 2px' border='0' width='120' height='34' src='include/images/poweredby_sugarcrm_65.png' alt='Powered By SugarCRM'>\n"; // handle resizing of the company logo correctly on the fly $companyLogoURL = $themeObject->getImageURL('company_logo.png'); $companyLogoURL_arr = explode('?', $companyLogoURL); $companyLogoURL = $companyLogoURL_arr[0]; $company_logo_attributes = sugar_cache_retrieve('company_logo_attributes'); if (!empty($company_logo_attributes)) { $ss->assign("COMPANY_LOGO_MD5", $company_logo_attributes[0]); $ss->assign("COMPANY_LOGO_WIDTH", $company_logo_attributes[1]); $ss->assign("COMPANY_LOGO_HEIGHT", $company_logo_attributes[2]); } else { // Always need to md5 the file $ss->assign("COMPANY_LOGO_MD5", md5_file($companyLogoURL)); list($width, $height) = getimagesize($companyLogoURL); if ($width > 212 || $height > 40) { $resizePctWidth = ($width - 212) / 212; $resizePctHeight = ($height - 40) / 40; if ($resizePctWidth > $resizePctHeight) { $resizeAmount = $width / 212; } else { $resizeAmount = $height / 40; } $ss->assign("COMPANY_LOGO_WIDTH", round($width * (1 / $resizeAmount))); $ss->assign("COMPANY_LOGO_HEIGHT", round($height * (1 / $resizeAmount))); } else { $ss->assign("COMPANY_LOGO_WIDTH", $width); $ss->assign("COMPANY_LOGO_HEIGHT", $height); } // Let's cache the results sugar_cache_put('company_logo_attributes', array($ss->get_template_vars("COMPANY_LOGO_MD5"), $ss->get_template_vars("COMPANY_LOGO_WIDTH"), $ss->get_template_vars("COMPANY_LOGO_HEIGHT"))); } $ss->assign("COMPANY_LOGO_URL", getJSPath($companyLogoURL) . "&logo_md5=" . $ss->get_template_vars("COMPANY_LOGO_MD5")); // Bug 38594 - Add in Trademark wording $copyright .= 'SugarCRM is a trademark of SugarCRM, Inc. All other company and product names may be trademarks of the respective companies with which they are associated.<br />'; //rrs bug: 20923 - if this image does not exist as per the license, then the proper image will be displayed regardless, so no need //to display an empty image here. if (file_exists('include/images/poweredby_sugarcrm_65.png')) { $copyright .= $attribLinkImg; } // End Required Image $ss->assign('COPYRIGHT', $copyright); // here we allocate the help link data $help_actions_blacklist = array('Login'); // we don't want to show a context help link here if (!in_array($this->action, $help_actions_blacklist)) { $url = 'javascript:void(window.open(\'index.php?module=Administration&action=SupportPortal&view=documentation&version=' . $GLOBALS['sugar_version'] . '&edition=' . $GLOBALS['sugar_flavor'] . '&lang=' . $GLOBALS['current_language'] . '&help_module=' . $this->module . '&help_action=' . $this->action . '&key=' . $GLOBALS['server_unique_key'] . '\'))'; $label = (isset($GLOBALS['app_list_strings']['moduleList'][$this->module]) ? $GLOBALS['app_list_strings']['moduleList'][$this->module] : $this->module) . ' ' . $app_strings['LNK_HELP']; $ss->assign('HELP_LINK', SugarThemeRegistry::current()->getLink($url, $label, "id='help_link_two'", 'help-dashlet.png', 'class="icon"', null, null, '', 'left')); } // end $ss->display(SugarThemeRegistry::current()->getTemplate('footer.tpl')); }
/** * Load the view_<view>_config.php file which holds options used by the view. */ function _loadConfig(&$view, $type) { $view_config_custom = array(); $view_config_module = array(); $view_config_root_cstm = array(); $view_config_root = array(); $view_config_app = array(); $config_file_name = 'view.' . $type . '.config.php'; $view_config = sugar_cache_retrieve("VIEW_CONFIG_FILE_" . $view->module . "_TYPE_" . $type); if (!$view_config) { if (file_exists('custom/modules/' . $view->module . '/views/' . $config_file_name)) { require_once 'custom/modules/' . $view->module . '/views/' . $config_file_name; $view_config_custom = $view_config; } if (file_exists('modules/' . $view->module . '/views/' . $config_file_name)) { require_once 'modules/' . $view->module . '/views/' . $config_file_name; $view_config_module = $view_config; } if (file_exists('custom/include/MVC/View/views/' . $config_file_name)) { require_once 'custom/include/MVC/View/views/' . $config_file_name; $view_config_root_cstm = $view_config; } if (file_exists('include/MVC/View/views/' . $config_file_name)) { require_once 'include/MVC/View/views/' . $config_file_name; $view_config_root = $view_config; } if (file_exists('include/MVC/View/views/view.config.php')) { require_once 'include/MVC/View/views/view.config.php'; $view_config_app = $view_config; } $view_config = array('actions' => array(), 'req_params' => array()); //actions if (!empty($view_config_app) && !empty($view_config_app['actions'])) { $view_config['actions'] = array_merge($view_config['actions'], $view_config_app['actions']); } if (!empty($view_config_root) && !empty($view_config_root['actions'])) { $view_config['actions'] = array_merge($view_config['actions'], $view_config_root['actions']); } if (!empty($view_config_root_cstm) && !empty($view_config_root_cstm['actions'])) { $view_config['actions'] = array_merge($view_config['actions'], $view_config_root_cstm['actions']); } if (!empty($view_config_module) && !empty($view_config_module['actions'])) { $view_config['actions'] = array_merge($view_config['actions'], $view_config_module['actions']); } if (!empty($view_config_custom) && !empty($view_config_custom['actions'])) { $view_config['actions'] = array_merge($view_config['actions'], $view_config_custom['actions']); } //req_params if (!empty($view_config_app) && !empty($view_config_app['req_params'])) { $view_config['req_params'] = array_merge($view_config['req_params'], $view_config_app['req_params']); } if (!empty($view_config_root) && !empty($view_config_root['req_params'])) { $view_config['req_params'] = array_merge($view_config['req_params'], $view_config_root['req_params']); } if (!empty($view_config_root_cstm) && !empty($view_config_root_cstm['req_params'])) { $view_config['req_params'] = array_merge($view_config['req_params'], $view_config_root_cstm['req_params']); } if (!empty($view_config_module) && !empty($view_config_module['req_params'])) { $view_config['req_params'] = array_merge($view_config['req_params'], $view_config_module['req_params']); } if (!empty($view_config_custom) && !empty($view_config_custom['req_params'])) { $view_config['req_params'] = array_merge($view_config['req_params'], $view_config_custom['req_params']); } sugar_cache_put("VIEW_CONFIG_FILE_" . $view->module . "_TYPE_" . $type, $view_config); } $action = strtolower($view->action); $config = null; if (!empty($view_config['req_params'])) { //try the params first foreach ($view_config['req_params'] as $key => $value) { if (!empty($_REQUEST[$key]) && $_REQUEST[$key] == "false") { $_REQUEST[$key] = false; } if (!empty($_REQUEST[$key])) { if (!is_array($value['param_value'])) { if ($value['param_value'] == $_REQUEST[$key]) { $config = $value['config']; break; } } else { foreach ($value['param_value'] as $v) { if ($v == $_REQUEST[$key]) { $config = $value['config']; break; } } } } } } if ($config == null && !empty($view_config['actions']) && !empty($view_config['actions'][$action])) { $config = $view_config['actions'][$action]; } if ($config != null) { $view->options = $config; } }
/** * static getUserRoleNames($user_id) * returns a list of Role names for a given user id * * @param GUID $user_id * * @return a list of ACLRole Names */ function getUserRoleNames($user_id) { $user_roles = sugar_cache_retrieve("RoleMembershipNames_" . $user_id); if (!$user_roles) { //if we don't have it loaded then lets check against the db $additional_where = ''; $query = "SELECT acl_roles.* " . "FROM acl_roles " . "INNER JOIN acl_roles_users ON acl_roles_users.user_id = '{$user_id}' " . "AND acl_roles_users.role_id = acl_roles.id AND acl_roles_users.deleted = 0 " . "WHERE acl_roles.deleted=0 "; $result = $GLOBALS['db']->query($query); $user_roles = []; while ($row = $GLOBALS['db']->fetchByAssoc($result)) { $user_roles[] = $row['name']; } sugar_cache_put("RoleMembershipNames_" . $user_id, $user_roles); } return $user_roles; }
/** * Constructor * * Sets the theme properties from the defaults passed to it, and loads the file path cache from an external cache * * @param $defaults string defaults for the current theme */ public function __construct($defaults) { // apply parent theme's properties first if (isset($defaults['parentTheme'])) { $themedef = array(); include "themes/{$defaults['parentTheme']}/themedef.php"; foreach ($themedef as $key => $value) { if (property_exists(__CLASS__, $key)) { // For all arrays ( except colors and fonts ) you can just specify the items // to change instead of all of the values if (is_array($this->{$key}) && !in_array($key, array('colors', 'fonts'))) { $this->{$key} = array_merge($this->{$key}, $value); } else { $this->{$key} = $value; } } } } foreach ($defaults as $key => $value) { if (property_exists(__CLASS__, $key)) { // For all arrays ( except colors and fonts ) you can just specify the items // to change instead of all of the values if (is_array($this->{$key}) && !in_array($key, array('colors', 'fonts'))) { $this->{$key} = array_merge($this->{$key}, $value); } else { $this->{$key} = $value; } } } if (!inDeveloperMode()) { // load stored theme cache from sugar cache if it's there if ($GLOBALS['external_cache_enabled'] && $GLOBALS['external_cache_type'] != 'base-in-memory') { $this->_jsCache = sugar_cache_retrieve('theme_' . $this->dirName . '_jsCache'); $this->_cssCache = sugar_cache_retrieve('theme_' . $this->dirName . '_cssCache'); $this->_imageCache = sugar_cache_retrieve('theme_' . $this->dirName . '_imageCache'); $this->_templateCache = sugar_cache_retrieve('theme_' . $this->dirName . '_templateCache'); } elseif (sugar_is_file($GLOBALS['sugar_config']['cache_dir'] . $this->getFilePath() . '/pathCache.php')) { $caches = unserialize(file_get_contents($GLOBALS['sugar_config']['cache_dir'] . $this->getFilePath() . '/pathCache.php')); if (isset($caches['jsCache'])) { $this->_jsCache = $caches['jsCache']; } if (isset($caches['cssCache'])) { $this->_cssCache = $caches['cssCache']; } if (isset($caches['imageCache'])) { $this->_imageCache = $caches['imageCache']; } if (isset($caches['templateCache'])) { $this->_templateCache = $caches['templateCache']; } } } $this->_initialCacheSize = array('jsCache' => count($this->_jsCache), 'cssCache' => count($this->_cssCache), 'imageCache' => count($this->_imageCache), 'templateCache' => count($this->_templateCache)); }
/** * @return boolean true if the user is a member of the role_name, false otherwise * @param string $role_name - Must be the exact name of the acl_role * @param string $user_id - The user id to check for the role membership, empty string if current user * @desc Determine whether or not a user is a member of an ACL Role. This function caches the * results in the session or to prevent running queries after the first time executed. * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.. * All Rights Reserved.. * Contributor(s): ______________________________________.. */ function check_role_membership($role_name, $user_id = '') { global $current_user; if (empty($user_id)) { $user_id = $current_user->id; } // Check the Sugar External Cache to see if this users memberships were cached $role_array = sugar_cache_retrieve("RoleMemberships_" . $user_id); // If we are pulling the roles for the current user if ($user_id == $current_user->id) { // If the Session doesn't contain the values if (!isset($_SESSION['role_memberships'])) { // This means the external cache already had it loaded if (!empty($role_array)) { $_SESSION['role_memberships'] = $role_array; } else { $_SESSION['role_memberships'] = ACLRole::getUserRoleNames($user_id); $role_array = $_SESSION['role_memberships']; } } else { $role_array = $_SESSION['role_memberships']; } } else { // If the external cache didn't contain the values, we get them and put them in cache if (!$role_array) { $role_array = ACLRole::getUserRoleNames($user_id); sugar_cache_put("RoleMemberships_" . $user_id, $role_array); } } // If the role doesn't exist in the list of the user's roles if (!empty($role_array) && in_array($role_name, $role_array)) { return true; } else { return false; } }
/** 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 = sugarArrayMerge($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 null; } $return_value = $mod_list_strings; $mod_list_strings = $temp_mod_list_strings; sugar_cache_put($cache_key, $return_value); return $return_value; }