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

$pbm_retr = FALSE;

if (isset($_GET['cpr']))
	$cpr = strip_tags(trim($_GET['cpr'])); // Récupération code Produit à Retourner
else
	$pbm_retr = TRUE;
if (isset($_GET['td']))
	$td = strip_tags(trim($_GET['td'])); // Récupération type de demande
else
	$pbm_retr = TRUE;
if (isset($_GET['tdo']))
	$tdo = strip_tags(trim($_GET['tdo'])); // Récupération type de demande de la fiche envoi
else
	$pbm_retr = TRUE;
if (isset($_GET['ce']))
	$ce = strip_tags(trim($_GET['ce'])); // Récupération code envoi
else
	$pbm_retr = TRUE;
$tx="";
if (isset($_GET['tx']))
	$tx = strip_tags(trim($_GET['tx'])); // Récupération source appel (tx=e -> appel depuis fiche de renvoi)

if ($cpr <> "")
{
	// Récupération des informations demande de retour
	$row = lit_enr_retr($cpr,TRUE);
	if (is_array($row))
	{
		extract ($row);
		
		if ($td<>"del")
		{
			if ($retr_clos==1)
				$td="view";
		}

		// Formatage des dates en français
		$retr_dateretf = formatedate($retr_dateret);
	}
	else
	{
		if ($td=="add")
		{
			$row = lit_enr_retp($cpr,TRUE);
			if (is_array($row))
				extract ($row);
			else
				$pbm_retr = TRUE;
		}
		else
			$pbm_retr = TRUE;
	}
	
	// Récupération fiche produit à retourner
	$row = lit_enr_retp($cpr,TRUE);
	if (is_array($row))
	{
		extract ($row);
		
		// Contrôle qu'une agence n'essaye pas de "hacker" un retour
		if ((@$_SESSION["niv_log"] == 4) AND ($retp_codeage <> @$_SESSION["code_age"]))
			$pbm_retr = TRUE;
	}
	else
		$pbm_retr = TRUE;

	// Récupération fiche d'envoi
	$row = lit_enr_rete($ce,TRUE);
	if (is_array($row))
	{
		extract ($row);
		
		// Formatage des dates en français
		$rete_dateenvf = formatedate($rete_dateenv);
	
		// Contrôle qu'une agence n'essaye pas de "hacker" un retour
		if ((@$_SESSION["niv_log"] == 4) AND ($rete_codeage <> @$_SESSION["code_age"]))
			$pbm_retr = TRUE;

		if ($rete_clos==0)
			$pbm_retr = TRUE;
	}
	else
		$pbm_retr = TRUE;

	// Récupération fiche demande de retour
	$row = lit_enr_retd($cpr,TRUE);

	if (is_array($row))
		extract ($row);
	else
		$pbm_retr = TRUE;
}
else
	$pbm_retr=TRUE;

switch ($td)
{
	case "add" :
		$titre = "SAISIE TRAITEMENT RETOUR";
		break;
	case "edit" :
		$titre = "MISE A JOUR TRAITEMENT RETOUR";
		break;
	case "view" :
			$titre = "DETAIL TRAITEMENT RETOUR";
		break;
	case "del":
		$titre = "SUPPRESSION TRAITEMENT RETOUR";
		break;
	default:
			$titre = "PROBLEME";
			$pbm_retr=TRUE;
		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 Traitement 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 pour vérifications -->
<script language="JavaScript" src="../jscript/verif_field.js"></script>

<!-- Scripts Javascript pour vérifications de formulaire -->
<script language="JavaScript" src="../jscript/verif_form.js"></script>

<!-- Définition Javascript pour calendrier popup -->
  <!-- Feuille de Style -->
  <link rel="stylesheet" type="text/css" media="all" href="../jscript/jscal/skins/aqua/theme.css" title="Aqua" />

  <!-- Script Javascript Principal -->
  <script type="text/javascript" src="../jscript/jscal/calendar.js"></script>

  <!-- Choix du langage -->
  <script type="text/javascript" src="../jscript/jscal/lang/calendar-<?PHP echo $_SESSION["lng"]; ?>.js"></script>

  <!-- the following script defines the Calendar.setup helper function, which makes
       adding a calendar a matter of 1 or 2 lines of code. -->
  <script type="text/javascript" src="../jscript/jscal/calendar-setup.js"></script>
<!-- Fin de la définition Javascript pour calendrier popup -->

<!-- Scripts Javascript pour contrôle de formulaire -->
<script	type="text/javascript" src="../jscript/vform/vform.js"></script>


<?PHP 
if (($td == "edit")  OR ($td=="add"))
{
?>
<script language="javascript">
<!--
var tab1_champ=new Array(
	"nom:dateretf ; format:date ; masque:<?PHP echo $datemsql; ?> ; req:Y ; txt:Date retour ; stok:frmok ; stbad:frmbad",
	"nom:typeope; format:liste ; req:Y ; txt:Type opération ; vmn:1 ; stok:frmok ; stbad:frmbad",
	"nom:codeme; format:liste ; req:Y ; txt:Moyen d'envoi ; vmn:1 ; stok:frmok ; stbad:frmbad",
	"nom:bord; format:txt ; req:N ; txt:Bordereau ; lmx:20 ; stok:frmok ; stbad:frmbad");
//-->
</script>
<?PHP
}
?>

<!-- Scripts Javascript pour contrôle de formulaire -->
<script	type="text/javascript" src="../jscript/verif_form.js"></script>

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

<!-- Scripts Javascript pour contrôle de champs -->
<script	type="text/javascript" src="../jscript/verif_field.js"></script>

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

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

</head>

<?PHP	
switch ($td)
{
case "del" :
case "view" :
	echo '<body onLoad="metReadonly();">';
	break;
default :
	echo '<body onLoad="metFocus();">';
	break;
}
?>
<?PHP
if ($pbm_retr == FALSE)
{
	if ($tx<>"e") include_once("../inc/entete.inc.php");
?>
<p align="center"> <span class="titrepage"><?PHP echo $titre ?></span></p>
<table width="100%"  border="0">
<tr>
	<td width="40%">
	<?PHP if ($tx<>"e") { ?>
	<strong><em><a href="retr_lst.php?ord=DES&tri=Date"><?PHP echo $txt_lnk_ret_liste; ?></a></em></strong>
	<?PHP } else { ?>
	&nbsp;
	<?PHP } ?></td>
	<td width="160" valign="top">
	<div id="oblig" align="center" class="annot_petit_it">(<img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>"> : <?PHP echo $txt_div_saisoblg; ?>)</div>
	</td>
	<td width="40%" align="right">&nbsp;</td>
</tr>
</table>
<form name="retr_maj" method="post" action="retr_enr.php" onSubmit="javascript:; return (verif_retr(this,tab1_champ,'',''));">
<input name="titre" type="hidden" id="titre" value="<?PHP echo $titre ?>">
<input name="td" type="hidden" id="td" value="<?PHP echo $td ?>">
<input name="tdo" type="hidden" id="tdo" value="<?PHP echo $tdo ?>">
<input name="tx" type="hidden" id="tx" value="<?PHP echo $tx ?>">
<input name="coderetp" type="hidden" id="coderetp" value="<?PHP echo $cpr ?>">
<input name="ce" type="hidden" id="ce" value="<?PHP echo $ce ?>">

<!-- Produit traité -->
<table width="100%"  border="0">
<tr>
	<td width="160" class="rubfrm" id="f_retp1" align="right">Produit (N/S)</td>
	<td>
		<span class="annot_std_gras"><?PHP echo $retp_des; ?> (<?PHP echo $retp_ns; ?>)</span>
	</td>
</tr>
<tr>
	<td width="160" class="rubfrm" id="f_retp2" align="right">Num&eacute;ro de retour</td>
	<td>
		<span class="annot_std_gras"><?PHP echo $retd_rma; ?></span>
	</td>
</tr>
<tr>
	<td width="160" class="rubfrm" id="f_retp3" align="right">Renvoy&eacute; le</td>
	<td>
		<input name="dateenvf" type="text" id="dateenvf" value="<?PHP echo $rete_dateenvf ?>" readonly="readonly">
	</td>
</tr>
</table>

<!-- Date renvoi -->
<table width="100%"  border="0">
<tr>
	<td width="160" class="rubfrm" id="f_dateretf" align="right">Date traitement</td>
	<td>
		<input name="dateretf" type="text" id="dateretf" value="<?PHP echo $retr_dateretf ?>" size="10" maxlength="10" readonly="1">
		<?PHP if (($td == "add") OR ($td == "edit")) { ?>
		<img src="../img/calendar.png" align="absmiddle" id="f_img_dateretf" title="<?PHP echo $alt_chxdate; ?>">
		<img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">
		<?PHP } ?>
	</td>
</tr>
</table>

<!-- Opération effectuée -->
<table width="100%"  border="0">
<tr>
	<td width="160" class="rubfrm" id="f_typeope" align="right">Statut</td>
	<td>
	<?PHP
	if (($td =="add") OR ($td=="edit"))  // Ajout/Edition = zone modifiable (on peut choisir un statut)
	{?>
		<select name="typeope" id="typeope">
		<option>-- Choisissez un statut --</option>
		<?PHP
		foreach ($ope_types as $key=>$value)
		{
			echo '<option value="'.$key.'"'; 
			if (($retr_typeope == $key) AND ($td=="edit"))
				echo ' selected';
			echo '>';
			echo $value."</option>";
		}
		?>
		</select>
		<img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">
	<?PHP
	}
	else
	{
	?>
	<input name="typeope" type="hidden" id="typeope" value="<?PHP echo $retr_typeope; ?>">
	<input name="nomtypeope" type="text" id="nomtypeope" value="<?PHP echo $doc_types[$retr_typeope]; ?>" size="20" maxlength="20" readonly="readonly">
	<?PHP
	}
	?>
	</td>
</tr>
</table>

<!-- Avoir -->
<table width="100%"  border="0">
<tr>
	<td width="160" class="rubfrm" id="f_avoir" align="right">N° avoir<br>(si avoir)</td>
	<td>
		<input name="avoir" type="text" id="avoir" value="<?PHP echo $retr_avoir ?>" size="20" maxlength="20">
	</td>
</tr>
</table>

<!-- Numéro de série -->
<table width="100%"  border="0">
<tr>
	<td width="160" class="rubfrm" id="f_ns" align="right">N° s&eacute;rie<br>(si &eacute;chang&eacute;)</td>
	<td>
	<input name="ns" type="text" id="ns" value="<?PHP echo $retr_ns; ?>" size="20" maxlength="20">
	</td>
</tr>
</table>

<!-- Motif -->
<table width="100%"  border="0">
<tr>
	<td width="160" class="rubfrm" id="f_raison" align="right">Motif<br>(si refus&eacute;<br /> ou rien fait)</td>
	<td>
		<?PHP
		if (($td == "add") OR ($td == "edit"))
		{
		?>
		<textarea name="raison" rows="5" id="raison"><?PHP echo htmlspecialchars($retr_raison,ENT_QUOTES); ?></textarea>
		<?PHP
		}
		else
		{
		?>
		<textarea name="raison" rows="5" id="raison" readonly="readonly"><?PHP echo htmlspecialchars($retr_raison,ENT_QUOTES); ?></textarea>
		<?PHP
		}
		?>
	</td>
</tr>
</table>

<!-- Effectué -->
<table width="100%"  border="0">
<tr>
	<td width="160" class="rubfrm" id="f_fait" align="right">Effectu&eacute;<br>(si r&eacute;par&eacute;)</td>
	<td>
		<?PHP
		if (($td == "add") OR ($td == "edit"))
		{
		?>
		<textarea name="fait" rows="5" id="fait"><?PHP echo htmlspecialchars($retr_fait,ENT_QUOTES); ?></textarea>
		<?PHP
		}
		else
		{
		?>
		<textarea name="fait" rows="5" id="fait" readonly="readonly"><?PHP echo htmlspecialchars($retr_fait,ENT_QUOTES); ?></textarea>
		<?PHP
		}
		?>
	</td>
</tr>
</table>

<!-- Mode d'envoi -->
<table width="100%"  border="0">
<tr>
	<td width="160" class="rubfrm" id="f_codeme" align="right">Mode d'envoi</td>
	<td>
		<?PHP
		if (($td =="add") OR ($td=="edit"))  // Ajout/Edition = zone modifiable (on peut choisir un mode)
		{ 
			// Création de la liste des mode d'envoi
			$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
			mysql_select_db(DBNAME);
			// Filtre sur agences ouvertes
			$rech = "SELECT * FROM ".TBME." ORDER BY me_nom";
			$rs = mysql_query($rech) or die(mysql_error());

			echo '<select name="codeme" id="codeme" onChange="verif_bord2(this.value);">';
			echo "<option>-- Choisissez un mode --</option>";
			echo "<option value=\"-1\"";
			if ($retr_codeme == "-1")
				echo ' selected';
			echo ">Sans objet";
			echo "</option>";

			if (mysql_num_rows($rs) <> 0)
			{
					while ($resultat = mysql_fetch_array($rs)) 
					{
						extract($resultat);
		
						echo '<option value="'.$me_code.'"';
						if ($retr_codeme == $me_code)
							echo ' selected';
						echo '>'.$me_nom.'</option>';
					}
			}
			echo "</select>";
			echo '<img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">';
			mysql_free_result($rs);
			mysql_close($conn);
			$urlcreeme = "me_maj.php?td=add&tx=r";
		?>
		<a href="javascript:;" onclick="fensaisie2('<?PHP echo $urlcreeme; ?>',1024,600,'status=no,scrollbars=yes,menubar=no,statusbar=no,location=no,locationbar=no');")><img src="../img/add.png" border="0" align="absmiddle"></a>
		<a href="javascript:;" onclick="fensaisie2('<?PHP echo $urlcreeme; ?>',1024,600,'status=no,scrollbars=yes,menubar=no,statusbar=no,location=no,locationbar=no');")> Ajouter un mode</a>
		<?PHP
		}
		else  // Edition ou suppression = zone non modifiable (affichage seul)
		{
			if ($retr_codeme<>"-1")
			{
				$row = lit_enr_me($retr_codeme,TRUE);
				if (is_array($row))
					extract($row);
			}
			else
				$me_nom="Sans objet";
		?>
		<input name="codeme" type="hidden" id="codeme" value="<?PHP echo $retr_codeme ?>">	
		<input name="nomme" type="text" id="nomme" value="<?PHP echo $me_nom ?>" size="50" maxlength="50" readonly="1">
		<?PHP 
		} 
		?>
	</td>
</tr>
</table>

<!-- Numéro de bordereau -->
<table width="100%"  border="0">
<tr>
	<td width="160" class="rubfrm" id="f_bord" align="right">Bordereau envoi<br>(Si mode d'envoi)</td>
	<td>
		<?PHP
		if (($td == "add") OR ($td == "edit"))
		{ 
		?>
			<input name="bord" type="text" id="bord" value="<?PHP echo htmlspecialchars($retr_bord) ?>" size="20">
		<?PHP } else { ?>
			<input name="bord" type="text" id="bord" value="<?PHP echo htmlspecialchars($retr_bord) ?>" size="20" readonly="1">
		<?PHP } ?>
	</td>
</tr>
</table>

<?PHP if (($td=="add") OR ($td=="edit")) { ?>
<!-- Cloture de fiche -->
<table width="100%"  border="0">
<tr>
	<td width="160" class="rubfrm" id="f_clos" align="right">Clore ce traitement</td>
	<td>
		<input type="checkbox" name="clos" id="clos" value="ok" <?PHP if ($retr_clos==1) echo 'checked="checked"'; ?>>
		<br><span class="annot_petit_it">(Si coch&eacute;, cette fiche sera valid&eacute;e et ne sera plus modifiable)</span>
	</td>
</tr>
</table>
<?PHP } else { ?>
<input type="hidden" name="clos" id="clos" value="<?PHP if ($rete_clos==1) echo "ok"; ?>">
<?PHP } ?>
  

  
<p align="center">
<?PHP
if (($td == "edit") OR ($td == "add"))
{
?>
	<input name="RAZ" type="reset" class="bton_std" id="RAZ" value="<?PHP echo $but_reinit; ?>">
	<input name="enr" type="submit" class="bton_std" id="enr" value="<?PHP echo $but_enr; ?>">
<?PHP
}
if ($td == "del") // Bouton si en mode suppression
{ 
?>
	<input name="del" type="submit" class="bton_std" id="del" value="<?PHP echo $but_del; ?>">
<?PHP 
} 
	if ($tx=="e") {
?>
<input name="quit" type="button" class="bton_std" id="quit" value="<?PHP echo $but_quit; ?>" onclick="javascript:; self.close('fscomp');">
<?PHP
	} else {
	include_once("pied.php");
	}
?>
</p>
</form>
<?PHP 
	if (($td <> "view") AND ($td<>"del"))
	{
	?>
		<script type="text/javascript">
<!--
		Calendar.setup({
			inputField     :    "dateretf",     // id of the input field
			ifFormat       :    "<?PHP echo $datefmtc; ?>",      // format of the input field
			button         :    "f_img_dateretf",  // trigger for the calendar (button ID)
			align          :    "Br",           // alignment (defaults to "Bl")
			electric	   :	false,
			singleClick    :    true
		});
		</script>
<?PHP
	}
}
else
{
?>
	<script type="text/javascript">
	<!--
<?PHP
	if ($tx=="e")
	{
?>
	self.close('fscomp');
<?PHP
	} else {
?>
	setTimeout("self.location.href=('index.php');",2000)
<?PHP
	}
?>
	//-->
	</script>
	<p align="center" class="annot_std_it">Probl&egrave;me de param&egrave;tres</p>
<?PHP
}
?>
