<?php
/**
 * Init file of {{$Page.PackageName}}. (Created by PHPGEN on {{$Page.CreatedTime}})
 *
 * @package     {{$Page.PackageName}}
 * @author      {{$Page.Author}}
 * @version     {{$IdTag}}
 */
/* Report all errors except E_NOTICE. */
error_reporting(E_ALL ^ E_NOTICE ^ E_WARNING);
session_start();
header("Cache-control: private");

/* Set the include path and BaseURL. */
$_CFG["SysRoot"]     = str_replace("\\", "/", str_replace("Include", "", dirname(__FILE__)));
$_CFG["PathDivider"] = eregi("WIN",PHP_OS) ? ";" : ":";
ini_set("include_path", $_CFG["SysRoot"]                   . $_CFG["PathDivider"] .
                        $_CFG["SysRoot"] . "Include/"      . $_CFG["PathDivider"] .
                        $_CFG["SysRoot"] . "Include/Class" . $_CFG["PathDivider"]);

/* Require needed files. */
require_once("Config.php");
include_once("FuncMain.php");
include_once("FuncHtml.php");
require_once("Smarty/Smarty.class.php");
require_once("ADO/adodb.inc.php");
require_once("Page.class.php");
include_once("JS.class.php");

/* Connect to {{$Page.PackageName}} database server and return the global DB handler -- $MyDB which is used anywhere and set the FETCH_MODE to ASSOC. */
$MyDB = &ADONewConnection("mysql");
$MyDB->Connect($_CFG["DB"]["Server"], $_CFG["DB"]["User"], $_CFG["DB"]["Password"], $_CFG["DB"]["Database"]);
$ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;

/* Init smarty class. */
$MyTPL = new Smarty;
$MyTPL->caching       = false;
$MyTPL->template_dir  = $_CFG["SysRoot"] . 'Templates';
$MyTPL->compile_dir   = $_CFG["SysRoot"] . 'Compile';
$MyTPL->compile_check = true;

/* Init JS classes. */
$MyJS = new JS;

/* Set the language and style. */
$_CFG["UserLang"]  = isset($_COOKIE["_UserLang"])  ? $_COOKIE["_UserLang"]  : key($_CFG["LangList"]);
$_CFG["UserStyle"] = isset($_COOKIE["_UserStyle"]) ? $_COOKIE["_UserStyle"] : "Default";
@setcookie("_UserLang",  $_CFG["UserLang"],  time()+360000);
@setcookie("_UserStyle", $_CFG["UserStyle"], time()+360000);

$LangMain = "Languages/" . $_CFG["UserLang"] . "/_COMMON.php";
$LangSelf = $_CFG["SysRoot"] . "Languages/" . $_CFG["UserLang"] . str_replace($_CFG["BasePath"], "", $_SERVER["PHP_SELF"]);
require_once($LangMain);
file_exists($LangSelf) ? require_once($LangSelf) : "";

/* Add slashes to REQUEST, GET, POST, COOKIE, FILES vars. */
if(!get_magic_quotes_gpc())
{
    $_REQUEST = sysAddSlash($_REQUEST);
    $_GET     = sysAddSlash($_GET);
    $_POST    = sysAddSlash($_POST);
    $_COOKIE  = sysAddSlash($_COOKIE);
    $_FILES   = sysAddSlash($_FILES);
}

/* 根据当前的PHPSELF，获得它对应的模板文件。可以在PHP程序里面直接$MyTPL->display($_CFG["TPL"]);。*/
$_CFG["TPL"] = substr($_SERVER["PHP_SELF"], 1);
$_CFG["TPL"] = str_replace($_CFG["BasePath"], "", str_replace(".php", ".htm", $_CFG["TPL"]));

/* Assign. */
$MyTPL->assign("CFG",  $_CFG);
$MyTPL->assign("Lang", $_LANG);
?>