/** * Called from process(). This method will display the correct javascript. */ protected function _displayJavascript() { global $locale, $sugar_config, $timedate; if ($this->_getOption('show_javascript')) { if (!$this->_getOption('show_header')) { $langHeader = get_language_header(); echo <<<EOHTML <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html {$langHeader}> <head> EOHTML; } $js_vars = array("sugar_cache_dir" => "cache/"); if (isset($this->bean->module_dir)) { $js_vars['module_sugar_grp1'] = $this->bean->module_dir; } if (isset($_REQUEST['action'])) { $js_vars['action_sugar_grp1'] = $_REQUEST['action']; } echo '<script>jscal_today = 1000*' . $timedate->asUserTs($timedate->getNow()) . '; if(typeof app_strings == "undefined") app_strings = new Array();</script>'; // Make sure the necessary cache files are in place $jsFiles = array("sugar_grp1.js", "sugar_grp1_yui.js", "sugar_grp1_jquery.js"); ensureJSCacheFilesExist($jsFiles); echo getVersionedScript('cache/include/javascript/sugar_grp1_jquery.js'); echo getVersionedScript('cache/include/javascript/sugar_grp1_yui.js'); echo getVersionedScript('cache/include/javascript/sugar_grp1.js'); $version_mark = getVersionedPath(null); echo '<script>SUGAR = SUGAR || {}; SUGAR.VERSION_MARK = ' . json_encode($version_mark) . ';</script>'; // output necessary config js in the top of the page $config_js = $this->getSugarConfigJS(); if (!empty($config_js)) { echo "<script>\n" . implode("\n", $config_js) . "</script>\n"; } // CSRF form token echo $this->getCsrfFormTokenJscript(); if (isset($sugar_config['email_sugarclient_listviewmaxselect'])) { echo "<script>SUGAR.config.email_sugarclient_listviewmaxselect = {$GLOBALS['sugar_config']['email_sugarclient_listviewmaxselect']};</script>"; } $image_server = defined('TEMPLATE_URL') ? TEMPLATE_URL . '/' : ''; echo '<script type="text/javascript">SUGAR.themes.image_server="' . $image_server . '";</script>'; // cn: bug 12274 - create session-stored key to defend against CSRF echo '<script type="text/javascript">var name_format = "' . $locale->getLocaleFormatMacro() . '";</script>'; echo self::getJavascriptValidation(); if (!is_file(sugar_cached('jsLanguage/') . $GLOBALS['current_language'] . '.js')) { require_once 'include/language/jsLanguage.php'; jsLanguage::createAppStringsCache($GLOBALS['current_language']); } echo getVersionedScript('cache/jsLanguage/' . $GLOBALS['current_language'] . '.js', $GLOBALS['sugar_config']['js_lang_version']); echo $this->_getModLanguageJS(); echo getVersionedScript('include/javascript/productTour.js'); if (isset($sugar_config['disc_client']) && $sugar_config['disc_client']) { echo getVersionedScript('modules/Sync/headersync.js'); } if (!is_file(sugar_cached("Expressions/functions_cache.js"))) { $GLOBALS['updateSilent'] = true; include "include/Expressions/updatecache.php"; } if (inDeveloperMode()) { echo getVersionedScript('cache/Expressions/functions_cache_debug.js'); } else { echo getVersionedScript('cache/Expressions/functions_cache.js'); } require_once "include/Expressions/DependencyManager.php"; echo "\n" . '<script type="text/javascript">' . DependencyManager::getJSUserVariables($GLOBALS['current_user']) . "</script>\n"; //echo out the $js_vars variables as javascript variables echo "<script type='text/javascript'>\n"; foreach ($js_vars as $var => $value) { echo "var {$var} = '{$value}';\n"; } echo "</script>\n"; } }