<?php

/**
 * 全局初始化文件
 *
============================================================================
 * 版权所有 2012-2020 深圳朝九科技有限公司，并保留所有权利。
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和
 * 使用；不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
 * $Author: Yukey  QQ:2787720874
*/

if (!defined('YUKEY'))
{
    die('Hacking attempt');
}

error_reporting(E_ALL);

if (__FILE__ == '')
{
    die('Fatal error code: 0');
}

/* 取得当前的根目录 */
define('ROOT_PATH', str_replace('includes/init.php', '', str_replace('\\', '/', __FILE__)));
define('APPDIR', str_replace($_SERVER['DOCUMENT_ROOT'], '', ROOT_PATH));

/*if (!file_exists(ROOT_PATH . 'data/install.lock') && !file_exists(ROOT_PATH . 'includes/install.lock')
    && !defined('NO_CHECK_INSTALL'))
{
    header("Location: ./install/index.php\n");

    exit;
}*/

/* 初始化设置 */
@ini_set('memory_limit',          '64M');
@ini_set('session.cache_expire',  180);
@ini_set('session.use_trans_sid', 0);
@ini_set('session.use_cookies',   1);
@ini_set('session.auto_start',    0);
@ini_set('display_errors',        1);

if (DIRECTORY_SEPARATOR == '\\')
{
    @ini_set('include_path', '.;' . ROOT_PATH);
}
else
{
    @ini_set('include_path', '.:' . ROOT_PATH);
}

require(ROOT_PATH . 'data/config.php');

if (defined('DEBUG_MODE') == false)
{
    define('DEBUG_MODE', 0);
}

if (PHP_VERSION >= '5.1' && !empty($timezone))
{
    date_default_timezone_set($timezone);
}

$php_self = isset($_SERVER['PHP_SELF']) ? $_SERVER['PHP_SELF'] : $_SERVER['SCRIPT_NAME'];
if ('/' == substr($php_self, -1))
{
    $php_self .= 'index.php';//页内跳转
}
define('PHP_SELF', $php_self);

//require(ROOT_PATH . 'includes/inc_constant.php');
require(ROOT_PATH . 'includes/cls_ecsy.php');//数据库表名前缀
require(ROOT_PATH . 'includes/cls_error.php');
//require(ROOT_PATH . 'includes/lib_time.php');
require(ROOT_PATH . 'includes/lib_base.php');
//require(ROOT_PATH . 'includes/lib_common.php');
require(ROOT_PATH . 'includes/lib_main.php'); //用户登入信息
//require(ROOT_PATH . 'includes/lib_insert.php');

/* 对用户传入的变量进行转义操作。*/
if (!get_magic_quotes_gpc())
{
    if (!empty($_GET))
    {
        $_GET  = addslashes_deep($_GET);
    }
    if (!empty($_POST))
    {
        $_POST = addslashes_deep($_POST);
    }

    $_COOKIE   = addslashes_deep($_COOKIE);
    $_REQUEST  = addslashes_deep($_REQUEST);
}

/* 创建 ECSHOP 对象 */
$si = new ECSY($db_name, $prefix_si);//其它表的前缀需要放在本文件末尾用户登入之后重载该文件时分类处理
//define('DATA_DIR', $ecs->data_dir());
//define('IMAGE_DIR', $ecs->image_dir());

/* 初始化数据库类 */
require(ROOT_PATH . 'includes/cls_mysql.php');
$db = new cls_mysql($db_host, $db_user, $db_pass, $db_name);
//$db->set_disable_cache_tables(array($ecs->table('sessions'), $ecs->table('sessions_data'), $ecs->table('cart')));
//$db->set_mysql_charset(EC_CHARSET);
//$db_host = $db_user = $db_pass = $db_name = NULL;

/* 创建错误处理对象 */
$err = new ecs_error('message.dwt');

/* 载入系统参数 这项可以去掉*/
$_CFG = load_config();

/* 载入语言文件 */
require(ROOT_PATH . 'data/common.php');

if (!defined('INIT_NO_USERS'))
{
    /* 初始化session */
   session_start();
}
if(isset($_SERVER['PHP_SELF']))
{
    $_SERVER['PHP_SELF']=htmlspecialchars($_SERVER['PHP_SELF']);
}
if (!defined('INIT_NO_SMARTY'))
{
    header('Cache-control: private');
    header('Content-type: text/html; charset='.EC_CHARSET);

    /* 创建 Smarty 对象。*/
    require(ROOT_PATH . 'smarty3/libs/Smarty.class.php');
    $smarty = new Smarty();

    $smarty->cache_lifetime = 60 * 60 * 24;
    $smarty->template_dir   = ROOT_PATH . 'smarty3/templates';
    $smarty->cache_dir      = ROOT_PATH . 'smarty3/caches';
    $smarty->compile_dir    = ROOT_PATH . 'smarty3/templates_c';
}
$id=!empty($_REQUEST['id']) ? $_REQUEST['id'] : '';//每页都会用到此变量，所以全部归纳于此处
$act=!empty($_REQUEST['act']) ? $_REQUEST['act'] : 'ready';
$isshow = isset($_REQUEST['isshow']) ? trim($_REQUEST['isshow']) : '';
if (!defined('INIT_NO_USERS'))
{
     if (!empty($_SESSION['tbID']))
	 {
            $smarty->assign('tbName',$_SESSION['tbName']);
			$smarty->assign('rank',$_SESSION['tbRank']);
            $smarty->assign('tbNickName',$_SESSION['tbNickName']);
			//以下防止smarty报header.dwt中的变量cat_val 和keywords undefine错误
			$smarty->assign('cat_val','');
			$smarty->assign('keywords','');
			$smarty->assign('isshow',$isshow);
	 }
}

$client = isset($_REQUEST['client']) ? trim($_REQUEST['client']) : $prefix_pu;
$pre=add_prefix($prefix_pu,$prefix_yo,$prefix_tt,$prefix_ft,$prefix_vc,$prefix_as,$prefix_xy,$client);
$prefix = new ECSY($db_name, $pre);
$db_host = $db_user = $db_pass = $db_name = NULL;//这一条要放下来，不能放在110行，不然$prefix实例无数据库名字
//check_login();不能放在这里，因为index.php无法在登入前检测状态
?>