<!--#INCLUDE FILE="conn.asp" -->
<!--#INCLUDE FILE="Class_Checkuser.asp" -->
<!--#INCLUDE FILE="Class_Top.asp" -->
<!--#INCLUDE FILE="inc/char.asp" -->

<%locat="教师通信录"
dim schoolid
Dim ClsID,ClassName
schoolid=request("schoolid")
if membername="" Then
  	ErrMsg=ErrMsg+"<br>"+"<li>您还没有<a href=Class_Login.asp><font color=red>登录或注册校友录</font></a>。"
	Call top(1,1)
	Call Error("Information",ErrMsg)
	call footer()
	response.end
	
else
if schoolid="" then
 	ErrMsg=ErrMsg+"<br>"+"<li>请确定您是从学校页面进入！</a>"
	Call top(1,1)
	Call Error("Information",ErrMsg)
	 call footer()
	response.end
else
schoolid=clng(schoolid)
dim rs
set rs=conn.execute("select * from joinclass where classid="&schoolid&" and userid='"&membername&"'")
	if rs.eof and rs.bof Then
	ErrMsg=ErrMsg+"<br><li>对不起，您不是此学校的学生，无法查看该教师通讯录！"
	Call top(1,1)
	Call Error("Exclamation",ErrMsg)
	 call footer()
	 response.end
    end if
ClsID=schoolid
Set Rs=Conn.Execute("Select classname,passed from class where classid="&ClsID)
if not (Rs.eof and Rs.bof) Then
ClassName=Rs(0)
End if
Set Rs=nothing
end if

	Select Case Request("action")
	Case "add"
		act="添加教师信息"
		Call top(2,1)
		Call AddForm()
		
	Case "save"
		act="添加教师信息"%>
		<!--#INCLUDE FILE="inc/chkTeacher.asp" -->
		<%Call top(2,1)
		Call SaveTeacher()
		
	Case "Delete"	
		act="删除教师信息"
		Call pagehead()
		Call RemoveTeacher()
	Case "modify"
		act="修改教师信息"%>
		<!--#INCLUDE FILE="inc/chkTeacher.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 TeacherList()
		
	End Select
End if

 call footer()
Sub detail()

dim TeacherID
dim rs
dim ErrMsg
%>

<table width=100% height=100% bgcolor=<%=BodyColor%>><tr><td valign=top>
<%
TeacherID=Request("id")
Set rs=conn.execute("Select * from teacher where id="&TeacherID)

if rs.eof or rs.bof Then
	ErrMsg=ErrMsg+"<br>"+"<li>非法操作，该教师的信息不存在"
	Call Error("Critical",ErrMsg)
Else

%>
		<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><a href="javascript:openScript('Class_Userinfo.asp?Name=<%=htmlencode(rs("collector"))%>',420,320)"><%=htmlencode(rs("collector"))%></a></font>提供
			<%if membername=rs("collector") or sysadmin Then

			Response.Write "<a href=""?schoolid="&schoolid&"&Action=edit&id="&rs("id")&"""><img src=images/edit.gif border=0></a>&nbsp;<a onclick=""javascript:return confirm('您确认要删除这个教师的信息吗?')""  href=""?schoolid="&schoolid&"&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="red"><%=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;电子邮件：
			<%=rs("email")%></td>
          </tr>
          <tr Class=LightTableBody>
            <td width="345" colSpan="2">&nbsp;通信地址：<%=htmlencode(rs("address"))%></td>
          </tr>
          <tr Class=LightTableBody>
            <td width="345" colSpan="2"><p align="left">&nbsp;邮政编码：<%=rs("zipcode")%></td>
          </tr>
<tr Class=LightTableBody>
            <td width="345" colSpan="2"><p align="left">&nbsp;其他信息：<%=htmlencode(rs("other"))%></td>
          </tr>
        </table>
        </td>
      </tr>
    </table>
	</td></tr></table>
<%
End if
Set rs=Nothing

End Sub


Sub TeacherList()

	Dim rs,sql
	dim keyword,cond
	dim CurrentPage,TotalPages
	Dim PageSize,i
	Pagesize=20
	%>
	<BR>
	<table width="100%" align=center cellspacing=0 cellpadding=0 border=0>
	<form action=Class_TeacherList.asp?schoolid=<%=schoolid%> method=post>
	<tr><td align=left width=220><IMG SRC=images/teacher.gif width=120></td>
	<td 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='Class_TeacherList.asp?schoolid=<%=schoolid%>&Action=add'" 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><th>邮编</th></tr>
	<%
	
	keyword=trim(request.form("keyword"))
	if keyword<>"" then
		cond=" and name like '%"&keyword&"%'"
	end if

	sql="Select id,name,telephone,email,address,zipcode,mobilephone from teacher where schoolid="&schoolid&" "&cond&" 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>"&_
			"<font color="&TableContentColor&">没有找到任何教师信息：(</font></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('Class_TeacherList.asp?schoolid="&schoolid&"&Action=ViewDetail&ID="&_
			rs(0)&"',420,280)"" title=查看详细信息>"&rs(1)&"</a></td>"&_
			"<td>"&rs(2)&"</td><td align=center>"&rs(6)&"</td>"&_
			"<td><a href=""mailto:"&rs(3)&""">"&rs(3)&"</td><td>"&htmlencode(rs(4))&"</td>"&_
			"<td align=center>"&rs(5)&"</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=""?schoolid="&schoolid&"&Page="&currentpage-1&"""><img src=images/left.gif border=0 hspace=2>上一页</a>"
	End if
			
	if currentpage<totalpages Then
		Response.Write "　<a href=""?schoolid="&schoolid&"&Page="&currentpage+1&"""><img src=images/right.gif border=0 hspace=2>下一页</a>"
	End if
	Response.Write "</td><td align=right valign=center>"&_
			"页次:"&currentpage&"/"&totalpages&"&nbsp;&nbsp;&nbsp;去第"&_
			"&nbsp;<select name=""page"" style=""width:35px"" onChange=""location.href='?schoolid="&schoolid&"&page='+this.options[selectedIndex].value"">"

             i=1
             do while i<=totalpages
             if i=currentPage then
             response.write("<option selected value="&i&">"&i&"</option>")
             else
             response.write("<option value="&i&">"&i&"</option>")
             end if
             i=i+1
             loop

	Response.Write "</select>&nbsp;页</td>"&_
			"<td width=15></td></tr></table>"

	End if

	Rs.close
	Set rs=Nothing

End Sub


Sub AddForm()
%>
<br><br>
<form style="MARGIN: 0px" name="frmteach" action="Class_TeacherList.asp?schoolid=<%=schoolid%>" method="post"
        onsubmit="return submitonce(this)">
          <input type="hidden" name="Action" value="save">
		  <input type="hidden" name="schoolid" value=<%=schoolid%>>
  <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="email"></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" bordercolor="#EBEBEB" colspan=2>
	<input style="WIDTH: 70px" type="submit" value="添&nbsp;&nbsp;加" name="submit" class=button>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
	<input style="WIDTH: 70px" type="button" value="返&nbsp;&nbsp;回"
              name="reset" onClick="javascript:history.go(-1)" class=button> </td>
</tr>
</table>
</form>
<BR>
<%
End Sub


Sub SaveTeacher()

if chkinput=True Then
	name=Request("name")
	schoolid=Request("schoolid")
	telephone=Request("telephone")
	mobilephone=Request("mobilephone")
	email=trim(Request("email"))
	address=trim(Request("address"))
	zipcode=Request("zipcode")
	other=rtrim(Request("other"))
	Set rs = Server.CreateObject("ADODB.Recordset")
	rs.open "teacher",conn,1,3
	rs.addnew
	rs("name")=name
	rs("schoolid")=schoolid
	if telephone<>"" Then rs("telephone")=telephone
	if mobilephone<>"" Then rs("mobilephone")=mobilephone
	if email<>"" Then rs("email")=email
	if address<>"" Then rs("address")=address
	if zipcode<>"" Then rs("zipcode")=zipcode
	rs("collector")=membername
	if other<>"" Then rs("other")=other
	rs.update
	rs.close
	Set rs=Nothing
	sql="update student Set point=point+"&PointSet(2)&" where userid='"&membername&"'"
	conn.execute(sql)

	rURL="Class_TeacherList.asp?schoolid="&schoolid&""
	rtitle="添加教师信息成功"
	rmsg="<FONT COLOR="&TableContentcolor&">本页面将在2秒后自动返回教师通讯录页面<br><ul>"&_
		"<li><a href=Class_TeacherList.asp?schoolid="&schoolid&"><font color="&TableContentcolor&">返回教师通讯录</font></a></li>"&_
		"</ul>"
	Redirect 2,rurl,rtitle,rmsg

End if
End Sub


Sub RemoveTeacher()

	teacherid=Request("id")

	Response.Write "<table width=100% height=100% bgcolor="&BodyColor&" align=center><tr><td valign=top>"
	if teacherid="" Then
		ErrMsg=ErrMsg+"<br>"+"<li>没有操作请求，您正试图进行非法操作！"
		Call Error("Exclamation",ErrMsg)
		Exit Sub
	End if

	sql="Select collector from teacher where id="&teacherid
	Set rs=conn.execute(sql)
	if rs.eof and rs.bof Then
		ErrMsg=ErrMsg+"<br>"+"<li>操作失败！指定的教师信息不存在！"
		FoundErr=True
	ElseIf rs(0)<>membername and not sysadmin Then
		ErrMsg=ErrMsg+"<br>"+"<li>您无权删除其他同学添加的教师信息！"
		FoundErr=True
	End if

	if founderr Then
		Call Error("Exclamation",ErrMsg)
		Exit Sub
	End if


	conn.execute("update student Set point=point+"&PointSet(4)&" where userid='"&rs(0)&"'")
	conn.execute("delete from teacher where id="&teacherid)

	Set rs=Nothing
	Call success("删除教师信息","删除教师信息成功！")

End Sub


Sub EditForm()

	Dim TeacherID
	Dim rs,ErrMsg
	TeacherID=Request("id")
	Set rs=conn.execute("Select * from teacher where id="&TeacherID)

	if rs.eof or rs.bof Then
		ErrMsg=ErrMsg+"<br>"+"<li>非法操作，该教师的信息不存在"
		Call Error("Critical",ErrMsg)
	Else
	%><table width=100% height=100% bgcolor=<%=BodyColor%>><tr><td valign=top>
<br>
	<form style="MARGIN: 0px" name="frmteach" action="Class_TeacherList.asp?schoolid=<%=schoolid%>" method="post"
			onsubmit="return submitonce(this)">
			  <input type="hidden" name="teacherid" value="<%=TeacherID%>">
			  <input type="hidden" name="Action" value="modify">
	<table border="0"
			  cellspacing="1" width="400" cellpadding="4" Class=TableBorder  align=center>
	<tr>
	<th colspan=2 align=center>修改教师通信录</th></tr>
	<tr Class=LightTableBody>
		<td height="13" align=center>教师姓名&nbsp;</td>
		<td>&nbsp;&nbsp;<input size="30" name="name" maxlength=16 value="<%=rs("name")%>"></td>
	</tr>
	<tr Class=LightTableBody>
		<td height="13" align=center>电子邮件&nbsp;</td>
		<td>&nbsp;&nbsp;<input size="30" name="email"  value="<%=rs("email")%>"></td>
	</tr>
	<tr Class=LightTableBody>
		<td height="13" align=center>联系电话&nbsp;</td>
		<td>&nbsp;&nbsp;<input size="30" name="telephone"  value="<%=rs("telephone")%>"></td>
	</tr>
	<tr Class=LightTableBody>
		<td height="13" align=center>移动电话&nbsp;</td>
		<td>&nbsp;&nbsp;<input size="30" name="Mobilephone"  value="<%=rs("Mobilephone")%>"></td>
	</tr>

	<tr Class=LightTableBody>
		<td align=center>邮政编码&nbsp;</td>
		<td>&nbsp;&nbsp;<input size="30" name="zipcode" maxlength=6  value="<%=rs("zipcode")%>"></td>
	</tr>
	<tr Class=LightTableBody>
		<td align=center>通信地址&nbsp;</td>
		<td>&nbsp;&nbsp;<input size="50" name="address"  value="<%=rs("address")%>"></td>
	</tr>
	<tr Class=LightTableBody>
		<td valign="center" align=center>其他信息&nbsp;</td>
		<td>&nbsp;&nbsp;<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: 70px" type="submit" value="修&nbsp;&nbsp;改" name="submit" class=button>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			<input style="WIDTH: 70px" type="button" value="返&nbsp;&nbsp;回"
				  name="reset" onClick="javascript:history.go(-1)" class=button> </td>
	</tr>
	</table>
	</form>
</td>
	</tr>
	</table>
	<%
	End if
	Set rs=Nothing

End Sub


Sub SaveEdit()

	Dim TeacherID
	Dim ErrMsg,FoundErr
	Dim sql,rs
	TeacherID=Request("teacherid")

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

	sql="Select collector from teacher where id="&TeacherID
	Set rs=conn.execute(sql)
	if rs(0)<>membername and not sysadmin Then
		ErrMsg=ErrMsg+"<br>"+"<li>您无权修改其他同学添加的教师信息！"
		Call Error("Exclamation",ErrMsg)
		Exit Sub
	End if
	Set rs=Nothing

	if chkinput=True Then
		name=Request("name")
		telephone=Request("telephone")
		mobilephone=Request("mobilephone")
		email=trim(Request("email"))
		address=trim(Request("address"))
		zipcode=Request("zipcode")
		other=rtrim(Request("other"))
		Set rs = Server.CreateObject("ADODB.Recordset")
		sql="Select * from teacher where id="&Clng(TeacherID)
		rs.open sql,conn,1,3
			rs("name")=name
			if telephone<>"" Then rs("telephone")=telephone Else rs("telephone")=null
			if mobilephone<>"" Then rs("mobilephone")=mobilephone Else rs("mobilephone")=null
			if email<>"" Then rs("email")=email Else rs("email")=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
		conn.execute("update student Set point=point+"&PointSet(3)&" where userid='"&membername&"'")
		Set rs=Nothing
		Call success("编辑教师信息","编辑教师信息成功！")
	End if

End Sub


%>