<?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_age.inc.php");
include_once("../inc/fic_cli.inc.php");
include_once("../inc/fic_co.inc.php");
include_once("../inc/fic_cocl.inc.php");
include_once("../inc/fic_do.inc.php");
include_once("../inc/fic_hum.inc.php");
include_once("../inc/fic_int.inc.php");
include_once("../inc/fic_mque.inc.php");
include_once("../inc/fic_ot.inc.php");
include_once("../inc/fic_ret.inc.php");
include_once("../inc/fic_st.inc.php");
include_once("../inc/fic_statut.inc.php");
include_once("../inc/fic_tec.inc.php");
include_once("../inc/fic_txt.inc.php");
include_once("../inc/func.inc.php");
include_once("../inc/func_time.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/func_txtcm.inc.php");
include_once("../inc/func_mail.inc.php");
include_once("../classes/phpmailer/class.phpmailer.php");
include_once("../inc/mail.inc.php");
Archivelog(@$_SESSION["code_log"]);

// Variables Formulaire
$titre = stripslashes(strip_tags(trim(@$_POST["titre"])));
$td = strip_tags(trim(@$_POST["td"]));

$coderetp = strip_tags(trim(@$_POST["coderetp"]));
$datedde = datefrang(strip_tags(trim(@$_POST["dateddef"])));
$codemque = strip_tags(trim(@$_POST["codemque"]));
$codepdtm = strip_tags(trim(@$_POST["codepdtm"]));
$blf = strip_tags(trim(@$_POST["blf"]));
$nblf = strip_tags(trim(@$_POST["nblf"]));
$dblf = datefrang(strip_tags(trim(@$_POST["dblff"])));
$gar = strip_tags(trim(@$_POST["gar"]));
$codemd = strip_tags(trim(@$_POST["codemd"]));
$dossier = strip_tags(trim(@$_POST["dossier"]));
$urgence = strip_tags(trim(@$_POST["urgence"]));
$imprimer= strip_tags(trim(@$_POST["imprimer"]));
$daterep = datefrang(strip_tags(trim(@$_POST["daterepf"])));
$rma = strip_tags(trim(@$_POST["rma"]));

$codeuser = @$_SESSION["code_log"];

$msg="";
$retourliste = TRUE;

if ($imprimer=="ok")
	$retourliste=FALSE;

switch ($td)
{
	// Ajout de la fiche demande de retour
	case "add" :
		if (exist_enr_retd($coderetp,TRUE)==FALSE)
		{
			$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
			mysql_select_db(DBNAME);
			$rech2 = "INSERT INTO " .TBRETD;
			$rech2.= " (retd_coderetp,retd_datedde,retd_codemque,retd_codepdtm,retd_blf,retd_nblf,retd_dblf,retd_gar,retd_codemd,retd_dossier,retd_nivurg,retd_daterep,retd_rma)";
			$rech2.= " VALUES";
			$rech2.= " ('$coderetp','$datedde','$codemque','$codepdtm','$blf','$nblf','$dblf','$gar','$codemd','$dossier','$urgence','$daterep','$rma')";
			$rs2 = mysql_query($rech2) or die(mysql_error());

			// On met à jour la fiche produit correspondante
			$rech = "UPDATE `".TBRETP. "` SET";
			$rech.= " `retp_datedde`='".$datedde."', `retp_daterep`='".$daterep."' ";
			$rech.= " WHERE `retp_code` = '".$coderetp."'";
			$rs = mysql_query($rech) or die(mysql_error());

			mysql_close($conn);
			$msg = "Fiche enregistrée";
		}
		else
		{
			$msg = "Demande d&eacute;j&agrave; effectu&eacute;e pour ce produit!";
			$retourliste = FALSE;
		}
/*	
		if ($retourliste == TRUE)
		{
			// Envoi d'email vers le webmaster
			envoi_mailwm("","Produit à retourner","retp","cre","xxx","age",$codepr,"","");
			// Envoi d'email vers l'agence (Si pas créé par une agence)
			if ((@$_SESSION["niv_log"] <> 4) AND (@$_SESSION["niv_log"] <> 3))
				envoi_mail("","Produit à retourner","retp","cre","xxx","age",$codepr,"","",FALSE);
			// Envoi d'email vers le centre de gestion (Si pas créé par le CDG)
			if (@$_SESSION["niv_log"] <> 5)
				envoi_mail("","produit à retourner","retp","cre","xxx","cdg",$codepr,"","",FALSE);
		}*/
		break;
		
	// MAJ de la fiche demande de retour
	case "edit" :
		
		$maj_retd_ok=TRUE;

		if (exist_enr_rete($coderetp,TRUE)==TRUE)
		{
			$maj_retd_ok=FALSE;
			$msg = "Le produit a d&eacute;j&agrave; &eacute;t&eacute; renvoy&eacute;";
			$retourliste = FALSE;
		}
		
		$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
		mysql_select_db(DBNAME);
		if ($maj_retd_ok==TRUE)
		{
			$rech = "UPDATE `" .TBRETD. "` SET";
			$rech .=" `retd_codemd`='".$codemd."', `retd_dossier`='".$dossier."', `retd_codepdtm`='".$codepdtm."',";
			$rech .=" `retd_blf`='".$blf."', `retd_nblf`='".$nblf."', `retd_dblf`='".$dblf."',";
			$rech .=" `retd_gar`='".$gar."', `retd_nivurg`='".$urgence."', ";
			$rech .=" `retd_daterep`='".$daterep."', `retd_rma`='".$rma."'";
			$rech .=" WHERE `retd_coderetp` = '".$coderetp."'";
			$rs = mysql_query($rech) or die(mysql_error());

			// On met à jour la fiche produit correspondante
			$rech = "UPDATE `".TBRETP. "` SET";
			$rech.= " `retp_datedde`='".$datedde."', `retp_daterep`='".$daterep."' ";
			$rech.= " WHERE `retp_code` = '".$coderetp."'";
			$rs = mysql_query($rech) or die(mysql_error());
					
			$msg = "Fiche mise &agrave; jour.";
		}
		mysql_close($conn);
	
		break;		


	// Suppression de la fiche demande de retour
	case "del" :
		if ((exist_enr_retr($code,TRUE)==FALSE) AND (exist_enr_rete($code,TRUE)==FALSE))
		{
			$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
			mysql_select_db(DBNAME);
			$rech = "DELETE FROM `" .TBRETD. "` WHERE `retd_coderetp` = '$coderetp'";
			$rs = mysql_query($rech) or die(mysql_error());

			// On met à jour la fiche produit correspondante
			$rech = "UPDATE `".TBRETP. "` SET `retp_datedde`='0000-00-00', ";
			$rech.= " `retp_daterep`='0000-00-00' ";
			$rech.=" WHERE `retp_code` = '".$coderetp."'";
			$rs = mysql_query($rech) or die(mysql_error());
					
			$msg = $txt_fiche_del;
		}
		else
		{
			if (exist_enr_retr($code,TRUE)==TRUE)
				$msg = "Ce retour a d&eacute;&agrave; &eacute;t&eacute; trait&eacute;.";
			else
				$msg = "Ce retour a d&eacute;&agrave; &eacute;t&eacute; renvoy&eacute;.";
			$retourliste = FALSE;
		}
		break;
		
	default :
		break;
}
?>
<!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; ?> : Fiche Demande 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>



</head>
<body>
<?php 
include_once("../inc/entete.inc.php"); 
?>
<p align="center"><span class="titrepage"><?PHP echo $titre ?></span></p>
<p align="center">&nbsp;</p>
<p align="center">
<?PHP if ($retourliste==FALSE)
	echo '<span class="alerte1">';
else
	echo '<span class="annot_std_gras">';
?>
<?PHP echo $msg ?>
</span>
</p>

<br>
<br>
<?PHP if ($retourliste == FALSE) 
{ 
	if ($imprimer=="ok")
	{
		$urlimp = "retd_pdf.php?cpr=".$coderetp;
?>
	<script type="text/javascript">
	<!--
	lanceimp('<?PHP echo $urlimp; ?>');
	//-->
	</script>
<?PHP
		aff_ret_lst_auto("retd_lst.php?ord=DES&tri=Demande%20le",2000);
	} 
	else
		aff_ret_idx_man($td,"retd_lst.php?ord=DES&tri=Demande%20le",$txt_lnk_ret_liste,TRUE);
} 
else 
{
	aff_ret_lst_auto("retd_lst.php?ord=DES&tri=Demande%20le",2000);
}
include_once("pied.php");
?>
