<?php
/**
 * [LJCMS] (C)2012-2099 LJdev,Inc.
 * <E-Mail：aspcms@qq.com>
 * Url http://www.liangjing.org
 *     http://www.8CMS.com
 * Update 2014.04.03
*/

class control extends oabase {
    
	public function action_run() {
            	$dept = parent::model('dept', 'oa');
               // $list=$node->get_grouplist();       
		$menu = array();
                $menu=$dept->get_menu_list();       
                $publicmodel=parent::model('public', 'oa');
		$tree = $publicmodel->list_to_tree($menu);
                $list=$dept->get_DeptGrade_list();
              
                $var_array = array(
                    'dept_grade_list'=>$list,
                    'dept_list'=>$menu,
                    'menu'=>$publicmodel->popup_tree_menu($tree),
                  );            
               unset($dept);
               TPL::assign($var_array);
	       TPL::display($this->cptpl.'dept/dept.tpl');
        }
        
        	/**编辑页面 **/
	public function action_read() {
                $id=$_REQUEST['id'];
		$node = parent::model('dept', 'oa');
		$vo = $node -> get_top_menu_data($id);
		
			if (!empty($vo)) {// 读取成功
				$return['data'] = $vo;
				$return['status'] = 1;
				$return['info'] = "读取成功";
				echo json_encode($return);
			} else {
				$return['status'] = 0;
				$return['info'] = "读取错误";
				echo json_encode($return);
			}
		
		//$this -> assign('vo', $vo);
	//	$this -> display();
		//return $vo;
	}
        public function action_add(){
             	$dept = parent::model('dept', 'oa');
                $list=$dept->get_DeptGrade_list();  
                $var_array = array(
                    'dept_grade_list'=>$list,
                  );            
               unset($dept);
               TPL::assign($var_array);
             TPL::display($this->cptpl.'dept/add.tpl');
        }

        public function action_save(){
            $arr=$_POST;
            $id=$arr['id'];
            $dept = parent::model('dept', 'oa'); 
              $arr=$this->SafeFilter($arr);
            if($arr['opmode']=='add'){
                $result = $dept->doadd($arr);
            }else{
                $result = $dept->doEdit($id, $arr);
            }
            if (true === $result) {
                $data['status']=1;
                $data['info']="编辑成功";
            }
            else {
                $data['info']="编辑失败";
            }
            echo json_encode($data);
        }
        
        public function action_winpop() {
                          	$dept = parent::model('dept', 'oa');
               // $list=$node->get_grouplist();       
		$menu = array();
                $menu=$dept->get_menu_list();       
                $publicmodel=parent::model('public', 'oa');
		$tree = $publicmodel->list_to_tree($menu);
                $var_array = array(
                    'menu'=>$publicmodel->popup_tree_menu($tree),
                  );                
                unset($dept);
		TPL::assign($var_array);
	       TPL::display($this->cptpl.'dept/winpop.tpl');
	}
        public function action_winpop2() {
		$dept = parent::model('dept', 'oa');
               // $list=$node->get_grouplist();       
		$menu = array();
                $menu=$dept->get_menu_list();       
                $publicmodel=parent::model('public', 'oa');
		$tree = $publicmodel->list_to_tree($menu);
                $var_array = array(
                    'menu'=>$publicmodel->popup_tree_menu($tree),
                  );                
                unset($dept);
		TPL::assign($var_array);
	       TPL::display($this->cptpl.'dept/winpop2.tpl');
	}
        public function action_del(){
                $id=$_POST['id'];
                $dept = parent::model('dept', 'oa');
		$list=$dept->getpidlist($id);
		if($list){
                    $data['info']='有子节点不能删除';
                    echo json_encode($data);
                    die;
		}
		$res=$dept->del($id);
                if($res){
                     $data['status']=1;
                     $data['info']='删除成功';
                } else {
                     $data['info']='操作失败';
                }
                 echo json_encode($data);
                die;
	}
    
}
?>
