/** * Loads a theme opening page - as stored in the "theme" session key. This is loaded for every * page in the Form Tools UI. * * Note: if the page isn't found in the current theme, it defaults to the * "default" theme. This is important (and handy!): it means that only the default theme * needs to contain every file. Other themes can just define whatever pages they want to override * and omit the others. * * @param string $template the location of the template file, relative to the theme folder * @param array $page_vars a hash of information to provide to the template * @param string $g_theme an optional parameter, letting you override the default theme * @param string $g_theme an optional parameter, letting you override the default swatch */ function ft_display_page($template, $page_vars, $theme = "", $swatch = "") { global $g_root_dir, $g_root_url, $g_success, $g_message, $g_link, $g_smarty_debug, $g_debug, $LANG, $g_smarty, $g_smarty_use_sub_dirs, $g_js_debug, $g_benchmark_start, $g_enable_benchmarking, $g_upgrade_info, $g_hide_upgrade_link; if (empty($theme) && isset($_SESSION["ft"]["account"]["theme"])) { $theme = $_SESSION["ft"]["account"]["theme"]; $swatch = isset($_SESSION["ft"]["account"]["swatch"]) ? $_SESSION["ft"]["account"]["swatch"] : ""; } elseif (empty($theme)) { $settings = ft_get_settings(array("default_theme", "default_client_swatch")); $theme = $settings["default_theme"]; $swatch = $settings["default_client_swatch"]; } if (!isset($_SESSION["ft"]["account"]["is_logged_in"])) { $_SESSION["ft"]["account"]["is_logged_in"] = false; } if (!isset($_SESSION["ft"]["account"]["account_type"])) { $_SESSION["ft"]["account"]["account_type"] = ""; } // common variables. These are sent to EVERY templates $g_smarty->template_dir = "{$g_root_dir}/themes/{$theme}"; $g_smarty->compile_dir = "{$g_root_dir}/themes/{$theme}/cache"; // check the compile directory has the write permissions if (!is_writable($g_smarty->compile_dir)) { ft_display_serious_error("Either the theme cache folder doesn't have write-permissions, or your \$g_root_dir value is invalid. Please update the <b>{$g_smarty->compile_dir}</b> to have full read-write permissions (777 on unix).", ""); exit; } $g_smarty->use_sub_dirs = $g_smarty_use_sub_dirs; $g_smarty->assign("LANG", $LANG); $g_smarty->assign("SESSION", $_SESSION["ft"]); $settings = isset($_SESSION["ft"]["settings"]) ? $_SESSION["ft"]["settings"] : array(); $g_smarty->assign("settings", $settings); $g_smarty->assign("account", $_SESSION["ft"]["account"]); $g_smarty->assign("g_root_dir", $g_root_dir); $g_smarty->assign("g_root_url", $g_root_url); $g_smarty->assign("g_debug", $g_debug); $g_smarty->assign("g_js_debug", $g_js_debug ? "true" : "false"); $g_smarty->assign("g_hide_upgrade_link", $g_hide_upgrade_link); $g_smarty->assign("same_page", ft_get_clean_php_self()); $g_smarty->assign("query_string", $_SERVER["QUERY_STRING"]); $g_smarty->assign("dir", $LANG["special_text_direction"]); $g_smarty->assign("g_enable_benchmarking", $g_enable_benchmarking); $g_smarty->assign("swatch", $swatch); // if this page has been told to dislay a custom message, override g_success and g_message if ((!isset($g_upgrade_info["message"]) || empty($g_upgrade_info["message"])) && isset($_GET["message"])) { list($g_success, $g_message) = ft_display_custom_page_message($_GET["message"]); } $g_smarty->assign("g_success", $g_success); $g_smarty->assign("g_message", $g_message); if (isset($page_vars["page_url"])) { $parent_page_url = ft_get_parent_page_url($page_vars["page_url"]); $g_smarty->assign("nav_parent_page_url", $parent_page_url); } // check the "required" vars are at least set so they don't produce warnings when smarty debug is enabled if (!isset($page_vars["head_string"])) { $page_vars["head_string"] = ""; } if (!isset($page_vars["head_title"])) { $page_vars["head_title"] = ""; } if (!isset($page_vars["head_js"])) { $page_vars["head_js"] = ""; } if (!isset($page_vars["page"])) { $page_vars["page"] = ""; } // if we need to include custom JS messages in the page, add it to the generated JS. Note: even if the js_messages // key is defined but still empty, the ft_generate_js_messages function is called, returning the "base" JS - like // the JS version of g_root_url. Only if it is not defined will that info not be included. $js_messages = isset($page_vars["js_messages"]) ? ft_generate_js_messages($page_vars["js_messages"]) : ""; if (!empty($page_vars["head_js"]) || !empty($js_messages)) { $page_vars["head_js"] = "<script>\n//<![CDATA[\n{$page_vars["head_js"]}\n{$js_messages}\n//]]>\n</script>"; } if (!isset($page_vars["head_css"])) { $page_vars["head_css"] = ""; } $g_smarty->assign("modules_dir", "{$g_root_url}/modules"); // theme-specific vars $g_smarty->assign("images_url", "{$g_root_url}/themes/{$theme}/images"); $g_smarty->assign("theme_url", "{$g_root_url}/themes/{$theme}"); $g_smarty->assign("theme_dir", "{$g_root_dir}/themes/{$theme}"); // now add the custom variables for this template, as defined in $page_vars foreach ($page_vars as $key => $value) { $g_smarty->assign($key, $value); } // if smarty debug is on, enable Smarty debugging if ($g_smarty_debug) { $g_smarty->debugging = true; } extract(ft_process_hook_calls("main", compact("g_smarty", "template", "page_vars"), array("g_smarty")), EXTR_OVERWRITE); // if the page or hook actually defined some CSS for inclusion in the page, wrap it in the appropriate style tag. This // was safely moved here in 2.2.0, because nothing used it (!) if (!empty($g_smarty->_tpl_vars["head_css"])) { $g_smarty->assign("head_css", "<style type=\"text/css\">\n{$g_smarty->_tpl_vars["head_css"]}\n</style>"); } $g_smarty->display(ft_get_smarty_template_with_fallback($theme, $template)); ft_db_disconnect($g_link); }
/** * Also called on the login page. This does a quick test to confirm the database tables exist as they should. * If not, it throws a serious error and prevents the user from logging in. */ function ft_verify_core_tables_exist() { global $g_table_prefix, $g_ft_tables, $g_db_name; $g_db_name = ft_get_clean_db_entity($g_db_name); $result = mysql_query("SHOW TABLES FROM {$g_db_name}"); $found_tables = array(); while ($row = mysql_fetch_array($result)) { $found_tables[] = $row[0]; } $all_tables_found = true; $missing_tables = array(); foreach ($g_ft_tables as $table_name) { if (!in_array("{$g_table_prefix}{$table_name}", $found_tables)) { $all_tables_found = false; $missing_tables[] = "{$g_table_prefix}{$table_name}"; } } if (!$all_tables_found) { $missing_tables_str = "<blockquote><pre>" . implode("\n", $missing_tables) . "</pre></blockquote>"; ft_display_serious_error("Form Tools couldn't find all the database tables. Please check your /global/config.php file to confirm the <b>\$g_table_prefix</b> setting. The following tables are missing: {$missing_tables_str}"); exit; } }