<?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.100/horius/registre_non_conformite.php?ordre=1&limite=0 */

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['SelMois']))
{
    $SelMois=0;

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

}

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 Table_Non_Conformite ';
$selectc = 'SELECT count(Num_ligne_Conformite) FROM Table_Non_Conformite';

if ($Num_CatPlu==0) {
$v.=" WHERE `IdNumClient`='".$IdNumClient."'";
$selectc.=" WHERE `IdNumClient`='".$IdNumClient."'";
 } else { 
    $v.=' WHERE Num_Conformite='.$Num_CatPlu; 
    $selectc.=' WHERE Num_Conformite='.$Num_CatPlu; 
    
    $selectc.=" AND IdNumClient='".$IdNumClient."'";
    $v.=" AND IdNumClient='".$IdNumClient."'";
     }
$Bixe = date("L", mktime(0,0,0,01,01,$SelAnne_y));
switch ($SelMois) {
	case 1 ;
	case 3 ;
	case 5 ;
	case 7 ;
	case 8 ;
	case 10 ;
	case 12 ;
	$SelMoisJD=01;
	$SelMoisJF=31;
	break ;
	case 4 ;
	case 6 ;
	case 9 ;
	case 11 ;
	$SelMoisJD=01;
	$SelMoisJF=30;
	break ;
	case 2 :
	if ($Bixe==0) {
	$SelMoisJD=01;
	$SelMoisJF=28;
	} else {
	$SelMoisJD=01;
	$SelMoisJF=29;	
	}
	break ;
}

if ($SelMois==0) {
	$SelDeb = date("Y-m-d", mktime(0,0,0,01,01,$SelAnne_y));
	$SelFin = date("Y-m-d", mktime(0,0,0,12,31,$SelAnne_y));
} else {
	$SelDeb = date("Y-m-d", mktime(0,0,0,$SelMois,$SelMoisJD,$SelAnne_y));
	$SelFin = date("Y-m-d", mktime(0,0,0,$SelMois,$SelMoisJF,$SelAnne_y));
}

$v.=" AND Date_Conformite BETWEEN '".$SelDeb."' AND '".$SelFin."'";
$selectc.=" AND Date_Conformite BETWEEN '".$SelDeb."' AND '".$SelFin."'";

$v.=' ORDER BY Num_ligne_Conformite DESC limit '.$limite.','.$nombre;

echo "<center>";
// Titre Page
echo "<div class='titre-text'><center>Registre des Analyses <br>Non Conformit&eacute;es & Actions Correctives</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 "Bisex = $Bixe  | Nb Pages : $NbPage | Total Enrg $total | Mois : $SelMois | 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 border='0' cellpadding='0' cellspacing='0' width='700' height='22' align=center>";
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 ann&eacute;e :";

  $class = '';
  $fyear = '2017';
  $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 class='text'>Par Mois : <select style=' width: 75px;' name='SelMois' id='SelMois'>";
echo "<option value='0'>Toutes</option>";
for ($i=1;$i<=12;$i++)
  {  
  if ($i==$SelMois) {	
	echo "<option value='$i' selected>$mois_lt[$i]</option>";
 	} else {
 	echo "<option value='$i'>$mois_lt[$i]</option>";
  }}
echo "</select>";  
echo "</td>";

echo "<td class='text'>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_conformite';
$req = mysqli_query($link, $sql);  
while ($row = mysqli_fetch_assoc($req)) {
        $num_cate_plu_intran = $row["num_cate_cft"];
        $categorie_plu_intran = $row["categorie_cft"];
        
   if ($Num_CatPlu==$num_cate_plu_intran) {
   	echo "<option value='$num_cate_plu_intran' selected>$num_cate_plu_intran | $categorie_plu_intran</option>";
   } else {
   	echo "<option value='$num_cate_plu_intran'>$num_cate_plu_intran | $categorie_plu_intran</option>";
   }   
}

echo "</select>";
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_nonconform.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='50'  height='20' valign='center' bgcolor='#CCCCCC'><div align='center'><span class='t-text'>N&#176;</div></td></span>";
echo "<td width='75' height='20' valign='center' bgcolor='#CCCCCC'><div align='center'><span class='t-text'>Date</td></span>";
echo "<td width='75' height='20' valign='center' bgcolor='#CCCCCC'><div align='center'><span class='t-text'>Cat&eacute;gorie</td></span>";
echo "<td width='250' height='20' valign='center' bgcolor='#CCCCCC'><div align='center'><span class='t-text'>Non Conformit&eacute;e</td></span>";
echo "<td width='50' height='20' valign='center' bgcolor='#CCCCCC'><div align='center'><span class='t-text'>Etat</td></span>";
echo "<td width='150' height='20' valign='center' bgcolor='#CCCCCC'><div align='center'><span class='t-text'>Actions Correctives</td></span>";
echo "<td width='32' height='20' valign='center' bgcolor='#CCCCCC'><div align='center'><span class='t-text'>E</td></span>";
echo "<td width='32' height='20' valign='center' bgcolor='#CCCCCC'><div align='center'><span class='t-text'>M</td></span>";
echo "<td width='32' height='20' valign='center' bgcolor='#CCCCCC'><div align='center'><span class='t-text'>D</td></span>";
echo "</tr>";

$req = mysqli_query($link, $v);  
while ($row = mysqli_fetch_assoc($req)) {
        $Num_ligne_Conformite = $row["Num_ligne_Conformite"];
        $Date_Conformite = $row["Date_Conformite"];
        $Num_Conformite = $row["Num_Conformite"];
        $Conformite_courte = $row["Conformite_courte"];
				$Etat_conformite = $row["Etat_conformite"];
        $action_corrective = $row["action_corrective_courte"];
        
				$sql = "SELECT categorie_cft FROM categorie_conformite WHERE num_cate_cft='$Num_Conformite'";  
				$req1 = mysqli_query($link, $sql);
				while ($row = mysqli_fetch_assoc($req1)) {$Nom_Conformite = $row["categorie_cft"];} 

$Date_Conformite=date("d/m/Y", strtotime($Date_Conformite));

echo "<tr>";    
echo "<td width='50'  height='20' valign='center' ><div align='center'><span class='t-text'><a href='#' onclick='javascript:Popup(\"detail_nonconform.php?ordre=1&numconform=$Num_ligne_Conformite\",900,400,\"location=0,menubar=0,scrollbars=0,statusbar=0\")'>$Num_ligne_Conformite</a></div></td></span>";
echo "<td width='75' height='20' valign='center' ><div align='center'><span class='t-text'>$Date_Conformite</td></span>";
echo "<td width='75' height='20' valign='center' ><div align='center'><span class='t-text'>$Nom_Conformite</td></span>";
echo "<td width='250' height='20' valign='center' ><div align='center'><span class='t-text'>$Conformite_courte</td></span>";

switch ($Etat_conformite) {
	case 0 :
	echo "<td width='50'><center><img src='images/Alert.png'></center></td>" ;
	break ;
	case 1 :
	echo "<td width='50'><center><img src='images/warning.png'><span class='t-text'></center></td>" ;
	break ;
	case 2 :
	echo "<td width='50'><center><img src='images/good_mark.png'><span class='t-text'></center></td>" ;
	break ;
}

echo "<td width='150' height='20' valign='center'><div align='center'><span class='t-text'>$action_corrective</td></span>";
echo "<td width='32' height='20' valign='center'><div align='center'><a class='' href='edition_detail_conformite_imp.php?num_entre=$Num_ligne_Conformite' TARGET=_BLANK><img src='images/print.png' width='20' height='20'></a></div></td>";
echo "<td width='32' height='20' valign='center'><div align='center'><a class='' href='modif_nonconform.php?ordre=1&numconform=$Num_ligne_Conformite'><img src='images/modifie.png' width='20' height='20'></a></div></td>";
echo "<td width='32' height='20' valign='center'><div align='center'><a class='' href='delette_nonconform.php?ordre=1&numconform=$Num_ligne_Conformite'><img src='images/pblle.jpg' width='20' height='20'></a></div></td></tr>";
echo "</tr>";                           
}
echo "</table><br>";      


include 'menu/footer.php';
?>
