How can PHP be used to dynamically generate a graphical monthly calendar for displaying room availability?
To dynamically generate a graphical monthly calendar for displaying room availability using PHP, you can create a script that generates an HTML table with the days of the month and highlight the available dates. You can use PHP to calculate the number of days in the month, the day of the week the month starts on, and loop through each day to display it in the table.
```php
<?php
// Get the current month and year
$month = date('n');
$year = date('Y');
// Get the number of days in the month
$days_in_month = cal_days_in_month(CAL_GREGORIAN, $month, $year);
// Get the day of the week the month starts on
$first_day = date('w', mktime(0, 0, 0, $month, 1, $year));
// Start the HTML table
echo '<table>';
// Display the table headers
echo '<tr>';
echo '<th>Sun</th>';
echo '<th>Mon</th>';
echo '<th>Tue</th>';
echo '<th>Wed</th>';
echo '<th>Thu</th>';
echo '<th>Fri</th>';
echo '<th>Sat</th>';
echo '</tr>';
// Start the table row
echo '<tr>';
// Add empty cells for the days before the first day of the month
for ($i = 0; $i < $first_day; $i++) {
echo '<td></td>';
}
// Loop through each day of the month
for ($day = 1; $day <= $days_in_month; $day++) {
// Check if the day is available and highlight it
$is_available = check_room_availability($day, $month, $year);
if ($is_available) {
echo '<td style="background-color: green;">' . $day . '</td>';
} else {
echo '<td>' . $day . '</td>';
}
// Start a new row if it's the end of the week
if (($day + $first_day) % 7 == 0) {
echo '</tr><tr>';
}
}
// Add empty cells for the days after the last day of the month
for ($i = ($day + $first_day) % 7; $i < 7; $i++) {
echo '<td></td>';
}
// End the table row and