<?php
include "../../include/function.php";
include "../admin_loginstate.php";
include "../../include/conn.php";
 include "../admin_version.php";
//**************************************************************************************************
// 软件名称: 搜一次 Content Management System
// 版本编号: V4.0.0版
// 官方网站: http://www.syccms.com
// 官方论坛：http://bbs.syccms.com
// 版权所有: 搜一次运营团队
// 郑重声明:
//    1、任何个人或组织不得在未经授权的情况下删除、修改、拷贝本软件及其他副本上一切关于版权的信息；
//    2、搜一次网络有限公司保留此软件的法律追究权利
//**************************************************************************************************
?>
<!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);									 
				})							
			}
	});
	$("#ChkAll3").click(function(){
		if($(this).attr("checked")==true){
			$("input[name='S_PurViewT[]']").each(function(){
				$(this).attr("checked",true);									 
			})							
		}else{
			$("input[name='S_PurViewT[]']").each(function(){
				$(this).attr("checked",false);									 
			})							
		}
	});
	$("#ChkAll2").click(function(){
		if($(this).attr("checked")==true){
			$("input[name='S_PurViewA[]']").each(function(){
				$(this).attr("checked",true);									 
			})							
		}else{
			$("input[name='S_PurViewA[]']").each(function(){
				$(this).attr("checked",false);									 
			})							
		}
	});
	$("#ChkAll1").click(function(){
		if($(this).attr("checked")==true){
			$("input[name='S_PurView[]']").each(function(){
				$(this).attr("checked",true);									 
			})							
		}else{
			$("input[name='S_PurView[]']").each(function(){
				$(this).attr("checked",false);									 
			})							
		}
	});
	
	$("#submit1").click(function(){
		var S_Name=$("#S_Name").val();
		var S_DisCount=$("#S_DisCount").val();
		$("#tishi").text("");
		$("#tishi1").text("");
		if(S_Name==""){
			$("#tishi").text("请输入会员组名称！");
			return false;
		};
		else if(S_DisCount==""){
			$("#tishi1").text("请输入消费点数！");
			return false;
			};
	});
});
function turnback(){
	window.history.go(-1);
	}
function del(id){
	jConfirm('您确定要删除该会员吗?', '操作提示', function(r) {
		if(r==true){
			window.location='?action=del&S_ID='+id;
			}
				});
		
};
function delall(){
	jConfirm('您确定要执行操作吗?', '操作提示', function(r) {
		if(r==true){form1.submit();}
		});
};
</script>
</head>
<body>
<?php
class ui_vipgroup{
	//DBU类构造函数
	public function editboard($ActionUrl,$emValues){
		global $db;
		if(is_array($emValues)){
			$S_ID = $emValues[0];
			$S_Name = $emValues[1];
			$S_Group = $emValues[2];
			$S_Info = $emValues[3];
			$S_DisCount = $emValues[4];
			$S_PurView = $emValues[5];
			$S_PurViewT = $emValues[6];
			$S_PurViewA = $emValues[7];
			//die($ActionUrl);
		}
		?>
    <table class="tb_style" width="100%" border="0" cellpadding="0" cellspacing="0">
    <form action="<?php echo $ActionUrl?>" name="form" method="post">
        <tr>
            <td colspan="2" class="td_title">&nbsp;&nbsp;会员组编辑</td>
        </tr>
        <tr>
            <td width="13%" height="30" bgcolor="#FFFFFF" class="td_border">&nbsp;&nbsp;会员组名：</td>
            <td width="87%" height="30" bgcolor="#FFFFFF" class="td_border"><input name="S_Name" type="text" id="S_Name" value="<?php echo $S_Name?>" size="30" />
            <font color="#FF0000" style="font-size:12px">＊</font>
            <label id="tishi" style="color:#F00"></label></td>
        </tr>
        <tr>
            <td height="30" bgcolor="#FFFFFF" class="td_border">&nbsp;&nbsp;会员组类：</td>
            <td height="30" bgcolor="#FFFFFF" class="td_border">
            <input type="radio" name="S_Group" id="S_Group1" value=0 class="radio" checked="checked"/>个人会员
            <input type="radio" name="S_Group" id="S_Group2" value=1 class="radio"<?php if($S_Group==1){echo("checked");}?>/>网吧会员
            </td>
        </tr>
        <tr>
            <td width="13%" height="30" bgcolor="#FFFFFF" class="td_border">&nbsp;&nbsp;消费点数：</td>
      <td height="30" bgcolor="#FFFFFF" class="td_border"><input name="S_DisCount" id="S_DisCount" type="text" value="<?php echo $S_DisCount?>" size="30" onkeyup="this.value=this.value.replace(/[^\d]/g,'')" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))"/>
            <font color="#FF0000" style="font-size:12px">＊</font>
            <label id="tishi1" style="color:#F00"></label>
            </td>
        </tr>
            
        <tr>
            <td width="13%" height="30" bgcolor="#FFFFFF" class="td_border">&nbsp;&nbsp;视频分类权限：            </td>
            <td  height="30" bgcolor="#FFFFFF" class="td_border"><br/>
            <?php
			$sqlvc="select * from s_class where S_SystemID=1";
			$resultvc=$db->query($sqlvc);
			$num1=0;
			while($rowvc=$db->fetch_array($resultvc)){
            ?>
            <input type="checkbox" class="checkbox" value="<?php echo $rowvc["S_ID"]?>" name="S_PurView[]" <?php echo isselect($S_PurView,$rowvc["S_ID"])?>/><?php echo $rowvc["S_Name"]?>
            <?php
			$num1=$num1+1;
			if($num1%7==0){
			echo("<br/>");	
			}
			
			}?>
            <input type="checkbox" name="ChkAll"  id="ChkAll1" class="checkbox"/>全选
            <font color="#FF0000" style="font-size:12px"><br/>&nbsp;&nbsp;</font>            
            </td>
        </tr>
        <tr>
            <td width="13%" height="30" bgcolor="#FFFFFF" class="td_border">&nbsp;&nbsp;文章分类权限：            </td>
            <td  height="30" bgcolor="#FFFFFF" class="td_border"><br/>
            <?php
            $sqlac="select * from s_class where S_SystemID=2";
			$resultac=$db->query($sqlac);
			$num2=0;
			while($rowac=$db->fetch_array($resultac)){
			?>
            <input type="checkbox" class="checkbox" value="<?php echo $rowac["S_ID"]?>" name="S_PurViewA[]" <?php echo isselect($S_PurViewA,$rowac["S_ID"])?>/><?php echo $rowac["S_Name"]?>
            <?php
			$num2=$num2+1;
			if($num2%6==0){
			echo("<br/>");	
			}
			}
			?>
            <input type="checkbox" name="ChkAll"  id="ChkAll2" class="checkbox"/>全选
            <font color="#FF0000" style="font-size:12px"><br/>&nbsp;&nbsp;</font>
            </td>
        </tr>
        <tr>
          <td height="30" bgcolor="#FFFFFF" class="td_border">&nbsp;</td>
          <td  height="30" bgcolor="#FFFFFF" class="td_border"><font color="#FF0000" style="font-size:12px">＊　权限说明：分类权限优先于时间权限！</font></td>
        </tr>
        <tr>
            <td width="13%" height="68" bgcolor="#FFFFFF" class="td_border">
            &nbsp;&nbsp;时间权限：            </td>
            <td height="68" bgcolor="#FFFFFF" class="td_border">
            <input type="checkbox" class="checkbox" value="1" name="S_PurViewT[]" <?php echo isselect($S_PurViewT,"1")?>/>1&nbsp;&nbsp;
            <input type="checkbox" class="checkbox" value="2" name="S_PurViewT[]" <?php echo isselect($S_PurViewT,"2")?>/>2&nbsp;&nbsp;
            <input type="checkbox" class="checkbox" value="3" name="S_PurViewT[]" <?php echo isselect($S_PurViewT,"3")?>/>3&nbsp;&nbsp;
            <input type="checkbox" class="checkbox" value="4" name="S_PurViewT[]" <?php echo isselect($S_PurViewT,"4")?>/>4&nbsp;&nbsp;
            <input type="checkbox" class="checkbox" value="5" name="S_PurViewT[]" <?php echo isselect($S_PurViewT,"5")?>/>5&nbsp;&nbsp;
            <input type="checkbox" class="checkbox" value="6" name="S_PurViewT[]" <?php echo isselect($S_PurViewT,"6")?>/>6&nbsp;&nbsp;
            <input type="checkbox" class="checkbox" value="7" name="S_PurViewT[]" <?php echo isselect($S_PurViewT,"7")?>/>7&nbsp;&nbsp;
            <input type="checkbox" class="checkbox" value="8" name="S_PurViewT[]" <?php echo isselect($S_PurViewT,"8")?>/>8&nbsp;&nbsp;
            <input type="checkbox" class="checkbox" value="9" name="S_PurViewT[]" <?php echo isselect($S_PurViewT,"9")?>/>9&nbsp;&nbsp;
            <input type="checkbox" class="checkbox" value="10" name="S_PurViewT[]" <?php echo isselect($S_PurViewT,"10")?>/>10
            <input type="checkbox" class="checkbox" value="11" name="S_PurViewT[]" <?php echo isselect($S_PurViewT,"11")?>/>11
            <input type="checkbox" class="checkbox" value="12" name="S_PurViewT[]" <?php echo isselect($S_PurViewT,"12")?>/>12<br/><br/>
            <input type="checkbox" class="checkbox" value="13" name="S_PurViewT[]" <?php echo isselect($S_PurViewT,"13")?>/>13
            <input type="checkbox" class="checkbox" value="14" name="S_PurViewT[]" <?php echo isselect($S_PurViewT,"14")?>/>14
            <input type="checkbox" class="checkbox" value="15" name="S_PurViewT[]" <?php echo isselect($S_PurViewT,"15")?>/>15
            <input type="checkbox" class="checkbox" value="16" name="S_PurViewT[]" <?php echo isselect($S_PurViewT,"16")?>/>16
            <input type="checkbox" class="checkbox" value="17" name="S_PurViewT[]" <?php echo isselect($S_PurViewT,"17")?>/>17
            <input type="checkbox" class="checkbox" value="18" name="S_PurViewT[]" <?php echo isselect($S_PurViewT,"18")?>/>18
            <input type="checkbox" class="checkbox" value="19" name="S_PurViewT[]" <?php echo isselect($S_PurViewT,"19")?>/>19
            <input type="checkbox" class="checkbox" value="20" name="S_PurViewT[]" <?php echo isselect($S_PurViewT,"20")?>/>20
            <input type="checkbox" class="checkbox" value="21" name="S_PurViewT[]" <?php echo isselect($S_PurViewT,"21")?>/>21
            <input type="checkbox" class="checkbox" value="22" name="S_PurViewT[]" <?php echo isselect($S_PurViewT,"22")?>/>22
            <input type="checkbox" class="checkbox" value="23" name="S_PurViewT[]" <?php echo isselect($S_PurViewT,"23")?>/>23
            <input type="checkbox" class="checkbox" value="24" name="S_PurViewT[]" <?php echo isselect($S_PurViewT,"24")?>/>24
            <input type="checkbox" name="ChkAll"  id="ChkAll3" class="checkbox"/>全选            
            </td>
        </tr>
        <tr><td width="13%" height="30" bgcolor="#FFFFFF" class="td_border">&nbsp;&nbsp;分组说明：</td>
        <td height="30" bgcolor="#FFFFFF" class="td_border"><textarea name="S_Info" style="height:80px; width:520px"><?php echo $S_Info?></textarea>
          <font color="#FF0000" style="font-size:12px">＊</font></td>
        </tr>
        <tr><td align="right">&nbsp;</td><td align="left">&nbsp;
          <input name="submit" type="submit" class="rb1" id="submit1" value="确定编辑"/> 
          &nbsp;&nbsp;
          &nbsp; <input type="button" name="back" value="返回列表" onclick="turnback()" class="rb1"/></td></tr>
    </form>
    </table>
<?php
	}//function editborad

	function lists($sql,$size){
		global $db;
		$Arr=getpagerow($sql,$size);//sql,每页显示条数
		$result=$db->query($Arr[2]);
		$action=SafeRequest("action","get");
?>
	<table class="tb_style" width="100%" border="0" cellpadding="0" cellspacing="0">
	<tr>
        <td colspan="10" class="td_title">&nbsp;&nbsp;会员组管理</td>
	</tr>
<form action="?action=delall" name="form1" method="post">
	<tr>
        <td height="30" bgcolor="#FFFFFF" class="td_btop3" width="7%">&nbsp;编号</td>
        <td  height="30" bgcolor="#FFFFFF" class="td_btop3" align="center" width="24%">会员组名</td>
        <td  height="30" bgcolor="#FFFFFF" class="td_btop3" align="center" width="44%">会员组类别</td>
        <td  height="30" bgcolor="#FFFFFF" class="td_btop3" align="center" width="13%">消费数额</td> 
        <td width="12%"  height="30" align="center" bgcolor="#FFFFFF" class="td_btop3">操作</td>
	</tr>
    <?php
    if($result){
		while ($row = $db ->fetch_array($result)){
	?>
    <tr>
        <td width="7%" height="30" class="td_border">
        <input type="checkbox" class="checkbox" value="<?php echo $row["S_ID"]?>" name="S_ID[]" <?php if($row["S_ID"]==1){echo("disabled='disabled'");}?>/><?php echo $row["S_ID"]?>.</td>
        <td width="24%" height="30" align="center" class="td_border"><?php echo $row["S_Name"]?></td>
        <td width="44%" height="30" align="center" class="td_border"><?php if($row["S_Group"]==0){echo("个人会员");}else{echo("网吧会员");}?></td>
        <td height="30" class="td_border" align="center"><?php echo $row["S_DisCount"]?></td>
        <td height="30" class="td_border" align="center"><a href="?action=edit&S_ID=<?php echo $row["S_ID"]?>">编辑</a>&nbsp; &nbsp;<?php if($row["S_ID"]==1){?>删除<?php }else{?><a style="cursor:pointer;" onclick="del(<?php echo $row["S_ID"]?>)">删除</a><?php }?></td>
    </tr>
    <?php
		}
	}
	?>
    <tr>
    <td colspan="6" style="padding-top:5px; padding-bottom:5px;"><table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td class="td_border"><input type="checkbox" name="ChkAll" id="ChkAll" class="checkbox" />
            &nbsp;全选&nbsp;&nbsp;
            <input name="button" type="button" class="rb1" onclick="delall()" value="删除会员组" />
			&nbsp;&nbsp; <input type="button" name="input3" value="添加会员组" class="rb1" onclick=location.href='Admin_UsersGroup.php?action=add' />
			</td>
          </tr>
        <tr>
          <td height="40" align="right" >
            <?php echo $Arr[0];?>
          </td>
          </tr>
      </table></td>
    </tr>
    </form>
</table>
<?php
	}//function lists
}//classs




$action=SafeRequest("action","get");
$ui=new ui_vipgroup;
switch($action){
	case "add" :
		Add();
		break;
	case "edit" :
		Edit();
		break;
	case "saveedit":
		SaveEdit();
		break;
	case "saveadd" :
		SaveAdd();
		break;
	case "del" :
		Del();
		break;
	case "delall" :
		DelAll();
		break;
	default :
		main();
		break;
}
//
function main(){
	global $ui;
	$ui->lists("select * from s_usersgroup Order by S_ID asc",30);
}
//
function Add(){
	global $ui;
	$arr=array("","","","","","","","");
	$ui->editboard("?action=saveadd",$arr);
}

function Del(){
	global $db;
	$S_ID = SafeRequest("S_ID","get");
	$sqlu="update s_users set S_Type=1 where S_Type=".$S_ID;
	$db->query($sqlu);
	$sql="delete from s_usersgroup where S_ID=".$S_ID;
	if($db->query($sql)){
		echo "<script>window.location='admin_usersgroup.php'</script>";
		}
	else{
		echo "<script>jAlert('会员组删除失败!','操作提示',function(R){history.back();})</script>";
		}
}

function DelAll(){
	global $db;
	$S_ID=RequestBox("S_ID");
	$S_IDArr=explode(",",$S_ID);
	for($i=0;$i<count($S_IDArr);$i++){
		$sqlu="update s_users set S_Type=1 where S_Type=".$S_IDArr[$i];
		$db->query($sqlu);
		$sql="delete from s_usersgroup where S_ID=".$S_IDArr[$i];
		$db->query($sql);
	}
	echo "<script>window.location='admin_usersgroup.php'</script>";
}

function SaveAdd(){
	global $db;
	$S_Name=SafeRequest("S_Name","post");
	$S_Group=SafeRequest("S_Group","post");
	$S_Info=SafeRequest("S_Info","post");
	$S_DisCount=SafeRequest("S_DisCount","post");
	$S_PurView=SafeRequest("S_PurView[]","post");
	$S_PurViewA=SafeRequest("S_PurViewA[]","post");
	$S_PurViewT=SafeRequest("S_PurViewT[]","post");
	if($S_DisCount==""){$S_DisCount=0;}
	$sql="insert into s_usersgroup (S_Name,S_Group,S_Info,S_DisCount,S_PurView,S_PurViewA) values ('".$S_Name."','".$S_Group."','".$S_Info."','".$S_DisCount."','".$S_PurView."','".$S_PurViewA."')";
	if($db->query($sql)){
		echo "<script>window.location='admin_usersgroup.php'</script>";
	}
	else{
		echo "<script>jAlert('会员组添加失败!','操作提示',function(R){history.back();})</script>";
	}
}

function Edit(){
	global $db;
	global $ui;
	$S_ID = SafeRequest("S_ID","get");
	$sql="select * from s_usersgroup where S_ID=".$S_ID;
	$result=$db->query($sql);
	$row=$db->fetch_array($result);
	$S_Name = $row["S_Name"];
	$S_Group =$row["S_Group"];
	$S_Info = $row["S_Info"];
	$S_DisCount = $row["S_DisCount"];
	$S_PurView = $row["S_PurView"];
	$S_PurViewT = $row["S_PurViewT"];
	$S_PurViewA = $row["S_PurViewA"];
	$Arr=array($S_ID,$S_Name,$S_Group,$S_Info,$S_DisCount,$S_PurView,$S_PurViewT,$S_PurViewA);
	$ui->editboard("?action=saveedit&S_ID=".$S_ID,$Arr);
}

function SaveEdit(){
	global $db;
	$S_ID = SafeRequest("S_ID","get");
	$S_Name = SafeRequest("S_Name","post");
	$S_Group = SafeRequest("S_Group","post");
	$S_Info = SafeRequest("S_Info","post");
	$S_DisCount = SafeRequest("S_DisCount","post");
	$S_PurView = RequestBox("S_PurView");
	$S_PurViewT = RequestBox("S_PurViewT");
	$S_PurViewA = RequestBox("S_PurViewA");
	if($S_DisCount==""){$S_DisCount=0;}
	$sql="update s_usersgroup set S_Name='".$S_Name."',S_Group='".$S_Group."',S_Info='".$S_Info."',S_DisCount='".$S_DisCount."',S_PurView='".$S_PurView."',S_PurViewT='".$S_PurViewT."',S_PurViewA='".$S_PurViewA."' where S_ID=".$S_ID;
	if($db->query($sql)){
		echo "<script>window.location='admin_usersgroup.php'</script>";
		}
	else{
		echo "<script>jAlert('会员组添加失败!','操作提示',function(R){history.back();})</script>";
		}
}
	function isselect($S_PurView,$values){
		if(($S_PurView=="0")||($S_PurView=="")){
			
		}
		else{
			$S_PurViewarr=explode(",",$S_PurView);
			for($i=0;$i<count($S_PurViewarr);$i++){
				if($S_PurViewarr[$i]==$values){
					echo("checked");
				}
			}
		}
	}

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