<!--#include file="admin_conn.asp"-->
<%
chkLogin
dim action : action = be("get","action")

select case action
	case else : headAdmin "会员管理" : main
end select
dispseObj()

sub main
	Dim pagenum : pagenum = be("all","page")
	if isN(pagenum) or not isNum(pagenum) then pagenum = 1
	if pagenum < 1 then pagenum = 1
	pagenum = cint(pagenum)
	dim group:group = be("get","group")
	Dim sql : sql = "SELECT u_id,u_name,u_group,u_qq,u_email,u_status,u_points,u_tj,u_loginnum,u_logintime,u_ip,u_flag FROM {pre}user "
	if not isN(group) then 
		sql = sql &  " where u_group = " & group
	end if
	sql = sql & " ORDER BY u_id DESC"
	
	Dim rs : Set rs = objdb.db(sql,"rs1")
%>
<script language="javascript">
$(document).ready(function(){
	$("#form2").validate({
		rules:{
			u_name:{
				required:true,
				stringCheck:true,
				maxlength:32
			},
			u_password:{
				maxlength:32
			},
			u_flag:{
				required:true
			},
			u_group:{
				required:true
			},
			u_qq:{
				number:true,
				maxlength:16
			},
			u_email:{
				email:true,
				maxlength:32
			},
			u_points:{
				number:true
			},
			u_status:{
				required:true
			}
		}
	});
	$("#group").change(function(){
		var group = $(this).children('option:selected').val();
		location.href= "admin_user.asp?group=" + group;
	});
	$('#form1').form({
		onSubmit:function(){
			if(!$("#form1").valid()) {return false;}
		},
	    success:function(data){
	        $.messager.alert('系统提示', data, 'info',function(){
	        location.href=location.href;
	        });
	    }
	});
	$('#form2').form({
		onSubmit:function(){
			if(!$("#form2").valid()) {return false;}
		},
	    success:function(data){
	        $.messager.alert('系统提示', data, 'info');
	    }
	});
	$("#btnDel").click(function(){
			if(confirm('确定要删除吗')){
				$("#form1").attr("action","admin_ajax.asp?action=del&flag=batch&tab={pre}manager");
				$("#form1").submit();
			}
			else{return false}
	});
	$("#btnAdd").click(function(){
		$('#form2').form('clear');
		$("#flag").val("add");
		$('#win1').window('open'); 
	});
	$("#btnCancel").click(function(){
		location.href= location.href;
	});
	$.fn.datebox.defaults.formatter = function(date) {
	var y = date.getFullYear();
	var m = date.getMonth() + 1;
	var d = date.getDate();
	return y + '-' + (m < 10 ? '0' + m : m) + '-' + (d < 10 ? '0' + d : d);
	};
	$('#u_starttime').datebox();
	$('#u_endtime').datebox();
});
function showflag(flag){
	if (flag==2){
		$("#flag2").show();
		$("#flag1").hide();
	}
	else if (flag==1){
		$("#flag2").hide();
		$("#flag1").show();
	}
	else{
		$("#flag2").hide();
		$("#flag1").hide();
	}
}
function edit(id)
{
	$('#form2').form('clear');
	$("#flag").val("edit");
	$('#win1').window('open');
	$.get('admin_ajax.asp?action=getinfo&tab={pre}user&col=u_id&val='+id,function(obj){
		$("#uid").val(obj.u_id);
		$("#u_name").val(obj.u_name);
		$("#u_qq").val(obj.u_qq);
		$("#u_email").val(obj.u_email);
		$("#u_points").val(obj.u_points);
		$("#u_phone").val(obj.u_phone);
		$("#u_question").val(obj.u_question);
		$("#u_answer").val(obj.u_answer);
		
		if(obj.u_status==1){
			$("#u_status").get(0).options[0].selected = true;
		}
		else{
			$("#u_status").get(0).options[1].selected = true;
		}
		if(obj.u_flag==1){
			$("#u_flag").get(0).options[1].selected = true;
			$('#u_starttime').datebox('setValue',obj.u_start);
			$('#u_endtime').datebox('setValue',obj.u_end);
			$("#flag1").show();
			$("#flag2").hide();
		}
		else if(obj.u_flag==2){
			$("#u_flag").get(0).options[2].selected = true;
			$("#u_startip").val(obj.u_start);
			$("#u_endip").val(obj.u_end);
			$("#flag2").show();
			$("#flag1").hide();
		}
		else{
			$("#u_flag").get(0).options[0].selected = true;
		}
		$("#u_group option").each(function(i){
       		if($(this).val() == obj.u_group){
            	$("#u_group").get(0).options[i].selected = true;
            }
        });
	},"json");
}
</script>
<table class="tb">
	<tr>
	<td colspan="5" ><strong>会员组查看：</strong>
	<select id="group" name="group">
	<option value="">全部会员</option>
	<%=makeSelect("{pre}user_group","ug_id","ug_name","","","&nbsp;|&nbsp;&nbsp;",group)%>
	</select>
	</td>
	</tr>
</table>

<form action="" method="post" id="form1" name="form1">
<table class="tb">
	<tr>
	<td width="4%">&nbsp;</td>
	<td>会员</td>
	<td width="10%">计费类型</td>
	<td width="15%">会员组</td>
	<td width="10%">积分</td>
	<td width="10%">推荐数</td>
	<td width="15%">是否锁定</td>
	<td width="15%">最后登陆</td>
	<td width="15%">操作</td>
	</tr>
	<%
		if rs.eof then
	%>
    <tr><td align="center" colspan="9" >没有任何记录!</td></tr>
    <%
		else
		Dim i,rsr
		rs.PageSize = app_pagenum
	    rs.AbsolutePage = pagenum
	  	for i = 1 to rs.PageSize
	  		if rs.eof then exit for
	%>
    <tr>
	  <td><input name="u_id" type="checkbox" id="u_id" value="<%=rs("u_id")%>" /></td>
      <td><%=rs("u_name")%></td>
      <td>
	  <%=getUserFlag(rs("u_flag"))%>
      </td>
      <td><%
        set rsr = objdb.DB("SELECT ug_name FROM {pre}user_group WHERE ug_id="&rs("u_group"),"rs1")
		if rsr.bof and rsr.eof then
			writeA  "未知"
		else
			writeA rsr("ug_name")
		end if
		objdb.c(rsr)
      %></td>
      <td><%=rs("u_points")%></td>
      <td><%=rs("u_tj")%></td>
      <td><% if rs("u_status") = 1 then %>启用<%else%>锁定<%end if%></td>
      <td><%=rs("u_logintime")%></td>
      <td><a href="javascript:void(0)" onclick="edit('<%=rs("u_id")%>');return false;">修改</a> |
	  <a href="admin_ajax.asp?action=del&tab={pre}user&u_id=<%=rs("u_id")%>" onClick="return confirm('确定要删除吗?');">删除</a></td>
    </tr>
	<%
	rs.MoveNext
	next
	end if
	%>
	<tr>
	<td colspan="9">全选<input type="checkbox" name="chkall" id="chkall" class="checkbox" onClick="checkAll(this.checked,'u_id')" />
	&nbsp;<input type="button" id="btnDel" value="批量删除" class="input" />
	&nbsp;<input type="button" id="btnAdd" value="添加"  class="input"/>
	</td></tr>
    <tr align="center">
	<td colspan="9">
	<%=pagelist_manage(rs.PageCount,pagenum,rs.RecordCount,app_pagenum,"admin_user.asp?page={p}&group="&group&"")%>
	</td>
	</tr>
</table>
</form>

<div id="win1" class="easyui-window" title="窗口" style="padding:5px;width:400px;" closed="true" closable="false" minimizable="false" maximizable="false">
<form action="admin_ajax.asp?action=save&tab={pre}user" method="post" name="form2" id="form2">
<table class="tb">
	<input id="uid" name="uid" type="hidden" value="">
	<input id="flag" name="flag" type="hidden" value="">
    <tr>
	<td width="30%">名称：</td>
	<td><INPUT type="text" id="u_name" size=20 value="" name="u_name">
	</td>
    </tr>
    <tr>
	<td>密码：</td>
	<td><INPUT id="u_password" type="password" size=20 value="" name="u_password">
	</td>
    </tr>
    <tr>
	<td>提示问题：</td>
	<td><INPUT type="text" id="u_question" size=30 value="" name="u_question">
	</td>
    </tr>
    <tr>
	<td>提示回答：</td>
	<td><INPUT type="text" id="u_answer" size=30 value="" name="u_answer">
	</td>
    </tr>
    <tr>
	<td>状态：</td>
	<td>
	<select id="u_status" name="u_status" style="width:100px;">
	<option value=1>启动</option>
	<option value=0>锁定</option>
	</select>
	</td>
    </tr>
    <tr>
	<td>计费类型：</td>
	<td>
	<select name="u_flag" id="u_flag" style="width:100px;" onChange="showflag(this.options[this.selectedIndex].value)">
	<option value="0" >计点</option>
	<option value="1" >包时</option>
	<option value="2" >网吧</option>
	</select> 
	</td>
    </tr>
	<tr id="flag1" style="display:none">
	<td>设置时间：</td>
	<td>
	起始时间:<INPUT type="text" id="u_starttime" size=20 value="" name="u_starttime"><br>
	截止时间:<INPUT type="text" id="u_endtime" size=20 value="" name="u_endtime" >
	</td>
	</tr>
	<tr id="flag2" style="display:none">
	<td>设置IP段：</td>
	<td>
	起始IP:<INPUT type="text" id="u_startip" size=20 value="" name="u_startip"><br>
	截止IP:<INPUT type="text" id="u_endip" size=20 value="" name="u_endip">
	</td>
    </tr>
    <tr>
	<td>会员组：</td>
	<td>
	<select id="u_group" name="u_group" style="width:100px;">
	<option value="">请选择会员组</option>
	<%for i=0 to ubound(cacheusergroup)%>
	<option value="<%=cacheusergroup(i)(0)%>"><%=cacheusergroup(i)(1)%></option>
	<%next%>
	</select>
	</td>
    </tr>
	<tr>
	<td>积分：</td>
	<td><INPUT id="u_points" type="text" size=10 value="0" name="u_points">
	</td>
    </tr>
	<tr>
	<td>QQ：</td>
	<td><INPUT id="u_qq" type="text" size=20 value="" name="u_qq">
	</td>
    </tr>
	<tr>
	<td>email：</td>
	<td><INPUT id="u_email" type="text" size=20 value="" name="u_email">
	</td>
    </tr>
    <tr>
	<td>电话：</td>
	<td><INPUT id="u_phone" type="text" size=20 value="" name="u_phone">
	</td>
    </tr>
	
	<tr align="center">
      <td colspan="2"><input class="input" type="submit" value="保存" id="btnSave"> <input class="input" type="button" value="返回" id="btnCancel"> </td>
    </tr>
</table>
</form>
</div>
</body>
</html>
<%
objdb.c(rs)
end sub
%>