%@LANGUAGE="VBSCRIPT"%>
<%
'Option Explicit
Dim datToday 'date today
Dim intCurrentMonth 'month from system clock
Dim intCurrentYear 'year from system clock
Dim strSelectedMonth 'selected month from Form (if any)
Dim intSelectedYear 'selected year from Form (if any)
Dim strYear
Dim intFirstDay 'first day of the selected month
Dim strSQL 'SQL command string
Dim rsEvents 'the current recordset of events
Dim intDays 'number of days in the month
Dim varDayCount 'count for table formatting
Dim intStartBlanks 'number of blank squares needed for table start
Dim intEndBlanks 'number of blank squares needed for table end
Dim intID 'selected event ID number
'if first time page is displayed then show calendar for
'current month. Otherwise show selected month and years
'from Form menu
datToday = Date 'find current date
intCurrentYear = Year(datToday)
intCurrentMonth = Month(datToday)
If Request.Form.Count = 0 And Request.QueryString.Count = 0 Then 'first time of execution
intSelectedMonth = intCurrentMonth
intSelectedYear = intCurrentYear
intFirstDay = WeekDay("1/" & intCurrentMonth & "/" & intCurrentYear)
Else
'note: if called from self, will Request from Form object
'if called from other pages will get info from QueryString!
intSelectedMonth = Request("Month")
intSelectedYear = Request("Year")
intFirstDay = WeekDay("1/"& intSelectedMonth & "/" & intSelectedYear)
End If
' determine number of days in current month
intDays = DaysInMonth(MonthName(intSelectedMonth),intSelectedYear)
'create SQL command string
strSQL = "SELECT EventName, EventID, EventDay, EventStatus FROM tblEvents WHERE EventStatus <> 'Pending' AND EventMonth LIKE '" & intSelectedMonth & "'" &_
" AND EventYear LIKE '" & intSelectedYear & "' ORDER BY EventDay"
' create the recordset
set rsEvents = Server.CreateObject("ADODB.Recordset")
rsEvents.ActiveConnection = MM_connEvents_STRING
rsEvents.Source = strSQL
rsEvents.CursorType = 0
rsEvents.CursorLocation = 2
rsEvents.LockType = 3
rsEvents.Open()
'Format calendar
'Display calendar head
function goYear(intmonth, intyear, strdir)
if strdir = "for" then
if intmonth = 12 then
goYear = intyear+1
else
goYear = intyear
end if
else
if intmonth = 1 then
goYear = intyear-1
else
goYear = intyear
end if
end if
end function
function goMonth(intmonth)
if intmonth = 0 then
goMonth = 12
elseif intmonth = 13 then
goMonth = 1
else
goMonth = intmonth
end if
end function
%>
<%
' add events to calendar table
' calculate number of start and trailing blanks
intStartBlanks = intFirstDay-1
Select Case intDays
Case 31
intEndBlanks = 7 - (intFirstDay+2)
If intEndBlanks = -2 Then
intEndBlanks = intFirstDay + intEndBlanks
ElseIf intEndBlanks = -1 Then
intEndBlanks = intFirstDay
End If
Case 30
intEndBlanks = 7 - (intFirstDay+1)
If intEndBlanks < 0 Then
intEndBlanks = intFirstDay + intEndBlanks
End If
Case 29
intEndBlanks = 7 - intFirstDay
Case 28
intEndBlanks = 7 - (intFirstDay-1)
If intEndBlanks = 7 Then
intEndBlanks = 0
End If
End Select
varDayCount = 1
%>
<%
' write blanks to fill calendar
For i = 1 to intStartBlanks
%>
<%
Next
Do While varDayCount <= intDays
%>
<%= varDayCount %>
<%
If NOT rsEvents.EOF Then
Do While rsEvents("EventDay").Value = varDayCount
intID = rsEvents("EventID").Value
%>
"Cancelled" then response.write("class=""eventlinkout"" onMouseOver=""className='eventlinkover'"" onMouseOut=""className='eventlinkout'""") else response.write("class=""eventcancelledout"" onMouseOver=""className='eventcancelledover'"" onMouseOut=""className='eventcancelledout'""") end if%> onClick="window.open('show_event.asp?intID=<%= intID %>','NewWindow','scrollbars=YES,width=590,height=560')" height="25"><%= rsEvents("EventName") %>
<%
rsEvents.MoveNext
If rsEvents.EOF Then
Exit Do
End If
Loop
End If
%>
<%
If (varDayCount+intStartBlanks) Mod 7 = 0 And Not varDayCount = intDays Then
%>
<%
End If
varDayCount = varDayCount + 1
Loop 'Days
' write blanks to fill calendar
For i = 1 to intEndBlanks
%>
<%
Next
'close last row
%>
<%
'close recordset
rsEvents.Close
set rsEvents = Nothing
%>