function smarty_function_ft_include($params, &$smarty)
{
    global $LANG, $g_default_theme, $g_root_dir, $g_smarty;
    if (empty($params["file"])) {
        $smarty->trigger_error("assign: missing 'file' parameter. This is required.");
        return;
    }
    // the template ("file") should be an absolute path relative to the
    $template = $params["file"];
    $theme = isset($_SESSION["ft"]["account"]["theme"]) ? $_SESSION["ft"]["account"]["theme"] : $g_default_theme;
    $html = $g_smarty->fetch(ft_get_smarty_template_with_fallback($theme, $template));
    return $html;
}
Ejemplo n.º 2
0
/**
 * 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);
}
Ejemplo n.º 3
0
/**
 * Displays basic << 1 2 3 >> navigation for lists, each linking to the current page.
 *
 * This function has exactly the same purpose as display_page_nav, except that the pages are
 * hidden/shown with DHTML instead of separate server-side calls per page. This technique is better
 * for lists that contain a smaller number of items, e.g. the client and forms listing pages.
 *
 * ASSUMPTION: the JS counterpart function with the same function is defined in the calling page.
 * That function does all the work of hiding/showing pages, updating the "viewing X-Y"
 * text, enabling disabling the << and >> arrows, and storing the current page in sessions. This
 * function merely sets up the base HTML + JS.
 *
 * This function uses a dhtml_pagination.tpl Smarty template file, found in the current theme's root
 * folder.
 *
 * @param integer $num_results The total number of results found.
 * @param integer $num_per_page The max number of results to list per page.
 * @param integer $current_page The current page number being examined (defaults to 1).
 */
function ft_get_dhtml_page_nav($num_results, $num_per_page, $current_page = 1)
{
    global $g_smarty, $g_smarty_debug, $g_root_dir, $g_root_url, $LANG, $g_smarty_use_sub_dirs;
    $theme = $_SESSION["ft"]["account"]["theme"];
    $smarty = $g_smarty;
    // new Smarty();
    $smarty->template_dir = "{$g_root_dir}/themes/{$theme}";
    $smarty->compile_dir = "{$g_root_dir}/themes/{$theme}/cache/";
    $smarty->use_sub_dirs = $g_smarty_use_sub_dirs;
    $smarty->assign("LANG", $LANG);
    $smarty->assign("SESSION", $_SESSION["ft"]);
    $smarty->assign("g_root_dir", $g_root_dir);
    $smarty->assign("g_root_url", $g_root_url);
    $smarty->assign("samepage", ft_get_clean_php_self());
    $smarty->assign("num_results", $num_results);
    $smarty->assign("num_per_page", $num_per_page);
    $smarty->assign("current_page", $current_page);
    // find the range that's being displayed (e.g 11 to 20)
    $range_start = ($current_page - 1) * $num_per_page + 1;
    $range_end = $range_start + $num_per_page - 1;
    $range_end = $range_end > $num_results ? $num_results : $range_end;
    $smarty->assign("range_start", $range_start);
    $smarty->assign("range_end", $range_end);
    $viewing_range = "";
    if ($num_results > $num_per_page) {
        $replacement_info = array("startnum" => "<span id='nav_viewing_num_start'>{$range_start}</span>", "endnum" => "<span id='nav_viewing_num_end'>{$range_end}</span>");
        $viewing_range = ft_eval_smarty_string($LANG["phrase_viewing_range"], $replacement_info);
    }
    $smarty->assign("viewing_range", $viewing_range);
    $smarty->assign("total_pages", ceil($num_results / $num_per_page));
    // now process the template and return the HTML
    return $smarty->fetch(ft_get_smarty_template_with_fallback($theme, "dhtml_pagination.tpl"));
}