I have this beautiful and versatile calendar script
$giorno = isset($_GET['g']) ? $_GET['g'] : date('Y-m-d');
$day = strtotime($giorno);
$today = date('Y-m-d', strtotime('today'));
$date = mktime(0, 0, 0, date("m", $day), 1, date("Y", $day));
$past = mktime(0, 0, 0, date("m", $date)-1, 1, date("Y", $date));
$future = mktime(0, 0, 0, date("m", $date)+1, 1, date("Y", $date));
$days = array("Domenica", "Lunedi", "Martedi", "Mercoledi", "Giovedi", "Venerdi", "Sabato");
$months = array("Gennaio", "Febbraio", "Marzo", "Aprile", "Maggio", "Giugno", "Luglio", "Agosto", "Settembre", "Ottobre", "Novembre", "Dicembre");
$month = date("m", $date);
$year = date("Y", $date);
$day_offset = 1; //$day_offset % 7;
$start_day = mktime(0, 0, 0, $month, 1, $year);
$start_day_number = date("w", $start_day);
$days_in_month = date("t", $start_day);
<table id="calendar">
<caption>
<div class="left"><a href="<?php echo $phpSelf; ?>?g=<?php echo date('d/m/Y', $past); ?>" title="Mese precedente">‹</a></div>
<div class="right"><a href="<?php echo $phpSelf; ?>?g=<?php echo date('d/m/Y', $future); ?>" title="Mese successivo">›</a></div>
<div class="center"><?php echo $months[$month-1]; ?> <?php echo $year; ?></div>
</caption>
<tr>
<?php for ($x = 0; $x <= 6; $x++) { ?>
<th scope="col"><?php echo substr(strtolower($days[($x+$day_offset)%7]), 0, 2); ?></th>
<?php } ?>
</tr>
<tr>
<?php
$blank_days = $start_day_number - $day_offset;
if ($blank_days < 0) { $blank_days = 7 - abs($blank_days); }
for ($x = 0; $x < $blank_days; $x++) {
?>
<td> </td>
<?php } ?>
<?php for($x = 1; $x <= $days_in_month; $x++) { ?>
<?php if (($x + $blank_days-1) % 7 == 0){ ?>
</tr>
<tr>
<?php } ?>
<?php $day = $year . "-" . $month . "-" . leading($x); ?>
<td><?php echo $x; ?></td>
<?php } ?>
<?php while ((($days_in_month + $blank_days) % 7) != 0) { ?>
<td> </td>
<?php $days_in_month++;
}
?>
</tr>
It simply loops, given a day, through the entire month and draws a table calendar: so far so good
Now the tricky part: I have a recordset of events like this:
mysql_select_db($database_connArtesicilia, $connArtesicilia);
$query_rsEvents = "SELECT eventi.eve_id, eventi.eve_name, eventi.eve_from, eventi.eve_to FROM eventi WHERE eventi.eve_active";
$rsEvents = mysql_query($query_rsEvents, $connArtesicilia) or die(mysql_error());
$row_rsEvents = mysql_fetch_assoc($rsEvents);
$totalRows_rsEvents = mysql_num_rows($rsEvents);
I'd like to highlight the calendar cells (ie. with
<td class="highlight">
) corresponding to events, and that would be not so difficult if events were limited to only one day... but some events span through multiple contiguous days (ie. from 5th to 8th december) and I have no idea how to highlight cells corresponding to 5, 6, 7 and 8
Please notice that database fields eve_from
and eve_to
are ALWAYS filled (if an event occur in only one day, dates are the same)
More, some events could overlap (ie. one from 5th to 8th and the other from 7th to 9th december): in an ideal world, I'd need both to simply highlight the cell if one or more events are present (for the small version of the calendar), and to list the event(s) of a cell (for the big version of the calendar)
Have you got some idea on how to achieve this?
Thanks in advance, as usual!