<?php
if(!defined('IN_CRONLITE'))exit();
$title="注册用户管理";
$breadcrumb='<li><a href="index.php?mod=user"><i class="icon fa fa-home"></i>首页</a></li>
<li><a href="index.php?mod=admin"><i class="icon fa fa-cog"></i>后台管理</a></li>
<li class="active"><a href="#"><i class="icon fa fa-user"></i>注册用户管理</a></li>';

$my=isset($_GET['my'])?$_GET['my']:null;

if ($isadmin!=1)
{
header("location:index.php");exit;
}
else
{
include TEMPLATE_ROOT."head.php";

echo '<div class="col-md-12" role="main">';

if(isset($_GET['daili'])) $link='&daili=1';

if($my==null){

if(isset($_GET['kw'])) {
	$sql=" `user` LIKE '%{$_GET['kw']}%' or `userid`='{$_GET['kw']}' or `email`='{$_GET['kw']}' or `qq`='{$_GET['kw']}'";
	$link='&kw='.$_GET['kw'];
	$rownum='包含'.$_GET['kw'].'的共有';
} elseif(isset($_GET['id'])) {
	$sql=" `userid`='{$_GET['id']}'";
	$link='';
	$rownum='本站共有';
} elseif(isset($_GET['daili'])) {
	$sql=" `daili`='1'";
	$rownum='本站共有代理用户';
} else {
	$sql=' 1';
	$link='';
	$rownum='本站共有';
}

$numrows = $DB->count("select count(*) from ".DBQZ."_user where".$sql);

echo '<h3>注册用户管理</h3>';
echo '<div class="alert alert-info">'.$rownum.$numrows.'个用户 [<a href="index.php?mod=reg">添加一个用户</a>]</div>';

if(isset($_GET['daili'])){
	echo '<form action="index.php?mod=admin-user&my=daili_add" class="form-inline" method="post">
		<div class="form-group">设置UID为<input type="text" style="width:50px;" name="uid">的会员为代理.<input type="submit" class="btn btn-primary" name="submit" value="确定"></div>
		</form>
';
}
$pagesize=$conf['pagesize'];
$pages=ceil($numrows/$pagesize);
$page=isset($_GET['page'])?intval($_GET['page']):1;
$offset=$pagesize*($page - 1);

?>
<style>
.table-responsive>.table>tbody>tr>td,.table-responsive>.table>tbody>tr>th,.table-responsive>.table>tfoot>tr>td,.table-responsive>.table>tfoot>tr>th,.table-responsive>.table>thead>tr>td,.table-responsive>.table>thead>tr>th{white-space: pre-wrap;}
</style>
<div class="panel panel-default table-responsive">
<table class="table table-hover">
	<thead>
		<tr>
			<th>UID</th>
			<th>用户名</th>
			<th>注册及登录信息</th>
			<th>数量</th>
		</tr>
	</thead>
	<tobdy>
<?php

$rs=$DB->query("select * from ".DBQZ."_user where{$sql} order by userid desc limit $offset,$pagesize");
$i=0;
while ($myrow = $DB->fetch($rs))
{
$i++;
$pagesl=$i+($page-1)*$pagesize;
if($myrow['daili']==1)$dailicon='<font color="red">[代理]</font>RMB：'.$myrow['daili_rmb'];
if($myrow['vip']!=0)$vipcon='<font color="red">[VIP]</font>';
echo '<tr><td style="width:20%;"><b>'.$myrow['userid'].'</b><br/><a href="index.php?mod=admin-user&my=del&uid='.$myrow['userid'].$link.'">删除用户</a></td><td style="width:30%">用户名:<a href="index.php?mod=admin-user&my=user&uid='.$myrow['userid'].$link.'">'.$myrow['user'].'</a>'.$vipcon.'<br/>'.$dailicon.'</td><td style="width:30%">注册日期:<font color="blue">'.$myrow['date'].'</font><br>最后登录:<font color="blue">'.$myrow['last'].'</font></td><td style="width:20%"><a href="index.php?mod=syslist&userid='.$myrow['userid'].'">任务</a>:'.($myrow['qqjobnum']+$myrow['signjobnum']+$myrow['wzjobnum']).'(<a href="index.php?mod=admin-user&my=clear&table=qqjob&uid='.$myrow['userid'].$link.'">清空</a>)<br/><a href="index.php?mod=qqlist&userid='.$myrow['userid'].$link.'">ＱＱ</a>:'.$myrow['qqnum'].'(<a href="index.php?mod=admin-user&my=qkqq&uid='.$myrow['userid'].$link.'">清空</a>)</td></tr>';
unset($dailicon);
unset($vipcon);
}
?>
	</tbody>
</table>
</div>

<?php
echo '<ul class="pagination">';
$first=1;
$prev=$page-1;
$next=$page+1;
$last=$pages;
if ($page>1)
{
echo '<li><a href="index.php?mod=admin-user&page='.$first.$link.'">首页</a></li>';
echo '<li><a href="index.php?mod=admin-user&page='.$prev.$link.'">&laquo;</a></li>';
} else {
echo '<li class="disabled"><a>首页</a></li>';
echo '<li class="disabled"><a>&laquo;</a></li>';
}
$start=$page-10>1?$page-10:1;
$end=$page+10<$pages?$page+10:$pages;
for ($i=$start;$i<$page;$i++)
echo '<li><a href="index.php?mod=admin-user&page='.$i.$link.'">'.$i .'</a></li>';
echo '<li class="disabled"><a>'.$page.'</a></li>';
for ($i=$page+1;$i<=$end;$i++)
echo '<li><a href="index.php?mod=admin-user&page='.$i.$link.'">'.$i .'</a></li>';
if ($page<$pages)
{
echo '<li><a href="index.php?mod=admin-user&page='.$next.$link.'">&raquo;</a></li>';
echo '<li><a href="index.php?mod=admin-user&page='.$last.$link.'">尾页</a></li>';
} else {
echo '<li class="disabled"><a>&raquo;</a></li>';
echo '<li class="disabled"><a>尾页</a></li>';
}
echo '</ul>';
#分页
}
}
if($my=='user'){
$userid=$_GET['uid'];
$row=$DB->get_row("select * from ".DBQZ."_user where userid='$userid' limit 1");

echo '<div class="panel panel-primary">
<div class="panel-heading"><h3 class="panel-title">用户资料</h3></div>';
echo '<div class="panel-body">
<div class="col-md-6 col-sm-12">
<b>UID：</b>'.$row['userid'].' (<a href="index.php?mod=admin-user&my=del&uid='.$userid.'">删除该用户</a>)';
if(in_array($row['userid'], explode('|', $conf['adminid'])) || $row['userid']==1)$isadmin=1;
else $isadmin=0;
if($row['vip']==1){
	if(strtotime($row['vipdate'])>time()){
		$isvip=1;
		$vipstatus='到期时间:<font color="green">'.$row['vipdate'].'</font>';
	}else{
		$isvip=0;
		$vipstatus='<font color="red">非 VIP</font>';
	}
}elseif($row['vip']==2){
	$isvip=2;
	$vipstatus='<font color="green">永久 VIP</font>';
}else{
	$isvip=0;
	$vipstatus='<font color="red">非 VIP</font>';
}
if($row['daili']==1){
	$isdaili=1;
}else{
	$isdaili=0;
}
echo '<br><b>用户名：</b>'.$row['user'].'<br><b>用户组：</b>'.usergroup().'<br><b>密码：</b>'.$row['pass'].'<br><b>邮箱：</b>'.$row['email'].'<br>'.($row['qq']?'<b>ＱＱ：</b>'.$row['qq'].'&nbsp;<a target="_blank" href="http://wpa.qq.com/msgrd?v=3&uin='.$row['qq'].'&site=qq&menu=yes"><img border="0" src="http://wpa.qq.com/pa?p=2:'.$row['qq'].':51" alt="点击这里给我发消息" title="点击这里给我发消息"/></a><br>':null).($row['phone']?'<b>手机：</b>'.$row['phone'].'<br>':null).'<b>注册日期：</b>'.$row['date'].'<br><b>最后登录：</b>'.$row['last'].'<br><b>注册IP：</b><a href="http://wap.ip138.com/ip_search138.asp?ip='.$row['zcip'].'" target="_blank">'.$row['zcip'].'</a><br><b>登录IP：</b><a href="http://wap.ip138.com/ip_search138.asp?ip='.$row['dlip'].'" target="_blank">'.$row['dlip'].'</a></div>';
echo '<div class="col-md-6 col-sm-12">';
if(OPEN_QQOL==1)echo '<b>ＱＱ数量：</b>'.$row['qqnum'].'(<a href="index.php?mod=qqlist&userid='.$userid.'">管理</a>|<a href="index.php?mod=set&my=qkqq&uid='.$userid.'">清空</a>)<br>
<b>ＱＱ任务数量：</b>'.$row['qqjobnum'].'(<a href="index.php?mod=qqlist&userid='.$userid.'">管理</a>|<a href="index.php?mod=admin-user&my=clear&table=qqjob&uid='.$userid.'">清空</a>)<br>';
if(OPEN_SIGN==1)echo '<b>签到任务数量：</b>'.$row['signjobnum'].'(<a href="index.php?mod=list-sign&userid='.$userid.'">管理</a>|<a href="index.php?mod=admin-user&my=clear&table=signjob&uid='.$userid.'">清空</a>)<br>';
if(OPEN_CRON==1)echo '<b>网址任务数量：</b>'.$row['wzjobnum'].'(<a href="index.php?mod=syslist&userid='.$userid.'">管理</a>|<a href="index.php?mod=admin-user&my=clear&table=wzjob&uid='.$userid.'">清空</a>)<br>';
if($conf['peie_open'])echo '<b>配额数量：</b><font color="orange">'.$row['peie'].'</font><br>';
echo '<b>'.$conf['coin_name'].'：</b><font color="red">'.$row['coin'].'</font><br>';
echo '<b>VIP状态：</b>'.$vipstatus.'</div>
</div>';

echo '<div class="panel-heading"><h3 class="panel-title">信息修改</h3></div>';
echo '<div class="panel-body"><form action="index.php?mod=admin-user&my=edit'.$link.'" method="POST"><input type="hidden" name="userid" value="'.$row['userid'].'">
<b>是否VIP：</b><select name="isvip" default="'.$row['vip'].'"><option value="0">0_否</option><option value="1">1_是</option><option value="2">2_永久</option></select>
<br/>
<b>VIP到期时间：</b>
<input type="text" id="d11" name="vipdate" value="'.$row['vipdate'].'" onClick="WdatePicker({isShowClear:false})"><br/>
<b>'.$conf['coin_name'].'：</b>
<input type="text" name="coin" value="'.$row['coin'].'"><br/>
<b>配额数量：</b>
<input type="text" name="peie" value="'.$row['peie'].'"><br/>
<b>是否代理：</b><select name="daili" default="'.$row['daili'].'"><option value="0">0_否</option><option value="1">1_是</option></select>
<br/>
<b>代理账户余额：</b>
<input type="text" name="daili_rmb" value="'.$row['daili_rmb'].'"><br/>
<b>密码(不重置请留空)：</b>
<input type="text" name="password" value=""><br/>
<br/>
<input type="submit" class="btn btn-primary btn-block" value="确定修改"></form>
</div></div>
<script>
var items = $("select[default]");
for (i = 0; i < items.length; i++) {
	$(items[i]).val($(items[i]).attr("default"));
}
</script>';
echo '<a href="index.php?mod=admin-user'.$link.'">>>返回用户管理</a>';
}
elseif($my=='daili_add'){
$uid=$_POST['uid'];
$DB->query("UPDATE ".DBQZ."_user SET daili='1' WHERE userid='$uid'");
exit('<script>window.location.href="index.php?mod=admin-user&daili=1";</script>');
}
elseif($my=='edit'){
echo '<div class="panel panel-info"><div class="panel-heading"><h3 class="panel-title">信息修改</h3></div><div class="panel-body">';
$userid=$_POST['userid'];
$vip=$_POST['isvip'];
$vipdate=$_POST['vipdate'];
$coin=$_POST['coin'];
$peie=$_POST['peie'];
$password=$_POST['password'];
$daili=$_POST['daili'];
$daili_rmb=$_POST['daili_rmb'];
$sql=$DB->query("update `".DBQZ."_user` set `vip` ='$vip',`vipdate` ='$vipdate',`coin` ='$coin',`peie` ='$peie',`daili` ='$daili',`daili_rmb` ='$daili_rmb' where `userid`='$userid'");
if(!empty($password))$DB->query("update `".DBQZ."_user` set `pass` ='$password' where `userid`='$userid'");
if($sql){echo '修改成功！';}
else{echo '修改失败！';}
echo '<hr/><a href="index.php?mod=admin-user'.$link.'">>>返回用户管理</a></div></div>';
}

elseif($my=='del'){
echo '<div class="panel panel-info"><div class="panel-heading"><h3 class="panel-title">删除用户</h3></div><div class="panel-body">';
$userid=$_GET['uid'];
if($userid==1)exit('你不能删除管理员！');
echo '<a href="index.php?mod=admin-user&my=del_ok&uid='.$userid.$link.'">确定要删除吗？是！</a><hr/>'; 
echo '<a href="index.php?mod=admin-user'.$link.'">>>返回用户管理</a></div></div>';
}

elseif($my=='del_ok'){
if($isadmin==0)exit;
echo '<div class="panel panel-info"><div class="panel-heading"><h3 class="panel-title">删除用户</h3></div><div class="panel-body">';
$userid=$_GET['uid'];
if($userid==1)exit('你不能删除管理员！');
$sql=$DB->query("DELETE FROM ".DBQZ."_user WHERE userid='$userid'");
$DB->query("DELETE FROM ".DBQZ."_qq WHERE uid='$userid'");
$DB->query("DELETE FROM ".DBQZ."_qqjob WHERE uid='$userid'");
$DB->query("DELETE FROM ".DBQZ."_signjob WHERE uid='$userid'");
$DB->query("DELETE FROM ".DBQZ."_wzjob WHERE uid='$userid'");
if($sql){echo '删除成功！';}
else{echo '删除失败！';}
echo '<hr/><a href="index.php?mod=admin-user'.$link.'">>>返回用户管理</a></div></div>';
}

elseif($my=='clear'){//清空任务
$userid=$_GET['uid'];
$table=$_GET['table'];
echo '<div class="panel panel-info"><div class="panel-heading"><h3 class="panel-title">清空任务</h3></div><div class="panel-body">';
echo '您确认要清空用户uid '.$userid.' 的所有 '.$table.' 任务吗？清空后无法恢复！<br><a href="index.php?mod=admin-user&my=clear2&table='.$table.'&uid='.$userid.'">确认</a> | <a href="javascript:history.back();">返回</a>';
echo '</div></div>';
}
elseif($my=='clear2'){//清空任务结果
$userid=$_GET['uid'];
$table=$_GET['table'];
echo '<div class="panel panel-info"><div class="panel-heading"><h3 class="panel-title">清空任务</h3></div><div class="panel-body">';
if($DB->query("DELETE FROM ".DBQZ."_{$table} WHERE uid='{$userid}'")==true){
$DB->query("UPDATE ".DBQZ."_user SET {$table}num='0' WHERE userid='$userid'");
echo '清空成功，';
}else{
echo '清空失败，';
}
echo '<hr/><a href="index.php?mod=admin-user'.$link.'">>>返回用户管理</a></div></div>';
}
elseif($my=='qkqq'){//清空QQ
$userid=$_GET['uid'];
echo '<div class="panel panel-info"><div class="panel-heading"><h3 class="panel-title">清空ＱＱ</h3></div><div class="panel-body">';
echo '您确认要清空用户uid '.$userid.' 的所有ＱＱ吗？清空后无法恢复！<br><a href="index.php?mod=admin-user&my=qkqq2&uid='.$userid.'">确认</a> | <a href="javascript:history.back();">返回</a>';
echo '</div></div>';
}
elseif($my=='qkqq2'){//清空QQ结果
$userid=$_GET['uid'];
echo '<div class="panel panel-info"><div class="panel-heading"><h3 class="panel-title">清空ＱＱ</h3></div><div class="panel-body">';
if($DB->query("DELETE FROM ".DBQZ."_qq WHERE uid='{$userid}'")==true){
$DB->query("UPDATE ".DBQZ."_user SET qqnum='0' WHERE userid='$userid'");
echo '清空成功，<hr/><a href="index.php?mod=admin-user'.$link.'">>>返回用户管理</a></div></div>';
}else{
echo '清空失败，<hr/><a href="index.php?mod=admin-user'.$link.'">>>返回用户管理</a></div></div>';
}
}
include TEMPLATE_ROOT."foot.php";
?>