<?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, $s,
$limiteprecedente, $limite, $total, $page, $Nom_Client, $semaine ;
// entete de la page

include 'menu/header.php';

/* http://192.168.1.200/orius/releve_temperature.php?limite=0&Num_CatPlu=0&SelAnne_y=2017# */

if (!isset($_GET['Num_CatPlu']))
{
    $Num_CatPlu=0;
    $Num_CatPlu_sel=0;
} else {
    $Num_CatPlu=($_GET['Num_CatPlu']);
    $Num_CatPlu_sel=($_GET['Num_CatPlu']);
}

if (!isset($_GET['SelAnne_y']))
{
    $SelAnne_y=date("Y");

} else {
    $SelAnne_y=($_GET['SelAnne_y']);
}


$limite=$_GET['limite'];
if (!isset($limite)) $limite = 0;
$nombre = 10;
$limitePage = 0 ;

$v='select * FROM Base_CF ';
$selectc = 'SELECT count(Num_ligne_CF) FROM Base_CF';

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


$v.=' ORDER BY Num_CF ASC limit '.$limite.','.$nombre;

echo "<center>";
// Titre Page
echo "<div class='titre-text'><center>Relev&eacute; des temp&eacute;ratures<br>des Chambres Froides</div></center><br>" ;

 // 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> selectc : ".$selectc;
echo "<HR size='2' width='500'>";
echo "Nb Pages : $NbPage | Total Enrg $total | semaine $semaine | catePLU $Num_CatPlu | sely $SelAnne_y<br></center>" ;
*/
// Filtres 

echo "<form id='form1' name='form1' method='get' action='#'>";
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 Cat&eacute;gorie : <select style=' width: 150px;' name='Num_CatPlu' id='Num_CatPlu' onchange='submit()'>";
echo "<option value='0'>Toutes</option>";

$sql = 'select * FROM categorie_CF';
$req = mysqli_query($link, $sql);  
while ($row = mysqli_fetch_assoc($req)) {
        $num_cate_plu_intran = $row["num_cate_cf"];
        $categorie_plu_intran = $row["categorie_cf"];
   echo "<option value='$num_cate_plu_intran'>$num_cate_plu_intran | $categorie_plu_intran</option>";
}

echo "</select>";
echo "</td>";
echo "<td>Par ann&eacute;e :";

  $class = '';
  $fyear = '2015';
  $lyear = '2050';
  $name = 'SelAnne';
  $yr=$SelAnne_y;

  // Année 
  
  $s.="<SELECT NAME=\"${name}_y\" class='$class'>\n"; 
  $s.="<OPTION VALUE=$yr>$yr</OPTION>\n";
  $sclt=""; 
  for ($i=$fyear;$i<=$lyear;$i++)
  { 
  $i2="$i"; 
  if ($i2==$yr) 
  $sclt=" SELECTED"; 
  else 
  $sclt=""; 
  $s.="<OPTION VALUE=\"$i\"$sclt>$i</OPTION>\n"; 
  } 
  $s.="</SELECT>\n"; 
    echo"$s";
echo "</td>";

echo "<td><input type='submit' value='ok'>";
echo "</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='2' width='500'>";
echo "<table cellspacing=0 cellpadding=0 align=center border=0>";
echo "<td>";
echo "<a href='ajout_releve_cf.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 border='1' cellpadding='1' cellspacing='1' width='750' height='22'><tr>";
echo "<td width='30'  height='20' valign='center' bgcolor='#CCCCCC'><div align='center'><span class='t-text'>N&#176;</div></td></span>";
echo "<td width='50' height='20' valign='center' bgcolor='#CCCCCC'><div align='center'><span class='t-text'>Nom C.F</td></span>";
echo "<td width='600' height='20' valign='center' bgcolor='#CCCCCC'><div align='center'><span class='t-text'>relev&eacute;</td></span>";
echo "</tr>";

$req1 = mysqli_query($link, $v);  
while ($row = mysqli_fetch_assoc($req1)) {
				 $NumLigneCF = $row["Num_ligne_CF"];
	       $Num_CF = $row["Num_CF"];
	       $Nom_CF = $row["Nom_CF"];
			   $Temp_Min = $row["Temp_Min"];
			   $Temp_Max = $row["Temp_Max"];
			   $num_cate_cf = $row["num_cate_cf"];
	
//	$Nom_CF = htmlspecialchars($Nom_CF, ENT_QUOTES);
  
  $sql = 'select * FROM categorie_CF';
	$req = mysqli_query($link, $sql);  
	while ($row = mysqli_fetch_assoc($req)) {
        $num_cate_plu_intran = $row["num_cate_cf"];
        $categorie_plu_intran = $row["categorie_cf"];
   
   if ($num_cate_cf==$num_cate_plu_intran )
   $Nom_Cate_Cf=$categorie_plu_intran ;
   
}
   
  echo "<tr>";
  echo "<td width='30' height='20' valign='center'><div align='center'><span class='t-text'>$Num_CF</div></td></span>";
	echo "<td width='50' height='20' valign='center'><div align='center'><a class='' href='#'><span class='t-text'>$Nom_CF</div></a></td></span>";
	echo "<td width='600' height='20' valign='center'><div align='center'>";
	
	for ($i=1; $i<=12 ;$i++){
	$mois = array("","Janvier","F&eacute;vrier","Mars","Avril","Mai","Juin","Juillet","Ao&ucirc;t","Septembre","Octobre","Novembre","D&eacute;cembre"); 
	
	switch ($i) {
		case 1:
		$datedeb = $SelAnne_y."01-01-".$SelAnne_y ;
		$datefin = $SelAnne_y."01-31-".$SelAnne_y ;
		break ;
		case 2:
		if (date("L", mktime(0, 0, 0, 1, 1, $SelAnne_y)) == 1) {
		// l'année n'est pas bissextile
		$datedeb = $SelAnne_y."02-01-".$SelAnne_y ;
		$datefin = $SelAnne_y."02-29-".$SelAnne_y ;
		} ELSE {
		// l'année est bissextile
		$datedeb = $SelAnne_y."02-01-".$SelAnne_y ;
		$datefin = $SelAnne_y."02-28-".$SelAnne_y ;
		}
		break ;
		case 3:
		$datedeb = $SelAnne_y."03-01-".$SelAnne_y ;
		$datefin = $SelAnne_y."03-30-".$SelAnne_y ;
		break ;
		case 4:
		$datedeb = $SelAnne_y."04-01-".$SelAnne_y ;
		$datefin = $SelAnne_y."04-30-".$SelAnne_y ;
		break ;
		case 5:
		$datedeb = $SelAnne_y."05-01-".$SelAnne_y ;
		$datefin = $SelAnne_y."05-31-".$SelAnne_y ;
		break ;
		case 6:
		$datedeb = $SelAnne_y."06-01-".$SelAnne_y ;
		$datefin = $SelAnne_y."06-30-".$SelAnne_y ;
		break ;
		case 7:
		$datedeb = $SelAnne_y."07-01-".$SelAnne_y;
		$datefin = $SelAnne_y."07-31-".$SelAnne_y;
		break ;
		case 8:
		$datedeb = $SelAnne_y."08-01-".$SelAnne_y;
		$datefin = $SelAnne_y."08-31-".$SelAnne_y;
		break ;
		case 9:
		$datedeb = $SelAnne_y."09-01-".$SelAnne_y ;
		$datefin = $SelAnne_y."09-30-".$SelAnne_y ;
		break ;
		case 10:
		$datedeb = $SelAnne_y."10-01-".$SelAnne_y ;
		$datefin = $SelAnne_y."10-31-".$SelAnne_y ;
		break ;
		case 11:
		$datedeb = $SelAnne_y."11-01-".$SelAnne_y ;
		$datefin = $SelAnne_y."11-30-".$SelAnne_y ;
		break ;
		case 12:
		$datedeb = $SelAnne_y."12-01-".$SelAnne_y ;
		$datefin = $SelAnne_y."12-31-".$SelAnne_y ;
		break ;
	}
	 			$sql2 = "SELECT * FROM `Temperature_Releve`";
				$sql2.=" WHERE `IdNumClient`='".$IdNumClient."'";
				$sql2.=" AND `date_releve`='".$date_releve."'";
				$sql2.=" AND `Num_CF`='".$Num_CF."'";
				$sql2.=" AND date_releve BETWEEN '".$SelDeb."' AND '".$SelFin."'";
				$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"];
				}
	echo "<a class='' href='#'><span class='t-text'>$mois[$i] | " ;


	}
	echo "</div></a></td></span>";
}
echo "</tr></table><br>";

echo "<center>";

echo "<table border='1' cellpadding='0' cellspacing='0' width='500' height='22'><tr>";
echo "<td width='120' height='20' valign='center'><div align='center'><span class='t-text'>";
	 
if($limite != 0) {
    echo '<a href="'.$page.'?limite='.$limiteprecedente.'">Page precedente  </a>';
}

for ($a = 1; $a <= $NbPage ; $a++) {
    $limitePage = $nombre + $limitePage;
    echo '<a href="'.$page.'?limite='.$limitePage
    .'&Num_CatPlu='.$Num_CatPlu_sel
    .'">'.$a.'</a> | ';
}
//

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


include 'menu/footer.php';
?>
