<?php
namespace admin\Controller;
use Think\Controller;
class NoticeController extends CommonController {
	public function lists(){
	
	 
		$map=array();
		$key = I('request.key','','trim');
		if ($key)
		{
			$key_type = I('request.key_type',0,'intval');
			if ($key_type=='1')
			{
				$map['title'] = array('like','%'.$key.'%');
			}
			if ($key_type=='2')
			{
				$map['content'] = array('like','%'.$key.'%');
			}
		}
		$settr = I('request.settr','','intval');
		if ($settr>0)
		{
			$stime=strtotime("-".$settr." day");
			$map['addtime'] = array('GT',$stime);
		}
		$sort='sort DESC,id DESC';
		$cut=100;
		$list=D("Notice")->get_list($map,true,$sort,10,$cut,true);
		$this->assign('notice',$list);
		$this->display();
	}
	
	public function add(){
		if(IS_POST)
		{
				$notice = D("Notice");
				if (!$notice->create()){
					$this->error($notice->getError());
				}
				else
				{
					$notice->uid = session('uu.uid');
					$notice->add();
					$this->success('保存完成');				
				}
		}
		else
		{
		 	$this->display();
		}
	}
	public function edit(){
		if(IS_POST)
		{
				$notice = D("Notice");
				if (!$notice->create()){
					$this->error($notice->getError());
				}
				else
				{
					$notice->save();
					$this->success('保存完成');				
				}
		}
		else
		{
			$id=I('get.id','','intval');
			if ($id)
			{
				$notice = M("Notice");
				$map['id']=$id;
				$show=$notice->where($map)->limit(1)->find();
				$this->assign('show',$show);
				$this->display();
				//dump($show);
			}
			else
			{
			$this->error('非法请求');
			}
		}
	}
	
	public function delete(){
	
		$ids = I('request.id');
		$ids = is_array($ids)?implode(",",$ids):$ids;
		if ($ids && preg_match("/^(\d{1,10},)*(\d{1,10})$/",$ids))
		{
			$notice = M("Notice");
			$s=$notice->delete($ids);
			$this->success("成功删除{$s}条数据");
		}
		else
		{
		$this->error('请选择要删除的信息！');
		}
	
 	}
}
?>