<?php

//Calendar for WS
//version 1003
$date = time();

$day = date('d', $date);
$month = date('m', $date);
$year = date('Y', $date);

$first_day = mktime(0, 0, 0, $month, 1, $year);

$title = date('F', $first_day);

$day_of_week = date('D', $first_day);

switch ($day_of_week) {
    case "$sun_n": $blank = 0;
        break;
    case "$mon_n": $blank = 1;
        break;
    case "$tue_n": $blank = 2;
        break;
    case "$wed_n": $blank = 3;
        break;
    case "$thu_n": $blank = 4;
        break;
    case "$fri_n": $blank = 5;
        break;
    case "$sat_n": $blank = 6;
        break;
}

$days_in_month = cal_days_in_month(0, $month, $year);

$rack['index']['contentleft'] = "<table border=0 align=center id=calendar>";
$rack['index']['contentleft'] .= "<tr><th colspan=7> $title $year </th></tr>";
$rack['index']['contentleft'] .= "<tr><td width=42>S</td><td width=42>M</td><td width=42>T</td><td width=42>W</td><td width=42>T</td><td width=42>F</td><td width=42>S</td></tr>";

$day_count = 1;

$rack['index']['contentleft'] .= "<tr>";

while
 ($blank > 0) {
    $rack['index']['contentleft'] .= "<td></td>";
    $blank = $blank - 1;
    $day_count++;
}

$day_num = 1;

while
 ($day_num <= $days_in_month) {

    if ($day_num == $day) {
        $rack['index']['contentleft'] .= "<td class=today>$day_num</td>";
    } else {
        $rack['index']['contentleft'] .= "<td class=days>$day_num</td>";
    }


    $day_num++;
    $day_count++;

    if ($day_count > 7) {
        $rack['index']['contentleft'] .= "</tr><tr>";
        $day_count = 1;
    }
}

while
 ($day_count > 1 && $day_count <= 7) {
    $rack['index']['contentleft'] .= "<td> </td>";

    $day_count++;
}
$rack['index']['contentleft'] .= "</tr></table>";
?>