<?php
class admin_templateControl extends skymvc{
	
	public function __construct(){
		parent::__construct();
	}
	
	public function onDefault(){
		$dir=ROOT_PATH."skins/";
		$hd=opendir($dir);
		$arr=array();
		$i=0;
		while(($f=readdir($hd))!=false)
		{
			if($f!="." && $f!=".."  && $f!='admin'   )
			{
				$arr[$i]['skins']=$f;
				if(file_exists($dir.$f."/"."config.php"))
				{
					require_once("{$dir}{$f}/config.php");
					$arr[$i]['skinsimg']="skins/".$f."/skins.jpg";
					$arr[$i]['skinsdir']=$f;
					$arr[$i]['skinsname']=$skinsname;
					$arr[$i]['skinsauthor']=$skinsauthor;
					$arr[$i]['skinsversion']=$skinsversion;
					$arr[$i]['skinsauthorsite']=$skinsauthorsite;
					$arr[$i]['skinstype']=$skinstype;
					if(SKINS==$f or WAPSKINS==$f )
					{
						$arr[$i]['using']="<font color='red'>正在使用</a>";					
					}else
					{	
						if($skinstype=='wap'){
							$arr[$i]['using']="<a href='".APPADMIN."?m=admin_template&a=using&wapskins=1&skins={$f}'>使用</a>";
						}else{
							$arr[$i]['using']="<a href='".APPADMIN."?m=admin_template&a=using&skins={$f}'>使用</a>";
						}
					}
				}
			}
			$i++;
		}
		$this->smarty->assign("skinslist",$arr);
		$this->smarty->display("template/index.html");
	}
	
	public function onUsing(){
		$skins=get('skins','h');
		$f=file_get_contents(ROOT_PATH."config/const.php");
		if(get('wapskins')){
			$f=preg_replace("/define\(\"WAPSKINS\".*\);/iUs","define(\"WAPSKINS\",'".$skins."');",$f,1);
		}else{
			$f=preg_replace("/define\(\"SKINS\".*\);/iUs","define(\"SKINS\",'".$skins."');",$f,1);
		}
		//$f=preg_replace("/skins=\'.*\';/iUs","skins='".$skins."';",$f);
		file_put_contents(ROOT_PATH."config/const.php",$f);
		$this->gomsg("模板切换成功");
	}
	
	public function onSave(){
		
	}
	
	
	
	
}
?>