<?php
class AdminuAction extends AdmincomAction{
	public function ulist(){
		$user=M('user');
		import("ORG.Util.Page");
		$count=$user->count();
		$page=new Page($count,20);
		$show=$page->show();
		$list=$user->order('id desc')->limit($page->firstRow.','.$page->listRows)->select();
		$this->assign('list',$list);
		$this->assign('page',$show);
		$this->display();
    }
	public function show()
	{
		$id=$_GET['id'];
		if(!checkId32($id))
		{
			echo "error ID";
			exit;
		}
		$user=M('user');
		$rs=$user->find($id);
		$this->assign('rs',$rs);
		$this->display();
	}
	public function save()
	{
		$status=$_POST['status'];
		$roleid=$_POST['roleid'];
		$id=$_POST['id'];
		$user=M('user');
		$data=array();
		$data['id']=$id;
		$data['status']=$status;
		$data['roleid']=$roleid;
		$ok=$user->save($data);
		if($ok)
			$this->success('保存成功');
		else
			$this->error('保存失败');
	}
	public function del()
	{
		$id=$_GET['id'];
		if(!checkId32($id))
		{
			$this->error('ID error');
		}
		else
		{
			$user=M('user');
			$user->delete($id);
			{
				//删除关注榜数据
				$att=M('attection');
				$att->whree('userid='.$id.' or objuser='.$id)->delete();
				//删除积分日志
				$slog=M('score');
				$slog->where('userid='.$id)->delete();
			}
			$this->success('删除成功');
		}
	}
	//delscore
	public function delscore()
	{
		$id=$_GET['id'];
		if(!checkId32($id))
		{
			$this->error('ID error');
		}
		else
		{
			$score=M('score');
			$score->delete($id);
			$this->success('删除成功');
		}
	}
	public function saveadd()
	{
		$userid=$_POST['userid'];
		$passwd=$_POST['passwd'];
		$repasswd=$_POST['repasswd'];
		$score=$_POST['score'];
		$home=$_POST['home'];
		if(empty($userid)||empty($passwd)||empty($score)||empty($home))
		{
			$this->error('所有项目必须输入');
		}
		if($passwd!=$repasswd)
		{
			$this->error('两次密码必须一致！');
		}
		$user=M('user');
		$rs=$user->where("userid='".$userid."'")->find();
		if($rs)
		{
			$this->error('此用户名已经存在!');
		}
		$rsh=$user->where("homepage='".$home."'")->find();
		if($rsh)
		{
			$this->error('该个人主页已经存在！');
		}
		load('extend');
		$da=array();
		$da['userid']=$userid;
		$da['passwd']=MD5($passwd);
		$da['score']=$score;
		$da['homepage']=$home;
		$da['status']=1;
		$da['groupid']=0;
		$da['roleid']=0;
		$da['create_time']=time();
		$da['create_ip']=get_client_ip();
		$ok=$user->add($da);
		if($ok)
			$this->success('保存成功');
		else
			$this->error('保存失败');
		
	}
	public function score()
	{
		$sc=M('score');
		import("ORG.Util.Page");
		$count=$sc->count();
		$page=new Page($count,20);
		$show=$page->show();
		$list=$sc->order('id desc')->limit($page->firstRow.','.$page->listRows)->select();
		$this->assign('list',$list);
		$this->assign('page',$show);
		$this->display();
	}
}
?>