Пример #1
0
function &default_context($make_session)
{
    /*
        Argument is a boolean value that tells the function whether to make a
        session or not.
    */
    $db =& get_db_connection();
    /* change character set to utf8 */
    $db->query("SET NAMES utf8mb4");
    //$db->query("SET CHARACTER SET 'utf8'");
    $user = null;
    $type = get_preferred_type($_GET['type'] ? $_GET['type'] : $_SERVER['HTTP_ACCEPT']);
    if ($type == 'text/html' && $make_session) {
        // get the session user if there is one
        session_set_cookie_params(86400 * 31, get_base_dir(), null, false, true);
        session_start();
        $user = cookied_user($db);
    }
    // Smarty is created last because it needs $_SESSION populated
    $sm =& get_smarty_instance($user);
    $ctx = new Context($db, $sm, $user, $type);
    return $ctx;
}
Пример #2
0
<?php

require_once '../lib/lib.everything.php';
enforce_master_on_off_switch($_SERVER['HTTP_ACCEPT_LANGUAGE']);
$context = default_context(True);
/**** ... ****/
$form_id = $_GET['id'] ? $_GET['id'] : null;
$form = get_form($context->db, $form_id);
$user = get_user($context->db, $form['user_id']);
if ($user['name']) {
    $form['user_name'] = $user['name'];
} else {
    $form['user_name'] = 'Anonymous';
}
$context->sm->assign('form', $form);
// Get fields
$fields = get_form_fields($context->db, $form_id);
$context->sm->assign('fields', $fields);
$type = $_GET['type'] ? $_GET['type'] : $_SERVER['HTTP_ACCEPT'];
$type = get_preferred_type($type);
if ($type == 'text/html') {
    header("Content-Type: text/html; charset=UTF-8");
    print $context->sm->fetch("form.html.tpl");
} else {
    header('HTTP/1.1 400');
    die("Unknown type.\n");
}