Out of the following code can anyone explain or (even better) show the code that would allow me to show filled event dates
as "booked" on the calander rather than eventName as it is now...and also to show dates not booked as "Available"?
The booked dates when clicked will go to a details page, and available dates to a booking form.
I am just learning asp (but need this for my own site) and feel this might be a bit advanced for me so I would very much appreciate any help.
Here is the code: (the whole app can be found here:
http://www22.brinkster.com/akira1976/ (access version))
<%Option Explicit
'U.K.
'session.LCID = 2057
'Declare all necessary variables here
Dim dateFormat
Dim http,image,path,imagePath,sql
Dim x,xx,xxx,y,yy,yyy,num,x1,x2
Dim lastDay,curMonth,curDay,curYear,eventType
Dim searchEnd,searchStart,currentDay,maxRows
Dim today,todayCell,events,eventsID
Dim cn_connection,rs_getEvent,rs_getType
Dim eventID(),eventName(),curDate
Dim dayCell
Dim bg1,bg2,bg3,fnt1,fnt2,cell_width1,cell_height1,cel l_width2,cell_height2
%>
<!--#include file="global.asp"-->
<!--#include file="getparameter.asp"-->
<!--#include file="schema.asp"-->
<%
'================================================= ================================================== =======
'absorb date format difference
'================================================= ================================================== =======
'************************************************* ********
'* Change DateFormat value according to your Date format *
'* MM/DD = 1 *
'* DD/MM = 2 *
'************************************************* ********
dateFormat = 2
if dateFormat = 1 then
'search for valid date (2/31/2001 -> 2/28/2001)
while not isDate(curMonth & "/" & curDay & "/" & curYear)
curDay = curDay - 1
wend
'look for lasy day number of the current month
searchEnd = 31
while not isDate(curMonth & "/" & searchEnd & "/" & curYear)
searchEnd = searchEnd - 1
wend
'searchStart is the first day of month
'searchEnd is the last day of month
searchStart = cdate(curMonth & "/1/" & curYear)
searchEnd = cdate(curMonth & "/" & searchEnd & "/" & curYear)
else
'search for valid date (31/2/2001 -> 28/2/2001)
while not isDate(curDay & "/" & curMonth & "/" & curYear)
curDay = curDay - 1
wend
'look for lasy day number of the current month
searchEnd = 31
while not isDate(searchEnd & "/" & curMonth & "/" & curYear)
searchEnd = searchEnd - 1
wend
'searchStart is the first day of month
'searchEnd is the last day of month
searchStart = cdate("1/" & curMonth & "/" & curYear)
searchEnd = cdate(searchEnd & "/" & curMonth & "/" & curYear)
end if
%><!--#include file="connect.asp"--><%
'================================================= ================================================== =======
'Get event for a month
'================================================= ================================================== =======
sql = "SELECT id, startDate, endDate, name FROM calendarEvent " & _
"WHERE ((startDate >= #" & searchStart & "# AND endDate <= #" & searchEnd & "#) " & _
"OR (startDate < #" & searchStart & "# AND endDate >= #" & searchStart & "# AND endDate <= #" & searchEnd & "#) " & _
"OR (startDate <= #" & searchEnd & "# AND startDate >= #" & searchStart & "# AND endDate > #" & searchEnd & "#) " & _
"OR (startDate < #" & searchStart & "# AND endDate > #" & searchEnd & "#)) "
if trim(eventType) = "" then
'ignore it
elseif cint(eventType) = 1 then
sql = sql & "AND eventType = 1"
elseif cint(eventType) = 2 then
sql = sql & "AND eventType = 2"
elseif cint(eventType) = 3 then
sql = sql & "AND eventType = 3"
elseif cint(eventType) = 4 then
sql = sql & "AND eventType = 4"
elseif cint(eventType) = 5 then
sql = sql & "AND eventType = 5"
elseif cint(eventType) = 6 then
sql = sql & "AND eventType = 6"
elseif cint(eventType) = 7 then
sql = sql & "AND eventType = 7"
elseif cint(eventType) = 8 then
sql = sql & "AND eventType = 8"
else
'sql = sql & "AND eventType = 7"
'ignore it
end if
Set rs_getEvent = cn_Connection.Execute(sql)
%><%'response.write("sql = " & sql & "<br>")%><%
sql = "SELECT id, eventType FROM eventType"
Set rs_getType = cn_Connection.Execute(sql)
curDate = searchStart
for x = 1 to day(searchEnd)
redim preserve eventID(x)
redim preserve eventName(x)
if not rs_getEvent.BOF then rs_getEvent.movefirst
while not rs_getEvent.EOF
x1 = rs_getEvent("startDate")
x2 = rs_getEvent("endDate")
if x1 = curDate OR x2 = curDate OR (x1 < curDate AND x2 > curDate) then
'make a list for event for each day
eventID(x) = eventID(x) & rs_getEvent("id") & "~||~"
eventName(x) = eventName(x) & rs_getEvent("name") & "~||~"
end if
rs_getEvent.movenext
wend
%><%'response.write("<b>eventName("&x&") = "&eventName(x)&"</b><br><br>")%><%
'move current day to next day
curDate = dateAdd("d", 1, curDate)
next
'check if date is in this month
if dateFormat = 1 then
if Not month(DateAdd("d", curDay-1, curMonth & "/1/" & curYear)) = cint(curMonth) then curDay = 1
lastDay = day(dateserial(curYear, curMonth+1, 1-1))
today = curMonth & "/" & curDay & "/" & curYear
else
if Not month(DateAdd("d", curDay-1, "1/" & curMonth & "/" & curYear)) = cint(curMonth) then curDay = 1
lastDay = day(dateserial(curYear, curMonth+1, 1-1))
today = curDay & "/" & curMonth & "/" & curYear
end if
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Calendar</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<table><tr><td>
<table border="1" cellpadding="0" cellspacing="0">
<tr>
<td bgcolor="<%=bg1%>" align="center" height="<%=cell_height1%>" width="<%=cell_width1%>"><font <%=fnt1%>><a href="<%=http%>calendar.asp?curDay=<%= curDay %>&curMonth=<%= month(dateAdd("m", -1, today)) %>&curYear=<%= year(dateAdd( "m", -1, today)) %>&eventType=<%= eventType %>"><%= monthName(month(dateAdd( "m", -1, today))) %></a></font></td>
<td bgcolor="<%=bg1%>" align="center" height="<%=cell_height1%>" width="<%=cell_width1*5%>" colspan="5"><font <%=fnt1%>><%= monthName(curMonth) %> <%= curYear %></font></td>
<td bgcolor="<%=bg1%>" align="center" height="<%=cell_height1%>" width="<%=cell_width1%>"><font <%=fnt1%>><a href="<%=http%>calendar.asp?curDay=<%= curDay %>&curMonth=<%= month(dateAdd("m", 1, today)) %>&curYear=<%= year(dateAdd( "m", 1, today)) %>&eventType=<%= eventType %>"><%= monthName(month(dateAdd( "m", 1, today))) %></a></font></td>
</tr>
<tr>
<form action="<%=http%>calendar.asp" name="search" method="post">
<td bgcolor="<%=bg1%>" align="center" height="<%=cell_height1%>" width="<%=cell_width1%>"><font <%=fnt1%>><a href="<%=http%>calendar.asp?curDay=<%= curDay %>&curMonth=<%= curMonth %>&curYear=<%=curYear-1%>&eventType=<%= eventType %>"><%= curYear-1 %></a></font></td>
<td bgcolor="<%=bg1%>" align="center" height="<%=cell_height1%>" width="<%=cell_width1*5%>" colspan="5"><select name="curMonth"><% for x = 1 to 12 %><option value="<%= x %>" <% if cint(curMonth) = x then %> selected <% end if %>><%= monthName(x) %></option><% next %></select><select name="curYear"><% for x = 1990 to 2020 %><option value="<%= x %>" <% if cint(curYear) = x then %> selected <% end if %>><%= x %></option><% next %></select><input type="hidden" name="eventType" value="<%= eventType %>"><input type="submit" name="submit" value="Search"></td>
<td bgcolor="<%=bg1%>" align="center" height="<%=cell_height1%>" width="<%=cell_width1%>"><font <%=fnt1%>><a href="<%=http%>calendar.asp?curDay=<%= curDay %>&curMonth=<%= curMonth %>&curYear=<%=curYear+1%>&eventType=<%= eventType %>"><%= curYear+1 %></a></font></td>
</form>
</tr>
<tr>
<td bgcolor="<%=bg2%>" align="center" height="<%=cell_height1%>" width="<%=cell_width1%>"><font <%=fnt1%>>Sun</font></td>
<td bgcolor="<%=bg2%>" align="center" height="<%=cell_height1%>" width="<%=cell_width1%>"><font <%=fnt1%>>Mon</font></td>
<td bgcolor="<%=bg2%>" align="center" height="<%=cell_height1%>" width="<%=cell_width1%>"><font <%=fnt1%>>Tue</font></td>
<td bgcolor="<%=bg2%>" align="center" height="<%=cell_height1%>" width="<%=cell_width1%>"><font <%=fnt1%>>Wed</font></td>
<td bgcolor="<%=bg2%>" align="center" height="<%=cell_height1%>" width="<%=cell_width1%>"><font <%=fnt1%>>Thu</font></td>
<td bgcolor="<%=bg2%>" align="center" height="<%=cell_height1%>" width="<%=cell_width1%>"><font <%=fnt1%>>Fri</font></td>
<td bgcolor="<%=bg2%>" align="center" height="<%=cell_height1%>" width="<%=cell_width1%>"><font <%=fnt1%>>Sat</font></td>
</tr>
<tr>
<%
currentDay = 1 - weekday(dateserial(curYear,curMonth,1))+1
lastDay = day(dateserial(curYear,curMonth+1,1-1))
if cint(currentDay) = -4 AND lastDay > 30 then
maxRows = 5
elseif cint(currentDay) = -5 AND lastDay >= 30 then
maxRows = 5
else
maxRows = 4
end If
num = 1
for x = 0 to maxRows
%><tr><%
for xx = 0 to 6
if currentDay > 0 AND currentDay <= lastDay then
'Set today
if dateFormat = 1 then
today = curMonth & "/" & currentDay & "/" & curYear
else
today = currentDay & "/" & curMonth & "/" & curYear
end if
%><td align="left" valign="top" height="<%=cell_height2%>" width="<%=cell_width2%>""<%
if cstr(today) = cstr(month(now())&"/"&day(now())&"/"&year(now())) then
%> bgcolor="<%=todayCell%>"<%
else
%> bgcolor="<%=bg3%>"<%
end if %>>
<font <%=fnt1%>><%= currentDay %></font><br><%
'outputting today's event name by looping through events array
if eventName(num) <> "" then
events = ""
eventsID = ""
events = split(eventName(num),"~||~")
eventsID = split(eventID(num),"~||~")
for y = 0 to ubound(events)
%><a href="#" onclick="window.open('<%=HTTP%>detail.asp?id=<%=ev entsID(y)%>','detail','scrollbars=yes,location=no, width=440,height=400')"><%=events(y)%></a><%
if y <> ubound(events) then
response.write("<br>")
end if
next
else
response.write(" ")
end if
response.write("</font></td>")
num = num + 1
else
%><td><br></tr><%
end if
currentDay = currentDay + 1
next
%><tr><%
next
%>
</tr>
<tr>
<form name="viewtype" action="<%=http%>calendar.asp" method="post">
<td colspan="4" align="center"><select name="eventType"><option value="-1"<%if cint(eventType) = -1 then%> selected<%end if%>>All</option><%while not rs_getType.EOF %><option value="<%=rs_getType("id")%>"<%if cint(eventType) = cint(rs_getType("id")) then%> selected<%end if%>><%= rs_getType("eventType") %></option><% rs_getType.moveNext %><%wend%></select><input type="hidden" name="curMonth" value="<%= curMonth %>"><input type="hidden" name="curYear" value="<%= curYear %>"> <input type="submit" name="viewevent1" value="Select Event Type"></td>
</form>
<form name="backtoday" action="<%=http%>calendar.asp" method="post">
<td colspan="3" align="center"><input type="submit" name="bakctoday1" value="Back to Today"></td>
</form>
</tr>
</td>
</tr>
</table>
</td>
</tr></table>
</body>
</html>
<!--#include file="disconnect.asp"-->
<!--#include file="replace.asp"-->
Thanks...