<% Response.Buffer = true %>
<% 'Functions specific to this website %>
<%
if request("ViewDay") then
call DisplayDay()
else
call BuildCalendar()
end if
sub DisplayDay()
EventID = Request("EventID")
SQL = "Select Events.*, " & _
"DatePart('m',[StartDate]) & '/' & DatePart('d',[StartDate]) & '/' & DatePart('yyyy',[StartDate]) AS FrontStartDate, " & _
"DatePart('m',[EndDate]) & '/' & DatePart('d',[EndDate]) & '/' & DatePart('yyyy',[EndDate]) AS FrontEndDate, " & _
"DatePart('m',[EndDate]) as EndMonth, " & _
"DatePart('d',[EndDate]) as EndDay, " & _
"DatePart('yyyy',[EndDate]) as Endyear, " & _
"DatePart('m',[StartDate]) as StartMonth, " & _
"DatePart('d',[StartDate]) as StartDay, " & _
"DatePart('yyyy',[StartDate]) as Startyear, " & _
"DatePart('h',[StartDate]) & ':' & DatePart('n',[StartDate]) AS TimeStartDate " & _
"from Events where EventID=" & EventID
Set RSRecord = RunQuery(SQL)
%>
<%
if not RSRecord.eof then
FrontStartDate = RSRecord("FrontStartDate") & ""
FrontEndDate = RSRecord("FrontEndDate") & ""
StartMonth = RSRecord("StartMonth") & ""
StartDay = RSRecord("StartDay") & ""
Startyear = RSRecord("Startyear") & ""
EndMonth = RSRecord("EndMonth") & ""
EndDay = RSRecord("EndDay") & ""
Endyear = RSRecord("Endyear") & ""
StartDate = RSRecord("StartDate") & ""
NiceStartDate = FormatDateTime(CDate(StartDate),vbLongDate)
StartTime = replace(FormatDateTime(CDate(StartDate),vbLongTime),":00 "," ")
EndDate = RSRecord("EndDate") & ""
EndTime = replace(FormatDateTime(CDate(EndDate),vbLongTime),":00 "," ")
ShortTitle = RSRecord("ShortTitle")
FullTitle = RSRecord("FullTitle")
Speakers = RSRecord("Speakers")
Organization = RSRecord("Organization")
Address = RSRecord("Address")
City = RSRecord("City")
StateID = trim(GetSateAbbreviation(RSRecord("StateID")))
Zip = RSRecord("Zip")
URL = RSRecord("URL")
Contact = RSRecord("Contact")
Phone = RSRecord("Phone")
Fax = RSRecord("Fax")
Email = RSRecord("Email")
Category = RSRecord("Category")
Region = RSRecord("Region")
Location = RSRecord("Location")
Description = replace(RSRecord("Description"), CHR(10), " ")
Directions = RSRecord("Directions")
IsTBA = RSRecord("IsTBA")
IsNA = RSRecord("IsNA")
end if
Call CloseRecord(RSRecord)
call CloseConnection()
%>
<%=ShortTitle%>
<%=FullTitle%>
<%=Description%>
<%If not trim(Category) & "" = "" then%>
Type of Event:
<%=Category%>
<%end if
If not trim(Speakers) & "" = "" then%>
Speaker Name(s):
<%=Speakers%>
<%end if%>
Start Date/Time:
<%=Monthname(StartMonth)%> <%=StartDay%>, <%=StartYear%> at
<%
if (IsTBA <> 1) then
Response.Write LCase(StartTime)
else
Response.Write "TBA"
end if
%>
End Date/Time:
<%=Monthname(EndMonth)%> <%=EndDay%>, <%=EndYear%> at
<%
if (IsNA <> 1) then
Response.Write LCase(EndTime)
else
Response.Write "TBA"
end if
%>
<%If not trim(Region) & "" = "" then%>
Region:
<%=Region%>
<%end if%>
<%If not trim(Location) & "" = "" then%>
Event Location:
<%=Location%>
<%end if%>
<%If not trim(Directions) & "" = "" then%>
Directions:
<%=Directions%>
<%end if%>
Event Sponsors Contact Information
<%If not trim(Organization) & "" = "" then%>
Organization:
<%=Organization%>
<%end if%>
<%If not trim(Contact) & "" = "" then%>
Contact:
<%=Contact%>
<%end if%>
<%If not trim(Address) & "" = "" then%>
Address:
<%=Address%>
<%end if%>
<%=City%><%If not City & "" = "" then%>, <%end if%><%=StateID%> <%=Zip%>
'Footer
<%
end sub
sub BuildCalendar()
Dim dDate ' Date we're displaying calendar for
Dim iDIM ' Days In Month
Dim iDOW ' Day Of Week that month starts on
Dim iCurrent ' Variable we use to hold current day of month as we write table
Dim iPosition ' Variable we use to hold current position in table
' Get selected date. There are two ways to do this.
' First check if we were passed a full date in RQS("date").
' If so use it, if not look for seperate variables, putting them togeter into a date.
' Lastly check if the date is valid...if not use today
If IsDate(Request.QueryString("date")) Then
dDate = CDate(Request.QueryString("date"))
Else
If IsDate(Request.QueryString("month") & "-" & Request.QueryString("day") & "-" & Request.QueryString("year")) Then
dDate = CDate(Request.QueryString("month") & "-" & Request.QueryString("day") & "-" & Request.QueryString("year"))
Else
dDate = Date()
' The annoyingly bad solution for those of you running IIS3
If Len(Request.QueryString("month")) <> 0 Or Len(Request.QueryString("day")) <> 0 Or Len(Request.QueryString("year")) <> 0 Or Len(Request.QueryString("date")) <> 0 Then
Response.Write "The date you picked was not a valid date. The calendar was set to today's date.
"
End If
' The elegant solution for those of you running IIS4
'If Request.QueryString.Count <> 0 Then Response.Write "The date you picked was not a valid date. The calendar was set to today's date.
"
End If
End If
'Now we've got the date. Now get Days in the choosen month and the day of the week it starts on.
iDIM = GetDaysInMonth(Month(dDate), Year(dDate))
iDOW = GetWeekdayMonthStartsOn(dDate)
%>
<% 'call AddEvent()%>
<%
' Write spacer cells at beginning of first row if month doesn't start on a Sunday.
If iDOW <> 1 Then
Response.Write vbTab & "
" & vbCrLf
iPosition = 1
Do While iPosition < iDOW
Response.Write vbTab & vbTab & "
" & vbCrLf
iPosition = iPosition + 1
Loop
End If
' Write days of month in proper day slots
iCurrent = 1
iPosition = iDOW
Do While iCurrent <= iDIM
' If we're at the begginning of a row then write TR
If iPosition = 1 Then
Response.Write vbTab & "
" & vbCrLf
End If
StartSearchDate = Month(dDate) & "-" & iCurrent & "-" & Year(dDate) & " 11:59:59 PM"
EndSearchDate = Month(dDate) & "-" & iCurrent & "-" & Year(dDate) & " 12:00 AM"
SQL = "Select ShortTitle, EventID from Events where StartDate <= #" & StartSearchDate & "# and EndDate >= #" & EndSearchDate & "#"
'Response.Write (SQL)
Set EventsRS = RunQuery(SQL)
EventsList = ""
While not EventsRS.eof
EventsList = EventsList & "" & EventsRS("ShortTitle") & " "
EventsRS.movenext
wend
' If the day we're writing is the selected day then highlight it somehow.
If iCurrent = Day(dDate) Then
Response.Write vbTab & vbTab & "
" & iCurrent & "
" & EventsList & "
" & vbCrLf
Else
Response.Write vbTab & vbTab & "
" & iCurrent & " " & EventsList & "
" & vbCrLf
End If
' If we're at the endof a row then write /TR
If iPosition = 7 Then
Response.Write vbTab & "
" & vbCrLf
iPosition = 0
End If
' Increment variables
iCurrent = iCurrent + 1
iPosition = iPosition + 1
Loop
' Write spacer cells at end of last row if month doesn't end on a Saturday.
If iPosition <> 1 Then
Do While iPosition <= 7
Response.Write vbTab & vbTab & "
" & vbCrLf
iPosition = iPosition + 1
Loop
Response.Write vbTab & "" & vbCrLf
End If
%>
<%
end sub
Sub AddEvent()
If request("Action") = "AddNewEvent" then
If IsDate(Request.QueryString("Addmonth") & "-" & Request.QueryString("Addday") & "-" & Request.QueryString("Addyear")) Then
RelatedDate = CDate(Request.QueryString("Addmonth") & "-" & Request.QueryString("Addday") & "-" & Request.QueryString("Addyear"))
Title = replace(request("Title"),"'","''")
Description = replace(request("Description"),"'","''")
SQL = "Insert into Events (RelatedDate,Title,Description) Values (#" & RelatedDate & "#, '" & Title & "', '" & Description & "')"
Set EmptyRS = RunQuery(SQL)
%>
Your Event Was Added!
<%
Else
' The annoyingly bad solution for those of you running IIS3
If Len(Request.QueryString("Addmonth")) <> 0 Or Len(Request.QueryString("Addday")) <> 0 Or Len(Request.QueryString("Addyear")) <> 0 Or Len(Request.QueryString("date")) <> 0 Then
Response.Write "The date you picked was not a valid date. The event was not added.
"
End If
' The elegant solution for those of you running IIS4
'If Request.QueryString.Count <> 0 Then Response.Write "The date you picked was not a valid date. The calendar was set to today's date.
"
End If
end if
end sub
Sub DatePicker()
%>
<%
end Sub
%><%
'*******************************************************
'* ASP 101 Sample Code - http://www.asp101.com/ *
'* *
'* This code is made available as a service to our *
'* visitors and is provided strictly for the *
'* purpose of illustration. *
'* *
'* http://www.asp101.com/samples/license.asp *
'* *
'* Please direct all inquiries to webmaster@asp101.com *
'*******************************************************
%><%
' ***Begin Function Declaration***
' New and improved GetDaysInMonth implementation.
' Thanks to Florent Renucci for pointing out that I
' could easily use the same method I used for the
' revised GetWeekdayMonthStartsOn function.
Function GetDaysInMonth(iMonth, iYear)
Dim dTemp
dTemp = DateAdd("d", -1, DateSerial(iYear, iMonth + 1, 1))
GetDaysInMonth = Day(dTemp)
End Function
' Previous implementation on GetDaysInMonth
'Function GetDaysInMonth(iMonth, iYear)
' Select Case iMonth
' Case 1, 3, 5, 7, 8, 10, 12
' GetDaysInMonth = 31
' Case 4, 6, 9, 11
' GetDaysInMonth = 30
' Case 2
' If IsDate("February 29, " & iYear) Then
' GetDaysInMonth = 29
' Else
' GetDaysInMonth = 28
' End If
' End Select
'End Function
Function GetWeekdayMonthStartsOn(dAnyDayInTheMonth)
Dim dTemp
dTemp = DateAdd("d", -(Day(dAnyDayInTheMonth) - 1), dAnyDayInTheMonth)
GetWeekdayMonthStartsOn = WeekDay(dTemp)
End Function
Function SubtractOneMonth(dDate)
SubtractOneMonth = DateAdd("m", -1, dDate)
End Function
Function AddOneMonth(dDate)
AddOneMonth = DateAdd("m", 1, dDate)
End Function
' ***End Function Declaration***
%>