<!--#INCLUDE FILE="conn.asp" -->
<!--#INCLUDE FILE="Class_Checkuser.asp" -->
<!--#INCLUDE FILE="Class_Top.asp" -->
<!--#INCLUDE FILE="inc/char.asp" -->
<%
locat="学校相册"

Dim fototype(3)
fototype(0)="校园风光"
fototype(1)="同学合影"
fototype(2)="真我风采"
fototype(3)="其他照片"

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)
	
Else
	Dim ClsID,Degree,ClassName
	ClsID=Request("ClassID")
	joinstatus=chkjoinclass(ClsID)
	if joinstatus<>"" Then
		Call top(1,1)
		Call Error("Exclamation",joinstatus)
	Else
		Select Case Request("action")
		Case "EditPhoto"
			act="编辑相片"
			Call pagehead()
			Call editform()
		Case "DelPhoto"
			act="删除相片"
			Call pagehead()
			Call Deletephoto()
		Case "BatchDel"
			act="批量删除照片"
			Call top(3,1)
			Call BatchDel()
			Call footer()
		Case "BatchMove"
			act="批量移动照片"
			Call top(3,1)
			Call BatchMove()
			Call footer()
		Case "SaveEdit"
			act="编辑照片"
			Call pagehead()
			Call editphoto()
		Case "DelComment"
			act="删除照片评论"
			Call pagehead()
			Call DelComment()
		End Select 
	End if
End if


Sub DelComment()

	Dim rs,sql
	Response.Write "<table width=700 align=center height=300><tr><td valign=top>"

	id=Request("id")
	photoid=Request("photoid")

	if id="" Then
		ErrMsg=ErrMsg+"<br>"+"<li>操作失败！请选择要删除的相片评论。"
		Call Error("Critical",ErrMsg)
		Exit Sub
	End if

	sql = "Select p.classid,c.name from photo p inner join comment c on p.picid=c.picid where c.id="&id
	Set rs=Conn.Execute(sql)
	if rs.Eof and rs.bof Then
		ErrMsg=ErrMsg+"<br>"+"<li>操作失败！该相片评论不存在。"
		founderr=True
	Else
		if not sysadmin Then
			if rs(0)<>Clng(ClsID) Then
				ErrMsg=ErrMsg+"<br>"+"<li>非法操作，您无权删除其他学校同学的照片评论！"
				FoundErr=True
			ElseIf ChkRights(5)=False and rs(1)<>membername Then
				ErrMsg=ErrMsg+"<br>"+"<li>操作失败，您无权删除校内其他同学的照片评论！"
				FoundErr=True
			End if
		End if
	End if


	if founderr=True Then
		Call Error("Exclamation",ErrMsg)
	Else

		sql="update student Set point=point+"&PointSet(23)&" where userid='"&rs(1)&"'"
		Conn.Execute(sql)

		sql="delete from comment where id="&Clng(id)
		Conn.Execute(sql)


		RURL="Class_Album.asp?ClassID="&ClsID&"&Action=ShowPhoto&PhotoID="&Clng(photoid)
		Rtitle="删除相片评论成功"
		Rmsg="本页面将在2秒后自动返回学校相册页面<br><ul>"&_
			"<li><a href="&RURL&">返回查看相片</a></li>"&_
			"</ul>"
		Redirect 2,RURL,Rtitle,Rmsg
	End if

	Set rs=Nothing

End Sub



Sub BatchMove()

	Dim idlist
	Dim phototype

	if Request("photoid")="" Then
		ErrMsg=ErrMsg+"<br>"+"<li>操作失败，请选择所要进行操作的相片！"
		Call Error("Information",ErrMsg)
		Exit Sub
	End if
	   

	if ChkRights(5)=False Then
		ErrMsg=ErrMsg+"<br>"+"<li>操作失败！您没有执行此项操作的权限！"
		Call Error("Exclamation",ErrMsg)
		Exit Sub
	End if

	phototype=Request.form("phototype")
	if not isinteger(phototype) Then
		phototype=0
	Else
		phototype=cint(phototype)
		if phototype<0 Then phototype=0
		if phototype>ubound(fototype) Then phototype=ubound(fototype)
	End if

	idlist=Request.form("photoid")

	sql="update photo Set typeid="&phototype&" where classid="&ClsID&" and picid in ("&idlist&")"
	Conn.Execute(sql)

	IP=Request.ServerVariables("REMOTE_ADDR") 
	body="从「"&fototype(Request("Catalog"))&"」分册批量移动相片到「"&fototype(phototype)&"」分册"
	sql="insert into log(userid,content,classid,ip)"&_
		" values('"&membername&"','"&body&"',"&ClsID&",'"&IP&"')"
	Conn.Execute(sql)

	rURL="Class_Album.asp?ClassID="&ClsID&"&Action=ShowAlbum&Catalog="&Request("Catalog")&"&Page="&Request("Page")&"&Batch=True"
	rtitle="管理操作成功"
	rmsg="成功移动相片<br><ul>"&_
			"<li><a href=MyClass.asp?ClassID="&ClsID&">返回"&htmlencode(ClassName)&"首页</a></li>"&_
			"<li><a href=""Class_Album.asp?ClassID="&ClsID&""">返回学校相册</a></li>"&_
			"<li><a href="&rURL&">返回浏览「"&fototype(Request("Catalog"))&"」相册</a></li>"&_
			"</ul>"
	Redirect 3,rurl,rtitle,rmsg

End Sub


Sub BatchDel()

	Dim idlist,idarr,photoid

	if Request("photoid")="" Then
		ErrMsg=ErrMsg+"<br>"+"<li>请选择所要进行操作的相片！"
		Call Error("Information",ErrMsg)
		Exit Sub
	End if
	   
	if ChkRights(5)=False Then
		ErrMsg=ErrMsg+"<br>"+"<li>操作失败！您没有执行此项操作的权限！"
		Call Error("Exclamation",ErrMsg)
		Exit Sub
	End if

	idlist=Request("photoid")

	idArr=Split(idlist)
	SucDelNum=0
	for i = 0 to ubound(idarr)
		photoid=Clng(idarr(i))

		sql = "Select name,filename,[file],smallfilename from photo where picid="&photoid&" and classid="&ClsID
		Set rs=Conn.Execute(sql)

		if not (rs.Eof and rs.bof) Then

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

			if IsFSOInstalled Then
				Set fso = CreateObject("Scripting.FileSystemObject")
				photofile=rs(2)&rs(1)
				filepath=server.mappath(photofile)
				if fso.FileExists(filepath)=True Then
					Set file = fso.GetFile(filepath)
					file.delete  
				End if
				''
				photofile=rs(2)&rs(3)
				filepath=server.mappath(photofile)
				if fso.FileExists(filepath)=True Then
					Set file = fso.GetFile(filepath)
					file.delete  
				End if
				''
				Set file=Nothing
				Set fso=Nothing
			End if

			Conn.Execute("delete from comment where picid="&photoid)
			Conn.Execute("delete from photo where picid="&photoid)
			SucDelNum=SucDelNum+1
		End if

		Set rs=Nothing
	next

	IP=Request.ServerVariables("REMOTE_ADDR") 
	body="批量删除「"&fototype(Request("Catalog"))&"」分册中的"&SucDelNum&"张相片"
	sql="insert into log(userid,content,classid,ip)"&_
		" values('"&membername&"','"&body&"',"&ClsID&",'"&IP&"')"
	Conn.Execute(sql)

	rURL="Class_Album.asp?CLassID="&ClsID&"&Action=ShowAlbum&Catalog="&Request("Catalog")&"&Page="&Request("Page")&"&Batch=True"
	rtitle="成功管理相片"
	rmsg="成功删除<font color=brown><b>"&SucDelNum&"</b></font>张相片<br><ul>"&_
			"<li><a href=""MyClass.asp?ClassID="&ClsID&""">返回"&htmlencode(ClassName)&"首页</a></li>"&_
			"<li><a href=""Class_Album.asp?ClassID="&ClsID&""">返回学校相册</a></li>"&_
			"<li><a href="&rURL&">返回浏览「"&fototype(Request("Catalog"))&"」相册</a></li>"&_
			"</ul>"
	Redirect 3,rurl,rtitle,rmsg

End Sub


Sub DeletePhoto()

	Dim rs,sql
	Dim photoid
	Response.Write "<table width=100% height=100% align=center bgcolor="&BodyColor&"><tr><td valign=top>"
	photoid=Request("photoid")
	if photoid="" Then
		ErrMsg=ErrMsg+"<br>"+"<li>操作失败！请选择要删除的照片。"
		Call Error("Critical",ErrMsg)
		Exit Sub
	End if
	photoid=Clng(photoid)
	sql = "Select name,classid,filename,[file],smallfilename from photo where picid="&photoid
	Set rs=Conn.Execute(sql)
	if rs.Eof and rs.bof Then
		ErrMsg=ErrMsg+"<br>"+"<li>操作失败！该相片不存在。"
		founderr=True
	Else
		if not sysadmin Then
			if rs(1)<>Clng(ClsID) Then
				ErrMsg=ErrMsg+"<br>"+"<li>非法操作，您无权删除其他学校同学的照片！"
				FoundErr=True
			ElseIf ChkRights(5)=False and rs(0)<>membername Then
				ErrMsg=ErrMsg+"<br>"+"<li>操作失败，您无权删除校内其他同学的照片！"
				FoundErr=True
			End if
		End if
	End if

	if FoundErr Then
		Call Error("Exclamation",ErrMsg)
		Exit sub
	Else
		sql="update student Set point=point+"&PointSet(21)&" where userid='"&rs(0)&"'"
		Conn.Execute(sql)

		if IsFSOInstalled Then
			Set fso = CreateObject("Scripting.FileSystemObject")
			photofile=rs(3)&rs(2)
			filepath=server.mappath(photofile)
			if fso.FileExists(filepath)=True Then
				Set file = fso.GetFile(filepath)
				file.delete  
			End if
			''
			photofile=rs(3)&rs(4)
			filepath=server.mappath(photofile)
			if fso.FileExists(filepath)=True Then
				Set file = fso.GetFile(filepath)
				file.delete  
			End if
			'''
			Set file=Nothing:Set fso=Nothing
		End if
	end if

	Set rs=Nothing

	sql="delete from comment where picid="&photoid
	Conn.Execute(sql)

	sql="delete from photo where picid="&photoid
	Conn.Execute(sql)

	stitle="管理相片"
	smsg="成功删除相片！"
	Call success(stitle,smsg)
	Response.Write "<SCRIPT LANGUAGE=""JavaScript"">opener.location=opener.location</SCRIPT>"

End Sub


Sub EditForm()

	Dim rs,sql
	Response.Write "<table width=700 align=center height=300><tr><td valign=top>"

	photoid=Request("photoid")
	if photoid="" Then
		ErrMsg=ErrMsg+"<br>"+"<li>操作失败！请选择要编辑的照片。"
		founderr=True
	Else
		sql = "Select title,remark,typeid,share from photo where picid="&Clng(photoid)
		Set rs=Conn.Execute(sql)
		if rs.Eof and rs.bof Then
			ErrMsg=ErrMsg+"<br>"+"<li>操作失败！该相片不存在。"
			founderr=True
		End if
	End if

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

	Response.Write "<BR><form action=Class_Admin_Album.asp?ClassID="&ClsID&" method=post>"&_
		"<input type=hidden name=Action value=SaveEdit>"&_
		"<input type=hidden name=PhotoID value="&photoid&">"&_
		"<table align=center width=90% cellspacing=1 cellpadding=5 Class=TableBorder>"&_
			"<tr><th colspan=2>编辑相片</th></tr>"&_
			"<tr Class=LightTableBody>"&_
				"<td height=13 align=right>图片标题&nbsp;</td>"&_
				"<td>&nbsp;&nbsp;<input size=41 name=title maxlength=30 style=""WIDTH:295px;HEIGHT:20px"" value="&rs(0)&"></td>"&_
			"</tr>"&_
			"<tr Class=LightTableBody>"&_
				"<td height=13 align=right>图片说明&nbsp;</td>"&_
				"<td>&nbsp;&nbsp;<textarea name=remark style=""WIDTH:295px;HEIGHT:80px"">"&rs(1)&"</TEXTAREA> </td>"&_
			"</tr>"&_
			"<tr Class=LightTableBody>"&_
				"<td height=13 align=right>图片分类&nbsp;</td><td>&nbsp;&nbsp;<Select name=pictype>"
					for i=0 to ubound(fototype)
						Response.Write "<option value="&i
						if rs(2)=i Then Response.Write " selected"
						Response.Write ">"&fototype(i)&"</option>"
					next
					Response.Write "</Select></td>"&_
			"</tr>"&_
			"<tr Class=LightTableBody>"&_
				"<td height=13 align=right>共享到公共相册&nbsp;</td><td>&nbsp;&nbsp;<Select name=share>"
						Response.Write "<option value=""1"""
                       if rs(3)=1 Then Response.Write " selected"
						Response.Write ">共 享</option>"
						Response.Write "<option value=""0"""
                       if rs(3)<>1 Then Response.Write " selected"
						Response.Write ">不共享</option>"
					Response.Write "</Select></td>"&_
			"</tr>"&_
			"<tr Class=DarkTableBody><td align=center colspan=2><input type=submit value=修改(M) accesskey=m class=button>&nbsp;&nbsp;&nbsp;&nbsp;"&_
				"<input type=button value=取消(C) onclick=javascript:history.go(-1) accesskey=c class=button></td>"&_
			"</tr>"&_
		"</table>"&_
		"</form>"

	Set rs=Nothing

End Sub


Sub EditPhoto()

	Dim rs,sql
	Dim photoid
	Response.Write "<table width=700 align=center height=300><tr><td valign=top>"
	photoid=Request("photoid")
	if photoid="" Then
		ErrMsg=ErrMsg+"<br>"+"<li>操作失败！请选择要编辑的照片。"
		Call Error("Critical",ErrMsg)
		Exit Sub
	End if
	
	photoid=Clng(photoid)
	sql = "Select classid,name from photo where picid="&photoid
	Set rs=Conn.Execute(sql)
	if rs.Eof and rs.bof Then
		ErrMsg=ErrMsg+"<br>"+"<li>操作失败！该相片不存在。"
		founderr=True
	Else
		if not sysadmin Then
			if rs(0)<>Clng(ClsID) Then
				ErrMsg=ErrMsg+"<br>"+"<li>非法操作，您无权修改其他学校同学的照片信息！"
				FoundErr=True
			ElseIf ChkRights(5)=False and rs(1)<>membername Then
				ErrMsg=ErrMsg+"<br>"+"<li>操作失败，您无权修改校内其他同学的照片信息！"
				FoundErr=True
			End if
		End if
	End if

	Set rs=Nothing

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

	title=trim(checkstr(Request.form("title")))
	if title="" Then
		ErrMsg=ErrMsg+"<br>"+"<li>请输入图片标题."
		founderr=True
	Else
		if strlength(title)>30 or strlength(title)<2 Then
			ErrMsg=ErrMsg+"<br>"+"<li>图片标题不能超过30个字符或少于2个字符。"
			founderr=True
		End if
	End if

	remark=rtrim(checkstr(Request.form("remark")))

	if remark="" Then
		ErrMsg=ErrMsg+"<br>"+"<li>请输入图片说明."
		founderr=True
	Else
		if strlength(remark)>250 or strlength(remark)<2 Then
			ErrMsg=ErrMsg+"<br>"+"<li>图片说明不能超过250个字符或少于2个字符。"
			founderr=True
		End if
	End if

	pictype=cint(Request.form("pictype"))
	share=cint(Request.form("share"))
	if share=1 then
	share=1
	else
	share=0
	end if

	if founderr=True Then
		Call Error("Exclamation",ErrMsg)
	Else

		sql="update photo Set title='"&title&"',remark='"&remark&"',typeid="&pictype&",share="&share&" where picid="&photoid
		Conn.Execute(sql)

		sql="update student Set point=point+"&PointSet(20)&" where userid='"&membername&"'"
		Conn.Execute(sql)

		rURL="Class_Album.asp?ClassID="&ClsID&"&Action=ShowPhoto&PhotoID="&photoid
		rtitle="编辑相片成功"
		rmsg="本页面将在2秒后自动返回学校相册页面<br><ul>"&_
			"<li><a href="&rURL&">返回查看相片</a></li>"&_
			"</ul>"
		Redirect 2,rurl,rtitle,rmsg
	End if

End Sub


Function photosize(picsize)

	if not isinteger(picsize) Then
		photosize=0
		Exit Function
	End if
	picsize=Clng(picsize)
	if picsize>=1024*1024 Then
		photosize=cstr(round(picsize/(1024*1024),2))&"M"
	ElseIf picsize>=1024 Then
		photosize=cstr(round(picsize/1024,2))&"K"
	Else
		photosize=picsize
	End if

End Function

%>
<!--#INCLUDE FILE="inc/chkfso.asp" -->
