<!--#include file="../conn.asp"-->
<!--#include file="admin_check.asp"-->
<!--#include file="../inc/function.asp"-->
<%
Response.Buffer = True 
Response.Expires = -1
Response.ExpiresAbsolute = Now() - 1 
Response.Expires = 0 
Response.CacheControl = "no-cache"
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
<title>管理页面</title>
<link id="maincss" rel="stylesheet" href="images/css/admin_style_<%= AdminSkin %>.css" type="text/css" media="all" />
<script language="javascript">
 function chkgt()
{
  if (document.gt.GradeTypename.value=="")
   {
    gtmsg.innerHTML="<font color=red>请填写等级方案！</font>";
	document.gt.GradeTypename.focus();
	return false;
   }
}

 function chkaddgrade(gid)
{
  if (eval("addgrade"+gid+".gradename.value==''") ||eval("addgrade"+gid+".gradename.value=='头衔名称'"))
   {
	eval("grmsg"+gid+".innerHTML='<font color=red>请填写头衔名称！</font>'");
	eval("addgrade"+gid+".gradename.focus()");
	return false;
   }
  if (eval("addgrade"+gid+".grade.value==''"))
   {
    eval("grmsg"+gid+".innerHTML='<font color=red>请填写等级！</font>'");
	eval("addgrade"+gid+".grade.focus()");
	return false;
   }

}
	  
	function modify(bb,aa,cname,id)
		{
			if(bb.innerText==cname)
			{
			bb.innerHTML="<form action=?act=modify&id="+id+" method=post><input name=GradeTypename type=text size=30 value="+cname+"> &nbsp;<input name=Submit type=submit value=修改名称></form>";
			aa.innerHTML="<font color=red><b>取消</b></font>"
			}
			else
			{
			bb.innerHTML="<b>"+cname+"</b>";
			aa.innerHTML="修改"
		}
	}
	
	function modify2(dd,cc,cname,id)
		{
			if(dd.innerText==cname)
			{
			dd.innerHTML="<form action=?act=modigrade&id="+id+" method=post><input name=Gradename type=text size=12 value="+cname+"> <input type=image src=Images/submit.gif></form>";
			cc.innerHTML="<font color=red><b>复</b></font>"
			}
			else
			{
			dd.innerHTML="<u>"+cname+"</u>";
			cc.innerHTML="改"
		}
	}
</script>
</head>
<body leftmargin="0" bottommargin="0" rightmargin="0" topmargin="5" marginheight="0" marginwidth="0" bgcolor="#DDEEFF">
<%
Call chkFlag(12)
dim act,id
act=Trim(Request.QueryString("act"))
id=Trim(Request.QueryString("id"))
opendb
Dim AskD
Set AskD = Server.CreateObject("KwAsk.FunAsk")
if act="add" then
   Call AddGradeType()
elseif act="modify" then
   Call modify()
elseif act="modigrade" then
   Call modigrade()
elseif act="default" then
   Call default()
elseif act="addgrade" then
   Call addgrade()
elseif act="delgrade" then
   Call delgrade()
elseif act="deltype" then
   Call deltype()
else 
   call main()
end if
Set AskD=Nothing
closedb

sub deltype()
   dim rs
   set rs=conn.execute("delete from "&predb&"UserGradetype where id="&id)
   set rs=nothing
   set rs=conn.execute("delete from "&predb&"UserGrade where GradeTypeId="&id)
   set rs=nothing
   Response.Write("<script>history.go(-1);</script>")
end sub

sub delgrade()
   dim rs
   set rs=conn.execute("delete from "&predb&"UserGrade where id="&id)
   set rs=nothing
   Response.Write("<script>history.go(-1);</script>")
end sub

Sub addgrade()
   dim rs,sql,idd
   set rs= Server.CreateObject("adodb.recordset")
   sql="select * from "&predb&"UserGrade order by id desc"
   rs.open sql,conn,1,3
   if rs.bof and rs.eof then
      idd=1
   else
      idd=rs("id")+1
   end if
   rs.addnew
   rs("id")=idd
   rs("Gradename")=Trim(Request.Form("Gradename"))
   rs("Grade")=Trim(Request.Form("Grade"))
   rs("GradeTypeId")=Trim(Request.Form("gradetypeid"))
   rs.update
   rs.close
   set rs=nothing
   Response.Write("<script>history.go(-1);</script>")
end sub

Sub modify()
    Dim rs,sql,GradeTypename
	GradeTypename=Trim(Request.Form("GradeTypename"))
	if GradeTypename="" then 
	  Call SendMsg("方案名称不能为空！")
	  Response.End()
	end if
	Set rs= Server.CreateObject("adodb.recordset")
	sql="select * from "&predb&"UserGradeType where id="&id
	rs.open sql,conn,1,3
	rs("GradeTypename")=GradeTypename
	rs.update
	rs.close
	set rs=nothing
	Response.Write("<script>history.go(-1);</script>")
End Sub

Sub modigrade()
    Dim rs,sql,Gradename
	Gradename=Trim(Request.Form("Gradename"))
	if Gradename="" then 
	  Call SendMsg("头衔不能为空！")
	  Response.End()
	end if
	Set rs= Server.CreateObject("adodb.recordset")
	sql="select * from "&predb&"UserGrade where id="&id
	rs.open sql,conn,1,3
	rs("Gradename")=Gradename
	rs.update
	rs.close
	set rs=nothing
	Response.Write("<script>history.go(-1);</script>")
End Sub

Sub default()
  dim rs
  set rs=conn.execute("update "&predb&"UserGradeType set isdefault=0")
  set rs=nothing
  set rs=conn.execute("update "&predb&"UserGradeType set isdefault=1 where id="&id)
  set rs=nothing
  Response.Write("<script>history.go(-1);</script>")
End Sub

Sub AddGradeType()
    Dim rs,sql,GradeTypename,idd
	GradeTypename=Trim(Request.Form("GradeTypename"))
	if GradeTypename="" then Response.End()
	Set rs= Server.CreateObject("adodb.recordset")
	sql="select * from "&predb&"UserGradeType order by id desc"
	rs.open sql,conn,1,3
	if rs.eof and rs.bof then
	idd=1 
	else
	idd=rs("id")+1
	end if
	rs.addnew
	rs("id")=idd
	rs("GradeTypename")=GradeTypename
	rs.update
	rs.close
	set rs=nothing
	Response.Write("<script>history.go(-1);</script>")
End Sub

sub main
%>
<table class="tableBorder" cellspacing="1" cellpadding="2" width="96%" align="center" border="0">
<tr>
		<th height="25" align="left">会员等级设置</th>
	</tr>
  <tr>
    <form action="?act=add" method="post" name="gt" onSubmit="return chkgt();">
    <td class="TableRow1"><font color="#008800">添加等级方案：</font>
    <input name="GradeTypename" type="text" id="GradeTypename" size="32">
    <input type="submit" name="button" id="button" value=" 添 加 "> <span id="gtmsg"></span>    </td>
    </form>
  </tr>
  <tr>
    <td class="TableRow2"><font color="red">注意：所有删除操作后将无法恢复，请确定无误后再删除，强烈建议操作前请备份数据库。</font><br/>
      <b>说明：</b><br/>
   &nbsp; 1、头衔一一对应于等级的分值，操作时请注意分值等级和头衔的对应性，并保证等级连续！如一级直到十八级。<br/>
   &nbsp; 2、请选择一个默认的头衔方案，不选择将随机抽取。<br/>
   </td>
  </tr>
</table>
<br>
<%
dim rs,sql,i
	Set rs= Server.CreateObject("adodb.recordset")
	sql="select * from "&predb&"UserGradeType order by id asc"
	rs.open sql,conn,1,1
	do while not rs.eof
	i=i+1
	
	dim maxgrade,rs2
	set rs2= conn.execute("select max(grade) from "&predb&"UserGrade where GradeTypeId="&rs("id"))
	maxgrade=rs2(0)+1
	set rs2=nothing
	if IsNumeric(maxgrade)=false then maxgrade=1
	
if rs("isDefault")=1 then
%>
<table class="tableBorder" cellspacing="1" cellpadding="2" width="96%" align="center" border="0">
     <tr>
	   <th width="72%" height="25" align="left" id="bb<%= i %>"><b><%= rs("GradeTypename") %></b></th>
	   <th width="28%" align="left">
       &nbsp;默认方案 &nbsp;<span id="aa<% =i %>" style="cursor:hand" onClick="modify(bb<%=i%>,aa<%=i%>,'<%= rs("GradeTypename") %>',<%= rs("id") %>);">修改</span>&nbsp; </th>
  </tr>
  <form action="?act=addgrade" method="post" name="addgrade<%=rs("id")%>" onSubmit="return chkaddgrade(<%= rs("id") %>);">
  <tr>
     <td colspan="2" class="TableRow2"><font color="#008800">添加等级：</font>
      <input name="gradename" type="text" id="gradename" value="头衔名称" onClick="if(this.value=='头衔名称'){this.value=''}">
      应用等级：
      <input name="grade" type="text" id="grade" onKeyUp="this.value=this.value.replace(/\D/g,'')" value="<%=maxgrade%>" size="4" onafterpaste="this.value=this.value.replace(/\D/g,'')">
      <input name="gradetypeid" type="hidden" id="gradetypeid" value="<%=rs("id")%>">
      <input type="submit" name="button3" id="button3" value="添加头衔">
      <span id="grmsg<%= rs("id") %>"></span></td>
  </tr>
  </form>
  <tr>
    <td colspan="2" class="TableRow1">
    <%
	dim sql2
	set rs2= Server.CreateObject("adodb.recordset")
	sql2="select * from "&predb&"UserGrade where GradeTypeId="&rs("id")
	rs2.open sql2,conn,1,1
    do while not rs2.eof
	%>
    <div class="gradelist">
    <ul>
    <li class="gs1">[<a href="?act=delgrade&id=<%= rs2("id") %>" onClick="return confirm('您确定进行删除操作吗？')">删</a>] [<span id="cc<% =rs2("id") %>" style="cursor:hand" onClick="modify2(dd<%=rs2("id")%>,cc<%=rs2("id")%>,'<%=rs2("Gradename")%>',<%= rs2("id") %>);">改</span>]</li>
    <li class="gs2"><%= AskD.NumToCC(rs2("grade")) %>级</li>
	<li class="gs3"><span id="dd<%= rs2("id") %>"><u><%=rs2("gradename")%></u></span></li>
    </ul>
    </div>
    <%
	rs2.movenext
	loop
	rs2.close
	set rs2=nothing
	%>
    </td>
  </tr>
</table>
<br>
<%
else
%>
<table class="tableBorder" cellspacing="1" cellpadding="2" width="96%" align="center" border="0">
     <tr>
	   <td width="72%" height="25" align="left" class="TableRow1" id="bb<%= i %>"><b><%= rs("GradeTypename") %></b></td>
	   <td width="28%" align="left" class="TableRow1">&nbsp;<a href="?act=default&id=<%= rs("id") %>">设为默认</a> &nbsp;<span id="aa<% =i %>" style="cursor:hand" onClick="modify(bb<%=i%>,aa<%=i%>,'<%= rs("GradeTypename") %>',<%= rs("id") %>);">修改</span>&nbsp; <a href="?act=deltype&id=<%= rs("id") %>" onClick="return confirm('您确定进行删除操作吗？')">删除?</a></td>
  </tr>
  <form action="?act=addgrade" method="post" name="addgrade<%= rs("id") %>" onSubmit="return chkaddgrade(<%= rs("id") %>);">
  <tr>
     <td colspan="2" class="TableRow2"><font color="#008800">添加等级：</font>
      <input name="gradename" type="text" id="gradename" value="头衔名称" onClick="if(this.value=='头衔名称'){this.value=''}">
      应用等级：
      <input name="grade" type="text" id="grade" onKeyUp="this.value=this.value.replace(/\D/g,'')"  value="<%=maxgrade%>" size="4" onafterpaste="this.value=this.value.replace(/\D/g,'')">
      <input name="gradetypeid" type="hidden" id="gradetypeid" value="<%=rs("id")%>">
      <input type="submit" name="button3" id="button3" value="添加头衔">
      <span id="grmsg<%= rs("id") %>"></span></td>
  </tr>
  </form>
  <tr>
    <td colspan="2" class="TableRow1">
    <%
	set rs2= Server.CreateObject("adodb.recordset")
	sql2="select * from "&predb&"UserGrade where GradeTypeId="&rs("id")
	rs2.open sql2,conn,1,1
    do while not rs2.eof
	%>
    <div class="gradelist">
    <ul>
    <li class="gs1">[<a href="?act=delgrade&id=<%= rs2("id") %>" onClick="return confirm('您确定进行删除操作吗？')">删</a>] [<span id="cc<% =rs2("id") %>" style="cursor:hand" onClick="modify2(dd<%=rs2("id")%>,cc<%=rs2("id")%>,'<%=rs2("Gradename")%>',<%= rs2("id") %>);">改</span>]</li>
    <li class="gs2"><%= AskD.NumToCC(rs2("grade")) %>级</li>
	<li class="gs3"><span id="dd<%= rs2("id") %>"><u><%=rs2("gradename")%></u></span></li>
    </ul>
    </div>
    <%
	rs2.movenext
	loop
	rs2.close
	set rs2=nothing
	%>
    </td>
  </tr>
</table>
<br>
<%
end if
rs.movenext
loop
rs.close
set rs=nothing
end sub
%>
<br>
</body>
</html>
