Hi all
I have downloaded this free calendar script:
<?php
/*
Yves Glodt (yg@mind.lu) 13.01.2002
This is based on a calendar I found in the phpbuilder code library ([url]http://phpbuilder.com/snippet/detail.php?type=snippet&id=22[/url])
It still looks kinda similar, but behind the scenes, much has changed.
Some description is available at [url]http://www.mind.lu/~yg/stuff/[/url]
19.02.2002 - Code cleanup and fixed error in getting the number of days in a month.
Changes:
---------
- The html actually validates.
- Changed form-method from "post" to "get", to simplify integration.
- All dates are handled correctly, the result looks always good and creates valid html.
- When the current month/year is shown, the current day is highlighted.
- The years-<select> is dynamic, it shows the selected year +/- 5 years.
- A light version, for embedding into existing pages is available. ([url]http://www.mind.lu/~yg/stuff/[/url])
Note:
The valid range of a timestamp is typically from
Fri, 13 Dec 1901 20:45:54 GMT to
Tue, 19 Jan 2038 03:14:07 GMT.
(These are the dates that correspond to the minimum and maximum values for a 32-bit signed integer.)
*/
$CurDate = getdate();
if ($QUERY_STRING == NULL) {
$YearToShow = $CurDate['year'];
$MonthToShow = $CurDate['mon'];
} else {
if (checkdate($HTTP_GET_VARS['month'],1,$HTTP_GET_VARS['year']) == false) {
$YearToShow = $CurDate['year'];
$MonthToShow = $CurDate['mon'];
} else {
$YearToShow = $HTTP_GET_VARS['year'];
$MonthToShow = $HTTP_GET_VARS['month'];
if ( ($YearToShow < 1902) || ($YearToShow > 2037) ) {
$YearToShow = $CurDate['year'];
$MonthToShow = $CurDate['mon'];
}
}
}
if ( ($YearToShow == $CurDate['year']) && ($MonthToShow == $CurDate['mon']) ) {
$DayToShow = $CurDate['mday'];
}
$NumberOfDays = date(t,mktime(0,0,0,$MonthToShow+1,0,$YearToShow,-1));
$MonthNames = array(1=>'January','February','March','April','May','June','July','August','September','October','November','December');
//$Years = array('1998','1999','2000','2001','2002','2003','2004','2005');
$Years = array($YearToShow-5,$YearToShow-4,$YearToShow-3,$YearToShow-2,$YearToShow-1,$YearToShow,$YearToShow+1,$YearToShow+2,$YearToShow+3,$YearToShow+4,$YearToShow+5);
echo <<<EOT
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>$MonthNames[$MonthToShow] $YearToShow - Simple PHP Calendar</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="expires" content="0">
<style type="text/css">
<!--
th { font-size: 10pt; background-color: #8080FF; font-weight: bold; }
td.n { font-size: 10pt; background-color: #F0F0F0; }
td.t { font-size: 10pt; background-color: #BBBBBB; }
td.f {}
//-->
</style>
</head>
<body>
<center>
<br><br><br><br><br>
<form action="$PHP_SELF" method="get">
<table width="320" border="0" cellpadding="10" cellspacing="0">
<tr align="center">
<td class="f">
<select name="month">
EOT;
while (list($key,$value) = each($MonthNames)) {
if ($key != $MonthToShow) {
print '<option value="'.$key.'">'.$value."</option>\n";
} else {
print '<option value="'.$key.'" selected>'.$value."</option>\n";
}
}
print "</select>\n</td>\n<td class=\"f\">\n<select name=\"year\">\n";
while (list($key,$value) = each($Years)) {
if ($value != $YearToShow) {
print '<option value="'.$value.'">'.$value."</option>\n";
} else {
print '<option value="'.$value.'" selected>'.$value."</option>\n";
}
}
echo <<<EOT
</select>
</td>
<td class="f"><input type="submit" value="Submit"></td>
</tr>
</table>
</form>
<br><br><br>
<table border="1" cellpadding="1" cellspacing="0">
<tr>
<td class="n" colspan="7" align="center"><h3>$MonthNames[$MonthToShow] $YearToShow</h3></td>
</tr>
<tr align="center">
<th>Mon</th>
<th>Tue</th>
<th>Wed</th>
<th>Thu</th>
<th>Fri</th>
<th>Sat</th>
<th>Sun</th>
</tr>
EOT;
$FirstDayOfWeek = date(l,mktime(0,0,0,$MonthToShow,1,$YearToShow));
switch ($FirstDayOfWeek) {
case 'Tuesday':
$offset = 1;
break;
case 'Wednesday':
$offset = 2;
break;
case 'Thursday':
$offset = 3;
break;
case 'Friday':
$offset = 4;
break;
case 'Saturday':
$offset = 5;
break;
case 'Sunday':
$offset = 6;
break;
default:
$offset = 0;
}
if ($offset > 0) {
print "<tr align=\"center\">\n";
echo str_repeat("<td class=\"n\"> </td>\n",$offset);
}
for ($i=1; $i <= $NumberOfDays; $i++) {
$DayOfWeek = date(l,mktime(0,0,0,$MonthToShow,$i,$YearToShow));
if($DayOfWeek == 'Monday') {
print "<tr align=\"center\">\n";
}
if ($i != $DayToShow) {
print "<td class=\"n\">$i</td>\n";
} else {
print "<td class=\"t\">$i</td>\n";
}
if($DayOfWeek == 'Sunday') {
print "</tr>\n";
}
}
if ( ( ($offset == 5) && ($NumberOfDays > 30) ) || ( ($offset == 6) && ($NumberOfDays > 29) ) ) {
if (42-$NumberOfDays-$offset > 0) {
echo str_repeat("<td class=\"n\"> </td>\n",42-$NumberOfDays-$offset);
}
print "</tr>\n";
} elseif ( ($NumberOfDays != 28) || ($offset > 0) ) {
if (35-$NumberOfDays-$offset > 0) {
echo str_repeat("<td class=\"n\"> </td>\n",35-$NumberOfDays-$offset);
print "</tr>\n";
}
}
echo <<<EOT
</table>
</center>
</body>
</html>
EOT;
?>
I have a MySQL table with dates in it (in the format 25-02-2003 (this is of varchar and not DATE type)). What I would like to able to do is modify the above code slightly so that it will colour in the dates that are in my DB.
Can anyone help me?
Thanks