<?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, $NumAbat;
// entete de la page


echo "<center><br>";

/*
http://192.168.1.200/horius/modif_det_plu.php?num_plu=18
num_ordre=2
Ingredients=Viande+Bovine%2C+Sel%2C+Poivre%2C+Sucre
mlegal_1=+Viande+100%25+fran%C3%A7aise
mlegal_2=Cuire+%C3%A0+Coeur
Tmin=0
Tmax=2
Code_Tva=2
ok=Valider
*/

if (!isset($_GET['num_ordre'])) { 
		// Transmis en POST
		$num_ordre=$_POST['num_ordre'];
		if (isset($_POST['num_plu'])) { $num_plu=$_POST['num_plu']; }  else {$num_plu=''; }
		if (isset($_POST['Ingredients'])) { $Ingredients=$_POST['Ingredients']; } else {$Ingredients=''; }
		if (isset($_POST['mlegal_1'])) { $mlegal_1=$_POST['mlegal_1']; } else {$mlegal_1=''; }
		if (isset($_POST['mlegal_2'])) { $mlegal_2=$_POST['mlegal_2']; } else {$mlegal_2=''; }
		if (isset($_POST['Tmin'])) { $Tmin=$_POST['Tmin']; } else {$Tmin=''; }
		if (isset($_POST['Tmax'])) { $Tmax=$_POST['Tmax']; } else {$Tmax=''; }
		if (isset($_POST['Code_Tva'])) { $Code_Tva=$_POST['Code_Tva']; } else {$Code_Tva=''; }

		
		$valForm="POST" ;
} else {
		// Transmis en GET
		$num_ordre=$_GET['num_ordre'];
		if (isset($_GET['num_plu'])) { $num_plu=$_GET['num_plu']; }  else {$num_plu=''; }
		if (isset($_GET['Ingredients'])) { $Ingredients=$_GET['Ingredients']; } else {$Ingredients=''; }
		if (isset($_GET['mlegal_1'])) { $mlegal_1=$_GET['mlegal_1']; } else {$mlegal_1=''; }
		if (isset($_GET['mlegal_2'])) { $mlegal_2=$_GET['mlegal_2']; } else {$mlegal_2=''; }
		if (isset($_GET['Tmin'])) { $Tmin=$_GET['Tmin']; } else {$Tmin=''; }
		if (isset($_GET['Tmax'])) { $Tmax=$_GET['Tmax']; } else {$Tmax=''; }
		if (isset($_GET['Code_Tva'])) { $Code_Tva=$_GET['Code_Tva']; } else {$Code_Tva=''; }
		
				
		$valForm="GET" ;
}

$timestamp = date('Y-m-d G:i:s');

$mlegal_1 = htmlentities($mlegal_1, ENT_QUOTES);
$mlegal_2 = htmlentities($mlegal_2, ENT_QUOTES);
$Ingredients = htmlentities($Ingredients, ENT_QUOTES);

$date = date("d-m-Y");
/*
Echo "<center><font color='red'>Enregistrement</font></center>";

echo "<br>";
echo "num_ligne : ".$num_plu." <br>";
echo "Ingredients: ".$Ingredients." <br>";
echo "mlegal_1: ".$mlegal_1."<br>";
echo "mlegal_2 : ".$mlegal_2." <br>";
echo "Tmin : ".$Tmin." <br>";
echo "Tmax ".$Tmax." <br>";
echo "DLC : ".$Code_Tva." <br>";
echo "timestamp : ".$timestamp." <br>";
*/

$sql = "UPDATE plu_textes SET 
`ingredients` = '$Ingredients', 
`mlegal_1` = '$mlegal_1', 
`mlegal_2` = '$mlegal_2', 
`Tmin` = '$Tmin', 
`Tmax` = '$Tmax', 
`Tx_tva` = '$Code_Tva', 
`Timestamp` = '$timestamp'
 WHERE `Num_PLU` = '$num_plu' AND `IdNumClient`=$IdNumClient";

echo "requet : ".$sql." <br>";

$res = mysqli_query($link, $sql);

echo "resultat requet : ".$res." <br>";

$refere = $_SERVER['HTTP_REFERER'] ;
Header("Location:  plu_detail.php?ordre=2&num_plu=$num_plu") ;
?>