<?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_pen.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"]));
$codep= strip_tags(trim(@$_POST["codep"]));
$ud= intval(strip_tags(trim(@$_POST["ud"])));
$pour= intval(strip_tags(trim(@$_POST["pour"])));
$idpb= intval(strip_tags(trim(@$_POST["npb"])));

$mini = strip_tags(trim(@$_POST["mini"]));
$maxi = strip_tags(trim(@$_POST["maxi"]));
$valeur = strip_tags(trim(@$_POST["valeur"]));

$retourliste = TRUE;

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

// On force la fiche pénalité en mode grille de valeurs
$rech = "UPDATE `" .TBPEN. "` SET `pen_tbar`='1'";
$rech.= " WHERE `pen_code` = '".$codep."'";
$rs = mysql_query($rech) or die(mysql_error());

switch ($td)
{
	// Ajout de la fiche montant pénalité
	case "add" :
		$rech2 = "INSERT INTO " .TBPENBAR;
		$rech2.= " (penbar_codepen,penbar_min,penbar_max,penbar_valeur)";
		$rech2.= " VALUES ('$codep','$mini','$maxi','$valeur')";
		$rs2 = mysql_query($rech2) or die(mysql_error());

		$msg = $txt_fiche_add;
		break;
		
	// MAJ de la fiche montant pénalité
	case "edit" :
		$majok=TRUE;
		
		if ($idpb<>last_id_penbar_in_pen($codep,FALSE))
		{
			$msg = "Bar&ecirc;me impossible &agrave; modifier";
			$majok = FALSE;
			$retourliste = FALSE;
		}
/*		
			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 `" .TBPENBAR. "` SET `penbar_min`='".$mini."', `penbar_max`='".$maxi."',";
			$rech.= " `penbar_valeur`='".$valeur."'";
			$rech.= " WHERE `penbar_id` = '".$idpb."'";
			$rs = mysql_query($rech) or die(mysql_error());
				
			$msg = $txt_fiche_mod;
		}
		break;

	// Suppression de la fiche montant pénalité
	case "del" :
		$delok=TRUE;

		if ($idpb<>last_id_penbar_in_pen($codep,FALSE))
		{
			$msg = "Bar&ecirc;me impossible &agrave; supprimer";
			$majok = FALSE;
			$retourliste = FALSE;
		}
/*		
			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 `" .TBPENBAR. "` WHERE `penbar_id` = '$idpb'";
			$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; ?> : P&eacute;nalit&eacute; 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_penbar("edit",$codep,$pour,$ud,"window.opener."); ?>
<script type="text/javascript">
<!--
tbpenbar();
self.close('fscomp');
//-->
</script>
<?PHP if ($retourliste==FALSE) { ?>
<p align="center">
<a href="javascript:void(0)" onClick="javascript:; self.close('fscomp');">cliquez ici pour fermer la fenêtre</a>
</p>
<?PHP } ?>

</body>
</html>
