I have a problem with the calendar script below. It works fine
untill i try to turn forward to February 2007 and past. Then the weekdays in the first week gets displaced.
I wonder if someone could help me solve this problem ?
<?php
# Calendar script that lets user choose next and previous month
if (isset($_GET["prev"])) {
$active_month = strtotime("-1 month", $_GET["prev"]);
}
elseif (isset($_GET['next'])) {
$active_month = strtotime("+1 month", $_GET["next"]);
}
else {
$active_month = strtotime("today");
}
echo "<table border=1><tr>";
echo "<td><a href=".$_SERVER["PHP_SELF"]."?prev=".$active_month."><</a></td>";
echo "<td colspan=6 align=center bgcolor=lightgreen><a href=".$_SERVER["PHP_SELF"].">".date("F Y", $active_month)."</a></td>";
echo "<td><a href=".$_SERVER["PHP_SELF"]."?next=".$active_month.">></a></td></tr>";
echo "<tr><td bgcolor=lightblue align=center>w</td>";
$weekdays = array("Mon","Tue","Wed","Thu","Fri","Sat","Sun");
foreach ($weekdays as $weekday) {
echo "<td bgcolor=lightblue align=center>$weekday</td>";
}
echo "<tr><td bgcolor=orange>".date("W",mktime(0,0,0,date("m", $active_month),0))."</td>";
for ($day = 0; $day < date("w",mktime(0,0,0,date("m", $active_month),0)); $day++) {
echo "<td><!--Empty Cells--></td>";
}
for ($dim = 1; $dim <= date("t", $active_month); $dim++) {
$timestamp = strtotime(date("Y-m-".$dim, $active_month));
$day = date("w", $timestamp);
# Output week numbers with orange bgcolor
if ($day==1) {
echo "</tr><tr><td bgcolor=orange>".date("W", $timestamp)."</td>";
}
# Output today with bold text and bgcolor=lightgreen
if ($dim == date("d", $active_month)) {
print "<td bgcolor=lightgreen><b>$dim</b></td>";
}
# Output weekend days with brown text
elseif ($day == 0 or $day == 6) {
echo "<td><font color=brown>$dim</font></td>";
}
else {
echo "<td>$dim</td>";
}
}
echo "</tr></table>";
?>