<?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_hum.inc.php");
include_once("../inc/fic_loc.inc.php");
include_once("../inc/fic_pdt.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"]);
// On initalise les tableaux des barêmes de location, des pénalités, des consommables
$_SESSION["pdtlbl"]=array();
$_SESSION["pdtlpl"]=array();
$_SESSION["pdtlcl"]=array();

$td = strip_tags(trim(@$_GET['td']));
$codecoloc = strip_tags(trim(@$_GET['cl']));
$codeart = strip_tags(trim(@$_GET['ca']));
if (isset($_GET["dd"]))
	$dd=strip_tags(trim(@$_GET["dd"]));
else
	$dd="";
if (isset($_GET["hd"]))
	$hd=strip_tags(trim(@$_GET["hd"]));
else
	$hd="";
if (isset($_GET["df"]))
	$df=strip_tags(trim(@$_GET["df"]));
else
	$df="";	
if (isset($_GET["hf"]))
	$hf=strip_tags(trim(@$_GET["hf"]));
else
	$hf="";	
	
$pbm_pdt=FALSE;

if (($td<>"add") AND ($td<>"edit") AND ($td<>"del") AND ($td<>"view") AND ($td<>"dep") AND ($td<>"ret"))
	$pbm_pdt=TRUE;
if ((datefrcorrecte($dd)==FALSE) OR (datefrcorrecte($df)==FALSE))
	$pbm_pdt=TRUE;
if ((heurecorrecte($hd.':00')==FALSE) OR (heurecorrecte($hf.':00')==FALSE))
	$pbm_pdt=TRUE;
	
if ($pbm_pdt==FALSE)
{
	if ($codecoloc <> "")
	{
		$row = lit_enr_coloc($codecoloc);
		if (is_array($row))
		{
			extract ($row);
			
			// Contrôle si contrat soldé (si tous les produits sont revenus, on force la clôture)
			if (formatedate($coloc_dateclos) =="")
			{
				if (all_pdtloc_ret_in_coloc($co,TRUE)==TRUE)
				{
					$coloc_dateclos=lastdate_ret_in_coloc($co,TRUE);
					clot_coloc($co,$coloc_dateclos,TRUE);
				}
			}
				
			// Si contrat terminé, force le mode "view"
			if (formatedate($coloc_dateclos) <> "")
				$td="view";

			// Récupération des données de la fiche article
			$row = lit_enr_pdtloc($codeart);
			if (is_array($row))
			{
				extract ($row);
				
				// Récupération des indexes
				$udesc1="";
				$udesc2="";
				$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);
						$udesc1=$pdtu_desc;
					}
				}
				$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);
						$udesc2=$pdtu_desc;
					}
				}
				mysql_free_result($rs);
				mysql_close($conn);
				
				if ($td == "add")
				{
					$pdtl_codecoloc = $codecoloc;
					$pdtl_codepdtloc = $pdtloc_code;
					$pdtl_datedeb = $dd;
					$pdtl_datefin = $df;
					$pdtl_noted = "";
					$pdtl_noter = "";
				}
				else
				{
					$_SESSION["pdtlbl"]=array();
					// Construction du tableau des barêmes
					$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
					mysql_select_db(DBNAME);
					// Récupération ID
					$rech = "SELECT * FROM `" .TBPDTL. "` WHERE `pdtl_codepdtloc` = '$codeart' AND `pdtl_codecoloc` = '$codecoloc'";
					$rs = mysql_query($rech)or die(mysql_error());
					if (mysql_num_rows($rs) == 1)
					{
						if ($row = mysql_fetch_array($rs))
						{
							extract($row);
							
							$pdtl_datedepf=formatedate($pdtl_datedep);
							$pdtl_dateretf=formatedate($pdtl_dateret);
							
							// construction du tableau pour le barême location
							$tab_enr=array();
							$rech2 = "SELECT * FROM `" .TBPDTLBL. "` WHERE `pdtlbl_idpdtl` = '$pdtl_id'";
							$rs2 = mysql_query($rech2)or die(mysql_error());
							if (mysql_num_rows($rs2) > 0)
							{
								if ($row2 = mysql_fetch_array($rs2))
								{
									extract($row2);
									$tab_enr["codecoloc"] = $codecoloc;
									$tab_enr["codeart"] = $codeart;
									$tab_enr["idbarloc"] = $pdtlbl_idbarloc;
									$tab_enr["qte"] = $pdtlbl_qte;
									$tab_enr["pvht"] = $pdtlbl_pvht;
									$tab_enr["codetva"] = $pdtlbl_codetva;
									$tab_enr["caution"] = $pdtlbl_caution;
									$tab_enr["tvacaut"] = $pdtlbl_tvacaut;
									$tab_enr["avecass"] = $pdtlbl_avecass;
									$tab_enr["mtass"] = $pdtlbl_mtass;
									$tab_enr["codetvaass"] = $pdtlbl_codetvaass;
									$tab_enr["qconsi1"] = $pdtlbl_qconsi1;
									$tab_enr["pdtuconsi1"] = $pdtlbl_pdtuconsi1;
									$tab_enr["puconsi1"] = $pdtlbl_puconsi1;
									$tab_enr["qconsi2"] = $pdtlbl_qconsi2;
									$tab_enr["pdtuconsi2"] = $pdtlbl_pdtuconsi2;
									$tab_enr["puconsi2"] = $pdtlbl_puconsi2;
									$tab_enr["dd"] = formatedate($pdtl_datedeb);
									$tab_enr["hd"] = substr($pdtl_heuredeb,0,5);
									$tab_enr["df"] = formatedate($pdtl_datefin);
									$tab_enr["hf"] = substr($pdtl_heurefin,0,5);
								}
							}
							$_SESSION["pdtlbl"][]=$tab_enr;
							mysql_free_result($rs2);
							
							// Lecture du barême rattaché
							if ($pdtlbl_idbarloc>0)
							{
								$row2=lit_enr_barloc_id($pdtlbl_idbarloc,FALSE);
								if (is_array($row2))
									extract($row2);
								else
									$pbm_pdt=TRUE;
							}
							else
							{
								$barloc_codetva=$pdtlbl_codetva;
								$barloc_codepen="1";
							}
							// construction du tableau pour la pénalité
							// ... On prend les valeurs par défaut
							$tab_enr=array();
							$tab_enr["codecoloc"] = $codecoloc;
							$tab_enr["codeart"] = $codeart;
							$tab_enr["codepen"]="-1";
							$tab_enr["valeur"]=0;
							$tab_enr["tva"]=$barloc_codetva;
							$tab_enr["penposs"] = $barloc_codepen;
							// ...On vérifie s'il n'y a pas déjà une pénalité enregistrée
							$rech2 = "SELECT * FROM `" .TBPDTLPL. "` WHERE `pdtlpl_idpdtl` = '$pdtl_id'";
							$rs2 = mysql_query($rech2)or die(mysql_error());
							if (mysql_num_rows($rs2) > 0)
							{
								if ($row2 = mysql_fetch_array($rs2))
								{
									extract($row2);
									$tab_enr["codepen"] = $pdtlpl_codepen;
									$tab_enr["valeur"] = $pdtlpl_valeur;
									$tab_enr["codetva"] = $pdtlpl_codetva;
								}
							}
							$_SESSION["pdtlpl"][]=$tab_enr;
							mysql_free_result($rs2);

							// construction du tableau pour les consommables
							// ... On prend les valeurs par défaut
							$tab_enr=array();
							$tab_enr["idpdtl"] = $pdtl_id;
							$tab_enr["valeur"]=0;
							$tab_enr["tva"]=$barloc_codetva;
							// ...On vérifie s'il n'y a pas déjà un montant consommables enregistré
							$rech2 = "SELECT * FROM `" .TBPDTLCL. "` WHERE `pdtlcl_idpdtl` = '$pdtl_id'";
							$rs2 = mysql_query($rech2)or die(mysql_error());
							if (mysql_num_rows($rs2) > 0)
							{
								if ($row2 = mysql_fetch_array($rs2))
								{
									extract($row2);
									$tab_enr["valeur"] = $pdtlcl_valeur;
									$tab_enr["codetva"] = $pdtlcl_codetva;
								}
							}
							$_SESSION["pdtlcl"][]=$tab_enr;
							mysql_free_result($rs2);
						}
					}
					mysql_free_result($rs);
					mysql_close($conn);
	
					if ($td == "edit")
					{
						$row = lit_enr_pdt_in_coloc($codeart,$codecoloc);
						if (is_array($row))
							extract ($row);
						else
							$pbm_pdt=TRUE;
					}
			
					if ($td == "del")
					{
						$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
						mysql_select_db(DBNAME);
						$rech = "SELECT * FROM `" .TBPDTL. "` WHERE `pdtl_codepdtloc` = '$codeart' AND `pdtl_codecoloc` = '$codecoloc'";
						$rs = mysql_query($rech)or die(mysql_error());
						if (mysql_num_rows($rs) == 0)
							$pbm_pdt=TRUE;
						else
						{
							if ($row = mysql_fetch_array($rs))
								extract ($row);
							else
								$pbm_pdt=TRUE;
						}
						mysql_free_result($rs);
						mysql_close($conn);
					}
				}
			}
			else
				$pbm_pdt=TRUE;
		}			
		else
			$pbm_pdt=TRUE;
	}			
	else
		$pbm_pdt=TRUE;
	
	switch ($td)
	{
		case "add" :
			$titre = "RESERVATION ARTICLE LOCATION";
			$okadd=FALSE;
			break;
		case "edit" :
			$titre = "EDITION RESA ARTICLE LOCATION ";
			break;
		case "del" :
			$titre = "SUPPRESSION RESA ARTICLE LOCATION";
			break;
		case "dep" :
			$titre = "LIVRAISON ARTICLE RESERVE";
			$pdtl_didx1=$pdtloc_idxcons1;
			$pdtl_didx2=$pdtloc_idxcons2;
			break;
		case "ret" :
			$titre = "RETOUR ARTICLE LOUE";
			$pdtl_ridx1=$pdtl_didx1;
			$pdtl_ridx2=$pdtl_didx2;
			break;
		case "view" :
			$titre = "VISUALISATION ARTICLE LOCATION ";
			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; ?> : Article 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>

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

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

<?PHP if ($td=="add") { ?>
<script language="javascript">
<!--
var tab1_champ=new Array(
	"nom:codecrea; format:liste ; req:Y ; txt:Nom de la personne réservant le matériel ; vmn:1 ; stok:frmok ; stbad:frmbad");
//-->
</script>
<?PHP }
if ($td=="dep") { ?>
<script language="javascript">
<!--
var tab1_champ=new Array(
	"nom:codedep; format:liste ; req:Y ; txt:Nom de la personne remettant le matériel ; vmn:1 ; stok:frmok ; stbad:frmbad",
	"nom:prispar; format:txt ; req:Y ; txt:Nom de la personne prenant le matériel ; stok:frmok ; stbad:frmbad",
	"nom:datedepf; format:date ; masque:<?PHP echo $datemsql; ?> ;req:Y ; txt:Date de remise du produit ; vmn:<?PHP echo $dd; ?> ; vmx:<?PHP echo $df; ?> ; stok:frmok ; stbad:frmbad",
<?PHP if (trim($udesc1)<>"") { ?>
	"nom:didx1; format:unsigned ; req:Y ; txt:Index <?PHP echo $udesc1; ?> ; vmn:<?PHP echo $pdtloc_idxcons1; ?> ; stok:frmok ; stbad:frmbad",
<?PHP } if (trim($udesc2)<>"") { ?>
	"nom:didx2; format:unsigned ; req:Y ; txt:Index <?PHP echo $udesc2; ?> ; vmn:<?PHP echo $pdtloc_idxcons2; ?> ; stok:frmok ; stbad:frmbad",
<?PHP } ?>
	"nom:coderegc ; format:liste ; req:Y ; txt:Mode règlement caution ; vmn:1 ; stok:frmok ; stbad:frmbad",
	"nom:noted; format:txt ; req:N ; txt:Commentaire d&eacute;part; stok:frmok ; stbad:frmbad");
//-->
</script>
<?PHP }
if ($td=="ret") { ?>
<script language="javascript">
<!--
var tab1_champ=new Array(
	"nom:coderet; format:liste ; req:Y ; txt:Nom de la personne récupérant le matériel ; vmn:1 ; stok:frmok ; stbad:frmbad",
	"nom:retpar; format:txt ; req:Y ; txt:Nom de la personne rendant le matériel ; stok:frmok ; stbad:frmbad",
	"nom:dateretf; format:date ; masque:<?PHP echo $datemsql; ?> ; req:Y ; txt:Date de retour du produit ; vmn:<?PHP echo formatedate($pdtl_datedeb); ?> ; stok:frmok ; stbad:frmbad",
<?PHP if (trim($udesc1)<>"") { ?>
	"nom:ridx1; format:unsigned ; req:Y ; txt:Index <?PHP echo $udesc1; ?> ; vmn:<?PHP echo $pdtl_didx1; ?> ; stok:frmok ; stbad:frmbad",
<?PHP } if (trim($udesc2)<>"") { ?>
	"nom:ridx2; format:unsigned ; req:Y ; txt:Index <?PHP echo $udesc2; ?> ; vmn:<?PHP echo $pdtl_didx2; ?> ; stok:frmok ; stbad:frmbad",
<?PHP } ?>
	"nom:noter; format:txt ; req:N ; txt:Commentaire retour; stok:frmok ; stbad:frmbad");
//-->
</script>
<?PHP } ?>
<script language="javascript">
<!--
var txtval = '<?PHP if ($okadd==TRUE) echo ''; else echo $but_choixprea2; ?>';
//-->
</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>

<?PHP cre_js_pdtlbl($td,$_SESSION["pdtlbl"],$_SESSION["pdtlpl"],$_SESSION["pdtlcl"],""); ?>

</head>

<body onLoad="putvalue_in_id('enr',txtval,false);tbpbarloc();metFocus();">

<?PHP
if ($pbm_pdt==FALSE)
{
?>
<p align="center"> <span class="titrepage"><?PHP echo $titre ?></span></p>
<p align="center"><span class="titre_gras">Pour la location : <?php echo $pdtl_codecoloc; ?> </span></p>

<form name="pdtl_maj" method="post" action="pdtl_enr.php" <?PHP if (($td=="add") OR ($td=="dep") OR ($td=="ret")) { ?> onSubmit="javascript:; return (VForm(this,tab1_champ,'','<?PHP echo $_SESSION["lng"]; ?>'));" <?PHP } ?>>
	<input name="titre" type="hidden" id="titre" value="<?PHP echo $titre; ?>">
    <input name="td" type="hidden" id="td" value="<?PHP echo $td; ?>">
    <input name="codecoloc" type="hidden" id="codecoloc" value="<?PHP echo $pdtl_codecoloc; ?>">
    <input name="nbl" type="hidden" id="nbl" value="<?PHP echo $barloc_id; ?>">
    <input name="codepen" type="hidden" id="codepen" value="<?PHP echo $barloc_codepen; ?>">
  <table width="100%"  border="0">
	<tr>
		<td width="250" class="rubfrm" id="f_codecrea" align="right">R&eacute;serv&eacute; par </td>
		<td>
	<?PHP 
	$aff_lst==FALSE;
	if ($td<>"add")
		$tab_pn=prenom_nom_compte($pdtl_codecrea,TRUE);
	else
	{
		if ($_SESSION["niv_log"]==3)
			$tab_pn=prenom_nom_compte($_SESSION["code_log"],TRUE);
		else
			$aff_lst=TRUE;
	}
	if ($aff_lst==FALSE)
		echo '<input name="codecrea" type="text" id="codecrea" value="'.$tab_pn["prenom"].' '.$tab_pn["nom"].' ('.$tab_niv_full[$tab_pn["level"]].')" size="100" readonly="1">';
	else
	{
		echo '<select name="codecrea" id="codecrea">';
		echo '<option value="">'.$sel_lst_tec.'</option>';
		$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
		mysql_select_db(DBNAME);
		$rech = "SELECT * FROM ".TBTEC." WHERE `tec_codeage` = '$coloc_codeage' AND `tec_out` = '0' ORDER BY tec_nom";
		$rs = mysql_query($rech) or die(mysql_error());

		if (mysql_num_rows($rs) <> 0)
		{
			while ($resultat = mysql_fetch_array($rs)) 
			{
				extract($resultat);
				echo '<option value="'.$tec_code.'"';
				if ($pdtl_codecrea == $tec_code)
					 echo ' selected';
				echo '>'.$tec_nom.' '.$tec_prenom.'</option>';
			}
		}
		echo '</select>';
		mysql_free_result($rs);
		mysql_close($conn);
	} ?>
		</td>
	</tr>
    <tr>
      <td width="160" class="rubfrm" id="f_code" align="right"><?PHP echo $txt_chp_code; ?></td>
      <td >
		  <input name="code" type="text" id="code" value="<?PHP echo $pdtl_codepdtloc ?>" size="50" readonly="1">
	  </td> 
    </tr>
    <tr>
      <td width="160" 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($pdtloc_des); ?>" size="50" readonly="1">
	  </td>
    </tr>
    <tr>
      <td width="160" class="rubfrm" id="f_per" align="right">P&eacute;riode pr&eacute;vue</td>
      <td>
	  	Du
	  	<input name="dd" type="text" id="dd" value="<?PHP echo $dd; ?>" size="10" readonly="1">
	  	<input name="hd" type="text" id="hd" value="<?PHP echo $hd; ?>" size="5" readonly="1">
		 Au 
	  	<input name="df" type="text" id="df" value="<?PHP echo $df; ?>" size="10" readonly="1">
	  	<input name="hf" type="text" id="hf" value="<?PHP echo $hf; ?>" size="5" readonly="1">
	  </td>
    </tr>
	<?PHP if (($_SESSION["niv_log"]==3) OR ($_SESSION["niv_log"]==4) OR ($_SESSION["niv_log"]==5) OR ($_SESSION["niv_log"]==9))
	{ ?>
    <tr>
      <td width="160" class="rubfrm" id="f_note" align="right">Notes internes</td>
      <td>
		<textarea name="note" id="note" rows="4" readonly="readonly"><?PHP echo htmlspecialchars($pdtloc_note); ?></textarea>
	  </td>
    </tr>
	<?PHP 
	}
	
// Affiché uniquement si en mode départ ou retour, ou visualisation
if (($td=="dep") OR ($td=="ret") OR ($td=="view")) { ?>
	<tr>
		<td align="center" colspan="2"><hr noshade width="100%" size="1" color="limegreen"></td>
	</tr>
	<tr>
		<td width="250" class="rubfrm" id="f_codedep" align="right">Remis par</td>
		<td>
	<?PHP 
	$aff_lst==FALSE;
	if ($td<>"dep")
		$tab_pn=prenom_nom_compte($pdtl_codedep,TRUE);
	else
	{
		if ($_SESSION["niv_log"]==3)
			$tab_pn=prenom_nom_compte($_SESSION["code_log"],TRUE);
		else
			$aff_lst=TRUE;
	}
	if ($aff_lst==FALSE)
	{
		if (trim($tab_pn["nom"])<>"")
			echo '<input name="codedep" type="text" id="codedep" value="'.$tab_pn["prenom"].' '.$tab_pn["nom"].' ('.$tab_niv_full[$tab_pn["level"]].')" size="100" readonly="1">';
		else
			echo '<input name="codedep" type="text" id="codedep" value="" size="100" readonly="1">';
	}
	else
	{
		echo '<select name="codedep" id="codedep">';
		echo '<option value="">'.$sel_lst_tec.'</option>';
		$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
		mysql_select_db(DBNAME);
		$rech = "SELECT * FROM ".TBTEC." WHERE `tec_codeage` = '$coloc_codeage' ORDER BY tec_nom";
		$rs = mysql_query($rech) or die(mysql_error());

		if (mysql_num_rows($rs) <> 0)
		{
			while ($resultat = mysql_fetch_array($rs)) 
			{
				extract($resultat);
				echo '<option value="'.$tec_code.'"';
				if ($pdtl_codedep == $tec_code)
					 echo ' selected';
				echo '>'.$tec_nom.' '.$tec_prenom.'</option>';
			}
		}
		mysql_free_result($rs);
		mysql_close($conn);
		echo '</select>';
		echo '<img src="../img/oblig.png" align="absmiddle" alt="'.$alt_chp_oblig.'">';
	} ?>
	</td>
	</tr>
	<tr>
	<td width="250" class="rubfrm" id="f_prispar" align="right">Remis à</td>
	<td>
		<input name="prispar" type="text" id="prispar" value ="<?PHP echo htmlspecialchars($pdtl_prispar); ?>" size="70" maxlength="70" <?PHP if ($td<>"dep") echo 'readonly="readonly"';?>>
		<?PHP if (($td<>"view") AND ($td<>"del")) { ?>
		<img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">
		<?PHP } ?>
	</td>
	</tr>
	<tr>
	<td width="250" class="rubfrm" id="f_datedep" align="right">Date d&eacute;part</td>
	<td>
		<input name="datedepf" type="text" id="datedepf" value="<?php echo $pdtl_datedepf; ?>" size="10" readonly="1">
		<?PHP
		if (($td<>"view") AND ($td<>"del"))
		{
		?>
		<img src="../img/calendar.png" align="absmiddle" id="f_img_datedep" title="<?PHP echo $alt_chxdate; ?>">
		 <select name="hdep" id="hdep">
		<?PHP
		// Création de la liste des heures
		for ($i=300; $i<86400 ;$i+=300)
		{
			$heure=heure_to_hhmm(sec_heure($i));
			echo '<option value="'.$heure.'" ';
			if (substr($pdtl_heuredep,0,5) == $heure)
				echo ' selected';
			echo '>'.$heure.'</option>';
		}
		?>
		</select>
		<img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">
		<br /><span class="annot_petit_it"> (La date doit &ecirc;tre comprise dans la p&eacute;riode pr&eacute;vue)</span>
		<?PHP
		}
		else
		{
		?>
		<input name="hdep" type="text" id="hdep" value="<?php echo heure_to_hhmm($pdtl_heuredep); ?>" size="5" readonly="1">
		<?PHP
		}
		?>
	</td>
	</tr>
	<?PHP if ((trim($udesc1)<>"") OR (trim($udesc2)<>"")) { ?>
	<tr>
	<td width="250" class="rubfrm" id="f_didx" align="right">Indexes d&eacute;part</td>
	<td>
		<?PHP if (trim($udesc1)<>"") { ?>
		<span class="annot_gras_it"><?PHP echo $udesc1; ?></span> : <input name="didx1" type="text" id="didx1" style="text-align:right" value="<?php echo $pdtl_didx1; ?>" size="10" <?PHP if ($td<>"dep") echo 'readonly="readonly"';?>>
		<img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">
		<br />
		<?PHP } if (trim($udesc2)<>"") { ?>
		<span class="annot_gras_it"><?PHP echo $udesc2; ?></span> : <input name="didx2" type="text" id="didx2" style="text-align:right" value="<?php echo $pdtl_didx2; ?>" size="10" <?PHP if ($td<>"dep") echo 'readonly="readonly"';?>>
		<img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">
		<?PHP } ?>
		<br /><span class="annot_petit_it"> (Anciens indexes repris. Les nouveaux doivent &ecirc;tre sup&eacute;rieurs ou égaux)</span>
	</td>
	</tr>
	<?PHP } ?>
	<tr>
	<td width="250" class="rubfrm" id="f_coderegc" align="right">Mode r&egrave;glement caution</td>
	<td>
	<?PHP 
	if ($td=="dep")
	{
		echo '<select name="coderegc" id="coderegc">';
		echo '<option>-- Choisissez un mode de règlement --</option>';
		
		// Création de la liste des Règlements
		$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
		mysql_select_db(DBNAME);
		$rs = mysql_query("SELECT * FROM ".TBREG." ORDER BY reg_desc");
		while ($resultat = mysql_fetch_array($rs)) 
		{
			extract($resultat);
			echo '<option value="'.$reg_code.'"';
			if ($pdtl_coderegc == $reg_code)
				echo ' selected';
			echo '>'.$reg_desc.'</option>';
		}
		mysql_free_result($rs);
		mysql_close($conn);
	  	echo '</select>';
		echo '<img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">';
	}
	else
	{
		$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
		mysql_select_db(DBNAME);
		$rech = "SELECT * FROM ".TBREG." WHERE reg_code='".$pdtl_coderegc."'";
		$rs = mysql_query($rech) or die(mysql_error());
		if ($row = mysql_fetch_assoc($rs))
			extract($row);
		mysql_free_result($rs);
		mysql_close($conn);
		echo '<input name="coderegc" type="text" id="coderegc" value="'.$reg_desc.'" size="50" readonly="readonly">';
	}
	$pvht=$pdtlbl_caution;
	$tothtcaut=round($pvht*100)/100;
	$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
	mysql_select_db(DBNAME);
	$rech = "SELECT * FROM ".TBTVA." WHERE tva_code='".$pdtlbl_tvacaut."'";
	$rs = mysql_query($rech) or die(mysql_error());
	if ($row = mysql_fetch_assoc($rs))
		extract($row);
	mysql_free_result($rs);
	mysql_close($conn);
	$txtva=$tva_tx/100;
	$totttccaut=round(($tothtcaut*(1+$txtva))*100)/100;
	$txt="(Montant : ".$totttccaut." ".$lang['symbole_monnaie_txt']." TTC)";
	echo '<br />';
	echo "<span class=\"annot_petit_it\">";
	echo $txt;
	echo "</span>";
	?>
	</td>
	</tr>
    <tr>
      <td width="160" class="rubfrm" id="f_texte" align="right">Commentaire d&eacute;part</td>
      <td>
	  	<textarea name="noted" id="noted" rows="4" <?PHP if ($td<>"dep") echo 'readonly="readonly"';?>><?PHP echo htmlspecialchars($pdtl_noted); ?></textarea>
		<input name="noter" type="hidden" id="noter" value="" readonly="readonly">
	  </td>
    </tr>

	<?PHP
	// Mode retour ou visualisation
	if (($td=="ret") OR ($td=="view")) { ?>
	<tr>
	<td align="center" colspan="2"><hr noshade width="100%" size="1" color="limegreen"></td>
	</tr>
	<tr>
		<td width="250" class="rubfrm" id="f_coderet" align="right">R&eacute;ceptionn&eacute; par </td>
		<td>
	<?PHP 
	$aff_lst==FALSE;
	if ($td<>"ret")
		$tab_pn=prenom_nom_compte($pdtl_coderet,TRUE);
	else
	{
		if ($_SESSION["niv_log"]==3)
			$tab_pn=prenom_nom_compte($_SESSION["code_log"],TRUE);
		else
			$aff_lst=TRUE;
	}
	if ($aff_lst==FALSE)
	{
		if (trim($tab_pn["nom"])<>"")
			echo '<input name="coderet" type="text" id="coderet" value="'.$tab_pn["prenom"].' '.$tab_pn["nom"].' ('.$tab_niv_full[$tab_pn["level"]].')" size="100" readonly="1">';
		else
			echo '<input name="coderet" type="text" id="coderet" value="" size="100" readonly="1">';
	}
	else
	{
		echo '<select name="coderet" id="coderet">';
		echo '<option value="">'.$sel_lst_tec.'</option>';
		$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
		mysql_select_db(DBNAME);
		$rech = "SELECT * FROM ".TBTEC." WHERE `tec_codeage` = '$coloc_codeage' ORDER BY tec_nom";
		$rs = mysql_query($rech) or die(mysql_error());

		if (mysql_num_rows($rs) <> 0)
		{
			while ($resultat = mysql_fetch_array($rs)) 
			{
				extract($resultat);
				echo '<option value="'.$tec_code.'"';
				if ($pdtl_coderet == $tec_code)
					 echo ' selected';
				echo '>'.$tec_nom.' '.$tec_prenom.'</option>';
			}
		}
		mysql_free_result($rs);
		mysql_close($conn);
		echo '</select>';
		echo '<img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">';
	} ?>
		</td>
	</tr>
	<tr>
	<td width="250" class="rubfrm" id="f_retpar" align="right">Rendu par</td>
	<td>
		<input name="retpar" type="text" id="retpar" value ="<?php echo htmlspecialchars($pdtl_retpar); ?>" size="70" maxlength="70" <?PHP if ($td<>"ret") echo 'readonly="readonly"';?>>
		<?PHP if (($td<>"view") AND ($td<>"del")) { ?>
		<img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">
		<?PHP } ?>
	</td>
	</tr>
	<tr>
	<td width="250" class="rubfrm" id="f_dateret" align="right">Date retour</td>
	<td>
		<input name="dateretf" type="text" id="dateretf" value="<?php echo $pdtl_dateretf; ?>" size="10" readonly="1" onChange="verif_dateret('0',this.value,'<?PHP echo $datemsql; ?>')">
		<?PHP
		if (($td<>"view") AND ($td<>"del"))
		{
		?>
		<img src="../img/calendar.png" align="absmiddle" id="f_img_dateret" title="<?PHP echo $alt_chxdate; ?>">
		<select name="hret" id="hret" onChange="verif_dateret('0',document.pdtl_maj.dateretf.value,'<?PHP echo $datemsql; ?>')"
		<?PHP
			// Création de la liste des heures
			for ($i=300; $i<86400 ;$i+=300)
			{
				$heure=heure_to_hhmm(sec_heure($i));
				echo '<option value="'.$heure.'" ';
				if (substr($pdtl_heureret,0,5) == $heure)
					echo ' selected';
				echo '>'.$heure.'</option>';
			}
			echo '</select>';
		?>
		<img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">
		 <span class="annot_petit_it"> (La date doit &ecirc;tre au moins la date de d&eacute;part)</span>
		<span id="addpen" style="visibility:hidden">
		<input name="bpen" type="button" id="bpen" onClick="fen_pen_rloc('ret');" class="bton_std" value="<?PHP echo $but_pen; ?>">
		</span>
		<?PHP
		}
		else
		{
		?>
		<input name="hret" type="text" id="hret" value="<?php echo substr($pdtl_heureret,0,5); ?>" size="5" readonly="1">
		<?PHP
		}
		?>
	</td>
	</tr>
	<?PHP if ((trim($udesc1)<>"") OR (trim($udesc2)<>"")) { ?>
	<tr>
	<td width="250" class="rubfrm" id="f_didx" align="right">Indexes retour</td>
	<td>
		<?PHP if (trim($udesc1)<>"") { ?>
		<span class="annot_gras_it"><?PHP echo $udesc1; ?></span> : <input name="ridx1" type="text" id="ridx1" style="text-align:right" value="<?php echo $pdtl_ridx1; ?>" size="10" onChange="verif_indexes('0')" <?PHP if ($td<>"ret") echo 'readonly="readonly"';?>>
		<input name="qci1" type="hidden" id="qci1" value="<?php echo $barloc_qconsi1; ?>" >
		<img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">
		<br />
		<?PHP } if (trim($udesc2)<>"") { ?>
		<span class="annot_gras_it"><?PHP echo $udesc2; ?></span> : <input name="ridx2" type="text" id="ridx2" style="text-align:right" value="<?php echo $pdtl_ridx2; ?>" size="10" onChange="verif_indexes('0')" <?PHP if ($td<>"ret") echo 'readonly="readonly"';?>>
		<input name="qci2" type="hidden" id="qci2" value="<?php echo $barloc_qconsi2; ?>" >
		<img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">
		<?PHP } ?>
		<span id="addidx" style="visibility:hidden">
		<input name="bidx" type="button" id="bidx" onClick="fen_cons_rloc('ret');" class="bton_std" value="<?PHP echo $but_idx; ?>">
		</span>
		<br /><span class="annot_petit_it"> (Indexes de d&eacute;part repris. Les nouveaux doivent &ecirc;tre sup&eacute;rieurs ou &eacute;gaux)</span>
	</td>
	</tr>
	<?PHP } ?>
	<tr>
	<td width="250" class="rubfrm" id="f_rcaut" align="right">Caution rendue ?</td>
	<td>
	<?PHP
	if ($td=="ret")
	{
		echo "<select name=\"rcaut\" size=\"1\" id=\"rcaut\">";
		foreach ($non_oui as $key=>$value)
		{
			echo '<option value="'.$key.'"'; 
			if ($pdtl_rcaut == $key)
				echo ' selected';
			echo '>';
			echo $value."</option>";
		}
		echo '</select>';
		echo '<img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">';
	}
	else
	{
		echo '<input name="rcaut" type="hidden" id="rcaut" value="'.$pdtl_rcaut.'" readonly="readonly">';
		echo '<input name="nrcaut" type="text" id="nrcaut" value="'.$non_oui[$pdtl_rcaut].'" size="3" readonly="readonly">';
	}
	?>
	</td>
	</tr>
	<tr>
	<td width="250" class="rubfrm" id="f_reloc" align="right">Remise en location ?</td>
	<td>
	<?PHP
	if ($td=="ret")
	{
		echo "<select name=\"reloc\" size=\"1\" id=\"reloc\">";
		foreach ($non_oui as $key=>$value)
		{
			echo '<option value="'.$key.'"'; 
			if ($pdtl_reloc == $key)
				echo ' selected';
			echo '>';
			echo $value."</option>";
		}
		echo '</select>';
		echo '<img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo $alt_chp_oblig; ?>">';
	}
	else
	{
		echo '<input name="reloc" type="hidden" id="reloc" value="'.$pdtl_reloc.'" readonly="readonly">';
		echo '<input name="nreloc" type="text" id="nreloc" value="'.$non_oui[$pdtl_reloc].'" size="3" readonly="readonly">';
	}
	?>
	</td>
	</tr>
    <tr>
      <td width="160" class="rubfrm" id="f_texte" align="right">Commentaire retour</td>
      <td>
	  	<textarea name="noter" id="noter" rows="4" <?PHP if ($td<>"ret") echo 'readonly="readonly"';?>><?PHP echo htmlspecialchars($pdtl_noter); ?></textarea>
	  </td>
    </tr>
<?PHP } // Fin mode retour ou visualisation
} // Fin affiché uniquement si en mode départ ou retour, ou visualisation
?>
	</table>

	<!-- Zone de choix des barêmes -->
	<table width="100%"  border="0">
	<tr>
		<td class="rubfrm" colspan="2" align="center">BAREMES</td>
	</tr>
	</table>
	<div id="detbarloc">
	</div>
	
	<div id="addbarloc">
	<!-- Lien d'ajout de barêmes -->
	<?PHP
	if (($td == "edit") OR ($td=="add"))
	{
		$urlchoixbar = "pdtlbl_maj.php?td=add&cl=".$codecoloc."&ca=".$codeart."&dd=".$dd."&hd=".$hd."&df=".$df."&hf=".$hf;
	?>
		<a href="javascript:;" onclick="fensaisie2('<?PHP echo $urlchoixbar; ?>',800,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="fensaisie2('<?PHP echo $urlchoixbar; ?>',800,500,'status=no,scrollbars=yes,menubar=no,statusbar=no,location=no,locationbar=no');")> Choisir un bar&ecirc;me</a>
		<br>
	<?PHP
	}
	?>
	</div>
  <p align="center">
    <?PHP if (($td == "add") OR ($td=="edit") OR ($td=="dep") OR ($td=="ret")) { ?>
    <input name="RAZ" type="button" class="bton_std" id="RAZ" value="<?PHP echo $but_reinit; ?>" onclick="javascript:; self.location=self.location;">
    <input name="enr" type="submit" <?PHP if (count($_SESSION["pdtlbl"])==0) echo 'class="bton_fmarr_dis"'; else echo 'class="bton_std"'; ?> id="enr" value="<?PHP echo $but_add; ?>" <?PHP if (count($_SESSION["pdtlbl"])==0) echo 'disabled="disabled"'; ?>>
    <?PHP } if ($td == "del") { ?>
    <input name="del" type="submit" class="bton_std" id="del" value="<?PHP echo $but_del; ?>">
    <?PHP } ?>
    <input name="annul" type="button" class="bton_std" id="annul" value="<?PHP if (($td == "add") OR ($td=="edit") OR ($td=="del") OR ($td=="dep") OR ($td=="ret")) echo $but_cancel; else echo $but_quit; ?>" onclick="javascript:; self.close('fscomp');">
  </p>
</form>
<?PHP if (($td=="dep") OR ($td=="ret")) { ?>
<script type="text/javascript">
<!--
<?PHP if ($td=="dep") { ?>
Calendar.setup({
	inputField     :    "datedepf",     // id of the input field
	ifFormat       :    "<?PHP echo $datefmtc; ?>",      // format of the input field
	button         :    "f_img_datedep",  // trigger for the calendar (button ID)
	align          :    "Br",           // alignment (defaults to "Bl")
	electric	   :	false,
	singleClick    :    true
});
<?PHP } 
if ($td=="ret") { ?>
Calendar.setup({
	inputField     :    "dateretf",     // id of the input field
	ifFormat       :    "<?PHP echo $datefmtc; ?>",      // format of the input field
	button         :    "f_img_dateret",  // trigger for the calendar (button ID)
	align          :    "Br",           // alignment (defaults to "Bl")
	electric	   :	false,
	singleClick    :    true
});
<?PHP } ?>
//-->
</script>
<?PHP
}
}
else
{
?>
	<script type="text/javascript">
	<!--
	self.close('fscomp');
	//-->
	</script>
<?PHP
}
?>
</body>
</html>
