<?php
class UserlistAction extends Action{
    public function checkUser($level){
		if(empty($_SESSION['aid'])) $this->redirect('/Admin/Index/login');
		if(!empty($level) && !in_array($level,$_SESSION['levels'])) $this->error('您没有此权限!.');
	}
	public function index(){
		$this->checkUser('4_1_1');
		$data = M('User');
		import("@.ORG.Page");
		$count = $data->where('uid != 1 ')->count('uid');
		$p     = new Page($count,20);
		if(isset($_GET['email'])){
			$email = (int)$_GET['email'];
			if($email == '0') $order = 'checkmail DESC';
			else $order = 'checkmail ASC';
		}else if(isset($_GET['money'])){
			$money = (int)$_GET['money'];
			if($money == '0') $order = 'money DESC';
			else $order = 'money ASC';
		}else if(isset($_GET['time'])){
			$time = (int)$_GET['time'];
			if($time == '0') $order = 'lasttime DESC';
			else $order = 'lasttime ASC';
		}else{
			$order = 'lasttime DESC';
		}
		$list = $data->where('uid != 1 ')->limit($p->firstRow.','.$p->listRows)->order($order)->select();
		$this->assign('list',$list);
		$page = $p->show();
		$this->assign("page",$page);
		$this->display();
	}
	public function detail(){
		$this->checkUser('4_1_2');
		$id = (int)$_GET['id'];
		$data = M('User');
		$list = $data->where("uid = $id")->find();
		$this->assign('list',$list);
		
		$data = M('User_detail');
		$detail = $data->where("uid = $id")->find();
		$detail['sex'] = $detail['sex']==0 ? '男' : '女';
		$this->assign('detail',$detail);
		
		$data = M('User_account');
		import("@.ORG.Page");
		$count = $data->where("uid = $id")->count('id');
		$apage     = new Page ($count,20);
		$account = $data->limit($apage->firstRow.','.$apage->listRows)->order('time DESC')->select();
		$this->assign('account',$account);
		//分页设置
		$apage->setConfig('header','条记录');
		$apage->setConfig('prev','<<上一页');
		$apage->setConfig('next','下一页>>');
		$apage->setConfig('first','<<第一页'); 
        $apage->setConfig('last','最后一页>>'); 
		$apage = $apage->show();
		$this->assign("apage",$apage);
		$this->display();
	}
	public function state(){
		$this->checkUser('4_1_3');
		$list['uid'] = (int)$_GET['id'];
		$list['state'] = (int)$_GET['state'];
		$data = M('User');
		if($data->save($list)) $this->success('操作成功!');
		$this->error('操作失败!');
	}
	public function del(){
		$this->checkUser('4_1_4');
		$data = M('User');
		$uid = (int)$_GET['id'];
		if($data->where("uid = $uid")->delete()) $this->success('操作成功!');
		$this->error('操作失败!');
	}
	
}
?>