<%@ Language=VBScript %>
<%
Option Explicit
Response.Buffer = True 'Turn buffering on
Response.Expires = -1 'Page expires immediately
'Constants
Const MIN_PAGESIZE = 3 'Minimum pagesize
Const MAX_PAGESIZE = 30 'Maximum pagesize
Const DEF_PAGESIZE = 5 'Default pagesize
'Variables
Dim objCn 'ADO DB connection object
Dim objRs 'ADO DB recordset object
Dim blnWhere 'True/False for have WHERE in sql already
Dim intRecord 'Current record for paging recordset
Dim intPage 'Requested page
Dim intPageSize 'Requested pagesize
Dim sql 'Dynamic sql query string
Dim ID
ID = Request.QueryString("ID") 'ID matches the Entry_ID for the news item in the database
'The following lines of code connect to the database and create the recordset.
'Create objects
Set objCn = Server.CreateObject("ADODB.Connection")
Set objRs = Server.CreateObject("ADODB.Recordset")
'Set/initialize variables
intRecord = 1
blnWhere = False
'-Get/set requested page
intPage = MakeLong(Request("page"))
If intPage < 1 Then intPage = 1
'-Get/set requested pagesize
If IsEmpty(Request("pagesize")) Then 'Set to default
intPageSize = DEF_PAGESIZE
Else
intPageSize = MakeLong(Request("pagesize"))
'Make sure it fits our min/max requirements
If intPageSize < MIN_PAGESIZE Then
intPageSize = MIN_PAGESIZE
ElseIf intPageSize > MAX_PAGESIZE Then
intPageSize = MAX_PAGESIZE
End If
End If
'-Build dynamic sql
sql = "SELECT Picture, Location, Site, Description, Museum, ImageName, ImageName2, PhotoID FROM Afpc "
'--Museum (partial and exact search)
If Not IsEmpty(Request("ID")) Then
Dim strSku
strSku = (Trim(Request("ID")))
If strSku <> "" Then
'Test for WHERE
If blnWhere Then sql = sql & "AND " Else sql = sql & "WHERE " : blnWhere = True
If (Left(strSku, 1) = "*" And Len(strSku) > 1) Then 'Partial search
sql = sql & "(Museum LIKE '%" & Replace(Mid(strSku, 2), "'", "''") & "%') "
ElseIf (Right(strSku, 1) = "*" And Len(strSku) > 1) Then 'Partial search
sql = sql & "(Museum LIKE '%" & Replace(Mid(strSku, 1, Len(strSku)-1), "'", "''") & "%') "
Else 'Exact match
sql = sql & "(Museum = '" & Replace(strSku, "'", "''") & "') "
End If
End If
End If
'--Sort By Field
sql = sql & "ORDER BY "
sql = sql & "PhotoID "
'--Sort Order
Select Case Trim(LCase(Request("sortorder")))
Case "desc": sql = sql & "DESC"
Case Else: sql = sql & "ASC"
End Select
'--Dynamic sql finished
'Create and open connection object
With objCn
.CursorLocation = adUseClient
.ConnectionTimeout = 15
.CommandTimeout = 30
.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & Server.MapPath("./Afc.mdb") & ";"
.Open
End With
'Create and open recordset object
With objRs
.ActiveConnection = objCn
.CursorLocation = adUseClient
.CursorType = adOpenForwardOnly
.LockType = adLockReadOnly
.Source = sql
.PageSize = intPageSize
.Open
Set .ActiveConnection = Nothing 'Disconnect the recordset
End With
'Creates a long value from a variant, invalid always set to zero
Function MakeLong(ByVal varValue)
If IsNumeric(varValue) Then
MakeLong = CLng(varValue)
Else
MakeLong = 0
End If
End Function
'Returns a neatly made paging string, automatically configuring for request
'variables, regardless of in querystring or from form, adjust output to your needs.
Function Paging(ByVal intPage, ByVal intPageCount, ByVal intRecordCount)
Dim strQueryString
Dim strScript
Dim intStart
Dim intEnd
Dim strRet
Dim i
If intPage > intPageCount Then
intPage = intPageCount
ElseIf intPage < 1 Then
intPage = 1
End If
If intRecordCount = 0 Then
strRet = "No Records Found"
ElseIf intPageCount = 1 Then
strRet = "End Of Hits"
Else
For i = 1 To Request.QueryString.Count
If LCase(Request.QueryString.Key(i)) <> "page" Then
strQueryString = strQueryString & "&"
strQueryString = strQueryString & Server.URLEncode(Request.QueryString.Key(i)) & "="
strQueryString = strQueryString & Server.URLEncode(Request.QueryString.Item(i))
End If
Next
For i = 1 To Request.Form.Count
If LCase(Request.Form.Key(i)) <> "page" Then
strQueryString = strQueryString & "&"
strQueryString = strQueryString & Server.URLEncode(Request.Form.Key(i)) & "="
strQueryString = strQueryString & Server.URLEncode(Request.Form.Item(i))
End If
Next
If Len(strQueryString) <> 0 Then
strQueryString = "?" & Mid(strQueryString, 2) & "&"
Else
strQueryString = "?"
End If
strScript = Request.ServerVariables("SCRIPT_NAME") & strQueryString
If intPage <= 10 Then
intStart = 1
Else
If (intPage Mod 10) = 0 Then
intStart = intPage - 9
Else
intStart = intPage - (intPage Mod 10) + 1
End If
End If
intEnd = intStart + 9
If intEnd > intPageCount Then intEnd = intPageCount
strRet = "Page " & intPage & " of " & intPageCount & ": "
If intPage <> 1 Then
strRet = strRet & "<<Prev "
End If
For i = intStart To intEnd
If i = intPage Then
strRet = strRet & "" & i & " "
Else
strRet = strRet & "" & i & ""
If i <> intEnd Then strRet = strRet & " "
End If
Next
If intPage <> intPageCount Then
strRet = strRet & " Next>> "
End If
End If
Paging = strRet
End Function
%>
The American School of Classical Studies at Athens: The Alison Frantz Photographic Collection
<%
'Object cleanup
If IsObject(objRs) Then
If Not objRs Is Nothing Then
If objRs.State = adStateOpen Then objRs.Close
Set objRs = Nothing
End If
End If
If IsObject(objCn) Then
If Not objCn Is Nothing Then
If objCn.State = adStateOpen Then objCn.Close
Set objCn = Nothing
End If
End If
%>