|
|
<%
'==========================================
'Global variables
Call dbConnect'Connect to the database
Dim strAction
strAction = Request.QueryString("action")
Dim strFont, strStartFont, strEndFont
strFont = "arial"
strStartFont = ""
strEndFont = ""
Dim strFormQuery
'Local scoped variables
Dim strTemp_form_date, strTemp_form_subject, strTemp_form_message
Dim strTemp_form_firstName, strTemp_form_lastName, strTemp_form_email
'==========================================
'==========================================
'Function for adding a new comment to the database
sub addComment
strTemp_form_date = month(date) & "/" & day(date) & "/" & year(date) & " " & Time
validateForm()
Set dbRecordSet = Server.CreateObject("ADODB.Recordset")
dbRecordSet.Open "comments", strConnect, adOpenStatic, adLockOptimistic, adCmdTable
dbRecordSet.AddNew
dbRecordSet("subject") = strTemp_form_subject
dbRecordSet("message") = strTemp_form_message
dbRecordSet("firstName") = strTemp_form_firstName
dbRecordSet("lastName") = strTemp_form_lastName
dbRecordSet("email") = strTemp_form_email
dbRecordSet.Update
dbRecordSet.Close
Set dbRecordSet = Nothing
notifyAdministrator()
end sub
'==========================================
'ADMINISTRATIVE NOTIFICATION FUNCTIONS
'==========================================
sub notifyAdministrator
'send mail
Dim administrators
administrators = "fred.wright@dot.state.fl.us,joe.montalto@lochrane.com,anna@lw.net"
'administrators = "dave@lw.net"
Dim mailObj
set mailObj = Server.CreateObject("CDONTS.NewMail")
mailObj.BodyFormat = 0
mailObj.MailFormat = 0
mailObj.From = strTemp_form_firstName & " " & strTemp_form_lastName & "<" & strTemp_form_email & ">"
mailObj.To = administrators
mailObj.Subject = "I-75 Project Comment (" & strTemp_form_subject & ")"
mailObj.Body = strTemp_form_message & vbCrLf & vbCrLf &_
strTemp_form_firstName & " " & strTemp_form_lastName & vbCrLf &_
strTemp_form_email
mailObj.Send
Set mailObj = Nothing
end sub
'==========================================
'==========================================
'Check and validate contents of form
sub validateForm
strTemp_form_subject = Request.Form("subject")
strTemp_form_message = Request.Form("message")
strTemp_form_firstName = Request.Form("firstName")
strTemp_form_lastName = Request.Form("lastName")
strTemp_form_email = Request.Form("email")
If strTemp_form_subject = " " Then
strTemp_form_subject = "No Subject"
End If
If strTemp_form_message = " " Then
strTemp_form_message = "This message is blank"
End If
'If strTemp_form_firstName = " " Then
' strTemp_form_firstName = "No first name given"
'End If
'If strTemp_form_lastName = " " Then
' strTemp_form_lastName = "No last name given"
'End If
If strTemp_form_email = " " Then
strTemp_form_email = "admin@lw.net"
End If
end sub
'==========================================
'==========================================
'Main router for actions
Select Case strAction
Case "addComment"
addComment()
End Select
'==========================================
'==========================================
'Decide what kind of page to display (list, or individual message)
Dim strDisplayType
strDisplayType = Request.QueryString("displayType")
If strDisplayType = "message" Then
'Set up any variable only needed for message display
Else
'Default behaviour
strDisplayType = "list"
End If
strFormQuery = strFormQuery & "&displayType=" & strDisplayType
'==========================================
'==========================================
'Get total number of messages from database
Dim intRecordCount
dbOpenRecordSet("SELECT COUNT(*) AS recCount FROM comments")
intRecordCount = CInt(dbRecordSet("recCount"))
dbCloseRecordSet()
'==========================================
%>
<%=intRecordCount%> Comment
<% if intRecordCount > 1 then Response.Write "s"
'==========================================
Dim strTemp_id, strTemp_date, strTemp_subject, strTemp_message
Dim strTemp_firstName, strTemp_lastName, strTemp_email
'==========================================
'==========================================
'If default behaviour then display the list of
'comments one page at a time
If strDisplayType = "list" Then
'==========================================
'Get basic information about the page
Dim intDisplayCount, intStartIndex, intPageNum
intDisplayCount = 10 'Default value, this may become a selectable option
intStartIndex = Request.QueryString("startIndex")
intPageNum = Request.QueryString("pageNum")
'==========================================
'==========================================
'Open recordset
Set dbRecordSet = Server.CreateObject("ADODB.Recordset")
dbRecordSet.Open "comments", strConnect, adOpenStatic, adLockOptimistic, adCmdTable
'==========================================
'==========================================
'Determine correct starting point in the recordset
If intStartIndex AND intStartIndex > 0 Then
dbRecordSet.Find "id=" & intStartIndex
ElseIf Not dbRecordSet.EOF AND Not dbRecordSet.BOF Then
dbRecordSet.MoveLast
intStartIndex = 0
End If
strFormQuery = strFormQuery & "&startIndex=" & intStartIndex & "&pageNum=" & intPageNum
'==========================================
'==========================================
'Variables needed for dealing with this recordsets fields
Dim strMessageList
'==========================================
'==========================================
'Prepare the top of the table
strMessageList = strMessageList &_
"" & vbCrLf
'==========================================
'==========================================
'Loop through the record set and prepare output for list
Dim intCountIndex
For intCountIndex = 1 to intDisplayCount
If Not dbRecordSet.EOF AND Not dbRecordSet.BOF Then
strTemp_id = dbRecordSet("id")
strTemp_date = dbRecordSet("date")
strTemp_subject = dbRecordSet("subject")
strTemp_message = dbRecordSet("message")
strTemp_firstName = dbRecordSet("firstName")
strTemp_lastName = dbRecordSet("lastName")
strTemp_email = dbRecordSet("email")
strMessageList = strMessageList &_
"" & vbCrLf &_
"| | " & vbCrLf &_
"" & strStartFont & strTemp_subject & strEndFont & " | " & vbCrLf &_
" " & vbCrLf &_
"" & vbCrLf &_
"| | " & vbCrLf &_
"" & vbCrLf &_
strStartFont & strTemp_date & " " & strTemp_firstName & " " & strTemp_lastName & strEndFont & vbCrLf &_
" | " & vbCrLf &_
" " & vbCrLf
dbRecordSet.MovePrevious
End If
Next
Dim strNextPageStart, strPrevPageStart
If Not dbRecordSet.EOF AND Not dbRecordSet.BOF Then
strNextPageStart = dbRecordSet("id")
Else
strNextPageStart = 0
End If
dbRecordSet.Close
Set dbRecordSet = Nothing
'==========================================
'==========================================
'Prepare the bottom of the table
strMessageList = strMessageList & " " & vbCrLf
'==========================================
'==========================================
'Set up page navigation for next/previous page
Dim strPageNavigation
strPageNavigation = strPageNavigation &_
"" & vbCrLf &_
"" & vbCrLf &_
"| " & vbCrLf
If intStartIndex > 0 Then
strPrevPageStart = intStartIndex + intDisplayCount
If strPrevPageStart <= intRecordCount Then
strPageNavigation = strPageNavigation &_
"Previous Page "
End If
End If
If strNextPageStart > 0 Then
strPageNavigation = strPageNavigation &_
"Next Page "
End If
strPageNavigation = strPageNavigation &_
" | " & vbCrLf &_
" " & vbCrLf &_
" " & vbCrLf
'==========================================
strMessageList = strPageNavigation & strMessageList & strPageNavigation
Response.Write strMessageList
End If
'==========================================
'==========================================
If strDisplayType = "message" Then
Dim strId
strId = Request.QueryString("id")
strFormQuery = strFormQuery & "&id=" & strId
dbOpenRecordSet("SELECT * FROM comments WHERE id=" & strId)
strTemp_date = dbRecordSet.Fields(1)
strTemp_subject = dbRecordSet.Fields(2)
strTemp_message = dbRecordSet.Fields(3)
strTemp_firstName = dbRecordSet.Fields(4)
strTemp_lastName = dbRecordSet.Fields(5)
strTemp_email = dbRecordSet.Fields(6)
dbCloseRecordSet()
Dim strMessageTable
strMessageTable = strMessageTable &_
"" & vbCrLf &_
"" & vbCrLf &_
"| " & vbCrLf &_
"Subject: " & strTemp_subject & " " & strTemp_date & vbCrLf &_
" | " & vbCrLf &_
" " & vbCrLf &_
"" & vbCrLf &_
"" & vbCrLf &_
"Comment: " & vbCrLf &_
strTemp_message & vbCrLf &_
" | " & vbCrLf &_
" " & vbCrLf &_
"" & vbCrLf &_
"| " & vbCrLf &_
"Submitted By: " & strTemp_firstName & " " & strTemp_lastName & vbCrLf &_
" | " & vbCrLf &_
" " & vbCrLf &_
" " & vbCrLf
'==========================================
'==========================================
'Back Button
Dim strBackButton
Dim temp_startIndex, temp_pageNum
temp_startIndex = Request.QueryString("startIndex")
temp_pageNum = Request.QueryString("pageNum")
strBackButton = strBackButton &_
"Back "
strMessageTable = strBackButton & strMessageTable
'==========================================
Response.Write strMessageTable
End If
'==========================================
%>
|
|
|
|
|
 |