checkAdministratorRight('3');
		
	}
	
	function index(){
		require_once (ONU_ROOT . "frame/Page.class.php");
		$admin = new AdvertAdminAction();
		$where = "where uid='{$_SESSION['user_infos']['id']}' and type=1 ";
		$page     = $_REQUEST['page']?$_REQUEST['page']:1;
		$pageSize = 5;
		$n        = ($page-1)*$pageSize;
		$pa       = "";//查询参数
		$limit = " $n,$pageSize";
		$info           = $_REQUEST['info'];
		$error			= $_REQUEST['error'];
		$uname          = $_SESSION['user_infos']['uname'];
		$list  = $admin->select_msg_list($where,$limit);
		$all_total = $admin->select_msg_count($where);
		$p = new Page($all_total,$pageSize,$pa);
		$pp = $p->fpage();
		$status_array = array(
			'1' => '开启',
			'2' => '禁用',
		);
		$this->assign('status_array',$status_array);
		$this->assign('info',$info);
		$this->assign('error',$error);
		$this->assign('page',$page);
		$this->assign("show",$pp);
		$this->assign('list',$list);
		$this->assign('uname',$uname);
		$this->display('index.html');
	}
	
	
	function add(){
		$admin = new AdvertAdminAction();
//		$_POST['msg_content'] = str_replace("\n","
",$_POST['msg_content']);
		$msg_content	= $_POST['msg_content'];
		$data['uid'] = $_SESSION['user_infos']['id'];
		$data['msg_title'] = addslashes($_POST['msg_title']);
		$data['msg_content'] = addslashes($msg_content);
		$data['status'] = $_POST['status'];
		$data['add_time'] = time();
		$data['update_time'] = time();
		$data['type'] = 1;
		if($_POST['msg_content']|| $_POST['msg_title']){
			
			if(!empty($data['msg_title']) && !empty($data['msg_content']) ){
					
				$add = $admin->add_email_msg($data);
					
				if($add){
					$info = "添加邮件模板成功";
					header("Location:/?a=email_template_admin&m=index&info=$info");
					exit();
				}else{
					$info = "添加失败";
				}
					
			}else{
				$info = "模板标题、内容均不能为空";
			}
		}
		$this->assign('data',$data);
		$this->assign('info',$info);
		$this->display('add.html');
	}
	
	
	
	function update(){
		$admin = new AdvertAdminAction();
		$id				= $_REQUEST['id'];
		
		$one_info 		= $admin->select_one_template($id);
//		$one_info['msg_content'] = str_replace("
","\n",$one_info['msg_content']);
//		$_POST['msg_content'] = str_replace("\n","
",$_POST['msg_content']);
		$msg_content	= addslashes($_POST['msg_content']);
		$data['msg_title'] = addslashes($_POST['msg_title']);
		$data['msg_content'] = $msg_content;
		$data['status'] = $_POST['status'];
		$data['update_time'] = time();
		
		if($_POST['msg_title'] || $_POST['msg_content']){
				
			if(!empty($data['msg_title']) && !empty($data['msg_content']) ){
					
				$update = $admin->update_email_msg($data, $id,$_SESSION['user_infos']['id']);
					
				if($update){
					$info = "修改邮件模板成功";
					header("Location:/?a=email_template_admin&m=index&info=$info");
					exit();
				}else{
					$info = "修改失败";
				}
					
			}else{
				$info = "模板标题、内容均不能为空";
			}
		}
	
		$one_info 		= $admin->select_one_template($id);
//		$one_info['msg_content'] = str_replace("
","\n",$one_info['msg_content']);
//		$one_info['msg_content'] =  htmlspecialchars(stripslashes($one_info['msg_content']));
		$this->assign('id',$id);
		$this->assign('one_info',$one_info);
		$this->assign('info',$info);
		$this->display('update.html');
	}
	
	//删除就是改状态为禁用
	public function delete(){
		
		$admin = new AdvertAdminAction();
		
		$id	   = $_REQUEST['id'];
		$status = $_REQUEST['status'];
		
		if(!empty($id)){
			$delete = $admin->deleteEmailTemplate($status,$id,$_SESSION['user_infos']['id']);
			$info = "禁用成功";
		}else{
			$error = "禁用失败";
		}
		
		header("Location:/?a=email_template_admin&m=index&info=$info&error=$error");
		exit();
	}
	//end class
}
?>