ArticleAction.class.php 3.83 KB
<?php
class ArticleAction extends CommonAction {
	public $tab='Article';
	public function __construct() {
		parent::__construct();
		$this->checkLog();	//判断用户是否已经登录
	}
/**
 * 通知公告
 */
    public function index(){
    	$this->assign('authlist',$this->getPower());	//用户权限
		// $order='Article.sort=0,sort asc,id desc';	//注意排序
		$order='dotop desc,sort asc,addtime desc,id desc';
		$where['isshow'] = array('eq',1);
		$model = M($this->tab);
		$field = array('id','uid','title','dotop','dotopend','dotopday','addtime','clicknum');
		$data = $this->_getLists($model,$where,$order,$field,12,'Pages3',array('header'=>'<li style="border:none;">共%totalRows%条记录','pages'=>'%nowPage%/%totalPages%页 </li>','prev'=>'<上一页','next'=>'下一页>','first'=>'首页','last'=>'尾页','theme'=>'%header% %pages% %prePage% %linkPage% %nextPage% %end%'));
		$this->assign('list',$data['list']?$data['list']:array());	//列表
		$this->assign('page',$data['page']);	//分页
		$this->assign('p',$data['p']);	//当前页数
		$this->assign('page_title','通知公告');
		$this->assign('empty','<tr><td colspan="7" style="padding-left:15px;font-size:14px;">暂无相关信息!</td></tr>');
		$this->display();
	}
 /**
  * 修改通知公告
  */
	public function edit(){
		$id=I('id',0,'intval');
		if(!$id){
			$this->error('参数有误!');
		}
		$Article=D($this->tab);
		if($this->isPost()){
			if($Article->create()){
				$Article->title=htmlspecialchars($Article->title,ENT_QUOTES);
				$lastid=$Article->save();
				if($lastid){
					$this->success('通知公告修改成功',U('Article/index',array('p'=>I('p',1,'intval'))));
				}else{
					$this->error('通知公告修改失败');
				}
			}else{
				$this->error($Article->getError());
			}
		}else{
			
			$data=$Article->where('id='.$id)->find();
			$this->assign('data',$data);
			$this->display();
		}		
	}
/**
 * 发布通知公告
 */
	public function add(){
		//最大排序值
		// $maxp['tid']=array('in',$this->AllCatid($tid,1,'Category'));
		// $maxsort=$Article->where($maxp)->max('sort');
		if($this->isPost()){
			$Article=D($this->tab);
			if($Article->create()){
				$Article->title=htmlspecialchars($Article->title,ENT_QUOTES);
				$lastid=$Article->add();
				 //echo $Article->getLastSql();
				// exit;
				if($lastid){
					$this->success('通知公告发布成功',U('index'));
				}else{
					$this->error('通知公告发布失败');
				}
			}else{
				$this->error($Article->getError());
			}
		}else{
			$this->display();
		}
	}

/**
 * 删除通知公告
 */
	public function delete(){
		$id=I('id',0,'intval');
		if(!$id){
			$this->error('参数有误!');
		}
		$where['id'] = array('eq',$id);
		$back=M($this->tab)->where($where)->delete();
		if($back){
			$this->success('删除成功!',U('index',array('p'=>I('p',1,'intval'))));
		}else{
			$this->error('删除失败!');
		}
	}


	//查看详情通知公告-回收站
	public function Look(){
		$id=I('id',0,'intval');
		if(!$id){
			$this->error('参数有误!');
		}
		$where['id'] = array('eq',$id);
		$where['isshow'] = array('eq',1);
		$m = M($this->tab);
		$arr = $m->where(array('id'=>array('eq',$id)))->find();
		$this->assign('data',$arr);
		if($arr){
			$m->where($where)->setInc('clicknum');			
		}
		$this->display();
	}
/**
 * zjp
 * ajax 通知公告审核
 */
	public function Shenhe(){
		$Article=D($this->tab);
		$is=$Article->where('id='.$this->_param('id'))->getField('isshow');
		if($is==1){
			$isnew=0;
		}else{
			$isnew=1;
		}
		$aa=$Article->where('id='.$this->_param('id'))->setField('isshow',$isnew);
		if($aa){
			$msg['success']=true;
			$msg['msg']='修改成功';
			$msg['val']=$isnew;
		}else{
			$msg['success']=false;
		}
		echo json_encode($msg);
	}
}