% OPTION EXPLICIT %>
<%
' Set Error Handler
' Declare variables
Dim rs, rs2
Dim strSQL
Dim dbConn
' Form elements
Dim isSubmit
Dim courseCode
Dim courseMonth
Dim courseYear
Dim courseLocation
Dim orderBy
' page vars
Dim helperVar
Dim temp
Dim i, tempDate, tempMonth, tempYear
' limited list vars
Dim nextUrl
Dim preUrl
Dim listlength
Dim totalRecords
Dim listStartNum
Dim listEndNum
Dim displayPreBtn
Dim displayNextBtn
' init values
listlength = 20
totalRecords = 0
listStartNum = 0
listEndNum = 0
displayPreBtn = false
displayNextBtn = false
nextUrl = ""
preUrl = ""
helperVar = false
' get some parameters
if (CStr(Request.Form("Submit")) = "") then
isSubmit = CStr(Request.QueryString("Submit"))
else
isSubmit = CStr(Request.Form("Submit"))
end if
if (CStr(Request.Form("paramtext_categoryId")) = "") then
courseCode = CStr(Request.QueryString("paramtext_categoryId"))
else
courseCode = CStr(Request.Form("paramtext_categoryId"))
end if
if (CStr(Request.Form("paramtext_courseMonth")) = "") then
courseMonth = CStr(Request.QueryString("paramtext_courseMonth"))
else
courseMonth = CStr(Request.Form("paramtext_courseMonth"))
end if
if (CStr(Request.Form("paramtext_courseYear")) = "") then
courseYear = CStr(Request.QueryString("paramtext_courseYear"))
else
courseYear = CStr(Request.Form("paramtext_courseYear"))
end if
if (CStr(Request.Form("paramtext_courseLocation")) = "") then
courseLocation = CStr(Request.QueryString("paramtext_courseLocation"))
else
courseLocation = CStr(Request.Form("paramtext_courseLocation"))
end if
if (CStr(Request.Form("paramtext_orderBy")) = "") then
orderBy = CStr(Request.QueryString("paramtext_orderBy"))
else
orderBy = CStr(Request.Form("paramtext_orderBy"))
end if
' Open DB connection
Set dbConn = Server.CreateObject("ADODB.Connection")
dbConn.Open "Driver={SQL Server}; Server=PAPASMURF; Database=UIProd001; Uid=UIProd001; Pwd=chainsaw;"
' Do something if request for records sent
if isSubmit = "Submit >>" then
' Get the records/ build the sql statement
set rs = Server.CreateObject("ADODB.Recordset")
rs.CursorLocation = 3 'adUseClient
strSQL = "SELECT * FROM Classes"
if not courseCode = "*" then
strSQL = strSQL & " WHERE curriculum='" & courseCode & "'"
helperVar = true
end if
if not courseMonth = "*" then
tempMonth = DatePart("m", courseMonth)
tempYear = DatePart("yyyy", courseMonth)
if helperVar = false then
strSQL = strSQL & " WHERE classDate BETWEEN '" & DateSerial(tempYear, tempMonth, 1) & "' AND '" & DateSerial(tempYear, tempMonth, 31) & "'"
else
strSQL = strSQL & " AND classDate BETWEEN '" & DateSerial(tempYear, tempMonth, 1) & "' AND '" & DateSerial(tempYear, tempMonth, 31) & "'"
end if
helperVar = true
end if
if not courseLocation = "*" then
if helperVar = false then
strSQL = strSQL & " WHERE city='" & courseLocation & "'"
else
strSQL = strSQL & " AND city='" & courseLocation & "'"
end if
end if
strSQL = strSQL & " ORDER BY " & orderBy
rs.Open strSQL, dbConn
totalRecords = rs.RecordCount
' Get startnumber parameter
if (CStr(Request.QueryString("startnum")) = "") then
listStartNum = 1
else
listStartNum = CStr(Request.QueryString("startnum"))
end if
' Page logic for start, end, next numbers for the limited list of records
if (totalRecords = 0) then
listStartNum = 0
end if
if (int(listStartNum) > (int(totalRecords) - int(listlength))) then
listEndNum = totalRecords
else
listEndNum = int(listStartNum) + int(listlength) - 1
end if
if ((int(totalRecords) - int(listStartNum)) >= int(listlength)) then
displayNextBtn = true
nextUrl = "searchCourse.asp?startnum=" & (listStartNum + listlength)
nextUrl = nextUrl & "&submit=" & isSubmit
nextUrl = nextUrl & "¶mtext_categoryId=" & courseCode
nextUrl = nextUrl & "¶mtext_courseMonth=" & courseMonth
nextUrl = nextUrl & "¶mtext_courseLocation=" & courseLocation
nextUrl = nextUrl & "¶mtext_orderBy=" & orderBy
else
displayNextBtn = false
end if
if (int(listStartNum) > int(listlength)) then
displayPreBtn = true
preUrl = "searchCourse.asp?startnum=" & (listStartNum - listlength)
preUrl = preUrl & "&submit=" & isSubmit
preUrl = preUrl & "¶mtext_categoryId=" & courseCode
preUrl = preUrl & "¶mtext_courseMonth=" & courseMonth
preUrl = preUrl & "¶mtext_courseLocation=" & courseLocation
preUrl = preUrl & "¶mtext_orderBy=" & orderBy
else
displayPreBtn = false
end if
end if
%>