<?php
if (!defined('IN_59MIAO'))
{
	exit('Access Defined');
}
//控制器基类
class Action {
	protected $_tpl = null;
	protected $_model = null;
	protected $_redirect = null;
	protected $_setting=null;
	protected $_site_title=null;
	protected $_site_titleb=null;
	protected $_site_url=null;
	protected $_site_keywords=null;
	protected $_site_description=null;
	protected $_login_checkcode=null;
		
	protected function __construct() {
		$this->_tpl = TPL::getInstance();
		$this->_model = Factory::setModel();
		$this->_redirect = Redirect::getInstance($this->_tpl);
		$this->GetSetting();		
		$this->_tpl->assign('tpl_style',SMARTY_FRONT);
		$this->_tpl->assign('rewrite',REWRITE);
		//用于前台tab
		if(isset($_GET['a'])){
			$this->_tpl->assign('a',trim($_GET['a']));
		}
		//伪静态
		if(REWRITE){
			//伪静态后缀
			$this->_tpl->assign('suffix',REWRITE_SUFFIX);
			//分配伪静态变量	
			$this->_tpl->assign('index',INDEX);
			$this->_tpl->assign('mall',MALL);
			$this->_tpl->assign('sellerinfo',SELLERINFO);
			$this->_tpl->assign('all',ALL);
			$this->_tpl->assign('b2c_category',B2C_CATEGORY);
			$this->_tpl->assign('tao_category',TAO_CATEGORY);
			$this->_tpl->assign('bitem',BITEM);
			$this->_tpl->assign('item',ITEM);
			$this->_tpl->assign('promo',PROMO);
			$this->_tpl->assign('artile',ARTILE);
			$this->_tpl->assign('artile_list',ARTILELIST);					
			$this->_tpl->assign('artile_content',ARTILE_CONTENT);		
			$this->_tpl->assign('shop',SHOP);
			$this->_tpl->assign('search',SEARCH);
		}
	}
	
	protected function page($_pagesize = PAGE_SIZE) {	
		$_page = new Page($this->_model->total(),$_pagesize);
		$this->_model->setLimit($_page->getLimit());
		$this->_tpl->assign('page',$_page->showpage());
		$this->_tpl->assign('num',($_page->getPage()-1)*$_pagesize);
	}
	
	public function run() {
		$_m = isset($_GET['m']) ? $_GET['m'] : 'index';
		method_exists($this, $_m) ? eval('$this->'.$_m.'();') : $this->index();
	}
	
	//获取网站配置信息
	public function GetSetting(){
		$setting=new SettingbasicModel();
		$this->_setting=$setting->findOne();		
		$this->_site_url=$this->_setting[0]->site_url;
		$this->_site_title=$this->_setting[0]->site_title;
		$this->_site_titleb=$this->_setting[0]->site_titleb;
		$this->_site_keywords=$this->_setting[0]->site_keywords;
		$this->_site_description=$this->_setting[0]->site_description;				
		$this->_login_checkcode=$this->_setting[0]->login_checkcode;	//是否开启登录验证码
		
		
		$this->_setting[0]->site_tongji=htmlspecialchars_decode($this->_setting[0]->site_tongji);
		//echo $this->_setting->site_tongji.'<br>';
		
		//print_r($this->_setting);
		define('DOMAIN',$this->_site_url);
		$this->_tpl->assign('domain',$this->_site_url);	
		$this->_tpl->assign('setting',$this->_setting[0]);
	}
}
?>