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

include_once("../inc/fic_pen.inc.php");
include_once("../inc/func.inc.php");
include_once("../inc/func_geo.inc.php");
include_once("../inc/func_txt.inc.php");
Archivelog(@$_SESSION["code_log"]);

$td = strip_tags(trim($_GET['td']));
$coderech = strip_tags(trim($_GET['code']));

$pbm_pen=FALSE;
$penmod=TRUE;
$pendesact=TRUE;
	
if ($coderech <> "")
{
	$row = lit_enr_pen($coderech);
	if (is_array($row))
	{
		extract ($row);
		$penmod=pen_modifiable($coderech,TRUE);
		$pendesact=pen_desactivable($coderech,TRUE);
	}
	else
		$pbm_pen=TRUE;
}
else
{
	if ($td<>"add")	$pbm_pen=TRUE;
}

if ($pbm_pen==FALSE)
{
	switch ($td)
	{
		case "add" :
			$titre = "CREATION PENALITE";
			break;
		case "edit" :
			$titre = "MODIFICATION PENALITE";
			$nextmin=next_min_penbar($pen_code,TRUE);
			break;
		case "del" :
			$titre = "SUPPRESSION PENALITE";
			break;
		default :
			$pbm_pen=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; ?> : Fiche 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>

<!-- Scripts Javascript sur les champs -->
<script language="JavaScript" src="../jscript/verif_field.js"></script>

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

<script language="javascript">
<!--
var tab_champ=new Array(
	"nom:code ; format:alphanum ; req:Y ; txt:<?PHP echo html_entity_decode($txt_chp_code); ?> ; lmn:1 ; lmx:10; stok:frmok ; stbad:frmbad",
<?PHP if ($td<>"add") { ?>
	"nom:valeur; format:reel_ns ; req:N ; txt:Valeur; lmx:10; stok:frmok ; stbad:frmbad",
<?PHP } ?>
	"nom:desc ; format:txt ; req:Y ; txt:<?PHP echo html_entity_decode($txt_chp_lib); ?>; lmn:1 ; lmx:40; stok:frmok ; stbad:frmbad");
//-->
</script>

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

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

<?PHP cre_js_penbar($td,$pen_code,$pen_pour,$pen_udec,""); ?>

</head>

<?PHP if ($td == "del") { ?>
<body onLoad="verif_tbar();warndel();metReadonly();tst_pour(document.pen_maj.pour.value);tbpenbar();">
<?PHP } else { ?>
<body onLoad="verif_tbar();tst_pour(document.pen_maj.pour.value);tbpenbar();metFocus();">
<?PHP }
include_once("../inc/entete.inc.php"); 
if ($pbm_pen==FALSE)
{
?>
<p align="center"> <span class="titrepage"><?PHP echo $titre ?></span></p>
<table width="100%"  border="0">
  <tr>
	<td width="33%"><strong><em><a href="pen_lst.php?ta=m"><?PHP echo $txt_lnk_ret_liste; ?></a></em></strong></td>
	<td width="33%"align="center" class="annot_petit_it">(<img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>"> : <?PHP echo $txt_div_saisoblg; ?>)</td>
	<td width="33%">&nbsp;</td>
  </tr>
</table>
<form name="pen_maj" method="post" action="pen_enr.php" onSubmit="javascript:; return (VForm(this,tab_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 ?>">
<?PHP if ($td<>"add") { ?>
<input name="nextmin" type="hidden" id="nextmin" value="<?PHP echo $nextmin; ?>">
<?PHP } ?>
<table width="100%"  border="0">
<tr>
	<td width="10%" class="rubfrm" align="right" id="f_code"><?PHP echo $txt_chp_code; ?></td>
	<td width="47%">
	<?PHP if ($td == "add") { ?>
	<input name="code" type="text" id="code" value="<?PHP echo $pen_code ?>" size="10" onChange="javascript:this.value=this.value.toUpperCase();">
	<img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">
	<?PHP } else { ?>
	<input name="code" type="text" id="code" value="<?PHP echo $pen_code ?>" size="10" readonly="1">
	</td>
	<?PHP } ?>
</tr>
<tr>
	<td class="rubfrm" align="right" id="f_desc"><?PHP echo $txt_chp_lib; ?></td>
	<td><input name="desc" type="text" id="desc" value="<?PHP echo htmlspecialchars($pen_desc); ?>" size="50" onChange="javascript:this.value=this.value.toUpperCase();">
	<img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>"></td>
</tr>
<?PHP if ($td<>"add") { ?>
<tr>
	<td class="rubfrm" align="right" id="f_tbar">Type bar&ecirc;me</td>
	<td>
	<?PHP 
	if ((($td == "add") OR ($td == "edit")) AND ($penmod==TRUE))
	{ 
		echo "<select name=\"tbar\" size=\"1\" id=\"tbar\" onChange=\"verif_tbar();\">";
		echo "<option value=\"0\"";
		if ($pen_tbar==0) echo " selected";
		echo ">Valeur unique</option>";
		echo "<option value=\"1\"";
		if ($pen_tbar==1) echo " selected";
		echo ">Grille de valeurs</option>";
		echo "</select>";
	?>
	<img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">
	<?PHP 
	}
	
	if (($td == "del") OR ($td == "view") OR ($penmod==FALSE))
	{ 
	if ($pen_tbar == 0)
	{
	?>
	<input name="tbar" type="hidden" id="tbar" value="0" readonly="1">
	<input name="ntbar" type="texte" id="ntbar" value="Valeur unique" readonly="1">
	<?PHP
	}
	else
	{
	?>
	<input name="tbar" type="hidden" id="tbar" value="1" readonly="1">
	<input name="ntbar" type="texte" id="ntbar" value="Grille de valeurs" readonly="1">
	<?PHP
	}
	}
	?>
	<br>
	<span class="annot_petit_it">
	<?PHP
	if ($penmod==TRUE) {
	?>
	'Valeur unique' : La p&eacute;nalit&eacute; est une valeur unique.<br>
	'Grille de valeurs' : La p&eacute;nalit&eacute; est &eacute;tablie selon une grille.
	<?PHP } else { ?>
	Vous ne pouvez pas modifier le type de bar&ecirc;me d'une p&eacute;nalit&eacute; d&eacute;j&agrave; utilis&eacute;e dans une location.
	<?PHP }?>
	</span>
	</td>
</tr>
<tr>
	<td class="rubfrm" align="right" id="f_valeur" align="left">
	<span id="txtpour2" style="display:none">Valeur</span>
	<span id="pas_txtpour2" style="display:block">Valeur HT</span>
	</td>
	<td>
	<input name="valeur" type="text" id="valeur" style="text-align:right" value="<?PHP echo $pen_valeur; ?>" size="10" onChange="formatedeci(this.id,2);" <?PHP if ($penmod==FALSE) echo "readonly=\"readonly\"" ?>>
	<span id="sympour" style="visibility:hidden" align="left">%</span>
	<span id="pas_sympour" style="visibility:visible" align="left"><?PHP echo $lang['symbole_monnaie']; ?></span>
	</td>
</tr>
<tr>
	<td class="rubfrm" align="right" id="f_pour">Pourcentage ?</td>
	<td>
	<?PHP 
	if ((($td == "add") OR ($td == "edit")) AND ($penmod==TRUE))
	{ 
		echo "<select name=\"pour\" size=\"1\" id=\"pour\" onChange=\"tst_pour(this.value);\">";
		echo "<option value=\"Oui\"";
		if ($pen_pour==TRUE) echo " selected";
		echo ">".$sel_lst_oui."</option>";
		echo "<option value=\"Non\"";
		if ($pen_pour==FALSE) echo " selected";
		echo ">".$sel_lst_non."</option>";
		echo "</select>";
	?>
	<img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">
	<?PHP 
	}
	
	if (($td == "del") OR ($td == "view") OR ($penmod==FALSE))
	{ 
	if ($pen_pour == TRUE)
	{
	?>
	<input name="pour" type="text" id="pour" value="Oui" size="3" maxlength="3" readonly="1">
	<?PHP
	}
	else
	{
	?>
	<input name="pour" type="text" id="pour" value="Non" size="3" maxlength="3" readonly="1">
	<?PHP
	}
	}
	?>
	<br>
	<span class="annot_petit_it">
	<?PHP
	if ($penmod==TRUE) {
	?>
	'Oui' : la valeur est un pourcentage du bar&ecirc;me.<br>
	'Non' : la valeur est un montant.
	<?PHP } else { ?>
	Vous ne pouvez pas modifier le type pourcentage d'une p&eacute;nalit&eacute; d&eacute;j&agrave; utilis&eacute;e dans une location.
	<?PHP }?>
	</span>
	</td>
</tr>
<tr>
  <td width="160" class="rubfrm" align="right" id="f_udec" align="right">Unit&eacute; de d&eacute;compte</td>
  <td>
  <?PHP if (($td == "add") OR ($td=="edit")) {?>
		<select name="udec" id="udec">
		<?PHP
		// Création de la liste des types de durées
		foreach ($lng_tduree as $key=>$value)
		{
			echo '<option value="'.$key.'"'; 
			if ($pen_udec == $key)
				echo ' selected';
			echo '>';
			echo $value."</option>";
		}
		?>
		</select>
		 <img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">
  <?PHP } else { ?>
	<input name="udec" type="hidden" id="udec" value="<?PHP echo $perloc_udec; ?>">
	<input name="nudec" type="text" id="nudec" value="<?PHP echo $lng_tduree[$perloc_udec]; ?>" readonly="readonly">
  <?PHP } ?>
  </td>
</tr>
<tr>
	<td class="rubfrm" align="right" id="f_prop">Proportionnel ?</td>
	<td>
	<?PHP 
	if ((($td == "add") OR ($td == "edit")) AND ($penmod==TRUE))
	{ 
		echo "<select name=\"prop\" size=\"1\" id=\"prop\">";
		echo "<option value=\"Oui\"";
		if ($pen_prop==TRUE) echo " selected";
		echo ">".$sel_lst_oui."</option>";
		echo "<option value=\"Non\"";
		if ($pen_prop==FALSE) echo " selected";
		echo ">".$sel_lst_non."</option>";
		echo "</select>";
	?>
	<img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">
	<?PHP 
	}
	
	if (($td == "del") OR ($td == "view") OR ($penmod==FALSE))
	{ 
	if ($pen_prop == TRUE)
	{
	?>
	<input name="prop" type="text" id="prop" value="Oui" size="3" maxlength="3" readonly="1" >
	<?PHP
	}
	else
	{
	?>
	<input name="prop" type="text" id="prop" value="Non" size="3" maxlength="3" readonly="1">
	<?PHP
	}
	}
	?>
	<br>
	<span class="annot_petit_it">
	<?PHP
	if ($penmod==TRUE) {
	?>
	Non' : la valeur sera valable quelque soit le nombre d'unit&eacute;s de retard. <br>
	'Oui' : la valeur sera proportionnelle au nombre d'unit&eacute;s de retard.
	<?PHP } else { ?>
	Vous ne pouvez pas modifier la valeur forfaitaire d'une p&eacute;nalit&eacute; d&eacute;j&agrave; utilis&eacute;e dans une location.
	<?PHP }?>
	</span>
	</td>
</tr>
<tr>
	<td class="rubfrm" align="right" id="f_actif">Active</td>
	<td>
	<?PHP 
	if ((($td == "add") OR ($td == "edit")) AND ($pendesact==TRUE))
	{ 
		echo "<select name=\"actif\" size=\"1\" id=\"actif\">";
		echo "<option value=\"Oui\"";
		if ($pen_actif==TRUE) echo " selected";
		echo ">".$sel_lst_oui."</option>";
		echo "<option value=\"Non\"";
		if ($pen_actif==FALSE) echo " selected";
		echo ">".$sel_lst_non."</option>";
		echo "</select>";
	?>
	<img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">
	<?PHP 
	}
	
	if (($td == "del") OR ($td == "view") OR ($pendesact==FALSE))
	{ 
	if ($pen_actif == TRUE)
	{
	?>
	<input name="actif" type="text" id="actif" value="Oui" size="3" maxlength="3" readonly="1">
	<?PHP
	}
	else
	{
	?>
	<input name="actif" type="text" id="actif" value="Non" size="3" maxlength="3" readonly="1">
	<?PHP
	}
	}

	if ($pendesact==FALSE) { ?>
	<br>
	<span class="annot_petit_it">Vous ne pouvez pas d&eacute;sactiver une p&eacute;nalit&eacute; d&eacute;j&agrave; utilis&eacute;e dans une location non close.</span>
	<?PHP
	}
	?>
	</td>
</tr>
<?PHP } ?>
</table>
<!-- Zone de saisie de la grille tarifaire des pénalités -->
<div id="detpenbar">
<?PHP
if (($td == "edit") OR ($td == "del") OR ($td == "view"))
{
?>
<table width="100%"  border="0">
<tr>
	<td class="rubfrm" colspan="2" align="center">
	GRILLE DE TARIFICATION
	</td>
</tr>
</table>
<div id="detbarpen">
</div>

<!-- Lien d'ajout de barêmes -->
<?PHP
if ($td == "edit")
{
?>
	<div id="addbp" style="<?PHP if ((exist_infini_penbar_code($pen_code,TRUE)==TRUE) OR ($pen_tbar==0))echo "display:none"; else "display:block"; ?>">
	<a href="javascript:;" onclick="fen_penbar_pen('add','<?PHP echo $pen_code; ?>',0);")><img src="../img/add.png" border="0" align="absmiddle"></a>
	<a href="javascript:;" onclick="fen_penbar_pen('add','<?PHP echo $pen_code; ?>',0);")> Ajouter un bar&ecirc;me</a>
	</div>
<?PHP
	}
}
?>
</div>
<p align="center">
<?PHP if (($td == "add") OR ($td == "edit")) { ?>
<input name="RAZ" type="reset" class="bton_std" id="RAZ" value="<?PHP echo $but_reinit; ?>">
<input name="submit" type="submit" class="bton_std" id="submit" value="<?PHP echo $but_enr; ?>">
<?PHP } ?>
<?PHP if ($td == "del") { ?>
<input name="del" type="submit" class="bton_std" id="del" value="<?PHP echo $but_del; ?>">
<?PHP } ?>
</p>
</form>
<?PHP
}
else
	aff_ret_pbm_auto("pen_lst.php?ta=m",2000);
include_once("pied.php");
?>
