<?php

	session_start();
	
	$_SESSION['database']="local";
	
	if($_SESSION['database']=="local")
	  {
	     $db_host    = "localhost";
	     $db_user   = "root";
	     $db_pass   = "";
     	     $db_name   = "boutique";

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

	 $connexion = mysql_connect($db_host,$db_user,$db_pass); 
   	 mysql_select_db($db_name, $connexion);
   	 
   	 
   	 if( isset($_GET['liste_table']) && !empty($_GET['liste_table']) ) 
	  { 	
	  	//echo $_GET['liste_table'];
	  
	    	//if($_GET['liste_table'] =="3")
	      	//  { $nom_table = "refrigerateur";
	            //echo $nom_table;
	      //	 }	
	    //else $nom_table = "lave_linge";  	
	    //header("Location: http://www.monsite.net/plan.html");
	  
	    
	    $nom_table = $_GET['liste_table'];
	    
	    
	  }	
   	 
   	 else { $nom_table = "";  
	      }	
	 
	 if($nom_table != "")
	   {
	 	$ligne_par_page = 8;
	 
	 	$contenu = "SELECT COUNT(*) AS total FROM "  .$nom_table ;
	 
	 	$res = mysql_query($contenu) OR die(mysql_error());
	 
	 	//$res = mysql_query('SELECT COUNT(*) AS total FROM $nom_table' ) OR die(mysql_error());
	 	$row = mysql_fetch_assoc($res);
	  
	 	$nb_enregistrement = $row['total'];
	 
		 //echo $nb_enregistrement; 
		 $nombre_pages=ceil($nb_enregistrement/$ligne_par_page); 
	 
	 	if(isset($_GET['page'])) 
           	{
     			$pageActuelle=intval($_GET['page']);
     
     			// Si la valeur de $pageActuelle (le numéro de la page) est plus grande que $nombreDePages...
     			if($pageActuelle>$nombre_pages) 
     		  	  {
          			$pageActuelle=$nombre_pages;
     		  	  }
	 	}

		else  {
     			$pageActuelle=1; // La page actuelle est la n°1    
	      	      }

		$premiereEntree=($pageActuelle-1)*$ligne_par_page; // On calcul la première entrée à lire 

	}	

	



?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html dir="ltr" lang="en">

<head>

<title>Administration - En cours de développement</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">



<meta http-equiv="Pragma" content="no-cache">
  
<link rel="stylesheet" href="default.css" type="text/css">
  
</head>
<body>

<div id="header"><h1>Administration</h1>
<div class="membre">Vous Ãªtes connectÃ© en tant que <b><?php echo $_SESSION['admin_identifiant']; ?> </b></div>
</div>
 
<?php include('menu.php'); ?>
 
			<div class="heading">Liste des articles</div><br>
		
			<form action="articles.php" method="GET" name="categoryList">  &nbsp;&nbsp;&nbsp;
			Choix de la catégorie :
			<!--  <input value="Voir les articles pour la catÃ©gorie -&gt;" type="submit"> -->

<?php				
	          	$connexion = mysql_connect($db_host,$db_user,$db_pass); 
   	          	mysql_select_db($db_name, $connexion);
		
  		  	echo " <select name=\"liste_table\" size=\"1\" onChange=\"submit()\" id=\"liste_table\">  ";
  		  	
  		  	if($nom_table != "")
	   		  {
  		  	    echo "<option selected=\"selected\" value=\"X\">$nom_table</option> ";
  		  	 
  		  	  }
  		  	
  		  	if($nom_table == "")
	   		  {
  		  	     echo "<option selected=\"selected\" value=\"X\">--[ Toutes ]--</option> ";
  		  	  }
  		  	  		  	
  		  	 	
                  	$sql = "SELECT * FROM categorie"; 
  		  	$ReqLog = mysql_query($sql, $connexion); 
  
			while($resultat = mysql_fetch_row($ReqLog))
  		  	     { 
    				echo '<option value="'.$resultat[1].'">'.$resultat[1]; 
    				echo '</option>'; 
  		  	     } 
   
  			echo '</select>'; 
  			
  			//<select name="liste_table" size="1" onChange="submit()" id="liste_table">
			//<option selected="selected" value="X">--[ Toutes ]--</option>
			//<option value="1">lave-linge    </option>
			//<option value="3">refrigerateur    </option>
			//</select>
  			
?>
			
			</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 class="center" width="1%">Image</th>
			<th align="left" width="15%">RÃ©fÃ©rence</th>
			<th align="left" width="*%">Produit</th>
			<th align="left" width="*%">Marque</th>
			<th align="left" width="*%">Fournisseur</th>
			<th align="center" nowrap="nowrap" width="5%">Prix TTC</th>
			<th align="center" nowrap="nowrap" width="5%">Prix HT</th>
			<th align="center" nowrap="nowrap" width="5%">TVA</th>
			<th align="center" nowrap="nowrap" width="5%">Remise</th>
			<th align="center" width="5%">Stock</th>
			<th class="center" width="1%">Edition</th>
			<th class="center" width="1%">Caractéristiques</th>
			<! -- <th class="center" width="1%">Générer</th> -->
			<th class="center" width="1%">Ajouter</th>


			<th class="center" width="1%">Effacer</th>
			</tr>

<?php

	if($nom_table != "")
	   {
		
		$retour_messages=mysql_query('SELECT * FROM '.$nom_table.' ORDER BY id DESC LIMIT '.$premiereEntree.', '.$ligne_par_page.'');

		while($data=mysql_fetch_assoc($retour_messages)) 
		     {	
		     	$status = $data['status'];
		     	$marque = $data['marque'];
		     	$id_catalogue = $data['id_catalogue'];
		       	$fournisseur = $data['fournisseur'];
		     	$designation=$data['designation'];
		     	$reference=$data['reference'];
		     	$tva=$data['tva'];
			$ttc=$data['prix_ttc'];
			$ht=$data['prix_ht'];
			$remise=$data['remise'];
			$image=$data['image'];
			
			
			$tab_remise = explode(" ", $remise);
			
			if($tab_remise[0] == "pourcent")
			  { $remise = $tab_remise[1] ." %"; 
			  }
			
			if($tab_remise[0] == "euro")
			  { $remise = $tab_remise[1] ." E"; 
			  }
			
			if($tab_remise[0] == "aucune")
			  { $remise = "Aucune"; 
			  }  
			  
			
			$stock=$data['stock'];

			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>
			
			// lien pour l'image
			<td class=\"center\" width=\"1%\">
			<a href=\"vignette.php?id=$id_catalogue&table=$nom_table\">$image</a>
			</td>
			
			<td class=\"left\" nowrap=\"nowrap\">$id_catalogue</td>
			
			
			<td class=\"left\">$reference</td>
			<td class=\"left\">$marque</td>
			<td class=\"left\">$fournisseur</td>
			
			
			<td class=\"right\" nowrap=\"nowrap\">&nbsp;$ttc&nbsp;â‚¬&nbsp;</td>
			<td class=\"right\" nowrap=\"nowrap\">&nbsp;$ht&nbsp;â‚¬&nbsp;</td>
			<td class=\"right\" nowrap=\"nowrap\">&nbsp;$tva &nbsp;%&nbsp;</td>
			
			<td class=\"left\">$remise</td>
			<td class=\"left\">$stock</td>
			
			
			
<!--			<td class=\"right\" nowrap=\"nowrap\">&nbsp;<b class=\"green\">10.00 %</b>&nbsp;</td>
			<td class=\"center\" nowrap=\"nowrap\">&nbsp;<b class=\"green\">900</b>&nbsp;</td>
-->			
			<td class=\"center\" width=\"1%\">
			<a href=\"edition_article.php?id=$id_catalogue&table=$nom_table\">
			<img src=\"images/update.png\" alt=\"Modifier\" title=\"Modifier\"></a>
			</td>
			
			<td class=\"center\" width=\"1%\">
			<a href=\"edition_descriptif.php?id=$id_catalogue&table=$nom_table\">
			<img src=\"images/carac16.png\" alt=\"descriptif de l'article\" title=\"descriptif\"></a>
			</td>
			
			<td class=\"center\" width=\"1%\">
			<!-- <a href=\"generation.php?id=$id_catalogue&table=$nom_table\"> -->
			<a href=\"ajouter_caracteristiques.php?id=$id_catalogue&table=$nom_table\">
			
			<img src=\"images/process.png\" alt=\"filtre\" title=\"filtre\"></a>
			</td>
			
			<td class=\"center\" width=\"1%\">
			<a href=\"index.php\">
			<img src=\"images/delete.png\" alt=\"Effacer\" title=\"Effacer\"></a>
			</td>
			</tr> ";

		}				

		echo "	<tr bgcolor=\"#f1f3f5\">
			<td colspan=\"15\" class=\"center\">&nbsp;</td>
			</tr>
			
			</tbody></table>
			</div>  ";
              
	        echo '<p align="center">Page : '; //Pour l'affichage, on centre la liste des pages
		
	        for($i=1; $i<=$nombre_pages; $i++) //On fait notre boucle
		   {
     		      //On va faire notre condition
     		       if($i==$pageActuelle) //Si il s'agit de la page actuelle...
     			 {
         		   echo ' [ '.$i.' ] '; 
     		         }	
     		       else //Sinon...
     			  {
          		     echo ' <a href="clients.php?page='.$i.'">'.$i.'</a> ';
     			  }
		   }
		echo '</p>';
        
	       }
?>


</body></html>