Forum Moderators: coopster
$llegada = '2011-08-01';
list ($lyr, $lmo, $lda) = explode('-', $llegada);
// Build the last day of the month:
$salida = date('Y-m-d', mktime(0,0,0,$lmo+1,0,$lyr));
list ($syr, $smo, $sda) = explode('-', $salida);
$stmt = " SELECT id_propiedad as propiedad, tiporeserva, propiedad as test, link_ingles, zona, duermen, MONTH(llegada) AS llegadaMonth,
DAY (llegada) AS llegadaDay, MONTH(salida) AS salidaMonth,
DAY (salida) AS salidaDay FROM casa
LEFT JOIN bookings ON bookings.propiedad = casa.id_propiedad
AND (llegada BETWEEN '$llegada' AND '$salida' OR salida
BETWEEN '$llegada' AND '$salida' OR llegada <= '$llegada' AND salida >= '$salida')
WHERE casa.tipo = 'villa'
order by id_propiedad
";
$result = mysql_query($stmt);
$propiedad = false;
$calendar = array(); $property = array();
while ($row = mysql_fetch_object($result)) {
if ($propiedad!== trim($row->propiedad)) {
$propiedad = trim($row->propiedad);
$calendar[$propiedad] = array_fill(1, $sda, '');
$property[$propiedad]['link'] = trim($row->link_ingles);
$property[$propiedad]['zone'] = trim($row->zona);
$property[$propiedad]['sleep'] = trim($row->duermen);
}
if ($row->propiedad!== trim($row->test)){
$propiedad = trim($row->propiedad);
$calendar[$propiedad] = array_fill(1, $sda, '');
}
elseif ($row->propiedad== trim($row->test)){
$larga = ($row->tiporeserva);
$begin = ($row->llegadaMonth == $lmo)? $row->llegadaDay : 1;
$end = ($row->salidaMonth == $lmo)? $row->salidaDay : $sda;
foreach (range($begin, $end) as $day) {
$calendar[$propiedad][$day] = 'N';
if ($larga=="larga") {
$calendar[$propiedad][$day] = 'L'; }
}
}
}
?><div align="center">
<?php
print "<table class='availability'>\n";
print "<tr> \n";
print"<th class='ancho127' colspan='34'> <p>Villas 3-5 bedrooms <span class='style1'>(8-14 persons)</span> <br />
</p></th>\n";
print"</tr> \n";
print "<tr>\n\t<td></td>\n";
print "\n\t<td>*</td>\n";
print "\n\t<td>**</td>\n"; $weekends = array(); // initialize
foreach (range($lda, $sda) as $day) { $class = (in_array(date('w', mktime(0, 0, 0, $lmo, $day, $lyr)), array(0, 6)))? ' class="weekend"' : '';
print "\t<td $class>$day</td>\n";// Populate an array with the weekend dates:
if ($class) { $weekends[] = $day; } }
print "</tr>\n";
foreach ($calendar as $propiedad => $bookings) {
foreach ($weekends as $weekend) {
$bookings[$weekend] = '#WEEKEND#' . $bookings[$weekend];
}
$bookings = '<th>' . implode("</td>\n\t<th>", $bookings) . '</th>';
$bookings = preg_replace("/<th>#WEEKEND#/", '<th class="weekend">', $bookings);
$link = $property[$propiedad]['link'];
$zone = htmlentities($property[$propiedad]['zone']);
$sleep = htmlentities($property[$propiedad]['sleep']);
$propiedad = str_replace("_", " ", $propiedad);
print "<tr>\n\t<td class='casa1'><a href=\"$link\">" . htmlentities($propiedad) . "</a></td>";
print "\n\t<th>$sleep</th>\n\t<th>$zone</th>\n\t $bookings\n</tr>\n"; }
print "<tr>\n\t<td></td>\n";
print "\n\t<td>*</td>\n";
print "\n\t<td>**</td>\n"; $weekends = array(); // initialize
foreach (range($lda, $sda) as $day) { $class = (in_array(date('w', mktime(0, 0, 0, $lmo, $day, $lyr)), array(0, 6)))? ' class="weekend"' : '';
print "\t<td $class>$day</td>\n";// Populate an array with the weekend dates:
if ($class) { $weekends[] = $day; }
}
print "</tr>\n";
print '</table><br /><br />';
?></div>