<?php defined('SYSPATH') or die('No direct script access.');
class Base_Controller extends Controller{
	function __construct(){
		parent::__construct();
		@define("BASEURL",url::base());
		$db_cfg	=	Kohana::config('database.default');
		@define("DBFIX",$db_cfg['table_prefix']);
		@define("CHARSET",$db_cfg['character_set']);
		@define("DB_NAME",$db_cfg['connection']['database']);
		unset($db_cfg);
//		$this->profiler = new Profiler;
//		$this->profiler->render(TRUE);
		$this->main 	= 	new View('admin/main');
		$this->lmtpl	=	new Template();
		//用户认证
		$auth					=	new Adminauth();
		$auth->authUser();
		//加载全局变量
		$objglobal	=	new Cfg_Model();
		$cfgList	=	$objglobal->getGlobal()->result_array(false);
		foreach ($cfgList as $tmparray) {
				@define($tmparray['global_name'],$tmparray['global_value']);
		}
		//加载网站配置
		$baseCfg	=	$objglobal->getBaseCfg();
		foreach($baseCfg as $key=>$value){
			@define(strtoupper($key),$value);
		}
		//是否删除字符串
		@define("IS_DELETE","onclick=\"if(!confirm('确认是否删除')){return false;}\"");
		//设置当前位置
		$this->position();
	}
	/**显示模板**/
	function display(){
		if(@$this->view){
			ob_start();
			$this->view->render(true);
			$this->main->mainTpl	=	ob_get_contents();
			ob_end_clean();
		}
		$this->main->render(true);
		//exit();
	}
	/**
	 * 过滤POST数据 
	 *
	 * @param string $field
	 * @param string $trim
	 * @return unknown
	 */
	function filtrPost($field=false,$trim=" "){
		$value	=	$this->input->post($field);
		if(is_array($value)){
			foreach ($value as $key=>$val){
				$tmp[$key]	=	str_replace($trim,"",$val);
			}
			return $tmp;
		}
		else{
			return str_replace($trim,"",$value);
		}
	}
	function position(){
		
	}
}