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


// Get ou Post existe ou pas ?
if (!isset($_GET['limite'])) { 
		// Transmis en POST
		$limite=$_POST['limite'];
		if (isset($_POST['Num_CatPlu'])) { $Num_CatPlu=$_POST['Num_CatPlu']; }  else {$Num_CatPlu=''; }
		$valForm="POST" ;
} else {
		// Transmis en GET
		$limite=$_GET['limite'];
		if (isset($_GET['Num_CatPlu'])) { $Num_CatPlu=$_GET['Num_CatPlu']; }  else {$Num_CatPlu=''; }
		$valForm="GET" ;
}

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


if (!isset($limite)) $limite = 0;
$nombre = 10;
$limitePage = 0 ;

$v='select * FROM Base_Tarifs ';
$selectc = 'SELECT count(Num_Base_Tarifs) FROM Base_Tarifs';

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

$v.=' ORDER BY Num_PLU 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."<br>";
echo "Selectcc : ".$selectc."<br>" ;
echo "<HR size='2' width='500'>";
echo " total : $NbPage | $total | $semaine | $Num_CatPlu <br></center>" ;
*/

echo "<center><b>Base Tarifs</b></center>" ;

echo "<center><HR size='1' width='500'>";

// Filtres 

echo "<form id='form1' name='form1' method='get' action='base_tarifs.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 Code Tarif : <select style=' width: 300px;' name='Num_CatPlu' id='Num_CatPlu'>";
echo "<option value='0'>Toutes</option>";
$myart =new categorie_tarif;
$select = 'select * FROM categorie_tarif';
$result = mysqli_query($link, $select);
$myart->getnum($result);
while ($myart->z < $myart->num) {
  $myart->readrow($result);
  $Num_Code_Tarif=$myart->Num_Code_Tarif ;
  $categorie_plu_intran=$myart->Code_Tarif ;

  if ($Num_Code_Tarif == $Num_CatPlu) {
  echo "<option value='$Num_Code_Tarif' selected>$Num_Code_Tarif | $categorie_plu_intran</option>";
  } ELSE {
  echo "<option value='$Num_Code_Tarif'>$Num_Code_Tarif | $categorie_plu_intran</option>";
  }
}

echo "</select>";
echo "</td>";
echo "<td><input type='submit' value='ok'></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_base_tarifs.php?ordre=1'><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 id='t01' border='1' cellpadding='1' cellspacing='1' width='600' height='22'>";
echo "<th width='30' height='20' valign='center' bgcolor='#CCCCCC'><div align='center'><span class='t-text'>N&#176;</div></th></span>";
echo "<th width='30' height='20' valign='center' bgcolor='#CCCCCC'><div align='center'><span class='t-text'>Code Tarif</div></th></span>";
echo "<th width='30' height='20' valign='center' bgcolor='#CCCCCC'><div align='center'><span class='t-text'>N&deg; PLU</div></th></span>";
echo "<th width='100' height='20' valign='center' bgcolor='#CCCCCC'><div align='center'><span class='t-text'>Nom PLU</th></span>";
echo "<th width='50' height='20' valign='center' bgcolor='#CCCCCC'><div align='center'><span class='t-text'>Prix HT</th></span>";
echo "<th width='50' height='20' valign='center' bgcolor='#CCCCCC'><div align='center'><span class='t-text'>Prix TTC</th></span>";
echo "<th width='32' height='20' valign='center' bgcolor='#CCCCCC'><div align='center'><span class='t-text'>M</th></span>";
echo "<th width='32' height='20' valign='center' bgcolor='#CCCCCC'><div align='center'><span class='t-text'>D</th></span>";


$myart =new Base_Tarifs;
$result = mysqli_query($link, $SelectEA);
$myart->getnum($result);
while ($myart->z < $myart->num) {
  $myart->readrow($result);
  $Num_Base_Tarifs=$myart->Num_Base_Tarifs ;
  $Num_Code_Tarif=$myart->Num_Code_Tarif ;
  $Num_PLU=$myart->Num_PLU ;
  $Prix_HT =$myart->Prix_HT ;
  $Prix_TTC =$myart->Prix_TTC ;
  
$sql = "SELECT * FROM plu WHERE Num_PLU='$Num_PLU'";  
$req =   mysqli_query($link, $sql) ;
 while ($row = mysqli_fetch_assoc($req)) {
        $PLU = $row["PLU"];
        $Plu_complement = $row["Plu_complement"];
    }
/*
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>";
echo "<td width='30' height='20' valign='center'>
	<div align='center'><span class='t-text'>$Num_Base_Tarifs</div></td></span>";
	echo "<td width='30' height='20' valign='center'>
	<div align='center'><span class='t-text'>$Num_Code_Tarif</div></td></span>";
	echo "<td width='30' height='20' valign='center'>
	<div align='center'><span class='t-text'>$Num_PLU</div></td></span>";
	if (!empty($Plu_complement))	{
	echo "<td width='100' height='20' valign='center'>
	<div align='center'><a class='' href='consult_base_tarifs.php?ordre=2&Num_Code_Tarifs=$Num_Base_Tarifs&num_plu=$Num_PLU'><span class='t-text'>$PLU -  $Plu_complement</div></a></td></span>";
  } ELSE {
  echo "<td width='100' height='20' valign='center'>
	<div align='center'><a class='' href='consult_base_tarifs.php?ordre=2&Num_Code_Tarifs=$Num_Base_Tarifs&num_plu=$Num_PLU'><span class='t-text'>$PLU<div></a></td></span>";
  }	 
	echo "<td width='50' height='20' valign='center'>
	<div align='center'><span class='t-text'>$Prix_HT &#128;</div></td></span>";
	echo "<td width='50' height='20' valign='center'>
	<div align='center'><span class='t-text'>$Prix_TTC &#128;</div></td></span>";
	echo "<td width='20' height='20' valign='center'>
	<div align='center'><a class='' href='modif_base_tarifs.php?ordre=4&Num_Code_Tarifs=$Num_Base_Tarifs'><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_tarifs.php?Num_Code_Tarifs=$Num_Base_Tarifs'><img src='images/pblle.jpg' width='20' height='20'></a></div></td></tr>";

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

echo "<center>";

echo "<table border='1' cellpadding='0' cellspacing='0' width='700' height='22'><tr>";
echo "<td width='120' height='20' valign='center'><div align='center'><span class='t-text'>";
/*
echo "<br> total enrg = ".$total.
" | Nbpages = ".$NbPage.
" | limite suivante= ".$limitesuivante.
" | limite encours= ".$limite.
" | limite precedente= ".$limiteprecedente.
" <br> Anne =".$SelAnne_y.
" | Semaine =".$SelSem_w.
" | Num_CatPlu=".$Num_CatPlu.
" | Num_Client=".$Num_Client_sel.
" | Nombre=".$nombre."<br>" ;	 
*/
if($limite != 0) {
    echo '<a href="'.$page.'?limite='.$limiteprecedente.'&Num_CatPlu='.$Num_CatPlu.'">Page precedente  </a>';
}

// http://192.168.1.200/orius/base_tarifs.php?limite=0&Num_CatPlu=1


for ($a = 1 ; $a <= 10 ; $a++) {
    $limitePage = $nombre + $limitePage;
	if (($limite/10)==$a) {
    echo "<a href=".$page."?limite=".$limitePage."&Num_CatPlu=".$Num_CatPlu."><FONT color='red'>".$a."</FONT></a> |";
	} else {
	echo "<a href=".$page."?limite=".$limitePage."&Num_CatPlu=".$Num_CatPlu.">".$a."</a> |";
	}
}

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

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


include 'menu/footer.php';
?>
