<?php
/**
 * This the admin system init file created by PHPGEN.
 *
 * PHPGEN is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * PHPGEN is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with PHPGEN; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * @copyright   EasySoft R&D Team (C) 2006
 * @author      Chunsheng Wang <wwccss@263.net>
 * @link        http://www.phpgen.com
 * @package     Include
 */
/* 设置错误提示警告。 */
error_reporting(E_ALL ^ E_NOTICE ^ E_WARNING);
session_start();
header("Cache-control: private");

/* 设置包含路径。 */
$_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_once("Config.php");
include_once("FuncMain.php");
include_once("FuncHtml.php");
require_once("Smarty/Smarty.class.php");
require_once("Page.class.php");
require_once("ADO/adodb.inc.php");
include_once("JS.class.php");

/* 连接到数据库，返回全局变量$MyDB。 */
$MyDB = &ADONewConnection("mysql");
$MyDB->Connect($_CFG["DB"]["Server"], $_CFG["DB"]["User"], $_CFG["DB"]["Password"], $_CFG["DB"]["Database"]);
$ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;

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

/* 设置JS类。*/
$MyJS = new JS;

/* 设置用户的语言和风格。*/
$_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) : "";

/* 对用户传入的变量进行AddAlash操作。*/
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(".php", ".htm", $_CFG["TPL"]);

/* 赋值到模板系统。*/
$MyTPL->assign("CFG",  $_CFG);
$MyTPL->assign("Lang", $_LANG);
?>