<!--#INCLUDE FILE="setup.asp" -->
<!--#INCLUDE FILE="checkuser.asp" -->
<!--#INCLUDE FILE="theme.asp" -->
<!--#INCLUDE FILE="include/char.asp" -->
<!--#INCLUDE FILE="include/upclass.asp"-->
<%
Server.ScriptTimeOut=99999
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
	ClsID=Request("ClassID")
	joinstatus=chkjoinclass(ClsID)
	if joinstatus<>"" Then
		Call top(1,1)
		Call Error("Exclamation",joinstatus)
	Else
		Select Case Request("action")
		Case "upload"
			act="上传照片"
			Call uploadphoto()
		Case "Add"
			act="上传照片"
			Call top(3,1)
			Call upform()
		End Select 
	End if
End if


Sub uploadphoto()

dim upFotoNum
Dim clsData
dim sql
dim FoundErr,ErrMsg
Dim LastUpload

if chkpost=False Then
	ErrMsg=ErrMsg+"<Br>"+"<li>您提交的数据不合法，请不要从同学录外部提交信息。"
	founderr=True
ElseIf BoolVar(6)=False Then
	ErrMsg=ErrMsg+"<br>"+"<li>操作失败，系统管理员禁止使用此项功能."
	founderr=True
ElseIf not sysadmin and Cint(IntVar(4))<>0 then
	upFotoNum=request.cookies("upFotoNum")
	if upFotoNum ="" then upFotoNum=0
	upFotoNum=cint(upFotoNum)
	if UpFotoNum>=Cint(IntVar(4)) Then
		ErrMsg=ErrMsg+"<br>"+"<li>操作失败，每次只能上传"&IntVar(4)&"个文件!"
		founderr=True
	End if
end if
if founderr Then
	Call top(3,1)
	Call Error("Exclamation",ErrMsg)
	Exit Sub
End if


Set clsData = new upLoad
clsData.CaseSensitive = False

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

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

pictype=cint(clsData.binRequest("pictype",0).Value)

sfotofile=clsData.binRequest("UpFile",0).ShortFileName
fileExt=lcase(right(sfotofile,4))
if fileEXT<>".gif" and fileEXT<>".jpg" and fileEXT<>".bmp" and fileEXT<>".png" Then
	ErrMsg=ErrMsg+"<br>"+"<li>所要上传的图片格式系统不支持！"
	founderr=True
End if

chkfoto=clsData.binRequest("UpFile",0).IsImage(imgWidth,imgHeight,imgType,imgSize,imgBit)
if chkfoto=False Then
	ErrMsg=ErrMsg+"<br>"+"<li>非法的图片格式！"
	founderr=True
End if

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

if imgSize<100 Then
	ErrMsg=ErrMsg+"<br>"+"<li>请选择你要上传的图片或你的图片文件太小."
	founderr=True
ElseIf IntVar(2)<>0 and imgSize>(IntVar(2)*1024) Then
 	ErrMsg=ErrMsg+"<br>"+"<li>文件大小超过了"&IntVar(2)&"K限制."
	founderr=True
Else
	strsql="Select sum(filesize) from photo where classid="&clsid
	Set rs=conn.execute(strsql)
	if not (rs.eof and rs.bof) Then
		albumsize=rs(0)
		if (albumsize+imgsize)>(IntVar(3)*1024*1024) Then
		 	ErrMsg=ErrMsg+"<br>"+"<li>上传失败！超过了班级相册容量"&IntVar(3)&"M限制."
			founderr=True
		End if
	End if
	Set rs=Nothing
End if


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

'if IsFSOInstalled=True Then
'	Set fso = CreateObject("Scripting.FileSystemObject")
'	path=server.mappath(StrVar(8))
'	if fso.folderexists(path)=False Then
'		fso.createfolder(path)
'	End if
'	Set fso=Nothing
'End if


randomize
ranNum=int(9000*rnd)+1000
dfotofile=year(now)&month(now)&day(now)&hour(now)&minute(now)&second(now)&ranNum&fileExt

upfoto=clsData.SavetoFile("UpFile",0,server.mappath(StrVar(8)&dfotofile),False)

Set clsData = Nothing

if upfoto=4 Then
 	ErrMsg=ErrMsg+"<br>"+"<li>图片上传失败！保存路径的目录不存在."
	founderr=True
ElseIf upfoto=8 Then
 	ErrMsg=ErrMsg+"<br>"+"<li>图片上传失败！该文件正在被使用."
	founderr=True
ElseIf upfoto=16 Then
 	ErrMsg=ErrMsg+"<br>"+"<li>图片上传失败！该目录没有可写权限."
	founderr=True
ElseIf upfoto=32 Then
 	ErrMsg=ErrMsg+"<br>"+"<li>图片上传失败！文件已经存在."
	founderr=True
End if	


if founderr=True Then
	Call top(3,1)
	Call Error("Information",ErrMsg)
	Exit Sub
ElseIf upfoto=0 Then

if Cint(IntVar(5))<>0 then
	sql="select max(uptime) from photo where classid="&ClsID
	set rs=conn.execute(sql)
	LastUpload=rs(0)
end if


if sysadmin Then fotostat=True Else	fotostat=not BoolVar(7)

sql="insert into photo (filename,filesize,typeid,name,title,remark,classid,width,height,depth,"&_
	"format,passed) values ('"&dfotofile&"',"&imgSize&","&pictype&",'"&membername&_
	"','"&title&"','"&remark&"',"&clsid&","&imgWidth&","&imgHeight&","&imgBit&",'"&imgType&"',"&fotostat&")"

conn.execute(sql)

upFotoNum=upFotoNum+1
response.cookies("UpFotoNum")=upFotoNum

sql="update student Set point=point+"&PointSet(19)&" where userid='"&membername&"'"
conn.execute(sql)

if Cint(IntVar(5))<>0 then

	sql="Select distinct S.email from student S inner join joinclass J on S.userid=J.userid where J.classid="&_
	ClsID&" and J.userid<>'"&membername&"' and J.isauditing=False and S.NewFotoFlag=True"
	if not isNull(LastUpload) then sql=sql&" and J.lastvisit > #"&LastUpload&"#"
	Set rs=Conn.Execute(sql)

	if not (rs.eof and rs.bof) Then
		mailto=rs(0)
		rs.movenext
		do until rs.eof
			mailto=mailto&","&rs(0)
			rs.movenext
		loop

		mailfrom=StrVar(2)
		mailtopic=StrVar(1)&"-班级相片通知"
		mailbody=vbcrlf&"您好！您的班级:"&ClassName&"有新的相片上传,请注意查看！"&vbcrlf&vbcrlf
		mailbody=mailbody&space(20)&"-------"&StrVar(1)&vbcrlf
		mailbody=mailbody&space(20)&SchoolmateURL&vbclf

		select case Cint(IntVar(5))
		case 1
			Call jmail_smtp()		
		case 2
			Call Cdonts()		
		case 3
			Call aspemail()
		case 4
			Call jmail_msg()		
		End select

	End if

end if 


rURL="ClassAlbum.asp?ClassID="&clsid&"&Action=ShowAlbum&Catalog="&pictype
rtitle="成功上传相片"

if fotostat=True Then
	rmsg="本页面将在2秒后自动返回班级相册页面<br><ul>"
	rtm=2
Else
	rmsg="图片成功上传，在未经系统管理员审核之前暂时还不能被其他同学看到。<br><ul>"
	rtm=5
End if

rmsg=rmsg&"<li><a href="&rURL&">返回班级相册</a></li>"&_
		"</ul>"
Call top(3,1)
Redirect rtm,rurl,rtitle,rmsg

End if

End Sub



Sub upform()

%><!--#INCLUDE FILE="script/sendnow.inc" --><%
Response.Write "<div id=""sponsorAdDiv"" style=""visibility:hidden"">"&_
"<table width=400 height=70 Class=TableBorder border=0 cellspacing=1>"&_
	"<tr><td><table width=""100%"" height=""100%""  border=0 cellspacing=0>"&_
			"<tr Class=LightTableBody><td>&nbsp;&nbsp;&nbsp;&nbsp;正在上传图片，请稍候......</td>"&_
			"</tr></table>"&_
	"</td></tr></table></div>"&_
"<script language=JavaScript src=""script/upload.js""></script>"&_
"<form name=""frmupload"" action=""UploadPhoto.asp?ClassID="&ClsID&"&Action=upload"" method=post enctype=""multipart/form-data"" onsubmit=""submitonce(this);initAd();"">"&_
"<input type=hidden name=pictype value="&Request("catalog")&">"&_
"<table border=0 cellspacing=1 width=600 cellpadding=5 Class=TableBorder align=center>"&_
	"<tr><th height=25 align=center colspan=2>上传照片</th></tr>"&_
	"<tr Class=LightTableBody><td height=13 colspan=2>"&_
			"<table width=""95%"" border=0 cellspacing=16 class=mp align=center><tr><td>"&_
			"<FONT color=#284654><b>注意事项：</b><BR>1. 请勿发布违反计算机信息网络安全相关条例的有害信息，一经发现，后果自负！<BR>"&_
			"2. 请勿发布和与本站内容无关的照片（如卡通、壁纸、电影剧照、海报、明星、球星、宠物、植物等），一经发现，立即删除。<BR>"&_
			"3. 仅接受JPG,GIF,BMP和PNG格式的图片,大小不超过<font color=brown>"&IntVar(2)&"K</font>字节。<BR></FONT>"&_
				"</td></tr></table>"&_
	"</td></tr>"&_
    "<tr Class=LightTableBody><td align=center>提 供 者：&nbsp;&nbsp;"&_
		"<input type=text size=41 style=""WIDTH: 295px; HEIGHT: 20px"" name=author value="&getrealname(membername)&" disabled></td>"&_
	"</tr><tr Class=LightTableBody><td align=center>照片标题：&nbsp;&nbsp;"&_
		"<input size=41 name=title maxlength=30 style=""WIDTH: 295px; HEIGHT: 20px""></td></tr>"&_
    "<tr Class=LightTableBody><td align=center valign=top>照片说明：&nbsp;&nbsp;"&_
		"<textarea name=remark style=""WIDTH: 295px; HEIGHT: 80px""></TEXTAREA></td></tr>"&_
	"<tr Class=LightTableBody><td align=center>照片位置：&nbsp;&nbsp;"&_
		"<INPUT type=file size=23 name=UpFile style=""height:16pt;width=163pt"" onchange=""return chgpre();"">&nbsp;"&_
		"<input type=submit name=prvbtn value=预览照片 onclick=""return preview();"" class=button disabled></td></tr>"&_
	"<tr Class=LightTableBody id=""prv"" style=""DISPLAY: none""><td height=13 colspan=2 align=center>"&_
		"<img name=foto onload=""javascript:if(this.width>550){this.width=550}""></td></tr>"&_
	"<tr Class=LightTableBody><td height=13 colspan=2>"&_
			"<table width=""100%"" cellspacing=13><tr><td valign=top>&nbsp;&nbsp;"&_
				"<img src=images/reminder.gif align=absmiddle space=4>如果你的照片文件较大或网络速度太慢，上载过程可能要一段时间，请耐心等待！"&_
				"</td></tr></table>"&_
	"</td></tr>"&_
	"<tr Class=DarkTableBody><td height=30 align=right colspan=2>"&_
		"<input type=submit value=开始上传 name=upsubmit class=button disabled>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>"&_
	"</tr></table></form>"


End Sub%>

<%Call footer%>
