<?php
class AdmincpAction extends AdmincomAction{
	public function taglist(){
		$tag=M('topic_tag');
		import("ORG.Util.Page");
		$count=$tag->count();
		$page=new Page($count,20);
		$show=$page->show();
		$list=$tag->order('id desc')->limit($page->firstRow.','.$page->listRows)->select();
		$this->assign('list',$list);
		$this->assign('page',$show);
		$this->display();
    }
	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();
	}
	public function blog()
	{
		load('extend');
		$sc=M('topic');
		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();
	}
	public function saveaddtag()
	{
		$tagname=$_POST['tagname'];
		$tag=M('topic_tag');
		$rs=$tag->where("title='".$tagname."'")->find();
		if($rs)
		{
			$this->error('此话题已经存在');
		}
		else
		{
			$data['title']=$tagname;
			$data['create_time']=time();
			$data['create_user']=getUserID();
			if($tag->add($data))
			{
				$this->success('保存成功');
			}
			else
				$this->error('保存失败');
		}
	}
	public function group()
	{
		$tg=M('topic_group');
		import("ORG.Util.Page");
		$count=$tg->count();
		$page=new Page($count,20);
		$show=$page->show();
		$list=$tg->order('id desc')->limit($page->firstRow.','.$page->listRows)->select();
		$this->assign('list',$list);
		$this->assign('page',$show);
		$this->display();
	}
	public function infogroup()
	{
		$id=$_GET['id'];
		if(checkId32($id))
		{
			$tg=M('topic_group');
			$rs=$tg->find($id);
			if($rs)
				$this->assign('rs',$rs);
			else
				$this->error('error id');
		}
		else
			$this->error('error id');
		$this->display('groupinfo');
	}
	public function savegroup()
	{
		$gname=$_POST['gname'];
		$sort=$_POST['sort'];
		$icon=$_POST['icon'];
		$id=$_POST['id'];
		$data['id']=$id;
		$data['groupname']=$gname;
		$data['sort']=$sort;
		$data['icon']=$icon;
		$tg=M('topic_group');
		if($tg->save($data))
			$this->success('保存成功');
		else
			$this->error('保存失败');
	}
	public function delgroup()
	{
		$id=$_GET['id'];
		$tg=M('topic_group');
		$rs=$tg->find($id);
		if($rs['is_default']==1)
			$this->error('默认群组不能删除，可以改名');
		else
		{
			if($tg->delete($id))
				$this->success('删除成功');
			else
				$this->error('删除失败');
		}
	}
	public function deltag()
	{
		$id=$_GET['id'];
		$tg=M('topic_tag');
		$rs=$tg->find($id);
		if($tg->delete($id))
			$this->success('删除成功');
		else
			$this->error('删除失败');
	}
	public function saveaddgroup()
	{
		$gname=$_POST['gname'];
		$sort=$_POST['sort'];
		$icon=$_POST['icon'];
		$tg=M('topic_group');
		$data['groupname']=$gname;
		$data['sort']=$sort;
		$data['icon']=$icon;
		$data['time']=time();
		$data['create_user']=getUserID();
		$data['is_default']=0;
		$data['parentid']=0;
		if($tg->add($data))
			$this->success('保存成功');
		else
			$this->error('保存失败');
	}
	public function delblog()
	{
		$id=$_GET['id'];
		if(!checkId32($id))
		{
			$this->error('error id');
		}
		$tp=M('topic');
		$rs=$tp->find($id);
		if($rs)
		{
			$types=$rs['parentid']==0?1:2;
			//删除对应的回复
			if($types==2)
			{
				$tp->where('parentid='.$rs['parentid'])->delete();
			}
			delUserScore($rs['userid'],$types,getUserAccount()."删除微博id=".$id.",parentid=".$rs['parentid']);
		}
		if($tp->delete($id))
			$this->success('删除成功');
		else
			$this->error('删除失败');
		
	}
}
?>