<?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';

/* http://192.168.1.200/orius/saisie_cf.php?limite=0&Num_CatPlu=2# */

if (!isset($_GET['Num_CatPlu']))
{
    $Num_CatPlu=0;
    $Num_CatPlu_sel=0;
} else {
    $Num_CatPlu=($_GET['Num_CatPlu']);
    $Num_CatPlu_sel=($_GET['Num_CatPlu']);
}



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

$v='select * FROM Base_CF ';
$selectc = 'SELECT count(Num_ligne_CF) FROM Base_CF';

if ($Num_CatPlu==0) {
$v.=" WHERE `IdNumClient`='".$IdNumClient."'";
$selectc.=" WHERE `IdNumClient`='".$IdNumClient."'";
 } else { 
    $v.=' WHERE num_cate_cf='.$Num_CatPlu; 
    $selectc.=' WHERE num_cate_cf='.$Num_CatPlu; 
    
    $selectc.=" AND IdNumClient='".$IdNumClient."'";
    $v.=" AND IdNumClient='".$IdNumClient."'";
     }


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

echo "<center>";
// Titre Page
echo "<div class='titre-text'><center>Base des Chambres Froides</div></center><br>" ;

 // 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> selectc : ".$selectc;
echo "<HR size='2' width='500'>";
echo "Nb Pages : $NbPage | Total Enrg $total | semaine $semaine | catePLU $Num_CatPlu <br></center>" ;
*/
// Filtres 

echo "<form id='form1' name='form1' method='get' action='#'>";
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' onchange='submit()'>";
echo "<option value='0'>Toutes</option>";

$sql = 'select * FROM categorie_CF';
$req = mysqli_query($link, $sql);  
while ($row = mysqli_fetch_assoc($req)) {
        $num_cate_plu_intran = $row["num_cate_cf"];
        $categorie_plu_intran = $row["categorie_cf"];
   echo "<option value='$num_cate_plu_intran'>$num_cate_plu_intran | $categorie_plu_intran</option>";
}

echo "</select>";
echo "</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='2' width='500'>";
echo "<table cellspacing=0 cellpadding=0 align=center border=0>";
echo "<td>";
echo "<a href='ajout_base_cf.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='750' 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 C.F</td></span>";
echo "<td width='100'  height='20' valign='center' bgcolor='#CCCCCC'><div align='center'><span class='t-text'>Cat&#233;gorie</td></span>";
echo "<td width='32'  height='20' valign='center' bgcolor='#CCCCCC'><div align='center'><span class='t-text'>T&deg; Min</td></span>";
echo "<td width='32'  height='20' valign='center' bgcolor='#CCCCCC'><div align='center'><span class='t-text'>T&deg; Max</td></span>";
echo "<td width='20'  height='20' valign='center' bgcolor='#CCCCCC'><div align='center'><span class='t-text'>M</td></span>";
echo "<td width='20'  height='20' valign='center' bgcolor='#CCCCCC'><div align='center'><span class='t-text'>D</td></span>";
echo "</tr>";

$req1 = mysqli_query($link, $v);  
while ($row = mysqli_fetch_assoc($req1)) {
				 $NumLigneCF = $row["Num_ligne_CF"];
	       $Num_CF = $row["Num_CF"];
	       $Nom_CF = $row["Nom_CF"];
			   $Temp_Min = $row["Temp_Min"];
			   $Temp_Max = $row["Temp_Max"];
			   $num_cate_cf = $row["num_cate_cf"];
	
//	$Nom_CF = htmlspecialchars($Nom_CF, ENT_QUOTES);
  
  $sql = 'select * FROM categorie_CF';
	$req = mysqli_query($link, $sql);  
	while ($row = mysqli_fetch_assoc($req)) {
        $num_cate_plu_intran = $row["num_cate_cf"];
        $categorie_plu_intran = $row["categorie_cf"];
   
   if ($num_cate_cf==$num_cate_plu_intran )
   $Nom_Cate_Cf=$categorie_plu_intran ;
   
}
  
  
  
  echo "<tr>";
  echo "<td width='30' height='20' valign='center'><div align='center'><span class='t-text'>$Num_CF</div></td></span>";
	echo "<td width='100' height='20' valign='center'><div align='center'><a class='' href='#'><span class='t-text'>$Nom_CF</div></a></td></span>";
	echo "<td width='100' height='20' valign='center'><div align='center'><span class='t-text'>$Nom_Cate_Cf</div></td></span>";
	echo "<td width='32' height='20' valign='center'><div align='center'><span class='t-text'>$Temp_Min &deg;c</div></td></span>";
	echo "<td width='32' height='20' valign='center'><div align='center'><span class='t-text'>$Temp_Max &deg;c</div></td></span>";
	echo "<td width='20' height='20' valign='center'><div align='center'><a class='' href='modif_cf.php?ordre=2&numligne=$NumLigneCF'><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_base_cf.php?ordre=3&numligne=$NumLigneCF''><img src='images/trash.png' 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
    .'">'.$a.'</a> | ';
}
//

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


include 'menu/footer.php';
?>
