<?php
include("include/data.php");
Init_boutique();
global $base, $MySQL_Host, $MySQL_User, $MySQL_Passw, $myart, $result, $NbLigne, $semaine, $limitesuivante, $limiteprecedente,
$total, $Nom_plu_intrant, $dlc_plu_intrant, $page, $refere ;
// entete de la page

include 'menu/header.php';

if (!isset($_GET['ordre'])) {
		// Transmis en POST
		$num_ordre=$_POST['ordre'];
		if (isset($_POST['date_releve'])) { $date_releve=$_POST['date_releve']; }  else {$date_releve=$aujourdhui_db; }
		if (isset($_POST['TypeFabric'])) { $type_fabric=$_POST['TypeFabric']; } else {$type_fabric=''; }
		$valForm="POST" ;
} else {
		// Transmis en GET
		$num_ordre=$_GET['ordre'];
		if (isset($_GET['date_releve'])) { $date_releve=$_GET['date_releve']; }  else {$date_releve=$aujourdhui_db; }
		if (isset($_GET['TypeFabric'])) { $type_fabric=$_GET['TypeFabric']; } else {$type_fabric=''; }
		$valForm="GET" ;
}

$Dateav = date("Y-m-d", strtotime($date_releve." -1 days"));
$Dateap = date("Y-m-d", strtotime($date_releve." +1 days"));

$refere = "http://192.168.1.200/orius/ajout_releve_cf.php?ordre=$num_ordre";
$refereav = $refere."&date_releve=$Dateav";
$refereap = $refere."&date_releve=$Dateap";

$datefr = DateFr($date_releve);


echo "<div class='titre-text'><center>Releve de temp&eacute;rature</div></center>" ;

echo "<center><HR size='1' width='500'></center>";
echo "<center><br>" ;
echo "<form name='FormDateReleve' method='GET' action='#'>";
echo "<input type='hidden' name='ordre' value='1'/>";
echo "<table class='t-text' width='550' border='1' cellspacing='1' cellpadding='1'>";
echo "<tr>";
echo "<td colspan=3><center>Date relev&eacute; :&nbsp;<input name='date_releve' type='date' id='date_releve' accesskey='1' tabindex='1' value='$date_releve' onchange='submit()'></td>";
echo "</tr><tr>";
echo "<td><center><a href='$refereav'>Jour -1</a></td>";
echo "<td><center>$datefr</td>";
echo "<td><center><a href='$refereap'>Jour +1</a>";
echo "</center></td></tr>";
echo "</table></form>";
echo "<br>";
echo "<table id='customers' width='800' border='1' cellspacing='1' cellpadding='1'>";
echo "<tr>";
echo "<th align='center' valign='middle'>N&deg; C.F</th>";
echo "<th align='center' valign='middle'>Nom C.F</th>";
echo "<th align='center' colspan=2 valign='middle'>Temp&eacute;rature Relev&eacute;e</th>";

echo "</tr>";

$sql = "SELECT * FROM `Base_CF`";
$sql.=" WHERE `IdNumClient`='".$IdNumClient."'";
$sql.=" ORDER BY `Num_CF` ASC";

$req = mysqli_query($link, $sql);
while ($row = mysqli_fetch_assoc($req)) {
				 $Num_CF = $row["Num_CF"];
	       $Nom_CF = $row["Nom_CF"];
			   $Temps_Min = $row["Temp_Min"];
			   $Temp_Min = $Temps_Min-0.5;
			   $Temp_Max = $Temps_Min+1;

	echo "<td align='center' valign='middle'>$Num_CF</td>";
	echo "<td align='center' valign='middle'>$Nom_CF</td>";
	echo "<td align='center' valign='middle'>";

			  $sql2 = "SELECT * FROM `Temperature_Releve`";
				$sql2.=" WHERE `IdNumClient`='".$IdNumClient."'";
				$sql2.=" AND `date_releve`='".$date_releve."'";
				$sql2.=" AND `Num_CF`='".$Num_CF."'";
				$req2 = mysqli_query($link, $sql2);
				while ($row = mysqli_fetch_assoc($req2)) {
								 $Temp_releve = $row["Temp_releve"];
								 $Num_ligne_Releve = $row["Num_ligne_Releve"];
								 $position = $row["Frigo-on-off"];
				}

if (!isset($position)) {$position=0;}

//echo "ligne : $Num_ligne_Releve tremp : $Temp_releve cf : $Num_CF<br>$sql2<br>Position : $position<br>";

		
			  for ($i = $Temp_Min; $i <= $Temp_Max; $i+=0.1) {
			  		$i = number_format($i, 2, '.', ' ')	;
			  		
			 	if ($position==2)	{	
				echo "<a href='traitement_releve_base_cf.php?ordre=3&NumLigne=$Num_ligne_Releve&date=$date_releve&numcf=$Num_CF&temprel=$i&CF=1'>$i</a> | ";
				} else {
				if (empty($Num_ligne_Releve)) {
					echo "<a href='traitement_releve_base_cf.php?ordre=1&date=$date_releve&numcf=$Num_CF&temprel=$i&CF=1'>$i</a> | ";
					} else {
							if ($i==$Temp_releve) {
							echo "<font color='red'>$i</font> | ";
							} else {
							echo "<a href='traitement_releve_base_cf.php?ordre=3&NumLigne=$Num_ligne_Releve&date=$date_releve&numcf=$Num_CF&temprel=$i&CF=1'>$i</a> | ";
						}
					}		
				}
	}

	echo "</td>";
	if ($position==2)	{	
		echo "<td><a href='traitement_releve_base_cf.php?ordre=3&date=$date_releve&numcf=$Num_CF&CF=0'><font color='red'>OFF</font></a></td>";
	} else {
		echo "<td><a href='traitement_releve_base_cf.php?ordre=1&date=$date_releve&numcf=$Num_CF&CF=0'>OFF</a></td>";
	}
	echo "</tr>";
	 $Temp_releve = "";
	 $Num_ligne_Releve = "";		  
	 $position = "";
}
echo "</table>";
echo "<input name='an' type='button' id='an' accesskey='14' tabindex='14' value='Retour' onClick='history.back()'>";

echo "</form>";
echo "</center><br>" ;


include 'menu/footer.php';
?>
