<?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() {
                $keyword=$_POST['keyword'];
                $eq_is_del=$_POST['eq_is_del'];
                $model = parent::model('user', 'oa');
	        $searchsql = "";
                if ($keyword!='') {
                    $searchsql .= " AND name LIKE '%".$keyword."%'";
                }
                if($eq_is_del){
                    $searchsql .= " AND is_del='$eq_is_del'";
                } else {
                    $searchsql .= " AND is_del='0'";
                }
                list($total, $data) = $model->getList(array('page'=>$this->page, 'pagesize'=>$this->pagesize, 'searchsql'=>$searchsql));
                $position_list=$model->getposition_list();
		$dept_list = $model -> getdept_list();
     
                $url = XRequest::getPhpSelf();
                $url .= '?c=User';
                $var_array = array(
                    'page'=>$this->page,
                    'nextpage'=>$this->page+1,
                    'prepage'=>$this->page-1,
                    'pagecount'=>ceil($total/$this->pagesize),
                    'pagesize'=>$this->pagesize,
                    'total'=>$total,
                    'showpage'=>XPage::index($total, $this->pagesize, $this->page, $url, 10),
                    'list'=>$data,
                    'eq_is_del'=>$eq_is_del,
                    'position_list'=>$position_list,
                     'dept_list'=>$dept_list
                );
                unset($model);
                TPL::assign($var_array);
	        TPL::display($this->cptpl.'user/user.tpl');
        }
        
        	/**编辑页面 **/
	public function action_read() {
                $id=$_REQUEST['id'];
		$model = parent::model('user', 'oa');
		$vo = $model -> 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(){
             	 $model = parent::model('user', 'oa');
                 $position_list=$model->getposition_list();
                $var_array = array(
                   'position_list'=>$position_list,
                  );            
               unset($model);
               TPL::assign($var_array);
             TPL::display($this->cptpl.'user/add.tpl');
        }

        public function action_save(){
            $arr=$_POST;
            $id=$arr['id'];
            $model = parent::model('user', 'oa'); 
            $arr=$this->SafeFilter($arr);
            if($arr['opmode']=='add'){
                $result = $model->doadd($arr);
            }else{
           //     print_r($arr);
                $result = $model->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_del(){
         
                $ids=$_POST['user_id'];
                $model = parent::model('user', 'oa'); 
                foreach($ids as $v){
                    $res=$model->del($v);
                }
                if($res){
                     $data['status']=1;
                     $data['info']='删除成功';
                } else {
                     $data['info']='操作失败';
                }
                 echo json_encode($data);
                die;
	}
        public function action_password() {
		$id = $_REQUEST['id'];
                $var_array = array(
                     'id'=>$id,
                ); 
                TPL::assign($var_array);
                TPL::display($this->cptpl.'user/password.tpl');
	}
        	//重置密码
	public function action_reset_pwd() {
		$id = $_POST['user_id'];
		$password = $_POST['password'];
		if ('' == trim($password)) {
		
                            $data['status']=0;
                            $data['info']="密码不能为空!!";

                        echo json_encode($data);
                        die;
		}
                $arr['password']= md5($password);
                $model = parent::model('user', 'oa'); 
                $result = $model->doEdit($id, $arr);

		if (false !== $result) {
                        $data['status']=1;
                        $data['info']="密码修改成功!!";
		} else {
                        $data['status']=0;
                        $data['info']="密码重置失败!";

		}
                
                        echo json_encode($data);
                        die;
	}
        public function action_del_pwd() {
		$ids = $_POST['user_id'];
                $model = parent::model('user', 'oa'); 
                    $data['pay_pwd'] = '';
                    foreach($ids as $v){
                        $res=$model->doEdit($v,$data);
                    }
                if($res){
                     $data['status']=1;
                     $data['info']='密码清除成功';
                } else {
                     $data['info']='清除密码失败';
                }
                 echo json_encode($data);
                die;
	}
    
        
        public function action_info(){
            $id= $_SESSION['USER_AUTH_KEY'];

               $model = parent::model('user', 'oa');
        	    $vo = $model -> get_info($id);
                $var_array = array(
                     'vo'=>$vo,
                ); 
                TPL::assign($var_array);
             TPL::display($this->cptpl.'user/info.tpl');
        }
                public function action_pwd() {
		$id= $_SESSION['USER_AUTH_KEY'];
               
                $var_array = array(
                     'id'=>$id,
                ); 
                TPL::assign($var_array);
                TPL::display($this->cptpl.'user/pwd.tpl');
	}
}
?>
