<?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_dloc.inc.php");
include_once("../inc/fic_pdt.inc.php");
include_once("../inc/fic_loc.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_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']));
$coderech = strip_tags(trim($_GET['code']));

$pbm_pdt=FALSE;
$cautionttc=0;
$pxrevient_rep=0;

if ($coderech <> "")
{
	// Récupération des informations produit
	$row = lit_enr_pdtloc($coderech);
	if (is_array($row))
		extract ($row);

	// Récupération des informations TVA
	$row = lit_enr_tva($pdtloc_tvacaut,TRUE);
	if (is_array($row))
		extract ($row);

	$txtva=$tva_tx/100;
	$cautionttc=round(($pdtloc_caution*(1+$txtva))*100)/100;

	$pxrevient_rep=px_revient_pdtlocr($pdtloc_code);
}
else
{
	if ($td<>"add")
		$pbm_pdt=TRUE;
}

if (@$_SESSION["niv_log"] == 3)
	$td="view";
	
switch ($td)
{
	case "add" :
		$titre = "CREATION ARTICLE A LOUER";
		$pdtloc_louable = TRUE;
		$pdtloc_loue = FALSE;
		if (@$_SESSION["niv_log"] == 4)
		{
			$iddloc=id_dloc_page($_SESSION["code_age"],TRUE);
			if ($iddloc>0)
				$pdtloc_iddloc=$iddloc;
			else
				$pbm_pdt=TRUE;
		}
		break;
	case "edit" :
		$titre = "MISE A JOUR ARTICLE A LOUER";
		if (@$_SESSION["niv_log"] == 4)
		{
			$iddloc=id_dloc_page($_SESSION["code_age"],TRUE);
			if ($iddloc<>$pdtloc_iddloc)
				$pbm_pdt=TRUE;
		}
		break;
	case "view" :
		$titre = "DETAIL ARTICLE A LOUER";
		break;
	case "del" :
		$titre = "SUPPRESSION ARTICLE A LOUER";
		if (@$_SESSION["niv_log"] == 4)
		{
			$iddloc=id_dloc_page($_SESSION["code_age"],TRUE);
			if ($iddloc<>$pdtloc_iddloc)
				$pbm_pdt=TRUE;
		}
		break;
	default :
		$pbm_pdt=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 Article &agrave; Louer</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 champs -->
<script	type="text/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 tab1_champ=new Array(
	"nom:code ; format:txt ; req:Y ; txt:<?PHP echo html_entity_decode($txt_chp_code); ?> ; lmx:20 ; stok:frmok ; stbad:frmbad",
<?PHP if (($td == "add") OR ($td == "edit"))
{ 
?>
	"nom:dloc ; format:liste ; req:Y ; txt:Dépôt ; vmn:1 ; stok:frmok ; stbad:frmbad",
	"nom:fam ; format:liste ; req:Y ; txt:Famille ; vmn:1 ; stok:frmok ; stbad:frmbad",
	"nom:tva; format:liste ; req:Y ; txt:TVA ; vmn:1 ; stok:frmok ; stbad:frmbad",
	"nom:ucons1 ; format:liste ; req:Y ; txt:Unité consommable 1; vmn:1 ; stok:frmok ; stbad:frmbad",
	"nom:tvacons1; format:liste ; req:Y ; txt:TVA consommable 1; vmn:1 ; stok:frmok ; stbad:frmbad",
	"nom:ucons2 ; format:liste ; req:Y ; txt:Unité consommable 2; vmn:1 ; stok:frmok ; stbad:frmbad",
	"nom:tvacons2; format:liste ; req:Y ; txt:TVA consommable 2; vmn:1 ; stok:frmok ; stbad:frmbad",
<?PHP
}
else
{
?>
	"nom:dloc ; format:txt ; req:Y ; txt:Dépôt ; stok:frmok ; stbad:frmbad",
	"nom:fam ; format:txt ; req:Y ; txt:Famille ; stok:frmok ; stbad:frmbad",
	"nom:tva; format:txt ; req:Y ; txt:TVA ; vmn:1 ; stok:frmok ; stbad:frmbad",
	"nom:ucons1 ; format:txt ; req:Y ; txt:Unité consommable 1 ; stok:frmok ; stbad:frmbad",
	"nom:tvacons1 ; format:txt ; req:Y ; txt:TVA consommable 1 ; vmn:1 ; stok:frmok ; stbad:frmbad",
	"nom:ucons2 ; format:txt ; req:Y ; txt:Unité consommable 2 ; stok:frmok ; stbad:frmbad",
	"nom:tvacons2 ; format:txt ; req:Y ; txt:TVA consommable 2 ; vmn:1 ; stok:frmok ; stbad:frmbad",
<?PHP
}
?>
	"nom:des; format:txt ; req:Y ; txt:<?PHP echo html_entity_decode($txt_chp_lib); ?> ; lmx:50 ; stok:frmok ; stbad:frmbad",
	"nom:ns; format:txt ; req:Y ; txt:Numéro de série ; lmx:100 ; stok:frmok ; stbad:frmbad",
	"nom:valneuf; format:reel_ns ; req:Y ; txt:Valeur à neuf ; lmx:10 ; stok:frmok ; stbad:frmbad",
	"nom:valnet; format:reel_ns ; req:Y ; txt:Valeur nette ; lmx:10 ; stok:frmok ; stbad:frmbad",
	"nom:caution; format:reel_ns ; req:Y ; txt:Caution ; lmx:10 ; stok:frmok ; stbad:frmbad",
	"nom:cautionttc; format:reel_ns ; req:Y ; txt:Caution TTC ; lmx:10 ; stok:frmok ; stbad:frmbad",
	"nom:idxcons1; format:unsigned ; req:N ; txt:Index consommable 1 ; lmx:10 ; stok:frmok ; stbad:frmbad",
	"nom:idxcons2; format:unsigned ; req:N ; txt:Index consommable 2 ; lmx:10 ; 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>

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

<?PHP cre_js_barloc($td,$pdtloc_code,""); ?>

</head>

<?PHP if ($td == "del"){ ?>
<body onload="warndel();metReadonly();">
<?PHP } else { ?>
<body onLoad="metFocus();tbbarloc();">
<?PHP 
}
include_once("../inc/entete.inc.php");
?>
<p align="center"> <span class="titrepage"><?PHP echo $titre ?></span></p>
<!-- Affiché uniquement s'il y a au moins famille et un dépôt actif -->
<?PHP
if ($pbm_pdt==FALSE)
{
if ((nb_fam() > 0) AND (nb_dloc_actifs()>0))
{
?>
<table width="100%"  border="0">
  <tr>
    <td width="33%"><strong><em><a href="pdtloc_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="pdtloc_maj" id="pdtloc_maj" method="post" action="pdtloc_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 ?>">

<table width="100%"  border="0">
<tr>
  <td width="160" class="rubfrm" id="f_dloc" align="right">D&eacute;p&ocirc;t</td>
  <td>
	<?PHP
	$aff_lst=TRUE;
	// On ne peut modifier le dépôt que si on est administrateur ou centre de gestion, ou le "propriétaire" du dépôt,
	// et uniquement si le produit n'est pas en cours de location, est louable, et n'est pas réservé
	if (($td == "add") OR ($td == "edit"))
	{ 
		if (($pdtloc_louable==TRUE) AND ($pdtloc_loue==FALSE))
		{
			if ((@$_SESSION["niv_log"]==9) OR (@$_SESSION["niv_log"]==5) OR (@$_SESSION["niv_log"]==4))
			{
				// Si c'est une agence, on vérifie
				// que le dépôt du produit est bien le principal de l'agence
				if (@$_SESSION["niv_log"]==4)
				{
					$iddloc=id_dloc_page(@$_SESSION["code_age"],TRUE);
					if ($pdtloc_iddloc<>$iddloc)
						$aff_lst==FALSE;
				}
	
				if ($aff_lst=TRUE)
				{
					// On vérifie que le produit n'est pas réservé
					if (exist_adep_in_coloc_ouv($pdtloc_code)==FALSE)
					{
						// On vérifie que le produit n'est pas en attente de retour
						if (exist_aret_in_coloc_ouv($pdtloc_code)==FALSE)
						{
  ?>
		<select name="dloc" size="1" id="dloc">
	  <?PHP
			echo "<option>-- Choisissez un dépôt --</option>";
			
			// Création de la liste des dépôts
			$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
			mysql_select_db(DBNAME);
			$rech = "SELECT * FROM ".TBDLOC." WHERE dloc_ouvert=1 ORDER BY dloc_nom ";
			$rs = mysql_query($rech)or die(mysql_error());

			while ($resultat = mysql_fetch_array($rs)) 
			{
				extract($resultat);
				echo '<option value="'.$dloc_id.'"';
				if ($pdtloc_iddloc == $dloc_id)
					echo ' selected';
				$txt_nom=$dloc_nom;
				if ($dloc_codeage<>NULL)
					$txt_nom.=" (Agence ".$dloc_codeage.")";
				echo '>'.$txt_nom.'</option>';
			}
			mysql_free_result($rs);
			mysql_close($conn);
			?>
		</select>
		<img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">
	<?PHP
						}
						else
							$aff_lst=FALSE;
					}
					else
						$aff_lst=FALSE;
				}
				else
					$aff_lst=FALSE;
			}
			else
				$aff_lst=FALSE;
		}
		else
			$aff_lst=FALSE;
	}
	else
		$aff_lst=FALSE;
	
	if ($aff_lst==FALSE)
	{
		$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
		mysql_select_db(DBNAME);
		$rech = "SELECT * FROM ".TBDLOC." WHERE `dloc_id`= '".$pdtloc_iddloc."'";
		$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);
	?>
		<input name="dloc" type="hidden" id="dloc" value="<?PHP echo $dloc_id ?>" >
		<input name="ndloc" type="text" id="ndloc" value="<?PHP echo $dloc_nom ?>" size="50" readonly="1">
	<?PHP
	}

	if ($td=="edit") 
	{ 
	?>
		<br /><span class="annot_petit_it">Le d&eacute;p&ocirc;t ne peut &ecirc;tre chang&eacute; que si le produit n'est pas r&eacute;serv&eacute; sur un contrat, n'est pas lou&eacute;, et est louable</span> 
		<br />
		<span class="annot_petit_it">Apr&egrave;s r&eacute;affection, si vous &ecirc;tes l'agence g&eacute;rant le d&eacute;p&ocirc;t ci-dessus et que vous transf&eacute;rez ce produit vers un autre d&eacute;p&ocirc;t, vous ne pourrez plus modifier cette fiche</span>	<?PHP
	}
	?>
	</td>
	<td width="40%" align="right" valign="top">&nbsp;
	<?PHP
	/*
	if (($td == "edit") OR ($td == "view"))
	{
	$urlimp1 = "pdtloc_pdf.php?cp=".$coderech;
	<a href="javascript:;" onclick="lanceimp('<?PHP echo $urlimp1; ?>');")><img src="../img/print.png" title="Imprimer" border="0" align="absmiddle"></a> 
	<a href="javascript:;" onclick="lanceimp('<?PHP echo $urlimp1; ?>');")> Imprimer</a> 
	}
	else
		echo "&nbsp;";
	*/
	?>
    </td>
</tr>
</table>

<table width="100%"  border="0">
<tr>
  <td width="160" class="rubfrm" id="f_code" align="right"><?PHP echo $txt_chp_code; ?></td>
  <td>
  <?PHP if ($td == "add") { ?>
	  <input name="code" type="text" id="code" value="<?PHP echo $pdtloc_code ?>" size="20" maxlength="20" 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 $pdtloc_code ?>" size="20" maxlength="20" readonly="1">
  <?PHP } ?>  </td>
</tr>
<tr>
  <td width="160" class="rubfrm" id="f_fam" align="right">Famille</td>
  <td>
  <?PHP if (($td == "add") OR ($td == "edit"))
  { 
  ?>
		<select name="fam" size="1" id="fam">
	  <?PHP
			echo "<option>-- Choisissez une famille --</option>";
			
			// Création de la liste des familles
			$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
			mysql_select_db(DBNAME);
			$rech = "SELECT * FROM ".TBFAM." ORDER BY fam_desc";
			$rs = mysql_query($rech)or die(mysql_error());

			while ($resultat = mysql_fetch_array($rs)) 
			{
				extract($resultat);
				echo '<option value="'.$fam_code.'"';
				if ($pdtloc_fam == $fam_code)
					echo ' selected';
				echo '>'.$fam_desc.'</option>';
			}
			mysql_free_result($rs);
			mysql_close($conn);
			?>
		</select>
		<img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">
	<?PHP
	}
	else
	{
		$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
		mysql_select_db(DBNAME);
		$rech = "SELECT * FROM ".TBFAM." WHERE `fam_code`= '".$pdtloc_fam."'";
		$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);
	?>
		<input name="fam" type="text" id="fam" value="<?PHP echo $fam_desc ?>" size="50" maxlength="50" readonly="1">
	<?PHP
	}
	?>	</td>
</tr>
<tr>
  <td width="160" class="rubfrm" id="f_des" align="right"><?PHP echo $txt_chp_lib; ?></td>
  <td>
  <?PHP if (($td == "add") OR ($td == "edit"))
  { 
  ?>
	<input name="des" type="text" id="des" value="<?PHP echo htmlspecialchars($pdtloc_des) ?>" size="50" onChange="javascript:this.value=this.value.toUpperCase();"> <img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">
  <?PHP
  }
  else
  {
  ?>
	<input name="des" type="text" id="des" value="<?PHP echo htmlspecialchars($pdtloc_des) ?>" size="50" readonly="1"> 
  <?PHP
  }
  ?>  </td>
</tr>
<tr>
  <td width="160" class="rubfrm" id="f_ns" align="right">Num&eacute;ro de s&eacute;rie</td>
  <td>
  <?PHP if (($td == "add") OR ($td == "edit"))
  { 
  ?>
	<input name="ns" type="text" id="ns" value="<?PHP echo htmlspecialchars($pdtloc_ns) ?>" size="100">
	 <img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">
  <?PHP
  }
  else
  {
  ?>
	<input name="ns" type="text" id="ns" value="<?PHP echo htmlspecialchars($pdtloc_ns) ?>" size="100" readonly="1"> 
  <?PHP
  }
  ?>  </td>
</tr>
<tr>
  <td class="rubfrm" id="f_louable" align="right">Louable</td>
  <td>
  <?PHP 
	if (($td <> "del") AND ($td <> "view") AND ($pdtloc_loue==FALSE))
	{ 
		echo "<select name=\"louable\" size=\"1\" id=\"louable\">";
		echo "<option value=\"Oui\"";
		if ($pdtloc_louable == TRUE)
			echo" selected";
		echo">".$sel_lst_oui."</option>";
		echo "<option value=\"Non\"";
		if ($pdtloc_louable == 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="louable" type="text" id="louable" value="<?PHP echo $non_oui[$pdtloc_louable]; ?>" size="3" maxlength="3" readonly="1">
  <?PHP
	}
	if ($pdtloc_loue==0)
	{
		echo '<span class="alerte2">';
		echo 'Non lou&eacute;';
	}
	else
	{
		echo '<span class="alerte1">';
		echo 'En cours de location';
	}
	echo '</span>';
	?></td>
</tr>
<tr>
  <td width="160" class="rubfrm" id="f_valneuf" align="right">Valeur &agrave; neuf</td>
  <td>
  <?PHP if (($td == "add") OR ($td == "edit"))
  { 
  ?>
	<input name="valneuf" type="text" id="valneuf" style="text-align:right" value="<?PHP echo format_num($pdtloc_valneuf,2); ?>" size="10" onChange="formatedeci(this.id,2);">
	 <?PHP echo $lang['symbole_monnaie']; ?><br>
	 <span class="annot_petit_it">(Hors taxes. La d&eacute;cimale doit &ecirc;tre '.' et pas la virgule)</span>
  <?PHP
  }
  else
  {
  ?>
	<input name="valneuf" type="text" id="valneuf" style="text-align:right" value="<?PHP echo format_num($pdtloc_valneuf,2); ?>" size="10" readonly="1">
	 <?PHP echo $lang['symbole_monnaie']; ?>
	 <span class="annot_petit_it">(Hors taxes)</span>
  <?PHP
  }
  ?>  </td>
</tr>
<tr>
  <td width="160" class="rubfrm" id="f_valnet" align="right">Valeur nette</td>
  <td>
  <?PHP if (($td == "add") OR ($td == "edit"))
  { 
  ?>
  	<span class="annot_petit_gras">VNC : </span>
	<input name="valnet" type="text" id="valnet" style="text-align:right" value="<?PHP echo format_num($pdtloc_valnet,2); ?>" size="10" onChange="somme(this.id,'mtrep','totvalnet',2,0);formatedeci(this.id,2);">
	 <?PHP echo $lang['symbole_monnaie']; ?>
	<span class="annot_petit_gras"> + R&eacute;parations : </span>
	<input name="mtrep" type="text" id="mtrep" style="text-align:right" value="<?PHP echo format_num($pxrevient_rep,2); ?>" size="10" readonly="1"> 
	<?PHP echo $lang['symbole_monnaie']; ?>
	<span class="annot_petit_gras"> = </span>
	<input name="totvalnet" type="text" id="totvalnet" style="text-align:right" value="<?PHP echo format_num($pdtloc_valnet+$pxrevient_rep,2); ?>" size="10" readonly="1"> 
	<?PHP echo $lang['symbole_monnaie']; ?>
  <?PHP
    if ($td == "edit")
	{
		$url_pdtlocr = "pdtlocr_maj.php?td=lst&cp=".$pdtloc_code;
    ?>
		 <a href="javascript:;" onclick="fensaisie('<?PHP echo $url_pdtlocr; ?>',950,560,'status=no,scrollbars=yes,menubar=no,statusbar=no,location=no,locationbar=no');")><img src="../img/int.png" title="Ajouter r&eacute;parataion" border="0" align="absmiddle"></a>
		<div class="annot_petit_it">(Hors taxes. La d&eacute;cimale doit &ecirc;tre '.' et pas la virgule)</div>
	<?PHP
	}
  }
  else
  {
  ?>
	<input name="valnet" type="text" id="valnet" style="text-align:right" value="<?PHP echo format_num($pdtloc_valnet,2); ?>" size="10" readonly="1"> 
	 <?PHP echo $lang['symbole_monnaie']; ?>
	<span class="annot_petit_gras"> + R&eacute;parations : </span>
	<input name="mtrep" type="text" id="mtrep" style="text-align:right" value="<?PHP echo format_num($px_revient_rep,2); ?>" size="10" readonly="1"> 
	<?PHP echo $lang['symbole_monnaie']; ?>
	<span class="annot_petit_gras"> = </span>
	<input name="totvalnet" type="text" id="totvalnet" style="text-align:right" value="<?PHP echo format_num($pdtloc_valnet+$px_revient_rep,2); ?>" size="10" readonly="1"> 
	<?PHP echo $lang['symbole_monnaie']; ?>
	 <div class="annot_petit_it">(Hors taxes)</div>
  <?PHP
  }
  ?>  </td>
</tr>
<tr>
  <td width="160" class="rubfrm" id="f_caution" align="right">Montant caution</td>
  <td>
  <?PHP if (($td == "add") OR ($td == "edit"))
  { 
  ?>
	<span class="annot_std_gras">HT</span> : <input name="caution" type="text" id="caution" style="text-align:right" value="<?PHP echo format_num($pdtloc_caution,2); ?>" size="10" onChange="formatedeci(this.id,2);ttc_from_ht(this.value,'tva','cautionttc',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('caution').value,this.id,'cautionttc',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 ($pdtloc_tvacaut == $tva_code)
				echo ' selected';
			echo '>'.$tva_desc.'</option>';
		}
		mysql_free_result($rs);
		mysql_close($conn);
	?>
	</select>
	<?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);
	?>	
	 <span class="annot_std_gras">TTC</span> : <input name="cautionttc" type="text" id="cautionttc" style="text-align:right" value="<?PHP echo format_num($cautionttc,2); ?>" size="10" onChange="formatedeci(this.id,2);ht_from_ttc(this.value,'tva','caution',2);">
	 <?PHP echo $lang['symbole_monnaie']; ?><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="caution" type="text" id="caution" style="text-align:right" value="<?PHP echo format_num($pdtloc_caution,2); ?>" size="10" readonly="1">
	 <?PHP echo $lang['symbole_monnaie']; ?>
	 <span class="annot_std_gras">TVA</span> :
	  <?PHP
		$row=lit_enr_tva($pdtloc_tvacaut,TRUE);
		if (is_array($row))
			extract($row);
	  ?>
	 <input name="tva" type="hidden" id="tva" value="<?PHP echo $pdtloc_tvacaut ?>"> 
	 <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="cautionttc" type="text" id="cautionttc" style="text-align:right" value="<?PHP echo format_num($cautionttc,2); ?>" size="10" readonly="1">
  <?PHP
  }
  ?>  </td>
</tr>
<tr>
<td width="160" class="rubfrm" id="f_note" align="right">Notes internes</td>
<td>
	<textarea name="note" id="note" rows="4" <?PHP if ($td=="view") echo 'readonly="readonly"';?>><?PHP echo htmlspecialchars($pdtloc_note); ?></textarea></td>
</tr>
<tr>
	<td class="rubfrm" colspan="2" align="center">CONSOMMABLES FACTURABLES</td>
</tr>
<tr>
	<table width="100%"  border="0">
	<tr>
	<td width="50%" colspan="2" align="center" class="rubfrm">Consommable 1</td>
	<td colspan="2" align="center" class="rubfrm">Consommable 2</td>
	</tr>
	<tr>
	  <td width="160" class="rubfrm" id="f_ucons1" align="right">Unit&eacute;</td>
	  <td>
	  <?PHP if (($td == "add") OR ($td == "edit"))
	  { 
	  ?>
			<select name="ucons1" size="1" id="ucons1" onChange="verif_ucons(1);">
		  <?PHP
				echo "<option value=\"-2\">-- Type de consommable --</option>";
				echo '<option value="-1"';
				if ($pdtloc_pdtucons1==-1)
					echo ' selected';
				echo '>Pas de consommable</option>';
				
				// Création de la liste des unités possibles
				$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
				mysql_select_db(DBNAME);
				$rech = "SELECT * FROM ".TBPDTU." ORDER BY pdtu_desc";
				$rs = mysql_query($rech)or die(mysql_error());
	
				while ($resultat = mysql_fetch_array($rs)) 
				{
					extract($resultat);
					echo '<option value="'.$pdtu_code.'"';
					if ($pdtloc_pdtucons1 == $pdtu_code)
						echo ' selected';
					echo '>'.$pdtu_desc.'</option>';
				}
				mysql_free_result($rs);
				mysql_close($conn);
				?>
			</select>
			<img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">
		<?PHP
		}
		else
		{
			$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);
			}
			else
				$pdtu_desc="Pas de consommable";
			mysql_free_result($rs);
			mysql_close($conn);
		?>
			<input name="ucons1" type="text" id="ucons1" value="<?PHP echo $pdtu_desc ?>" size="50" maxlength="50" readonly="1">
		<?PHP
		}
		?>
	  </td>
	  <td width="160" class="rubfrm" id="f_ucons2" align="right">Unit&eacute;</td>
	  <td>
	  <?PHP if (($td == "add") OR ($td == "edit"))
	  { 
	  ?>
			<select name="ucons2" size="1" id="ucons2" onChange="verif_ucons(2);">
		  <?PHP
				echo "<option value=\"-2\">-- Type de consommable --</option>";
				echo '<option value="-1"';
				if ($pdtloc_pdtucons2==-1)
					echo ' selected';
				echo '>Pas de consommable</option>';
				
				// Création de la liste des unités possibles
				$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
				mysql_select_db(DBNAME);
				$rech = "SELECT * FROM ".TBPDTU." ORDER BY pdtu_desc";
				$rs = mysql_query($rech)or die(mysql_error());
	
				while ($resultat = mysql_fetch_array($rs)) 
				{
					extract($resultat);
					echo '<option value="'.$pdtu_code.'"';
					if ($pdtloc_pdtucons2 == $pdtu_code)
						echo ' selected';
					echo '>'.$pdtu_desc.'</option>';
				}
				mysql_free_result($rs);
				mysql_close($conn);
				?>
			</select>
			<img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">
		<?PHP
		}
		else
		{
			$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);
			}
			else
				$pdtu_desc="Pas de consommable";
			mysql_free_result($rs);
			mysql_close($conn);
		?>
			<input name="ucons2" type="text" id="ucons2" value="<?PHP echo $pdtu_desc ?>" size="50" maxlength="50" readonly="1">
		<?PHP
		}
		?>		</td>
	</tr>
	<tr>
	  <td width="160" class="rubfrm" id="f_idxc1" align="right">Index actuel</td>
	  <td>
		<input name="idxcons1" type="text" id="idxcons1" style="text-align:right" value="<?PHP echo $pdtloc_idxcons1; ?>" size="10" <?PHP if ($td=="view") echo 'readonly="readonly"'; ?>>
	  </td>
	  <td width="160" class="rubfrm" id="f_idxc2" align="right">Index actuel</td>
	  <td>
		<input name="idxcons2" type="text" id="idxcons2" style="text-align:right" value="<?PHP echo $pdtloc_idxcons2; ?>" size="10" <?PHP if ($td=="view") echo 'readonly="readonly"'; ?>>
	  </td>
	</tr>
	</tr>
	<tr>
	  <td width="160" class="rubfrm" id="f_tvac1" align="right">TVA applicable</td>
	  <td>
	  <?PHP if (($td == "add") OR ($td == "edit"))
	  { 
	  ?>
		 <select name="tvacons1" size="1" id="tvacons1" onChange="verif_ucons(1);">
		  <?PHP
			echo "<option value=\"\">-- Choisissez une TVA --</option>";
			echo '<option value="-1"';
			if ($pdtloc_tvacons1==-1)
				echo ' selected';
			echo ">-- Sans objet --</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 ($pdtloc_tvacons1 == $tva_code)
					echo ' selected';
				echo '>'.$tva_desc.'</option>';
			}
			mysql_free_result($rs);
			mysql_close($conn);
		?>
		</select>
	  <?PHP
	  }
	  else
	  {
	  ?>
		  <?PHP
			$row=lit_enr_tva($pdtloc_tvacons1,TRUE);
			if (is_array($row))
				extract($row);
			else
				$tva_desc="-- Sans objet --";
		  ?>
		 <input name="tvacons1" type="hidden" id="tvacons1" value="<?PHP echo $pdtloc_tvacons1 ?>"> 
		 <input name="ntvacons1" type="text" id="ntvacons1" align="right" value="<?PHP echo $tva_desc ?>" size="40" readonly="1"> 
	  <?PHP
	  }
	  ?>	  </td>
	  <td width="160" class="rubfrm" id="f_tvac2" align="right">TVA applicable</td>
	  <td>
	  <?PHP if (($td == "add") OR ($td == "edit"))
	  { 
	  ?>
		 <select name="tvacons2" size="1" id="tvacons2" onChange="verif_ucons(2);">
		  <?PHP
			echo "<option value=\"\">-- Choisissez une TVA --</option>";
			echo '<option value="-1"';
			if ($pdtloc_tvacons1==-1)
				echo ' selected';
			echo ">-- Sans objet --</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 ($pdtloc_tvacons2 == $tva_code)
					echo ' selected';
				echo '>'.$tva_desc.'</option>';
			}
			mysql_free_result($rs);
			mysql_close($conn);
		?>
		</select>
	  <?PHP
	  }
	  else
	  {
	  ?>
		  <?PHP
			$row=lit_enr_tva($pdtloc_tvacons2,TRUE);
			if (is_array($row))
				extract($row);
			else
				$tva_desc="-- Sans objet --";
		  ?>
		 <input name="tvacons2" type="hidden" id="tvacons2" value="<?PHP echo $pdtloc_tvacons2; ?>"> 
		 <input name="ntvacons2" type="text" id="ntvacons2" align="right" value="<?PHP echo $tva_desc ?>" size="40" readonly="1"> 
	  <?PHP
	  }
	  ?>	  </td>
	</tr>
	</table>
</tr>
</table>
	<!-- Zone de saisie des barêmes -->
	<?PHP
	if (($td == "edit") OR ($td == "del") OR ($td == "view"))
	{
	?>
		<table width="100%"  border="0">
		<tr>
			<td class="rubfrm" colspan="2" align="center">BAREMES</td>
		</tr>
		</table>
		<div id="detbarloc">
		</div>
	
		<!-- Lien d'ajout de barêmes -->
		<?PHP
		if ($td == "edit")
		{
			$urlchoixbar = "perloc_lst.php?ta=p&cp=".$coderech;
		?>
			<a href="javascript:;" onclick="fensaisie('<?PHP echo $urlchoixbar; ?>',900,500,'status=no,scrollbars=yes,menubar=no,statusbar=no,location=no,locationbar=no');")><img src="../img/add.png" border="0" align="absmiddle"></a>
			<a href="javascript:;" onclick="fensaisie('<?PHP echo $urlchoixbar; ?>',900,500,'status=no,scrollbars=yes,menubar=no,statusbar=no,location=no,locationbar=no');")> Ajouter un bar&ecirc;me</a>
			<br>
		<?PHP
		}
	}
	?>
  <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 } 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:; history.back();">
    <?PHP } if ($td == "view") { ?>
    <input name="annul" type="button" class="bton_std" id="annul" value="<?PHP echo $but_retlst; ?>" onclick="javascript:; history.back();">
    <?PHP } ?>
  </p>
</form>
<!-- Fin Affiché uniquement s'il y a au moins une famille article -->
	<?PHP
	}
	else
	{
		if (nb_dloc_actifs()==0)
			$txt_err.="<br>Merci de cr&eacute;er au moins un d&eacute;p&ocirc;t.";
		if (nb_fam()==0)
			$txt_err.="<br>Merci de cr&eacute;er au moins une famille article.";
	?>
		<p align="center" class="annot_std_it"><?PHP echo $txt_err; ?></p>
		<script type="text/javascript">
		<!--
		setTimeout("self.location.href=('index.php');",2000)
		//-->
		</script>
<?PHP 
	}
}
else
	aff_ret_pbm_auto("pdtloc_lst.php?td=m&ca=".@$_SESSION["code_age"],2000);
include_once("pied.php");
?>
