<?php
include("include/data.php");
Init_boutique();
global $base, $MySQL_Host, $MySQL_User, $MySQL_Passw, $myart, $A_NumArt,$i, $result, 
$NbLigne, $mygroupeart, $mysousgroupeart, $semaine, $limitesuivante, 
$limiteprecedente, $limite, $total, $page, $Nom_Client, $semaine ;
// entete de la page

include 'menu/header.php';

if (!isset($_GET['search']) )
{
    $search=0;
    $search_sel=0;

} else {

	if (!empty($_GET['search']))
	{
	  $search=($_GET['search']);
      $search_sel=($_GET['search']);
	 } else {
	  $search=0;
      $search_sel=0;
	 }
}

/*
// test recuperation
echo "categorie_plu_intran : ".$Num_CatPlu." search : ".$search ;
*/

$limite=$_GET['limite'];
if (!isset($limite)) $limite = 0;
$nombre = 10;
$limitePage = 0 ;

$v='select * FROM clients_base ';
$selectc = 'SELECT count(Num_Client) FROM clients_base';

if (!empty($search)) {	
	    $v.=" WHERE LCASE (Nom_Client) LIKE LCASE ('%".$search."%')";
 	    $selectc.=" WHERE LCASE (Nom_Client) LIKE LCASE ('%".$search."%')";
 	    $v.=" AND IdNumClient='".$IdNumClient."'";
			$selectc.=" AND IdNumClient='".$IdNumClient."'";

 } else { 
      
      $v.=" WHERE `IdNumClient`='".$IdNumClient."'";
			$selectc.=" WHERE `IdNumClient`='".$IdNumClient."'";
     }

$v.=' ORDER BY 	Num_Client ASC limit '.$limite.','.$nombre;

$SelectEA = $v ;

echo "<center>";

 // on va afficher 10 résultats par page.
$limitesuivante = $limite + $nombre;
$limiteprecedente = $limite - $nombre;
$result = mysqli_query($link, $selectc);
$row = mysqli_fetch_row($result);
$total = $row[0];
$NbPage = floor($total/10);
/*
// test donneee
echo "<center><HR size='2' width='500'>";
echo "v : ".$v."<br> SelectEA : ".$SelectEA;
echo "<HR size='2' width='500'>";
echo " total : $NbPage | $total | $semaine |  $search <br></center>" ;
*/
echo "<div class='titre-text'><center>Fichier Clients</div></center><br>" ;

// Filtres 

echo "<form id='form1' name='form1' method='get' action='clients_bases.php'>";
echo "<input type='hidden' name='limite' value='$limite'/>";
Echo "<table cellspacing=0 cellpadding=0 align=center border=0>";
Echo "<tr><td><span class='t-text'><center>FILTRES<br><HR size='1' width='500'></center></td></tr>";
echo "<tr class='text'>";
echo "<td><center>Mot cle : <input type='text' name='search' placeholder='Ex : sel' autofocus size='25'><input type='submit' value='ok'></center></td>";
Echo "</tr>";
Echo "</span>";
Echo "</table>";
echo "</form></center>";
/*
echo "total : ".$total."| limite  ".$limite."<br> limite suivante ".$limitesuivante."| limite precedente".$limiteprecedente ."<br>";
*/

// sous Menu 1

echo "<center><HR size='1' width='500'>";
echo "<table cellspacing=0 cellpadding=0 align=center border=0>";
echo "<td>";
echo "<a href='ajout_bases_clients.php'><b>Nouveau</b></a> <b> | </b>";
echo "<a href=''><b>Consulter</b></a> <b> | </b>";
echo "<a href=''><b>Supprimer</b></a> <b> | </b>";
echo "<a href=''><b>Modifier</b></a> <b> | </b>";
echo "<a href=''><b></b></a><b></b>";
echo "</td></tr>";
echo "</tbody>";
echo "</table><br>";

// Corps de page

//echo "<br>" ;
echo "<table border='1' cellpadding='1' cellspacing='1' width='800' height='22'><tr>";
echo "<td width='50' height='20' valign='center' bgcolor='#CCCCCC'>
	<div align='center'><span class='t-text'>N&#176; client</div></td></span>";
echo "<td width='100' height='20' valign='center' bgcolor='#CCCCCC'>
	<div align='center'><span class='t-text'>Nom client</td></span>";
echo "<td width='100' height='20' valign='center' bgcolor='#CCCCCC'>
	<div align='center'><span class='t-text'>Adresse</td></span>";
echo "<td width='100' height='20' valign='center' bgcolor='#CCCCCC'>
	<div align='center'><span class='t-text'>ville client</td></span>";
echo "<td width='32' height='20' valign='center' bgcolor='#CCCCCC'>
	<div align='center'><span class='t-text'>Cd T</td></span>";
echo "<td width='32' height='20' valign='center' bgcolor='#CCCCCC'>
	<div align='center'><span class='t-text'>M</td></span>";
echo "<td width='32' height='20' valign='center' bgcolor='#CCCCCC'>
	<div align='center'><span class='t-text'>D</td></span>";
echo "</tr>";

$myart =new clients_base;
$result = mysqli_query($link, $SelectEA);
$myart->getnum($result);
while ($myart->z < $myart->num) {
  $myart->readrow($result);
  $Num_Client_Base=$myart-> Num_Client_Base ;
  $Num_Client=$myart-> Num_Client ;   
  $Nom_Client=$myart-> Nom_Client ;  
  $Adresse_1=$myart-> Adresse_1	;	
  $Adresse_2=$myart-> Adresse_2 ;  	
  $Adresse_3=$myart-> Adresse_3 ;     
  $Code_Postal=$myart-> Code_Postal ;
  $Ville=$myart-> Ville ;
  $Telephone=$myart-> Telephone	;	
  $Portable=$myart->  Portable ;     
  $Email=$myart-> Email ;
  $Code_tarif=$myart-> Code_tarif ;
  

    echo "<tr><td width='50' height='20' valign='center'>
	<div align='center'><span class='t-text'>$Num_Client</div></td></span>";
	echo "<td width='100' height='20' valign='center'>
	<div align='center'><a class='' href='consult_plu_intrants.php?Num_entre=$Num_Client_Base'><span class='t-text'>$Nom_Client</div></a></td></span>";
	echo "<td width='100' height='20' valign='center'>
	<div align='center'><span class='t-text'>$Adresse_1</div></td></span>";
	echo "<td width='100' height='20' valign='center'>
	<div align='center'><span class='t-text'>$Code_Postal - $Ville</div></td></span>";
	echo "<td width='32' height='20' valign='center'>
	<div align='center'><span class='t-text'>$Code_tarif</div></td></span>";
	echo "<td width='32' height='20' valign='center'>
	<div align='center'><a class='' href='modif_bases_clients.php?Num_entre=$Num_Client_Base'><img src='images/modifie.png' width='20' height='20'></a></div></td>";
	echo "<td width='32' height='20' valign='center'>
	<div align='center'><a class='' href='traitement_delette_clients_base.php?Num_entre=$Num_Client_Base&conf=2'><img src='images/pblle.jpg' width='20' height='20'></a></div></td></tr>";

} 
echo "</tr></table><br>";

echo "<center>";

echo "<table border='1' cellpadding='0' cellspacing='0' width='500' height='22'><tr>";
echo "<td width='120' height='20' valign='center'><div align='center'><span class='t-text'>";
	 
if($limite != 0) {
    echo '<a href="'.$page.'?limite='.$limiteprecedente.'">Page precedente  </a>';
}

for ($a = 1; $a <= $NbPage ; $a++) {
    $limitePage = $nombre + $limitePage;
    echo '<a href="'.$page.'?limite='.$limitePage
    .'&search='.$search
    .'">'.$a.'</a> | ';
}
//

//
if($limitesuivante < $total) 
{
echo '<a href="'.$page.'?limite='.$limitesuivante
.'&search='.$search
.'">Page Suivante</a>';
}
echo "</div></td></span>";
echo "";
echo "</tr></table>";


include 'menu/footer.php';
?>
