<?php

/*
'#################################################################
'# 程序名称：中环CMSV2.0
'# 授权方式：免费软件
'# 作者：善
'# 联系QQ:9118847
'# 作者网站:http://www.ps173.com
'# 发布时间：2015-6-10
'# 声明：欢迎广大的PHP爱好者一起共同探讨
'# 声明：各种用途均可免费使用、自由传播，但必须保留程序代码中的版权信息。
'#################################################################
 */
error_reporting(E_ERROR | E_PARSE);
//设置文件编码
header("Content-Type:text/html; charset=utf-8");
//设置中国区时间
date_default_timezone_set("PRC");

session_start();

$config = str_replace("\\", "/", dirname(__FILE__))."/init.php";

if(file_exists($config)){
	include($config);
}else{
	exit("No such file ".$config);
}

$file =get_include_path();                  
$file.=PATH_SEPARATOR.ZH."Core/";  
$file.=PATH_SEPARATOR.APP_PATH;             
set_include_path($file);

//自动加载类
function __autoload($className){
	if(substr($className, -5)=="Model"){
		include(ZH."Model/".$className.".class.php");
	}else if($className == "Smarty"){
		include(ZH."libs/Smarty.class.php");
	}else if(file_exists(ZH."libs/sysplugins/".strtolower($className).".php")){
		include(ZH."libs/sysplugins/".strtolower($className).".php");
	}else{
		include $className.".class.php";
	}
}

val::parseurl();
$spath=rtrim(substr(dirname(str_replace("\\", '/', dirname(__FILE__))), strlen(rtrim($_SERVER["DOCUMENT_ROOT"],"/\\"))), '/\\');
$GLOBALS["root"]=$spath.'/'; //Web服务器根到项目的根
$GLOBALS["public"]=$GLOBALS["root"].'Public/';        //资源目录
$GLOBALS["res"]=rtrim(dirname(dirname($_SERVER["SCRIPT_NAME"])), "/\\").'/'.ltrim(STYLE, './');
$GLOBALS["app"]=$_SERVER["SCRIPT_NAME"].'/';
$GLOBALS["url"]=$GLOBALS["app"].$_GET["m"].'/';
define("B_URL", rtrim($GLOBALS["url"], '/'));
define("B_RES", rtrim($GLOBALS["res"], '/'));
define("B_APP", rtrim($GLOBALS["app"], '/'));
define("B_ROOT", rtrim($GLOBALS["root"], '/'));
define("B_PUBLIC", rtrim($GLOBALS["public"], '/'));

$Controller=APP_PATH.ucfirst($_GET["m"])."Action.class.php";
if(file_exists($Controller)){
	$className=ucfirst($_GET["m"])."Action";
	$controler=new $className();
	$controler->run();
}else{
	val::mess('访问的模块不存在');
}

function D($className){
	$db = null;
	if(is_null($className)){
		$class = "Model";
		$db = new $class;
	}else{
		$className = strtolower($className);
		$model = val::model($className);
		$model = new $model();
		$model->settable($className);
		$db = $model;
	}

	return $db;
}

//删除目录和文件
function deldir($dirname){
		if(is_dir($dirname)){
			if($dir_handle = opendir($dirname)){
				while(false !== ($filename = readdir($dir_handle))){
					$file = $dirname.'/'.$filename;
					if($filename != '.' && $filename != '..'){
						if(is_dir($file)){
							deldir($file);
						}else{
							unlink($file);
						}
					}
				}
				closedir($dir_handle);
			}

			rmdir($dirname);
		}
	}

?>