<!--#INCLUDE FILE="conn.asp" -->
<!--#INCLUDE FILE="Class_Checkuser.asp" -->
<!--#INCLUDE FILE="Class_Top.asp" -->
<!--#INCLUDE FILE="inc/char.asp" -->
<!--#INCLUDE FILE="inc/upclass.asp"-->
<!--#INCLUDE FILE="inc/email.asp"-->
<%Server.ScriptTimeOut=999999999%>
<%
locat="学校相册"
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 "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
dim sharephoto
Dim classphoto

Set rsp=Conn.Execute("Select classphoto from class where classid="&ClsID)
if rsp.eof and rsp.bof Then
classphoto=0
else
classphoto=rsp(0)
end if
Set rsp=Nothing

if chkpost=False Then
	ErrMsg=ErrMsg+"<Br>"+"<li>您提交的数据不合法，请不要从校友录外部提交信息。"
	founderr=True
ElseIf BoolVar(6)=False Then
	ErrMsg=ErrMsg+"<br>"+"<li>操作失败，系统管理员禁止使用此项功能."
	founderr=True
Else
	upFotoNum=request.cookies("upFotoNum")
	if upFotoNum ="" then upFotoNum=0
	upFotoNum=cint(upFotoNum)
	if UpFotoNum>=Cint(IntVar(4)) and not sysadmin Then
		ErrMsg=ErrMsg+"<br>"+"<li>操作失败，每次只能上传<font color=brown><strong>"&IntVar(4)&"</strong></font>个文件!"
		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
''''''''''''''''''''''''''''''''''''''''''''''
sharephoto=clsData.binRequest("sharephoto",0).Value
if sharephoto=1 then
sharephoto=1
else
sharephoto=0
end if
'''''''''''''''''''''''''''''''''''''''''''''
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 imgSize>(IntVar(2)*1024) and not sysadmin Then
 	ErrMsg=ErrMsg+"<br>"+"<li>文件大小超过了<font color=brown><strong>"&IntVar(2)&"K</strong></font>限制！"
	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)>(classphoto*1024*1024) Then
		 	ErrMsg=ErrMsg+"<br>"+"<li>上传失败！超过了学校相册容量<font color=brown><strong>"&classphoto&"M</strong></font>限制！"
			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

'按月份自动明名上传文件夹,需要ＦＳＯ组件支持。

	Dim objFSO,uploadpath,CreatePath
	uploadpath=ClsID                        '以学校ID创建上传文件夹
	'uploadpath=year(now)&"-"&month(now)	'以年月创建上传文件夹，格式：2004－7
	On Error Resume Next
	Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
		If objFSO.FolderExists(Server.MapPath(StrVar(8)&uploadpath))=False Then
			objFSO.CreateFolder Server.MapPath(StrVar(8)&uploadpath)
		End If
		If Err.Number = 0 Then
			CreatePath=uploadpath&"/"
		Else
			CreatePath=""
		End If
	Set objFSO = Nothing

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)&CreatePath&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

''''''''''''''''''使用缩略图'''''''''''''''
dim filesmallname
if IsObjInstalled("Persits.Jpeg") and BoolVar(22) then
dim jpegs,smallphotowidth,smallphotohight
Dim Paths,cimgw,cimgh

smallphotowidth=cint(IntVar(9))''''定义缩略图宽
smallphotohight=cint(IntVar(10))''''定义缩略图高
Set Jpegs = Server.CreateObject("Persits.Jpeg")
Paths = Server.MapPath(StrVar(8)&CreatePath&dfotofile)
Jpegs.Open Paths

if jpegs.width=<smallphotowidth and jpegs.height=<smallphotohight then
filesmallname=dfotofile
else

if jpegs.width>=jpegs.height then
cimgw=smallphotowidth
cimgh=jpegs.height*(smallphotowidth/jpegs.width)
end if
if jpegs.height>jpegs.width or cimgh>smallphotohight then
cimgh=smallphotohight
cimgw=jpegs.width*(smallphotohight/jpegs.height)
end if

Jpegs.Width =cimgw
Jpegs.Height =cimgh

Jpegs.Save Server.MapPath(StrVar(8)&CreatePath&"small_"&dfotofile)
filesmallname="small_"&dfotofile
end if
Set Jpegs = Nothing
else
filesmallname=dfotofile
end if
''''''''''''''''结束'''''''''''''''''''''''
''''''''''''''''添加站标'''''''''''''''''''''''''''''''''''''''
If IsObjInstalled("Persits.Jpeg") and ChkNumeric(StrVar(11))=1 and fileExt<>".gif" Then
dim logobox,logbox1,FSO,LogoPath,thisfile,Jpeg
dim Draw_X,Draw_Y,Draw_Graph,Draw_Color
dim logowidth,logoheight,logourl
If IsNumeric(StrVar(13)) Then
Draw_Graph = Formatnumber(StrVar(13),2)        ''''透明度
Else
Draw_Graph = 1
End If
If StrVar(14)<>"" or StrVar(14)<>"0" Then
Draw_Color = Replace(StrVar(14),"#","&h")       '''去掉背景颜色
End If
logowidth=ChkNumeric(StrVar(15))         'LOGO图片宽
logoheight=ChkNumeric(StrVar(16))        'LOGO图片高
logourl=trim(StrVar(12))                 'LOGO图片地址
logbox1=0
thisfile=StrVar(8)&CreatePath&dfotofile
Set Jpeg = Server.CreateObject("Persits.Jpeg")
Jpeg.Open Server.MapPath(thisfile)
Set Logobox = Server.CreateObject("Persits.Jpeg")
if logourl<>"" then
Set FSO = Server.CreateObject("Scripting.FileSystemObject")
if fso.FileExists(Server.MapPath(logourl)) then
LogoPath = Server.MapPath(logourl)
Logobox.Open LogoPath
Logobox.Width = logowidth
Logobox.Height = logoheight
Draw_X = DrawImage_X(jpeg.width,logowidth,2)
Draw_Y = DrawImage_y(jpeg.height,logoheight,2)
'Draw_X=jpeg.width-StrVar(15)-5
'Draw_Y=jpeg.height-StrVar(16)-5
logbox1=1
end if
Set fso=nothing
if logbox1=1 then
Jpeg.DrawImage Draw_X,Draw_Y,Logobox,Draw_Graph,Draw_Color,90
end if

'Set FSO = Server.CreateObject("Scripting.FileSystemObject")
'if fso.FileExists(Server.MapPath(thisfile)) then
'FSO.DeleteFile(Server.MapPath(thisfile))
'end if
'Set fso=nothing
Jpeg.Save Server.MapPath(thisfile)
end if
Set Jpeg = Nothing
set Logobox =nothing
end if

''''''''''''''''''''''''''添加站标结束''''''''''''''''''''''''''

''''''检查最后上传的相片
'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 BoolVar(7)=0 then 
'fotostat=True
'else
'fotostat=False
'end if

if sysadmin Then
fotostat=1
else
if BoolVar(7) Then
fotostat=0
Else
fotostat=1
end if
end if

sql="insert into photo ([file],filename,filesize,typeid,name,title,remark,classid,width,height,depth,"&_
	"format,passed,share,smallfilename) values ('"&StrVar(8)&CreatePath&"','"&dfotofile&"',"&imgSize&","&pictype&",'"&membername&_
	"','"&title&"','"&remark&"',"&clsid&","&imgWidth&","&imgHeight&","&imgBit&",'"&imgType&"',"&fotostat&","&sharephoto&",'"&filesmallname&"')"

conn.execute(sql)

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

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


rURL="Class_Album.asp?ClassID="&clsid&"&Action=ShowAlbum&Catalog="&pictype

''''''

if Cint(IntVar(5))<>0 and BoolVar(21) and upFotoNum<2 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=0 and S.NewFotoFlag=1"
	'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)
		MailFromName=StrVar(1)
		mailtopic=StrVar(1)&"-学校新相片通知"
		mailbody=vbcrlf&"您好！您的学校:"&ClassName&"有新的相片上传,请注意查看！"&vbcrlf&"地址："&SchoolmateURL&rURL&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
	set rs=nothing

end if 
'''''''''

rtitle="成功上传相片"

if fotostat=1 Then
	rmsg="本页面将在3秒后自动返回学校相册页面！<br><ul>"
	rtm=3
Else
	rmsg="&nbsp;&nbsp;&nbsp;&nbsp;<font color=red>图片成功上传，在未经系统管理员审核之前暂时还不能被其他同学看到。</font><br><ul>"
	rtm=5
End if

rmsg=rmsg&"<li><a href=Class_UploadPhoto_2.asp?ClassID="&clsid&"&Action=Add&Catalog="&pictype&"><font color=red>继续上传相片</font></a></li><br><br><li><a href="&rURL&">返回学校相册</a></li>"&_
		"</ul>"
Call top(3,1)
Redirect rtm,rurl,rtitle,rmsg

End if

End Sub
'''''''''''检测组建涵数''''''''''
Function IsObjInstalled(strClassString)
On Error Resume Next
IsObjInstalled = False
Err = 0
Dim xTestObj
Set xTestObj = Server.CreateObject(strClassString)
If 0 = Err Then IsObjInstalled = True
Set xTestObj = Nothing
Err = 0
End Function
'''''''''''''''''结束'''''''''''
''''''''' X轴坐标边缘距离
 Function DrawImage_X(xImage_W,xLogo_W,SpaceVal)
		Select Case StrVar(17)
			Case "0" '左上
				DrawImage_X = SpaceVal
			Case "1" '左下
				DrawImage_X = SpaceVal
			Case "2" '居中
				DrawImage_X = (xImage_W - xLogo_W) / 2
			Case "3" '右上
				DrawImage_X = xImage_W - xLogo_W - SpaceVal
			Case "4" '右下
				DrawImage_X = xImage_W - xLogo_W - SpaceVal
			Case Else '不显示
				DrawImage_X = 0
		End Select
	End Function
''''''' Y轴坐标边缘距离
Function DrawImage_Y(yImage_H,yLogo_H,SpaceVal)
		Select Case StrVar(17)
			Case "0" '左上
				DrawImage_Y = SpaceVal
			Case "1" '左下
				DrawImage_Y = yImage_H - yLogo_H - SpaceVal
			Case "2" '居中
				DrawImage_Y = (yImage_H - yLogo_H) / 2
			Case "3" '右上
				DrawImage_Y = SpaceVal
			Case "4" '右下
				DrawImage_Y = yImage_H - yLogo_H - SpaceVal
			Case Else '不显示
				DrawImage_Y = 0
		End Select
	End Function
Function ChkNumeric(Byval Values)
		If Values<>"" and Isnumeric(Values) Then
			ChkNumeric = Int(Values)
		Else
			ChkNumeric = 0
		End If
	End Function

Sub upform()

%><!--#INCLUDE FILE="inc/sendnow.inc" --><%
dim pictype,pictype0,pictype1,pictype2,pictype3
pictype0=""
pictype1=""
pictype2=""
pictype3=""
pictype=Request("catalog")
if pictype=0 then
pictype0="checked"
elseif pictype=1 then
pictype1="checked"
elseif pictype=2 then
pictype2="checked"
elseif pictype=3 then
pictype3="checked"
end if

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=""inc/upload.js""></script>"&_
"<form name=""frmupload"" action=""Class_UploadPhoto_2.asp?ClassID="&ClsID&"&Action=upload"" method=post enctype=""multipart/form-data"" onsubmit=""submitonce(this);initAd();"">"&_
"<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><strong>"&IntVar(2)&"K</strong></font>字节，每天只可以上传<font color=brown><strong>"&IntVar(4)&"</strong></font>张照片。<BR>"
			if BoolVar(6)<>True then
			Response.Write "<font color=red>4. 系统管理员已经关闭相片上传功能，暂时不可以上传相片！</font>"
			elseif BoolVar(6)=True and BoolVar(7)=True then
			Response.Write "<font color=red>4. 您上传的相片须管理员审核才能显示出来，如果相片不符合要求，将被删除！</font>"
			end if
			Response.Write "</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=radio value=0 "&pictype0&" name=pictype>校园风光&nbsp;<INPUT type=radio value=1 "&pictype1&" name=pictype>同学合影&nbsp;<INPUT type=radio value=2 "&pictype2&" name=pictype>真我风采&nbsp;<INPUT type=radio value=3 "&pictype3&" name=pictype>其他照片</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></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 align=center><font color=red>共享此相片到公共相册</font>&nbsp;<input type=""checkbox"" name=""sharephoto"" value=""1"">"

	Response.Write "</td></tr><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 >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>"&_
	"</tr></table></form>"
End Sub%>

<%Call footer%>
