soyons plus complet...
PHP :
<?php
// A gérer soi-même :
if(!$_GET['y']) $year=time('Y'); else $year=$_GET['y']; // Année
if(!$_GET['m']) $month=time('m'); else $month=$_GET['m']; // Mois
if(!$_GET['d']) $day=time('d'); else else $day=$_GET['d']; // Jour
// Précalculs :
$time=mktime(0,0,0,$month,1,$year); // Timestamp du mois
$jours_mois=date('t',$time); // Nombre de jours dans le mois
if($day>$jours_mois) $day=$jours_mois; // Dernier jour du mois
$firstday=(date('w',$time)+6)%7; // Premier jour de la semaine
// Liens mois et années
$previousmonthlink='?y='.($month<2?$year-1:$year).'&m='.($month<2?12:$month-1).'&d='.$day;
$nextmonthlink='?y='.($month>11?$year+1:$year).'&m='.($month>11?1:$month+1).'&d='.$day;
$previousyearlink='?y='.($year-1).'&m='.$month.'&d='.$day;
$nextyearlink='?y='.($year+1).'&m='.$month.'&d='.$day;
?>
<table class="cal" cellspacing="1">
<tr><th>L</th><th>M</th><th>M</th><th>J</th><th>V</th><th>S</th><th>D</th></tr>
<?
$tr=0;
echo '<tr>';
for($i=0;$i<$firstday;$i++) {
echo '<td> </td>';
$tr++;
}
for($i=1;$i<=$jours_mois;$i++) {
if($day==$i) {
echo '<td><a href="#" class="active">'.$i.'</a></td>';
} else {
echo '<td><a href="?y='.$year.'&m='.$month.'&d='.$i.'">'.$i.'</a></td>';
}
$tr++;
if($tr%7==0) echo '</tr><tr>';
}
$i=$tr%7;
for($j=$i;$j<7;$j++) {
echo '<td> </td>';
}
echo '</tr>';
?>
</table>
<p><a href="<? echo $previousyearlink; ?>">Année précédente</a>
<a href="<? echo $previousmonthlink; ?>">Mois précédent</a>
<? echo sprintf("%02d",$day).'/'.sprintf("%02d",$month).'/'.$year; ?>
<a href="<? echo $nextmonthlink; ?>">Mois suivant</a>
<a href="<? echo $nextyearlink; ?>">Année suivante</a></p>
?>
CSS :
/* Calendrier */
.cal {
background:#DBDBCD;
}
.cal th {
text-align:center;
background:#80806b;
color:#fff;
}
.cal td {
background:#DBDBCD;
text-align:center;
padding:0;
}
.cal td a {
display:block;
background:#E5E5D8;
text-decoration:none;
font-size:10px;
}
.cal td a.active {
background:#fff;
font-weight:bold;
}
.cal td a:hover {
text-decoration:none;
background:#fff;
}
(désolé pour les variables en anglais c'est l'habitude...)
Modifié par dew (30 Jun 2005 - 17:28)