<!--#INCLUDE FILE="setup.asp" -->
<!--#INCLUDE FILE="checkuser.asp" -->
<!--#INCLUDE FILE="theme.asp" -->
<!--#INCLUDE FILE="include/char.asp" -->
<%
Dim Locat,Act
Locat="附加通信录"

If MemberName="" Then
  	ErrMsg=ErrMsg+"<br>"+"<li>您还没有<a href=login.asp>登录</a>。"
	Call top(1,1)
	Call Error("Information",ErrMsg)
Else
	Dim ClsID,Degree,ClassName
	Dim joinstatus
	ClsID=Request("ClassID")
	joinstatus=chkjoinclass(ClsID)
	If joinstatus<>"" Then
		Call top(1,1)
		Call Error("Exclamation",joinstatus)
	Else
		Select Case Request("Action")
		Case "add"
			act="添加同学信息"
			Call top(2,1)
			Call AddForm()
			Call footer()
		Case "save"
			act="添加同学信息"%>
			<!--#INCLUDE FILE="include/chkAppend.asp" -->
			<%Call top(2,1)
			Call SaveAppend()
			Call footer()
		Case "Delete"
			act="删除同学信息"
			Call pagehead()
			Call RemoveAppend()
		Case "modify"
			act="修改同学信息"%>
			<!--#INCLUDE FILE="include/chkAppend.asp" -->
			<%Call pagehead()
			Call SaveEdit()
		Case "edit"
			act="修改同学信息"
			Call pagehead()
			Call EditForm()
		Case "ViewDetail"
			act="查看同学详细信息"
			Call pagehead()
			Call Detail()
		Case Else
			Call top(2,1)
			Call ListAppend()
			Call footer()
		End Select
	End If
End If


Sub Detail()

	dim AppendID,ErrMsg,Rs

	response.write "<table width=100% height=100% bgcolor="&BodyColor&"><tr><td valign=top>"
	AppendID=Request("id")
	'name,collector,telephone,address,zipcode,other,mobilephone
	Set Rs=Conn.Execute("Select * from append where id="&AppendID&" and classid="&ClsID)

	If Rs.eof or Rs.bof Then
		ErrMsg=ErrMsg+"<br>"+"<li>非法操作，该同学的信息不存在！"
		Call Error("Exclamation",ErrMsg)
	Else

	%>
		<BR><table cellSpacing="1" width="361" cellpadding=4 border="0" align=center bgcolor="<%=DarkTBColor%>">
		  <tr>
			<th>附加通讯录</th></tr><tr><td>
			<table cellSpacing="1" width="380" border="0" Class=TableBorder cellpadding=3>
			  <tr Class=LightTableBody>
				<td align="right" colSpan="2" valign=center>本信息由<font color=brown><%=getrealname(Rs("collector"))%></font>提供
				<%If MemberName=Rs("collector") or Degree>1 or sysadmin Then
				Response.Write "<a href=AppendList.asp?ClassID="&ClsID&"&Action=edit&ID="&Rs("id")&"><img src=images/edit.gif border=0></a>&nbsp;<a onclick=""return confirm('您确认要删除这个同学的信息吗?')"" href=AppendList.asp?ClassID="&ClsID&"&Action=Delete&ID="&Rs("id")&"><img src=images/recycle.gif border=0></a>"
				End If
				%></td>
			  </tr>
			  <tr Class=LightTableBody>
				<td width="345" colSpan="2">&nbsp;姓&nbsp;&nbsp;&nbsp;&nbsp;名：<font
				color="brown"><%=htmlencode(Rs("name"))%></font></td>
				
			  </tr>
			  <tr Class=LightTableBody>
				<td width="345" colSpan="2">&nbsp;联系电话：<%=Rs("telephone")%></td>
				
			  </tr>
			  <tr Class=LightTableBody>
				<td width="345" colSpan="2">&nbsp;移动电话：<%=Rs("mobilephone")%></td>
				
			  </tr>
			  <tr Class=LightTableBody>
				<td width="345" colSpan="2">&nbsp;通信地址：<%=htmlencode(Rs("address"))%></td>
			  </tr>
			  <tr Class=LightTableBody>
				<td width="345" colSpan="2">&nbsp;邮政编码：<%=Rs("zipcode")%></font></td>
			  </tr>
	<tr Class=LightTableBody>
				<td width="345" colSpan="2">&nbsp;其他信息：<%=htmlencode(Rs("other"))%></td>
			  </tr>
			</table>
			</td>
		  </tr>
		</table>
			</td>
		  </tr>
		</table>

	<%

	End If
	Set Rs=Nothing

End Sub


Sub ListAppend()

	Dim Rs,sql
	Dim CurrentPage,TotalPages
	Dim PageSize,i
	Dim keyword,cond
	PageSize=20

	Response.Write "<BR><BR>"&_
			"<table width=""100%"" align=center cellspacing=0 cellpadding=0 border=0><form action=AppendList.asp?ClassID="&ClsID&" method=post><tr><td align=left width=200></td>"&_
			"<td align=center valign=bottom><INPUT TYPE=text NAME=keyword maxlength=4><INPUT TYPE=submit value=查询 class=button></td>"&_
			"<td align=right valign=bottom><input onClick=""location.href='AppendList.asp?ClassID="&ClsID&"&Action=add'"" type=button value=添加同学 class=button>"&_
			"&nbsp;<input onClick=""location.href='ClassMate.asp?ClassID="&ClsID&"'"" type=button value=班级名册 class=button>"&_
			"&nbsp;<input name=Button onClick=document.all.WebBrowser.ExecWB(6,1) type=button value=打印本页 class=button>"&_
			"<OBJECT classid=ClsID:8856F961-340A-11D0-A96B-00C04FD705A2 height=0 id=WebBrowser width=0></OBJECT>"&_
			"</td></tr></form></table>"&_
			 "<table width=""100%"" border=0 cellspacing=1 cellpadding=4 align=center class=TableBorder>"&_
			"<tr><th>姓名</th><th>电话</th><th>手机</th><th>通讯地址</th><th>邮编</th></tr>"


	keyword=trim(request.form("keyword"))
	if keyword<>"" then
		cond=" name like '%"&keyword&"%' and"
	end if

	sql="select id,name,telephone,address,zipcode,mobilephone from append where"&cond&_
		" classid="&ClsID&" order by id desc"
	Set Rs = server.CreateObject("ADODB.Recordset")

	Rs.open sql,Conn,1,1

	If Rs.eof or Rs.bof Then
		Response.Write "<tr class=LightTableBody><td colSpan=6 width=100% height=27>"&_
			"没有找到任何附加同学联络信息：）</td></tr></table><BR>"
	Else

	Rs.pagesize=pagesize
	totalpages=Rs.pagecount

	currentPage=Request("page")

	If currentpage="" Then currentpage=1
	If not isnumeric(currentpage) Then
		currentpage=1
	ElseIf cint(currentpage)>totalpages Then
		currentpage=totalpages
	End If
	currentpage=Cint(currentpage)
	Rs.absolutepage=currentpage

	for i=1 to pagesize

	Response.Write "<tr class=LightTablebody>"&_
		"<td><a href=""javascript:openScript('AppendList.asp?ClassID="&ClsID&"&Action=ViewDetail&ID="&_
		Rs(0)&"',420,280)"" title=查看详细信息>"&Rs(1)&"</a></td>"&_
		"<td>"&Rs(2)&"</td><td>"&Rs(5)&"</td>"&_
		"<td>"&htmlencode(Rs(3))&"</td><td align=center>"&Rs(4)&"</td></tr>"

	Rs.movenext

	if currentpage=totalpages then
		if rs.eof then exit for
	end if 
	next


	Response.Write "</table>"&_
		"<table width=100% align=center>"&_
		"<tr><td align=left valign=center>"

	If currentpage>1 Then
		Response.Write "　<a href=""?Page="&currentpage-1&"""><img src=images/left.gif border=0 hspace=2>上一页</a>"
	End If
			
	If currentpage<totalpages Then
		Response.Write "　<a href=""?Page="&currentpage+1&"""><img src=images/right.gif border=0 hspace=2>下一页</a>"
	End If
	Response.Write "</td><td align=right valign=center>"&_
			"页 "&currentpage&"&nbsp;/&nbsp;"&totalpages&"&nbsp;&nbsp;&nbsp;去第"&_
			"&nbsp;<input type=text name=targetPage size=2 style=""height:16px;width:20px;"">&nbsp;页</td>"&_
			"<td width=15 align=right style=""cursor:hand"" onclick=""location.href='?ClassID="&ClsID&"&Page='+targetPage.value;"">"&_
			"<img src=images/btngo.gif width=13 height=15>"&_
			"</td></tr></table>"

	End If
	rs.close:Set Rs=Nothing

End Sub


Sub AddForm()
%>
<br><br>
<form style="MARGIN: 0px" name="frmappend" action="AppendList.asp?ClassID=<%=ClsID%>" method="post"
        onsubmit="return submitonce(this)">
          <input type="hidden" name="Action" value="save">
<table border="0" cellspacing="1" width="500" cellpadding="5" Class=TableBorder  align=center>
<tr>
<th colspan=2 align=center>添加附加通信录</th></tr>
<tr Class=LightTableBody>
	<td height="13" align=center>同学姓名</td>
	<td>&nbsp;&nbsp;<input size="30" name="name" maxlength=16></td>
</tr>
<tr Class=LightTableBody>
	<td height="13" align=center>联系电话</td>
	<td>&nbsp;&nbsp;<input size="30" name="telephone"></td>
</tr>
<tr Class=LightTableBody>
	<td height="13" align=center>移动电话</td>
	<td>&nbsp;&nbsp;<input size="30" name="mobilephone"></td>
</tr>
<tr Class=LightTableBody>
	<td align=center>邮政编码</td>
	<td>&nbsp;&nbsp;<input size="30" name="zipcode" maxlength=6></td>
</tr>

<tr Class=LightTableBody>
	<td align=center>通信地址</td>
	<td>&nbsp;&nbsp;<input size="50" name="address"></td>
</tr>
<tr Class=LightTableBody>
	<td valign="center" align=center>其他信息</td>
	<td>&nbsp;&nbsp;<textarea rows="4" cols="50" name="other"></textarea></td>
</tr>
<tr Class=LightTableBody>
	<td colspan=2 valign=center><img src=images/reminder.gif>&nbsp;只有你和班级管理员才有权修改和删除你录入的通信资料！</td>
</tr>
<tr Class=DarkTableBody>
	<td height="30" align="center" colspan=2>
	<input style="WIDTH: 60px" type="submit" value="添&nbsp;加" class=button>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
	<input style="WIDTH: 60px" type="button" value="返&nbsp;回" onclick="javascript:history.go(-1)" class=button> </td>
</tr>
</table>
</form>
<BR>
<%
End Sub


Sub SaveAppend()

	Dim Action
	Dim ErrMsg,FoundErr
	Action=Request.form("action")

	If action<>"save" Then
		ErrMsg=ErrMsg+"<br>"+"<li>没有操作请求，您正试图进行非法操作！"
		founderr=True
		Call Error("Critical",ErrMsg)
		Exit Sub
	End If

	If chkinput=True Then
		name=Request("name")
		telephone=Request("telephone")
		mobilephone=Request("mobilephone")
		address=Trim(Request("address"))
		zipcode=Request("zipcode")
		other=rtrim(Request("other"))
		Set Rs = Server.CreateObject("ADODB.Recordset")
		Rs.open "append",Conn,1,3
		Rs.addnew
		Rs("name")=name
		If telephone<>"" Then Rs("telephone")=telephone
		If mobilephone<>"" Then Rs("mobilephone")=mobilephone
		If address<>"" Then Rs("address")=address
		If zipcode<>"" Then Rs("zipcode")=zipcode
		Rs("collector")=MemberName
		Rs("classid")=ClsID
		If other<>"" Then Rs("other")=other
		Rs.update
		Rs.close
		Set Rs=Nothing
		sql="update student Set point=point+"&PointSet(5)&" where userid='"&MemberName&"'"
		Conn.Execute(sql)

		rURL="AppendList.asp?ClassID="&ClsID
		rtitle="添加同学信息成功"
		rmsg="本页面将在2秒后自动返回附加通讯录页面<br><ul>"&_
			"<li><a href="&rURL&">返回附加通讯录</a></li>"&_
			"</ul>"
		Redirect 3,rurl,rtitle,rmsg

	End If

End Sub



Sub RemoveAppend()
	
	dim AppendID
	dim sql,rs

	response.write "<table width=100% height=100% bgcolor="&BodyColor&"><tr><td valign=top>"

	AppendID=Request("id")

	If AppendID="" Then
		ErrMsg=ErrMsg+"<br>"+"<li>操作失败，缺少参数！"
		Call Error("Exclamation",ErrMsg)
		Exit Sub
	End If

	sql="Select collector,classid from append where id="&AppendID
	Set Rs=Conn.Execute(sql)

	If Rs.eof and Rs.bof Then
		ErrMsg=ErrMsg+"<br>"+"<li>操作失败！指定的同学信息不存在！"
		FoundErr=True
	Else
		If not sysadmin Then
			If Clng(ClsID)<>Rs(1) Then
				ErrMsg=ErrMsg+"<br>"+"<li>非法操作，您无权删除其他班级的附加同学信息！"
				founderr=True
			ElseIf ChkRights(7)=False and Rs(0)<>MemberName Then
				ErrMsg=ErrMsg+"<br>"+"<li>操作失败，您无权删除班内其他同学添加的附加同学信息！"
				founderr=True
			End If
		End If
	End If

	If founderr=True Then
		Call Error("Exclamation",ErrMsg)
		Exit Sub
	End If

	sql="update student Set point=point+"&PointSet(7)&" where userid='"&Rs(0)&"'"
	Conn.Execute(sql)

	Set Rs=Nothing

	sql="delete from append where id="&AppendID
	Conn.Execute(sql)

	Call success("删除同学信息","删除同学信息成功！")

End Sub



Sub EditForm()

	dim AppendID
	response.write "<table width=100% height=100% bgcolor="&BodyColor&"><tr><td valign=top>"

	AppendID=Request("id")
	Set Rs=Conn.Execute("Select * from append where id="&AppendID)

	If Rs.eof or Rs.bof Then
		ErrMsg=ErrMsg+"<br>"+"<li>非法操作，指定的附加同学信息不存在"
		Call Error("Exclamation",ErrMsg)
	Else
	%>
	<br>
	<form style="MARGIN: 0px" name="frmteach" action="AppendList.asp?ClassID=<%=ClsID%>" method="post"
			onsubmit="return submitonce(this)">
			  <input type="hidden" name="appendid" value="<%=AppendID%>">
			  <input type="hidden" name="Action" value="modify">
	<table border="0"
			  cellspacing="1" width="400" cellpadding="5" Class=TableBorder  align=center>
	<tr>
	<th colspan=2 align=center>修改附加通信录</th></tr>
	<tr Class=LightTableBody>
		<td height="13" align=center>同学姓名&nbsp;</td>
		<td><input size="30" name="name" maxlength=16 value="<%=Rs("name")%>"></td>
	</tr>
	<tr Class=LightTableBody>
		<td height="13" align=center>联系电话&nbsp;</td>
		<td><input size="30" name="telephone"  value="<%=Rs("telephone")%>"></td>
	</tr>
	<tr Class=LightTableBody>
		<td height="13" align=center>移动电话&nbsp;</td>
		<td><input size="30" name="mobilephone"  value="<%=Rs("mobilephone")%>"></td>
	</tr>
	<tr Class=LightTableBody>
		<td align=center>邮政编码&nbsp;</td>
		<td><input size="30" name="zipcode" maxlength=6  value="<%=Rs("zipcode")%>"></td>
	</tr>
	<tr Class=LightTableBody>
		<td align=center>通信地址&nbsp;</td>
		<td><input size="50" name="address"  value="<%=Rs("address")%>"></td>
	</tr>
	<tr Class=LightTableBody>
		<td valign="center" align=center>其他信息&nbsp;</td>
		<td><textarea rows="4" cols="50" name="other"><%=Rs("other")%></textarea></td>
	</tr>
	<tr Class=LightTableBody>
		<td colspan=2 valign=center><img src=images/reminder.gif>&nbsp;只有你和班级管理员才有权修改和删除你录入的通信资料！</td>
	</tr>
	<tr Class=DarkTableBody>
		<td height="30" align="center" colspan=2>
		<input style="WIDTH: 60px; HEIGHT: 20px" type="submit" value="修&nbsp;改" name="submit" class=button>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
		<input style="WIDTH: 60px; HEIGHT: 20px" type="button" value="返&nbsp;回" onclick="javascript:history.go(-1)"
				  name="reset" class=button> </td>
	</tr>
	</table>
	</form>

</td></tr></table>
	<%
	End If
	Set Rs=Nothing

End Sub


Sub SaveEdit()

	response.write "<table width=100% height=100% bgcolor="&BodyColor&"><tr><td valign=top>"

	appendid=Request.form("appendid")
	If appendid="" Then
		ErrMsg=ErrMsg+"<br>"+"<li>没有操作请求，您正试图进行非法操作！"
		Call Error("Exclamation",ErrMsg)
		Exit Sub
	End If

	sql="Select collector,classid from append where id="&appendid
	Set Rs=Conn.Execute(sql)

	If not sysadmin Then
		If Clng(ClsID)<>Rs(1) Then
			ErrMsg=ErrMsg+"<br>"+"<li>非法操作，您无权修改其他班级的附加同学信息！"
			founderr=True
		ElseIf ChkRights(7)=False and Rs(0)<>MemberName Then
			ErrMsg=ErrMsg+"<br>"+"<li>操作失败，您无权修改班内其他同学添加的附加同学信息！"
			founderr=True
		End If
	End If

	If founderr=True Then
		Call Error("Exclamation",ErrMsg)
		Exit Sub
	End If

	Set Rs=Nothing

	If chkinput=True Then
		name=Request("name")
		telephone=Request("telephone")
		mobilephone=Request("mobilephone")
		address=Trim(Request("address"))
		zipcode=Request("zipcode")
		other=rtrim(Request("other"))
		Set Rs = Server.CreateObject("ADODB.Recordset")
		sql="Select * from append where id="&Clng(appendid)
		Rs.open sql,Conn,1,3
			Rs("name")=name
			Rs("collector")=MemberName
			If telephone<>"" Then Rs("telephone")=telephone Else Rs("telephone")=null
			If mobilephone<>"" Then Rs("mobilephone")=mobilephone Else Rs("mobilephone")=null
			If address<>"" Then Rs("address")=address Else Rs("address")=null
			If zipcode<>"" Then Rs("zipcode")=zipcode Else Rs("zipcode")=null
			If other<>"" Then Rs("other")=other Else Rs("other")=null
		Rs.update
		Rs.close
		sql="update student Set point=point+"&PointSet(6)&" where userid='"&MemberName&"'"
		Conn.Execute(sql)
		Set Rs=Nothing
		stitle="修改同学信息"
		smsg="修改附加同学信息成功！"
		Call success(stitle,smsg)

	End If

End Sub
%>





