Actualité du site
Création d'un calendrier
marc à écrit le 2007-12-03:
En ce mois de décembre, il est temps de mettre à jours vos calendrier.
J'ai commis ce petit script pour me dérouiller les neurones.
Il s'agit d'une fonction créant un calendrier pour un mois donné. Cette fonction peut optionnellement prendre en option une page de liens ainsi qu'un tableau d'evenements.
Janvier 2008
| Lu | Ma | Me | Je | Ve | Sa | Di |
| 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 |
function calendar($month,$year,$link=false,$event=FALSE)
{
$time=mktime(0,0,0,$month,1,$year);
$today = getdate($time);
$flag=FALSE;
$num=1;
$jour=array(0=>"Di ",1=>"Lu ",2=>"Ma ",3=>"Me ",4=>"Je ",5=>"Ve ",6=>"Sa ",7=>"Di ");
$mois=array(
1=>"Janvier",
2=>"Février",
3=>"Mars",
4=>"Avril",
5=>"Mai",
6=>"Juin",
7=>"Juillet",
8=>"Août",
9=>"Septembre",
10=>"Octobre",
11=>"Novembre",
12=>"Décembre");
echo "<table>";
echo "<h3>".$mois[$month]." $year</h3>";
echo "<tr>\n";
for ($i=1;$i<8; $i++)
{
echo"\t<td class=\"jour\"> ".$jour[$i]." </td>\n";
}
echo "</tr>\n";
for($semaine=0;$semaine<6;$semaine++)
{
echo "<tr>";
for ($i=1;$i<8; $i++)
{
$time=mktime(0,0,0,$month,$num,$year);
$today = getdate($time);
echo"\t<td";
if($today[wday]==$i||($today[wday]==0 && $i==7))
{
$flag=TRUE;
}
if ($flag&&!(checkdate($month,$num,$year)))
{
$flag=FALSE;
}
if ($flag)
{
echo" class=\"day$i\"";
}
echo">";
if ($flag)
{
echo "\n\t\t";
if(($link&&!$event)||($link&&$event&&in_array($num,$event)))
{
echo"<b><a href=\"$link?d=$num&m=$month&y=$year\">";
}
echo $num++;
if(($link&&!event)||($link&&$event&&in_array($num,$event)))
{
echo "</a></b>";
}
}
echo"\n\t</td>\n";
}
if(!$flag)
{
echo "</tr>\n";
break;
}
echo "</tr>\n";
}
echo "</table><br/>";
}
Ajouter un commentaire
Haut de page
