<!--#include file="setup.asp"-->
<%
NC_Admin.AdminChk = "44"
NC_Admin.Check
DownsysClass.admin_header

Dim GroupSetting
select case request("action")
case "save" 
	call savegroup()
case "savedit" 
	call savedit()
case "del"
	call delgroup()
case "group" 
	call gradeinfo()
case "addgroup" 
	call addgroup()
case "editgroup"
	call editgroup()
case else
	call usergroup()
end select
if FoundErr = True then
	NC_Admin.Error_Msg(ErrMsg)
end if
DownsysClass.admin_footer
NothingObject
sub usergroup()
%>
<table width="98%" border="0" cellspacing="1" cellpadding="3"  align=center class="tableBorder">
<tr> 
<th height="23" colspan="4" >用户组管理&nbsp;&nbsp;<a href="?action=addgroup"><font color=#FFFFFF>[添加用户组]</font></a></th>
</tr>
<tr><td colspan=4 height=25 class="Forumrow"><B>说明</B>：<BR>
①在这里您可以设置各个用户组在系统中的默认权限，系统默认用户组不能删除和编辑用户等级;<BR>
②可以进行添加用户组操作并设置其权限，可以将其他组用户转移到该组，请到用户管理中进行相关操作;<BR>
③可以删除和编辑新添加的用户组，添加组时请填相应用户等级。<BR>
</td></tr>
<tr align=center>
<td height="23" width="30%" class=forumHeaderBackgroundAlternate><B>用户组</B></td>
<td height="23" width="20%" class=forumHeaderBackgroundAlternate><B>用户数量</B></td>
<td height="23" width="20%" class=forumHeaderBackgroundAlternate><B>编辑</B></td>
<td height="23" width="30%" class=forumHeaderBackgroundAlternate><B>用户等级</B></td>
</tr>
<%
dim trs
set rs=DownsysClass.execute("select * from NC_UserGroup order by groupid")
do while not rs.eof
set trs=DownsysClass.execute("select count(*) from [NC_user] where Grade="&rs("Grades"))
%>
<tr align=center>
<td height="23" width="30%" class="Forumrow"><%=rs("GroupName")%></td>
<td height="23" width="20%" class="Forumrow"><%if rs("Grades") = 0 Then%>匿名用户<%Else%><%=trs(0)%><%End If%></td>
<td height="23" width="20%" class="Forumrow"><a href="?action=editgroup&groupid=<%=rs("groupid")%>">用户组设置</a><%if rs("groupid") > 3 then%> | <a href="?action=del&groupid=<%=rs("groupid")%>&Grade=<%=rs("Grades")%>" onclick="{if(confirm('此操作将删除本用户组\n 您确定执行的操作吗?')){return true;}return false;}">删除</a><%end if%></td>
<td height="23" width="30%" class="Forumrow"><%=rs("Grades")%></td>
</tr>
<%
rs.movenext
loop
rs.close
set rs=nothing
%>
</table><BR>
<%
end sub
Sub addgroup()
        Dim GroupNum
        Set Rs = CreateObject("Adodb.recordset")
        SQL = "select Max(groupid) from NC_UserGroup"
        Rs.Open SQL, Conn, 1, 1
        If Rs.EOF And Rs.bof Then
                GroupNum = 1
        Else
                GroupNum = Rs(0) + 1
        End If
        If IsNull(GroupNum) Then GroupNum = 1
        Rs.Close
%>
<table width="98%" border="0" cellspacing="1" cellpadding="3"  align=center class="tableBorder">
<tr> 
<th height="23" colspan="2" >添加新的用户组</th>
</tr>
<FORM METHOD=POST ACTION="admin_group.asp?action=save">
<input type="hidden" name="newgroupid" value="<% = GroupNum %>">
<tr><td colspan=2 height=25 class="Forumrow"><B>说明</B>：<BR>
①可以进行添加用户组操作并设置其权限，可以将其他组用户转移到该组，请到用户管理中进行相关操作；<BR>
②可以删除和编辑新添加的用户组，添加是请填写相应用户等级。<BR>
</td></tr>
<tr> 
<th height="23" colspan="2" >添加新的用户组</th>
</tr>
<tr>
<td height="23" width="60%" class=Forumrow>用户组名称</td>
<td height="23" width="40%" class=Forumrow><input size=35 name="GroupName" type=text></td>
</tr>
<script>function checkclick(msg){if(confirm(msg)){event.returnValue=true;}else{event.returnValue=false;}}</script>
<tr>
<td height="23" class=Forumrow>用户组等级；请输入数字(数字越大级别越高)</td>
<td height="23" class=Forumrow><input size=10 name="Grades" type=text value=<%=conn.execute("Select max(Grades)from NC_UserGroup")(0)+1%>></td>
</tr>
<tr>
<td height="23" width="60%" class=Forumrow>是否可以发布软件
</td>
<td height="23" width="40%" class=Forumrow><input type=radio name="GroupSet(0)" value=0> 否&nbsp; <input type=radio name="GroupSet(0)" value=1 checked> 是 </td>
</tr>
<tr>
<td height="23" width="60%" class=Forumrow>发布软件增加的点数,不设置请填“0”
</td>
<td height="23" width="40%" class=Forumrow><input name="GroupSet(1)" type=text size=5 value="10"></td>
</tr>
<tr>
<td height="23" width="60%" class=Forumrow>每天下载软件的个数,不设置请填“0”
</td>
<td height="23" width="40%" class=Forumrow><input name="GroupSet(2)" type=text size=5 value="20"></td>
</tr>
<tr> 
<td height="23" width="60%" class=Forumrow>
</td>
<td height="23" width="40%" class=Forumrow>
<input type="button" name="Submit1" onclick="javascript:history.go(-1)" value="返回上一页" class=button>　
<input type="submit" name="submit" value="添加用户组" class=button></td>
</tr>
</FORM>
</table><BR>
<%
set rs=nothing
End Sub
Sub editgroup()
	dim GroupSet
	set rs=DownsysClass.execute("select * from NC_UserGroup where groupid="&request("groupid")&"")
	GroupSet = Split(rs("GroupSet"),",")
%>
<table width="98%" border="0" cellspacing="1" cellpadding="3"  align=center class="tableBorder">
<tr> 
<th height="23" colspan="2" >修改用户组</th>
</tr>
<FORM METHOD=POST ACTION="admin_group.asp?action=savedit">
<tr><td colspan=2 height=25 class="Forumrow"><B>说明</B>：<BR>
①可以进行修改用户组操作并设置其权限，可以将其他组用户转移到该组，请到用户管理中进行相关操作；<BR>
</td></tr>
<tr> 
<th height="23" colspan="2" >修改用户组</th>
</tr>
<tr>
<td height="23" width="60%" class=Forumrow>用户组名称</td>
<td height="23" width="40%" class=Forumrow><input size=35 name="GroupName" type=text value="<%=rs("GroupName")%>"></td>
</tr>
<tr>
<td height="23" class=Forumrow>用户组等级；请输入数字(数字越大级别越高)</td>
<td height="23" class=Forumrow><input size=10 type=text value="<%=rs("Grades")%>" disabled>
<input size=10 name="Grades" type=hidden value="<%=rs("Grades")%>"></td>
</tr>
<tr>
<td height="23" width="60%" class=Forumrow>是否可以发布软件
</td>
<td height="23" width="40%" class=Forumrow><input type=radio name="GroupSet(0)" value=0 <%If GroupSet(0) = 0 Then%>checked<%End if%>> 否&nbsp; <input type=radio name="GroupSet(0)" value=1 <%If GroupSet(0) = 1 Then%> checked<%End IF%>> 是 </td>
</tr>
<tr>
<td height="23" width="60%" class=Forumrow>发布软件增加的点数,不设置请填“0”
</td>
<td height="23" width="40%" class=Forumrow><input name="GroupSet(1)" type=text size=5 value="<%=GroupSet(1)%>"></td>
</tr>
<tr>
<td height="23" width="60%" class=Forumrow>每天下载软件的个数,不设置请填“0”
</td>
<td height="23" width="40%" class=Forumrow><input name="GroupSet(2)" type=text size=5 value="<%=GroupSet(2)%>"></td>
</tr>
<tr> 
<td height="23" width="60%" class=Forumrow>
</td>
<td height="23" width="40%" class=Forumrow>
<input type="button" name="Submit1" onclick="javascript:history.go(-1)" value="返回上一页" class=button>　
<input type="submit" name="submit" value="保存修改" class=button></td>
</tr>
<input type=hidden value="<%=Request.Querystring("groupid")%>" name="groupid">
</FORM>
</table><BR>	
<%
	   rs.close:set rs=nothing
End Sub
Sub CheckSave()
	if Len(request.form("GroupName")) = 0 then
  		founderr=true
  		errmsg=errmsg+"<li>用户组不能为空！</li>"
		Exit Sub
	end if
	if Trim(request.form("Grades")) = "" then
  		founderr = true
  		errmsg = errmsg+"<li>用户等级不能为空！</li>"
		Exit Sub
	end if
	if Trim(request.form("GroupSet(0)")) = "" and Trim(request.form("GroupSet(1)")) = "" then
  		founderr = true
  		errmsg = errmsg+"<li>金钱或下载个数不能为空！</li>"
		Exit Sub
	else
		GroupSetting = "" & request.form("GroupSet(0)") & "," & request.form("GroupSet(1)") & "," & request.form("GroupSet(2)") & ",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,,,,,,,,,,,"
	end if
End Sub
Sub savegroup()
	call checksave()
if FoundErr = False then
	  sql = "select * from [NC_UserGroup] where (groupid is null)"
	  rs.open sql,conn,1,3
  	   rs.addnew
	   rs("groupid") = request.form("newgroupid")
	   rs("GroupName") = request.form("GroupName")
	   rs("Grades") = request.form("Grades")
	   rs("GroupSet") = GroupSetting
	   rs.update
	   rs.close:set rs=nothing
	NC_Admin.Succeed_Msg("<li>添加用户组 "&request.form("GroupName")&" 成功!</li>")
	End If
End Sub
Sub savedit()
	call checksave()
	if FoundErr = False then
	  sql = "select * from [NC_UserGroup] where groupid = " &request.form("groupid")
	  rs.open sql,conn,1,3
	   rs("GroupName") = request.form("GroupName")
	   rs("Grades") = request.form("Grades")
	   rs("GroupSet") = GroupSetting
	   rs.update
	   rs.close:set rs=nothing
	NC_Admin.Succeed_Msg("<li>修改用户组 "&request.form("GroupName")&" 成功!</li>")
	End If
End Sub
Sub delgroup()
	DownsysClass.execute("Delete From NC_UserGroup where groupid="&request("groupid")&"")
	DownsysClass.execute("update NC_user set Grade=1 where Grade="&request("Grade")&"")
	Response.Redirect("admin_group.asp")
End Sub
%>