<?php
include("include/data.php");
Init_boutique();
global $link, $base, $MySQL_Host, $MySQL_User, $MySQL_Passw, $myart, $result, $NbLigne, 
$semaine, $limitesuivante, $limiteprecedente, $total, $page ;

// entete de la page
/*
traitement_releve_base_cf.php
ordre=3
date=2017-07-17
numcf=2
temprel=2.40
*/


if (!isset($_GET['ordre'])) { 
		// Transmis en POST
		$num_ordre=$_POST['ordre'];
		if (isset($_POST['date'])) { $date_releve=$_POST['date']; }  else {$date_releve=''; }
		if (isset($_POST['numcf'])) { $numcf=$_POST['numcf']; } else {$numcf=''; }
		if (isset($_POST['temprel'])) { $temprel=$_POST['temprel']; } else {$temprel=''; }
		if (isset($_POST['NumLigne'])) { $NumLigne=$_POST['NumLigne']; } else {$NumLigne=''; }
		if (isset($_POST['CF'])) { $CF=$_POST['CF']; }  else {$CF=''; }
		$valForm="POST" ;
} else {
		// Transmis en GET
		$num_ordre=$_GET['ordre'];
		if (isset($_GET['date'])) { $date_releve=$_GET['date']; }  else {$date_releve=''; }
		if (isset($_GET['numcf'])) { $numcf=$_GET['numcf']; } else {$numcf=''; }
		if (isset($_GET['temprel'])) { $temprel=$_GET['temprel']; } else {$temprel=''; }
		if (isset($_GET['CF'])) { $CF=$_GET['CF']; }  else {$CF=''; }	
		if (isset($_GET['NumLigne'])) { $NumLigne=$_GET['NumLigne']; } else {$NumLigne=''; }
		$valForm="GET" ;
}

//include 'menu/header.php';

$last_num_entre = 0 ;
$sql = 'SELECT max(Num_ligne_Releve) FROM Temperature_Releve';
$req = mysqli_query($link, $sql); 
$row = mysqli_fetch_row($req);
$last_num_entre = $row[0];
$last_num_entre = $last_num_entre + 1 ;

switch ($CF) {
	Case 1 :
$position=1;
break;
	Case 0 :
$position=2;
$temprel=0;
break;	
}



echo "<center>";
echo "Form : ".$valForm." | Num ordre : ".$num_ordre."<br>" ;
echo "Num CF : ".$numcf."<br>" ;
echo "CF ON / OFF : ".$CF." | Position base : ".$position."<br>" ;
echo "Num Ligne : ".$NumLigne."<br>" ;
echo "temp releve : ".$temprel."<br>" ;
echo "LastNum :".$last_num_entre."<br>" ;


switch ($num_ordre) {
	case 1 : // Cree
			
$sql = "INSERT INTO Temperature_Releve VALUES (
'".$last_num_entre."',
'".$IdNumClient."',
'".$IdNomClient."',
'".$date_releve ."',
'".$numcf."', 
'".$temprel."',
'".$position."', 
'', 
'".$timestamp."')";

echo "ajout : ".$sql;
 
$res = mysqli_query($link, $sql);

echo "<br>Requette : ".$res ;			

					break;
					
	case 3 : // update
$sql1 = "UPDATE Temperature_Releve SET `Temp_releve` = '$temprel', `Frigo-on-off` = '$position', `Timestamp` = '$timestamp' WHERE `Num_ligne_Releve` = '$NumLigne'";


echo "Mise a Jour : ".$sql1;
 
$res1 = mysqli_query($link, $sql1);

echo "<br>Requette : ".$res1 ;
					
					break;
}


$refere = $_SERVER['HTTP_REFERER'] ;
Header("Location:  $refere") ;

?>
