<?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.'staff/index.tpl');
        }       
        
        public function action_read() {
                $id=$_REQUEST['id'];
                $where="1=1";
                if (!empty($id)) {
			$dept = parent::model('dept', 'oa');
                        $menu=$dept->get_menu_list();       
                        $publicmodel=parent::model('public', 'oa');
			$dept = $publicmodel->tree_to_list($publicmodel->list_to_tree($menu, $id));
			$dept = $publicmodel->rotate($dept);
                         if(empty($dept)){
                             $dept = "$id";
                         } else {
                             $dept = implode(",", $dept['id']) . ",$id";
                         }
			
                        $where .=" AND User.is_del='0' AND User.dept_id in ($dept)";
		}

		$keyword = $_REQUEST['keyword'];
		if (!empty($keyword)) {
                        $where .=" AND User.name LIKE '%".$keyword."%' or User.emp_no LIKE '%".$keyword."%'";
		}

		$model = parent::model('user', 'oa');
		$data = $model ->get_user_view($where);
		//echo($model->getLastSql());
		$return['data'] = $data;
		$return['status'] = 1;
		echo json_encode($return);
	}
}