Пример #1
0
function displayCalendar($year, $month)
{
    // display header
    echo "<h1>Calendar for " . $month . "/" . $year . "</h1>";
    // table header
    echo "<table><thead><tr>";
    $days = array("Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun");
    for ($i = 0; $i < count($days); $i++) {
        echo "<th>" . $days[$i] . "</th>\n";
    }
    echo "</tr></thead><tbody><tr>";
    // table body
    // initial empty days
    $date = mktime(0, 0, 0, $month, 1, $year);
    // 1st day of the month
    $dow = dow($date);
    // use our own dow() function to get day-of-week
    for ($i = 0; $i < $dow; $i++) {
        echo "<td>&nbsp;</td>";
    }
    // days
    $numdays = cal_days_in_month(CAL_GREGORIAN, $month, $year);
    for ($day = 1; $day <= $numdays; $day++) {
        $date = mktime(0, 0, 0, $month, $day, $year);
        echo "<td>" . $day . "</td>";
        if (dow($date) == 6) {
            // Sun
            echo "</tr>";
            // close row
            if ($day < $numdays) {
                // more days to come
                echo "<tr>";
            }
        }
    }
    // remaining empty days
    // Mind that $date holds the last day of the month
    $left = 6 - dow($date);
    if ($left > 0) {
        for ($i = 0; $i < $left; $i++) {
            echo "<td>&nbsp;</td>";
        }
        echo "</tr>";
    }
    echo "</tbody></table>";
}
Пример #2
0
function displayCalendar($year, $month, $checkin, $checkout, $booked)
{
    // table header
    echo "<table><thead><tr><th colspan='7'>" . $month . "/" . $year . "</th></tr><tr>";
    $days = array("Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun");
    for ($i = 0; $i < count($days); $i++) {
        echo "<th>" . $days[$i] . "</th>\n";
    }
    echo "</tr></thead><tbody><tr>";
    // table body
    // initial empty days
    $date = mktime(0, 0, 0, $month, 1, $year);
    // 1st day of the month
    $dow = dow($date);
    // use our own dow() function to get day-of-week
    for ($i = 0; $i < $dow; $i++) {
        echo "<td>&nbsp;</td>";
    }
    // days
    $numdays = cal_days_in_month(CAL_GREGORIAN, $month, $year);
    for ($day = 1; $day <= $numdays; $day++) {
        $date = mktime(0, 0, 0, $month, $day, $year);
        $class = array_key_exists(date("Y-m-d", $date), $booked) ? "booked" : "available";
        // indicate selected dates (check-out date excluded)
        if ($date >= $checkin && $date < $checkout) {
            $class .= " selected";
        }
        echo "<td class='" . $class . "'>" . $day . "</td>";
        if (dow($date) == 6) {
            // Sun
            echo "</tr>";
            // close row
            if ($day < $numdays) {
                // more days to come
                echo "<tr>";
            }
        }
    }
    // remaining empty days
    // Mind that $date holds the last day of the month
    $left = 6 - dow($date);
    if ($left > 0) {
        for ($i = 0; $i < $left; $i++) {
            echo "<td>&nbsp;</td>";
        }
        echo "</tr>";
    }
    echo "</tbody></table>";
}