<?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);
	 
	 $ligne_par_page = 8;
	 
	 $res = mysql_query('SELECT COUNT(*) AS total FROM clients') OR die(mysql_error());
	 $row = mysql_fetch_assoc($res);
	  
	$nb_enregistrement = $row['total'];
	 
	echo $nb_enregistrement; 
	
	 
	echo $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 
	
	 
	 
	 //$data_client = mysql_fetch_array($result); 
	 
	 //var_dump($data_client);
	 
	 //$nombre = mysql_num_rows($result);	
	 // on a trouver un clients 
	 //if($nombre > 0)	
	 // {      $result = mysql_query($requete);
	 // 	 $data_client = mysql_fetch_array($result);
	 // }
	 
	 
?>	 


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Administration :: Patrice Delpy</title>

<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 clients</div>
		<div id="list">
		<table class="list">
	        <tr>
	        <th align="center" width="1%"> </th>
	        <th align="center" width="1%"> </th>
	        <th align="center" width="1%"> </th>
		<th width="*%" align="left">Nom - prénom</th>
		<th width="*%" align="left">Email</th>
		<th width="*%" align="left">Identifiant</th>
		<th width="*%" align="left">Password</th>
		<th width="*%" align="left">Adresse</th>
		<th width="*%" align="left">Complement</th>
		<th width="*%" align="left">Cp</th>
		<th width="*%" align="left">Ville</th>
	        <th width="*%" align="left">Téléphone</th>
		<th width="*%" align="center">Compte</th>
		<th width="*%" align="center">Supprimer</th>
		
		
		</tr>
        

<?php

	// La requ�te sql pour r�cup�rer les messages de la page actuelle.
$retour_messages=mysql_query('SELECT * FROM clients ORDER BY id DESC LIMIT '.$premiereEntree.', '.$ligne_par_page.'');

		while($data=mysql_fetch_assoc($retour_messages)) 

		//while($data = mysql_fetch_array($result,MYSQL_ASSOC))
		     {
		     	
		     	$nom = $data['nom'];
		     	$prenom = $data['prenom'];
		     	$client = $data['prenom']. " " .$data['nom'];
		     	$email = $data['email'];
		     	$identifiant=$data['identifiant'];
		     	$password=$data['password'];
		     	$telephone=$data['telephone'];
		     	
			$adresse=$data['adresse'];
		     	$complement=$data['complement'];
		     	$cp=$data['cp'];
		     	$ville=$data['ville'];
		     	$age=$data['age'];
		     	$statut_compte=$data['statut_compte'];

			//$info = $data['date']. " " .$data['heure'];
			//$montant = $data['total_ttc'];
		     	
		   	echo "	
		       		<tr class=\"row2\" onmouseover=\"this.className='highlight'\" onmouseout=\"this.className='row2'\">
		       		
<td align=\"center\"><a href=\"commandes.php?email=$email&nom=$nom&prenom=$prenom\"><img src=\"view_cmd.png\" border=\"0\" alt=\"View\" title=\"Voir les commandes du client\" /></a></td>

<td align=\"center\"><a href=\"edition.php?email=$email&nom=$nom&prenom=$prenom\"><img src=\"update.png\" border=\"0\" alt=\"View\" title=\"Editer le compte du client\" /></a></td>
		
<td align=\"center\"><a href=\"envoi_email.php?email=$email&nom=$nom&prenom=$prenom\"><img src=\"email_send.png\" border=\"0\" alt=\"View\" title=\"Envoyer un mail au client\" /></a></td>


			 
		       		
		       		<td align=\"left\" nowrap=\"nowrap\">$client</td>
		       		<td align=\"left\" nowrap=\"nowrap\">$email</td>
		       		<td align=\"left\" nowrap=\"nowrap\">$identifiant</td>
		       		<td align=\"left\" nowrap=\"nowrap\">$password</td>
		       		<td align=\"left\" nowrap=\"nowrap\">$adresse</td>
		       		<td align=\"left\" nowrap=\"nowrap\">$complement</td>
		       		<td align=\"left\" nowrap=\"nowrap\">$cp</td>
		       		<td align=\"left\" nowrap=\"nowrap\">$ville</td>
		       		<td align=\"left\" nowrap=\"nowrap\">$telephone</td>
		       		
		       				      
		      		<td align=\"center\" nowrap=\"nowrap\"> 
		      		
		      		
		      		
		      		<b class=\"blue\">$statut_compte</b>
		      		</td>
 				
 				
		       		

		       		
		       		<td class=\"center\" width=\"1%\">
		       		<a href=\"pipo.php\">
		       		<img src=\"supprimer.png\" alt=\"Supprimer\" title=\"supprimer le compte client\" /></a>
		       		</td>
		       		</tr>  ";
		     }

			  
?>              
             
              </table>
		</div>

<?php
              
             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>