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

include 'menu/header.php';

$date = date("d-m-Y");

// menu haut new-supp-modif

echo "<center>";
Echo "<table cellspacing=0 cellpadding=0 align=center border=0>";
Echo "<tbody>";
echo "<a href='saisie_ajout_abattoir.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>";
Echo "</td></tr>";
Echo "</tbody>";
Echo "</table><br>";

$id_presta=htmlentities($_POST['id_presta']);
$DateEntre_y = $_POST['DateEntre_y'];
$DateEntre_m = $_POST['DateEntre_m'];
$DateEntre_d = $_POST['DateEntre_d'];

$Poids=htmlentities($_POST['poids_dechets']);

$Num_categorie=htmlentities($_POST['Num_categorie']);
$Observations=htmlentities($_POST['Observations']);
$Num_bon=htmlentities($_POST['Num_bon_dechets']);

$mrs=htmlentities($_POST['mrs']);

$Date_Entre=date("d/m/y", mktime(0,0,0,$DateEntre_m,$DateEntre_d,$DateEntre_y));

$Date_Es=date("Y-m-d", mktime(0,0,0,$DateEntre_m,$DateEntre_d,$DateEntre_y));

$jour=$DateEntre_d; 
$mois=$DateEntre_m;
$annee=$DateEntre_y;
$anne_a = date("y", mktime(0,0,0,$mois,$jour,$annee));
$semaine = date("W", mktime(0,0,0,$mois,$jour,$annee));

$last_num_entre = 0 ;
$sql = "SELECT max(num_ligne_dechets) FROM table_dechets";  
$req = mysqli_query($link, $sql); 
$row = mysqli_fetch_row($req);
$last_num_entre = $row[0];
$last_num_entre = $last_num_entre + 1 ;

Echo "<center><font color='red'>Enregistrement</font></center>";

echo "<br>";
echo "Date Es : ".$Date_Es." date Entre : ".$Date_Entre." /y= ".$DateEntre_y."  /m= ".$DateEntre_m." /d= ".$DateEntre_d."<br>";
echo "Num four : ".$id_presta." <br>";
echo "Num_Categorie : ".$Num_categorie." <br>";
echo "Num Bon : ".$Num_bon." <br>";
echo "Poids Froid : ".$Poids." <br>";
echo "Observations : ".$Observations." <br>";
echo "semaine : ".$semaine." <br>";
echo "Mrs : ".$mrs." <br>";
echo "Num Enregistrment : ".$last_num_entre." <br>";


$sql = "INSERT INTO table_dechets VALUES ('".$last_num_entre."', '".$Num_bon."', '".$id_presta."', '".$Num_categorie."', '".$mrs."', '".$Poids."', '".$semaine."', '".$Date_Es."', '".$Observations."')";
echo "requet : ".$sql." <br>";
$res = mysqli_query($link, $sql);
echo "resultat requet : ".$res." <br>";

if ($mrs==1) {
echo "go to ajout mrs";
Header("Location: saisie_ajout_mrs.php?num_bon=$Num_bon&y=$DateEntre_y&m=$DateEntre_m&d=$DateEntre_d&presta=$id_presta");

} else {
echo "go to liste dechets";
Header("Location: dechets.php?limite=0");

}

?>
