<!-- #INCLUDE FILE="../../include/cmn_dir.asp" -->
<!-- ASP FTP -->
<!-- Copyright 2000 - All Rights Reserved - See Readme.txt for details -->

<%


' ASP FTP Restrictions:
' 1) Filenames should not contains spaces
' 2) Only sub-directories and the root directories are shown as 'albums'


Sub PhotoMain

	szAlbumDir = Request.QueryString("szAlbumDir")
	
	If IsNull(szAlbumDir) Or szAlbumDir="" Then
		ShowMainPhotoAlbums
	Else
		szAlbumDir = cmn_ValidatePath(g_szRootDir, szAlbumDir)
		ShowSubDirPhotos szAlbumDir
	End If

End Sub


Sub ShowMainPhotoAlbums
	ShowHeader
	ShowLargeTitle
%>
	<TABLE WIDTH="80%" ALIGN="CENTER" CELLSPACING="4" CELLPADDING="2" BORDER="0" BGCOLOR="#f0f0f0">
<%
Dim MyDirectory, MyFolders, folderfound

    Set MyDirectory=Server.CreateObject("Scripting.FileSystemObject") 
    Set MyFolders=MyDirectory.GetFolder(Server.MapPath(g_szRootDir)) 
    For each folderfound in MyFolders.SubFolders 
%> 
	<TR VALIGN="TOP"><TD ALIGN="LEFT" WIDTH="60"><a href="showphotos.asp?szAlbumDir=<%=g_szRootDir%>/<%=folderfound.Name%>"><IMG SRC="<%=g_szGfxPath%>album.gif" BORDER="0"></a></TD><TD><a href="showphotos.asp?szAlbumDir=<%=g_szRootDir%>/<%=folderfound.Name%>"><FONT SIZE="6"><%=folderfound.Name%></FONT></a></TD></TR>
<%
    Next 
%>
	</TABLE>
<%
	If g_bAllowDownloadSource Then
%>
		<DIV ALIGN="CENTER">
		<HR>
		<FONT COLOR="#ff0000" SIZE="5">Why not <a href="photo.zip">Download</a> the ASP source for <i>Photo Album</i>?</FONT>
		</DIV>
<%	
	End If

	ShowCopyright
	ShowFooter
End Sub

Sub ShowSubDirPhotos(szAlbumDir)
Dim RootFileName
Dim Tmp
Dim PicName, RootPicName
Dim p
	
	blnFullSize=0	

	Tmp = Request.QueryString("blnFullSize")
	If IsNumeric(Tmp) Then
		If Int(Tmp) Then
			blnFullSize=1
		End If
	End If

	Tmp = Request.QueryString("photo")
	If IsNumeric(Tmp) Then
		PicNum = Int(Tmp)
	Else
		PicNum = 0
	End If

	Tmp = Request.QueryString("reload")
	If Tmp And IsNumeric(Tmp) Then
		g_blnReloadPage = Int(Tmp)
	End If

	ShowHeader

	' Strip directory name from RHS of string
	Tmp=Left(szAlbumDir, Len(szAlbumDir)-1)
	p = InStrRev(Tmp, "/")
	Tmp=Right(Tmp, Len(Tmp)-p)

	If szAlbumDir=g_szRootDir Then
		ShowLargeTitle
	Else
		ShowSmallTitle Tmp
	End If

	iTotal = 0
    Tmp = szAlbumDir

	Set MyDirectory=Server.CreateObject("Scripting.FileSystemObject") 
    Set MyFiles=MyDirectory.GetFolder(Server.MapPath(Tmp)) 
	'
%>
	<SCRIPT TYPE="text/javascript">
	<!--
	var idx=<%=PicNum%>
	var iTotal=0
	piclist=new Array(
<%
			For each filefound in MyFiles.files 
				Select Case UCase(Right(filefound,4))
				Case ".GIF",".JPG"
						If iTotal Then
							Response.Write ","
						End If

						%>"<%=szAlbumDir%>/<%=filefound.Name%>"<%
						iTotal = iTotal+1
				End Select
			Next
%>
		)

		function showstatus(i)
		{
			window.status = piclist[i]
		}

		function nextPic()
		{
			idx++
			if (idx==piclist.length)
				idx=0
			showPic(idx)
		}

		function lastPic()
		{
			if (idx==0)
				idx=piclist.length
			idx--
			showPic(idx)
		}

		function showPic(i)
		{
			idx=i
			document.pic.src=piclist[idx]
		}

		function ChangeSize(bFull)
		{
		str="showphotos.asp?szAlbumDir="
		str=str+"<%=Request.QueryString("szAlbumDir")%>"
		str=str+"&blnFullSize="+bFull+"&photo="
		str=str+idx
		window.location.replace(str)	
		}
	//-->
	</SCRIPT>
	<%
	' Create entire page now, either with full-size, or minature -->
	If iTotal Then
		If blnFullSize Then
			' Always True
			g_blnReloadPage = True

			Response.Write "<BR><DIV ALIGN='CENTER'>"
			%>
			<TABLE WIDTH="95%" ALIGN="CENTER" CELLSPACING="0" CELLPADDING="0" BORDER="0" BACKGROUND="<%=g_szGfxPath%>filmh.gif">
				<TR VALIGN="MIDDLE" ALIGN="CENTER"><TD><IMG SRC="<%=g_szGfxPath%>null.gif" WIDTH="1" HEIGHT="58"></TD><TD>
				<%
					iTotal = 0
					PicName=g_szGfxPath&"null.gif"
					For each filefound in MyFiles.files 
						Select Case UCase(Right(filefound,4))
						Case ".GIF",".JPG"
								If iTotal = PicNum Then
									PicName = filefound.Name
									RootPicName = Left(PicName, Len(PicName)-4)
									Response.Write "<FONT COLOR='#ff0000'>  {"&iTotal+1&"}  </FONT>"
								Else
									Response.Write "  "
									AddPhotoLink iTotal, iTotal+1, 0
									Response.Write "  "
								End If
								iTotal = iTotal+1
						End Select
					Next
				%>
			</TD></TR>
			</TABLE>
			<BR>
				<a href="javascript:ChangeSize(0)">
			<%
				Response.Write "<b>"&RootPicName&"</b><BR>"
				Tmp = szAlbumDir+PicName
				Response.Write "<IMG SRC='"&Tmp&"' BORDER='0'>"

			%>
				<BR>[Click Here For The Small Version]</a><BR>
			<%
			If g_blnReloadPage Then
				Response.Write("<BR><BR>")
				Tmp = Tmp&".txt"
				WriteTextToResponseBuffer Tmp,1
			End If
			%>
				<BR>
				<a href="showphotos.asp"><IMG SRC="<%=g_szGfxPath%>index.gif" BORDER="0"></a>
				<a href="<%=g_szHomePage%>"><IMG SRC="<%=g_szGfxPath%>home.gif" BORDER="0"></a><BR>
			<%
		Else	'Mini-pics
		%>
		<TABLE WIDTH="90%" CELLSPACING="0" ALIGN="CENTER" CELLPADDING="0" BORDER="0" BGCOLOR="#ffffff">
			<TR><TD COLSPAN="4"> </TD></TR>
			<TR VALIGN="TOP">
			<TD ALIGN="RIGHT">

				<TABLE CELLSPACING="0" CELLPADDING="0" BORDER="0" BACKGROUND="<%=g_szGfxPath%>film1.gif">
				<%
					Dim aspPicList
					Dim strFileName

					' Create LHS of picture indices
					iTotal = 0
					PicName=g_szGfxPath&"null.gif"
					For each filefound in MyFiles.files 
						Select Case UCase(Right(filefound.Name,4))
						Case ".GIF",".JPG"
								strFileName = Left(filefound.Name, Len(filefound.Name)-4)
								If iTotal = PicNum Then
									PicName = filefound.Name
									RootPicName = strFileName
								End If

								If g_blnReloadPage Then
									%>
									<TR VALIGN="TOP"><TD WIDTH="56" ALIGN="CENTER">
									<%
									If iTotal = PicNum Then
										Response.Write (iTotal+1)&"</TD></TR>"
									Else
										AddPhotoLink iTotal, iTotal+1, False
										Response.Write "</TD></TR>"
									End If
								Else
								%>
								<TR VALIGN="TOP"><TD WIDTH="56" ALIGN="CENTER"><a href="javascript:showPic(<%=iTotal%>)"><%=(iTotal+1)%></a></TD></TR>
								<%
								End If
								iTotal = iTotal+1
						End Select
					Next
				%>
				</TABLE>
			</TD>			

			<TD ALIGN="LEFT"><TABLE CELLSPACING="0" CELLPADDING="0" BORDER="0">
			<%
				' Create LHS of picture indices
				iTotal = 0
				PicName=g_szGfxPath&"null.gif"
				For each filefound in MyFiles.files 
					Select Case UCase(Right(filefound.Name,4))
					Case ".GIF",".JPG"
							strFileName = Left(filefound.Name, Len(filefound.Name)-4)
							If iTotal = PicNum Then
								PicName = filefound.Name
								RootPicName = strFileName
							End If

							If g_blnReloadPage Then
								%>
								<TR VALIGN="TOP">
								<%
								If iTotal = PicNum Then
									Response.Write "<TD ALIGN='LEFT'><FONT COLOR='#ff0000'>"&strFileName&"</FONT></TD></TR>"
								Else
									Response.Write "<TD ALIGN='LEFT'>"&strFileName&"</TD></TR>"
								End If
							Else
							%>
							<TR VALIGN="TOP"><TD WIDTH="250" ALIGN="LEFT"><%=strFileName%></TD></TR>
							<%
							End If
							iTotal = iTotal+1
					End Select
				Next
			%>
			</TABLE></TD>

			<!-- Show us the picture! -->
			<TD ALIGN="CENTER">
				<a href="javascript:ChangeSize(1)">
			<%
				Tmp = szAlbumDir+PicName
				If g_blnReloadPage Then
			%>
					<IMG SRC="<%=Tmp%>" WIDTH="240" BORDER="0"></a>
			<%
				Else
			%>
					<IMG SRC="<%=Tmp%>" WIDTH="240" HEIGHT="180" BORDER="0" NAME="pic"></a>
			<%
				End If
				
				Response.Write"<BR>"
			%>
				<a href="javascript:ChangeSize(1)">[Click Here For The Full Size Version!]</a>
			</TD>

			<!-- Show us the RHS buttons, next/prev etc -->
			<TD>
			<%
				If g_blnReloadPage Then
					' Previous?
					If PicNum > 0 Then
						AddPhotoLink PicNum-1, g_szGfxPath&"prev.gif", True
					Else
						Response.Write "<IMG SRC='"&g_szGfxPath&"null.gif' WIDTH='56' BORDER='0'>"
					End If
					' Next?
					If PicNum+1 < iTotal Then
						AddPhotoLink PicNum+1, g_szGfxPath&"next.gif", True
					Else
						Response.Write "<IMG SRC='"&g_szGfxPath&"null.gif' WIDTH='56' BORDER='0'>"
					End If
				Else
			%>
				<a href="javascript:lastPic()"><IMG SRC="<%=g_szGfxPath%>prev.gif" name="prev" BORDER="0"></a>
				<a href="javascript:nextPic()"><IMG SRC="<%=g_szGfxPath%>next.gif" name="next" BORDER="0"></a>
			<%
				End If
			%>
				<BR>
				<a href="showphotos.asp"><IMG SRC="<%=g_szGfxPath%>index.gif" BORDER="0"></a><BR>
				<a href="<%=g_szHomePage%>"><IMG SRC="<%=g_szGfxPath%>home.gif" BORDER="0"></a><BR>

			</TD></TR>
	<%
		' You can only have comments if you reload the page
		If g_blnReloadPage Then
			Response.Write("<TR WIDTH='100%'><TD COLSPAN='2'> </TD><TD COLSPAN='2'><BR>")
			Tmp = Tmp&".txt"
			WriteTextToResponseBuffer Tmp,1
			Response.Write("</TD></TR>")
		End If
	%>
		<TR><TD COLSPAN="4"> </TD></TR>
		</TABLE>

	<%
		End If
	Else
	%>
		<DIV ALIGN="CENTER">
			<FONT SIZE="5"><b><BR><BR>There are no photographs at the moment.<BR><BR></b></FONT>
			<BR>
			<a href="showphotos.asp"><IMG SRC="<%=g_szGfxPath%>index.gif" BORDER="0"></a>
			<a href="<%=g_szHomePage%>"><IMG SRC="<%=g_szGfxPath%>home.gif" BORDER="0"></a><BR>
		</DIV>
	<%
	End If
	%>
	<BR><HR WIDTH="50%">
<%
	' Show directories
	If ShowPhotoAlbums(szAlbumDir) Then
		Response.Write "<HR>"
	End If

	' Show parent dir
	If g_ShowParentDirectories Then
		ShowPhotoAlbums szAlbumDir+".."
	End If

	ShowCopyright
	ShowFooter
End Sub


Sub AddPhotoLink(iPhoto, LabelName, bAsImage)
	Response.Write "<a href='showphotos.asp?"	
	Response.Write "szAlbumDir="&Request.QueryString("szAlbumDir")
	Response.Write "&blnFullSize="&Request.QueryString("blnFullSize")
	Response.Write "&photo="&iPhoto&"' onMouseOver=""showstatus("&iPhoto&"); return true"">"

	If bAsImage Then
		%><IMG SRC="<%=LabelName%>" ALT="<%=LabelName%>" BORDER="0"></a><%
	Else
		Response.Write LabelName&"</a>"
	End If
End Sub


Sub WriteTextToResponseBuffer(strFileName, blnShowBorder)
Dim objFSO, objTextFile, strText

'	On Error Resume Next
	' Create FileSystemObject to deal with file access
	Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
	strFileName = Server.MapPath(strFileName)

	If objFSO.FileExists(strFileName) Then

		Set objTextFile = objFSO.OpenTextFile(strFileName, 1, False)

		' Read the current count from the file
		If Not objTextFile.AtEndOfStream Then
			' Set value to contents of the file
			If blnShowBorder Then
			%>
				<TABLE BORDER="0" CELLPADDING="2" CELLSPACING="0" WIDTH="95%"><TR><TD BGCOLOR="#FF0000">
				<TABLE BORDER="0" CELLPADDING="2" CELLSPACING="0" WIDTH="100%" BGCOLOR="#FFFFFF"><TR><TD><BR>
			<%
			End If

			strText = objTextFile.ReadAll()
			strText = Server.HTMLEncode(strText)
			strText = Replace(strText, vbCrLf, "<BR>" & vbCrLF, 1, -1, 1)
			Response.Write strText

			If blnShowBorder Then
				Response.Write "<BR><BR></TD></TR></TABLE></TD></TR></TABLE>"
			End If
		End If

		objTextFile.Close
	End If

	' Close the file and destroy the object
	Set objTextFile = Nothing
	' And the file system
	Set objFSO = Nothing
End Sub


Function ShowPhotoAlbums(path)
Dim MyDirectory, MyFolders, folderfound

	iNum=0
%>
	<TABLE WIDTH="100%" ALIGN="CENTER" CELLSPACING="4" CELLPADDING="2" BORDER="0">
		<TR VALIGN="TOP">
<%
			Set MyDirectory=Server.CreateObject("Scripting.FileSystemObject") 
			Set MyFolders=MyDirectory.GetFolder(Server.MapPath(path)) 
			For each folderfound in MyFolders.SubFolders 
			iNum=iNum+1
%> 
			<TD ALIGN="CENTER"><a href="showphotos.asp?szAlbumDir=<%=path&"/"&folderfound.Name%>&blnFullSize=<%=Request.QueryString("blnFullSize")%>"><IMG SRC="<%=g_szGfxPath%>album.gif" BORDER="0"><BR><%=folderfound.Name%></a></TD>
<%
		    Next 
		Response.Write("</TR></TABLE>")
	Set MyDirectory = Nothing
	ShowPhotoAlbums = iNum
End Function
%>