<?php
class AboutAction 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('7_1_1');
		$data = M('About');
		$list = $data->find();
		$this->assign('list',$list);
		$this->display();
	}
	public function checkInfo(){
		$this->checkUser('7_1_2');
		unset($_POST['__hash__']);
		$data = M('About');
		$_POST['address'] = stripslashes($_POST['address']);
		$_POST['about'] = stripslashes($_POST['about']);
		if(!$data->where('id=1')->save($_POST)) $this->error('修改失败!请重试 = =!');
		$this->success('修改成功! ^_^');
	}
	public function page(){
		$this->checkUser('7_2_1');
		$data = M('Page');
		$list = $data->select();
		$this->assign('list',$list);
		$this->display();
	}
	public function add(){
		$this->checkUser('7_3_1');
		$this->checkUser();
		$this->display();
	}
	public function check(){
		if(empty($_POST['name']) || empty($_POST['content']) || empty($_POST['pagename'])) $this->error('不是我强迫你，标题和内容都必须有！对吧？');	
		$this->checkUser('7_3_1');
		$data = M('Page');
		$_POST['content'] = stripslashes($_POST['content']);
		if ($data->create()){
			if(!$data->add()) $this->error("添加页面失败!= = ");
			$this->assign('jumpUrl','__URL__/page/');
			$this->success("页面添加成功!^_^");
		}else{
			$this->error($data->getError());
		}
	}
	public function edit(){
		$this->checkUser('7_3_1');
		$id = (int)$_GET['id'];
		$data = M('Page');
		$list = $data->where("id = $id")->find();
		$this->assign('list',$list);
		$this->display();
	}
	public function amend(){
		$this->checkUser('7_3_1');
		$data = M('Page');
		if ($data->create()){
			if(!$data->save()) $this->error("页面修改失败!= = ");
			$this->assign('jumpUrl','__URL__/page/');
			$this->success("页面修改成功!^_^");
		}else{
			$this->error($data->getError());
		}
	}
	public function del(){
		$this->checkUser('7_3_1');
		$data = M('Page');
		$id = (int)$_GET['id'];
		if(!$data->where("id = $id")->delete()) $this->error('删除页面失败!= =');
		$this->success("删除页面成功!");
	}
}
?>