<?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() {
            	$node = parent::model('node', 'oa');
		if (!empty($_POST['eq_pid'])) {
			$eq_pid = $_POST['eq_pid'];
		} elseif (!empty($_GET['eq_pid'])) {
			$eq_pid = $_GET['eq_pid'];
		} else {
			$eq_pid = $node ->get_nodeid();
		}
                $list=$node->get_grouplist();       
		$menu = array();
                $menu=$node->get_menu_list();       
                $publicmodel=parent::model('public', 'oa');
		$tree = $publicmodel->list_to_tree($menu, $eq_pid);
		$nodelist =$node ->get_node_list();
                $var_array = array(
                    'eq_pid'=>$eq_pid,
                    'groupList'=>$list,
                    'node_list'=>$nodelist,
                    'menu'=>$publicmodel->popup_tree_menu($tree),
                  );            
                unset($node);
		TPL::assign($var_array);
	       TPL::display($this->cptpl.'node.tpl');
        }
        
        	/**编辑页面 **/
	public function action_read() {
                $id=$_REQUEST['id'];
		$node = parent::model('node', '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(){
             TPL::display($this->cptpl.'add.tpl');
        }

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