<?php
class BaseAction extends Action {
	public function checkUser($level){
		if(empty($_SESSION['aid'])) $this->redirect('/Admin/Index/login');
		if(!empty($level) && !in_array($level,$_SESSION['levels'])) $this->error('您没有此权限!.');
	}
	public function index(){
		$this->checkUser('1_1_1');
		$data = M('Config');
		$list = $data->find();
		$this->assign('list',$list);
		$this->display();
	}
	public function checkBase(){
		$this->checkUser('1_1_2');
		unset($_POST['__hash__']);
		if($_FILES['logo']['error']!='4'){
			import("@.ORG.UploadFile");
			$upload = new UploadFile();
			$upload->maxSize =10485760;
			$upload->allowExts = explode(',','jpg,gif,png,jpeg');
			$upload->savePath ='Public/'; 
			$upload->thumb=true;
			$upload->imageClassPath = '@.ORG.Image';
			$upload->thumbPrefix = 'logo_';
			$upload->thumbMaxWidth = C('logowidth');
			$upload->thumbMaxHeight= C('logoheight');
			$upload->saveRule = uniqid;
			$upload->thumbRemoveOrigin = true;
			if(!$upload->upload()){
				$this->error($upload->getErrorMsg());
			}else{
				$uploadList = $upload->getUploadFileInfo();
				$data = M('Config');
				$logo = $data->field('logo')->where("id = 1")->find();
				unlink($_SERVER['DOCUMENT_ROOT'].$logo['logo']);
				$_POST['logo'] = C('URL').'/Public/logo_'.$uploadList[0]['savename'];
			}
		}
		$data = M('Config');
		$_POST['statcode'] = stripslashes($_POST['statcode']);
		$_POST['icp'] = stripslashes($_POST['icp']);
		$_POST['copy'] = stripslashes($_POST['copy']);
		if(!$data->where('id=1')->save($_POST)) $this->error('修改失败!请重试 = =!');
		$this->success('修改成功! ^_^');
	}
}
?>