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

Copyright (C) 2006  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
****************************************************************************************/

include ("../inc/config.inc.php");
?>
<?php // require ("../inc/func.inc.php") ?>
<?php require ("../inc/func_log.inc.php") ?>
<?php // require ("../inc/fic.inc.php") ?>
<?PHP
	Archivelog(@$HTTP_SESSION_VARS["code_log"]);
?>
<?php
	$ci = strip_tags(trim(@$_POST["ci"])); // Récupération code Intervention
	$page = strip_tags(trim(@$_POST["page"])); // Récupération du numéro de page actuel
	$last = strip_tags(trim(@$_POST["last"])); // Récupération du dernier numéro de page

	// "Valider" : On valide simplement la fiche en cours
	if (strip_tags(trim(@$_POST["enr"])) ==  "Valider")
	{
		$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
		mysql_select_db(DBNAME);
		$rech = "UPDATE `" .TBRPBM. "` SET `rpbm_datemod`= '".$datea."', `rpbm_codemod`= '".$codeuser."', `rpbm_fait`= '".@$_POST["fait"]."' WHERE `rpbm_id`= '".@$_POST["nrpbm"]."'";
		$rs = mysql_query($rech) or die(mysql_error());
		mysql_close($conn); 
		header("Location: ".$_POST["urlcour"]);
	}
	
	// "Terminé" : on a fini de saisir tous les traitements
	if (strip_tags(trim(@$_POST["fin"])) ==  "Terminé")
	{
		$tab_txtfait=array();

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

		// On valide d'abord la fiche courante
		$rech = "UPDATE `" .TBRPBM. "` SET `rpbm_datemod`= '".$datea."', `rpbm_codemod`= '".$codeuser."', `rpbm_fait`= '".@$_POST["fait"]."' WHERE `rpbm_id`= '".@$_POST["nrpbm"]."'";
		$rs = mysql_query($rech) or die(mysql_error());

		// On crée ensuite le texte de la zone "fait" pour la fiche intervention
		$rech = "SELECT * FROM `" .TBRPBM. "` WHERE `rpbm_codeint`= '".$ci."'";
		$rs = mysql_query($rech);
		if (mysql_num_rows($rs) <> 0)
		{
			while ($row = mysql_fetch_array($rs)) 
			{
				extract ($row);
				
				if ($rpbm_fait <> "")
				{
					$txtfait_titre ="---- TRAVAIL EFFECTUE SUR PROBLEME N°".sprintf("%'010s",$rpbm_id)." ----";
					$txtfait_corps = $rpbm_fait;
					$txtfait_pied = "---- FIN TRAVAIL EFFECTUE SUR PROBLEME N°".sprintf("%'010s",$rpbm_id)." ----";
					$tab_txtfait[]=array($txtfait_titre,$txtfait_corps,$txtfait_pied);
				}
			}
		}
		mysql_free_result($rs);
		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 - ESPACE PRIVE : Traitement Probl&egrave;mes</title>

<!-- Script Javascript pour moulinage des tableaux-->
<script language="JavaScript" src="../inc/phparray2js.js"></script>

</head>

<body>

<?PHP
// Si le formulaire a été validé en entier, on transfère dans la fiche intervention
if (strip_tags(trim(@$_POST["fin"])) == "Terminé")
{
?>
	<script type="text/javascript">
		var tableau1 = new PhpArray2Js("<?php echo htmlspecialchars(serialize($tab_txtfait)); ?>");
		var tab1 = tableau1.retour();
		var texte1 ="";
		
	
		for (i=0; i<tab1.length; i++)
		{
			texte1 += tab1[i].join("\n")+"\n\n";
		}
	
		window.opener.document.int_maj.fait.value=texte1;
		window.opener.document.int_maj.fait.readOnly = true;
		self.close();
	</script>
<?PHP
}
?>

</body>
</html>
