<!--#INCLUDE FILE="conn.asp" -->
<!--#include file="admin_Checkuser.asp"-->
<HTML><HEAD><title><%=StrVar(1)%>--管理页面</title>
<META http-equiv=Content-Type content="text/html; charset=gb2312">
<!--#include file="inc/admin_main.css"-->
</HEAD>
<BODY leftMargin=0 topMargin=0 marginwidth="0" marginheight="0">
<%
if  not sysadmin or session("adminlogin")<>"0K" Then
	Errmsg=Errmsg+"<br>"+"<li>本页面为管理员专用，请<a href=admin_index.asp target=_top>登陆</a>后进入。"
	Call Error("Information",ErrMsg)
Else
	Call main()
End if
Call endconnection()


Sub main()
%>
<table cellpadding=5 cellspacing=1 border=0 width=90% Class=TableBorder align=center>
  <tr>
	<th>欢迎<b><%=membername%></b>进入管理页面</th>
</tr></table>
		<%
		if Request("action")="merge" Then
			Call merge()
		Else
			Call classinfo()
		End if
End Sub


Sub classinfo()
%>
<SCRIPT LANGUAGE="JavaScript">
function checkinput(cls,aobj)
{
	var nv;
	if (cls==2)
	{nv=main.class2.value;}
	else
	{nv=main.class1.value;}
	if(nv!=""&&!isNaN(nv))
	{
		aobj.href="../Class_index.asp?ClassID="+nv;
		return true;
	}
	window.alert("您输入了错误的学校ID");
	return false;
}
</SCRIPT>

<TABLE border=0 width=600 align=center Class=TableBorder>
<TR>
	<TD class=forumRowHighlight><b>说明：</b><br>
	(1)如果合并前学校2的开放等级为学校管理员审核请改为完全开放后再执行合并操作！<BR>
	(2)合并后的学校将保留学校1的学校信息。<BR>
	(3)合并后的学校需要重新任命管理员。</TD>
</TR>
</TABLE>
<form method="POST" action=admin_merge.asp name=main>
<input type=hidden name=action value=merge>
<table width="600" border="0" cellspacing="1" cellpadding="5"  align=center Class=TableBorder>
<tr> 
	<th height="11" colspan="2" >请输入要合并的学校信息</th>
</tr>
<tr> 
	<td width="41%" height="18" Class=forumrowhighlight>学校1(请输入学校ID)</td>
	<td width="59%" height="18" Class=forumrowhighlight>
	<input type="text" name="class1" size="35">&nbsp;<a href="" target=_blank name=a1 onClick="return checkinput(1,this);">>>转到学校页面</a>
	</td>
</tr>
<tr>
	<td width="41%" height="18" class=forumrow>学校2(请输入学校ID)</td>
	<td width="59%" height="18" class=forumrow> 
	<input type="text" name="class2" size="35">&nbsp;<a href="" target=_blank name=b1 onClick="return checkinput(2,this);">>>转到学校页面</a>
	</td>
</tr>
<tr>
	<td width="41%" height="18" Class=forumrowhighlight>合并后学校的管理员(用户名)</td>
	<td width="59%" height="18" Class=forumrowhighlight><input type="text" name="clsadm1" size="35"></td>
</tr>
<tr>
	<td width="41%" height="18" class=forumrow>合并后学校的管理员2(用户名)</td>
	<td width="59%" height="18" class=forumrow><input type="text" name="clsadm2" size="35"></td>
</tr>
<tr> 
	<td height="23" colspan="2" align=right Class=forumrowhighlight> 
	<input type="submit" name="Submit" value="执行学校合并" class=button>
	</td>
</tr>
</table>
</form>
<%
End Sub


Sub merge()

	dim class1,class2,clsadm1,clsadm2
	dim sql,rs
	dim errmsg,founderr
	dim classname2

	class1=trim(Request.form("class1"))
	if class1="" or not isnumeric(class1) then
		ErrMsg=ErrMsg+"<br>"+"<li>学校1的ID输入有误！"
		founderr=True
	else
		sql="Select classid from class where classid="&class1
		Set rs=conn.execute(sql)
		if rs.eof and rs.bof Then
			ErrMsg=ErrMsg+"<br>"+"<li>学校1不存在。"
			founderr=True
		End if
		set rs=nothing
	end if

	class2=trim(Request.form("class2"))
	if class2="" or not isnumeric(class2) then
		ErrMsg=ErrMsg+"<br>"+"<li>学校2的ID输入有误！"
		founderr=True
	else
		sql="Select classname from class where classid="&class2
		Set rs=conn.execute(sql)
		if rs.eof and rs.bof Then
			ErrMsg=ErrMsg+"<br>"+"<li>学校2不存在。"
			founderr=True
		else
			classname2=rs(0)
		End if
		set rs=nothing
	end if

	clsadm1=trim(Request.form("clsadm1"))

	if clsadm1<>"" Then
		sql="Select userid from joinclass where userid='"&clsadm1&"' and (classid="&class1&" or classid="&class2&")"
		Set	rs=conn.execute(sql)
		if rs.eof Then
			ErrMsg=ErrMsg+"<br>"+"<li>对不起，"&clsadm1&"不是这两个学校的成员。"
			founderr=True
		End if

	End if

	clsadm2=trim(Request.form("clsadm2"))


	if clsadm2<>"" Then
		sql="Select userid from joinclass where userid='"&clsadm2&"' and (classid="&class1&" or classid="&class2&")"
		Set	rs=conn.execute(sql)

		if rs.eof Then
			ErrMsg=ErrMsg+"<br>"+"<li>对不起，"&clsadm2&"不是这两个学校的成员。"
			founderr=True
		End if

	End if

	if founderr=True Then
		Call Error("Information",ErrMsg)
		Exit Sub
	End if

	sql="update Classtopic Set classid="&class1&" where classid="&class2
	conn.execute(sql)
	
	sql="update ClasstopicReply Set classid="&class1&" where classid="&class2
	conn.execute(sql)

	sql="update photo Set classid="&class1&" where classid="&class2
	conn.execute(sql)

	sql="update append Set classid="&class1&" where classid="&class2
	conn.execute(sql)

	sql="delete from votebox where classid="&class2
	conn.execute(sql)

	sql="delete from log where classid="&class2
	conn.execute(sql)

	'write log
	IP=Request.ServerVariables("REMOTE_ADDR") 
	sql="insert into log(userid,content,classid,ip)"&_
		" values('管理员','将学校“"&classname2&"”合并入本校',"&class1&",'"&IP&"')"
	Conn.Execute(sql)

	sql="select userid,degree from joinclass where (classid="&class1&" or classid="&class2&") and degree>1"
	set rs =conn.execute(sql)
	do until rs.eof
		ResignPoint=Round(PointSet(13)*rs(1)/8)
		conn.execute("update student Set point=point+"&ResignPoint&" where userid='"&rs(0)&"'")
		rs.movenext
	loop

	sql="update student Set point=point+"&PointSet(12)&" where userid='"&clsadm1&"' or userid='"&clsadm2&"'"
	conn.execute(sql)

	sql="delete from joinclass where classid="&class2&" and userid in (Select userid from joinclass where classid="&class1&")"
	conn.execute(sql)

	sql="update joinclass Set classid="&class1&" where classid="&class2
	conn.execute(sql)

	sql="update joinclass set degree=1 where classid="&class1&" and degree>1"
	conn.execute(sql)
	
	sql="update joinclass set degree=8 where classid="&class1&" and userid='"&clsadm1&"'"
	conn.execute(sql)

	sql="update joinclass set degree=8 where classid="&class1&" and userid='"&clsadm2&"'"
	conn.execute(sql)

	sql="Select count(userid) from joinclass where classid="&class1
	Set rs=conn.execute(sql)

	sql="update class Set admin1='"&clsadm1&"',admin2='"&clsadm2&"',studcount="&rs(0)&" where classid="&class1
	conn.execute(sql)

	sql="delete from class where classid="&class2
	conn.execute(sql)

	sql="update config set ClassNum=ClassNum-1"
	conn.execute(sql)

		Set rs=Nothing

Call adminmsg("恭喜，学校合并成功！建议更新每个用户注册的学校数！")

End Sub%>
</BODY></HTML>


