<!--#include file="config.asp"--><%
'*********************************************************************************
' Picture Gallery ASP script(c) Fedor Skvortsov, COMobjects.NET. June, 2001
' Mailto: support@comobjects.net
' WWW:
'*********************************************************************************
'If number of pictures exceedes intMaxPictures, contents of the folder
'splits into pages.
Dim intMaxPictures
intMaxPictures = intColCount * intMaxRows
'Getting parameters from URL.
Dim strPath, intPage, strPhysicalPath, strPicture
'Path to the current folder of the gallery
strPath = Request.QueryString("path"
'Number of the current page. Default value is 1
If Request.QueryString("page"

<>"" Then
intPage = CInt(Request.QueryString("page"

)
Else
intPage=1
End If
'Filename of the picture
strPicture = Request.QueryString("picture"
'Physical path of the current folder
strPhysicalPath = Server.MapPath(strGalleryPath & strPath)
'Prevent somebody from browsing the structure of file system
'*******************************************************************************************************
If InStr(1, Server.MapPath(strGalleryPath & strPath), Server.MapPath(strGalleryPath), 1) <> 1 Or _
InStr(1,Server.MapPath(strGalleryPath & strPath & strPicture), Server.MapPath(strGalleryPath), 1) <> 1 Then
Err.Raise 5054, "COMobjectsNET PictureGallery Script", "Security Error"
End If
'*******************************************************************************************************
Dim objFileSystem, objFolder, objSubFolder, objFile
Set objFileSystem = Server.CreateObject("Scripting.FileSystemObject"

Set objFolder = objFileSystem.GetFolder(strPhysicalPath)
'Displaying Path to the current folder (or picture) and placing references to the folders
Dim strFolders
strFolders = Split(strPath, "/"
Response.Write "<table width='" & strGalleryWidth & "'><tr><td width='100%'><p class=path><img border='0' src='" & strOpenFolderIcon & "'>"
If strPath<>"" Or strPicture<>"" Then
Response.Write " <a href='PictureGallery.asp'>Gallery</a>"
Else
Response.Write " Gallery"
End If
Dim strP
strP = ""
For I=0 To UBound(strFolders)-2
strP= strP + strFolders(i) + "/"
Response.Write "\<a href='PictureGallery.asp?path=" & Server.URLEncode(strP) & "'>" & strFolders(i) & "</a>"
Next
If UBound(strFolders)>0 Then
If strPicture="" Then
Response.Write "\" & strFolders(UBound(strFolders)-1)
Else
strP = strP + strFolders(UBound(strFolders)-1) + "/"
Response.Write "\<a href='PictureGallery.asp?path=" & Server.URLEncode(strP) & "&page=" & intPage & "'>"
Response.Write strFolders(UBound(strFolders)-1) & "</a>"
End If
End If
If strPicture<>"" Then
Response.Write "\" & strPicture
End If
Response.Write "</p></td>"
'Displaying "Top" and "Parent" buttons
Response.Write "<td width='100'><p>"
If strPath<>"" Or strPicture<>"" Then
Response.Write "<a href='PictureGallery.asp?path=" & Server.URLEncode(strP)
If strPicture<>"" Then Response.Write "&page=" & intPage
Response.Write "'>"
Response.Write "<img border='0' src='" & strParentButton & "'></a>"
Else
Response.Write "<img border='0' src='" & strParentButtonDisabled & "'>"
End If
Response.Write "</p></td><td width='100'><p>"
If strPath<>"" Or strPicture<>"" Then
Response.Write "<a href='PictureGallery.asp'><img border='0' src='" & strTopButton & "'></a>"
Else
Response.Write "<img border='0' src='" & strTopButtonDisabled & "'>"
End If
Response.Write "</p></td></tr></table><br>"
'Creating description file if it is missed and auto generation of it is enabled
Dim strDescFilePath, objDescFile
strDescFilePath = objFolder.Path + "\" + strDescFileName
If blnDescCreation Then
If Not objFileSystem.FileExists(strDescFilePath) Then
Set objDescFile = objFileSystem.CreateTextFile(strDescFilePath)
objDescFile.WriteLine "FileName" & strDelimiter & "Description"
objDescFile.Close
Set objDescFile = Nothing
End If
End If
'Opening description file with ADO
'Determines exists or not description file.
'If description file exists it equals 1, elsewhere 0.
Dim intDescExists
Dim objConnection, objRecordSet, strConnString
Set objRecordSet = Server.CreateObject("ADODB.RecordSet"

If objFileSystem.FileExists(strDescFilePath) Then
strConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & objFolder.Path & ";Extended Properties='text;FMT=Delimited'"
Set objConnection = Server.CreateObject("ADODB.Connection"
objConnection.ConnectionTimeout = 15
objConnection.Open strConnString
intDescExists = 1
Else
intDescExists = 0
objConnection = null
End If
'Displaying subfolders and thumbnails or whole picture
If strPicture="" Then
'Displaying subfolders
Response.Write "<table width='" & strGalleryWidth & "'>"
Dim I
I= 0
For Each objSubFolder In objFolder.SubFolders
'Don't display thumbnails and hidden folders, such as Front Page Extensions ones
If Left(objSubFolder.Name,1)<>"_" And objSubFolder.Name<>"Thumbnails" Then
If I Mod 2 = 0 Then Response.Write "<tr>"
Response.Write "<td width='50%'>"
Response.Write "<p class=folder><img border='0' src='" & strFolderIcon & "'> "
Response.Write "<a target='_self' href='PictureGallery.asp?path=" & Server.URLEncode(strPath & objSubFolder.Name) & "/'>"
Response.Write objSubFolder.Name
Response.Write "</a> ("
If objFileSystem.FileExists(objSubFolder.Path & "\" & strDescFileName) Then
Response.Write objSubFolder.Files.Count - 1
Else
Response.Write objSubFolder.Files.Count
End If
Response.Write "

</p></td>"
If I Mod 2 = 1 Then Response.Write "</tr>"
I=I+1
End If
Next
If I Mod 2 = 1 Then Response.Write "<td></td></tr>"
Response.Write "</table>"
'Displaying thumbnails
Response.Write "<table width='" & strGalleryWidth & "'>"
I = 0
For Each objFile In objFolder.Files
If objFile.Name<>strDescFileName Then
If (I+1)>=((intPage-1)*intMaxPictures+1) And (I+1)<=((intPage)*intMaxPictures) Then
If I Mod intColCount = 0 Then Response.Write "<tr>"
Response.Write "<td width='" & 100 \ intColCount & "%' align='center' valign='top'>"
Response.Write "<table width='100%'>"
Response.Write "<tr><td width='100%' height='" & (intThumbnailSize + 5) & "' valign='bottom' align='center'>"
Response.Write "<a target='_blank' href='PictureGallery.asp?path=" & Server.URLEncode(strPath)
Response.Write "&picture=" & Server.URLEncode(objFile.Name) & "&page=" & intPage & "'>"
Response.Write "<img border='0' class=thumb src='thumbnail.asp?path="
Response.Write Server.URLEncode(strGalleryPath & strPath & objFile.Name) & "&size=" & intThumbnailSize & "'>"
Response.Write "</a></td></tr>"
'Displaying picture info
Response.Write "<tr><td align='center' height='50' width='100%' class='infobox'>"
Response.Write "<p>"
If intDescExists=1 Then
objRecordSet.Open "Select * From " & strDescFileName & " Where FileName='" & objFile.Name & "'", objConnection, 3, 1, 1
If Not objRecordSet.EOF Then
If objRecordSet(1)<>"" Then
Response.Write "<span class=description>" & objRecordSet(1) & "</span><br>"
End If
Else
If blnDescCreation Then
objConnection.Execute "INSERT INTO " & strDescFileName & "(FileName, Description) VALUES('" & objFile.Name & "', '')"
End If
End If
objRecordSet.Close
End If
Response.Write "<span class=info>" & objFile.Name & "</span><br>"
Response.Write "<span class=info>" & Month(objFile.DateLastModified) & "/"
Response.Write Day(objFile.DateLastModified) & "/" & Year(objFile.DateLastModified) & "</span><br>"
Response.Write "<span class=info>" & objFile.Size \ 1024 & "kb</span>"
Response.Write "</p></td></tr></table></td>"
If I Mod intColCount = intColCount-1 Then Response.Write "</tr>"
End If
I=I+1
End If
Next
If I Mod intColCount > 0 Then
Dim J
For J=(I Mod intColCount) + 1 To intColCount
Response.Write "<td width='" & 100 \ intColCount & "%' align='center' valign='bottom'>"
Response.Write "<table width='100%'>"
Response.Write "<tr></tr></table></td>"
Next
Response.Write "</tr>"
End If
Response.Write "</table>"
'Diplaying references to the pages if it's necessary
If objFolder.Files.Count-intDescExists>intMaxPictures Then
Dim intTotalPages
intTotalPages = (objFolder.Files.Count + intMaxPictures - 1 - intDescExists) \ intMaxPictures
Response.Write "<table width='" & strGalleryWidth & "'><tr>"
Response.Write "<td width='100%' align='center'><p class=navbar>"
If intPage>1 Then
Response.Write "<a href='PictureGallery.asp?path=" & Server.URLEncode(strPath) & "&page=" & intPage-1 & "'><< Prev <<</a>"
Else
Response.Write "<< Prev <<"
End If
For I=1 To intTotalPages
If I<>intPage Then
Response.Write "<a href='PictureGallery.asp?path=" & Server.URLEncode(strPath) & "&page=" & I & "'>| " & (I-1)*intMaxPictures+1 & "-"
If I*intMaxPictures>objFolder.Files.Count-intDescExists Then
Response.Write objFolder.Files.Count-intDescExists
Else
Response.Write I*intMaxPictures
End If
Response.Write " |</a>"
Else
Response.Write "| " & (I-1)*intMaxPictures+1 & "-"
If I*intMaxPictures>objFolder.Files.Count-intDescExists Then
Response.Write objFolder.Files.Count-intDescExists
Else
Response.Write I*intMaxPictures
End If
Response.Write "|"
End If
Next
If intPage<intTotalPages Then
Response.Write "<a href='PictureGallery.asp?path=" & Server.URLEncode(strPath) & "&page=" & intPage+1 & "'>>> Next >></a>"
Else
Response.Write ">> Next >>"
End If
Response.Write "</p></td></tr></table>"
End If
Else
'Displaying whole picture
Response.Write "<table width='" & strGalleryWidth & "'>"
Response.Write "<tr><td width='100%' align='center'>"
On Error Resume Next
If intDescExists=1 Then
objRecordSet.Open "Select * From " & strDescFileName & " Where FileName='" & strPicture & "'", objConnection, 3, 1, 1
If Not objRecordSet.EOF Then
If objRecordSet(1)<>"" Then
Response.Write "<p class=description>" & objRecordSet(1) & "</p>"
End If
End If
objRecordSet.Close
End If
On Error GoTo 0
Response.Write "<img class=fullimage src='" & strGalleryPath & strPath & strPicture & "'>"
'Scanning for files in folder
Dim strFiles()
ReDim strFiles(objFolder.Files.Count-intDescExists)
I = 0
Dim intPicture
For Each objFile in objFolder.Files
If objFile.Name<>strDescFileName Then
strFiles(I) = objFile.Name
If objFile.Name = strPicture Then intPicture = I
I = I + 1
End If
Next
Response.Write "<p align=center class=navbar>"
If intPicture>0 Then
Response.Write "<a href='PictureGallery.asp?path=" & Server.URLEncode(strPath)
Response.Write"&picture=" & Server.URLEncode(strFiles(intPicture-1)) & "'><< Prev <<</a> "
Else
Response.Write "<< Prev << "
End If
For I=0 To UBound(strFiles)-1
If I<>intPicture Then
Response.Write "<a href='PictureGallery.asp?path=" & Server.URLEncode(strPath)
Response.Write"&picture=" & Server.URLEncode(strFiles(I)) & "'>| " & I+1 & " |</a> "
Else
Response.Write "| " & (I+1)
Response.Write "| "
End If
Next
If intPicture+1<UBound(strFiles) Then
Response.Write " <a href='PictureGallery.asp?path=" & Server.URLEncode(strPath)
Response.Write"&picture=" & Server.URLEncode(strFiles(intPicture+1)) & "'>>> Next >></a>"
Else
Response.Write " >> Next >>"
End If
Response.Write "</p></td></tr></table>"
End If
If objConnection<>Null Then objConnection.Close
Set objConnection = Nothing
Set objRecordSet = Nothing
Set objFolder = Nothing
Set objFileSystem = Nothing
%>