<?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['Num_CatPlu']))
{
    $Num_CatPlu=0;
    $Num_CatPlu_sel=0;
} else {
    $Num_CatPlu=($_GET['Num_CatPlu']);
    $Num_CatPlu_sel=($_GET['Num_CatPlu']);
}

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 plu_intrant ';
$selectc = 'SELECT count(Num_plu_intrant) FROM plu_intrant';
if (($search || $Num_CatPlu )>0) {
$v.=' WHERE' ;
$selectc.=' WHERE' ;
} else { 
    $v.=" WHERE `IdNumClient`='".$IdNumClient."'";; 
    $selectc.=" WHERE `IdNumClient`='".$IdNumClient."'";;
    }

if ($Num_CatPlu==0) {
$v.='';
$selectc.='';
 } else { 
    $v.=' num_cate_intrant='.$Num_CatPlu; 
    $selectc.=' num_cate_intrant='.$Num_CatPlu; 
     }

if (!empty($search)) {	
		if ($Num_CatPlu==0) {
        $v.=" LCASE (nom_plu_intrant) LIKE LCASE ('%".$search."%')";
 	    $selectc.=" LCASE (nom_plu_intrant) LIKE LCASE ('%".$search."%')";
 } else { 
        $v.=" AND LCASE (nom_plu_intrant) LIKE LCASE ('%".$search."%')";
 	    $selectc.=" AND LCASE (nom_plu_intrant) LIKE LCASE ('%".$search."%')";
     }
	$v.='';
	$selectc.='';
}
$v.=" AND IdNumClient='".$IdNumClient."'";
$v.=' ORDER BY num_plu_intrant DESC 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 donnees
echo "<center><HR size='2' width='500'>";
echo "v : ".$v."<br> SelectEA : ".$SelectEA;
echo "<HR size='2' width='500'>";
echo " total : $NbPage | $total | $semaine | $Num_CatPlu | $search <br></center>" ;
*/

// Filtres 

echo "<form id='form1' name='form1' method='get' action='saisie_intrants.php'>";
echo "<input type='hidden' name='limite' value='$limite'/>";
Echo "<table cellspacing=0 cellpadding=0 align=center border=0>";
Echo "<tr><td colspan=5><span class='t-text'><center>FILTRES<br><HR size='1' width='500'></center></td></tr>";
echo "<tr class='text'>";

echo "<td>Par Cat&eacute;gorie : <select style=' width: 150px;' name='Num_CatPlu' id='Num_CatPlu'>";
echo "<option value='0'>Toutes</option>";
$myart =new categorie_intrant;
$select = 'select * FROM categorie_intrant';
$result = mysqli_query($link, $select);
$myart->getnum($result);
while ($myart->z < $myart->num) {
  $myart->readrow($result);
  $num_cate_plu_intran=$myart->num_cate_plu_intran ;
  $categorie_plu_intran=$myart->categorie_plu_intran ;
  echo "<option value='$num_cate_plu_intran'>$num_cate_plu_intran | $categorie_plu_intran</option>";
}

echo "</select>";
echo "</td>";
echo "<td>Mot cle : <input type='text' name='search' placeholder='Ex : sel' autofocus ></td>";
echo "<td><input type='submit' value='ok'>";
echo "</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_plu_intrant.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 "</td></tr>";
echo "</tbody>";
echo "</table><HR size='1' width='500'>";

// Corps de page

//echo "<br>" ;
echo "<table border='1' cellpadding='1' cellspacing='1' width='700' height='22'><tr>";
echo "<td width='30' height='20' valign='center' bgcolor='#CCCCCC'>
	<div align='center'><span class='t-text'>N&#176;</div></td></span>";
echo "<td width='100' height='20' valign='center' bgcolor='#CCCCCC'>
	<div align='center'><span class='t-text'>Nom intrant</td></span>";
echo "<td width='50' height='20' valign='center' bgcolor='#CCCCCC'>
	<div align='center'><span class='t-text'>Cat&#233;gorie</td></span>";
echo "<td width='50' height='20' valign='center' bgcolor='#CCCCCC'>
	<div align='center'><span class='t-text'>DLC</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 plu_intrant;
$result = mysqli_query($link, $SelectEA);
$myart->getnum($result);
while ($myart->z < $myart->num) {
  $myart->readrow($result);
  $num_plu_intant=$myart->num_plu_intrant ;
  $nom_plu_intrant=$myart->nom_plu_intrant ;
  $num_cate_intrant=$myart->num_cate_intrant ;
  $dlc_plu_intrants =$myart->dlc_plu_intrant ;
 
$sql = "SELECT categorie_plu_intran FROM categorie_intrant WHERE num_cate_plu_intran='$num_cate_intrant'";  
$req =   mysqli_query($link, $sql) ;
 while ($row = mysqli_fetch_assoc($req)) {
        $categorie_plu_intrant = $row["categorie_plu_intran"];
    }
/*
echo "<br>".$categorie_plu_intran ;
$date_e=date("d/m/Y", strtotime($Date_Entre));
echo  date("d/m/Y", strtotime($Date_Entre))." ".$date_e;
*/
  
    echo "<tr><td width='30' height='20' valign='center'>
	<div align='center'><span class='t-text'>$num_plu_intant</div></td></span>";
	echo "<td width='100' height='20' valign='center'>
	<div align='center'><a class='' href='consult_plu_intrants.php?Num_entre=$num_plu_intant'><span class='t-text'>$nom_plu_intrant</div></a></td></span>";
	echo "<td width='50' height='20' valign='center'>
	<div align='center'><span class='t-text'>$categorie_plu_intrant</div></td></span>";
	echo "<td width='50' height='20' valign='center'>
	<div align='center'><span class='t-text'>$dlc_plu_intrants jrs</div></td></span>";
	echo "<td width='20' height='20' valign='center'>
	<div align='center'><a class='' href='modif_plu_intrant.php?Num_entre=$num_plu_intant'><img src='images/modifie.png' width='20' height='20'></a></div></td>";
	echo "<td width='20' height='20' valign='center'>
	<div align='center'><a class='' href='delette_plu_intrant.php?num_plu_intant=$num_plu_intant&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
    .'&Num_CatPlu='.$Num_CatPlu_sel
    .'&search='.$search
    .'">'.$a.'</a> | ';
}
//

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


include 'menu/footer.php';
?>
