<?php
class AnnounceAction extends GlobalAction{
	
    

    /**
	 * 栏目列表
	 *
	 */
    public function index(){

		$Announce = D("Announce");
		import("@.ORG.Page"); //导入分页类
		$count = $Announce->count();//计算总数
		$p = new page($count,15);
		$list = $Announce->limit($p->firstRow.','.$p->listRows)->findAll();
		$page = $p->show();
		$this->assign("page",$page);
		$this->assign('list',$list);
		$this->display();
    }
	



    /**
     * 添加信息
	 *
     */
    public function add(){

		//表单提交
		if($this->isPost()){

			$Announce = D('Announce');
			if($Announce->create()){
				$Announce->posttime = time();

				if(false !== $Announce->add()){
					$this->success('添加成功');
				}
				else{
					$this->error('添加失败');
				}
			}
			else{
				$this->error($Announce->getError());
			}
		}else{
			//显示类目
			$ProjectClassid = D('ProjectClassid');
			$list = $ProjectClassid->findAll();
			$this->assign('list',$list);
			$this->display();
		}
    }
	
    /**
     * 修改
	 *
     */
    public function edit(){
		
		//表单提交
		if($this->isPost()){
			$Help = D('Announce');
			if($Help->create()){
				if(false !== $Help->save()){
					$this->assign('jumpUrl',$_POST['returnurl']);
					$this->success('更新成功');					
				}
				else{
					$this->error('没有任何更新');
				}
			}
			else{
				$this->error($Help->getError());
			}
		}
		else{
			//修改栏目
			if(!empty($_GET['id'])){
				$Help = D('Announce');
				$data= $Help->getById($_GET['id']);
				if($data){
					//显示类目
					$ProjectClassid = D('ProjectClassid');
					$list = $ProjectClassid->findAll();
					$this->assign('list',$list);
					$this->assign('returnurl',$_SERVER['HTTP_REFERER']);
					$this->assign('data',$data);
					$this->display();
				}
				else{
					exit('编辑项不存在');
				}		
			}
			else{
				exit('编辑项不存在');
			}
		}
    }

    /**
     * 删除
	 *
     */
	 public function delete(){
		
		if(!empty($_GET['id'])){
			$Announce = D('Announce');
			if($Announce->delete($_GET['id'])) {
				$this->success('删除成功!');
			}
			else{
				$this->error('删除出错!');
			}
		}
		else{
			$this->error('删除项不存在');
		}
	 }
}
?>