<?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_ret.inc.php");
include_once("../inc/func.inc.php");
include_once("../inc/func_txt.inc.php");
Archivelog(@$_SESSION["code_log"]);

// Variables Formulaire
$td = strip_tags(trim(@$_GET["td"]));
$tdo = strip_tags(trim(@$_GET["tdo"]));
$ce = str_majuscules(strip_tags(trim(@$_GET["ce"])));
$cp = str_majuscules(strip_tags(trim(@$_GET["cp"])));

$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
mysql_select_db(DBNAME);
switch ($td)
{
	// Ajout du produit dans la fiche d'envoi
	case "add" :
		$rech = "INSERT INTO " .TBRETEP
		. " (retep_codeenv,retep_coderetp)"
		. " VALUES"
		. " ('$ce','$cp')";
		$rs = mysql_query($rech) or die(mysql_error());

		// On met ŕ jour la fiche produit correspondante
		$rech = "UPDATE `" .TBRETP. "` SET `retp_codeenv`='".$ce."'";
		$rech .=" WHERE `retp_code` = '".$cp."'";
		$rs = mysql_query($rech) or die(mysql_error());
		break;
		
	// Suppression du produit dans la fiche d'envoi
	case "del" :
		$rech = "DELETE FROM `" .TBRETEP. "` WHERE `retep_codeenv` = '$ce' AND `retep_coderetp` = '$cp' ";
		$rs = mysql_query($rech) or die(mysql_error());

		// On met ŕ jour la fiche produit correspondante
		$rech = "UPDATE `".TBRETP. "` SET `retp_codeenv`=NULL, `retp_dateenv`='0000-00-00' ";
		$rech .=" WHERE `retp_code` = '".$cp."'";
		$rs = mysql_query($rech) or die(mysql_error());
				
		break;
		
	default :
		break;
}
mysql_close($conn);
?>
<!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">

</head>
<body>
<?PHP
cre_js_pdte($tdo,$ce,"window.opener."); 
?>
<script type="text/javascript">
<!--
updatenv();
var objet1 = window.opener.document.getElementById('clos');
var objet2 = window.opener.document.getElementById('butimp');
var objet3 = window.opener.document.getElementById('nbcol');
var objet4 = window.opener.document.getElementById('imp');
<?PHP  if (nb_art_in_envoi($ce,TRUE)>0) { ?>
objet1.disabled = false;
objet2.style.visibility = "visible";
objet3.disabled = false;
objet4.style.display = "block";
<?PHP } else { ?>
objet1.disabled = true;
objet2.style.visibility = "hidden";
objet3.disabled = true;
objet4.style.display = "none";
<?PHP } ?>
self.close('fscomp');
//-->
</script>
