<%option explicit%> [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] <% '********************************************** 'TITLE: CALENDAR.ASP 'AUTHOR: ANDY EARNEST 'PURPOSE: This page shows the calendar for each month. It connects to the database ' to pull back a listing of events that match the current month and puts each one in the ' corresponding day. The calendar is limited by space, so the titles of each event "add event page" ' have a size limit so that they don't screw up the overall look of the page. 'REVISIONS: 'LTR DATE AUTHOR PURPOSE 'A 1/19/04 AE changed the date format for SQL from mm/dd/yyyy to yyyy-mm-dd because the queries ' weren't pulling back the info. Not sure why no longer working. Hosting company ' may have updated MYSQL to 5.0.' '********************************************** Response.buffer = false 'Check user's rights getSession() 'checkSession() 'no check session since non admins can look at this page DIM rs,datToday,intThisYear,strMonthName,datFirstDay,intLastday DIM intPrevMonth,intPrevYear,lastMonthDay,lastMonthYear DIM intNextYear,intPrintDay,LastMonthDate DIM dFirstDay,dLastDay,NextMonthDate DIM sSQL,sScript,intThisMonth,intFirstWeekDay,intNextMonth,intLastMonth DIM EndRows,intLoopDay,dToday,bEvents,sEvent Dim Start_Time,End_Time,Daily_Start_Time,Daily_End_Time '------------------------------------------------------------ ' This function finds the last date of the given month '------------------------------------------------------------ Function GetLastDay(intMonthNum, intYearNum) Dim dNextStart If CInt(intMonthNum) = 12 Then dNextStart = CDate( "1/1/" & intYearNum) Else dNextStart = CDate(intMonthNum + 1 & "/1/" & intYearNum) End If GetLastDay = Day(dNextStart - 1) End Function '------------------------------------------------------------------------- ' This routine prints the individual table divisions for days of the month '------------------------------------------------------------------------- Sub Write_TD(sValue, sClass) Response.Write " " & sValue & "" & vbCrLf 'Response.Write " " & _ ' "" & _ ' " " & vbCrLf End Sub ' Constants for the days of the week Const cSUN = 1, cMON = 2, cTUE = 3, cWED = 4, cTHU = 5, cFRI = 6, cSAT = 7 ' Get the name of this file sScript = Request.ServerVariables("SCRIPT_NAME") ' Check for valid month input If IsEmpty(Request("MONTH")) OR NOT IsNumeric(Request("MONTH")) Then datToday = Date() intThisMonth = Month(datToday) ElseIf CInt(Request("MONTH")) < 1 OR CInt(Request("MONTH")) > 12 Then datToday = Date() intThisMonth = Month(datToday) Else intThisMonth = CInt(Request("MONTH")) End If ' Check for valid year input If IsEmpty(Request("YEAR")) OR NOT IsNumeric(Request("YEAR")) Then datToday = Date() intThisYear = Year(datToday) Else intThisYear = CInt(Request("YEAR")) End If strMonthName = MonthName(intThisMonth) datFirstDay = DateSerial(intThisYear, intThisMonth, 1) intFirstWeekDay = WeekDay(datFirstDay, vbSunday) intLastDay = GetLastDay(intThisMonth, intThisYear) ' Get the previous month and year intPrevMonth = intThisMonth - 1 If intPrevMonth = 0 Then intPrevMonth = 12 intPrevYear = intThisYear - 1 Else intPrevYear = intThisYear End If ' Get the next month and year intNextMonth = intThisMonth + 1 If intNextMonth > 12 Then intNextMonth = 1 intNextYear = intThisYear + 1 Else intNextYear = intThisYear End If ' Get the last day of previous month. Using this, find the sunday of ' last week of last month LastMonthDate = GetLastDay(intLastMonth, intPrevYear) - intFirstWeekDay + 2 NextMonthDate = 1 ' Initialize the print day to 1 intPrintDay = 1 ' Open a record set of schedules Set Rs = Server.CreateObject("ADODB.RecordSet") ' These dates are used in the SQL ' UPDATE: Turns out the SQL wants the date format in "YYYY-MM-DD" 'OLD DATE CODE (PRE-2004) 'dFirstDay = intThisMonth & "/1/" & intThisYear 'dLastDay = intThisMonth & "/" & intLastDay & "/" & intThisYear 'NEW DATE CODE dFirstDay = intThisYear & "-" & intThisMonth & "-01" dLastDay = intThisYear & "-" & intThisMonth & "-" & intLastDay sSQL = "SELECT DISTINCT EventID,title, starttime, endtime FROM events WHERE " & _ "(starttime >='" & dFirstDay & "' AND starttime <= '" & dLastDay & "') " & _ "OR " & _ "(endtime >='" & dFirstDay & "' AND endtime <= '" & dLastDay & "') " & _ "OR " & _ "(starttime < '" & dFirstDay & "' AND endtime > '" & dLastDay & "' ) " & _ "ORDER BY starttime" 'USE THIS TO PRINT OUT THE SQL STATEMENT TO THE PAGE FOR DEBUGGING 'Response.Write sSQL openConnection() if connectionstate() = true then ' Open the RecordSet with a static cursor. This cursor provides bi-directional navigation Rs.Open sSQL, oConn, adOpenStatic, adLockReadOnly, adCmdText else response.redirect "error.asp?code=database" end if %> Schedule for <% = strMonthName & " " & intThisYear %> [an error occurred while processing this directive]
sValue & "
<% ' Initialize the end of rows flag to false EndRows = False Response.Write vbCrLf ' Loop until all the rows are exhausted Do While EndRows = False ' Start a table row Response.Write " " & vbCrLf ' This is the loop for the days in the week For intLoopDay = cSUN To cSAT ' If the first day is not sunday then print the last days of previous month in grayed font If intFirstWeekDay > cSUN Then Write_TD LastMonthDate, "NON" LastMonthDate = LastMonthDate + 1 intFirstWeekDay = intFirstWeekDay - 1 ' The month starts on a sunday Else ' If the dates for the month are exhausted, start printing next month's dates ' in grayed font If intPrintDay > intLastDay Then Write_TD NextMonthDate, "NON" NextMonthDate = NextMonthDate + 1 EndRows = True Else ' If last day of the month, flag the end of the row If intPrintDay = intLastDay Then EndRows = True End If dToday = CDate(intThisMonth & "/" & intPrintDay & "/" & intThisYear) If NOT Rs.EOF Then ' Set events flag to false. This means the day has no event in it bEvents = False Do While NOT Rs.EOF AND bEvents = False ' If the date falls within the range of dates in the recordset, then ' the day has an event. Make the events flag True ' need to remove time time stamps from the Event Times Start_Time = CDate(Month(rs("starttime")) & "/" & Day(rs("starttime")) & "/" & Year(rs("starttime"))) End_Time = CDate(Month(rs("endtime")) & "/" & Day(rs("endtime")) & "/" & Year(rs("endtime"))) If dToday >= Start_Time AND dToday <= End_Time Then Response.Write "" bEvents = True ElseIf dToday < Start_Time Then ' If the Start date is greater than the date itself, there is no point ' checking other records. Exit the loop Exit Do ' Move to the next record Else Rs.MoveNext End If Loop ' Checks for that day Rs.MoveFirst End If ' If the event flag is not raise for that day, print it in a plain font If bEvents = False Then Write_TD " " & intPrintDay & "", "SOME" End If End If ' Increment the date. Done once in the loop. intPrintDay = intPrintDay + 1 End If ' Move to the next day in the week Next Response.Write " " & vbCrLf Loop Rs.Close Set Rs = Nothing %>
Previous Month <% = strMonthName & " " & intThisYear %> Next Month
S M T W T F S
" & vbCrLf RESPONSE.WRITE " " & intPrintDay & "" RESPONSE.Write " " DO WHILE NOT RS.EOF Daily_Start_Time = CDate(Month(rs("starttime")) & "/" & Day(rs("starttime")) & "/" & Year(rs("starttime"))) Daily_End_Time = CDate(Month(rs("endtime")) & "/" & Day(rs("endtime")) & "/" & Year(rs("endtime"))) IF ((dToday = Daily_Start_Time OR dToday=Daily_End_Time) OR (dToday >= Daily_Start_Time AND dToday <= Daily_End_Time)) THEN 'IF event occurs on that day, write out title RESPONSE.WRITE " " RS.MOVENEXT ELSEif dToday < Start_Time THEN Exit DO ELSE RS.MOVENEXT END IF 'RS.MOVENEXT LOOP RESPONSE.WRITE "
" & rs("title") & "
" RESPONSE.WRITE "
[an error occurred while processing this directive]