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

Version 0.9.6
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 include ("../inc/func.inc.php") ?>
<?php include ("../inc/func_log.inc.php") ?>
<?php include ("../inc/func_txt.inc.php") ?>
<?PHP
	Archivelog(@$HTTP_SESSION_VARS["code_log"]);
?>
<?php
	 	// Variables Formulaire
		$titre = strip_tags(trim(@$_POST["titre"]));
		$typdde = strip_tags(trim(@$_POST["typdde"]));
		$codeint = strip_tags(trim(@$_POST["codeint"]));

		$code = str_majuscules(strip_tags(trim(@$_POST["code"])));
		$des = str_majuscules(strip_tags(trim(@$_POST["des"])));
		$qte = str_majuscules(strip_tags(trim(@$_POST["qte"])));
		if (!settype($qte,"float"))
		{
			echo "Pbm de conversion : ";
			echo $qte;
			echo "<br>";
			exit();
		}
		$pu = str_majuscules(strip_tags(trim(@$_POST["pu"])));
		if (!settype($pu,"float"))
		{
			echo "Pbm de conversion : ";
			echo $pu;
			echo "<br>";
			exit();
		}
		$ns = strip_tags(trim(@$_POST["ns"]));
		$texte = strip_tags(trim(@$_POST["texte"]));

		$retourliste = TRUE;

		if ($typdde == "add")
		{
			// Ajout de la fiche Produit Intervention
		
			$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
			mysql_select_db(DBNAME);
			$rech = "SELECT * FROM " .TBPDTI. " WHERE pdti_codeint = '$codeint' AND pdti_codepdt = '$code'";
			$rs = mysql_query($rech) or die(mysql_error());
			if (mysql_num_rows($rs) == 0)
			{
				$rech2 = "INSERT INTO " .TBPDTI;
				$rech2 .= " (pdti_codeint,pdti_codepdt,pdti_puttc,pdti_qte,pdti_ns,pdti_texte) VALUES";
				$rech2 .= " ('$codeint','$code','$pu','$qte','$ns','$texte')";
				$rs2 = mysql_query($rech2) or die(mysql_error());

				$msg = "Fiche Ajoutée avec succès !";			
			}
			else
			{
				$msg = "Ce code est déjà saisi dans cette intervention !";
				$retourliste = FALSE;
			}
			mysql_free_result($rs);
			mysql_close($conn);

		}

		if ($typdde == "edit")
		{
			$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
			mysql_select_db(DBNAME);

			// MAJ de la fiche Produit Intervention
		
			$rech = "UPDATE `" .TBPDTI. "` SET `pdti_codeint`='".$codeint."', `pdti_codepdt`='".$code."', `pdti_puttc`='".$pu."', `pdti_qte`='".$qte."', `pdti_ns`='".$ns."', `pdti_texte`='".$texte."'";
			$rech .= " WHERE `pdti_codeint` = '".$codeint."' AND `pdti_codepdt` = '".$code."'";
			$rs = mysql_query($rech) or die(mysql_error());
				
			mysql_close($conn);

			$msg = "Produit Ajouté avec succès !";
		}
		
		if ($typdde == "del")
		{
			$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
			mysql_select_db(DBNAME);

			// SUPPRESSION de la fiche Produit de l'intervention

			$rech = "DELETE FROM `" .TBPDTI. "` WHERE `pdti_codeint` = '$codeint' AND `pdti_codepdt` = '$code'";
			$rs = mysql_query($rech) or die(mysql_error());

			mysql_close($conn);

			$msg = "Produit supprimé avec succès !";
		}
?>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>SMI - ESPACE PRIVE : Article Intervention</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 -->
<link href="../inc/menu.css" rel="stylesheet" type="text/css">
<script language="JavaScript" src="../coolmenus/coolmenus4.js"></script>

<!-- Scripts Javascript pour affichages -->
<script language="JavaScript" src="../inc/aff.js"></script>

</head>
<body>

<p align="center"><span class="titrepage"><?PHP echo $titre ?></span></p>
<p align="center">&nbsp;</p>
<p align="center" class="annot_gras_it"><?PHP echo $msg ?></p>
<p align="center" class="annot_std_it">Retour à la fiche intervention dans 2 secondes...</p>

<!-- Fermeture temporisée -->
<script type="text/javascript">
	window.opener.location.reload();
	setTimeout("self.close('fscomp');",2000)
</script>
<p align="center">Sinon, <a href="javascript:void(0)" onClick="javascript:; window.opener.location.reload(); self.close('fscomp');">cliquez ici</a> </p>

</body>
</html>
