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

		$AboutCategory = D("AboutCategory");
		import("@.ORG.Page"); //导入分页类
		$count = $AboutCategory->count();//计算总数
		$p = new page($count,15);
		$list = $AboutCategory->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()){
			$AboutCategory = D('AboutCategory');
			if($AboutCategory->create()){
				if(false !== $AboutCategory->add()){
					$this->success('添加成功');
				}
				else{
					$this->error('添加失败');
				}
			}
			else{
				$this->error($AboutCategory->getError());
			}
		}
		else{
			//添加信息
			$this->display();
		}
    }

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

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

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

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