<?php
if (!defined('IN_59MIAO'))
{
	exit('Access Defined');
}
//管理员控制器
class ClearcacheAction extends Action {	
	public function __construct() {
		parent::__construct();		
	}	
	//管理员列表reportbot
	public function index(){
		$alldir=$this->getdir();		
		$this->_tpl->assign('alldir',$alldir);
		$this->_tpl->display(SMARTY_ADMIN.'public/clearcache.tpl');		
	}
	//clearAllCache
	public function clearsmarty(){
		$this->_tpl->clear_all_cache();
		$this->_redirect->succ(Tool::getPrevPage(), '恭喜您清除缓存成功！');
	} 
	public function apicache(){
		if(isset($_GET['dir'])){
			$dir=ROOT_PATH.'/cache/'.$_GET['dir'];		
			if(Tool::delCache($dir)){
				$this->_redirect->succ(Tool::getPrevPage(), '恭喜您清除缓存成功！');
			}
			else{
				$this->_redirect->error('对不起清理缓存失败');
			}
		}
	}
	//清除全部缓存
	public function clearall(){
		$this->_tpl->clear_all_cache();
		if(Tool::delCache(TAO_CACHEPATH) && Tool::delCache(API_CACHEPATH)){
				$this->_redirect->succ(Tool::getPrevPage(), '恭喜您清除缓存成功！');
			}
			else{
				$this->_redirect->error('对不起清理缓存失败');
			}

	}
		
	private function getdir(){
		$dir = scandir (ROOT_PATH.'/cache' );
		$all_dir=array();		
		foreach ( $dir as $k => $v ) {
				if ($v != '..' && $v != '.') {
					$f_dir=$v;
					if($f_dir=='api59miao_cache'){
						$name='B2C数据缓存';
					}
					else{
						$name='淘宝数据缓存';
					}
					$child_dir=scandir(ROOT_PATH . '/cache/' . $v);
					$child_array=array();		
					foreach ($child_dir as $key=>$value){
						if ($value != '..' && $value != '.') {
							$child_array[]=array(
								'dir'=>$value
							);							
						}
					}
					$all_dir[]=array(
					'dir'=>$f_dir,
					'name'=>$name,
					'child_dir'=>$child_array
					);
				}
				
			}
		$all_dir=array_filter($all_dir);			
		return $all_dir;
	}
}
?>