<?php
/****************************************************************************************
SMI (Services Maintenance Interventions) est une gestion libre de maintenance et de SAV

Version 0.9.9

Copyright (C) 2006-2009  Sylvain FATOME
This program is free software; you can redistribute it and/or modify it under the terms
of the GNU General Public License as published by the Free Software Foundation; 
either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program
(in the directory docs); 
if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 
Boston, MA  02110-1301, USA.

Contact : galawa@free.fr

Web : http://smitst.homelinux.com
****************************************************************************************/


// Vérification des tentatives de hack
$pos=strpos($_SERVER['PHP_SELF'],"inc.php");
if ($pos===FALSE)
	$ok_inc=TRUE;
else
	$ok_inc=FALSE;
if ($ok_inc==FALSE) header("Location: ../index.php");

include_once("../inc/fic_mque.inc.php");
include_once("../inc/fic_ret.inc.php");
include_once("../inc/func.inc.php");
include_once("../inc/func_date.inc.php");
include_once("../inc/func_geo.inc.php");
include_once("../inc/func_txt.inc.php");
include_once("../inc/lst.inc.php");
Archivelog(@$_SESSION["code_log"]);

$td="";
if (isset($_GET['td']))
	$td = strip_tags(trim($_GET['td'])); // Récupération type demande
$tx="";
if (isset($_GET['tx']))
	$tx = strip_tags(trim($_GET['tx'])); // Récupération source appel (tx=e -> appel depuis fiche de renvoi)
$cm="";
if (isset($_GET['cm']))
	$cm = strip_tags(trim($_GET['cm'])); // Récupération code marque
$ce="";
if (isset($_GET['ce']))
	$ce = strip_tags(trim($_GET['ce'])); // Récupération code envoi
$ca="";
if (isset($_GET['ca']))
	$ca = strip_tags(trim($_GET['ca'])); // Récupération code agence
$fi="";
if (isset($_GET['fi']) && (trim($_GET['fi'])<>""))
	$fi=intval(strip_tags(trim($_GET['fi'])));

$pbm_retp=FALSE;
if (($cm=="") AND ($tx=="e"))
	$pbm_retp=TRUE;
	
if ($cm<>"")
{
	$row=lit_enr_mque($cm,TRUE);
	if (is_array($row))
		extract ($row);
	else
		$pbm_retp=TRUE;
}

if (($ce=="") AND ($tx=="e"))
	$pbm_retp=TRUE;
if (($ca=="") AND ($tx=="e"))
	$pbm_retp=TRUE;

?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>

<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<title>SMI - <?PHP echo $title_esp_prive; ?> : Liste Produits &agrave; Retourner</title>
<!-- Feuille de style pour les affichages courants -->
<link href="../css/smi.css" rel="stylesheet" type="text/css">

<!-- Feuille de style & Script pour le menu -->
<script language="JavaScript" src="../jscript/coolmenus/coolmenus4.js"></script>

<!-- Scripts Javascript pour fenêtres -->
<script language="JavaScript" src="../jscript/fen.js"></script>

<!-- Scripts Javascript divers -->
<script language="JavaScript" src="../jscript/divers.js"></script>

</head>

<body onLoad="metFocus();">
<?PHP
if ($pbm_retp==FALSE)
{
	if ($tx<>"e") include_once("../inc/entete.inc.php");
?>
	<p align="center"><span class="titrepage">LISTE DES PRODUITS A RETOURNER</span></p>
<?PHP if ($tx=="e") { ?>
<div align="center" class="annot_std_gras">Pour le bon de renvoi <?PHP echo $ce; ?></div>
<br>
<?PHP }

	if ($tx<>"e")
	{
		$fic_imp = "retp_lsti.php";
		$url_add = "retp_maj.php?td=add&cr=&ca=";
	}
	$tab_fi[]="Tous les produits";
	$tab_fi[]="Demandes non effectuées";
	$tab_fi[]="Envois non effectués";
	$tab_fi[]="Non traités";

	$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
	mysql_select_db(DBNAME);
	
	if ($tx == "e")
		$rech=cree_strrechlstretprma();
	else
		$rech = cree_strrechlstretp();

	if ((@$_SESSION["niv_log"] == 4) OR (@$_SESSION["niv_log"] == 3))
	{
		if(!stristr($rech,"WHERE "))
			$rech .= " WHERE ".TBRETP.".retp_codeage='".@$_SESSION["code_age"]."'";
		else
			$rech .= " AND ".TBRETP.".retp_codeage='".@$_SESSION["code_age"]."'";
	}

	switch ($fi)
	{
		case "1" :
			if(!stristr($rech,"WHERE "))
				$rech .= " WHERE retp_datedde='0000-00-00'";
			else
				$rech .= " AND retp_datedde='0000-00-00'";
			break;
		case "2" :
			if(!stristr($rech,"WHERE "))
				$rech .= " WHERE retp_dateenv='0000-00-00'";
			else
				$rech .= " AND retp_dateenv='0000-00-00'";
			break;
		case "3" :
			if(!stristr($rech,"WHERE "))
				$rech .= " WHERE retp_dateret='0000-00-00'";
			else
				$rech .= " AND retp_dateret='0000-00-00'";
			break;
		default :
			break;
	}

	if ($tx == "e")
		$rech .= crestr_triord($retpe_titre_col,"retp_code",FALSE,$limit);
	else
		$rech .= crestr_triord($retp_titre_col,"retp_code",FALSE,$limit);
	$rs = mysql_query($rech) or die(mysql_error());
	$numrows = mysql_num_rows($rs); // Nombre de résultats à la requête
	
	// *** Pagination d'entête
	pagine_lst($numrows,$limit);
	
	if($numrows == 0)
	{
		if ($tx=="e")
		{
			echo "<div align=\"center\">";
			echo "<span class=\"annot_std_gras\">Tous les produits avec num&eacute;ros de retour accord&eacute;s,<br>du fournisseur <span class=\"annot_gras_it\">".$mque_ste."</span> on &eacute;t&eacute; saisis dans des fiches de renvoi.</span><br>";
			echo "</div>";
		}
		else
			retpp();
	}
	 else
	{
		if ($tx == "e")
			$rech=cree_strrechlstretprma();
		else
		{
			include_once("formr.inc.php"); 
			$rech = cree_strrechlstretp();
		}
	
		if ((@$_SESSION["niv_log"] == 4) OR (@$_SESSION["niv_log"] == 3))
		{
			if(!stristr($rech,"WHERE "))
				$rech .= " WHERE ".TBRETP.".retp_codeage='".@$_SESSION["code_age"]."'";
			else
				$rech .= " AND ".TBRETP.".retp_codeage='".@$_SESSION["code_age"]."'";
		}
	
		switch ($fi)
		{
			case "1" :
				if(!stristr($rech,"WHERE "))
					$rech .= " WHERE retp_datedde='0000-00-00'";
				else
					$rech .= " AND retp_datedde='0000-00-00'";
				break;
			case "2" :
				if(!stristr($rech,"WHERE "))
					$rech .= " WHERE retp_dateenv='0000-00-00'";
				else
					$rech .= " AND retp_dateenv='0000-00-00'";
				break;
			case "3" :
				if(!stristr($rech,"WHERE "))
					$rech .= " WHERE retp_dateret='0000-00-00'";
				else
					$rech .= " AND retp_dateret='0000-00-00'";
				break;
			default :
				break;
		}
	
		if ($tx == "e")
			$rech .= crestr_triord($retpe_titre_col,"retp_code",FALSE,$limit);
		else
			$rech .= crestr_triord($retp_titre_col,"retp_code",FALSE,$limit);

		$rs = mysql_query($rech) or die(mysql_error());
		$numrows = mysql_num_rows($rs);
	
		// *** Affichage de la table
		 echo "<table class=\"Mtable\" border=\"0\" width=\"100%\" cellpadding=\"0\" cellspacing=\"0\">\n";     
	
		// Création entête
		if ($tx=="e")
			titlst($retpe_titre_col);
		else
			titlst($retp_titre_col);
		echo "<th>".ucfirst($txt_ent_lst_clic)."</th>\n";
			
		
		$i = 0;
		
		
		while ($row = mysql_fetch_assoc($rs)) 
		{         
		 // Affichage liste produit à retourner
	
			// Création de l'entête de ligne (TR)
			creetrlst($i);
	
			echo "<td>";
			echo $row["retp_code"];
			echo "</td>\n";
			echo "<td>";
			echo "<div align=\"center\">";
			echo formatedate($row["retp_datecrea"]);
			echo "<span class=\"annot_petit_it\">";
			$row2=lit_enr_retr($row["retp_code"],FALSE);
			if (is_array($row2))
			{
				if ($row2["retr_clos"]==1)
				{
					$lst_retps=TRUE;
					echo " <img src=\"../img/ok.png\" title =\"Trait&eacute; le ".formatedate($row2["retr_dateret"])."\" border=\"0\" align=\"absmiddle\">";
				}
			}
			else
			{
				if ($row["retp_codeenv"]<>"")
				{
					$row2=lit_enr_rete($row["retp_codeenv"],FALSE);
					if (formatedate($row["retp_dateenv"])<>"")
						echo "<br>Envoyé le ".formatedate($row["retp_dateenv"]);
					else
						echo "<br>Pr&ecirc;t &agrave; partir";
				}
				else
				{
					if (formatedate($row["retp_datedde"])<>"")
					{
						echo "<br>Demande le ".formatedate($row["retp_datedde"]);
						$row2=lit_enr_retd($row["retp_code"],FALSE);
						if (is_array($row2))
						{
							if (formatedate($row2["retd_daterep"])<>"")
								echo "<br>R&eacute;ponse le ".formatedate($row2["retd_daterep"]);
						}
					}
				}
			}
			echo "</span>";
			echo "</td>\n";
	
			echo "</div>";
			echo "</td>\n";
			if ($tx<>"e")
			{
				echo "<td>";
				echo $row["retp_codeage"];
				echo "</td>\n";
			}
			echo "<td>";
			echo "<span class=\"annot_std_gras\">";
			echo $row["retp_des"];
			echo "</span>";
			if ($row["retp_ns"]<>"")
				echo "<br>->N/S : ".$row["retp_ns"];
			echo "</td>\n";
			
			echo "<td align=\"center\">";
			if ($row["retp_codeint"]<>"-1")
				echo $row["retp_codeint"];
			else
				echo "-";
			echo "</td>\n";
	
			if ($tx<>"e")
			{
				echo "<td align=\"center\">";
				if ($row["retp_codeenv"]<>"")
					echo $row["retp_codeenv"];
				else
					echo "-";
				echo "</td>\n";
			}
	
			// CREATION lien dynamique sur icône (édition, suppression, etc...)
			if ($tx <> "e")
			{
				 echo "<td>";
				 echo "<div align=\"center\">";
		
				$voir=FALSE;
				
				if (($row["retp_codeenv"] <> "") OR (exist_enr_retr($row["retp_code"],FALSE)==TRUE) OR (exist_enr_retd($row["retp_code"],FALSE)==TRUE) OR (exist_enr_rete($row["retp_code"],FALSE)==TRUE))
					$voir=TRUE;
		
				if ($voir==FALSE)
				{
					$lst_maj = TRUE;
					echo "<a href=\"retp_maj.php?td=edit&cpr=".$row["retp_code"]."&ca=".$row["retp_codeage"]."\"><img src=\"../img/edit.png\" border=\"0\" align=\"absmiddle\" title=\"".$alt_edit."\"></a>";
					echo " ";
					if (@$_SESSION["niv_log"] >= 4)
					{
						$lst_retd = TRUE;
						echo "<a href=\"retd_maj.php?td=add&cpr=".$row["retp_code"]."\"><img src=\"../img/retd.png\" border=\"0\" align=\"absmiddle\" title=\"Ajouter\"></a>";
						echo " ";
					}
					$lst_del = TRUE;
					echo "<a href=\"retp_maj.php?td=del&cpr=".$row["retp_code"]."&ca=".$row["retp_codeage"]."\"><img src=\"../img/del.png\" border=\"0\" align=\"absmiddle\" title=\"".$alt_del."\"></a>";
					echo " ";
				}
				else
				{
					$lst_voir = TRUE;
					echo "<a href=\"retp_maj.php?td=view&cpr=".$row["retp_code"]."\"><img src=\"../img/eye.png\" border=\"0\" align=\"absmiddle\" title=\"".$alt_voir."\"></a>";
					echo " ";
				}
				 echo "</div>";
				 echo "</td>\n";
			}
			else
			{
				 echo "<td>";
				 echo "<div align=\"center\">";
				 $lst_retee = TRUE;
				 echo "<a href=\"retep_enr.php?td=add&tdo=".$td."&ce=".$ce."&cp=".$row["retp_code"]."\"><img src=\"../img/rete.png\" border=\"0\" align=\"absmiddle\" title=\"Demande de retour\"></a>";
				 echo " ";
				 echo "</div>";
				 echo "</td>\n";
			}	
			 echo "</tr>\n";
			
			$i++;    
		}  
		echo "</table>\n";
		// *** Fin affichage de la table
		
		mysql_free_result($rs);
		mysql_close($conn);  
		
		// *** Pagination de pied
		pagine_lst($numrows,$limit);
		
		$taille_piedla="";
		include_once("piedla.inc.php"); 
	}
	if ($tx<>"e") 
		include_once("pied.php");
	else
	{
		echo "<br>";
		echo "<div align=\"center\">";
	    echo '<input name="quit" type="button" class="bton_std" id="quit" value="'.$but_quit.'" onclick="javascript:; self.close(\'fscomp\');">';
		echo "</div>";
	}
}
else
{
	if ($tx=="e")
	{
?>
	<script type="text/javascript">
	<!--
	self.close('fscomp');
	//-->
	</script>
<?PHP
	}
}
?>
