<% class ASP_Calendar private p_chooser ' If the calendar will be used to select a date for a form private p_db_bind ' If the calendar will be databound by a database connection private p_db_conn ' A connection to a database private p_db_field ' The string name of the database field containing the calendar dates private p_db_table ' The string name of the database table containing the calendar dates private p_month ' The month to display private p_url ' The url to link to ' 1) the same page on which the calendar is displayed when scrollable is on ' 2) the page to link to when scrollable is off private p_year ' The year to display private p_selectable private p_scrollable ' If the calendar is scrollable links exist to change the month, otherwise the ' name of the month is a link to p_url and no scroll buttons are displayed private sub Class_Initialize() ' Initialize property values p_db_bind = false p_db_field = "" p_db_table = "" p_month = month(date()) p_year = year(date()) p_selectable = false p_scrollable = false end sub ' Draw method outputs html to the browser to display the calendar and dates public function draw(a_url) dim dates dates = "|" if p_db_bind then dim rs dim sql sql = "SELECT DISTINCT " & p_db_field & " FROM " & p_db_table & _ " WHERE MONTH(" & p_db_field & ") = '" & p_month & "' AND " & _ " YEAR(" & p_db_field & ") = '" & p_year & "'" p_db_conn.open() set rs = p_db_conn.execute(sql) while not rs.eof dates = dates & day(rs.fields(p_db_field)) & "|" rs.movenext wend p_db_conn.close() end if ' Exits the method if the month and year are not numeric or the month is out of range if not isnumeric(p_month) or not isnumeric(p_year) or p_month < 1 or p_month > 12 then response.Write "There was an error displaying the days for month number " & p_month & _ " for the year " & p_year exit function end if ' Exits the method if the requested month has passed if p_year < Year(Date()) then p_year = Year(Date) end if ' Exits the method if the requested month has passed if p_year = Year(Date()) and p_month < Month(Date()) then p_year = Year(Date) p_month = Month(Date) end if ' Assign url to calendar p_url = a_url ' Dimension variables dim cursor dim output dim row ' Initialize cursor to 1 cursor = 1 ' Initialize output string with calendar header output = "" & vbcr & get_header() ' Loop through each row of the calendar for row=1 to 6 output = output & "" dim col ' Loop through each column of the current row for col=1 to 7 output = output & "" next output = output & "" next output = output & "
" dim current_date current_date = DateSerial(p_year, p_month, cursor) ' Display the corrrect date for the day of the week if IsDate(current_date) and WeekDay(current_date) = col and Month(current_date) = p_month then dim cursor_output cursor_output = cursor if dates <> "|" and instr(dates, "|" & cursor & "|") > 0 then cursor_output = "" & cursor & "" end if output = output & cursor_output cursor = cursor + 1 end if output = output & "
" ' Return the output string draw = output end function ' Retrieves the header of the calendar private function get_header() ' Dim and initialize output string to return dim output output = "" dim eval eval = true if p_month = Month(Date()) and p_year = Year(Date()) then eval = false end if ' Display the link to scroll back if the calendar is scrollable and the current month is not being displayed if p_scrollable and eval then output = output & "<<" end if output = output & "  " ' Display the month and year as a link to another page if the calendar is not scrollable if not p_scrollable then output = output & "" end if output = output & "" & MonthName(p_month) & " " & p_year & "" if not p_scrollable then output = output & "" end if output = output & "  " if p_scrollable then output = output & ">>" end if output = output & "" & vbcr ' Return the output string get_header = output end function ' Method to retrieve all of the current query strings and adjust the month and year querystrings accordingly private function get_query_strings(direction) dim query_strings dim count count = 0 dim var for each var in request.QueryString dim separator if count = 0 then separator = "?" else separator = "&" end if if var <> "mo" and var <> "yr" and var <> "day" and var <> "s" then count = count + 1 query_strings = query_strings & separator & var & "=" & request.QueryString(var) end if next dim mo dim yr if p_month > 0 and p_month < 13 then mo = p_month + direction yr = p_year end if if p_month = 1 and direction = -1 then mo = 12 yr = p_year - 1 end if if p_month = 12 and direction = 1 then mo = 1 yr = p_year + 1 end if if query_strings = "" then query_strings = query_strings & "?mo=" & mo & "&yr=" & yr else query_strings = query_strings & "&mo=" & mo & "&yr=" & yr end if get_query_strings = query_strings end function public property let database_bind(a) p_db_bind = a end property public property let database_connection(a) set p_db_conn = a end property public property let database_field(a) p_db_field = a end property public property let database_table(a) p_db_table = a end property public property let set_month(a) p_month = a end property public property let scrollable(a) p_scrollable = a end property public property let set_year(a) p_year = a end property end class %>