<?php
define('TM_ROOT', substr(dirname(__FILE__), 0, -8).'/');
define('MICROTIME_START', microtime());
define('IN_TM', TRUE);
define('MAGIC_QUOTES_GPC', get_magic_quotes_gpc());
define('TIME', time());
set_magic_quotes_runtime(0);
unset($LANG, $HTTP_ENV_VARS, $HTTP_POST_VARS, $HTTP_GET_VARS, $HTTP_POST_FILES, $HTTP_COOKIE_VARS);
@require_once TM_ROOT.'data/config.inc.php';
require_once TM_ROOT.'include/global.func.php';
define('CACHE_PATH', TM_ROOT.'data/cache'); //缓存默认存储路径
define('IP', ip());
define('HTTP_REFERER', isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '');
define('SCRIPT_NAME', isset($_SERVER['SCRIPT_NAME']) ? $_SERVER['SCRIPT_NAME'] : preg_replace("/(.*)\.php(.*)/i", "\\1.php", $_SERVER['PHP_SELF']));
define('QUERY_STRING', safe_replace($_SERVER['QUERY_STRING']));
define('DOMAIN', isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : preg_replace("/([^:]*)[:0-9]*/i", "\\1", $_SERVER['HTTP_HOST']));
define('RELATE_URL', isset($_SERVER['REQUEST_URI']) ? safe_replace($_SERVER['REQUEST_URI']) : SCRIPT_NAME.(QUERY_STRING ? '?'.QUERY_STRING : PATH_INFO));
define('SITE_URL', strtolower((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ? 'https' : 'http').'://'.$_SERVER['HTTP_HOST'].substr($_SERVER['PHP_SELF'], 0, strrpos($_SERVER['PHP_SELF'], '/'))).'/');
define('URL', SITE_URL.RELATE_URL);
define('RELATE_REFERER',urlencode(RELATE_URL));
define("FORMHASH", formhash());
define('TPL_ROOT', 'templates/'); //模板保存物理路径
define('TPL_CACHE_PATH', 'data/cache_template/'); //模板缓存物理路径
define('TPL_PATH', TPL_ROOT.TPL_NAME.'/');
define('SKIN_PATH', TPL_ROOT.TPL_NAME.'/skins/');
$PHP_SELF = SCRIPT_NAME;
ERRORLOG ? set_error_handler('tm_error') : error_reporting(E_ERROR | E_WARNING | E_PARSE);

if(function_exists('date_default_timezone_set')) date_default_timezone_set(TIMEZONE);
header('Content-type: text/html; charset='.CHARSET);

if(GZIP && function_exists('ob_gzhandler')){
	ob_start('ob_gzhandler');
}else{
	ob_start();
}
$dbclass = 'db_'.DB_DATABASE;
require TM_ROOT.'include/'.$dbclass.'.class.php';
$db = new $dbclass;
$db->connect(DB_HOST, DB_USER, DB_PW, DB_NAME, DB_PCONNECT, DB_CHARSET);

require TM_ROOT.'include/'.'session_mysql.class.php';
$session = new session();
session_set_cookie_params(SESSION_TTL, COOKIE_PATH, COOKIE_DOMAIN);

if(!@include CACHE_PATH.'/data_setting.php') {
	 require_once TM_ROOT.'include/cache.func.php';
	 cache_all();
     
}
include CACHE_PATH.'/data_business.php';
include CACHE_PATH.'/data_seccode.php';
include CACHE_PATH.'/data_seccodedata.php';

if($_REQUEST){	
	if(MAGIC_QUOTES_GPC)	{		
		$_REQUEST = new_stripslashes($_REQUEST);		
		if($_COOKIE) $_COOKIE = new_stripslashes($_COOKIE);	
	}else{		
		$_POST = new_addslashes($_POST);		
		$_GET = new_addslashes($_GET);		
		$_COOKIE = new_addslashes($_COOKIE);		
		@extract($_POST);		
		@extract($_GET);		
		@extract($_COOKIE);	
	}
}
$dosubmit = isset($dosubmit) ? 1 : 0; 
$_userid = 0;
$_username = '';
$tm_auth = get_cookie('xt_auth');
if($tm_auth){
	list($_userid,$_username, $_password) = explode("\t", xt_auth($tm_auth, 'DECODE'));
	$_userid = intval($_userid);
	$sql_member = "SELECT * FROM `".DB_PRE."member_cache` WHERE `userid`=$_userid";
	$r = $db->get_one($sql_member);
	if(!$r && cache_member()){
		$r = $db->get_one($sql_member);
	}
	if($r && $r['password'] === $_password){
		if($r['groupid'] == 2){
			set_cookie('auth', '');
			showmessage($LANG['userid_banned_by_administrator']);
		}
		@extract($r, EXTR_PREFIX_ALL, '');
	}else{
		$_userid = 0;
		$_username = '';
		set_cookie('auth', '');
	}
	unset($r, $tm_auth, $_password, $sql_member);
}
?>