<?php
error_reporting(E_ALL ^ E_NOTICE);
date_default_timezone_set('PRC');
header('Content-Type: text/html; charset=utf-8');

//改写不安全的register_global和防sql注入处理
if (@ini_get('register_globals')) {
	foreach($_REQUEST as $name => $value){unset($$name);}
}

//url路由配置
$module = $mod = $act = 'index';

$mod = $_POST['mod'] ? $_POST['mod'] : ($_GET['mod'] ? $_GET['mod'] : $mod);
$act = $_POST['act'] ? $_POST['act'] : ($_GET['act'] ? $_GET['act'] : $act);

if ($_SERVER['PATH_INFO']) {
	$module = 'index';
	$_pathinfo = explode('/', str_ireplace('.html', '', trim($_SERVER['PATH_INFO'], '/')));

	$mod = $_pathinfo[0] ? $_pathinfo[0] : $mod;
	$act = $_pathinfo[1] ? $_pathinfo[1] : $act;

	if ($_pathinfo[1]) {
		$querystr = explode('-', $_pathinfo[1]);
		$querystr[0] && $act = $querystr[0];
		//预设3个参数值
		$querystr[1] && $_g_urlarg[1] = $querystr[1];
		$querystr[2] && $_g_urlarg[2] = $querystr[2];
		$querystr[3] && $_g_urlarg[3] = $querystr[3];
	}
}
else {
	$module = basename($_SERVER['SCRIPT_NAME'], '.php');
}



include(dirname(__FILE__).'/config.php');

//#################=====定义全局路径=====#################//
$pe['host_root'] = 'http://'.str_ireplace(rtrim(str_replace('\\','/',$_SERVER['DOCUMENT_ROOT']), '/'), $_SERVER['HTTP_HOST'], str_replace('\\', '/', dirname(__FILE__))).'/';
$pe['path_root'] = str_replace('\\','/',dirname(__FILE__)).'/';
//#################=====包含常用类-函数文件=====#################//
include($pe['path_root'].'/include/class/db.class.php');
include($pe['path_root'].'/include/class/page.class.php');
include($pe['path_root'].'/include/class/cache.class.php');
include($pe['path_root'].'/include/function/global.func.php');
include($pe['path_root'].'/include/function/extention.func.php');
$cache_setting = cache::get('setting');
//#################=====整合相关设置=====#################//
define('WP_SITE','http://'.$pe['wp_site'].'/');
define('CPS_SITE','http://'.$pe['cps_site'].'/');
define('PAY_SITE',$pe['host_root']);
define('TIME',time());

$pe['host_tpl'] = "{$pe['host_root']}template/{$cache_setting['web_tpl']['setting_value']}/{$module}/";
$pe['path_tpl'] = "{$pe['path_root']}template/{$cache_setting['web_tpl']['setting_value']}/{$module}/";
if (get_magic_quotes_gpc()) {
	!empty($_GET) && extract(pe_trim(pe_stripslashes($_GET)), EXTR_PREFIX_ALL, '_g');
	!empty($_POST) && extract(pe_trim(pe_stripslashes($_POST)), EXTR_PREFIX_ALL, '_p');
}
else {
	!empty($_GET) && extract(pe_trim($_GET),EXTR_PREFIX_ALL,'_g');
	!empty($_POST) && extract(pe_trim($_POST),EXTR_PREFIX_ALL,'_p');
}

session_start();
!empty($_SESSION) && extract(pe_trim($_SESSION),EXTR_PREFIX_ALL,'_s');
!empty($_COOKIE) && extract(pe_trim(pe_stripslashes($_COOKIE)),EXTR_PREFIX_ALL,'_c');

//连接数据库开始吧
$db = new db($pe['db_host'], $pe['db_user'], $pe['db_pw'], $pe['db_name'], $pe['db_coding']);

/*
//二级域名记录cookie并跳转
$cache_package = cache::get('package');
if (stripos($pe['host_root'], $pe['domain_mark']) === false) {//解析绑定其他域名
	
	foreach ($cache_package as $k => $v) {
		if (stripos($pe['host_root'], $v['package_domainmark']) !== false) {
			$domain_mark = $v['package_domainmark'];
			break;
		}
	}
}
else {
	$domain_mark = $pe['domain_mark'];
}
$domain_pos = stripos($pe['host_root'], $domain_mark);
$domain_sub = substr($pe['host_root'], 7, $domain_pos-8);
if ($domain_sub != 'www' && !empty($domain_sub) && $domain_pos != 7) {
	setcookie('domain_sub', $domain_sub, 0, '/');
	//$url_now = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];
	//pe_goto(str_ireplace("{$domain_sub}.{$pe['domain_mark']}", "{$pe['domain_mark']}", $url_now));
}
*/

//推广用户名放url参数里记录cookie并跳转
if(isset($_GET['u']) && !empty($_GET['u']))
{
	setcookie('domain_sub', $_GET['u'], 0, '/');//记录推荐人用户名
	$domain_sub=$_GET['u'];
}
if (in_array($module, array('index', 'admin'))) {
//邮件群发计划任务
pe_lead('hook/qunfa.hook.php');
qunfa_emailtpl();
//套餐计划任务
$db->pe_update('packagelog', " and `packagelog_etime` <= '".time()."' and `packagelog_state`=1", "`packagelog_state`=0");
}
?>