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

<%
locat="公共相册"

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

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()
Else
		Select Case Request("action")
		
		Case "ShowPhoto"
			act="查看相片"
			Call pagehead()
			Call showphoto()
		Case Else
		if Request("catalog")>="0" and Request("catalog")<=cstr(ubound(fototype)) Then
				act="浏览「"&fototype(Request("catalog"))&"」相册"
			Else
				act="浏览公共相册"
			End if
			Call top(1,1)
			Call showalbum()
			Call footer()
		End Select 
	End if


Sub ShowPhoto()

Dim rs,sql
Dim acturalwidth
Dim ErrMsg,FoundErr
Dim phototid

photoid=Request("photoid")

if photoid="" Then
	ErrMsg=ErrMsg+"<br>"+"<li>操作失败！请选择要查看的照片。"
	Call Error("Critical",ErrMsg)
	Exit Sub
End if

photoid=Clng(photoid)
sql = "Select P.*,S.realname from photo P inner join student S on P.name=S.userid where P.share=1 and P.picid="&photoid
Set rs=Conn.Execute(sql)

if rs.Eof and rs.bof Then
	ErrMsg=ErrMsg+"<br>"+"<li>操作失败！您要查看的相片不存在或已被删除。"
	founderr=True
ElseIf not sysadmin and rs("passed")=0 Then
	ErrMsg=ErrMsg+"<br>"+"<li>操作失败！该相片还没有通过管理员审核。"
	founderr=True
End if

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

sql="update photo Set visitcount=visitcount+1 where picid="&photoid
Conn.Execute(sql)

if rs("width")>600 Then acturalwidth=600 Else acturalwidth=rs("width")

if rs("depth")<=8 Then depth=2^cint(rs("depth")) Else depth=rs("depth")&"b"
iconame="images/"&rs("format")&".gif"

lsql="select min(picid) from photo where typeid="&rs("typeid")&" and share=1 and passed=1 and picid>"&photoid
Set lrs=Conn.Execute(lsql)
if lrs.eof and lrs.bof Then pfoto=0 Else pfoto=lrs(0)
lsql="select max(picid) from photo where typeid="&rs("typeid")&" and share=1 and passed=1 and picid<"&photoid
Set lrs=Conn.Execute(lsql)
if lrs.eof and lrs.bof Then nfoto=0 Else nfoto=lrs(0)
Set lrs=Nothing

%>
<SCRIPT LANGUAGE="JavaScript">
<!--
function ShowOperationIcon(imgName,imgAlt)
{var OutStr='';
OutStr='<IMG src="images\/'+imgName+'" hspace=1 align=top alt='+imgAlt+
' style="border:1pt solid #fafaff"'+
' onmouseover="this.style.border=\'1pt outset #eeffee\'"'+
' onmouseout="this.style.border=\'1pt solid #fafaff\';'+
'this.style.position=\'relative\';this.style.top=\'0px\'"'+
' onmouseup="this.style.border=\'1pt outset #eeffee\';'+
'this.style.position=\'relative\';this.style.top=\'0px\'"'+
' onmousedown="this.style.border=\'1pt inset #eeffee\';'+
'this.style.position=\'relative\';this.style.top=\'1px\'">';
document.write(OutStr);}
//-->
</SCRIPT>
<script language="JavaScript" src="inc/ViewImage.js"></script>
<%
Response.Write "<table width=100% border=0 align=center bgcolor="&BodyColor&"><tr><td>"&_
	"<table><TR><TD align=middle height=10></TD></TR></table>"&_
	"<TABLE cellSpacing=1 cellPadding=2 width=90% border=0 align=center>"&_
		"<TR><TD height=24 >『"&htmlencode(rs("title"))&"』</TD>"&_
          "<TD align=right><A href=""Class_Userinfo.asp?Name="&rs("name")&_
		  """ target=_blank>"&rs("name")&"</A>&nbsp;"&rs("uptime")&"</TD>"&_
		 "</TR>"&_
		 "<TR><TD colSpan=2 height=23><HR size=1 width=""100%"">图片说明：&nbsp;&nbsp;"&htmlencode(rs("remark"))&"</TD>"&_
		"</TR>"&_
	"</TABLE>"&_
	"<table><TR><TD align=middle height=10></TD></TR></table>"&_
	"<TABLE cellSpacing=0 cellPadding=0 width=90% border=0 align=center>"&_
        "<TR><TD align=middle height=450 valign=center>"&_
		  "<table cellspacing=0 cellpadding=0 border=0><tr><td><img src=images/pf_lt.gif></td>"&_
			"<td background=images/pf_t.gif></td><td><img src=images/pf_rt.gif></td></tr>"&_
			"<tr><td background=images/pf_l.gif></td><td>"&_
				"<table cellpadding=6 bgcolor=#ffffff cellspacing=0 border=0>"&_
					"<tr><td><A href="&rs("file")&rs("filename")&" target=_blank>"&_
				   	  "<IMG src="&rs("file")&rs("filename")&" width="&acturalwidth&" border=0 alt=点击看全图 name=photo></a>"&_
				"</td></tr></table>"&_
		  "</td><td background=images/pf_r.gif></td></tr>"&_
		  "<tr><td><img src=images/pf_lb.gif></td><td background=images/pf_b.gif></td><td><img src=images/pf_rb.gif>"&_
		  "</td></tr></table>"&_
		"</TD></TR>"&_
	"</table>"&_
	"<table><TR><TD align=middle height=10></TD></TR></table>"&_
	"<TABLE cellSpacing=0 cellPadding=0 width=90% border=0 align=center height=40 valign=top>"&_
        "<TR>"&_
          "<TD align=left class=novdn>"&_
		  "<img src="&iconame&" hspace=2 align=absmiddle>"&_
			  rs("width")&"x"&rs("height")&"x"&depth&"&nbsp;&nbsp;"&photosize(rs("filesize"))&_
		  "</TD>"&_
		  "<TD width=""50%"" align=right>"
			if pfoto<>0 Then
				Response.Write "<a onfocus=""this.blur()"" href=Class_SharePhoto.asp?Action=ShowPhoto&PhotoID="&pfoto&">"&_
				"<script>ShowOperationIcon('p_pre.gif','上一张')</script></a>"
			End if
			if nfoto<>0 Then 
				Response.Write "<a onfocus=""this.blur()"" href=Class_SharePhoto.asp?Action=ShowPhoto&PhotoID="&nfoto&">"&_
				"<script>ShowOperationIcon('p_next.gif','下一张')</script></a>"
			End if

			Response.Write "<A onfocus=""this.blur()"" href="&rs("file")&rs("filename")&" target=_blank>"&_
			  "<script>ShowOperationIcon('p_full.gif','全图')</script></A>"&_
			  "<A onfocus=""this.blur()"" href=""javascript:fitpage("&rs("width")&","&rs("height")&")"">"&_
			  "<script>ShowOperationIcon('p_fit.gif','最合适大小')</script></A>&nbsp;"&_
			  "<A href=""javascript:zoomin()"">"&_
			  "<IMG src=images/p_zoomin.gif border=0 hspace=1 align=absmidle alt=放大></A>&nbsp;"&_
			  "<A href=""javascript:zoomout()"">"&_
			  "<IMG src=images/p_zoomout.gif border=0 hspace=1 align=absmidle alt=缩小></A>&nbsp;"

			if rs("name")=membername or Degree>1 or sysadmin Then
				Response.Write "<a onfocus=""this.blur()"" onclick=""return confirm('确定要删除这张相片吗?')"""&_
				" href=Class_Admin_Album.asp?ClassID="&rs("classid")&"&Action=DelPhoto&PhotoID="&photoid&">"&_
				"<script>ShowOperationIcon('p_del.gif','删除')</script></a>"&_
				"<A onfocus=""this.blur()"" href=Class_Admin_Album.asp?ClassID="&rs("classid")&"&Action=EditPhoto&PhotoID="&photoid&">"&_
				"<script>ShowOperationIcon('p_edit.gif','编辑')</script></A>"
			End if

			Response.Write "</TD>"&_
			"</TR>"&_
	"</table>"

End Sub



Sub ShowAlbum()

Dim catalog
Dim rs,sql
Dim currentpage,totalpages

catalog=Request("catalog")
if not isinteger(catalog) Then
	catalog=4
Else
	catalog=cint(catalog)
	if catalog<0 Then catalog=4
	if catalog>ubound(fototype) Then catalog=ubound(fototype)
End if
currentpage=Request("Page")
%>

<Script language="javascript" src="inc/PopText.asp"></Script>
<script language=JavaScript src="inc/ViewImage.js"></script>
<%Response.Write "<BR><TABLE border=0 align=center width=""100%"" cellspacing=0 cellpadding=2>"&_
	"<tr><th align=center width=""80%"">"
Response.Write "公共相册</th><th align=right>照片分类:<select name=phototype onchange=""location.href='Class_SharePhoto.asp?Catalog='+options[this.selectedIndex].value+''"">"

for i=0 to ubound(fototype)
	Response.Write "<option value="&i
	if i=catalog Then Response.Write " selected"
	Response.Write ">"&fototype(i)&"</option>"
next
Response.Write "</Select></th></tr></table>"


Response.Write 	"<TABLE border=0 align=center width=""100%"" Class=LightTableBody>"

Response.Write "<TR><TD align=center height=170><TABLE border=0 width=""100%"">"	
if catalog=4 then 
sql="Select filename,title,picid,name,uptime,filesize,width,height,depth,visitcount,[file],smallfilename "&_
	"from photo where share=1 and passed=1 order by picid desc"
else
sql="Select filename,title,picid,name,uptime,filesize,width,height,depth,visitcount,[file],smallfilename "&_
	"from photo where share=1 and typeid="&catalog&" and passed=1 order by picid desc"
end if
Set rs = server.CreateObject("ADODB.Recordset")
rs.open sql,Conn,1,1

if rs.eof and rs.bof Then 
	Response.Write "<tr><td align=middle><IMG alt=还没有任何相片:(  src=""images/nopic.gif"">"&_
					"</td></tr></table>"&_
					"</td></tr></table><BR>"
Else

rs.pagesize=16
totalpages=rs.pagecount
if currentpage="" Then currentpage=1
if not isInteger(currentpage) Then
	currentpage=1
ElseIf Cint(currentpage)>totalpages Then
	currentpage=totalpages
End if
currentpage=Cint(currentpage)
rs.absolutepage=currentpage

for i=1 to 16

if i mod 4=1 Then Response.Write "<TR>"
Response.Write "<TD align=center width=""25%"" height=""160"">"
if rs(8)<=8 Then depth=2^(rs(8)) Else depth=rs(8)&"b"

altinfo="相片提供:"&rs(3)&"&lt;br&gt;"&_
		"上传时间:"&formatdatetime(rs(4),vbShortDate)&"&nbsp;"&formatdatetime(rs(4),vbShortTime)&"&lt;br&gt;"&_
		"人气指数:"&rs(9)&"&lt;br&gt;"&_
		"相片属性:"&rs(6)&"x"&rs(7)&"x"&depth

Response.Write "<TABLE cellSpacing=2 cellPadding=0 width=120 border=0 Class=DarkTableBody"&_
	" onmouseover=""this.style.background='"&tablebordercolor&"'"" onmouseout=""this.style.background='"&DarkTBColor&"'"">"&_
	"<tr><TD height=120 align=center Class=LightTableBody>"&_
	"<table border=0 cellspacing=1 cellpadding=0 width=""100%"" height=""100%"" align=center Class=TableBorder>"&_
	"<tr Class=DarkTableBody><td onmouseover=""this.style.cursor='hand'"" align=center onclick=""javascript:ShowsharePic('"&rs(2)&"')"">"&_
	"<IMG src="""&rs(10)&rs(11)&""" "&sizeadjust(rs(6),rs(7),100)&" border=0 title="""&altinfo&""">"&_
	"</td></tr></table>"&_
	"</TD></TR></TABLE>"&_
	"<TABLE cellSpacing=1 cellPadding=2 width=120 border=0>"&_
	"<TR>"
Response.Write	"<TD align=middle width=130>"&htmlencode(CutStr(rs(1),16))&"</TD></TR></TABLE>"&_
	"</TD>"

rs.movenext
if currentpage=totalpages then
	if rs.eof then 
		response.write "</tr>"
		exit for
	end if
end if
if i mod 4=0 then response.write "</tr>"

next

rs.close
Set rs=Nothing

Response.Write "</TABLE>"

Response.Write "</td></tr></table>"


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

if currentpage=0 Then currentpage=1
if not (currentpage=1 or totalpages=0) Then
	Response.Write "　<a href=""?Catalog="&Catalog&"&Page="&(currentpage-1)&"""><img src=images/left.gif border=0 hspace=2>上一页</a>"
End if
		
if not (currentpage=totalpages or totalpages=0) Then
	Response.Write "　<a href=""?Catalog="&Catalog&"&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='?Catalog="&catalog&"&page='+this.options[selectedIndex].value"">"
  dim i
             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></tr></table>"

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

Function sizeadjust(byval fotow,byval fotoh,byval shrksize)
	sizeadjust=""
	if fotow="" or fotoh="" Then Exit Function
	if fotow>0 and fotoh>0 Then
		if fotow>shrksize or fotoh>shrksize Then
			if  fotow>=fotoh Then sizeadjust="width="&shrksize Else sizeadjust="height="&shrksize
		End if
	Else
		sizeadjust="width="&shrksize&" height="&shrksize
	End if
End Function
%>
