Show Script
Showing code for: includes/cal.irev
Back
<?rev
-- version of calendar page to allow it to be embedded in any page as an include
-- smaller and doesn't allow any date selection
-- All the function names have had "Fn" appended to avoid any conflicts with
-- functions used in the basic web page structure
-- returns the month name & 4-digit year
function monthYearFn
put monthNumberFn() into tMonthNum
put yearNumberFn() into tYear
put line tMonthNum of the monthnames into tMonth
return tMonth && tYear
end monthYearFn
-- calculates number of days in the given month, allowing for leap years
function daysInMonthFn pMonthNum, pYearNum
if (pMonthNum is in "1,3,5,7,8,10") or (pMonthNum = 12) then
return 31
else if (pMonthNum is in "4,6,9,11") then
return 30
else if (pYearNum mod 400 = 0) or (pYearNum mod 100 <> 0) and (pYearNum mod 4 = 0) then
return 29 -- leap year
else
return 28
end if
end daysInMonthFn
-- Get the number of the current month
function monthNumberFn
put the seconds into tNow
convert tNow to dateItems
put item 2 of tNow into tMonthNum
return tMonthNum
end monthNumberFn
-- Get the number of the current year
function yearNumberFn
put the seconds into tNow
convert tNow to dateItems
put item 1 of tNow into tYear
return tYear
end yearNumberFn
?>
<!-- Calendar table -->
<table border="1" cellspacing="0" cellpadding="4" style="font-size: x-small;">
<tr>
<th colspan="7" align="center">
<?rev put monthYearFn() ?>
</th>
</tr>
<tr>
<th width="25" align="center"><font color="#ff9900">Sun
</font></th>
<th width="25" align="center">Mon
</th>
<th width="25" align="center">Tue
</th>
<th width="25" align="center">Wed
</th>
<th width="25" align="center">Thu
</th>
<th width="25" align="center">Fri
</th>
<th width="25" align="center">Sat
</th>
</tr>
<?rev
put yearNumberFn() into tYear
put monthNumberFn() into tMonthNum
put daysInMonthFn(tMonthNum, tYear) into tDaysInMonth
put tMonthNum & "/1/" & tYear into tFirstDate
convert tFirstDate from english date to dateItems
put last item of tFirstDate into tFirstDayNum
?>
<tr>
<?rev
repeat with x = 1 to 7 ?>
<td align="right">
<?rev
if x < tFirstDayNum then
put " "
else
put x - tFirstDayNum + 1 into tDay
if x = 1 then
put "<font color=" & quote & "#ff9900" & quote & ">" & tDay & "</font>"
else
put tDay
end if
end if
?>
</td>
<?rev end repeat ?>
</tr>
<?rev put x - tFirstDayNum + 2 into tLastUsedNum ?>
<?rev repeat with w = 2 to 6 ?>
<tr>
<?rev repeat with d = 1 to 7 ?>
<td align="right">
<?rev
if tLastUsedNum > tDaysInMonth then
put " "
else
if d = 1 then
put "<font color=" & quote & "#ff9900" & quote & ">" & tLastUsedNum & "</font>"
else
put tLastUsedNum
end if
end if
add 1 to tLastUsedNum
?>
</td>
<?rev end repeat
-- don't show any more weeks than required
if tLastUsedNum > tDaysInMonth then
exit repeat
end if
?>
</tr>
<?rev end repeat ?>
</table>