Code Snippets

  

ColdFusion Source Code


Welcome to Dream.In.Code
Getting Help is Easy!

Join 131,102 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 2,130 people online right now. Registration is fast and FREE... Join Now!





Quick Calendar

This tag allows you to do the following cool things: to have an interactive calendar on any page of your site; to attach single and multiple events to particular dates and make it visible on the calendar; to access multiple and single event pages from the calendar in one click. to add, edit, and delete events at the calendar administrator panel

Submitted By: semenov2001
Actions:
Rating:
Views: 4,407

Language: ColdFusion

Last Modified: August 10, 2005
Instructions: You can see how code works and download the entire application with event manager at
http://www.doctorjackson.org/calendar/index.cfm

Snippet


  1. <!--
  2.  
  3. You can download the entire application with event manager at
  4.  
  5. http://www.doctorjackson.org/calendar/index.cfm
  6.  
  7. Calendar has three atributes a user has to define. The required attribute is a name of a
  8. cfm template in which cf_calendar tag is inserted. For example, if you want to insert
  9. this tag into index.cfm page you have to specify this page as a custom tag
  10. attribute: page = "index.cfm"
  11.  
  12. -->
  13.  
  14. <cfparam name="attributes.page" type="string" default="calendar.cfm">
  15.  
  16. <!--
  17.  
  18. There are also two optional attributes that allow to specify ColdFusion
  19. datasource and table name where you keep information about events. If you
  20. do not specify these attributes they are set up as "calendar" datasource
  21. and "calendar" table name by default. If you use your own datasource be sure
  22. that your event table has the following required fields:
  23.  
  24. id (integer autoincrement)
  25. cdate (date/time general date format in MSAccess)
  26. ctitle (text field)
  27. cdescription (memo field)
  28.  
  29. -->
  30.  
  31. <cfparam name="attributes.cdatasource" type="string" default="calendar">
  32. <cfparam name="attributes.ctable" type="string" default="calendar">
  33.  
  34. <!--
  35.  
  36. To navigate through the calendar a URL parameter URL.mLink is used. If left arrow
  37. clicked, the page in which the calendar is loaded and based on the URL.mLink
  38. parameter the calendar shifts itself either one month ahead (URL.mLink is 2 )
  39. or one month back (URL.mLink is 1 ). By default this parameter is equal zero and
  40. calendar is set up to the current month.
  41.  
  42. -->     
  43.  
  44. <cfparam name="URL.mLink" type="numeric" default="0">
  45.  
  46. <!--Initialization -->
  47.  
  48. <cfif URL.mLink is 0>
  49.      <cfset SESSION.cMonth = Month(Now())>
  50.      <cfset SESSION.cYear = Year(Now())>
  51.      <cfset SESSION.nDays = DaysInMonth(Now())>
  52.      <cfset SESSION.startDay = DayOfWeek(CreateDate(SESSION.cYear,SESSION.cMonth,1))>
  53. </cfif>
  54.  
  55. <!-- When the left arrow clicked, the calendar is set up to one month back from the
  56. current month -->
  57.  
  58. <cfif URL.mLink is 1>
  59.      <cfset SESSION.cMonth = SESSION.cMonth-1>
  60.      <cfif  SESSION.cMonth lt 1>
  61.           <cfset SESSION.cYear = SESSION.cYear-1>
  62.           <cfset SESSION.cMonth = 12>
  63.      </cfif>
  64.      <cfset SESSION.nDays = DaysInMonth(CreateDate(SESSION.cYear, SESSION.cMonth,1))>
  65.      <cfset SESSION.startDay = DayOfWeek(CreateDate(SESSION.cYear, SESSION.cMonth,1))>
  66. </cfif>
  67.  
  68. <!-- When the right arrow clicked, the calendar is set up to one month forward from the
  69. current month -->
  70. <cfif URL.mLink is 2>
  71.      <cfset SESSION.cMonth = SESSION.cMonth+1>
  72.      <cfif  SESSION.cMonth GT 12>
  73.           <cfset SESSION.cYear = SESSION.cYear+1>
  74.           <cfset SESSION.cMonth = 1>
  75.      </cfif>
  76.      <cfset SESSION.nDays = DaysInMonth(CreateDate(SESSION.cYear, SESSION.cMonth,1))>
  77.      <cfset SESSION.startDay = DayOfWeek(CreateDate(SESSION.cYear, SESSION.cMonth,1))>
  78. </cfif>
  79. <cfset pos = 1>
  80.  
  81. <!-- Calendar styles is a subject to customization -->
  82.  
  83. <style type="text/css">
  84. <!--
  85. .style1 {color: #FCFAE9}
  86. .style6 {font-family: Arial; font-size: 12px; }
  87. .style9 {font-family: "Times New Roman", Times, serif; font-size: 12px; color: #FFFFFF; }
  88. -->
  89. </style>
  90.  
  91. <!-- To output a calendar the tabular format is used. The next code generates 7 x 8 HTML table. First row
  92. is allocated for the calendar navigation (month link). Second row is week days header, and the rest are cells allocated to
  93. display day numbers -->
  94.  
  95. <cfoutput>
  96. <table width="140"  border="1" cellpadding="0" cellspacing="0" bordercolor="##CCCCCC" bgcolor="##FCFAE9">
  97. <tr valign="middle" bgcolor="0C0F57">
  98. <td height="30" colspan="7" align="center" class="style6">
  99. <table width="100%" border="0" cellpadding="0" cellspacing="0">
  100.   <tr>
  101.     <td width="30"><a href="#attributes.page#?mLink=1"><img src="arrow_l.gif" width="20" height="30" border="0"></a></td>
  102.     <td width="100%" align="center" valign="middle" class="style9">#MonthAsString(SESSION.cMonth)# #SESSION.cYear#</td>
  103.     <td width="30"><a href="#attributes.page#?mLink=2"><img src="arrow_r.gif" width="20" height="30" border="0"></a></td>
  104.   </tr>
  105. </table>
  106.   </td>
  107. </tr>
  108.  
  109. <tr align="center" valign="middle" bgcolor="0C0F57">
  110. <td width="20" height="20"><span class="style9">Su</span></td>
  111. <td width="20" height="20"><span class="style9">Mo</span></td>
  112. <td width="20" height="20"><span class="style9">Tu</span></td>
  113. <td width="20" height="20"><span class="style9">We</span></td>
  114. <td width="20" height="20"><span class="style9">Th</span></td>
  115. <td width="20" height="20"><span class="style9">Fr</span></td>
  116. <td width="20" height="20"><span class="style9">Sa</span></td>
  117. </tr>
  118. <cfloop index ="i" from="1" to="6">
  119. <tr>
  120. <cfloop index ="j" from="1" to="7">
  121. <cfset theDay = pos - (SESSION.startDay-1)>
  122. <!-- NewDate is a variable that will be used to query Events table. Here the
  123. calendar tries to create a date object. In case of success a triger variable
  124. trigger is set to 1 -->
  125. <cftry>
  126.      <cfset newDate = CreateODBCDate(CreateDate(SESSION.cYear, SESSION.cMonth, theDay))>
  127.      <cfset trigger = 1>
  128. <cfcatch>
  129.      <cfset trigger = 0>
  130. </cfcatch>
  131. </cftry>
  132.  
  133. <!-- If newDate is a date when an event(s) happen then we link this date in the calendar to
  134. events.cfm page where events for this date will be populated. Otherwise the date in the calendar
  135. will by dysplayed without the link and the highlighted background. This query starts if trigger
  136. variable is set to 1 that means that date is correct -->
  137.  
  138. <cfset bgrd = "FCFAE9">
  139.  
  140. <!-- bgrd defines a background color of the cell. The idea is that if the calendar has any events
  141. at this date, the cell background changes its color. You can customize backgrounf color
  142. as it fits the color gamma of your web page -->
  143.  
  144. <cfif trigger eq 1>
  145.      <cfquery datasource="#attributes.cdatasource#" name="checkEvent">
  146.      select * from #attributes.ctable#
  147.      where cdate = <cfqueryparam value='#newDate#' cfsqltype="cf_sql_timestamp">
  148.      </cfquery>
  149.      <!-- If there are some events we highlight the backgound of a date cell -->
  150.      <cfif checkEvent.recordcount GT 0>
  151.      <cfset bgrd = "CCCCCC">
  152.      </cfif>
  153. </cfif>
  154.  
  155.  
  156. <td width="20" height="20" align="center" valign="middle" bgcolor="#bgrd#">
  157.  
  158. <!-- If the date in the right range than it is dysplayed -->
  159. <cfif NOT (theDay LT 1 OR theDay GT SESSION.nDays)>
  160.  
  161. <cfif trigger eq 1>
  162. <cfif checkEvent.recordcount GT 0>
  163. <a href="calendar_add_event_show.cfm?m1=#SESSION.cMonth#&y1=#SESSION.cYear#&d1=#theDay#" target="_blank"><span class="style6">#theDay#</span></a>
  164. <cfelse>
  165. <span class="style6">#theDay#</span>
  166. </cfif>
  167. </cfif>
  168. <!-- Otherwise, the hidden dash is inserted in order to dysplay the table borders correctly -->
  169. <cfelse>
  170. <span class="style1">-</span>
  171. </cfif>
  172.  
  173. </td>
  174. <cfset pos = pos +1>
  175. </cfloop>
  176. </tr>
  177. </cfloop>
  178. </table>
  179. </cfoutput>

Copy & Paste


Comments


There are currently no comments for this snippet. Be the first to comment!

Add comment


You must be registered and logged on to </dream.in.code> to leave comments.





Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month