<?php
   
include("include/data.php");
Init_boutique();

// entete de la page

include 'menu/header.php';

if (!isset($_GET['ordre'])) { 
		// Transmis en POST
		if (isset($_POST['ordre'])) { $ordre=$_POST['ordre']; } else {$ordre=''; }
		if (isset($_POST['Sel_w'])) { $Sel_w=$_POST['Sel_w']; } else {$Sel_w=''; }
		$valForm="POST" ;
} else {
		// Transmis en GET
		$limite=$_GET['ordre'];
		if (isset($_GET['ordre'])) { $ordre=$_GET['ordre']; } else {$ordre=''; }
		if (isset($_GET['Sel_w'])) { $Sel_w=$_GET['Sel_w']; } else {$Sel_w=''; }
	
		$valForm="GET" ;
}

// TITRE Page //
echo "<div class='titre-text'><center>Suppression des Imports</div></center><HR size='2' width='500'>" ;

// FILTRES
// menu haut new-supp-modif
echo "<form id='form1' name='form1' method='get' action=''>";
echo "<input type='hidden' name='ordre' value='$ordre'/>";
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'>";


// Semaine    

echo "</td>";
echo "<td>&nbsp;Par semaine :";

  $class = '';
  $fyear='1';
  $lyear='53';
  $name = 'Sel';

  $yr=date("W");
  
  $s="<SELECT style=' width: 65px;' NAME=\"${name}_w\" class='$class'>\n";
  $s.="<OPTION VALUE='0' SELECTED>Toutes</OPTION>\n";
 // $s.="<OPTION VALUE=$yr>$yr</OPTION>\n";
  
  //select semaines encore dans la base
  
	$sql = "SELECT DISTINCT `Num_semaine` FROM temp_import_csv";  
	$sql.=" WHERE `IdNumClient`='".$IdNumClient."'";
	$sql.=" AND RsltImport ='1'";
	$sql.=" AND RsltLot='1'";
	$sql.=" AND RsltStock='1'";
	$req = mysqli_query($link, $sql);  
	while ($row = mysqli_fetch_assoc($req)) {
	        $i = $row["Num_semaine"];
	        
  $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>";

	$Nb_etiq_import = 0 ;
	$sql1 = "SELECT count(num_etiq_ligne) FROM temp_import_csv";  
	$sql1.=" WHERE `IdNumClient`='".$IdNumClient."'";
	if (!empty($Sel_w)){ $sql1.=" AND Num_semaine='".$Sel_w."'";}
	$sql1.=" AND RsltImport ='1'";
	$sql1.=" AND RsltLot='1'";
	$sql1.=" AND RsltStock='1'";
	$req1 = mysqli_query($link, $sql1); 
	$row = mysqli_fetch_row($req1);
	$Nb_etiq_import = $row[0];
	
	$Nb_clients_import = 0 ;
	$sql1 = "SELECT COUNT(DISTINCT num_client) FROM temp_import_csv";  
	$sql1.=" WHERE `IdNumClient`='".$IdNumClient."'";
	if (!empty($Sel_w)){ $sql1.=" AND Num_semaine='".$Sel_w."'";}
	$sql1.=" AND RsltImport ='1'";
	$sql1.=" AND RsltLot='1'";
	$sql1.=" AND RsltStock='1'";
	$req1 = mysqli_query($link, $sql1); 
	$row = mysqli_fetch_row($req1);
	$Nb_clients_import = $row[0];

if (!empty($Sel_w)){
echo "<center><br>";	
echo "<div class='t-text12'>Lecture base importation ...... Selection de la semaine $Sel_w <br> Nombre d'&#233;tiquettes a traiter : $Nb_etiq_import - Pour : $Nb_clients_import clients</div>"; 
echo "<br><center>";
}	else {
echo "<center><br>";	
echo "<div class='t-text12'>Lecture base importation Complete (pas de selection)...... <br> Nombre d'&#233;tiquettes a traiter : $Nb_etiq_import - Pour : $Nb_clients_import clients</div>"; 
echo "<br><center>";	
}


//
echo "<form id='ImportBl' id='thing-alerts' name ='ImportBl' method='GET' action='delete_bl_temp.php'>";
echo "<input type='hidden' name='ordre' value='1'/>";
echo "<input type='hidden' name='Sel_w' value='$Sel_w'/>";
echo "<table class='t-text' width='750' border='1' cellspacing='2' cellpadding='2'>";

$sql1 = "SELECT * FROM categorie_Clients";
$sql1.= " WHERE `IdNumClient`='".$IdNumClient."'";
$sql1.= " ORDER BY `categorie_Clients`.`num_cate_clt` ASC";
$req1 = mysqli_query($link, $sql1);
while ($row = mysqli_fetch_assoc($req1)) {
	$num_cate_clt = $row["num_cate_clt"]; 
	$Nom_cate_clt = $row["categorie_clt"]; 

echo "<tr><td colspan=2>$num_cate_clt | $Nom_cate_clt</td></tr>";
echo "<tr><td>";
	$sql2 ="SELECT COUNT(DISTINCT temp_import_csv.num_client, clients_base.Code_categorie) FROM temp_import_csv";  
	$sql2.=" INNER JOIN clients_base ON temp_import_csv.num_client = clients_base.Num_Client";
	$sql2.=" WHERE temp_import_csv.IdNumClient='".$IdNumClient."'";
	if (!empty($Sel_w)){ $sql2.=" AND Num_semaine='".$Sel_w."'";}
	$sql2.=" AND Code_categorie='".$num_cate_clt."'";
	$sql2.=" AND RsltImport ='1'";
	$sql2.=" AND RsltLot='1'";
	$sql2.=" AND RsltStock='1'";
		$req2 = mysqli_query($link, $sql2); 
		$row = mysqli_fetch_row($req2);
		$nb_enrg = $row[0];
		$nb_enrg_col = floor ($nb_enrg/2);
		$i=0;
	
	$sql3 ="SELECT DISTINCT temp_import_csv.num_client, clients_base.Nom_Client, clients_base.Code_categorie FROM temp_import_csv";  
	$sql3.=" INNER JOIN clients_base ON temp_import_csv.num_client = clients_base.Num_Client";
	$sql3.=" WHERE temp_import_csv.IdNumClient='".$IdNumClient."'";
	if (!empty($Sel_w)){ $sql3.=" AND Num_semaine='".$Sel_w."'";}
	$sql3.=" AND temp_import_csv.RsltImport ='1'";
	$sql3.=" AND temp_import_csv.RsltLot='1'";
	$sql3.=" AND temp_import_csv.RsltStock='1'";  
	$sql3.=" AND Code_categorie='".$num_cate_clt."'";
	$sql3.=" ORDER BY `clients_base`.`Code_categorie` ASC, `temp_import_csv`.`num_client` ASC";
	
	$req3 = mysqli_query($link, $sql3); 
	while ($row = mysqli_fetch_assoc($req3)) {
	$Num_Client_import = $row["num_client"];
	$Nom_ClientSel = $row["Nom_Client"];
	$Cate_ClientSel = $row["Code_categorie"];
	
	$NumClientSelect=substr($Num_Client_import, 0, 2);
  $NumClientSelect.=substr($Num_Client_import, -3);
	
	$i=$i+1;
				if (($i-1)==$nb_enrg_col) {
				echo "<td>";
				} else {
				
				}

echo "<input type='checkbox' name='CltSelBL[]' value=".$NumClientSelect."/>".$Num_Client_import." - <a href='#' onclick='javascript:Popup(\"detail_bl_temp_liste_import.php?ordre=1&num_clt=$Num_Client_import&Rsi=1&Rsl=1&Rss=1&Sel_w=$Sel_w\",1000,500,\"location=0,menubar=0,scrollbars=0,statusbar=0\")'>".$Nom_ClientSel."</a><br>";
   
	
} 
echo "</td>";
}
echo "</tr>";

echo "<td colspan =2 align='center' valign='middle'>
	    <input type='submit' name='ok' id='ok' value='Valider' accesskey='11' tabindex='11'>
	    &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;
	    <input name='an' type='button' id='an' accesskey='12' tabindex='12' value='Retour' onClick='history.back()'>
	    &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;
	    <input type='submit' name='ok' id='ok' value='Tout' text='Tout Importer' accesskey='11' tabindex='11'></td>";
echo " </tr></div>";
echo "</table>";
echo "</form>";


include 'menu/footer.php';

?>
