<?php
class ProcategoryAction extends CommonAction {

	public function index(){
			$procategory=D('procategory');
			
			$list=$procategory->field("id,name,title,pid,path,concat(path,'-',id) as bpath")->order('bpath')->select();
			
			foreach($list as $key=>$value){
				$list[$key]['count']=count(explode('-',$value['bpath']));
			}
			

			$this->assign('list',$list);
			
			$this->display();
		}
		
	
    public function insert() {
        $Cate = D('Procategory');
        if ($procategory = $Cate->create()) {
            $list = $Cate->add();
            if ($list) {
                $procategory["id"] = $list;
               
                $this->success("类别增加成功！");
            }else {
                $this->error("类别增加失败!");
            }
        }else {
            $this->error($Cate->getError());
        }
    }

    public function delete() {
        $Cate = M('Procategory');
        $id = $_REQUEST[$Cate->getPk()];
        if (isset($id)) {
            $condition[$Cate->getPk()] = $id;
            if ($Cate->where($condition)->delete()) {
                $this->ajaxReturn($id, $id."分类删除成功！", 1);
            }else {
                $this->error($Cate->getError());
            }
        }
        
    }
        // 编辑数据 
    public function edit() { 
        if(!empty($_GET['id'])) { 
            $Procategory    =    M("Procategory"); 
            $vo    =    $Procategory->getById($_GET['id']); 
            if($vo) { 
                $this->assign('vo',$vo); 
                $this->display(); 
            }else{ 
                exit('编辑项不存在！'); 
            } 
        }else{ 
            exit('编辑项不存在！'); 
        } 
    } 

     // 更新数据 
    public function update() { 
        $Procategory    =    D("Procategory"); 
        if($vo = $Procategory->create()) { 
            $list=$Procategory->save(); 
            if($list!==false){ 
                $this->success('数据更新成功！'); 
            }else{ 
                $this->error("没有更新任何数据!"); 
            } 
        }else{ 
            $this->error($Procategory->getError()); 
        } 
    } 
    

}
?>