<?php
/**
 * Copy Right IJH.CC
 * Each engineer has a duty to keep the code elegant
 * $Id$
 */
if(!defined('__CORE_DIR')){
    exit("Access Denied");
}
class Ctl_Cate extends Ctl
{
	public function cate()
    {
    	$cates = array();
        if($items = K::M('cate/cate')->fetch_all()){
            foreach($items as $k=>$val){
                if($val['parent_id'] == 0){
                    $cates[$k] = $val; 
                }
            }
            foreach($cates as $k=>$val){
                foreach($items as  $kk=>$v){
                    if($v['parent_id'] == $val['cate_id']){
                        if($v){
                            $cates[$k]['cates'][] = $v;
                        }else{
                            $cates[$k]['cates'] = array();
                        }
                    }
                }      
            }
            
        }else{
            $cates = array();
        }
        $this->msgbox->add('success');
        $this->msgbox->set_data('data',array('items'=>array_values($cates)));
        
    }
    
    public function staff_cate(){
        if($items = K::M('cate/cate')->fetch_all()){
            foreach ($items as $k=>$val){
                if($val['parent_id'] == 0){
                    unset($items[$k]);
                }
            }
        }
        if(!$items){
            $items = array();
        }
        $this->msgbox->add('success');
        $this->msgbox->set_data('data',array('items'=>array_values($items)));
    }
    
}