<?php
/*
 *		Powered by YiCms 
 *
 *		mailto:yixiao@yicms.cn
 *
 */
class AdAction 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_7_1');
		$data = M('Ad');
		$list = $data->select();
		$this->assign('list',$list);
		$this->display();
	}
	public function add(){
		$this->checkUser('1_7_2');
		$this->display();
	}
	public function check(){
		$this->checkUser('1_7_2');
		$_POST['time'] = $_SERVER['REQUEST_TIME'];
		$_POST['code'] = stripslashes($_POST['code']);
		$data = M('Ad');
		if ($data->create()){
			if(!$data->add($_POST)) $this->error("添加广告失败!");
			$this->assign('jumpUrl','__URL__/index');
			$this->success("添加广告成功!^_^");
		}else{
			$this->error("添加广告失败!");
		}
	}
	public function edit(){
		$this->checkUser('1_7_2');
		$id = (int)$_GET['id'];
		$data = M('Ad');
		$list = $data->where("id = $id")->find();
		$this->assign('list',$list);
		$this->display();
	}
	public function amend(){
		$this->checkUser('1_7_2');
		unset($_POST['__hash__']);
		$_POST['time'] = (int)$_SERVER['REQUEST_TIME'];
		$_POST['code'] = stripslashes($_POST['code']);
		$data = M('Ad');
		if(!$data->save($_POST)) $this->error('修改广告内容失败!');
		$this->assign('jumpUrl','__URL__/index');
		$this->success('修改广告内容成功! ^_^');
	}
	public function del(){
		$this->checkUser('1_7_2');
		$id = (int)$_GET['id'];
		$data = M('Ad');
		if(!$data->where("id = $id")->delete()) $this->error('删除广告失败!');
		$this->success('删除广告成功!');
	}
}
?>	