<?php
include "../../include/conn.php";
include "../../include/function.php";
include "../admin_loginstate.php";
include "../admin_version.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 src="../js/jquery.js"></script>
<script 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<6)||(S_PassWord.length>18))){
		$("#S_PassWord").css("border","1px solid red");
		$("#tishi").text("密码限制6-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("提示问题限制6-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("提示答案限制6-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;}
	else if(S_Tel==""){
		$("#S_Tel").css("border","1px solid red");
		$("#tishi").text("请输入电话！");
		return false;}
	else if((len(S_Tel)<4)||(len(S_Tel)>18)){
		$("#S_Tel").css("border","1px solid red");
		$("#tishi").text("电话限制4-18位！");
		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 showwb(){
	$("#qishiip").css("display","");
	$("#jieshuip").css("display","");
	$("#dengji").css("display","none");
	$("#dengji1").css("display","");
	$("#dengluip").css("display","none");
	$("#denglucishu").css("display","none");
};
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
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_Type = $emValues[6];
			$S_State = $emValues[7];
			$S_QQ = $emValues[8];
			$S_Email = $emValues[9];
			$S_UseType = $emValues[10];
			$S_Tel = $emValues[11];
			$S_Coin = $emValues[12];
			$S_UseDate = $emValues[13];
			$S_StartIP = $emValues[14];
			$S_LastIP = $emValues[15];
			$S_RealName = $emValues[16];
			$S_LogIP = $emValues[17];
			$S_LogNum = $emValues[18];
			$S_CreateTime = $emValues[19];
		}
?>


<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_Group" id="S_Group1" value=0 class="radio"<?php if($S_Group==0){echo "checked='checked'";}?> onfocus="showgr(<?php echo $S_UseType?>)"/>个人会员&nbsp;&nbsp;&nbsp;
            <input type="radio" name="S_Group" id="S_Group2" value=1 class="radio"<?php if($S_Group==1){echo("checked='checked'");}?> onfocus="showwb()"/>网吧会员
    </td>
</tr>

<tr id="dengji">
    <td width="14%" height="30" align="center" class="td_border">&nbsp;&nbsp;会员等级：</td>
    <td width="86%" height="30" class="td_border">
    <select name="S_Type1" id="S_Type1">
    <?php
	$sqllevel="select * from s_usersgroup where S_Group=0 order by S_ID asc";
    $results=$db->query($sqllevel);
    if($results){
		while ($row3=$db->fetch_array($results)){?>
    <option value="<?php echo $row3["S_ID"]?>" <?php if($row3["S_ID"]==$S_Type){echo("selected='selected'");}?>><?php echo $row3["S_Name"]?></option>
    <?php
		}
	}
	?>
    </select>
    </td>
</tr>

<tr id="dengji1">
    <td width="14%" height="30" align="center" class="td_border">&nbsp;&nbsp;会员等级：</td>
    <td width="86%" height="30" class="td_border">
    <select name="S_Type2" id="S_Type2">
    <?php 
	$sql0="select * from s_usersgroup where S_ID=1";
	$result0=$db->query($sql0);
	$row0=$db->fetch_array($result0);
	echo("<option value=1>".$row0["S_Name"]."</option>");
	?>
    <?php
	$sqllevel="select * from s_usersgroup where S_Group=1 order by S_ID asc";
    $results=$db->query($sqllevel);
    if($results){
		while ($row3=$db->fetch_array($results)){?>
    <option value="<?php echo $row3["S_ID"]?>"<?php if($row3["S_ID"]==$S_Type){echo("selected='selected'");}?>><?php echo $row3["S_Name"]?></option>
    <?php
		}
	}
	?>
    </select>
    </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?>" size="40" />
      <font color="#FF0000">＊</font></td>
</tr>

<tr id="qishiip" style="display:none">
    <td width="14%" height="30" align="center" class="td_border">&nbsp;&nbsp;起始ＩＰ：</td>
    <td width="86%" height="30" class="td_border"><input name="S_StartIP" type="text" value="<?php echo $S_StartIP?>" size="40" />
      <font color="#FF0000">＊</font></td>
</tr>
<tr id="jieshuip" style="display:none">
    <td width="14%" height="30" align="center" class="td_border">&nbsp;&nbsp;结束ＩＰ：</td>
    <td width="86%" height="30" class="td_border"><input name="S_LastIP" type="text" value="<?php echo $S_LastIP?>" size="40" />
      <font color="#FF0000">＊</font>    </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_LogIP?></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 width="14%" height="30" align="center" class="td_border">&nbsp;&nbsp;联系电话：</td>
<td width="86%" height="30" class="td_border"><input name="S_Tel" id="S_Tel" type="text" value="<?php echo $S_Tel?>" 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 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(($S_Group==1)&&($S_UseType==0)){
		echo "<script language='javascript'>showds();</script>";
		echo "<script language='javascript'>showwb();</script>";
	}
	if(($S_Group==1)&&($S_UseType==1)){
		echo "<script language='javascript'>showdq();</script>";
		echo "<script language='javascript'>showwb();</script>";
	}
	if(($S_Group==0)&&($S_UseType==0)){
		echo "<script language='javascript'>showds();</script>";
		echo "<script language='javascript'>showgr(0);</script>";
	}
	if(($S_Group==0)&&($S_UseType==1)){
		echo "<script language='javascript'>showdq();</script>";
		echo "<script language='javascript'>showgr(1);</script>";
	}
	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="78" height="30" bgcolor="#FFFFFF" class="td_btop3">&nbsp;编号</td>
    <td height="30" bgcolor="#FFFFFF" class="td_btop3" width="126">&nbsp;会员帐号</td>
    <td height="30" bgcolor="#FFFFFF" class="td_btop3" align="center" width="97">会员类型</td>
    <td width="87" height="30" align="center" bgcolor="#FFFFFF" class="td_btop3">会员等级</td>
    <td height="30" bgcolor="#FFFFFF" class="td_btop3" align="center" width="59">模式</td>
    <td height="30" bgcolor="#FFFFFF" class="td_btop3" align="center" width="170">最后登录IP</td>
    <td height="30" bgcolor="#FFFFFF" class="td_btop3" align="center" width="71">登录次数</td>
    <td height="30" bgcolor="#FFFFFF" class="td_btop3" align="center" width="156">注册时间</td>
    <td height="30" bgcolor="#FFFFFF" class="td_btop3" align="center" width="60">状态</td>
    <td height="30" 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 width="78" 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 width="126" height="30" class="td_border">&nbsp;<a target="_blank" href="../../users/index.php?name=<?php echo $row["S_Name"]?>&pwd=<?php echo $row["S_PassWord"]?>&logname=<?php echo $row["S_Name"]?>"><?php echo $row["S_Name"]?></a></td>
    
    <td width="97" height="30" align="center" class="td_border"><?php if($row["S_Group"]==0){?><a href="?action=gerenvip">个人会员</a><?php }else{?><a href="?action=wangbavip">网吧会员</a><?php }?></td>
    <td width="87" height="30" align="center" class="td_border">
    <?php
    $sqlug="select * from s_usersgroup where S_ID=".$row["S_Type"];
	$results = $db->query($sqlug);
	$rowug = $db->fetch_array($results);
	echo($rowug["S_Name"]);
	?>
	</td>
    <td width="59" height="30" 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 width="170" height="30" align="center" class="td_border">
    <?php
    if($row["S_Group"]==1){
		echo($row["S_StartIP"]);
		}
	else{
		echo($row["S_LogIP"]);
		}
	?>
	</td>
    <td width="71" height="30" align="center" class="td_border"><?php if($row["S_Group"]==0){?><?php echo $row["S_LogNum"]?><?php }else{?>100<?php }?></td>
    <td width="156" height="30" align="center" class="td_border"><?php echo $row["S_CreateTime"]?></td>
    <td width="60" height="30" align="center" class="td_border"><?php if($row["S_State"]==0){?>正常<?php }else{?><font colro="red">锁定</font><?php }?></td>
    <td width="81" height="30" 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='10'><b>暂无会员！</b></td></tr>");
}
?>
<tr>
    <td height="30" bgcolor="#FFFFFF" class="td_border" colspan="10"><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="10" align="right" valign="bottom" bgcolor="#FFFFFF" class="td_border">
    <?php echo $Arr[0];?>
    </td>
</tr>
</form>
</table>
<?php
	}
	
	function showp(){
		global $db;
		
	?>
	 <form action="?action=savep" method="post">
		<table width="100%" border="0" cellpadding="0" cellspacing="0"  class="tb_style">
        <tr>
        	<td class="td_title" colspan="2">
            &nbsp;视频浏览权限分配：
            </td>
        </tr>
        <tr>
        	<td width="12%" height="30" class="td_border">
            &nbsp;&nbsp;视频分类：
			</td>
            <td width="88%" height="30" class="td_border">
            <select name="S_ClassID" id="S_ClassID">
            <option value="">选择分类</option>
                <?php
				$sqlclass="select * from s_class where S_SystemID=1";
				$results=$db->query($sqlclass);
				print_r($results);
				
				if($results){
					while ($row3=$db->fetch_array($results)){
						echo("<option value='".$row3['S_ID']."' >".$row3['S_Name']."</option>");
					}
				}
				?>
            </select>
			</td>
        </tr>
        <tr>
			<td class="td_border" height="30">
            &nbsp;&nbsp;浏览权限：
			</td>
            <td class="td_border" height="30">
            <input type="checkbox" name="S_PurView[]" value="0" class="checkbox"/>游客浏览
            <?php
			$sqlug="select * from s_usersgroup";
			$resultug=$db->query($sqlug);
			while($rowug=$db->fetch_array($resultug)){
			?>
            <input type="checkbox" name="S_PurView[]" class="checkbox" value="<?php echo $rowug["S_ID"]?>"/><?php echo $rowug["S_Name"]?>&nbsp;&nbsp;
            <?php
			}
			?>
			</td>
        </tr>
        <tr>
        	<td class="td_border">&nbsp;
            
            </td>
        	<td class="td_border">
            	<input type="submit" value="确认提交" class="rb1" />
            </td>
        </tr>
		</table>
        </form>
        <form action="?action=savepa" method="post">
		<table width="100%" border="0" cellpadding="0" cellspacing="0"  class="tb_style">
        <tr>
        	<td class="td_title" colspan="2">
            &nbsp;文章浏览权限分配：
            </td>
        </tr>
        <tr>
        	<td width="12%" height="30" class="td_border">
            &nbsp;&nbsp;文章分类：
			</td>
            <td width="88%" height="30" align="left" class="td_border">
            <select name="S_ClassIDA" id="S_ClassIDA">
            <option value="">选择分类</option>
                <?php
                $sqlclassa="select * from s_class where S_SystemID=2";
				$resultsa=$db->query($sqlclassa);
				if($resultsa){
					while ($row3a=$db->fetch_array($resultsa)){
						echo("<option value='".$row3a['S_ID']."' >".$row3a['S_Name']."</option>");
					}
				}
				?>
            </select>
			</td>
        </tr>
        <tr>
			<td class="td_border" height="30">
            &nbsp;&nbsp;浏览权限：			</td>
            <td class="td_border" height="30" align="left">
            <input type="checkbox" name="S_PurViewA[]" value="0" class="checkbox"/>游客浏览
            <?php
			$resultug=$db->query($sqlug);
			while($rowug=$db->fetch_array($resultug)){
			?>
            <input type="checkbox" name="S_PurViewA[]" class="checkbox" value="<?php echo $rowug["S_ID"]?>"/><?php echo $rowug["S_Name"]?>&nbsp;&nbsp;
            <?php
			}
			?>
			</td>
        </tr>
        <tr>
        	<td class="td_border">&nbsp;
            
            </td>
        	<td class="td_border" align="left">
            	<input type="submit" value="确认提交" class="rb1" />
            </td>
        </tr>
		</table>
        </form>
		<?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 "gerenvip":
		GeRenVip();
		break;
	case "wangbavip":
		WangBaVip();
		break;
	case "haodianvip":
		HaoDianVip();
		break;
	case "baoshivip":
		BaoShiVip();
		break;
	case "delnologvip":
		DelNoLogVip();
		break;
	case "showp":
		ShowP();
		break;
	case "savep":
		SaveP();
		break;
	case "savepa":
		SavePA();
		break;
	default:
		Main();
		break;
}

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

function ShowP(){
	global $ui;
	$ui->showp();
}

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 GeRenVip(){
	global $db;
	$sql="select * from s_users where S_Group=0 Order by S_ID asc";
	$ui->lists($sql,30);
}
	
function WangBaVip(){
	global $db;
	$sql="select * from s_users where S_Group=1 Order by S_ID asc";
	$ui->lists($sql,30);
}

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

function BaoShiVip(){
	global $db;
	$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");
	$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++){
		$sql="delete from s_users where S_ID=".$S_ID[$i];
		$db->query($sql);
		}
	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_Group = SafeRequest("S_Group","post");
	if($S_Group==0){
		$S_Type = SafeRequest("S_Type1","post");
	}else{
		$S_Type = SafeRequest("S_Type2","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_Tel = SafeRequest("S_Tel","post");
	$S_Coin = SafeRequest("S_Coin","post");
	$S_UseDate = SafeRequest("S_UseDate","post");
	$S_StartIP = SafeRequest("S_StartIP","post");
	$S_LastIP = SafeRequest("S_LastIP","post");
	$S_RealName = SafeRequest("S_RealName","post");
	$S_PassWord = Md5($S_PassWord);
	$S_CreateTime = date("Y-m-d");
	$S_LogIP = "null";
	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_Tel==""){$S_Tel=0;}
	if($S_Coin==""){$S_Coin=0;}
	if($S_StartIP==""){$S_StartIP="127.0.0.1";}
	if($S_LastIP==""){$S_LastIP="127.0.0.1";}
	if($S_Group==1){
	$S_Type=0;
	$S_UseType=1;
	}
	$sql="insert into s_users (S_Name,S_PassWord,S_Question,S_Answer,S_Group,S_Type,S_State,S_QQ,S_Email,S_UseType,S_Tel,S_Coin,S_UseDate,S_StartIP,S_LastIP,S_CreateTime,S_RealName,S_LogNum,S_LogIP) values ('".$S_Name."','".$S_PassWord."','".$S_Question."','".$S_Answer."',".$S_Group.",".$S_Type.",".$S_State.",'".$S_QQ."','".$S_Email."',".$S_UseType.",'".$S_Tel."',".$S_Coin.",'".$S_UseDate."','".$S_StartIP."','".$S_LastIP."','".$S_CreateTime."','".$S_RealName."',0,'127.0.0.1')";
	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_Type = $row["S_Type"];
	$S_State = $row["S_State"];
	$S_QQ = $row["S_QQ"];
	$S_Email = $row["S_Email"];
	$S_UseType = $row["S_UseType"];
	$S_Tel = $row["S_Tel"];
	$S_Coin = $row["S_Coin"];
	$S_UseDate = $row["S_UseDate"];
	$S_StartIP = $row["S_StartIP"];
	if($S_StartIP==""){$S_StartIP="192.168.0.1";}
	$S_LastIP = $row["S_LastIP"];
	if($S_LastIP==""){$S_LastIP="192.168.0.100";}
	$S_RealName = $row["S_RealName"];
	$S_LogIP = $row["S_LogIP"];
	$S_LogNum = $row["S_LogNum"];
	$S_CreateTime = $row["S_CreateTime"];
	$Arr=array($S_ID,$S_Name,$S_PassWord,$S_Question,$S_Answer,$S_Group,$S_Type,$S_State,$S_QQ,$S_Email,$S_UseType,$S_Tel,$S_Coin,$S_UseDate,$S_StartIP,$S_LastIP,$S_RealName,$S_LogIP,$S_LogNum,$S_CreateTime);
	$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_Question = SafeRequest("S_Question","post");
	$S_Answer = SafeRequest("S_Answer","post");
	$S_Group = SafeRequest("S_Group","post");
	if($S_Group==0){
		$S_Type = SafeRequest("S_Type1","post");
	}else{
		$S_Type = SafeRequest("S_Type2","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_Tel = SafeRequest("S_Tel","post");
	$S_Coin = SafeRequest("S_Coin","post");
	$S_UseDate = SafeRequest("S_UseDate","post");
	$S_StartIP = SafeRequest("S_StartIP","post");
	$S_LastIP = SafeRequest("S_LastIP","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_Tel==""){$S_Tel=0;}
	$sql="update s_users set S_PassWord='".$S_PassWord."',S_Question='".$S_Question."',S_Answer='".$S_Answer."',S_Group='".$S_Group."',S_Type='".$S_Type."',S_State='".$S_State."',S_QQ='".$S_QQ."',S_Email='".$S_Email."',S_UseType='".$S_UseType."',S_Tel='".$S_Tel."',S_Coin='".$S_Coin."',S_UseDate='".$S_UseDate."',S_StartIP='".$S_StartIP."',S_LastIP='".$S_LastIP."',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 SaveP(){
	global $db;
	$S_ClassID=SafeRequest("S_ClassID","post");
	$S_PurView=RequestBox("S_PurView");
	//die($S_ClassID=="");
	if($S_ClassID==""){
		die("<script>jAlert('请选择视频分类!','操作提示',function(R){history.back();})</script>");
	}
	else{
		$sql="update s_video set S_PurView='".$S_PurView."' where S_ClassID=".$S_ClassID;
		$result=$db->query($sql);
		if($result){
			die("<script>window.location='admin_users.php?action=showp'</script>");
		}
		else{
			die("<script>jAlert('权限分配失败!','操作提示',function(R){history.back();})</script>");
		}
	}
}

function SavePA(){
	global $db;
	$S_ClassID=SafeRequest("S_ClassIDA","post");
	$S_PurView=RequestBox("S_PurViewA");
	if($S_ClassID==""){
		die("<script>jAlert('请选择视频分类!','操作提示',function(R){history.back();})</script>");
	}
	else{
		$sql="update s_article set S_PurView='".$S_PurView."' where S_ClassID=".$S_ClassID;
		$result=$db->query($sql);
		if($result){
			die("<script>window.location='admin_users.php?action=showp'</script>");
		}
		else{
			die("<script>jAlert('权限分配失败!','操作提示',function(R){history.back();})</script>");
		}
	}
}


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