popline
Invité n'ayant pas de compte PHPfrance
11 déc. 2006, 14:12
bonjour,j'avais fait un calendrier en php lors d'un stage avec la possibilité de consulter les mois suivant et précédents du mois en cours.Il marchait et si je l'utilise chez moi les clic premettant de voir le mois suivant e précédents ne marchent pas on voit toujours le mois acutel.
<?php
global $month, $year;
include ('connexion.php');
// traduction du mois et du jour.
//-------------------------------------------------------------------
$date_month = array('1' => 'janvier', '2' => 'fevrier', '3' => 'mars', '4' => 'avril', '5' => 'mai', '6' => 'juin',
'7' => 'juillet', '8' => 'aout', '9' => 'septembre', '10' => 'octobre', '11' => 'novembre', '12' => 'decembre');
$date_day = array('Monday' => 'lundi', 'Tuesday' => 'mardi', 'Wednesday' => 'mercredi', 'Thursday' => 'jeudi',
'Friday' => 'vendredi', 'Saturday' => 'samedi', 'Sunday' => 'dimanche');
// On defini les parametres de la date actuelle.
//-------------------------------------------------------------------
$current_day = date('d', time());
$current_month = date('n', time());
$current_year = date('Y', time());
$today_date = date("Y-m-d");
// gestion des mois suivant et precedent.
//-------------------------------------------------------------------
if($month == null || $year == null) {
$month = $current_month;
$year = $current_year;
}
if ($month==0) {
$year='0'.$year-1;
$month = 12;
}
elseif ($month==13) {
$year='0'.$year+1;
$month = 1;
}
elseif ($year==-1) {
$year = 99;
$month = 12;
}
elseif ($year==100) {
$year = 00;
$month = 1;
}
// On convertie en format timestamp pour la reconnaisance du nombre de jour.
//-----------------------------------------------------------------------------------
$timestamp = mktime(0, 0, 0, $month, 1, $year);
$total_day = date('t', $timestamp); // Nombre de jours dans le mois
$numb_fisrt = date('w', $timestamp); // Jour de la semaine au format numérique; 0 (pour dimanche) à 6 (pour samedi)
$numb_fisrt -= 1; // On decremente car $numb_fisrt est incrementé ds la ligne precedente
if ($numb_fisrt == -1)
$numb_fisrt += 7;
// On cree ici le tableau avec toutes les jours du mois suivant les jours de semaine.
//-----------------------------------------------------------------------------------
for ($i = 0, $fill = 0; $i < 6; $i++)
{
for ($j = 0; $j < 7; $j++, $fill++)
{
if ($i == 0 AND $j < $numb_fisrt)
$var[$i][$j] = '';
elseif ($fill <= $total_day + $numb_fisrt - 1)
$var[$i][$j] = $fill - $numb_fisrt + 1;
else
$var[$i][$j] = '';
}
}
$i=0;
// Creation du tableau d'affichage
//-----------------------------------------------------------------------------------
echo "<table border='0' width='80%' align=center>";
echo "<tr align=center><td><font color=#0066cc>Lundi</font></td><td><font color=#0066cc>Mardi</font></td><td><font color=#0066cc>Mercredi</font></td><td><font color=#0066cc>Jeudi</font></td><td><font color=#0066cc>Vendredi</font></td><td><font color=#0066cc>Samedi</font></td><td><font color=#0066cc>Dimanche</td></tr>";
echo "<tr height='90'>";
foreach ($var as $v1) { // Affichage des données
foreach ($v1 as $date) { // du tableau var
$sql = "Select Conge_Id,Conge_DateDeb,Conge_DateFin,Conge_NbJour,Conge_Type,Conge_Salarie_Email from conge where Conge_Etat='valide'"; // On récupere tout les congés
$req = mysql_query($sql) or die('Error SQL !<br>'.$sql.'<br>'.mysql_error());
$color = ($date==date('d', time()) && $month == $current_month && $year == $current_year)?'darkred':'lightblue'; // On detecte si on visualise le mois actuel. si oui alors on coloris la case de l& date en rouge sinon on laisse en blue claire
if($i>=7) {
echo "</tr><tr height='110' valign='top'>"; // gestion des saut de ligne dans le tableau
$i=0;
}
echo "<td width='110' valign='top' bgcolor='$color'>";
echo "<table border='0' width='100%'>";
echo "<tr height='18'><td align='left' width='100%'>$date</td></tr>";
while($data = mysql_fetch_array($req)) { // pour chaque congé
$deb_date = explode("-",$data['Conge_DateDeb']); // extrait la date du debut
$fin_date = explode("-",$data['Conge_DateFin']); // extrait la date du fin
$date2 = $month;
$date3 = $year;
if($deb_date[2]<=$date and $fin_date[2]>=$date and $deb_date[1]<=$date2 and $fin_date[1]>=$date2 and $deb_date[0]<=$date3 and $fin_date[0]>=$date3){ // si la date correspond au bon interval on l'affiche
$sql2 = "Select Salarie_Email,Salarie_Nom from salarie where Salarie_Email='$data[Conge_Salarie_Email]'"; // on récupere le nom du salarié
$req2 = mysql_query($sql2) or die('Error SQL !<br>'.$sql2.'<br>'.mysql_error());
$affiche = mysql_fetch_array($req2);
echo "<tr height='18'><td align='left' width='100%'> - <font color='black' size='1' face='arial'>$affiche[Salarie_Nom] ($data[Conge_Type])</font></td></tr>";
}
}
echo "</table>";
echo "</td>";
$i++;
}
}
echo '</tr></table >';
// Gestion des lien precedent/suivant.
//-----------------------------------------------------------------------------------
echo '<p align=center><a href="?month='.($month-1).'&year='.$year.'" alt="" >precedent</a> ';
echo "$date_month[$month] $year ";
echo '<a href="?month='.($month+1).'&year='.$year.'" alt="" >Suivant</a></p> ';
mysql_close();
?>
merci de m'aider