Example #1
0
/**
 * Open a database connection. This is called once for all page requests, and closed at the footer.
 * Depending on the $g_check_ft_sessions global (true by default), it also logs the time of each
 * request, to perform the sessions timeout check. This parameter is enabled for the main script
 * so that all users are subject to being booted out if there's been no activity. But for external
 * scripts (such as the API) this setting can be disabled, giving them unfettered use of the database
 * connection without worrying about being - incorrectly - logged out.
 *
 * @return resource returns a reference to the open connection.
 */
function ft_db_connect()
{
    global $g_db_hostname, $g_db_username, $g_db_password, $g_db_name, $g_unicode, $g_db_ssl, $g_check_ft_sessions, $g_set_sql_mode;
    extract(ft_process_hook_calls("start", array(), array()), EXTR_OVERWRITE);
    if ($g_db_ssl) {
        $link = @mysql_connect($g_db_hostname, $g_db_username, $g_db_password, true, MYSQL_CLIENT_SSL);
    } else {
        $link = @mysql_connect($g_db_hostname, $g_db_username, $g_db_password, true);
    }
    if (!$link) {
        ft_display_serious_error("<p>Form Tools was unable to make a connection to the database hostname. This usually means the host is temporarily down, it's no longer accessible with the hostname you're passing, or the username and password you're using isn't valid.</p><p>Please check your /global/config.php file to confirm the <b>\$g_db_hostname</b>, <b>\$g_db_username</b> and <b>\$g_db_password</b> settings.</p>");
        exit;
    }
    $db_connection = mysql_select_db($g_db_name);
    if (!$db_connection) {
        ft_display_serious_error("Form Tools was unable to make a connection to the database. This usually means the database is temporarily down, or that the database is no longer accessible. Please check your /global/config.php file to confirm the <b>\$g_db_name</b> setting.");
        exit;
    }
    // if required, set all queries as UTF-8 (enabled by default)
    if ($g_unicode) {
        @mysql_query("SET NAMES 'utf8'", $link);
    }
    if ($g_set_sql_mode) {
        @mysql_query("SET SQL_MODE=''", $link);
    }
    if ($g_check_ft_sessions && isset($_SESSION["ft"]["account"])) {
        ft_check_sessions_timeout();
    }
    return $link;
}
Example #2
0
<?php

/**
 * Actions.php
 *
 * This file handles all server-side responses for Ajax requests. As of 2.0.0, it returns information
 * in JSON format to be handled by JS.
 */
// -------------------------------------------------------------------------------------------------
// this var prevents the default behaviour of auto-logging the user out
$g_check_ft_sessions = false;
require_once "../session_start.php";
// check the permissions
$permission_check = ft_check_permission("user", false);
// check the sessions haven't timeoutted
$sessions_still_valid = ft_check_sessions_timeout(false);
if (!$sessions_still_valid) {
    @session_destroy();
    $_SESSION["ft"] = array();
    $permission_check["has_permission"] = false;
    $permission_check["message"] = "session_expired";
}
// the action to take and the ID of the page where it will be displayed (allows for
// multiple calls on same page to load content in unique areas)
$request = array_merge($_GET, $_POST);
$action = $request["action"];
// To be deprecated! This is the pre-jQuery way to return vars back. Change to use return_vars, which passes an object
// ------------
// Find out if we need to return anything back with the response. This mechanism allows us to pass any information
// between the Ajax submit function and the Ajax return function. Usage:
//   "return_vals[]=question1:answer1&return_vals[]=question2:answer2&..."
Example #3
0
/**
 * This function should be called at the top of every module page - or at least every module page that wants to
 * retain the custom module nav. It does the following:
 *
 * 	- start sessions
 *  - checks permission
 *  - loads the module language file into the $LANG[module_folder] variable in the global namespace with
 *    the users chosen language (or if it doesn't exist, the module's default language). It also
 *    loads the language snippets into a $L global, for shorter use. So these are synonymous:
 *        $LANG.image_manager.phrase_hello_world
 *        $L.phrase_hello_world
 *
 * (the longer option is provided simply for consistency: that's how you access the module language variables in
 * regular Form Tools pages after using the ft_include_module() function).
 *
 * @param string $account_type who is allowed to see this module page: "admin", "client"
 */
function ft_init_module_page($account_type = "admin")
{
    global $g_root_dir, $g_session_type, $g_session_save_path, $g_check_ft_sessions, $LANG;
    if ($g_session_type == "database") {
        $sess = new SessionManager();
    }
    if (!empty($g_session_save_path)) {
        session_save_path($g_session_save_path);
    }
    @session_start();
    header("Cache-control: private");
    header("Content-Type: text/html; charset=utf-8");
    ft_check_permission($account_type);
    if ($g_check_ft_sessions && isset($_SESSION["ft"]["account"])) {
        ft_check_sessions_timeout();
    }
    $module_folder = _ft_get_current_module_folder();
    // if there's a library file defined, include it
    if (is_file("{$g_root_dir}/modules/{$module_folder}/library.php")) {
        include_once "{$g_root_dir}/modules/{$module_folder}/library.php";
    }
    // get the language file content
    $content = ft_get_module_lang_file_contents($module_folder);
    $LANG[$module_folder] = $content;
    $GLOBALS["L"] = $content;
    extract(ft_process_hook_calls("end", compact("account_type", "module_folder"), array()), EXTR_OVERWRITE);
}