Page 1 sur 1

calendrier avec lien pour les mois

Posté : 23 juin 2007, 17:22
par popo
Bonjour, j'avais fait un calendrier avec des liens permettant de canger de mois.
Je l'avais fait en PHP4 mais après ma mise en jour en PHP5 les liens ne marchent plus!
Je ne comprend pas ou ca coincent.
Je vous met le code du calendrier en entier.
<?php
  global $month, $year;
    if (isset($_GET["month"])) {$month=$_GET["month"];}
  if (isset($_GET["year"])) {$month=$_GET["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');
  
  //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;

  // 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) {     
      foreach ($v1 as $date) {    
                
        $sql = "Select Conge_Id,Conge_DateDeb,Conge_DateFin,Conge_NbJour,RTT_NbJour,Conge_Type,Conge_Salarie_Login 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'>"; 
          $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)) {            
          $deb_date = explode("-",$data['Conge_DateDeb']);  
          $fin_date = explode("-",$data['Conge_DateFin']); 
          $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_Login,Salarie_Nom from salarie where Salarie_Login='$data[Conge_Salarie_Login]'"; 
	          $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>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
	 echo "$date_month[$month] $year &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
	  echo '<a href="?month='.($month+1).'&year='.$year.'" alt="" >Suivant</a></p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
	  
	
    mysql_close();
    
    
?>	
Merci de votre aide

Posté : 24 juin 2007, 00:11
par sadeq
Corrige ici:
global $month, $year;
    if (isset($_GET["month"])) {$month=$_GET["month"];}
  if (isset($_GET["year"])) {$month=$_GET["year"];}
Enlève la ligne global ça ne sert que dans une fonction
et dans la 3° ligne remplace $month par $year

Comme ça:
if (isset($_GET["month"])) {$month=$_GET["month"];}
if (isset($_GET["year"])) {$year=$_GET["year"];}