<?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"]);
$fi="";
if (isset($_GET['fi']) && (trim($_GET['fi'])<>""))
	$fi=intval(strip_tags(trim($_GET['fi'])));
?>
<!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 demandes de retour</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 include_once("../inc/entete.inc.php"); ?>
<p align="center"><span class="titrepage">LISTE DES DEMANDES DE RETOUR</span></p>
<?PHP
$fic_imp = "retd_lsti.php";
$tab_fi[]="Toutes les demandes";
$tab_fi[]="Demandes sans réponse";

$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
mysql_select_db(DBNAME);

$rech = cree_strrechlstretd();
if (@$_SESSION["niv_log"] == 4)
{
	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 retd_daterep='0000-00-00'";
		else
			$rech .= " AND retd_daterep='0000-00-00'";
		break;
	default :
		break;
}
$rech .= crestr_triord($retd_titre_col,"retd_datedde",FALSE,$limit);
$rs = mysql_query($rech) or die(mysql_error());
$numrows = mysql_num_rows($rs); // Nombre de résultats à la requête

if($numrows == 0)
{
	retpp();
}
 else
{
	include_once("formr.inc.php"); 

	$rech = cree_strrechlstretd();
	if (@$_SESSION["niv_log"] == 4)
	{
		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 retd_daterep='0000-00-00'";
			else
				$rech .= " AND retd_daterep='0000-00-00'";
			break;
		default :
			break;
	}
	$rech .= crestr_triord($retd_titre_col,"retd_datedde",TRUE,$limit);

	$rs = mysql_query($rech) or die(mysql_error());

	// *** Pagination de pied
	pagine_lst($numrows,$limit);

	// *** Affichage de la table
	 echo "<table class=\"Mtable\" border=\"0\" width=\"100%\" cellpadding=\"0\" cellspacing=\"0\">\n";     

	// Création entête
	titlst($retd_titre_col);
	echo "<th>".ucfirst($txt_ent_lst_clic)."</th>\n";
		
	
	$i = 0;
	
	
	while ($row = mysql_fetch_assoc($rs)) 
	{         
	 // Affichage liste Demandes de retours

		// Création de l'entête de ligne (TR)
		creetrlst($i);

		echo "<td align=\"center\">";
		echo formatedate($row["retd_datedde"]);
		echo "</td>\n";
		echo "<td>";
		echo $row["retd_coderetp"];
		$row2=lit_enr_retr($row["retd_coderetp"],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\">";
			}
		}
		echo " <a href=\"retp_maj.php?td=view&cpr=".$row["retp_code"]."\"><img src=\"../img/eye.png\" width=\"14\" height=\"14\" border=\"0\" align=\"absmiddle\" title=\"Voir fiche\"></a>";
		$row2=lit_enr_mque($row["retd_codemque"],FALSE);
		if (is_array($row2))
		{
			echo "<span class=\"annot_petit_it\">";
			echo "<br> ->".$row2["mque_ste"];
			echo " <a href=\"mque_maj.php?td=edit&code=".$row["mque_code"]."\"><img src=\"../img/eye.png\" width=\"14\" height=\"14\" border=\"0\" align=\"absmiddle\" title=\"Voir fiche\"></a>";
			echo "</span>";
		}
		$row2=lit_enr_retp($row["retd_coderetp"],FALSE);
		if (is_array($row2))
		{
			echo "<span class=\"annot_petit_it\">";
			echo "<br> ->".$row2["retp_des"]." (".$row2["retp_ns"].")";
			echo "</span>";
		}
		echo "</td>\n";
		echo "<td align=\"center\">";
		echo formatedate($row["retd_daterep"]);
		echo "</td>\n";
		echo "<td align=\"center\">";
		echo "<span class=\"annot_std_gras\">";
		echo $row["retd_rma"];
		echo "</span>";
		echo "</td>\n";
		echo "<td align=\"center\">";
		if ($row["retp_codeenv"]<>"")
		{
			echo $row["retp_codeenv"];
			if (envoi_clos($row["retp_codeenv"],FALSE)==TRUE)
			{
				$lst_env=TRUE;
				echo " <img src=\"../img/ok.png\" title =\"Envoyé le ".formatedate(date_envoi($row["retp_codeenv"],FALSE))."\" border=\"0\" align=\"absmiddle\">";
			}
			echo " <a href=\"rete_maj.php?td=edit&ce=".$row["retp_codeenv"]."\"><img src=\"../img/eye.png\" width=\"14\" height=\"14\" border=\"0\" align=\"absmiddle\" title=\"Voir fiche\"></a>";
		}
		else
			echo "-";
		echo "</td>\n";
		
		// CREATION lien dynamique sur icône (édition, suppression, etc...)
		 echo "<td>";
		 echo "<div align=\"center\">";

		$voir=FALSE;
		
		if (($row2["retp_codeenv"] <> "") OR (exist_enr_rete($row["retd_code"],FALSE)==TRUE))
			$voir=TRUE;

		if ($voir==FALSE)
		{
			$lst_maj = TRUE;
			echo "<a href=\"retd_maj.php?td=edit&cpr=".$row["retd_coderetp"]."\"><img src=\"../img/edit.png\" border=\"0\" align=\"absmiddle\" title=\"".$alt_edit."\"></a>";
			echo " ";
		}
		else
		{
			$lst_voir = TRUE;
			echo "<a href=\"retd_maj.php?td=view&cpr=".$row["retd_coderetp"]."\"><img src=\"../img/eye.png\" border=\"0\" align=\"absmiddle\" title=\"".$alt_voir."\"></a>";
			echo " ";
		}
		$lst_imp = TRUE;
		$urlimp = "retd_pdf.php?cpr=".$row["retd_coderetp"];
		echo "<a href=\"javascript:;\" onclick=\"lanceimp('".$urlimp."');\")><img src=\"../img/print.png\" title=\"Imprimer la demande\" border=\"0\" align=\"absmiddle\"></a>";
		echo " ";
		if ($voir==FALSE)
		{
			$lst_del = TRUE;
			echo "<a href=\"retd_maj.php?td=del&cpr=".$row["retd_coderetp"]."\"><img src=\"../img/del.png\" border=\"0\" align=\"absmiddle\" title=\"".$alt_del."\"></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"); 
}
include_once("pied.php");
?>
