JavaScript appears to be disabled. We recommend you enable JavaScript while visiting this site.

(All original content on this site is licensed under the Creative Commons License Attribution-Noncommercial-No Derivative Works 3.0.)

Two simple ColdFusion calendar outputs

Here's two rough drafts of calendars created via ColdFusion (7, but I believe 6.1 would have the same functionality).

Tables-based

<cfparam name="URL.CalendarMonth" default="#Month(now())#" type="integer" />
<cfparam name="URL.CalendarYear" default="#Year(now())#" type="integer" />

<cfif URL.CalendarMonth LT 1 OR URL.CalendarMonth GT 12>
	<cfset URL.CalendarMonth = Month(now()) />
</cfif>

<cfset VARIABLES.Calendar.StartDate = CreateDate(URL.CalendarYear, URL.CalendarMonth, 1) />

<table style="width:375px;" summary="Calendar of events for <cfoutput>#DateFormat(VARIABLES.Calendar.StartDate, 'mmmm yyyy')#</cfoutput>.">
	<thead>
		<tr>
			<th colspan="7"><cfoutput>#DateFormat(VARIABLES.Calendar.StartDate, "mmmm yyyy")#</cfoutput></th>
		</tr>
		<tr>
			<th>S</th>
			<th>M</th>
			<th>T</th>
			<th>W</th>
			<th>Th</th>
			<th>F</th>
			<th>S</th>
		</tr>
	</thead>
	<tbody>
		<cfloop from="1" to="#DaysInMonth(VARIABLES.Calendar.StartDate)#" index="iDay">
			<cfset VARIABLES.Calendar.CurrentDate = CreateDate(URL.CalendarYear, URL.CalendarMonth, iDay) />
			<cfif DayOfWeek(VARIABLES.Calendar.CurrentDate) EQ 1 OR iDay EQ 1><!--- This is Sunday, or the first day. --->
				<tr>
			</cfif>
			<cfif iDay EQ 1><!--- If it's the first day, determine how many empty cells we need. --->
				<cfoutput>#RepeatString("<td></td>", DayOfWeek(VARIABLES.Calendar.StartDate) - 1)#</cfoutput>
			</cfif>
				<cfoutput><td><span title="#DateFormat(VARIABLES.Calendar.CurrentDate, 'mmmm d, yyyy')#">#iDay#</span></td></cfoutput>
			<cfif iDay EQ DaysInMonth(VARIABLES.Calendar.StartDate)>
				<cfoutput>#RepeatString("<td></td>", 7 - DayOfWeek(VARIABLES.Calendar.CurrentDate))#</cfoutput>
			</cfif>
			<cfif DayOfWeek(VARIABLES.Calendar.CurrentDate) EQ 7 OR iDay EQ DaysInMonth(VARIABLES.Calendar.StartDate)><!--- This is Saturday, or the last day. --->
				</tr>
			</cfif>
		</cfloop>
	</tbody>
</table>

Ordered list and CSS

The following is a rough version of an ordered list and CSS-based calendar.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title></title>
	<style type="text/css">
	.olCalendar {
		width:375px;
	}
	.olCalendar ol li {
		display:block;
		float:left;
		list-style-position:inside;
		margin:0;
		width:45px;
	}
	.olCalendar li.noDate {
		list-style-image:none;
	}
	</style>
</head>
<body>
<cfparam name="URL.CalendarMonth" default="#Month(now())#" type="integer" />
<cfparam name="URL.CalendarYear" default="#Year(now())#" type="integer" />

<cfif URL.CalendarMonth LT 1 OR URL.CalendarMonth GT 12>
	<cfset URL.CalendarMonth = Month(now()) />
</cfif>

<cfset VARIABLES.Calendar.StartDate = CreateDate(URL.CalendarYear, URL.CalendarMonth, 1) />
<div class="olCalendar">
	<ol start="<cfoutput>#2 - DayOfWeek(VARIABLES.Calendar.StartDate)#</cfoutput>">
		<cfloop from="1" to="#DaysInMonth(VARIABLES.Calendar.StartDate)#" index="iDay">
			<cfset VARIABLES.Calendar.CurrentDate = CreateDate(URL.CalendarYear, URL.CalendarMonth, iDay) />
			<cfif iDay EQ 1><!--- If it's the first day, determine how many empty cells we need. --->
				<cfoutput>#RepeatString('<li class="noDate"> </li>', DayOfWeek(VARIABLES.Calendar.StartDate) - 1)#</cfoutput>
			</cfif>
				<cfoutput><li class="#LCase(DayOfWeekAsString(DayOfWeek(VARIABLES.Calendar.CurrentDate)))#"><span title="#DateFormat(VARIABLES.Calendar.CurrentDate, 'mmmm d, yyyy')#">#iDay#</span></li></cfoutput>
			<cfif iDay EQ DaysInMonth(VARIABLES.Calendar.StartDate)>
				<cfoutput>#RepeatString('<li class="noDate"> </li>', 7 - DayOfWeek(VARIABLES.Calendar.CurrentDate))#</cfoutput>
			</cfif>
		</cfloop>
	</ol>
</div>

</body>
</html>

But, let's be honest, this version sucks. I think tables are a necessary evil in this regard.

EDIT 12/21/2009: Corrected StartDate/CurrentDate mistake with repeating td elements.

Tags: ,

Categories: article

(All original content on this site is licensed under the Creative Commons License Attribution-Noncommercial-No Derivative Works 3.0.)

ColdFusion: cfscript to determine if variable exists and output html-escaped

There may be an easier way to do this in ColdFusion, but I finally created a function to determine whether a variable exists and if it does, returns in, all html-escaped.

<cfscript>
	// Checks the passed CF variable to see if it exists, and if it does, outputs a trimmed and html-ready version of the value.
	function checkForValueOutput(data) {
		if (IsDefined(data)) {
			return HtmlEditFormat(Trim(Evaluate(data)));
		} else {
			return "";
		}
	}
</cfscript>

(Obviously, this can rather easily be converted to a function.)

This results in a change from:

<input type="text" id="someField" name="someField" value="<cfif IsDefined("FORM.someField") AND Trim(FORM.someField) NEQ ""><cfoutput>#HtmlEncodedFormat(Trim(FORM.someField))#</cfoutput></cfif>" />

To:

<input type="text" id="someField" name="someField" value="<cfoutput>#checkForValueOutput("FORM.someField")#</cfoutput>" />

Much easier to read, and much shorter.

Tags:

Categories: article

(All original content on this site is licensed under the Creative Commons License Attribution-Noncommercial-No Derivative Works 3.0.)

Collection down after opening - resolution

We've been running into an issue, off and on, with ColdFusion MX 7.0.2 having issues with Verity collections.

During one of our nightly jobs, two Verity collections are purged, through ColdFusion, and then re-built. 

Sometimes this will bring the collection down, resulting in a message like the following.

Collection down after opening (10)

Using the mdvdk executable, you can get some information about the collection, and even bring it back up.

mdvdk can be found in the \verity\k2\_nti40\bin\ directory, within the ColdFusion root directory.

You can get information about the status of the collection through this: 

mkvdk -collection <path to collection> -about

You don't use the online option/switch, but rather the repair one to bring the collection back online.

mkvdk -collection <path to collection> -repair

You should be able to reindex successfully.

I also changed the code to do a refresh, instead of a purge, since the former doesn't take the collection offline.

You can find additional options by using the following:

mkvdk -help

 

Tags:

Categories: article, software