<?xml version="1.0" encoding="utf-8"?>
<!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>
<title>cfscript calendar</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<style type="text/css">
.dow, .calDay, .calDay_now, .empty { width:15px; height:15px; font-family:verdana; cursor:default; }
.calDay, .calDay_now { font-size:9px; text-align:right; vertical-align:bottom; }
.calTable { background-color:#cccccc; border-right:2px #000000 solid; border-bottom:2px #000000 solid; }
.calMoYr { font-size:10px; background-color:#7097c7; text-align:center; font-family:verdana; font-size:11px; }
.dow { font-size:10px; background-color:#d1e0f3; text-align:center; font-weight:bold; }
.calDay { background-color:#ffffff; border:1px #ffffff solid; }
.calDay_now { background-color:#ffffcc; border:1px #7097c7 solid; }
.empty { font-size:9px; background-color:#ececec; text-align:right; vertical-align:bottom; color:#999999; }
a { color:#000000; text-decoration:none; }
</style>
</head>
<body>
<cfscript>
// *********************************************************************************************************************
if (NOT structKeyExists(URL, 'mo')) URL.mo = month(now()); // ensure a URL var for month
if (NOT structKeyExists(URL, 'yr')) URL.yr = year(now()); // ensure a URL var for year
try {
variables.current_date = createDate(URL.yr, URL.mo, 1); // the current month/year as a valid date object
}
catch(any excpt) {
variables.current_date = now();
}
variables.current_date = createDate(URL.yr, URL.mo, 1); // the current month/year as a valid date object
variables.first_day_of_month = dayOfWeek(variables.current_date); // the first day of the week of the current month
variables.month_prev = dateAdd('m', -1, current_date); // determine previous month (use for links)
variables.month_next = dateAdd('m', 1, current_date); // determine next month (use for links)
variables.maxDays = daysInMonth(current_date); // how many days in the current month
variables.maxDays_prev = daysInMonth(variables.month_prev); // how many days in the previous month
// where to start counting the previous month's days
variables.startDay_prev = variables.maxDays_prev - variables.first_day_of_month + 2;
variables.currentDay = 1; // start counting current days (current month)
variables.nextMoDay = 1; // start counting current days (next month)
// determines when to end current month and begin next month
variables.lastDay = 7 - dayOfWeek(createDate(year(current_date), month(current_date), daysInMonth(current_date)));
// total boxes needed (for prev, current, and next months)
variables.total_boxes = variables.first_day_of_month + variables.lastDay + daysInMonth(current_date) - 1;
variables.newrow = false;
// *********************************************************************************************************************
writeOutput('<table style="background-color:##cccccc;" cellspacing="1">');
writeOutput('<tr>');
writeOutput('<td class="calMoYr"><a href="cfscript_calendar.cfm?mo=' & month(variables.month_prev) & '&yr=' & year(variables.month_prev) & '" class="navLink"><</td>');
writeOutput('<td class="calMoYr" colspan="5">' & left(monthAsString(month(current_date)), 3) & ' ' & year(current_date) & '</td>');
writeOutput('<td class="calMoYr"><a href="cfscript_calendar.cfm?mo=' & month(variables.month_next) & '&yr=' & year(variables.month_next) & '" class="navLink">></td>');
writeOutput('</tr>');
writeOutput('<tr>');
for (i=1; i LTE 7; i=i+1) {
writeOutput('<td class="dow">' & left(dayOfWeekAsString(i), 1) & '</td>');
}
writeOutput('</tr>');
writeOutput('<tr>');
for (this_day=1; this_day LTE variables.total_boxes; this_day=this_day+1) {
if (variables.newrow) writeOutput('<tr>');
if (this_day LT variables.first_day_of_month) {
writeOutput('<td class="empty">' & variables.startDay_prev & '</td>');
variables.startDay_prev = variables.startDay_prev + 1;
} else {
if (variables.currentDay LTE variables.maxDays) {
if (month(now()) EQ month(current_date) AND year(now()) EQ year(current_date) AND day(now()) EQ variables.currentDay) {
thisClass = "calDay_now";
} else {
thisClass = "calDay";
}
writeOutput('<td class="' & thisClass & '">' & variables.currentDay & '</td>');
variables.currentDay = variables.currentDay + 1;
} else {
writeOutput('<td class="empty">' & variables.nextMoDay & '</td>');
variables.nextMoDay = variables.nextMoDay + 1;
}
}
if (this_day MOD 7 EQ 0) {
variables.newrow = true;
writeOutput('</tr>');
} else {
variables.newrow = false;
}
}
writeOutput('</table>');
</cfscript>
</body>
</html>
|