<!--
You can download the entire application with event manager at
http://www.doctorjackson.org/calendar/index.cfm
Calendar has three atributes a user has to define. The required attribute is a name of a
cfm template in which cf_calendar tag is inserted. For example, if you want to insert
this tag into index.cfm page you have to specify this page as a custom tag
attribute: page = "index.cfm"
-->
<cfparam name="attributes.page" type="string" default="calendar.cfm">
<!--
There are also two optional attributes that allow to specify ColdFusion
datasource and table name where you keep information about events. If you
do not specify these attributes they are set up as "calendar" datasource
and "calendar" table name by default. If you use your own datasource be sure
that your event table has the following required fields:
id (integer autoincrement)
cdate (date/time general date format in MSAccess)
ctitle (text field)
cdescription (memo field)
-->
<cfparam name="attributes.cdatasource" type="string" default="calendar">
<cfparam name="attributes.ctable" type="string" default="calendar">
<!--
To navigate through the calendar a URL parameter URL.mLink is used. If left arrow
clicked, the page in which the calendar is loaded and based on the URL.mLink
parameter the calendar shifts itself either one month ahead (URL.mLink is 2 )
or one month back (URL.mLink is 1 ). By default this parameter is equal zero and
calendar is set up to the current month.
-->
<cfparam name="URL.mLink" type="numeric" default="0">
<!--Initialization -->
<cfif URL.mLink is 0>
<cfset SESSION.cMonth = Month(Now())>
<cfset SESSION.cYear = Year(Now())>
<cfset SESSION.nDays = DaysInMonth(Now())>
<cfset SESSION.startDay = DayOfWeek(CreateDate(SESSION.cYear,SESSION.cMonth,1))>
</cfif>
<!-- When the left arrow clicked, the calendar is set up to one month back from the
current month -->
<cfif URL.mLink is 1>
<cfset SESSION.cMonth = SESSION.cMonth-1>
<cfif SESSION.cMonth lt 1>
<cfset SESSION.cYear = SESSION.cYear-1>
<cfset SESSION.cMonth = 12>
</cfif>
<cfset SESSION.nDays = DaysInMonth(CreateDate(SESSION.cYear, SESSION.cMonth,1))>
<cfset SESSION.startDay = DayOfWeek(CreateDate(SESSION.cYear, SESSION.cMonth,1))>
</cfif>
<!-- When the right arrow clicked, the calendar is set up to one month forward from the
current month -->
<cfif URL.mLink is 2>
<cfset SESSION.cMonth = SESSION.cMonth+1>
<cfif SESSION.cMonth GT 12>
<cfset SESSION.cYear = SESSION.cYear+1>
<cfset SESSION.cMonth = 1>
</cfif>
<cfset SESSION.nDays = DaysInMonth(CreateDate(SESSION.cYear, SESSION.cMonth,1))>
<cfset SESSION.startDay = DayOfWeek(CreateDate(SESSION.cYear, SESSION.cMonth,1))>
</cfif>
<cfset pos = 1>
<!-- Calendar styles is a subject to customization -->
<style type="text/css">
<!--
.style1 {color: #FCFAE9}
.style6 {font-family: Arial; font-size: 12px; }
.style9 {font-family: "Times New Roman", Times, serif; font-size: 12px; color: #FFFFFF; }
-->
</style>
<!-- To output a calendar the tabular format is used. The next code generates 7 x 8 HTML table. First row
is allocated for the calendar navigation (month link). Second row is week days header, and the rest are cells allocated to
display day numbers -->
<cfoutput>
<table width="140" border="1" cellpadding="0" cellspacing="0" bordercolor="##CCCCCC" bgcolor="##FCFAE9">
<tr valign="middle" bgcolor="0C0F57">
<td height="30" colspan="7" align="center" class="style6">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="30"><a href="#attributes.page#?mLink=1"><img src="arrow_l.gif" width="20" height="30" border="0"></a></td>
<td width="100%" align="center" valign="middle" class="style9">#MonthAsString(SESSION.cMonth)# #SESSION.cYear#</td>
<td width="30"><a href="#attributes.page#?mLink=2"><img src="arrow_r.gif" width="20" height="30" border="0"></a></td>
</tr>
</table>
</td>
</tr>
<tr align="center" valign="middle" bgcolor="0C0F57">
<td width="20" height="20"><span class="style9">Su</span></td>
<td width="20" height="20"><span class="style9">Mo</span></td>
<td width="20" height="20"><span class="style9">Tu</span></td>
<td width="20" height="20"><span class="style9">We</span></td>
<td width="20" height="20"><span class="style9">Th</span></td>
<td width="20" height="20"><span class="style9">Fr</span></td>
<td width="20" height="20"><span class="style9">Sa</span></td>
</tr>
<cfloop index ="i" from="1" to="6">
<tr>
<cfloop index ="j" from="1" to="7">
<cfset theDay = pos - (SESSION.startDay-1)>
<!-- NewDate is a variable that will be used to query Events table. Here the
calendar tries to create a date object. In case of success a triger variable
trigger is set to 1 -->
<cftry>
<cfset newDate = CreateODBCDate(CreateDate(SESSION.cYear, SESSION.cMonth, theDay))>
<cfset trigger = 1>
<cfcatch>
<cfset trigger = 0>
</cfcatch>
</cftry>
<!-- If newDate is a date when an event(s) happen then we link this date in the calendar to
events.cfm page where events for this date will be populated. Otherwise the date in the calendar
will by dysplayed without the link and the highlighted background. This query starts if trigger
variable is set to 1 that means that date is correct -->
<cfset bgrd = "FCFAE9">
<!-- bgrd defines a background color of the cell. The idea is that if the calendar has any events
at this date, the cell background changes its color. You can customize backgrounf color
as it fits the color gamma of your web page -->
<cfif trigger eq 1>
<cfquery datasource="#attributes.cdatasource#" name="checkEvent">
select * from #attributes.ctable#
where cdate = <cfqueryparam value='#newDate#' cfsqltype="cf_sql_timestamp">
</cfquery>
<!-- If there are some events we highlight the backgound of a date cell -->
<cfif checkEvent.recordcount GT 0>
<cfset bgrd = "CCCCCC">
</cfif>
</cfif>
<td width="20" height="20" align="center" valign="middle" bgcolor="#bgrd#">
<!-- If the date in the right range than it is dysplayed -->
<cfif NOT (theDay LT 1 OR theDay GT SESSION.nDays)>
<cfif trigger eq 1>
<cfif checkEvent.recordcount GT 0>
<a href="calendar_add_event_show.cfm?m1=#SESSION.cMonth#&y1=#SESSION.cYear#&d1=#theDay#" target="_blank"><span class="style6">#theDay#</span></a>
<cfelse>
<span class="style6">#theDay#</span>
</cfif>
</cfif>
<!-- Otherwise, the hidden dash is inserted in order to dysplay the table borders correctly -->
<cfelse>
<span class="style1">-</span>
</cfif>
</td>
<cfset pos = pos +1>
</cfloop>
</tr>
</cfloop>
</table>
</cfoutput>