<?php
	session_start();
	
	if($_SESSION['connexion'] != "ON")
 	  {	 header('Location: login.php');
	  }
	
	include('config_inc.php'); 
	include('fonction.php'); 
		
	if($_SESSION['database']=="local")
	  {
	     $db_host    = "localhost";
	     $db_user   = "root";
	     $db_pass   = "";
     	     $db_name   = "gestion_projet";

	 }
	
	if($_SESSION['database']=="public")
	  {
  	     $db_host    = "sql2";
   	     $db_user   = "analogde";
 	     $db_pass   = "rainbow";
    	     //$db_type   = "mysql";
	     $db_name   = "analogde";
	 }


	 $tab_projet= array();
	 $ligne_par_page = 8;
	 $selection = false;

	 $connexion = mysql_connect($db_host,$db_user,$db_pass); 
   	 mysql_select_db($db_name, $connexion);
   	 
   	 if( !isset($_POST['statut']) && !isset($_GET['position']) )
	   { $statut = "tous";
	     $requete = "SELECT * FROM projet";
	     $result = mysql_query($requete);
             $nb_enregistrement = mysql_num_rows($result);
             //echo "<BR>";
             //echo "par défaut";
             //echo "</BR>";
	     if($nb_enregistrement > $ligne_par_page)
	       {  $nombre_pages = ceil($nb_enregistrement/$ligne_par_page); 
	       }
	     if($nb_enregistrement <= $ligne_par_page)
	       { $nombre_pages = 1;
	       }	
	         $pageActuelle=1; 
		 $premiereEntree=($pageActuelle-1)*$ligne_par_page; 
		
	  }    	
	  	
	 if( isset($_GET['page']) ) 	
	   {  //echo "<BR>";
	      //echo "pagination";
	      //echo "</BR>";
	      $requete = "SELECT * FROM projet";
	      $result = mysql_query($requete);
              $nb_enregistrement = mysql_num_rows($result);
	      if($nb_enregistrement > $ligne_par_page)
	       {  $nombre_pages = ceil($nb_enregistrement/$ligne_par_page); 
	       }
	      if($nb_enregistrement <= $ligne_par_page)
	       { $nombre_pages = 1;
	       }
	      
	      
     	      $pageActuelle = $_GET['page']; 
     	      //echo "<BR>";
	      //echo "---->  " .$pageActuelle;
	      //echo "</BR>";
	      $premiereEntree=($pageActuelle-1)*$ligne_par_page; 
	  }	 
	  
	  if( isset($_GET['nom_projet'] )  && $_GET['mot'] != ""  ) 	
	   {  $nom_projet = $_GET['mot'];	
	      //echo "<BR>";
  	      //echo "Recherche  " .$nom_projet;
  	      //echo "</BR>";
	      $nombre_pages = 1;
  	      $pageActuelle=1; 
	      $premiereEntree=($pageActuelle-1)*$ligne_par_page; 
	      $selection = true;
	   }
	  
	  
	  if( isset($_GET['nom_projet'] )  && $_GET['mot'] == ""  ) 	
	    {	 
	    	 if( $_GET['nom_projet'] == "--[ Tous ]--")
	    	   { $nom_projet = $_GET['nom_projet'];
	    	  }	
	    	
	    	 else {
	    	 	$nom_projet = $_GET['nom_projet'];
	  	 	$nombre_pages = 1;
	  	 	$pageActuelle=1; 
		 	$premiereEntree=($pageActuelle-1)*$ligne_par_page; 
		 	$selection = true;
	     } 
	     
	        //echo "<BR>";
  	 	//echo "Selection  " .$nom_projet;
  	 	//echo "</BR>";
		 
	  }
	  
	  
	  
	  	 //echo "<BR>";
	  	 //echo "Nombres de pages  " .$nombre_pages;
	  	 //echo "</BR>";
	   	
	   	 //echo "<BR>";
	  	 //echo "Step  " .$premiereEntree;
	  	 //echo "</BR>";
		 
		if($_SESSION['logged_droits'] ==  "User")
		   {   include('menu_user.php');
		   }
		if($_SESSION['logged_droits'] ==  "Leader")
		   {   include('menu_leader.php');
		   }
		if($_SESSION['logged_droits'] ==  "Root")
		   {   include('menu_root.php');
		   }     


?>
 
			<div class="heading">Liste des projets</div><br>
		
			<form action="" method="GET" name="form_lister_projet">  &nbsp;&nbsp;&nbsp;
			Choix :
			
<?php				
	          	$connexion = mysql_connect($db_host,$db_user,$db_pass); 
   	          	mysql_select_db($db_name, $connexion);
		
  		  	echo " <select name=\"nom_projet\" size=\"1\" onChange=\"submit()\" id=\"\">  ";
  		  	
  		  	if($nom_projet != "")
	   		  {
  		  	   
  		  	     echo "<option selected=\"selected\" value=\"--[ Tous ]--\">$nom_projet</option> ";
  		  	     echo "<option value=\"--[ Tous ]--\">--[ Tous ]--</option> ";
  		  	 
  		  	  }
  		  	
  		  	if($nom_projet == "")
	   		  {
  		  	     echo "<option selected=\"selected\" value=\"--[ Tous ]--\">--[ Tous ]--</option> ";
  		  	  }
  		  	  		  	
  		  	 	
                  	$sql = "SELECT * FROM projet"; 
  		  	$req = mysql_query($sql, $connexion); 
  
			while($resultat = mysql_fetch_row($req))
  		  	     {  $tab_projet[]= $resultat[1];
    				echo '<option value="'.$resultat[1].'">'.$resultat[1]; 
    				echo '</option>'; 
  		  	     } 
   
  			echo '</select>'; 
	  
		        echo " <input type=\"text\" name=\"mot\"  value=\"\" size=\"15\"> ";
?>		    
		        <input type="submit" value="Rechercher" alt="Lancer la recherche!">
			
			</form>

			<div id="list">
			<table align="left" bgcolor="#d5d5d5" border="0" cellpadding="5" cellspacing="1" width="100%">
			<tbody><tr bgcolor="#f1f3f5">
			<th class="center" width="1%">Status</th>
			<th align="left" width="15%">Nom</th>
			<th align="left" width="*%">Famille</th>
			<th align="left" width="*%">Owner</th>
			<th align="left" width="*%">Date</th>
			<th align="left" width="*%">Heure</th>
			<th align="left" width="*%">Planning</th>
			<th class="center" width="1%">Edition</th>
			<th class="center" width="1%">Effacer</th>
			</tr>

<?php

		if($selection == true)
		  {
	  	    $requete = "SELECT * FROM projet where nom_projet='$nom_projet'";	
	            $retour = mysql_query($requete);
	            //echo "<BR>";
	            //echo "---->  simple";
	            //echo "</BR>";
		  }

		if($selection == false)
		  {
		    $requete="SELECT * FROM projet ORDER BY id DESC LIMIT $premiereEntree, $ligne_par_page ";
	            $retour = mysql_query($requete);
	            //echo "<BR>";
	      	    //echo "---->  multiple";
	      	    //echo "</BR>";
	          }

	
		while($data=mysql_fetch_assoc($retour)) 
		     {	
		     	$id = $data['id'];
		     	$nom = $data['nom_projet'];
		     	$famille = $data['famille'];
		       	$date = $data['date']; 
        		$date_creation = date_us_fr($date);
			$heure=$data['heure'];
			$status=$data['status'];
			$owner=$data['owner'];

			echo " 

			<tr class=\"row2\" onmouseover=\"this.className='highlight'\" onmouseout=\"this.className='row2'\">
<!--			<td class=\"center\"><img src=\"liste_article.php_fichiers/1.png\" alt=\"Active\" title=\"Actif\"></td>
			<td class=\"center\"><img src=\"liste_article.php_fichiers/3_1.jpg\" class=\"category\" height=\"30\" width=\"30\"></td>
-->			
			
			<td class=\"left\" nowrap=\"nowrap\">$status</td>
			<td class=\"left\" nowrap=\"nowrap\">$nom</td>
			<td class=\"left\">$famille</td>
			<td class=\"left\">$owner</td>
			<td class=\"left\">$date_creation</td>
			<td class=\"left\">$heure</td>
			
			<td class=\"center\" width=\"1%\">
			<a href=\"essai08.php?id=$id\">
			<img src=\"images/nb_article.png\" alt=\"Plannifier\" title=\"Plannifier\"></a>
			</td>
			
			<td class=\"center\" width=\"1%\">
			<a href=\"edition_projet.php?id=$id\">
			<img src=\"images/update.png\" alt=\"Modifier\" title=\"Modifier\"></a>
			</td>
						
			<td class=\"center\" width=\"1%\">
			<a href=\"supprimer_projet.php?nom=$nom\">
			<img src=\"images/delete.png\" alt=\"Supprimer\" title=\"Supprimer\"></a>
			</td> ";

		}				

		echo "	<tr bgcolor=\"#f1f3f5\">
			<td colspan=\"16\" class=\"center\">&nbsp;</td>
			</tr>
			
			</tbody></table>
			</div>  ";
                echo '<p align="center">Page : '; 
		
		 	for($i=1; $i<=$nombre_pages; $i++) 
		           {    		      		
     		       		if($i==$pageActuelle) //Si il s'agit de la page actuelle...
     			 	  {
         		   	     echo ' [ '.$i.' ] '; 
     		                  }	
     		             else {
				       echo ' <a href="lister_projet.php?position='.$statut.'&page='.$i.'">'.$i.'</a> ';

     			  	  }
		           }
		        echo '</p>';
	        
?>


		</body>
		</html>