1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
| <?php
function reservation()
{
//-- tableau pour simuler une BDD --------------------------------
$reservation = array(
'2008-01-05',
'2008-02-16',
'2008-03-29',
'2008-04-12',
'2008-05-10',
'2008-08-30',
'2008-10-11',
'2008-12-20',
);
return $reservation;
}
function chercheBorne($jour, $numJourDeb, $jourDeb, $decalage)
{
$tsDate = strtotime($jour);
if(date('N', $tsDate) != $numJourDeb)
{
$tsDate = strtotime($decalage . ' ' . $jourDeb, $tsDate);
}
return $tsDate;
}
function creeDate($tsDeb, $tsFin)
{
while ($tsDeb <= $tsFin)
{
$mois = strftime('%B', $tsDeb);
$date[$mois][] = $tsDeb;
$tsDeb = strtotime('next week', $tsDeb);
}
return $date;
}
function affichage($date, $annee)
{
$reservation = reservation();
$tableau = '';
foreach($date as $cle => $valeur)
{
$fin = (sizeof($valeur) < 5) ? '<td> </td>' : '';
$tableau .= '<tr><td>' . $cle . '</td>';
foreach ($valeur as $tsJour)
{
$couleur = (! in_array(date('Y-m-d', $tsJour), $reservation)) ? ' bgcolor="#99FF99"' : '';
$tableau .= '<td' . $couleur . '>' . date('d', $tsJour) . '</td>';
}
$tableau .= $fin . '</tr>' . "\n";
}
return $tableau;
}
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
setlocale (LC_TIME, 'fr_FR.utf8','fra');
$annee = (isset($_GET['annee'])) ? $_GET['annee'] : date('Y');
$numJourDeb = (isset($_GET['jour'])) ? $_GET['jour'] : 6;
$jourDeb = ($numJourDeb == 6) ? 'saturday' : 'sunday';
$tsDeb = chercheBorne($annee . '-01-01', $numJourDeb, $jourDeb, 'next');
$tsFin = chercheBorne($annee . '-12-31', $numJourDeb, $jourDeb, 'last');
$date = creeDate($tsDeb, $tsFin);
$page = $_SERVER['PHP_SELF'];
$nomJourDeb = strftime('%A', $tsDeb);
$anneePrecedente = date('Y', strtotime('last year', $tsDeb));
$anneeSuivante = date('Y', strtotime('next year', $tsDeb));
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>test</title>
<script type="text/javascript">
</script>
</head>
<body onload="// init()">
<table align="center" border="1">
<tr>
<td colspan="6">DISPONIBILITES <?php echo $annee; ?></td>
</tr>
<tr>
<td width="23" bgcolor="#99FF99"class="td3"></td>
<td height="5" colspan="6" class="td3"><div align="left">Disponible</div></td>
</tr>
<tr >
<td colspan="6" class="td6"><div align="center">Semaines débutant un <?php echo $nomJourDeb; ?></div></td>
</tr>
<?php echo affichage($date, $annee); ?>
<tr>
<td width="199" colspan="6">
<div align="center">
<a href="<?php echo $page . '?annee=' . $anneePrecedente . '&jour=' . $numJourDeb; ?>"/><< <?php echo $anneePrecedente; ?></a>
- -
<a href="<?php echo $page . '?annee=' . $anneeSuivante . '&jour=' . $numJourDeb; ?>"/><?php echo $anneeSuivante; ?>>></a>
</div>
</td>
</tr>
<tr>
<td width="199" colspan="6">
<div align="center">jour début</div>
</td>
</tr>
<tr>
<td width="199" colspan="6">
<div align="center">
<a href="<?php echo $page . '?annee=' . $annee . '&jour=6' ?>"/>samedi</a>
- -
<a href="<?php echo $page . '?annee=' . $annee . '&jour=7' ?>"/>dimanche</a>
</div>
</td>
</tr>
</table>
</body>
</html> |
Partager