if (isset($_GET['prev'])) {
$active_ts = strtotime('-1 month', $_GET['prev']);
} elseif (isset($_GET['next'])) {
$active_ts = strtotime('+1 month', $_GET['next']);
} else {
$active_ts = strtotime('today');
}
echo "<table border=1>";
echo "<tr>";
echo '<td><a href="' . $_SERVER['PHP_SELF'] . '?prev=' . $active_ts . '"><</a></td>';
echo "<td colspan=6 align=center bgcolor=lightgreen>".date("F Y", $active_ts)."</td>";
echo '<td><a href="' . $_SERVER['PHP_SELF'] . '?next=' . $active_ts . '">></a></td></tr>';
echo "<tr><td bgcolor=lightgreen>week</td>";
$weekdays = array("Mon","Tue","Wed","Thu","Fri","Sat","Sun");
foreach ($weekdays as $weekday) {
echo "<td bgcolor=lightblue>$weekday</td>";
}
echo "<tr><td bgcolor=lightgrey>".date("W",mktime(0,0,0,date("m", $active_ts),0))."</td>";
for ($day = 0; $day < date("w",mktime(0,0,0,date("m", $active_ts),0)); $day++) {
echo "<td> <!--Empty Cells--></td>";
}
for ($dim = 1; $dim <= date('t', $active_ts); $dim++) {
$timestamp = strtotime(date("Y-m-".$dim, $active_ts));
$day = date("w", $timestamp);
if ($day==1) {
echo "</tr><tr><td bgcolor=lightgrey>".date("W", $timestamp)."</td>";
}
if ($dim == date("d", $active_ts)) {
print "<td bgcolor=lightblue>$dim</td>";
}
elseif ($day == 0 or $day == 6) {
echo "<td><font color=red>$dim</font></td>";
}
else {
echo "<td>$dim</td>";
}
}
echo "</tr></table>";