Important alert: (current site time 7/16/2013 6:51:03 AM EDT)
 

VB icon

CFcalendar3

Email
Submitted on: 11/10/2002 12:36:45 PM
By: Fréderic vandenplas  
Level: Intermediate
User Rating: Unrated
Compatibility: Cold Fusion 4.5
Views: 12262
(About the author)
 
     takes arrival date and departure date out of a database and displays the customers staying in a hotel:) for every date of the calendar visit http://www.coppernicus.be/calendar/CFcalendar2.cfm for a working example
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
//**************************************
// Name: CFcalendar3
// Description:takes arrival date and departure date out of a database and displays the customers staying in a hotel:) for every date of the calendar
visit http://www.coppernicus.be/calendar/CFcalendar2.cfm
for a working example
// By: Fréderic vandenplas
//
// Returns:calebdar with customers
//
// Assumes:you must create a database containing at a minimum a name and a date of arrival and a date of departure
//
//This code is copyrighted and has// limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=62&lngWId=9//for details.//**************************************

<!--------------------------------------------------------------- 
File : CFcalendar2.cfm
Author : Cornelio Gallardo, Jr.
Modified by : vandenplas Fréderic
Email : vandenplas@coppernicus.be
Discription1 : show a calendar what ever year you want, and show the people's names, who reserved
a room in the hotel, for the days they stay in the hotel
Description2 : Purpose of this code is to make dates between arrival and departure date in a
hotel or other reservation system and to link it to a calendar program to see who
is in the hotel on every day of the year. This code is integrated in CFCalendar.cfm
by Cornelio Gallardo, Jr.
--------------------------------------------------------------- --->
<!---Read the contents of CUSTMOER_INFOR table in--->
<!--- ----------------------------------------------->
<CFQUERY NAME="customers" DATASOURCE="" dbtype="ODBC" connectstring="" > 
SELECT * FROM CUSTOMER_INFOR
</CFQUERY>
<!---Simply dump the contents of the query--->
<cfdump var=#customers#>
<!---Create an array and populate it with the the basic numbers and dates we need--->
<CFSET datums =ArrayNew(2)>
<cfset h=1>
<CFLOOP QUERY="customers" STARTROW="1" ENDROW="#customers.RecordCount#">
	
	<CFSET arrdate=#arrdate#>
	<CFSET depdate=#depdate#>
	
	<CFSET arrdate=DateAdd("d",arrdate,0)>
	<CFSET depdate=DateAdd("d",depdate,0)>
	
	<CFSET lname=#fname#>
	<CFSET datums[h][1]=lname>
	<cfset datums[h][2]= "0">
	<CFSET datums[h][3]=arrdate>
	<CFSET workdate=DateAdd("d",arrdate,0)>
	<cfset datums[h][4]=workdate>
	<cfset i=4>
<!--- make the dates between arrdate en depdate and populate the array with them--->		
		<CFLOOP CONDITION="workdate LT depdate">
		<CFSET workdate = DateAdd("d",workdate,1)>
		<CFSET i=i+1>
		<cfset datums[h][i]=workdate>
		
		<CFSET datums[h][2]=i>
		
		</CFLOOP>
		<CFSET h=h+1>
</CFLOOP>
<html>
<head>
	<title>CF Calendar</title>
</head>
<BODY bgcolor="White" vlink="#0000FF" alink="#0000FF">
<!------------------------------------------------------------------------------------------------------------------------- 
						Set the month and year to equal the current values if they do not exist.
 ------------------------------------------------------------------------------------------------------------------------->	
<CFPARAM NAME = "month" DEFAULT = "#DatePart('m', Now())#">
<CFPARAM NAME = "year" DEFAULT = "#DatePart('yyyy', Now())#">
<!--- table and font dispaly formating --->
<cfparam name="headercolor" default="6c006">
<cfparam name="dbgcolor" default="ffe8ff">
<cfparam name="wbgcolor" default="6c006c">
<cfparam name="wfontcolor" default="ffffff">
<cfparam name="daycolor" default="663366">
<cfparam name="curdayColor" default="d2b48c">
<cfparam name="curdaysize" default="+1">
<cfparam name="daysize" default="1">
<cfparam name="align" default="center">
<CFSET MyDay=12>
<CFSET Mymonth=11>
<CFSET MyYear=2002>
<cfoutput>
<CFIF parameterexists(url.months)>
	<cfset month = #url.months#>
	<cfset year = #url.year#>
	<!------------------------------------------------------------------------------------------------------------------------- 
				Set the requested month/year date and determine the number of days in the month. 
	-------------------------------------------------------------------------------------------------------------------------->
	<CFSET ThisMonthYear = CreateDate(year, month, '1')>
	<CFSET Days = DaysInMonth(ThisMonthYear)>
	<!-------------------------------------------------------------------------------------------------------- 
		Set the values for the previous and next months for the back/next links. 
	--------------------------------------------------------------------------------------------------------->
	<CFSET LastMonthYear = DateAdd('m', -1, ThisMonthYear)>
	<CFSET LastMonth = DatePart('m', LastMonthYear)>
	<CFSET LastYear = DatePart('yyyy', LastMonthYear)>
	<CFSET NextMonthYear = DateAdd('m', 1, ThisMonthYear)>
	<CFSET NextMonth = DatePart('m', NextMonthYear)>
	<CFSET NextYear = DatePart('yyyy', NextMonthYear)>
<cfelse>
	<!------------------------------------------------------------------------------------------------------------------------- 
					Set the requested month/year date and determine the number of days in the month. 
	-------------------------------------------------------------------------------------------------------------------------->
	<CFSET ThisMonthYear = CreateDate(year, month, '1')>
	<CFSET Days = DaysInMonth(ThisMonthYear)>
	<!-------------------------------------------------------------------------------------------------------- 
			Set the values for the previous and next months for the back/next links. 
	--------------------------------------------------------------------------------------------------------->
	<CFSET LastMonthYear = DateAdd('m', -1, ThisMonthYear)>
	<CFSET LastMonth = DatePart('m', LastMonthYear)>
	<CFSET LastYear = DatePart('yyyy', LastMonthYear)>
	<CFSET NextMonthYear = DateAdd('m', 1, ThisMonthYear)>
	<CFSET NextMonth = DatePart('m', NextMonthYear)>
	<CFSET NextYear = DatePart('yyyy', NextMonthYear)>
	<CFSET MyDate="20-11-2002">
	
</cfif>
</cfoutput>
<BLOCKQUOTE>
<TABLE BORDER = "0" width="500" align="<cfoutput>#align#</cfoutput>">
	<TR>
	<TD valign="top" align="left">
	<CFOUTPUT>
		
		<FONT FACE="Verdana" COLOR="#headercolor#"><B>
		<A HREF = "CFcalendar2.cfm?month=#LastMonth#&year=#LastYear#">«</A>  #MonthAsString(month)# #year#  <A HREF = "CFcalendar2.cfm?month=#NextMonth#&year=#NextYear#">»</A>
		</FONT></B>
	</CFOUTPUT>
	</TD>
	<TD valign="center" align="right">
	<cfoutput>
	
		<!------------------------------------------------- 
		put a dropdown month to target your specific month you want to view
		-------------------------------------------------->
		<SELECT name="months" onChange="location=this.options[this.selectedIndex].value;">
		<cfloop from="1" to="12" index="i">
		<cfif month eq i>
			<OPTION VALUE="CFcalendar2.cfm?months=#i#&year=#year#" selected>#MonthAsString(i)#
			<cfelse>
				<OPTION VALUE="CFcalendar2.cfm?months=#i#&year=#year#">#MonthAsString(i)#
			</cfif>
		</cfloop>	
		</SELECT>
		<!------------------------------------------------- 
		put a dropdown year to target your specific year you want to view
		-------------------------------------------------->
		<SELECT name"year" onChange="location=this.options[this.selectedIndex].value;">
		<cfloop from="2001" to="2010" index="i">
		<cfif year eq i>
		<OPTION VALUE="CFcalendar2.cfm?year=#i#&month=#month#" selected>#i#
		<cfelse>	
			<OPTION VALUE="CFcalendar2.cfm?year=#i#&month=#month#">#i#	
		</cfif>	
		</cfloop>	
		</SELECT>
	<cfset monthnum = #DatePart('m', ThisMonthYear)#>
	</cfoutput>
	</TD>
	
	</tr>
	<TR>
		<TD ALIGN = "Center" colspan="2">
			<!---------------------------------------------------------------------------------- 
						Display the current month/year as well as the back/next links. 
			----------------------------------------------------------------------------------->
	
			<P>
					
			<TABLE BORDER = "0" bordercolordark="Navy" bordercolorlight="Black">
			<!-------------------------------------------------------------------------------------------------------------- 
													Display the days of the week headers. 
			--------------------------------------------------------------------------------------------------------------->				
				<TR>
					<CFLOOP FROM = "1" TO = "7" INDEX = "MoveDay">						
						<CFOUTPUT>
						<TD WIDTH = "50" ALIGN = "center" bgcolor="#wbgcolor#"><FONT COLOR="#wfontcolor#" FACE="Verdana" SIZE="-1">#Left(DayOfWeekAsString(MoveDay), 3)#</FONT></TD>
						</CFOUTPUT>				
					</CFLOOP>			
				</TR>				
			<!----------------------------------------------------------------------------------------------------------------- 
													Set the ThisDay variable to 0. 
				 This value will remain 0 until the day of the week on which the first day of the month falls on is reached. 
			------------------------------------------------------------------------------------------------------------------->
				<CFSET ThisDay = 0>				
			<!---------------------------------------------------------------------------------------------------------------- 
										Loop through until the number of days in the month is reached. 
			------------------------------------------------------------------------------------------------------------------>
				<CFLOOP CONDITION = "ThisDay LTE Days">	
				<TR>
			<!---------------------------------------------------------------------------------------------------------------- 
													Loop through each day of the week. 
			----------------------------------------------------------------------------------------------------------------->
					<CFLOOP FROM = "1" TO = "7" INDEX = "MoveDay">
			<!--------------------------------------------------------------------------------------------------------------- 
							If ThisDay is still 0, check to see if the current day of the week in the loop 					
							 		 matches the day of the week for the first day of the month. 
						 		 			If the values match, set ThisDay to 1. 
						 	Otherwise, the value will remain 0 until the correct day of the week is found. 
			----------------------------------------------------------------------------------------------------------------->
						<CFIF ThisDay IS 0>	
							<CFIF DayOfWeek(ThisMonthYear) IS MoveDay>
								<CFSET ThisDay = 1>							
							</CFIF>	
						</CFIF>
			<!--------------------------------------------------------------------------------------------------------------- 
						If the ThisDay value is still 0, or it is greater than the number of days in the month,
													display nothing in the column. 
									Otherwise, display the day of the month and increment the value. 
			----------------------------------------------------------------------------------------------------------------->
						<CFIF (ThisDay IS NOT 0) AND (ThisDay LTE Days)>
							 
							<TD align="left" valign="top" width="75" height="50" bgcolor="4169e1">
								<CFOUTPUT>
								
								<CFIF #DatePart('d', Now())# IS #ThisDay# AND #DatePart('m', Now())# IS #month# and #DatePart('yyyy', Now())# is #year#>
								
								<FONT COLOR="#curdayColor#" size="#curdaysize#">
								
								
								#ThisDay#
								<CFSET h=1>
									<CFLOOP CONDITION = "h LTE #customers.RecordCount#">
									<CFSET x=4>
									<CFLOOP CONDITION="x LTE datums[#h#][2]">
									<CFIF #DatePart('d',datums[h][x] )# IS #ThisDay# AND #DatePart('m', datums[h][x])# IS #month# and #DatePart('yyyy', datums[h][x])# IS #year#>
									<p>#datums[h][1]#</p>
									</CFIF>
									<CFSET x=x+1>
									</CFLOOP>
									<CFSET h=h+1>
									</CFLOOP>
								
								
								</FONT>
								
								<CFELSE>
								<!--- This is when the calendar date is NOTEQ computerdate--->
								
								
								
										<FONT COLOR="#curdaycolor#" SIZE="#curdaysize#">
									#ThisDay#
									<CFSET h=1>
									<CFLOOP CONDITION = "h LTE #customers.RecordCount#">
									<CFSET x=4>
									<CFLOOP CONDITION="x LTE datums[#h#][2]">
									<CFIF #DatePart('d',datums[h][x] )# IS #ThisDay# AND #DatePart('m', datums[h][x])# IS #month# and #DatePart('yyyy', datums[h][x])# IS #year#>
									<p>#datums[h][1]#</p>
									</CFIF>
									<CFSET x=x+1>
									</CFLOOP>
									<CFSET h=h+1>
									</CFLOOP>
										</FONT>
								</cfif>		
								</CFOUTPUT>
							</TD>
							<CFSET ThisDay = ThisDay + 1>
						<CFELSE>		
							<TD> </TD>
						</CFIF>
									
					</CFLOOP>	
				</TR>				
				</CFLOOP>							
			</TABLE>
		</TD>
	</TR>
</TABLE>		
</BODY>
</HTML>


Other 1 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Intermediate category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.