<?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/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']));
$codepdt = strip_tags(trim(@$_GET['cp']));
$codepl = strip_tags(trim(@$_GET['pl']));

$pbm_bar=FALSE;

if (($codepdt <> "") AND ($codepl<> ""))
{
	// Récupération des données de la fiche article
	$row = lit_enr_pdtloc($codepdt);
	if (is_array($row))
	{
		extract ($row);
	
		$row = lit_enr_perloc($codepl);

		if (is_array($row))
		{
			extract($row);

			if ($td == "add")
			{
				$barloc_codeperloc = $codepl;
				$barloc_codepdtloc = $pdtloc_code;
			}
		
			if ($td == "edit")
			{
				$row = lit_enr_barloc_in_pdtloc($codepl,$codepdt);
				if (is_array($row))
					extract ($row);
				else
					$pbm_bar=TRUE;
			}
		
			if ($td == "del")
			{
				$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
				mysql_select_db(DBNAME);
				$rech = "SELECT * FROM `" .TBBARLOC. "` WHERE `barloc_codeperloc` = '$codepl' AND `barloc_codepdtloc` = '$codepdt'";
				$rs = mysql_query($rech)or die(mysql_error());
				if (mysql_num_rows($rs) == 0)
					$pbm_bar=TRUE;
				else
				{
					if ($row = mysql_fetch_array($rs))
						extract ($row);
					else
						$pbm_bar=TRUE;
				}
				mysql_free_result($rs);
				mysql_close($conn);
			}

			// Récupération des informations TVA
			$row = lit_enr_tva($barloc_codetva,TRUE);
			if (is_array($row))
				extract ($row);
			$txtva=$tva_tx/100;
			$puttc=round(($barloc_pvht*(1+$txtva))*100)/100;

			$row = lit_enr_tva($barloc_codetvaass,TRUE);
			if (is_array($row))
				extract ($row);
			$txtva=$tva_tx/100;
			$mtassttc=round(($barloc_mtass*(1+$txtva))*100)/100;

			// Vérification de la validité du barême
			if ((formatedate($barloc_dateval2)<>"") AND (comp_date($datea,$barloc_dateval2)==FALSE))
				$barloc_actif = 0;
			
			// Formatage des dates en français
			$barloc_dateval1f = formatedate($barloc_dateval1);
			$barloc_dateval2f = formatedate($barloc_dateval2);
		}
		else
			$pbm_bar=TRUE;
	}
	else
		$pbm_bar=TRUE;
}			
else
	$pbm_bar=TRUE;

switch ($td)
{
	case "add" :
		$titre = "SAISIE BAREME";
		$barloc_dateval1f = formatedate($datea);
		$barloc_mtass = 0;
		$barloc_assobl = 0;
		$barloc_mutl = 1;
		$barloc_actif = 1;
		$barloc_qconsi1=0;
		$barloc_qconsi2=0;
		$nextmin1=1;
		$nextmin2=1;
		break;
	case "edit" :
		$titre = "EDITION BAREME";
		$nextmin1=next_min_tcons($barloc_id,$barloc_qconsi1,1,TRUE);
		$nextmin2=next_min_tcons($barloc_id,$barloc_qconsi2,2,TRUE);
		break;
	case "del" :
		$titre = "SUPPRESSION BAREME";
		break;
	default :
		$pbm_bar=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; ?> : 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>

<!-- 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:desbl; format:txt ; req:Y ; txt:<?PHP echo html_entity_decode($txt_chp_lib); ?> ; lmx:50 ; stok:frmok ; stbad:frmbad",
	"nom:dateval1f; format:date ; masque:<?PHP echo $datemsql; ?> ; req:Y ; txt:Date validité (première date) ; stok:frmok ; stbad:frmbad",
	"nom:tva; format:liste ; req:Y ; txt:TVA ; vmn:1 ; stok:frmok ; stbad:frmbad",
	"nom:puht; format:reel_ns ; req:Y ; txt:PU HT ; lmx:10 ; vmn : 0.01; stok:frmok ; stbad:frmbad",
	"nom:pu; format:reel_ns ; req:Y ; txt:PU TTC ; lmx:10 ; vmn : 0.01; stok:frmok ; stbad:frmbad",
	"nom:mtass; format:reel_ns ; req:N ; txt:Montant assurance ; lmx:10 ; stok:frmok ; stbad:frmbad",
<?PHP
if ($td == "edit")
{
?>
	"nom:typarr; format:liste ; req:Y ; txt:Type arrondi; vmn:1 ; stok:frmok ; stbad:frmbad",
	"nom:pen; format:liste ; req:Y ; txt:Pénalité applicable; vmn:1 ; stok:frmok ; stbad:frmbad",
<?PHP
	if ((trim($pdtloc_pdtucons1)<>"") AND (trim($pdtloc_pdtucons1)<>"-1")) { ?>
	"nom:qconsi1; format:unsigned ; req:Y ; txt:Quantité consommables 1 incluse ; lmx:10 ; stok:frmok ; stbad:frmbad",
<?PHP }
	if ((trim($pdtloc_pdtucons2)<>"") AND (trim($pdtloc_pdtucons2)<>"-1")) { ?>
	"nom:qconsi2; format:unsigned ; req:Y ; txt:Quantité consommables 2 incluse ; lmx:10 ; stok:frmok ; stbad:frmbad",
<?PHP }} ?>
	"nom:tvaass; format:liste ; req:Y ; txt:TVA Assurance; vmn:1 ; 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>

<!-- Définition Javascript pour calendrier popup -->
  <!-- Feuille de Style -->
  <link rel="stylesheet" type="text/css" media="all" href="../jscript/jscal/skins/aqua/theme.css" title="Aqua" />

  <!-- Script Javascript Principal -->
  <script type="text/javascript" src="../jscript/jscal/calendar.js"></script>

  <!-- Choix du langage -->
  <script type="text/javascript" src="../jscript/jscal/lang/calendar-<?PHP echo $_SESSION["lng"]; ?>.js"></script>

  <!-- the following script defines the Calendar.setup helper function, which makes
       adding a calendar a matter of 1 or 2 lines of code. -->
  <script type="text/javascript" src="../jscript/jscal/calendar-setup.js"></script>
<!-- Fin de la définition Javascript pour calendrier popup -->

<?PHP cre_js_tarcons($td,$barloc_id,""); ?>

</head>
<?PHP 
switch ($td)
{
	case "del" :
	case "view" :
		echo '<body onLoad="metReadonly();tbtarcons1();tbtarcons2();">';
		break;
	default :
		echo '<body onLoad="metFocus();tbtarcons1();tbtarcons2();">';
		break;
}

if ($pbm_bar==FALSE)
{
?>
<p align="center"> <span class="titrepage"><?PHP echo $titre ?></span></p>
<p align="center">Pour le produit : <br><span class="titre_gras"><?php echo $pdtloc_des; ?> </span></p>

<form name="barloc_maj" method="post" action="barloc_enr.php" onSubmit="javascript:; return (VForm(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="codepdt" type="hidden" id="codepdt" value="<?PHP echo $pdtloc_code; ?>">
    <input name="nextmin1" type="hidden" id="nextmin1" value="<?PHP echo $nextmin1; ?>">
    <input name="nextmin2" type="hidden" id="nextmin2" value="<?PHP echo $nextmin2; ?>">
	<?PHP if (($td=="edit") OR ($td=="del")) { ?>
    <input name="nbl" type="hidden" id="nbl" value="<?PHP echo $barloc_id; ?>">
	<?PHP } ?>
  <table width="100%"  border="0">
    <tr>
		<td class="rubfrm" colspan="2" align="center">P&eacute;riode de location</td>
	</tr>
    <tr>
      <td width="25%" class="rubfrm" id="f_code" align="right"><?PHP echo $txt_chp_code; ?></td>
      <td width="75%">
		  <input name="code" type="text" id="code" value="<?PHP echo $perloc_code ?>" size="10" maxlength="10" readonly="readonly">
	  </td> 
    </tr>
    <tr>
      <td class="rubfrm" id="f_des" align="right"><?PHP echo $txt_chp_lib; ?></td>
      <td>
	  	<input name="des" type="text" id="des" value="<?PHP echo htmlspecialchars($perloc_desc); ?>" size="50" readonly="readonly">
	  </td>
    </tr>
    <tr>
      <td class="rubfrm" id="f_jourd1" align="right">Commence entre un<br />et un</td>
      <td>
		<input name="njourd1" type="text" id="njourd1" value="<?PHP echo $lng_tjouri[$perloc_jourd1]; ?>" readonly="readonly">
		 <br />
		<input name="njourd2" type="text" id="njourd2" value="<?PHP echo $lng_tjouri[$perloc_jourd2]; ?>" readonly="readonly">
      </td>
    </tr>
    <tr>
      <td class="rubfrm" id="f_duree" align="right">Sur une dur&eacute;e de</td>
      <td>
		<input name="nduree" type="text" id="nduree" value="<?PHP echo $perloc_nduree ?>" size="3" readonly="readonly">
		<input name="tduree" type="hidden" id="tduree" value="<?PHP echo $perloc_tduree; ?>">
		<input name="ntduree" type="text" id="ntduree" value="<?PHP echo $lng_tduree[$perloc_tduree]; ?>" readonly="readonly">
	  </td>
    </tr>
    <tr>
		<td class="rubfrm" colspan="2" align="center">Bar&ecirc;me</td>
	</tr>
    <tr>
      <td class="rubfrm" id="f_actif" align="right">Bar&ecirc;me actif ?</td>
      <td>
	  <?PHP
      if (($td == "add") OR ($td=="edit")) {
		echo "<select name=\"actif\" size=\"1\" id=\"actif\">";
		echo "<option value=\"Oui\"";
		if ($barloc_actif == TRUE)
			echo" selected";
		echo">".$sel_lst_oui."</option>";
		echo "<option value=\"Non\"";
		if ($barloc_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 } else { ?>
		<input name="nvalide" type="text" id="nvalide" value="<?PHP echo $non_oui[$barloc_actif]; ?>">
      <?PHP } ?>
	  </td>
    </tr>
    <tr>
      <td class="rubfrm" id="f_desbl" align="right"><?PHP echo $txt_chp_lib; ?></td>
      <td>
	  	<input name="desbl" type="text" id="desbl" value="<?PHP echo htmlspecialchars($barloc_des); ?>" size="50">
		 <img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">
	  </td>
    </tr>
	<tr>
		<td class="rubfrm" id="f_rdv" align="right">Validit&eacute;</td>
		<td>
			<input name="dateval1f" type="text" id="dateval1f" value="<?PHP echo $barloc_dateval1f ?>" size="10" maxlength="10" readonly="1" onChange="verif_dates();">
			<?PHP if (($td == "add") OR ($td == "edit")) { ?>
			<img src="../img/calendar.png" align="absmiddle" id="f_img_dateval1f" title="<?PHP echo $alt_chxdate; ?>">
			<a href="javascript:;" onClick="document.barloc_maj.dateval1f.value='';verif_dates();"><img src="../img/raz.png" border="0" align="absmiddle"></a>
			 <img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">
			<?PHP } ?>
			 au 
			<input name="dateval2f" type="text" id="dateval2f" value="<?PHP echo $barloc_dateval2f ?>" size="10" maxlength="10" readonly="1" onChange="verif_dates();">
			<?PHP if (($td == "add") OR ($td == "edit")) { ?>
			<img src="../img/calendar.png" align="absmiddle" id="f_img_dateval2f" title="<?PHP echo $alt_chxdate; ?>">
			<a href="javascript:;" onClick="document.barloc_maj.dateval2f.value='';verif_dates();"><img src="../img/raz.png" border="0" align="absmiddle"></a>
			 <span class="annot_petit_it">(Si pas de date de fin, bar&ecirc;me illimit&eacute;)</span>
			<?PHP } ?>
		</td>
	</tr>
    <tr>
      <td class="rubfrm" id="f_pu" align="right">Tarif location</td>
      <td>
      <?PHP if (($td == "add") OR ($td == "edit"))
	  { 
	  ?>
		<span class="annot_std_gras">HT</span> : <input name="puht" type="text" id="puht" style="text-align:right" value="<?PHP echo format_num($barloc_pvht,2); ?>" size="10" onChange="formatedeci(this.id,2);ttc_from_ht(this.value,'tva','pu',2);">
		<?PHP echo $lang['symbole_monnaie']; ?>
		 <span class="annot_std_gras">TVA</span> : <select name="tva" size="1" id="tva" onChange="ttc_from_ht(document.getElementById('puht').value,this.id,'pu',2);">
	  <?PHP
		echo "<option value=\"\">-- Choisissez une TVA --</option>";
		
		// Création de la liste des TVA
		$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
		mysql_select_db(DBNAME);
		$rs = mysql_query("SELECT * FROM ".TBTVA." WHERE tva_actif=1 ORDER BY tva_desc");

		while ($resultat = mysql_fetch_array($rs)) 
		{
			extract($resultat);
			echo '<option value="'.$tva_code.'"';
			if ($barloc_codetva == $tva_code)
				echo ' selected';
			echo '>'.$tva_desc.'</option>';
		}
		mysql_free_result($rs);
		mysql_close($conn);
		?>
		</select>
		 <span class="annot_std_gras">TTC</span> : <input name="pu" type="text" id="pu" style="text-align:right" value="<?PHP echo  format_num($puttc,2); ?>" size="10"  onChange="formatedeci(this.id,2);ht_from_ttc(this.value,'tva','puht',2);"> 
		<?PHP echo $lang['symbole_monnaie']; ?> <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
		// Création des taux de TVA (champs cachés)
		$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
		mysql_select_db(DBNAME);
		$rs = mysql_query("SELECT * FROM ".TBTVA." WHERE tva_actif=1 ORDER BY tva_desc");
		
		while ($resultat = mysql_fetch_array($rs)) 
		{
			extract($resultat);
			echo '<input name="'.$tva_code.'" type="hidden" id="'.$tva_code.'" value="'.$tva_tx.'">';
		}
		mysql_free_result($rs);
		mysql_close($conn);
	  }
	  else
	  {
	  ?>
		<span class="annot_std_gras">HT</span> : <input name="puht" type="text" id="puht" style="text-align:right" value="<?PHP echo format_num($barloc_pvht,2); ?>" size="10" readonly="1"> 
	  <?PHP 
	  	echo $lang['symbole_monnaie'];
		$row=lit_enr_tva($barloc_codetva,TRUE);
		if (is_array($row))
			extract($row);
	  ?>
		<input name="tva" type="hidden" id="tva" value="<?PHP echo $barloc_codetva ?>"> 
		 <span class="annot_std_gras">TVA</span> : <input name="ntva" type="text" id="ntva" align="right" value="<?PHP echo $tva_desc ?>" size="40" readonly="1"> 
		 <span class="annot_std_gras">TTC</span> : <input name="pu" type="text" id="pu" style="text-align:right" value="<?PHP echo format_num($puttc,2); ?>" size="10" readonly="1"> 
	  <?PHP 
	  	echo $lang['symbole_monnaie'];
	  } ?>
      </td>
    </tr>
    <tr>
      <td class="rubfrm" id="f_mtass" align="right">Assurance<br /><span class="annot_petit">Par p&eacute;riode de location</span></td>
      <td>
		
	  <?PHP if (($td == "add") OR ($td=="edit")) { ?>
		<span class="annot_std_gras">HT</span> : <input name="mtass" type="text" id="mtass" style="text-align:right" value="<?PHP echo  format_num($barloc_mtass,2); ?>" size="10"  onChange="formatedeci(this.id,2);verif_assobl(); ttc_from_ht(this.value,'tvaass','mtassttc',2);"> 
		<?PHP echo $lang['symbole_monnaie']; ?>
		 <span class="annot_std_gras">TVA</span> : <select name="tvaass" size="1" id="tvaass" onChange="ttc_from_ht(document.getElementById('mtass').value,this.id,'mtassttc',2);">
	  <?PHP
		echo "<option value=\"\">-- Choisissez une TVA --</option>";
		
		// Création de la liste des TVA
		$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
		mysql_select_db(DBNAME);
		$rs = mysql_query("SELECT * FROM ".TBTVA." WHERE tva_actif=1 ORDER BY tva_desc");

		while ($resultat = mysql_fetch_array($rs)) 
		{
			extract($resultat);
			echo '<option value="'.$tva_code.'"';
			if ($barloc_codetvaass == $tva_code)
				echo ' selected';
			echo '>'.$tva_desc.'</option>';
		}
		mysql_free_result($rs);
		mysql_close($conn);
		?>
		</select>
		 <span class="annot_std_gras">TTC</span> :
		<input name="mtassttc" type="text" id="mtassttc" style="text-align:right" value="<?PHP echo  format_num($mtassttc,2); ?>" size="10" onChange="formatedeci(this.id,2);ht_from_ttc(this.value,'tvaass','mtass',2);"> 
		<?PHP echo $lang['symbole_monnaie']; ?> <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 { ?>
		<span class="annot_std_gras">HT</span> : <input name="mtass" type="text" id="mtass" style="text-align:right" value="<?PHP echo  format_num($barloc_mtass,2); ?>" size="10" readonly="readonly"> 
	  <?PHP echo $lang['symbole_monnaie'];
		$row=lit_enr_tva($barloc_codetvaass,TRUE);
		if (is_array($row))
			extract($row);
	  ?>
		 <span class="annot_std_gras">TVA</span> : 
		<input name="tvaass" type="hidden" id="tvaass" value="<?PHP echo $barloc_codetvaass ?>"> 
		<input name="ntvaass" type="text" id="ntvaass" align="right" value="<?PHP echo $tva_desc ?>" size="40" readonly="1"> 
		 <span class="annot_std_gras">TTC</span> : 
		<input name="mtassttc" type="text" id="mtassttc" style="text-align:right" value="<?PHP echo format_num($mtassttc,2); ?>" size="10" readonly="1"> 
	<?PHP echo $lang['symbole_monnaie'];
      }
	  ?>
	  </td>
	 </tr>
	<tr>
      <td class="rubfrm" id="f_actif" align="right">Assurance Obligatoire ?</td>
      <td>
      <?PHP if (($td == "add") OR ($td=="edit")) {
		echo "<select name=\"assobl\" size=\"1\" id=\"assobl\" onChange=\"verif_assobl();\">";
		echo "<option value=\"Oui\"";
		if ($barloc_assobl == TRUE)
			echo" selected";
		echo">".$sel_lst_oui."</option>";
		echo "<option value=\"Non\"";
		if ($barloc_assobl == FALSE)
			echo" selected";
		echo ">".$sel_lst_non."</option>";
		echo "</select>";
	  } else { ?>
		<input name="assobl" type="text" id="assobl" value="<?PHP echo $non_oui[$barloc_assobl]; ?>" size="3" readonly="readonly"> 
	  <?PHP
	 }
	 ?>
	 </td>
	</tr>
	<tr>
      <td class="rubfrm" id="f_mult" align="right">Multiple ?</td>
      <td>
      <?PHP if (($td == "add") OR ($td=="edit")) {
		echo "<select name=\"mult\" size=\"1\" id=\"mult\">";
		echo "<option value=\"Oui\"";
		if ($barloc_mult == TRUE)
			echo" selected";
		echo">".$sel_lst_oui."</option>";
		echo "<option value=\"Non\"";
		if ($barloc_mult == FALSE)
			echo" selected";
		echo ">".$sel_lst_non."</option>";
		echo "</select>";
	  } else { ?>
		<input name="mult" type="text" id="mult" value="<?PHP echo $non_oui[$barloc_mult]; ?>" size="3" readonly="readonly"> 
	  <?PHP
	 }
	 ?>
	 <span class="annot_petit_it">(Si 'Oui', on peut saisir une quantit&eacute; sup&eacute;rieure &agrave; 1)</span>
	 </td>
	</tr>
	<tr>
      <td class="rubfrm" id="f_typarr" align="right">Type arrondi</td>
      <td>
      <?PHP if (($td == "add") OR ($td=="edit")) {
		echo "<select name=\"typarr\" size=\"1\" id=\"typarr\">";
		echo "<option value=\"\">".$sel_lst_makechx."</option>";
		foreach ($bloc_typarr as $key=>$value)
		{
			echo '<option value="'.$key.'"'; 
			if (($barloc_typarr<>"") AND ($barloc_typarr == $key))
				echo ' selected';
			echo '>';
			echo $value."</option>";
		}
		echo "</select>";
	  } else { ?>
		<input name="typarr" type="text" id="typarr" value="<?PHP echo $bloc_typarr[$barloc_typarr]; ?>" size="20" readonly="readonly"> 
	  <?PHP
	 }
	 ?>
	 <br /><span class="annot_petit_it">('Aucun' : prorata au r&eacute;el. 'Inf&eacute;rieur' : Arrondi &agrave; l'entier inf&eacute;rieur. 'Sup&eacute;rieur' : Toute p&eacute;riode entam&eacute;e est d&ucirc;e)</span>
	 </td>
	</tr>
	<tr>
      <td class="rubfrm" id="f_pen" align="right">P&eacute;nalit&eacute; applicable</td>
      <td>
      <?PHP if (($td == "add") OR ($td=="edit")) {
		echo '<select name="pen" size="1" id="pen">';
		echo "<option value=\"\">-- Choisissez une pénalité --</option>";
		echo "<option value=\"-1\"";
		if ($barloc_codepen == -1)
			echo ' selected';
		echo ">Pas de pénalité</option>";
		
		// Création de la liste des pénalités
		$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
		mysql_select_db(DBNAME);
		$rs = mysql_query("SELECT * FROM ".TBPEN." WHERE pen_actif=1 ORDER BY pen_desc");

		while ($resultat = mysql_fetch_array($rs)) 
		{
			extract($resultat);
			echo '<option value="'.$pen_code.'"';
			if ($barloc_codepen == $pen_code)
				echo ' selected';
			echo '>'.$pen_desc.' ('.$pen_code.')</option>';
		}
		mysql_free_result($rs);
		mysql_close($conn);
		echo "</select>";
	  } else {
		$row=lit_enr_pen($barloc_codepen);
		$pen_desc="Pas de pénalité";
		if (is_array($row))
			extract($row);
	  ?>
		<input name="pen" type="hidden" id="pen" value="<?PHP echo $barloc_codepen; ?>"> 
		<input name="npen" type="text" id="npen" value="<?PHP echo $pen_desc; ?>"> 
	  <?PHP
	 }
	 ?>
	 </td>
	</tr>
  </table>
	<input name="tvacons1" type="hidden" id="tvacons1" value="<?PHP echo $pdtloc_tvacons1; ?>">
	<input name="tvacons2" type="hidden" id="tvacons2" value="<?PHP echo $pdtloc_tvacons2; ?>">
	<!-- Zone de saisie de la grille tarifaire des consommables -->
	<?PHP
	if (($td == "edit") OR ($td == "del") OR ($td == "view"))
	{
	?>
		<table width="100%"  border="0">
		<tr>
			<td class="rubfrm" colspan="2" align="center">CONSOMMABLES</td>
		</tr>
		</table>
		<?PHP if ((trim($pdtloc_pdtucons1)<>"") AND (trim($pdtloc_pdtucons1)<>"-1"))  { ?>
		<table width="100%"  border="0">
		<tr>
			<td colspan="2">
			<?PHP
			$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
			mysql_select_db(DBNAME);
			$rech = "SELECT * FROM ".TBPDTU." WHERE `pdtu_code`= '".$pdtloc_pdtucons1."'";
			$rs = mysql_query($rech)or die(mysql_error());
			if (mysql_num_rows($rs) == 1) // Uniquement UN SEUL enregistrement !
			{
				if ($row = mysql_fetch_array($rs)) 
					extract ($row);
			}
			mysql_free_result($rs);
			mysql_close($conn);
			?>
			<div class="titre_gras_soul">Consommable 1 (<?PHP echo $pdtu_desc; ?>)</div>
			<div align="center">
			<?PHP
			echo ' Quantit&eacute; incluse dans ce bar&ecirc;me :';
			echo ' <input name="qconsi1" type="text" id="qconsi1" value="'.$barloc_qconsi1.'" style="text-align:right" size="10">';
			echo ', pour un montant de';
			echo ' <input name="puconsi1" type="text" id="puconsi1" value="'.format_num($barloc_puconsi1,2).'" style="text-align:right" size="10" onChange="formatedeci(this.id,2);">';
			echo ' '.$lang['symbole_monnaie'];
			?>
			</div>
			</td>
		</tr>
		</table>
		<div id="dettarcons1">
		</div>
	
		<!-- Lien d'ajout de barêmes -->
		<?PHP
		if ($td == "edit")
		{
		?>
			<div id="addtc1" style="<?PHP if (exist_infini_tcons_id($barloc_id,1,TRUE)==TRUE) echo "display:none"; else "display:block"; ?>">
			<a href="javascript:;" onclick="fen_tcons_barloc('add',<?PHP echo $barloc_id; ?>,'','1');")><img src="../img/add.png" border="0" align="absmiddle"></a>
			<a href="javascript:;" onclick="fen_tcons_barloc('add',<?PHP echo $barloc_id; ?>,'','1');")> Ajouter un tarif</a>
			</div>
		<?PHP
		}

		if ((trim($pdtloc_pdtucons1)<>"") && (trim($pdtloc_pdtucons2)<>"")) {
		?>
		<hr noshade width="50%" size="1" align="center" color="#93742D">
		<?PHP }
		}
		if ((trim($pdtloc_pdtucons2)<>"") AND (trim($pdtloc_pdtucons2)<>"-1"))  { ?>
		<table width="100%"  border="0">
		<tr>
			<td colspan="2">
			<?PHP
			$pdtu_desc="";
			$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
			mysql_select_db(DBNAME);
			$rech = "SELECT * FROM ".TBPDTU." WHERE `pdtu_code`= '".$pdtloc_pdtucons2."'";
			$rs = mysql_query($rech)or die(mysql_error());
			if (mysql_num_rows($rs) == 1) // Uniquement UN SEUL enregistrement !
			{
				if ($row = mysql_fetch_array($rs)) 
					extract ($row);
			}
			mysql_free_result($rs);
			mysql_close($conn);
			?>
			<div class="titre_gras_soul">Consommable 2 (<?PHP echo $pdtu_desc; ?>)</div>
			<div align="center">
			<?PHP
			echo ' Quantit&eacute; incluse dans ce bar&ecirc;me :';
			echo ' <input name="qconsi2" type="text" id="qconsi2" value="'.$barloc_qconsi2.'" style="text-align:right" size="10">';
			echo ', pour un montant de';
			echo ' <input name="puconsi2" type="text" id="puconsi2" value="'.format_num($barloc_puconsi2,2).'" style="text-align:right" size="10" onChange="formatedeci(this.id,2);">';
			echo ' '.$lang['symbole_monnaie'];
			?>
			</div>
			</td>
		</tr>
		</table>
		<div id="dettarcons2">
		</div>
	
		<!-- Lien d'ajout de barêmes consommables -->
		<?PHP
		if ($td == "edit")
		{
		?>
			<div id="addtc2" style="<?PHP if (exist_infini_tcons_id($barloc_id,2,TRUE)==TRUE) echo "display:none"; else "display:block"; ?>">
			<a href="javascript:;" onclick="fen_tcons_barloc('add',<?PHP echo $barloc_id; ?>,'','2');")><img src="../img/add.png" border="0" align="absmiddle"></a>
			<a href="javascript:;" onclick="fen_tcons_barloc('add',<?PHP echo $barloc_id; ?>,'','2');")> Ajouter un tarif</a>
			</div>
		<?PHP
		}
		
		}
	}
	?>
  <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_valider; ?>">
    <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 
if (($td == "edit") OR ($td == "add"))
{
?>
	<script type="text/javascript">
	<!--
		Calendar.setup({
			inputField     :    "dateval1f",     // id of the input field
			ifFormat       :    "<?PHP echo $datefmtc; ?>",      // format of the input field
			button         :    "f_img_dateval1f",  // trigger for the calendar (button ID)
			align          :    "Br",           // alignment (defaults to "Bl")
			electric	   :	false,
			singleClick    :    true
		});
		Calendar.setup({
			inputField     :    "dateval2f",     // id of the input field
			ifFormat       :    "<?PHP echo $datefmtc; ?>",      // format of the input field
			button         :    "f_img_dateval2f",  // trigger for the calendar (button ID)
			align          :    "Br",           // alignment (defaults to "Bl")
			electric	   :	false,
			singleClick    :    true
		});
	//-->
	</script>
<?PHP
} 
}
else
{
?>
	<script type="text/javascript">
	<!--
	self.close('fscomp');
	//-->
	</script>
<?PHP
}
?>
</body>
</html>
