<?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/fic_taxes.inc.php");
include_once("../inc/func.inc.php");
include_once("../inc/func_date.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"]);

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

$code = str_majuscules(strip_tags(trim(@$_POST["code"])));
$des = str_majuscules(str_escape(trim(@$_POST["desbl"])));
$datev1f = strip_tags(trim(@$_POST["dateval1f"]));
if ($datev1f <> "")
	$dateval1 = datefrang($datev1f);
else
	$dateval1 = $datev1f;
$datev2f = strip_tags(trim(@$_POST["dateval2f"]));
if ($datev2f <> "")
	$dateval2 = datefrang($datev2f);
else
	$dateval2 = $datev2f;
$puht = strip_tags(trim(@$_POST["puht"]));
$tva = strip_tags(trim(@$_POST["tva"]));
$mtass = strip_tags(trim(@$_POST["mtass"]));
$tvaass = strip_tags(trim(@$_POST["tvaass"]));
$assobl = strip_tags(trim(@$_POST["assobl"]));
if ($assobl == "Oui")
	$assoblok = TRUE;
else
	$assoblok = FALSE;
$mult = strip_tags(trim(@$_POST["mult"]));
if ($mult == "Oui")
	$multok = TRUE;
else
	$multok = FALSE;
$actif = strip_tags(trim(@$_POST["actif"]));
if ($actif == "Oui")
	$actifok = TRUE;
else
	$actifok = FALSE;
$pen = strip_tags(trim(@$_POST["pen"]));
$qconsi1 = strip_tags(trim(@$_POST["qconsi1"]));
$puconsi1 = strip_tags(trim(@$_POST["puconsi1"]));
$tvacons1 = strip_tags(trim(@$_POST["tvacons1"]));
$qconsi2 = strip_tags(trim(@$_POST["qconsi2"]));
$puconsi2 = strip_tags(trim(@$_POST["puconsi2"]));
$tvacons2 = strip_tags(trim(@$_POST["tvacons2"]));


$retourliste = TRUE;

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

switch ($td)
{
	// Ajout de la fiche Barême
	case "add" :
		$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
		mysql_select_db(DBNAME);
		$rech = "SELECT * FROM " .TBBARLOC. " WHERE barloc_codepdtloc = '$codepdt' AND barloc_codeperloc = '$code'";
		$rs = mysql_query($rech) or die(mysql_error());
		if (mysql_num_rows($rs) == 0)
		{
			$rech2 = "INSERT INTO " .TBBARLOC;
			$rech2.= " (barloc_codepdtloc,barloc_codeperloc,barloc_des,barloc_dateval1,barloc_dateval2,";
			$rech2.=" barloc_pvht,barloc_codetva,barloc_mtass,barloc_codetvaass,barloc_assobl,barloc_mult,barloc_actif,barloc_codepen,";
			$rech2.= "barloc_qconsi1,barloc_puconsi1,barloc_tvacons1,barloc_qconsi2,barloc_puconsi2,barloc_tvacons2)";
			$rech2.= " VALUES ('$codepdt','$code','$des','$dateval1','$dateval2','$puht','$tva','$mtass','$tvaass','$assoblok','$multok',";
			$rech2.= "'$actifok','$pen','$qconsi1','$puconsi1','$tvacons1','$qconsi2','$puconsi2','$tvacons2')";
			$rs2 = mysql_query($rech2) or die(mysql_error());
	
			$msg = $txt_fiche_add;
		}
		else
		{
			$msg = "Ce code est d&eacute;j&agrave; saisi pour ce produit !";
			$retourliste = FALSE;
		}
		mysql_free_result($rs);
		break;
		
	// MAJ de la fiche Barême
	case "edit" :
		$majok=TRUE;
		
		if ($actif==0)
		{
			if (exist_barloc_in_coloc_ouv($idbl,FALSE)==TRUE)
			{
				$msg = "Bar&ecirc;me utilis&eacute; dans une location non close";
				$majok = FALSE;
				$retourliste = FALSE;
			}
		}
		
		if ($majok==TRUE)
		{
			$rech = "UPDATE `" .TBBARLOC. "` SET `barloc_codepdtloc`='".$codepdt."', `barloc_codeperloc`='".$code."',";
			$rech.= " `barloc_dateval1`='".$dateval1."', `barloc_dateval2`='".$dateval2."', `barloc_pvht`='".$puht."',";
			$rech.= " `barloc_codetva`='".$tva."', `barloc_actif`='".$actifok."', `barloc_codepen`='".$pen."', `barloc_des`='".$des."',";
			$rech.= " `barloc_mtass`='".$mtass."', `barloc_codetvaass`='".$tvaass."', `barloc_assobl`='".$assoblok."', `barloc_mult`='".$multok."',";
			$rech.= " `barloc_qconsi1`='".$qconsi1."',`barloc_puconsi1`='".$puconsi1."',`barloc_tvacons1`='".$tvacons1."',";
			$rech.= " `barloc_qconsi2`='".$qconsi2."',`barloc_puconsi2`='".$puconsi2."',`barloc_tvacons2`='".$tvacons2."'";
			$rech.= " WHERE `barloc_codepdtloc` = '".$codepdt."' AND `barloc_codeperloc` = '".$code."'";
			$rs = mysql_query($rech) or die(mysql_error());
				
			$msg = $txt_fiche_mod;
		}
		break;

	// Suppression de la fiche Barême
	case "del" :
		$delok=TRUE;

		if ($actif==0)
		{
			if (exist_barloc_in_coloc($idbl,FALSE)==TRUE)
			{
				$msg = "Bar&ecirc;me utilis&eacute; dans une location. D&eacute;sactivez le.";
				$delok = FALSE;
				$retourliste = FALSE;
			}
		}
		
		if ($delok==TRUE)
		{
			$rech = "DELETE FROM `" .TBBARLOC. "` WHERE `barloc_codepdtloc` = '$codepdt' AND `barloc_codeperloc` = '$code'";
			$rs = mysql_query($rech) or die(mysql_error());
	
			$msg = $txt_fiche_del;
		}
		break;
		
	default :
		break;
}
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 - <?PHP echo $title_esp_prive; ?> : 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_barloc("edit",$codepdt,"window.opener."); 
?>
<script type="text/javascript">
<!--
tbbarloc();
<?PHP if ($retourliste==TRUE) { ?>self.close('fscomp');<?PHP } ?>
//-->
</script>
<p align="center"><a href="javascript:void(0)" onClick="javascript:; self.close('fscomp');"><?PHP echo $txt_lnk_clic_ici; ?></a></p>

</body>
</html>
