<?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_prm.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_time.inc.php");
include_once("../inc/func_txt.inc.php");
Archivelog(@$_SESSION["code_log"]);

$td = strip_tags(trim(@$_GET['td']));
$codep= strip_tags(trim(@$_GET['codep']));
$idpb= intval(strip_tags(trim(@$_GET['npb'])));
$nextmin = intval(strip_tags(trim(@$_GET['nm'])));
$pour= intval(strip_tags(trim(@$_GET['po'])));
$ud= intval(strip_tags(trim(@$_GET['ud'])));
$pbm_pb=FALSE;
if (($pour<>0) AND ($pour<>1))
	$pbm_pb=TRUE;


if ((trim($codep)<>"") AND ($pbm_pb==FALSE))
{
	// Récupération des données de la pénalité
	$row = lit_enr_pen($codep);
	if (is_array($row))
	{
		extract ($row);
		
		$row = lit_enr_pen($penbar_codepen);
		if (is_array($row))
			extract($row);

		if ($idpb > 0)
		{
			if ($idpb==last_id_penbar_in_pen($codep,TRUE))
			{
				// Récupération des données du tarif consommable
				$row = lit_enr_penbar_id($idpb);
				if (is_array($row))
					extract($row);
				else
					$pbm_pb=TRUE;
			}
			else
				$pbm_pb=TRUE;
		}
		else
		{
			if ($idpb < 0)
				$pbm_pb=TRUE;
			else
			{
				if ($td<>"add")
					$pbm_pb=TRUE;
			}
		}
	}
	else
		$pbm_pb=TRUE;
}			
else
	$pbm_pb=TRUE;

switch ($td)
{
	case "add" :
		$titre = "AJOUT PENALITE";
		if (exist_infini_penbar($codep,TRUE)==FALSE)
		{
			$penbar_codepen = $codep;
			$penbar_min = $nextmin;
			$penbar_max = $nextmin+1;
		}
		else
			$pbm_pb=TRUE;
		break;
	case "edit" :
		$titre = "EDITION PENALITE";
		break;
	case "del" :
		$titre = "SUPPRESSION PENALITE";
		break;
	default :
		$pbm_pb=TRUE;
		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; ?> : Penalit&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>

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

<script language="javascript">
<!--
var tab1_champ=new Array(
	"nom:mini; format:unsigned ; req:Y ; txt:Minimum ; lmx:10 ; stok:frmok ; stbad:frmbad",
	"nom:maxi; format:unsigned ; req:Y ; txt:Maximum ; lmx:10 ; stok:frmok ; stbad:frmbad",
	"nom:valeur; format:reel_ns ; req:Y ; txt:Valeur ; lmx:10 ; vmn : 0.01; stok:frmok ; stbad:frmbad");
//-->
</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 sur les formulaires -->
<script language="JavaScript" src="../jscript/verif_form.js"></script>

<?PHP cre_js_penbar("edit",$codep,$pour,$ud,"window.opener."); ?>

</head>

<body onLoad="metFocus();tbpenbar();">

<?PHP
if ($pbm_pb==FALSE)
{
?>
<p align="center"> <span class="titrepage"><?PHP echo $titre ?></span></p>
<p align="center">Pour la p&eacute;nalit&eacute; : <span class="titre_gras"><?php echo $pen_desc; ?></span></p>

<form name="penbar_maj" method="post" action="penbar_enr.php" onSubmit="javascript:; return (verif_tpen(this,tab1_champ,'','<?PHP echo $_SESSION["lng"]; ?>'));">
	<input name="titre" type="hidden" id="titre" value="<?PHP echo $titre ?>">
    <input name="td" type="hidden" id="td" value="<?PHP echo $td ?>">
    <input name="codep" type="hidden" id="codep" value="<?PHP echo $codep ?>">
    <input name="ud" type="hidden" id="ud" value="<?PHP echo $ud ?>">
    <input name="pour" type="hidden" id="pour" value="<?PHP echo $pour ?>">
    <input name="npb" type="hidden" id="npb" value="<?PHP echo $idpb; ?>">
  <table width="100%"  border="0">
    <tr>
      <td width="25%" class="rubfrm" id="f_mini" align="right">Retard</td>
      <td>
	  	<span class="annot_gras_it">de</span> <input name="mini" type="text" id="mini" style="text-align:right" value="<?PHP echo $penbar_min; ?>" size="10" readonly="1">
	  	 <span class="annot_gras_it">&agrave;</span> <input name="maxi" type="text" id="maxi" style="text-align:right" value="<?PHP echo $penbar_max; ?>" size="10">
	  	 <span class="annot_gras_it"><?PHP echo $lng_tduree[$ud]; ?></span>
		 <img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">
 		<?PHP if ($td<>"del") { ?>
		 <br /><span class="annot_petit_it">(Maxi : au moins <?PHP echo $penbar_max;?>, ou '0' pour infini)</span>
		<?PHP } ?>
	  </td>
    </tr>
	<tr>
      <td class="rubfrm" id="f_valeur" align="right">P&eacute;nalit&eacute; de </td>
      <td>
      <?PHP 
	  if (($td == "add") OR ($td == "edit"))
	  { 
	  ?>
		<input name="valeur" type="text" id="valeur" style="text-align:right" value="<?PHP echo format_num($penbar_valeur,2); ?>" size="10" onChange="formatedeci(this.id,2);">
		<?PHP if ($pour==0) echo $lang['symbole_monnaie']; else echo "%"; ?> <img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>"><br />
		<span class="annot_petit_it">(La d&eacute;cimale doit &ecirc;tre '.' et pas la virgule)</span>
	  <?PHP } else { ?>
		<input name="valeur" type="text" id="valeur" style="text-align:right" value="<?PHP echo format_num($penbar_valeur,2); ?>" size="10" readonly="1">
	  <?PHP if ($pour==0) echo $lang['symbole_monnaie']; else echo "%";
	  } ?>
	  </td>
    </tr>
  </table>
  <p align="center">
    <?PHP if ($td == "add") { ?>
    <input name="RAZ" type="reset" class="bton_std" id="RAZ" value="<?PHP echo $but_reinit; ?>">
    <input name="enr" type="submit" class="bton_std" id="enr" value="<?PHP echo $but_add; ?>">
    <input name="annul" type="button" class="bton_std" id="annul" value="<?PHP echo $but_cancel; ?>" onclick="javascript:; self.close('fscomp');">
    <?PHP } if ($td == "edit") { ?>
    <input name="mod" type="submit" class="bton_std" id="mod" value="<?PHP echo $but_modif; ?>">
    <input name="annul" type="button" class="bton_std" id="annul" value="<?PHP echo $but_cancel; ?>" onclick="javascript:; self.close('fscomp');">
    <?PHP } if ($td == "del") { ?>
    <input name="del" type="submit" class="bton_std" id="del" value="<?PHP echo $but_del; ?>">
    <input name="annul" type="button" class="bton_std" id="annul" value="<?PHP echo $but_cancel; ?>" onclick="javascript:; self.close('fscomp');">
    <?PHP } ?>
  </p>
</form>
<?PHP
}
else
{
?>
	<script type="text/javascript">
	<!--
	self.close('fscomp2');
	//-->
	</script>
<?PHP
}
?>
</body>
</html>
