<?php
/*
'**************************************************************************************************
' 软件名称: 盘锦DJ舞曲网CMS Content Management PjRen.Net
' 版本编号: Version 2.5
' 盘锦舞曲: http://www.pj57.com
' 官方网站: http://www.pjren.net
' 小说网站: http://www.hx39.com
' 0427DJ网: http://www.0427dj.net
' 官方论坛: http://www.tianjiazhen.com
' 版权所有: 盘锦舞曲开发团队    盘锦人(QQ:814006710)
' 郑重声明:
'    1、任何个人或组织不得在未经授权的情况下删除、修改、拷贝本软件及其他副本上一切关于版权的信息；
'    2、盘锦网络事业部保留此软件的法律追究权利
'**************************************************************************************************
*/
include "../../include/conn.php";
include "../../include/function.php";
include "../admin_loginstate.php";
include "../admin_version.php";
if(S_Ucmode==1){
include_once("../../config.uc.php");
include_once("../../client/client.php");
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>会员管理</title>
<link  href="../images/style.css" rel="stylesheet" type="text/css" />
<link href="../images/alerts.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" language="javascript">var tentpath='<?php echo S_SitePath?>';</script>
<script language="javascript" type="text/javascript" src="../../images/datepicker/wdatepicker.js"></script>
<script language="javascript" src="../js/jquery.js"></script>
<script language="javascript" src="../js/alerts.js"></script>
<script language="javascript">
$(document).ready(function(){
$("#ChkAll").click(function(){
		if($(this).attr("checked")==true){
			$("input[name='S_ID[]']").each(function(){
				$(this).attr("checked",true);									 
			})							
		}else{
			$("input[name='S_ID[]']").each(function(){
				$(this).attr("checked",false);									 
			})							
		}
});
$("#queren").click(function(){
	var S_Name=$("#S_Name").val();
	var S_PassWord=$("#S_PassWord").val();
	var S_Question=$("#S_Question").val();
	var S_Answer=$("#S_Answer").val();
	var S_QQ=$("#S_QQ").val();
	var S_Email=$("#S_Email").val();
	var S_RealName=$("#S_RealName").val();
	var S_Tel=$("#S_Tel").val();
	$("#S_Name").css("border-color","#666 #ccc #ccc #666");
	$("#S_PassWord").css("border-color","#666 #ccc #ccc #666");
	$("#S_Question").css("border-color","#666 #ccc #ccc #666");
	$("#S_Answer").css("border-color","#666 #ccc #ccc #666");
	$("#S_QQ").css("border-color","#666 #ccc #ccc #666");
	$("#S_Email").css("border-color","#666 #ccc #ccc #666");
	$("#S_RealName").css("border-color","#666 #ccc #ccc #666");
	$("#S_Tel").css("border-color","#666 #ccc #ccc #666");
	if(S_Name==""){
		$("#S_Name").css("border","1px solid red");
		$("#tishi").text("请输入帐号！");
		return false;}
	else if(isID(S_Name)==false){
		$("#S_Name").css("border","1px solid red");
		$("#tishi").text("帐号不允许特殊字符！");
		return false;}
	else if((len(S_Name)<4)||(len(S_Name)>16)){
		$("#S_Name").css("border","1px solid red");
		$("#tishi").text("帐号限制4-16位！");
		return false;}
	else if(S_PassWord==""){
		$("#S_PassWord").css("border","1px solid red");
		$("#tishi").text("请输入密码！");
		return false;}
	else if((S_PassWord.length!=32)&&((S_PassWord.length<5)||(S_PassWord.length>18))){
		$("#S_PassWord").css("border","1px solid red");
		$("#tishi").text("密码限制5-18位！");
		return false;}
	else if(S_Question==""){
		$("#S_Question").css("border","1px solid red");
		$("#tishi").text("请输入提示问题！");
		return false;}
	else if((len(S_Question)<6)||(len(S_Question)>18)){
		$("#S_Question").css("border","1px solid red");
		$("#tishi").text("提示问题限制3-18位！");
		return false;}
	else if(S_Answer==""){
		$("#S_Answer").css("border","1px solid red");
		$("#tishi").text("请输入提示答案！");
		return false;}
	else if((len(S_Answer)<6)||(len(S_Answer)>18)){
		$("#S_Answer").css("border","1px solid red");
		$("#tishi").text("提示答案限制3-18位！");
		return false;}
	else if(S_QQ==""){
		$("#S_QQ").css("border","1px solid red");
		$("#tishi").text("请输入QQ！");
		return false;}
	else if((len(S_QQ)<5)||(len(S_QQ)>18)){
		$("#S_QQ").css("border","1px solid red");
		$("#tishi").text("QQ限制5-18位！");
		return false;}
	else if(S_Email==""){
		$("#S_Email").css("border","1px solid red");
		$("#tishi").text("请输入Email！");
		return false;}
	else if(isEmail(S_Email)==false){
		$("#S_Email").css("border","1px solid red");
		$("#tishi").text("邮箱格式错误！");
		return false;}
	else if(len(S_Email)>50){
		$("#S_Email").css("border","1px solid red");
		$("#tishi").text("邮箱限制最大50位！");
		return false;}
	else if(S_RealName==""){
		$("#S_RealName").css("border","1px solid red");
		$("#tishi").text("请输入呢称！");
		return false;}
	else if(isID(S_RealName)==false){
		$("#S_RealName").css("border","1px solid red");
		$("#tishi").text("呢称不允许特殊字符！");
		return false;}
	else if(len(S_RealName)>50){
		$("#S_RealName").css("border","1px solid red");
		$("#tishi").text("呢称限制最大50位！");
		return false;}
});

$("#submit11").click(function(){
	var S_Name=$("#SearchStr").val();
	$("#SearchStr").css("border-color","#666 #ccc #ccc #666");
	if(S_Name==""){
		$("#SearchStr").css("border","1px solid red");
		return false;
		}
	})

})
function turnback(){
	window.history.go(-1);
	};

function showgr(id){
	if(id==0){
		$("#dianshu").css("display","");
		$("#daoqi").css("display","none");
		document.form1.S_UseType1.checked=true;
		};
	else if(id==1){
		$("#dianshu").css("display","none");
		$("#daoqi").css("display","");
		document.form1.S_UseType2.checked=true;
		};
	else if(id==""){
		$("#dianshu").css("display","");
		$("#daoqi").css("display","none");
		document.form1.S_UseType1.checked=true;
		};
	$("#qishiip").css("display","none");
	$("#jieshuip").css("display","none");
	$("#dengji").css("display","");
	$("#dengluip").css("display","");
	$("#denglucishu").css("display","");
	$("#dengji1").css("display","none");
	document.form1.S_UseType1.disabled=false;
};
function showds(){
	$("#dianshu").css("display","");
	$("#daoqi").css("display","none");
	};
function showdq(){
	$("#dianshu").css("display","none");
	$("#daoqi").css("display","");
	};
function del(id){
	jConfirm('您确定要删除该会员吗?', '操作提示', function(r) {
		if(r==true){
			window.location='?action=del&S_ID='+id;
			}
				});
};
function delall(){
	jConfirm('您确定要执行操作吗?', '操作提示', function(r) {
		if(r==true){form2.submit();}
		});
};
function isEmail(str){
 res = /^[0-9a-zA-Z_\-\.]+@[0-9a-zA-Z_\-]+(\.[0-9a-zA-Z_\-]+)*$/;
 var re = new RegExp(res);
 return !(str.match(re) == null);
};
function isID(str){
	res = /^(?!_)(?!.*?_$)[a-zA-Z0-9\u4e00-\u9fa5]+$/;
	var re = new RegExp(res);
	return !(str.match(re) == null);
};
function len(s) {
	var l = 0;
	var a = s.split("");
	for (var i=0;i<a.length;i++) {
	if (a[i].charCodeAt(0)<299) {
		l++;
		}
	else{
   l+=2;
		}
	}
	return l;
}
</script>
</head>
<body>
<?php
SystemPer(9);
class ui_vip{
	public function editboard($ActionUrl,$emValues){
		global $db;
		$action=SafeRequest("action","get");
		if(is_array($emValues)){
			$S_ID = $emValues[0];
			$S_Name = $emValues[1];
			$S_PassWord = $emValues[2];
			$S_Question = $emValues[3];
			$S_Answer = $emValues[4];
			$S_Group = $emValues[5];
			$S_State = $emValues[6];
			$S_QQ = $emValues[7];
			$S_Email = $emValues[8];
			$S_UseType = $emValues[9];
			$S_Coin = $emValues[10];
			$S_UseDate = $emValues[11];
			$S_RealName = $emValues[12];
			$S_LogTime = $emValues[13];
			$S_LogNum = $emValues[14];
			$S_CreateTime = $emValues[15];
			$S_RMB = $emValues[16];
		}
?>


<table width="100%" border="0" cellpadding="0" cellspacing="0"  class="tb_style">
<tr>
	<td colspan="2" class="td_title">&nbsp;&nbsp;会员用户编辑&nbsp; <label id="tishi" style="color:#F00"></label></td>
</tr>
<form action="<?php echo $ActionUrl?>" method="post" name="form1">
<tr>
    <td width="14%" height="30" align="center" class="td_border">&nbsp;&nbsp;会员帐号：</td>
    <td width="86%" height="30" class="td_border"><input name="S_Name" type="text" id="S_Name" value="<?php echo $S_Name?>" size="40"<?php if($action!="add"){echo("disabled='disabled'");}?>/>
    <font color="#FF0000"> ＊</font>
      <input name="S_ID" type="hidden" value="<?php echo $S_ID?>" />
    </td>
</tr>
<tr>
    <td width="14%" height="30" align="center" class="td_border">&nbsp;&nbsp;会员密码：</td>
    <td width="86%" height="30" class="td_border"><input name="S_PassWord" type="password" id="S_PassWord" value="<?php echo $S_PassWord?>" size="40"/>
      <font color="#FF0000">＊</font>    </td>
</tr>
<tr>
    <td width="14%" height="30" align="center" class="td_border">&nbsp;&nbsp;提示问题：</td>
    <td width="86%" height="30" class="td_border"><input name="S_Question" id="S_Question" type="text" value="<?php echo $S_Question?>" size="40" />
      <font color="#FF0000">＊</font></td>
</tr>
<tr>
    <td width="14%" height="30" align="center" class="td_border">&nbsp;&nbsp;提示回答：</td>
    <td width="86%" height="30" class="td_border"><input name="S_Answer" id="S_Answer" type="text" value="<?php echo $S_Answer?>" size="40" />
      <font color="#FF0000">＊</font>    </td>
</tr>

<tr>
    <td width="14%" height="30" align="center" class="td_border">&nbsp;&nbsp;消费模式：</td>
    <td width="86%" height="30" class="td_border"><input type="radio" name="S_UseType" id="S_UseType1" value=0 class="radio"<?php if($S_UseType==0){echo "checked='checked'";}?> onfocus="showds()"/>耗点&nbsp;&nbsp;&nbsp;
            <input type="radio" name="S_UseType" id="S_UseType2" value=1 class="radio"<?php if($S_UseType==1){echo "checked='checked'";}?> onfocus="showdq()"/>包月
    </td>
</tr>
<tr id="dianshu">
    <td width="14%" height="30" align="center" class="td_border">&nbsp;&nbsp;剩余点数：</td>
    <td width="86%" height="30" class="td_border"><input name="S_Coin" type="text" value="<?php echo $S_Coin?>" size="40" onkeyup="this.value=this.value.replace(/[^\d]/g,'')" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))"/>
      <font color="#FF0000">＊</font>    </td>
</tr>

<tr id="daoqi">
    <td width="14%" height="30" align="center" class="td_border">&nbsp;&nbsp;到期时间：</td>
    <td width="86%" height="30" class="td_border"><input name="S_UseDate" type="text" value="<?php echo $S_UseDate?>" onClick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})" size="40" />
      <font color="#FF0000">＊</font></td>
</tr>

<tr>
  <td width="14%" height="30" align="center" class="td_border">&nbsp;&nbsp;剩余金钱：</td>
  <td width="86%" height="30" class="td_border"><input name="S_RMB" id="S_RMB" type="text" value="<?php echo $S_RMB?>" size="40" /></td></tr>

<?php if($action!="add"){?>
<tr id="dengluip">
  <td width="14%" height="30" align="center" class="td_border">&nbsp;&nbsp;最后登录：</td>
  <td width="86%" height="30" class="td_border"><label><?php echo $S_LogTime?></label></td></tr>
<tr id="denglucishu"><td width="14%" height="30" align="center" class="td_border">&nbsp;&nbsp;登录次数：</td>
<td width="86%" height="30" class="td_border"><label><?php echo $S_LogNum?></label></td></tr>
<tr>
  <td width="14%" height="30" align="center" class="td_border">&nbsp;&nbsp;注册时间：</td>
  <td width="86%" height="30" class="td_border"><label><?php echo $S_CreateTime?></label></td></tr>
<?php
}
?>
<tr><td width="14%" height="30" align="center" class="td_border">&nbsp;&nbsp;是否锁定：</td>
<td width="86%" height="30" class="td_border"><input type="radio" name="S_State" id="S_State1" value=0 class="radio"<?php if($S_State==0){echo "checked='checked'";}?>/>正常&nbsp;&nbsp;&nbsp;
      <input type="radio" name="S_State" id="S_State2" value=1 class="radio"<?php if($S_State==1){echo "checked='checked'";}?>/>锁定</td></tr>
<tr>
  <td width="14%" height="30" align="center" class="td_border">&nbsp;&nbsp;会员ＱＱ：</td>
  <td width="86%" height="30" class="td_border"><input name="S_QQ" id="S_QQ" type="text" value="<?php echo $S_QQ?>" size="40" onkeyup="this.value=this.value.replace(/[^\d]/g,'')" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))"/>
  <font color="#FF0000">＊</font></td>
</tr>
<tr><td width="14%" height="30" align="center" class="td_border">&nbsp;&nbsp;会员邮箱：</td>
<td width="86%" height="30" class="td_border"><input name="S_Email" id="S_Email" type="text" value="<?php echo $S_Email?>" size="40" />
  <font color="#FF0000">＊</font></td>
</tr>
<tr><td width="14%" height="30" align="center" class="td_border">&nbsp;&nbsp;会员呢称：</td>
<td width="86%" height="30" class="td_border"><input name="S_RealName" id="S_RealName" type="text" value="<?php echo $S_RealName?>" size="40" />
  <font color="#FF0000">＊</font></td>
</tr>
<tr>
  <td height="40" class="td_border" align="right">&nbsp;</td>
  <td height="40" class="td_border" align="left"><input name="submit" type="submit" class="rb1" id="queren" value="确认编辑"/>
    &nbsp;
    <input type="reset" value="重置设置" class="rb1"/>
    &nbsp;
    <input type="button" onclick="turnback()" value="返回列表" class="rb1"/></td></tr>
<?php
	if($action=="add"){
		echo("<script language='javascript'>showgr(0);</script>");
	}
?>
</form>
</table>
<?php
}



function lists($sql,$size){
		global $db;
		$Arr=getpagerow($sql,$size);//sql,每页显示条数
		$result=$db->query($Arr[2]);
		$action=SafeRequest("action","get");
		?>
<table class="tb_style" cellspacing="0" cellpadding="0" border="0">
<form action="?action=search" method="post">
<tr>
	<td colspan="5" class="td_title">
    &nbsp;&nbsp;会员用户管理
    </td>
</tr>
<tr>
	<td width="83" valign="middle" class="td_btop3">
    &nbsp;&nbsp;会员搜索：
    </td>
    <td width="146" valign="middle" class="td_btop3">
    <input type="text" name="SearchStr" id="SearchStr"/>
    </td>
    <td width="63" valign="middle" class="td_btop3">
    <input type="submit" value="搜索" / class="rb1" id="submit11" align="left"/>
    </td>
    <td width="124" valign="middle" class="td_btop3">
    <input type="button" value="添加一个会员" onclick="window.location='?action=add';" class="rb1"/>
    </td>
    <td width="327" valign="middle" class="td_btop3">
           <input type="button" value="删除未登录会员" onclick="window.location='?action=delnologvip';" class="rb1"/>
    </td>
</tr>
</form>
</table>

<table width="100%" border="0" cellpadding="0" cellspacing="0" class="tb_style">
<form action="?action=delall" method="post" name="form2">
<tr>
    <td width="8%" height="30" bgcolor="#FFFFFF" class="td_btop3">&nbsp;编号</td>
    <td height="12%" bgcolor="#FFFFFF" class="td_btop3" width="126">&nbsp;会员帐号</td>
    <td height="10%" bgcolor="#FFFFFF" class="td_btop3" align="center" width="59">模式</td>
    <td height="15%" bgcolor="#FFFFFF" class="td_btop3" align="center" width="150">最后登录IP</td>
    <td height="10%" bgcolor="#FFFFFF" class="td_btop3" align="center" width="71">登录次数</td>
    <td height="15%" bgcolor="#FFFFFF" class="td_btop3" align="center" width="156">注册时间</td>
    <td height="10%" bgcolor="#FFFFFF" class="td_btop3" align="center" width="40">推荐</td>
    <td height="10%" bgcolor="#FFFFFF" class="td_btop3" align="center" width="40">状态</td>
    <td height="10%" bgcolor="#FFFFFF" class="td_btop3" align="center" width="81">操作</td>
</tr>
<?php
$numdate="a";
if($result){
	while ($row = $db ->fetch_array($result)){
		$numdate="b";
?>

<tr>
    <td height="30" class="td_border"><input type="checkbox" value="<?php echo $row["S_ID"]?>" name="S_ID[]" class="checkbox"/><?php echo $row["S_ID"]?>.</td>
    <td class="td_border">&nbsp;<a target="_blank" href="<?php echo userlink('index',$row["S_Name"])?>"><?php echo $row["S_Name"]?></a></td>
    <td align="center" class="td_border"><?php if($row["S_UseType"]==0){?><a href="?action=haodianvip">耗点会员</a><?php }else{?><a href="?action=baoshivip">包月会员</a><?php }?></td>
    <td align="center" class="td_border"><?php echo($row["S_LogIP"]);?></td>
    <td align="center" class="td_border"><?php echo $row["S_LogNum"]?></td>
    <td align="center" class="td_border"><?php echo $row["S_CreateTime"]?></td>
    <td align="center" class="td_border"><?php if($row["S_Tid"]==0){?><a href="?action=istid&S_ID=<?php echo $row["S_ID"]?>&S_Tid=1" title="点击推荐该会员"><img src='../../images/common/no.gif'/></a><?php }else{?><a title="点击取消推荐该会员" href="?action=istid&S_ID=<?php echo $row["S_ID"]?>&S_Tid=0"><img src='../../images/common/yes.gif'/></a><?php }?></td>
    <td align="center" class="td_border"><?php if($row["S_State"]==0){?>正常<?php }else{?><font colro="red">锁定</font><?php }?></td>
    <td align="center" class="td_border"><a href="?action=edit&S_ID=<?php echo $row["S_ID"]?>">编辑</a>&nbsp;&nbsp;<a style="cursor:pointer;" onclick="del(<?php echo $row["S_ID"]?>)">删除</a></td>
</tr>

<?php
	}
}
if($numdate=="a"){
		echo("<tr><td height='30' align='center' class='td_border' colspan='9'><b>暂无会员！</b></td></tr>");
}
?>
<tr>
    <td height="30" bgcolor="#FFFFFF" class="td_border" colspan="9"><input type="checkbox" name="ChkAll" id="ChkAll" ids="S_ID" class="checkbox"/>
    全选&nbsp;&nbsp; <input type="button" value="删除所选会员" class="rb1" onclick="delall()"/>    </td>
    </tr>
<tr>
    <td height="40" colspan="9" align="right" valign="bottom" bgcolor="#FFFFFF" class="td_border">
    <?php echo $Arr[0];?>
    </td>
</tr>
</form>
</table>
<?php
	}
}
$action=SafeRequest("action","get");
$ui=new ui_vip;
switch($action){
	case "del":
		Del();
		break;
	case "delall":
		DelAll();
		break;
	case "add" :
		Add();
		break;
	case "edit":
		Edit();
		break;
	case "saveedit":
		SaveEdit();
		break;
	case "saveadd":
		SaveAdd();
		break;
	case "search":
		Search();
		break;
	case "haodianvip":
		HaoDianVip();
		break;
	case "baoshivip":
		BaoShiVip();
		break;
	case "delnologvip":
		DelNoLogVip();
		break;
	case "savep":
		SaveP();
		break;
	case "savepa":
		SavePA();
		break;
	case "istid":
		IsTid();
		break;
	default:
		Main();
		break;
}

function Main(){
	global $ui;
	$ui->lists("select * from s_users order by S_ID asc",30);
}


function Search(){
	global $ui;
	$S_Name=SafeRequest("SearchStr","post");
	$sql="select * from s_users where S_Name like '%".$S_Name."%' order by S_Name asc";
	$ui->lists($sql,30);
}

function HaoDianVip(){
	global $ui;
	$sql="select * from s_users where S_UseType=0 Order by S_ID asc";
	$ui->lists($sql,30);
}

function BaoShiVip(){
	global $ui;
	$sql="select * from s_users where S_UseType=1 Order by S_ID asc";
	$ui->lists($sql,30);
}

function DelNoLogVip(){
	global $db;
	$sql="delete from s_users where S_LogNum=0 and S_Group=0";
	if($db->query($sql)){
		die("<script>window.location='admin_users.php'</script>");
		}
	else{
		die("<script>jAlert('会员删除失败!','操作提示',function(R){history.back();})</script>");
		}
}

function Del(){
	global $db;
	$S_ID = SafeRequest("S_ID","get");
	$sqlc="select S_Name,S_Logo from s_users where S_ID=".$S_ID." Order by S_ID desc";
	$crow=$db->getrow($sqlc);
		$fileurl="../../Upload/userlogo/big".$crow['S_Logo'];
		$fileurl1="../../Upload/userlogo/small".$crow['S_Logo'];
		     if(file_exists($fileurl)){
		              unlink($fileurl);
		     }
		     if(file_exists($fileurl1)){
		              unlink($fileurl1);
		     }
	$sqlp="select * from s_pic where S_user='".$crow['S_Name']."' Order by S_ID desc";
	$rs=$db->query($sqlp);
	$num=$db->num_rows($rs);
	     for($i=0;$i<$num;$i++){
	              $row=$db->fetch_array($rs);
                $picurl=explode("upload",$row['S_Url']);
                $picurl="/upload".$picurl[1];
		$fileurl="../..".$picurl;
		     if(file_exists($fileurl)){
		              unlink($fileurl);
		     }
                   }
	$sqld="delete from s_pic where S_user='".$crow['S_Name']."'";
	$db->query($sqld);
	$sql1="delete from s_dt where S_User='".$crow['S_Name']."'";
	$db->query($sql1);
	$sql2="delete from s_usersc where S_User='".$crow['S_Name']."'";
	$db->query($sql2);
	$sql3="delete from s_down where S_User='".$crow['S_Name']."'";
	$db->query($sql3);
	$sql4="delete from s_xiaoxi where S_Namea='".$crow['S_Name']."'  or  S_Nameb='".$crow['S_Name']."'";
	$db->query($sql4);
	$sql5="delete from s_friendzu  where S_User='".$crow['S_Name']."'";
	$db->query($sql5);
	$sql6="delete from s_friend  where S_Namea='".$crow['S_Name']."'  or  S_Nameb='".$crow['S_Name']."'";
	$db->query($sql6);
	$sql7="delete from s_look  where S_Namea='".$crow['S_Name']."'  or  S_Nameb='".$crow['S_Name']."'";
	$db->query($sql7);
	$sql8="delete from s_blog  where S_User='".$crow['S_Name']."'";
	$db->query($sql8);
	$sql9="delete from s_gbook  where S_Namea='".$crow['S_Name']."'  or  S_Nameb='".$crow['S_Name']."'";
	$db->query($sql9);
	$sql="delete from s_users where S_ID=".$S_ID;
	if($db->query($sql)){
		die("<script>window.location='admin_users.php'</script>");
		}
	else{
		die("<script>jAlert('会员删除失败!','操作提示',function(R){history.back();})</script>");
		}
}

function DelAll(){
	global $db;
	$S_ID=RequestBox("S_ID");
	$S_ID=explode(",",$S_ID);

	for($i=0;$i<count($S_ID);$i++){
	$sqlc="select S_Name,S_Logo from s_users where S_ID=".$S_ID[$i]." Order by S_ID desc";
	$crow=$db->getrow($sqlc);
		$fileurl="../../Upload/userlogo/big".$crow['S_Logo'];
		$fileurl1="../../Upload/userlogo/small".$crow['S_Logo'];
		     if(file_exists($fileurl)){
		              unlink($fileurl);
		     }
		     if(file_exists($fileurl1)){
		              unlink($fileurl1);
		     }
	$sqld="delete from s_pic where S_User='".$crow['S_Name']."'";
	$db->query($sqld);
	$sql1="delete from s_dt where S_User='".$crow['S_Name']."'";
	$db->query($sql1);
	$sql2="delete from s_usersc where S_User='".$crow['S_Name']."'";
	$db->query($sql2);
	$sql3="delete from s_down where S_User='".$crow['S_Name']."'";
	$db->query($sql3);
	$sql4="delete from s_xiaoxi where S_Namea='".$crow['S_Name']."'  or  S_Nameb='".$crow['S_Name']."'";
	$db->query($sql4);
	$sql5="delete from s_friendzu  where S_User='".$crow['S_Name']."'";
	$db->query($sql5);
	$sql6="delete from s_friend  where S_Namea='".$crow['S_Name']."'  or  S_Nameb='".$crow['S_Name']."'";
	$db->query($sql6);
	$sql7="delete from s_look  where S_Namea='".$crow['S_Name']."'  or  S_Nameb='".$crow['S_Name']."'";
	$db->query($sql7);
	$sql8="delete from s_blog  where S_User='".$crow['S_Name']."'";
	$db->query($sql8);
	$sql9="delete from s_gbook  where S_Namea='".$crow['S_Name']."'  or  S_Nameb='".$crow['S_Name']."'";
	$db->query($sql9);
	$sql10="delete from s_users where S_ID=".$S_ID[$i];
	$db->query($sql10);
	}
	die("<script>window.location='admin_users.php'</script>");
}

function Add(){
	global $ui;
	$arr=array("","","","","","","","","","","","","","","","","","","","");
	$ui->editboard("?action=saveadd",$arr);
}

function SaveAdd(){
	global $db;
	$S_Name = SafeRequest("S_Name","post");
	$S_PassWord = SafeRequest("S_PassWord","post");
	$S_Question = SafeRequest("S_Question","post");
	$S_Answer = SafeRequest("S_Answer","post");
	$S_UseType = SafeRequest("S_UseType","post");
	$S_State = SafeRequest("S_State","post");
	$S_QQ = SafeRequest("S_QQ","post");
	$S_Email = SafeRequest("S_Email","post");
	$S_UseType = SafeRequest("S_UseType","post");
	$S_Coin = SafeRequest("S_Coin","post");
	$S_UseDate = SafeRequest("S_UseDate","post");
	$S_RealName = SafeRequest("S_RealName","post");
	$S_PassWord = Md5($S_PassWord);
	$S_CreateTime = date('Y-m-d');
	$S_ChangeTime =date('Y-m-d H:i:s');
	$S_LogIP = "null";
	$S_RMB = SafeRequest("S_RMB","post");
	if($S_Name!=""){
		$sqlc="select * from s_users where S_Name=".$S_Name;
		if($db->query($sqlc)){
			$resultc=$db->query($sqlc);
			$rowc=$db->fetch_array($resultc);
			if($rowc["S_Name"]==$S_Name){
			die("<script>jAlert('用户名已存在!','操作提示',function(R){history.back();})</script>");
			}
		}
	}
	if($S_UseDate=="") $S_UseDate = date('Y-m-d');
	if($S_QQ=="") $S_QQ=0;
	if($S_Coin=="") $S_Coin=0;
	if($S_RMB=="") $S_RMB=0;
	if($S_UseType=="") $S_UseType=1;
	$sql="insert into s_users (S_RMB,S_Name,S_Logo,S_PassWord,S_QQ,S_Email,S_UseType,S_Coin,S_CreateTime,S_RealName,S_City,S_Sex,S_Question,S_Answer,S_UseDate,S_ChangeTime,S_Uid) values ('".$S_RMB."','".$S_Name."','','".$S_PassWord."','".$S_QQ."','".$S_Email."','".$S_UseType."','".$S_Coin."','".$S_CreateTime."','".$S_RealName."','未知','1','".$S_Question."','".$S_Answer."','".$S_UseDate."','".$S_ChangeTime."','')";

	if($db->query($sql)){
		die("<script>window.location='admin_users.php'</script>");
		}
	else{
		die("<script>jAlert('会员添加失败!','操作提示',function(R){history.back();})</script>");
		}
}

function Edit(){
	global $db;
	global $ui;
	$S_ID=SafeRequest("S_ID","get");
	if($S_ID==""){
		die("<script>jAlert('请选择要操作的数据?','操作提示',function(R){history.back();})</script>");
	}
	$sql="select * from s_users where S_ID=".$S_ID;
	$result=$db->query($sql);
	$row=$db->fetch_array($result);
	$S_Name = $row["S_Name"];
	$S_PassWord = $row["S_PassWord"];
	$S_Question = $row["S_Question"];
	$S_Answer = $row["S_Answer"];
	$S_Group = $row["S_Group"];
	$S_State = $row["S_State"];
	$S_QQ = $row["S_QQ"];
	$S_Email = $row["S_Email"];
	$S_UseType = $row["S_UseType"];
	$S_Coin = $row["S_Coin"];
	$S_UseDate = $row["S_UseDate"];
	$S_RealName = $row["S_RealName"];
	$S_LogTime = $row["S_LogTime"];
	$S_LogNum = $row["S_LogNum"];
	$S_CreateTime = $row["S_CreateTime"];
	$S_RMB = $row["S_RMB"];
	$Arr=array($S_ID,$S_Name,$S_PassWord,$S_Question,$S_Answer,$S_Group,$S_State,$S_QQ,$S_Email,$S_UseType,$S_Coin,$S_UseDate,$S_RealName,$S_LogTime,$S_LogNum,$S_CreateTime,$S_RMB);
	$ui->editboard("?action=saveedit&S_ID=".$S_ID,$Arr);
}

function SaveEdit(){
	global $db;
	$S_ID = SafeRequest("S_ID","post");
	$S_PassWord = SafeRequest("S_PassWord","post");
	$S_PassWorduc = SafeRequest("S_PassWord","post");
	$S_Question = SafeRequest("S_Question","post");
	$S_Answer = SafeRequest("S_Answer","post");
	$S_State = SafeRequest("S_State","post");
	$S_QQ = SafeRequest("S_QQ","post");
	$S_Email = SafeRequest("S_Email","post");
	$S_UseType = SafeRequest("S_UseType","post");
	$S_Coin = SafeRequest("S_Coin","post");
	$S_RMB = SafeRequest("S_RMB","post");
	$S_UseDate = SafeRequest("S_UseDate","post");
	$S_RealName = SafeRequest("S_RealName","post");
	$sqlc="select * from s_users where S_ID=".$S_ID;
	$resultc=$db->query($sqlc);
	$rowc=$db->fetch_array($resultc);
	if($rowc["S_PassWord"]==$S_PassWord){
		$S_PassWord=$rowc["S_PassWord"];
	}
	else{
		$S_PassWord = Md5($S_PassWord);	
	}
	if($S_UseDate=="") $S_UseDate=date('Y-m-d');
	if($S_Coin=="") $S_Coin=0;
	if($S_QQ=="") $S_QQ=0;
	if($S_RMB=="") $S_RMB=0;
	$sql="update s_users set S_PassWord='".$S_PassWord."',S_Question='".$S_Question."',S_Answer='".$S_Answer."',S_State='".$S_State."',S_QQ='".$S_QQ."',S_Email='".$S_Email."',S_UseType='".$S_UseType."',S_Coin='".$S_Coin."',S_RMB='".$S_RMB."',S_UseDate='".$S_UseDate."',S_RealName='".$S_RealName."' where S_ID=".$S_ID;
	if($db->query($sql)){
		die("<script>window.location='admin_users.php'</script>");
		}
	else{
		die("<script>jAlert('会员修改失败!','操作提示',function(R){history.back();})</script>");
		}
}

function IsTid(){
		global $db;
		$Tid=SafeRequest("S_Tid","get");
		$id=SafeRequest("S_ID","get");
		if(!IsNum($Tid)) $Tid=0;
		if(!IsNum($id)) die("<script>jAlert('id传输错误?','操作提示',function(R){history.back();})</script>");	
		$sql="update s_users set S_Tid=$Tid where S_ID=$id";
		if($db->query($sql)){
			die("<script>window.location='admin_users.php';</script>");
			}
		else{
			die("<script>jAlert('未知错误!','操作提示',function(R){history.back();})</script>");
			}		
}

include "../admin_bottom.php"; ?>
</body>
</html>