% Option Explicit %> <% Dim oConn, sConn, sAbsPath Dim sHTTPHost: sHTTPHost = Request.ServerVariables("HTTP_HOST") Dim sHTTPPort: sHTTPPort = Request.ServerVariables("SERVER_PORT") Dim blnNamedPipe: blnNamedPipe = False If InStr(sHTTPHost, "localhost") > 0 AND sHTTPPort = "80" Then sAbsPath = "http://" & sHTTPHost & "/ie/2007-12-20" blnNamedPipe = True ElseIf InStr(sHTTPHost, "localhost") > 0 AND sHTTPPort = "8080" Then sAbsPath = "http://" & sHTTPHost & "/interexcel/ie/2007-12-20" ElseIf InStr(sHTTPHost, "interexcel.co.za") > 0 Then sAbsPath = "http://www.interexcel.co.za/clients/interexcel" Else sAbsPath = "http://www.interexcel.co.za" End If Sub openConn() Set oConn = Server.CreateObject("ADODB.Connection") If NOT blnNamedPipe Then sConn = "Driver={SQL Server};Server=(local);Database=interexcel;Uid=interexcel;Pwd=iedbpass1" Else sConn = "Driver={SQL Server};Server=PIETERPC\PIETERPC;Database=interexcel;Uid=interexcel;Pwd=iedbpass1" End If oConn.Open sConn End Sub Sub closeConn() If IsObject(oConn) Then On Error Resume Next If oConn.State = 1 Then oConn.Close End If Set oConn = Nothing Err.Clear On Error Goto 0 End If End Sub %> <% '-------------------------------------------------------------------------- ' Check if a value is found in an array '-------------------------------------------------------------------------- Function in_array(element, arr) Dim iCnt If IsArray(arr) Then For iCnt = LBound(arr) To Ubound(arr) If IsNumeric(arr(iCnt)) AND IsNumeric(element) Then If CInt(arr(iCnt)) = CInt(element) Then in_array = True Exit Function Else in_array = False End If Else If Trim(arr(iCnt)) = Trim(element) Then in_array = True Exit Function Else in_array = False End If End If Next Else If IsNumeric(element) AND IsNumeric(arr) Then If CInt(element) = CInt(arr) Then in_array = True Exit Function Else in_array = False End If Else If Trim(element) = Trim(arr) Then in_array = True Exit Function Else in_array = False End If End If End If End Function '-------------------------------------------------------------------------- ' Check if user is admin '-------------------------------------------------------------------------- Function isAdmin() Dim AdminIDSession: AdminIDSession = Request.Cookies("InterexcelAdminID") isAdmin = False If AdminIDSession <> "" Then isAdmin = True End If End Function %> <% '-------------------------------------------------------------------------- ' Return pagination string '-------------------------------------------------------------------------- ' Syntax: Response.Write (pagination(byVal current_page, byVal objRS.PageCount, byVal objRS.RecordCount) '-------------------------------------------------------------------------- ' Dependancies: CSS styles which may be found in /admin/css/global.css and /admin/css/[theme].css '-------------------------------------------------------------------------- Function pagination(byVal pg, byVal total_pages, byVal total_records) Dim url, oncelink, prevlink, nextlink, lastlink Dim str_pages: str_pages = "" On Error Resume Next pg = CLng(pg) On Error GoTo 0 '-- build URL, remove old pg data -- Dim oRegExp: Set oRegExp = New RegExp oRegExp.Pattern = "(&|\?)?pg=[^&]*(&|$)" oRegExp.IgnoreCase = True oRegExp.Global = True url = oRegExp.Replace(Request.ServerVariables("SCRIPT_NAME") & "?" & Request.ServerVariables("QUERY_STRING"), "$1") Set oRegExp = Nothing If (Right(url, 1) = "&") Then url = Left(url, Len(url) - 1) If (Right(url, 1) = "?") Then url = Left(url, Len(url) - 1) If (InStr(url, "?") > 0) Then url = url & "&" Else url = url & "?" End If url = Replace(url, "&", "&") If (pg < total_pages) AND (pg > 1) Then oncelink = "<" prevlink = "«" nextlink = "»" lastlink = ">" End If If (pg = 1) Then oncelink = "<" prevlink = "«" nextlink = "»" lastlink = ">" End If If (pg = total_pages) Then If (total_pages = 1) Then oncelink = "<" prevlink = "«" nextlink = "»" lastlink = ">" Else oncelink = "<" prevlink = "«" nextlink = "»" lastlink = ">" End If End If str_pages = "" str_pages = str_pages & "
")
Call print_r(posted, 0)
Response.Write ("")
Response.End
j = UBound(posted)
For i = 0 To j - 1
If posted(i) <> 0 Then
Exit For
End If
Next
str_out = posted(i) & " " & names(i)
If posted(i) <> 1 Then
str_out = str_out & "s"
End If
If i + 1 < 5 Then
If posted(i + 1) <> 0 Then
str_out = str_out & ", " & posted(i + 1) & " " & names(i + 1)
If posted(i + 1) <> 1 Then
str_out = str_out & "s"
End If
End If
End If
Else
str_out = "Unknown date format"
End If
time_since = str_out
End Function
'--------------------------------------------------------------------------
' Determines if a date falls on a week-end
'--------------------------------------------------------------------------
Function isWeekEnd(byVal dteDate)
If WeekDay(dteDate) = vbSunday OR WeekDay(dteDate) = vbSaturday Then
isWeekEnd = True
Else
isWeekEnd = False
End If
End Function
'--------------------------------------------------------------------------
' Return the number of days to skip (forward) to get back to
' a work date
'--------------------------------------------------------------------------
Function skipDate(byVal dteDate)
If WeekDay(dteDate) = vbSunday Then
skipDate = universalDate(DateAdd("d", 1, dteDate))
ElseIf WeekDay(dteDate) = vbSaturday Then
skipDate = universalDate(DateAdd("d", 2, dteDate))
Else
skipDate = dteDate
End If
End Function
'--------------------------------------------------------------------------
' Universal date: convert date to human-readable and
' database-safe date
'--------------------------------------------------------------------------
Function universalDate(byVal dteDate)
dim dteDay, dteMonth, dteYear
' Check to see that a valid date was passed
If IsDate(dteDate) = True Then
dteDay = Day(dteDate)
dteMonth = Month(dteDate)
dteYear = Year(dteDate)
universalDate = dteYear & "-" & Right(Cstr(dteMonth + 100),2) & "-" & Right(Cstr(dteDay + 100),2)
Else
universalDate = Null
End If
End Function
'--------------------------------------------------------------------------
' Database-safe date/time
'--------------------------------------------------------------------------
Function dbDate(byVal dt)
dbDate = Year(dt) & Right("0" & Month(dt), 2) & Right("0" & Day(dt), 2) & " " & FormatDateTime(dt, 4)
End Function
'--------------------------------------------------------------------------
' Convert a date to a UNIX timestamp
'--------------------------------------------------------------------------
Function UDate(byVal oldDate)
UDate = DateDiff("s", "01/01/1970 00:00:00", oldDate)
End Function
'--------------------------------------------------------------------------
' Returns a date from a UNIX timestamp
'--------------------------------------------------------------------------
Function unUDate(byVal intTimeStamp)
unUDate = DateAdd("s", intTimeStamp, "01,01,1970 00:00:00")
End Function
'--------------------------------------------------------------------------
' Extended date/time formatting function
'--------------------------------------------------------------------------
Function formatDate(byVal formatting, byVal intTimeStamp)
dim unUDate, A
' Test to see if intTimeStamp looks valid. If not, they have passed a normal date
If NOT (IsNumeric(intTimeStamp)) Then
If IsDate(intTimeStamp) Then
intTimeStamp = DateDiff("S", "01/01/1970 00:00:00", intTimeStamp)
Else
Response.Write ("Date Invalid")
Exit Function
End If
End If
If (intTimeStamp = 0) Then
unUDate = Now()
Else
unUDate = DateAdd("s", intTimeStamp, "01/01/1970 00:00:00")
End If
unUDate = Trim(unUDate)
dim startM : startM = InStr(1, unUDate, "/", vbTextCompare) + 1
dim startY : startY = InStr(startM, unUDate, "/", vbTextCompare) + 1
dim startHour : startHour = InStr(startY, unUDate, " ", vbTextCompare) + 1
dim startMin : startMin = InStr(startHour, unUDate, ":", vbTextCompare) + 1
dim dateDay : dateDay = Mid(unUDate, 1, 2)
dim dateMonth : dateMonth = Mid(unUDate, startM, 2)
dim dateYear : dateYear = Mid(unUDate, startY, 4)
dim dateHour : dateHour = Mid(unUDate, startHour, 2)
dim dateMinute : dateMinute = Mid(unUDate, startMin, 2)
dim dateSecond : dateSecond = Mid(unUDate, InStr(startMin, unUDate, ":", vbTextCompare) + 1, 2)
formatting = Replace(formatting, "%Y", Right(dateYear, 4))
formatting = Replace(formatting, "%y", Right(dateYear, 2))
formatting = Replace(formatting, "%m", dateMonth)
formatting = Replace(formatting, "%n", CInt(dateMonth))
formatting = Replace(formatting, "%F", MonthName(CInt(dateMonth)))
formatting = Replace(formatting, "%M", Left(MonthName(CInt(dateMonth)), 3))
formatting = Replace(formatting, "%d", dateDay)
formatting = Replace(formatting, "%j", CInt(dateDay))
formatting = Replace(formatting, "%h", Mid(unUDate, startHour, 2))
formatting = Replace(formatting, "%g", CInt(Mid(unUDate, startHour, 2)))
If (CInt(dateHour) > 12) Then
A = "PM"
Else
A = "AM"
End If
formatting = Replace(formatting, "%A", A)
formatting = Replace(formatting, "%a", LCase(A))
If (A = "PM") Then formatting = Replace(formatting, "%H", Left("0" & dateHour - 12, 2))
formatting = Replace(formatting, "%H", dateHour)
If (A = "PM") Then formatting = Replace(formatting, "%G", Left("0" & CInt(dateHour) - 12, 2))
formatting = Replace(formatting, "%G", CInt(dateHour))
formatting = Replace(formatting, "%i", dateMinute)
formatting = Replace(formatting, "%I", CInt(dateMinute))
formatting = Replace(formatting, "%s", dateSecond)
formatting = Replace(formatting, "%S", CInt(dateSecond))
formatting = Replace(formatting, "%L", WeekDay(unUDate))
formatting = Replace(formatting, "%D", Left(WeekDayName(WeekDay(unUDate)), 3))
formatting = Replace(formatting, "%l", WeekDayName(WeekDay(unUDate)))
formatting = Replace(formatting, "%U", intTimeStamp)
formatting = Replace(formatting, "11%O", "11th")
formatting = Replace(formatting, "1%O", "1st")
formatting = Replace(formatting, "12%O", "12th")
formatting = Replace(formatting, "2%O", "2nd")
formatting = Replace(formatting, "13%O", "13th")
formatting = Replace(formatting, "3%O", "3rd")
formatting = Replace(formatting, "%O", "th")
formatDate = formatting
End Function
%>
<%
'--------------------------------------------------------------------------
' Prints out the values of an array for debugging purposes
'--------------------------------------------------------------------------
Sub print_r(ByVal array_value, depth)
dim iCnt
If IsArray(array_value) Then
Response.Write ("Array")
Response.Write (vbCrLf)
If depth > 0 Then
Response.Write (Space(4 * depth))
End If
Response.Write ("(")
Response.Write (vbCrLf)
For iCnt = LBound(array_value) To UBound(array_value)
Response.Write (Space(4 * (depth + 1)))
Response.Write ("[")
Response.Write (iCnt)
Response.Write ("] => ")
If IsArray(array_value(iCnt)) Then
Call print_r(array_value(iCnt), depth + 2)
Else
Response.Write (array_value(iCnt))
Response.Write (vbCrLf)
End If
Next
If depth > 0 Then
Response.Write (Space(4 * depth))
End If
Response.Write (")")
Response.Write (vbCrLf)
Response.Write (vbCrLf)
End If
End Sub
'--------------------------------------------------------------------------
' Prints out the values of a variable for debugging purposes
'--------------------------------------------------------------------------
Sub var_dump(ByRef variable)
dim iCnt, variable_type, variable_name
variable_type = VarType(variable)
variable_name = TypeName(variable)
Select Case variable_type
'vbEmpty
Case 0:
Response.Write (variable_name)
'vbNull
Case 1:
Response.Write (variable_name)
'vbInteger
Case 2:
Response.Write (variable_name)
'vbLong
Case 3:
Response.Write (variable_name)
'vbSingle
Case 4:
Response.Write (variable_name)
'vbDouble
Case 5:
Response.Write (variable_name)
'vbCurrency
Case 6:
Response.Write (variable_name)
'vbString
Case 7:
Response.Write (variable_name)
'vbObject
Case 8:
Response.Write ("vbString")
Case 9:
Response.Write ("vbObject")
Case 10:
Response.Write ("vbError")
Case 11:
Response.Write ("vbBoolean")
Case 12:
Response.Write ("vbVariant")
Case 13:
Response.Write ("vbDataObject")
Case 17:
Response.Write ("vbByte")
Case 8192, 8204, 8209:
Response.Write ("vbArray")
End Select
End Sub
%>
<%
'--------------------------------------------------------------------------
' Error handling class
'--------------------------------------------------------------------------
On Error Resume Next
Class Errors
'----------------------------------------------------------------------
' Public Declarations
'----------------------------------------------------------------------
' Detailed errors 0 = off , 1 = on
Public m_bDetailedError
' Create an error log file
Public m_bLogErrors
'----------------------------------------------------------------------
' Private Declarations
'----------------------------------------------------------------------
' File location
Private m_FilePath
' File name
Private m_LogFile
'----------------------------------------------------------------------
' Private Functions
'----------------------------------------------------------------------
' Called when class is initialised
Private Sub Class_Initialise()
dim Err
' Turn detailed errors on
m_bDetailedError = 1
' Turn off error log
m_bLogErrors = 0
' Get location of site
m_FilePath = Server.MapPath("/")
' Set file location and name
m_LogFile = m_FilePath & "errors.log"
End Sub
Private Sub Class_Terminate()
' Called when class terminates
m_bDetailedError = 0
m_bLogErrors = 0
End Sub
'----------------------------------------------------------------------
' Public Functions
'----------------------------------------------------------------------
Public Function DetailedErrors(bDetail)
' Turn on/off detailed errors
m_bDetailedError = bDetail
End Function
Public Function LogErrors(bLog)
' Turn on/off error logging
m_bLogErrors = bLog
End Function
Public Function LogError()
dim objFS, objTextFile
' Create File System Object and open error log for appending
set objFS = Server.CreateObject("Scripting.FileSystemObject")
set objTextFile = objFS.OpenTextFile(m_LogFile, 8, 1)
' Log the error
objTextFile.WriteLine Date & ", " & Err.number & ", " & Err.Description
' Clean up
objTextFile.Close
set objTextFile = Nothing
set objFS = Nothing
End Function
Public Function DisplayError()
dim m_strStandardError
' Only display the error is there was one.
If Err.Number <> 0 Then
' Set standard error message
m_strStandardError = "An error occurred while processing your request. Please try again.
" ' Check to see if they want detailed errors If m_bDetailedError = 1 Then m_strStandardError = m_strStandardError & "Error " & Err.Number & " produced by " & Err.Source & ": " & Err.Description & "
") Select Case msg Case "add" Response.Write (str_msg): Response.Write (" added successfully") Case "upd" Response.Write (str_msg): Response.Write (" updated successfully") Case "del" Response.Write (str_msg): Response.Write (" deleted successfully") End Select Response.Write ("
"): Response.Write (vbCrLf) session("msg") = "" End If End Sub '-------------------------------------------------------------------------- ' Check and display error messages '-------------------------------------------------------------------------- Sub checkErrs() Dim err_num: err_num = Session("err") session("err") = "" If NOT IsNull(err_num) AND err_num <> "" Then Response.Write (t(1)): Response.Write ("") Select Case err_num Case "000001": Response.Write ("Unable to connect to the database host or datasource") Case "000002": Response.Write ("The database record you wished to manipulate could not be found") Case "000003": Response.Write ("An error occurred during the update process") Case "000004": Response.Write ("An error occurred during the delete process") Case "000005": Response.Write ("Invalid record selection") Case "000007": Response.Write ("An error occurred during the insert process") Case "000008": Response.Write ("Invalid email address supplied") Case "000009": Response.Write ("If you remove this record, your site's administration will no longer function as expected") Case "000010": Response.Write ("Record insertion denied to avoid creating a duplicate entry") End Select Response.Write ("
"): Response.Write (vbCrLf) err_num = "" End If End Sub '-------------------------------------------------------------------------- ' Set error message and redirect '-------------------------------------------------------------------------- Sub throw_error(err_num, redirect_url) Session("err") = err_num Response.Redirect(redirect_url) End Sub '-------------------------------------------------------------------------- ' Set confirmation message and redirect '-------------------------------------------------------------------------- Sub confirm_action(str_msg, redirect_url) Session("msg") = str_msg Response.Redirect (redirect_url) End Sub '-------------------------------------------------------------------------- ' Display form errors '-------------------------------------------------------------------------- Sub output_errors(error_msgs) Response.Write ("
|