<?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");

if (!isset($_SESSION["lng"])) $_SESSION["lng"]="fr";
include_once("../lng/".$_SESSION["lng"].".inc.php"); // Paramètres de language
include_once("../inc/config.inc.php");
include_once("../inc/fic_loc.inc.php");
include_once("../inc/func.inc.php");
include_once("../inc/func_log.inc.php");
include_once("../inc/func_geo.inc.php");
include_once("../inc/func_txt.inc.php");
Archivelog(@$_SESSION["code_log"]);
if (!isset($_SESSION["pdtlbl"])) $_SESSION["pdtlbl"]=array();
if (!isset($_SESSION["pdtlpl"])) $_SESSION["pdtlpl"]=array();
if (!isset($_SESSION["pdtlcl"])) $_SESSION["pdtlcl"]=array();

// Variables Formulaire
$titre = stripslashes(strip_tags(trim(@$_POST["titre"])));
$td = strip_tags(trim(@$_POST["td"]));
$tab_enr=array();
$tab_enr["codecoloc"] = strip_tags(trim(@$_POST["cl"]));
$tab_enr["codeart"] = strip_tags(trim(@$_POST["ca"]));
$tab_enr["idbarloc"] = intval(strip_tags(trim(@$_POST["ibl"])));
$tab_enr["qte"] = strip_tags(trim(@$_POST["qte"]));
$tab_enr["pvht"] = strip_tags(trim(@$_POST["pvht"]));
$tab_enr["codetva"] = strip_tags(trim(@$_POST["tva"]));
$tab_enr["caution"] = strip_tags(trim(@$_POST["caution"]));
$tab_enr["tvacaut"] = strip_tags(trim(@$_POST["tvacaut"]));
$tab_enr["avecass"] = strip_tags(trim(@$_POST["assobl"]));
$tab_enr["mtass"] = strip_tags(trim(@$_POST["mtass"]));
$tab_enr["codetvaass"] = strip_tags(trim(@$_POST["tvaass"]));
$tab_enr["qconsi1"] = strip_tags(trim(@$_POST["qcons1"]));
$tab_enr["pdtuconsi1"] = strip_tags(trim(@$_POST["pdtucons1"]));
$tab_enr["puconsi1"] = strip_tags(trim(@$_POST["mtcons1"]));
$tab_enr["qconsi2"] = strip_tags(trim(@$_POST["qcons2"]));
$tab_enr["pdtuconsi2"] = strip_tags(trim(@$_POST["pdtucons2"]));
$tab_enr["puconsi2"] = strip_tags(trim(@$_POST["mtcons2"]));
$tab_enr["dd"] = strip_tags(trim(@$_POST["dd"]));
$tab_enr["hd"] = strip_tags(trim(@$_POST["hd"]));
$tab_enr["df"] = strip_tags(trim(@$_POST["df"]));
$tab_enr["hf"] = strip_tags(trim(@$_POST["hf"]));
// Données pour la pénalité
$codecoloc=strip_tags(trim(@$_POST["cl"]));
$codeart=strip_tags(trim(@$_POST["ca"]));
$codetva=strip_tags(trim(@$_POST["tva"]));
$penposs=strip_tags(trim(@$_POST["cpen"]));

$retourliste = TRUE;

switch ($td)
{
	// Ajout du barême de location
	case "add" :
		if (count($_SESSION["pdtlbl"])==0)
		{
			$_SESSION["pdtlbl"][0]=$tab_enr;

			// Ajout de la pénalité rattachée
			$tab_enr=array();

			$tab_enr["codecoloc"] = $codecoloc;
			$tab_enr["codeart"] = $codeart;
			$tab_enr["codepen"] = "-1";
			$tab_enr["valeur"] = 0;
			$tab_enr["tva"] = $codetva;
			$tab_enr["penposs"] = $penposs;
			$_SESSION["pdtlpl"][0]=$tab_enr;
			
			$msg = "Bar&ecirc;me ajout&eacute;";
		}
		else
		{
			$retourliste=FALSE;
			$msg = "Un seul bar&ecirc;me par produit lou&eacute;";
		}
		break;
		
	// MAJ du barême de location
	case "edit" :
		if (count($_SESSION["pdtlbl"])==1)
		{
			$_SESSION["pdtlbl"][0]=$tab_enr;

			// Ajout de la pénalité rattachée
			$tab_enr=array();

			$tab_enr["codecoloc"] = $codecoloc;
			$tab_enr["codeart"] = $codeart;
			$tab_enr["codepen"] = "-1";
			$tab_enr["valeur"] = 0;
			$tab_enr["tva"] = $codetva;
			$tab_enr["penposs"] = $penposs;
			$_SESSION["pdtlpl"][0]=$tab_enr;
			$msg = "Barême mis &agrave; jour";
		}
		else
		{
			$retourliste=FALSE;
			$msg = "Probl&egrave;me dans le nombre de bar&egrave;mes enregistr&eacute;s";
		}
		break;

	// Suppression du barême de location
	case "del" :
		if (count($_SESSION["pdtlbl"])==1)
		{
			$_SESSION["pdtlbl"]=array();
			$_SESSION["pdtlpl"]=array();
			$msg = "Bar&ecirc;me supprim&eacute;";
		}
		else
		{
			$retourliste=FALSE;
			$msg = "Probl&egrave;me dans le nombre de bar&egrave;mes enregistr&eacute;s";
		}
		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; ?> : Article (Bar&ecirc;me Location)</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>

<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>


<!-- Fermeture temporisée -->
<?PHP 
cre_js_pdtlbl("edit",$_SESSION["pdtlbl"],$_SESSION["pdtlpl"],$_SESSION["pdtlcl"],"window.opener.");
?>
<script type="text/javascript">
<!--
tbpbarloc();
self.close('fscomp');
//-->
</script>
<p align="center"><?PHP echo $txt_div_sinon; ?>, <a href="javascript:void(0)" onClick="javascript:; self.close('fscomp');"><?PHP echo $txt_lnk_clic_ici; ?></a> </p>

</body>
</html>
