<?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_pen.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_time.inc.php");
include_once("../inc/func_txt.inc.php");

Archivelog(@$_SESSION["code_log"]);

// Variables Formulaire
$pbm_pen=FALSE;
$titre = "PENALITE SUR LOCATION";
$td = strip_tags(trim(@$_GET["td"]));
if (($td<>"ret") AND ($td<>"del"))
	$pbm_pen=TRUE;
$tab_enr=array();
$dp="";
$hp="";
$dr="";
$hr="";
$dp=strip_tags(trim(@$_GET["dp"]));
$hp=strip_tags(trim(@$_GET["hp"]));
$dr=strip_tags(trim(@$_GET["dr"]));
$hr=strip_tags(trim(@$_GET["hr"]));

if ((datefrcorrecte($dp)==FALSE) OR (datefrcorrecte($dp)==FALSE))
	$pbm_pen=TRUE;

if ((heurecorrecte($hr.':00')==FALSE) OR (heurecorrecte($hr.':00')==FALSE))
	$pbm_pen=TRUE;

?>
<!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">

<!-- Scripts Javascript pour contrôle de formulaire -->
<script	type="text/javascript" src="../jscript/vform/vform.js"></script>

<!-- Scripts Javascript divers -->
<script language="JavaScript" src="../jscript/divers.js"></script>

<!-- Scripts Javascript sur les champs -->
<script language="JavaScript" src="../jscript/verif_field.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>
<br />
<div align="center">
<span class="annot_gras_it">Calculs en cours</span>
<br />
<br />
<img src="../img/wait30.gif" alt="wait" width="30" height="30">
</div>
<?PHP
$retourliste = TRUE;
if ($pbm_pdt==FALSE)
{
	$diff_secondes=diff_dateheure_sec($dp.' '.$hp.':00',$dr.' '.$hr.':00');
	switch ($td)
	{
		// Ajout de la pénalité de location
		case "ret" :
			if (isset($_SESSION["pdtlpl"]))
			{
				$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
				mysql_select_db(DBNAME);
		
				// Calculs du total HT pour le barême choisi
				// Récupération enregistrement barême location
				if ($_SESSION["pdtlbl"][0]["idbarloc"]<>0)
				{
					$rech2 = "SELECT * FROM ".TBBARLOC." WHERE barloc_id='".$_SESSION["pdtlbl"][0]["idbarloc"]."'";
					$rs2 = mysql_query($rech2) or die(mysql_error());
					if ($row2 = mysql_fetch_assoc($rs2))
						extract($row2);
				}
				mysql_free_result($rs2);
				mysql_close($conn);
				
				$qte=$_SESSION["pdtlbl"][0]["qte"];
				
				// Calculs divers
				//... Montant location
				$pvht=$_SESSION["pdtlbl"][0]["pvht"];
				$tothtloc=round(($qte*$pvht)*100)/100;
				//... Caution
				$pvht=$_SESSION["pdtlbl"][0]["caution"];
				$tothtcaut=round($pvht*100)/100;
				//... Assurance
				$tothtass=0;
				if ($_SESSION["pdtlbl"][0]["avecass"]==1)
				{
					$pvht=$_SESSION["pdtlbl"][0]["mtass"];
					$tothtass=round(($qte*$pvht)*100)/100;
				}
				//...Consommables
				//... Consommable 1
				$pvht=$_SESSION["pdtlbl"][0]["puconsi1"];
				$tothtcons1=round(($qte*$pvht)*100)/100;
				//... Consommable 2
				$pvht=$_SESSION["pdtlbl"][0]["puconsi2"];
				$tothtcons2=round(($qte*$pvht)*100)/100;
			
				// Total HT
				$totbarht=$tothtloc+$tothtcaut+$tothtass+$tothtcons1+$tothtcons2;
	
				// Calcul du montant de la pénalité
				$tot_penalite=calcul_penalite($_SESSION["pdtlpl"][0]["penposs"],$totbarht,$_SESSION["pdtlpl"][0]["codetva"],$diff_secondes);
				$_SESSION["pdtlpl"][0]["codepen"]=$_SESSION["pdtlpl"][0]["penposs"];
				$_SESSION["pdtlpl"][0]["valeur"]=$tot_penalite;

				$msg = "Calculs effectu&eacute;s";
			}
			else
			{
				$retourliste=FALSE;
				$msg = "Probl&egrave;me dans les sessions";
			}
			break;
			
		// Suppression de la pénalité de location
		case "del" :
			$_SESSION["pdtlpl"][0]["codepen"]="-1";
			$_SESSION["pdtlpl"][0]["valeur"]=0;
			$msg = "P&eacute;nalit&eacute; supprim&eacute;e";
			break;
			
		default :
			break;
	}
}
else
{
	$retourliste=FALSE;
	$msg = "Probl&egrave;me de param&egrave;tres";
}

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

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

</body>
</html>
