appreciate it!
I need to build a calendar page that displays available/unavailable
info from a DB and colour a cell according to that info, but somewhere
I've gone completely off the rails! Basically it is a room
availability page for an intranet and should simply colour a calendar
cell red if the room is booked, or green if it isn't. Rooms are
typically booked by lecturers for multiple days or even weeks, so only
the start and end dates are entered into the calendar.
My code doesn't get all the info and I'm pulling hair out with
frustration!
Anyway, here's the code:
<!--#include file = "datacon.asp"-->
<%CODEPAGE="1252"
Dim MyMonth 'Month of calendar
Dim MyYear 'Year of calendar
Dim FirstDay 'First day of the month. 0 = Sunday
Dim CurrentDay 'Used to print dates in calendar - Day only, otherwise
same as varDateNow
Dim Col 'Calendar column
Dim Row 'Calendar row
'======
Dim RoomCI 'Start booking
Dim RoomCO 'End booking
Dim varBackground 'cell background colour
Dim varDateNow 'Current full date ---Not actual date, but date
calendar cell is working with
Dim var1stBack
MyMonth = cint(Request.Querystring("Month"))
MyYear = cint(Request.Querystring("Year"))
If MyMonth = 0 then MyMonth = Month(Date)
if MyYear = 0 then MyYear = Year(Date)
Call ShowHeader (MyMonth, MyYear)
FirstDay = WeekDay(DateSerial(MyYear, MyMonth, 1)) -1
CurrentDay =
1 '--------------------------------------------------------------------------------
>Start CurrentDay on 1'=================================
varDateNow = Trim(Currentday) & "/" & Trim(MyMonth) & "/" &
Trim(MyYear)
varDateNow = CDate(varDateNow)
'=================================
Dim var1stDay
var1stDay = "01" & "/" & Trim(MyMonth) & "/" & Trim(MyYear) 'We need
to start looking at the 1st of the month
var1stDay=CDate(var1stDay) 'Change the variable to a proper date
'Let's build the calendar
dim varCDay
varBackground = "green" 'Default starting background colour
For Row = 0 to 5
rscal = ""
rsCal1 = ""
For Col = 0 to 6
If Row = 0 and Col < FirstDay then
response.write "<td> </td>"
elseif CurrentDay LastDay(MyMonth, MyYear) then
response.write "<td> </td>"
else
'================================================= =======
'This section formats varDateNow
Dim varCurrentDay 'CurrentDay reformatted to always have 2 char's
Dim TotalDays
Dim TotalDate
Dim HouseName
'=====================================
If CurrentDay < 10 and MyMonth >= 10 then varDateNow = "0" &
Trim(Currentday) & "/" & Trim(MyMonth) & "/" & Trim(MyYear)
If CurrentDay < 10 and MyMonth < 10 then varDateNow = "0" &
Trim(Currentday) & "/" & "0" & Trim(MyMonth) & "/" & Trim(MyYear)
If CurrentDay =10 and MyMonth < 10 then varDateNow =
Trim(Currentday) & "/" & "0" & Trim(MyMonth) & "/" & Trim(MyYear)
If CurrentDay >= 10 and MyMonth >=10 then varDateNow =
Trim(Currentday) & "/" & Trim(MyMonth) & "/" & Trim(MyYear)
'If CurrentDay < 10 then CurrentDay = "0" & CurrentDay
varDateNow = CDATE(VarDateNow)
'''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''''''''''''''''''''''' '''''''
'response.write "varDateNow = " & varDateNow & "<br>"
'''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''''''''''''''''''''''' '''''''
set rsCal = cnndata.Execute("SELECT codate, cidate FROM tblReservation
WHERE cidate >= '" & varDateNow & "' AND room ='ICT-01'")
If Not rsCal.EOF then RoomCI = rscal("cidate")
If Not rsCal.EOF then RoomCO = rscal("codate")
RoomCI = CDATE(RoomCI)
RoomCO = CDATE(RoomCO)
varDateNow = CDATE(varDateNow)
If RoomCO = varDateNow AND RoomCI < varDateNow THEN varBackground =
"green"
If RoomCI = varDateNow then varBackground = "red"
If Not rsCal.EOF then RoomCI = rscal("cidate")
RoomCI = CDATE(RoomCI)
RoomCO = CDATE(RoomCO)
If Not rsCal.EOF then rsCal.MoveNext
'''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''''''''''''''''''''''' '''''''
'================================================
response.write "<td bgcolor='" & varBackground & "'"
if MyMonth = Month(Date) and CurrentDay = Day(Date) then
response.write " align='center'>"
else
response.write " align='center'>"
end if
'Print the day date number and bold on selected date
if request("selecteddate") = "" Then
if CurrentDay = day(date) Then
response.write "" & CurrentDay & ""
else
response.write "<font=Arial>" & CurrentDay & "</font>" 'This is
the line that writes the days to the calendar
end if
else
if day(request("selecteddate")) = CurrentDay Then
response.write "" & "<font=Arial>" & CurrentDay & "</font>" & ""
else
response.write CurrentDay
end if
end if
response.write "</a></td>"
CurrentDay = CurrentDay + 1
End If
Next
response.write "</tr>"
Next
response.write "</table>"
'------ Sub and functions
Sub ShowHeader(MyMonth,MyYear)
%>
<body>
<table cellspacing='1' cellpadding='0' width='35%' border="1"
bordercolor="#800000">
<tr align='center'>
<td colspan='7'>
<table border='0' width='100%'>
<tr>
<td align='left'>
<font face="Tahoma" color="black">
<%
response.write "<font face='Tahoma' color='black'><a href = '" &
Request.ServerVariables("SCRIPT_NAME") & "?"
if MyMonth - 1 = 0 then
response.write "month=12&year=" & MyYear -1
else
response.write "month=" & MyMonth - 1 & "&year=" & MyYear
end if
response.write "'><<</a>"
%>
</font>
</td><td align='center' class='ListHeaderTable'>
<%
response.write "<b><font face='Tahoma' color='black'>" &
MonthName(MyMonth) & " " & MyYear & "</font></b>"
%>
</font>
</td><td align='right'>
<%
response.write "<font face='Tahoma' color='black'><a href = '" &
Request.ServerVariables("SCRIPT_NAME") & "?"
if MyMonth + 1 = 13 then
response.write "month=1&year=" & MyYear + 1
else
response.write "month=" & MyMonth + 1 & "&year=" & MyYear
end if
response.write "'>>></a>"
%>
</font>
</td></tr></table>
</td>
</tr>
<tr align='center'>
<td width="8%" ><font color="#800000" face="Tahoma"><b><i>Sun</i></
b></font></td>
<td width="8%" ><font color="#800000" face="Tahoma"><b><i>Mon</i></
b></font></td>
<td width="8%" ><font color="#800000" face="Tahoma"><b><i>Tue</i></
b></font></td>
<td width="8%" ><font color="#800000" face="Tahoma"><b><i>Wed</i></
b></font></td>
<td width="8%" ><font color="#800000" face="Tahoma"><b><i>Thu</i></
b></font></td>
<td width="8%" ><font color="#800000" face="Tahoma"><b><i>Fri</i></
b></font></td>
<td width="8%" ><font color="#800000" face="Tahoma"><b><i>Sat</i></
b></font></td>
</tr>
</body>
<%
End Sub
Function MonthName(MyMonth)
Select Case MyMonth
Case 1
MonthName = "January"
Case 2
MonthName = "Febuary"
Case 3
MonthName = "March"
Case 4
MonthName = "April"
Case 5
MonthName = "May"
Case 6
MonthName = "June"
Case 7
MonthName = "July"
Case 8
MonthName = "August"
Case 9
MonthName = "September"
Case 10
MonthName = "October"
Case 11
MonthName = "November"
Case 12
MonthName = "December"
Case Else
MonthName = "ERROR! - Monthname"
End Select
End Function
Function LastDay(MyMonth, MyYear)
' Returns the last day of the month. Takes into account leap years
' Usage: LastDay(Month, Year)
' Example: LastDay(12,2000) or LastDay(12) or Lastday
Select Case MyMonth
Case 1, 3, 5, 7, 8, 10, 12
LastDay = 31
Case 4, 6, 9, 11
LastDay = 30
Case 2
If IsDate(MyYear & "-" & MyMonth & "-" & "29") Then
LastDay = 29 Else LastDay = 28
Case Else
LastDay = 0
End Select
End Function
%>