<?php
class HelpAction extends GlobalAction{
	
    /**
	 * 栏目列表
	 *
	 */
    public function classindex(){

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

    /**
	 * 添加栏目
	 *
	 */
    public function addclass(){

		//表单提交
		if($this->isPost()){
			$HelpCategory = D('HelpCategory');
			if($HelpCategory->create()){
				if(false !== $HelpCategory->add()){
					$this->success('添加成功');
				}
				else{
					$this->error('添加失败');
				}
			}
			else{
				$this->error($HelpCategory->getError());
			}
		}
		else{
			//添加信息
			$this->display();
		}
    }

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

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

		$Help = D("Help");
		import("@.ORG.Page"); //导入分页类
		$count = $Help->count();//计算总数
		$p = new page($count,15);
		$list = $Help->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()){

			$Help = D('Help');
			if($Help->create()){
				$Help->addtime = time();
				if(false !== $Help->add()){
					$this->success('添加成功');
				}
				else{
					$this->error('添加失败');
				}
			}
			else{
				$this->error($Help->getError());
			}
		}else{
			//显示类目
			$HelpCategory = D('HelpCategory');
			$list = $HelpCategory->findAll();
			$this->assign('list',$list);
			$this->display();
		}
    }
	
    /**
     * 修改
	 *
     */
    public function edit(){
		
		//表单提交
		if($this->isPost()){
			$Help = D('Help');
			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('Help');
				$data= $Help->getById($_GET['id']);
				if($data){
					//显示类目
					$HelpCategory = D('HelpCategory');
					$list = $HelpCategory->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'])){
			$Help = D('Help');
			if($Help->delete($_GET['id'])) {
				$this->success('删除成功!');
			}
			else{
				$this->error('删除出错!');
			}
		}
		else{
			$this->error('删除项不存在');
		}
	 }
}
?>