<?php
/****************************************************************************************
 * SMI (Services Maintenance Interventions) est une gestion libre de maintenance et de SAV
 *
 * Version 1.0.2
 *
 * Copyright (C) 2006-2015  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://smi.no-ip.org
 ****************************************************************************************/


// 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/config.inc.php");
include_once("../inc/fic_droits.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");
include_once("../classes/ezSQL/shared/ez_sql_core.php");
include_once("../classes/ezSQL/mysqli/ez_sql_mysqli.php");
include_once("../inc/func_sql.inc.php");
Archivelog(@$_SESSION["code_log"]);
// On initalise les tableaux des barèmes de location, des pénalités, des consommables
$_SESSION["pdtlbl"] = [];
$_SESSION["pdtlpl"] = [];
$_SESSION["pdtlcl"] = [];

// Variables Formulaire
fix_magic_quotes();
$_GET = clean_str($_GET);

$td = @$_GET['td'];
$codecoloc = @$_GET['cl'];
$codeart = @$_GET['ca'];
if (isset($_GET["dd"]))
    $dd = @$_GET["dd"];
else
    $dd = "";
if (isset($_GET["hd"]))
    $hd = @$_GET["hd"];
else
    $hd = "";
if (isset($_GET["df"]))
    $df = @$_GET["df"];
else
    $df = "";
if (isset($_GET["hf"]))
    $hf = @$_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 ((chkdate($dd) == FALSE) OR (chkdate($df) == FALSE))
    $pbm_pdt = TRUE;
if ((heurecorrecte($hd . ':00') == FALSE) OR (heurecorrecte($hf . ':00') == FALSE))
    $pbm_pdt = TRUE;

// Récupération des paramètres de SMI
$db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
$rech = "SELECT * FROM `" . TBPPRM . "`";
$row = $db->get_row($rech, ARRAY_A);
if ($row)
    extract($row);
$db->disconnect();

if ($pbm_pdt == FALSE) {
    if ($codecoloc <> "") {
        $row = lit_enr_coloc($codecoloc);
        if (is_array($row)) {
            $row = encode_str($row);
            extract($row);

            // Contrôle si contrat soldé (si tous les produits sont revenus, on force la clôture)
            if (datetolocal($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 (datetolocal($coloc_dateclos) <> "")
                $td = "view";

            // Récupération des données de la fiche article
            $row = lit_enr_pdtloc($codeart);
            if (is_array($row)) {
                $row = encode_str($row);
                extract($row);

                // Récupération des indexes
                $udesc1 = "";
                $udesc2 = "";
                $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
                $rech = "SELECT * FROM `" . TBPDTU . "` WHERE `pdtu_code`= '" . $pdtloc_pdtucons1 . "'";
                $row = $db->get_row($rech, ARRAY_A);
                if ($row) {
                    $row = encode_str($row);
                    extract($row);
                    $udesc1 = $pdtu_desc;
                }
                $rech = "SELECT * FROM `" . TBPDTU . "` WHERE `pdtu_code`= '" . $pdtloc_pdtucons2 . "'";
                $row = $db->get_row($rech, ARRAY_A);
                if ($row) {
                    $row = encode_str($row);
                    extract($row);
                    $udesc2 = $pdtu_desc;
                }
                $db->disconnect();

                if ($td == "add") {
                    $pdtl_codecoloc = $codecoloc;
                    $pdtl_codepdtloc = $pdtloc_code;
                    $pdtl_datedeb = $dd;
                    $pdtl_datefin = $df;
                    $pdtl_noted = "";
                    $pdtl_noter = "";
                } else {
                    // Récupération de la devis du produit
                    $codeadev = give_dev_codea_defaut_pdtloc($codeart, $_SESSION["lng"], TRUE);

                    $_SESSION["pdtlbl"] = [];
                    // Construction du tableau des barèmes
                    $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
                    // Récupération ID
                    $rech = "SELECT * FROM `" . TBPDTL . "` WHERE `pdtl_codepdtloc` = '$codeart' AND `pdtl_codecoloc` = '$codecoloc'";
                    $row = $db->get_row($rech, ARRAY_A);
                    if ($row) {
                        $row = encode_str($row);
                        extract($row);

                        $pdtl_datedepf = datetolocal($pdtl_datedep);
                        $pdtl_dateretf = datetolocal($pdtl_dateret);

                        // construction du tableau pour le barème location
                        $tab_enr = [];
                        $rech2 = "SELECT * FROM `" . TBPDTLBL . "` WHERE `pdtlbl_idpdtl` = '$pdtl_id'";
                        $row2 = $db->get_row($rech2, ARRAY_A);
                        if ($row2) {
                            $row2 = encode_str($row2);
                            extract($row2);
                            $tab_enr["id"] = $pdtlbl_id;
                            $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"] = datetolocal($pdtl_datedeb);
                            $tab_enr["hd"] = substr($pdtl_heuredeb, 0, 5);
                            $tab_enr["df"] = datetolocal($pdtl_datefin);
                            $tab_enr["hf"] = substr($pdtl_heurefin, 0, 5);
                        }
                        $_SESSION["pdtlbl"][] = $tab_enr;

                        // Lecture du barème rattaché
                        if ($pdtlbl_idbarloc > 0) {
                            $row2 = lit_enr_barloc_id($pdtlbl_idbarloc, FALSE);
                            if (is_array($row2)) {
                                $row2 = encode_str($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 = [];
                        $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'";
                        $row2 = $db->get_row($rech2, ARRAY_A);
                        if ($row2) {
                            extract($row2);
                            $tab_enr["id"] = $pdtlpl_id;
                            $tab_enr["codepen"] = $pdtlpl_codepen;
                            $tab_enr["valeur"] = $pdtlpl_valeur;
                            $tab_enr["codetva"] = $pdtlpl_codetva;
                        }
                        $_SESSION["pdtlpl"][] = $tab_enr;

                        // construction du tableau pour les consommables
                        // ... On prend les valeurs par défaut
                        $tab_enr = [];
                        $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'";
                        $row2 = $db->get_row($rech2, ARRAy_A);
                        if ($row2) {
                            $row2 = encode_str($row2);
                            extract($row2);
                            $tab_enr["valeur"] = $pdtlcl_valeur;
                            $tab_enr["codetva"] = $pdtlcl_codetva;
                        }
                        $_SESSION["pdtlcl"][] = $tab_enr;
                    }
                    $db->disconnect();

                    if ($td == "edit") {
                        $row = lit_enr_pdt_in_coloc($codeart, $codecoloc);
                        if (is_array($row)) {
                            $row = encode_str($row);
                            extract($row);
                        } else
                            $pbm_pdt = TRUE;
                    }

                    if ($td == "del") {
                        $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
                        $rech = "SELECT COUNT(*) FROM `" . TBPDTL . "` WHERE `pdtl_codepdtloc` = '$codeart' AND `pdtl_codecoloc` = '$codecoloc'";
                        $row = $db->get_row($rech, ARRAY_A);
                        if ($row) {
                            $row = encode_str($row);
                            extract($row);
                        } else
                            $pbm_pdt = TRUE;
                        $db->disconnect();
                    }
                }
            } 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=UTF-8">
    <title>SMI - <?PHP echo _("ESPACE PRIVE"); ?> : <?PHP echo _("Article Location"); ?></title>

    <?PHP include_once("../inc/header.inc.php"); ?>

    <script language="javascript">
    <!--
    var tab1_champ = [
        <?PHP
        switch ($td)
        {
            case "add" :
                echo '"nom:codecrea; format:liste ; req:Y ; txt:'._("Nom de la personne réservant le matériel").' ; vmn:1 ; stok:frmok ; stbad:frmbad"';
                break;
            case "dep" :
                echo '"nom:codedep; format:liste ; req:Y ; txt:'._("Nom de la personne remettant le matériel").' ; vmn:1 ; stok:frmok ; stbad:frmbad",';
                echo '"nom:prispar; format:txt ; req:Y ; txt:'. _("Nom de la personne prenant le matériel").' ; stok:frmok ; stbad:frmbad",';
                echo '"nom:datedepf; format:date ; masque:'.$_SESSION['date_fmtfull'].' ;req:Y ; txt:'._("Date de remise du produit").' ; vmn:'.$dd.' ; vmx:'.$df.' ; stok:frmok ; stbad:frmbad",';
                if (trim($udesc1)<>"")
                    echo '"nom:didx1; format:unsigned ; req:Y ; txt:'._("Index") . ' ' .$udesc1.' ; vmn:'.$pdtloc_idxcons1.' ; stok:frmok ; stbad:frmbad",';
                if (trim($udesc2)<>"")
                    echo '"nom:didx2; format:unsigned ; req:Y ; txt:'._("Index") .' ' .$udesc2.' ; vmn:'.$pdtloc_idxcons2.' ; stok:frmok ; stbad:frmbad",';
                echo '"nom:coderegc ; format:liste ; req:Y ; txt:'. _("Mode règlement caution").' ; vmn:1 ; stok:frmok ; stbad:frmbad",';
                echo '"nom:noted; format:txt ; req:N ; txt:'. _("Commentaire départ").' ; stok:frmok ; stbad:frmbad"';
                break;
            case "ret" :
                echo '"nom:coderet; format:liste ; req:Y ; txt:'. _("Nom de la personne récupérant le matériel").' ; vmn:1 ; stok:frmok ; stbad:frmbad",';
                echo '"nom:retpar; format:txt ; req:Y ; txt:'._("Nom de la personne rendant le matériel").' ; stok:frmok ; stbad:frmbad",';
                echo '"nom:dateretf; format:date ; masque:'.$_SESSION['date_fmtfull'].' ; req:Y ; txt:'. _("Date de retour du produit").'  ; vmn:'.datetolocal($pdtl_datedeb).' ; stok:frmok ; stbad:frmbad",';
                if (trim($udesc1)<>"")
                    echo '"nom:ridx1; format:unsigned ; req:Y ; txt:'._("Index").' '.$udesc1.' ; vmn:'.$pdtl_didx1.' ; stok:frmok ; stbad:frmbad",';
                if (trim($udesc2)<>"")
                    echo '"nom:ridx2; format:unsigned ; req:Y ; txt:'._("Index").' '.$udesc2.' ; vmn:'.$pdtl_didx2.' ; stok:frmok ; stbad:frmbad",';
                echo '"nom:noter; format:txt ; req:N ; txt:'. _("Commentaire retour").' ; stok:frmok ; stbad:frmbad"';
                break;
        }
        ?>
    ];
    //-->
    </script>

    <script type="text/javascript">
        <!--
        <?PHP cre_html_pdtlbl('detbarloc', $td, $_SESSION["pdtlbl"], $_SESSION["pdtlpl"], $_SESSION["pdtlcl"], ''); ?>

        function init_datepicker() {
            $.datepicker.setDefaults({
                closeText: "<?PHP echo _("Fermer"); ?>",
                prevText: "<?PHP echo _("Précédent"); ?>",
                nextText: "<?PHP echo _("Suivant"); ?>",
                currentText: "<?PHP echo _("Aujourd'hui"); ?>",
                monthNames: ["<?PHP echo implode('","',$lng_tmoisf); ?>"],
                monthNamesShort: ["<?PHP echo implode('","',$lng_tmoism); ?>"],
                dayNames: ["<?PHP echo implode('","',$lng_tjourf); ?>"],
                dayNamesShort: ["<?PHP echo implode('","',$lng_tjourm); ?>"],
                dayNamesMin: ["<?PHP echo implode('","',$lng_tjours); ?>"],
                weekHeader: "<?PHP echo _("Sem."); ?>",
                dateFormat: "<?PHP echo $_SESSION['date_fmtshort']; ?>",
                firstDay: 1,
                isRTL: !1,
                changeMonth: true,
                changeYear: true,
                showMonthAfterYear: !1,
                yearSuffix: "",
                showButtonPanel: true,
                showOn: "both",
                buttonImageOnly: true,
                buttonImage: "../img/calendar.png",
                buttonText: "<?PHP echo _("Calendrier"); ?>"
            });

            $("#dateretf").datepicker({
                onSelect: function (datesel) {
                    $("#dateretf").blur();
                    chk_datedif(datesel, this.id, '<?PHP echo $_SESSION['date_fmtshort']; ?>', true, 'datedepf', '', '',false);
                    chk_dateret(this.id,'<?PHP echo $_SESSION['date_fmtshort']; ?>','hret','df-hf','addpen');
                }
            });
        }

        function init_all() {
            init_Body();
            init_datepicker();
            <?PHP
            switch ($td)
            {
                case "add" :
                    echo "init_fensaisie('chx_bar',900,500);";
                    echo "init_valid_form('enr','pdtl_maj','".$_SESSION['date_fmtshort']."',tab1_champ,'','');";
                    echo "readonly_id('codedep-prispar-datedepf-hdep-didx1-didx2-coderegc-noted-coderet-retpar-dateretf-hret-ridx1-ridx2-qci1-qci2-rcaut-reloc-noter',false);";
                    break;
                case "edit" :
                    echo "init_fensaisie('chx_bar',900,500);";
                    echo "init_valid_form('enr','pdtl_maj','".$_SESSION['date_fmtshort']."',tab1_champ,'','');";
                    echo "readonly_id('codedep-prispar-datedepf-hdep-didx1-didx2-coderegc-noted-coderet-retpar-dateretf-hret-ridx1-ridx2-qci1-qci2-rcaut-reloc-noter',false);";
                    break;
                case "dep" :
                    echo "init_valid_form('enr','pdtl_maj','".$_SESSION['date_fmtshort']."',tab1_champ,'','');";
                    echo '$( "#datedepf" ).datepicker();';
                    echo "readonly_id('coderet-retpar-dateretf-hret-ridx1-ridx2-qci1-qci2-rcaut-reloc-noter',false);";
                    break;
                case "ret" :
                    echo "init_valid_form('enr','pdtl_maj','".$_SESSION['date_fmtshort']."',tab1_champ,'','');";
                    echo "readonly_id('codedep-prispar-datedepf-hdep-didx1-didx2-coderegc-noted',false);";
                    echo "chk_dateret('dateretf','".$_SESSION['date_fmtshort']."','hret','df-hf','addpen');";
                    echo "init_chk_dateret('hret','dateretf','".$_SESSION['date_fmtshort']."','hret','df-hf','addpen');";
                    echo "chk_indexes('ridx1','didx1','didx2','ridx1','didx2','qci1','qci2','addidx');";
                    echo "init_chk_indexes('ridx1','didx1','didx2','ridx1','didx2','qci1','qci2','addidx',true);";
                    echo "init_fen_rloc('bpen','ret','bpen',500,520);";
                    break;
                default :
                    echo "readonly_all();";
                    break;
            }
            ?>
            tbpbarloc();
            add_func_click('annul', 'sclose','');
            $('#RAZ').click(function () {
                location.reload();
                Focus_first();
            });
        }

        $(document).ready(function () {
            init_all();
        });
        //-->
    </script>

</head>

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

    <form name="pdtl_maj" id="pdtl_maj" method="post" action="pdtl_enr.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; ?>">
    <input name="nbutton" type="hidden" id="nbutton" value="">
    <table width="100%" border="0">
    <tr>
        <td width="250" class="rubfrm" id="f_codecrea" align="right"><?PHP echo _("Réservé 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="">' . _("-- Faites votre choix --") . '</option>';
                $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
                $rech = "SELECT * FROM `" . TBTEC . "` WHERE `tec_codeage` = '$coloc_codeage' AND `tec_out` = '0' ORDER BY tec_nom";
                $rows = $db->get_results($rech, ARRAY_A);

                if ($rows) {
                    foreach ($rows as $row) {
                        extract($row);
                        echo '<option value="' . $tec_code . '"';
                        if ($pdtl_codecrea == $tec_code)
                            echo ' selected';
                        echo '>' . $tec_nom . ' ' . $tec_prenom . '</option>';
                    }
                }
                echo '</select>';
                $db->disconnect();
            }
            ?>
        </td>
    </tr>
    <tr>
        <td width="160" class="rubfrm" id="f_code" align="right"><?PHP echo _("Code"); ?></td>
        <td>
            <input name="code" type="text" id="code" value="<?PHP echo $pdtl_codepdtloc ?>" size="50" readonly>
        </td>
    </tr>
    <tr>
        <td width="160" class="rubfrm" id="f_des" align="right"><?PHP echo _("Libellé"); ?></td>
        <td>
            <input name="des" type="text" id="des" value="<?PHP echo $pdtloc_des; ?>" size="50" readonly>
        </td>
    </tr>
    <tr>
        <td width="160" class="rubfrm" id="f_per" align="right"><?PHP echo _("Période prévue"); ?></td>
        <td>
            <?PHP echo _("Du"); ?>
            <input name="dd" type="text" id="dd" value="<?PHP echo $dd; ?>" size="10" readonly>
            <input name="hd" type="text" id="hd" value="<?PHP echo $hd; ?>" size="5" readonly>
            <?PHP echo _("Au"); ?>
            <input name="df" type="text" id="df" value="<?PHP echo $df; ?>" size="10" readonly>
            <input name="hf" type="text" id="hf" value="<?PHP echo $hf; ?>" size="5" readonly>
        </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"><?PHP echo _("Notes internes"); ?></td>
            <td>
                <textarea name="note" id="note" rows="4" readonly><?PHP echo $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"><?PHP echo("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="">' . _("-- Faites votre choix --") . '</option>';
                    $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
                    $rech = "SELECT * FROM `" . TBTEC . "` WHERE `tec_codeage` = '$coloc_codeage' ORDER BY tec_nom";
                    $rows = $db->get_results($rech, ARRAY_A);

                    if ($rows) {
                        foreach ($rows as $row) {
                            extract($row);
                            echo '<option value="' . $tec_code . '"';
                            if ($pdtl_codedep == $tec_code)
                                echo ' selected';
                            echo '>' . $tec_nom . ' ' . $tec_prenom . '</option>';
                        }
                    }
                    $db->disconnect();
                    echo '</select>';
                    echo ' <img src="../img/oblig.png" align="absmiddle" alt="' . _("Champ obligatoire") . '">';
                } ?>
            </td>
        </tr>
        <tr>
            <td width="250" class="rubfrm" id="f_prispar" align="right"><?PHP echo _("Remis à"); ?></td>
            <td>
                <input name="prispar" type="text" id="prispar" value="<?PHP echo $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 _("Champ obligatoire"); ?>">
                <?PHP } ?>
            </td>
        </tr>
        <tr>
            <td width="250" class="rubfrm" id="f_datedep" align="right"><?PHP echo _("Date départ"); ?></td>
            <td>
                <input name="datedepf" type="text" id="datedepf" value="<?php echo $pdtl_datedepf; ?>" size="10" readonly>
                <?PHP
                $tab_heures = give_tab_heures(($pprm_firsthour * 3600), ($pprm_lasthour * 3600), ($pla_stepmin * 60));
                // $tab_heures = give_tab_heures(($pprm_firsthour * 3600), ($pprm_lasthour * 3600), 300, true);
                cre_select('hdep', 'hdep', $tab_heures, substr($pdtl_heuredep, 0, 5));
                echo '<div class="annot_petit_it"> ('._("La date doit être comprise dans la période prévue").')</div>';
                ?>
            </td>
        </tr>
        <?PHP if ((trim($udesc1) <> "") OR (trim($udesc2) <> "")) { ?>
            <tr>
                <td width="250" class="rubfrm" id="f_didx" align="right"><?PHP echo _("Indexes dé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">
                        <img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo _("Champ obligatoire"); ?>">
                        <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">
                        <img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo _("Champ obligatoire"); ?>">
                    <?PHP } ?>
                    <br /><span
                        class="annot_petit_it"> (<?PHP echo _("Anciens indexes repris. Les nouveaux doivent être supérieurs ou égaux"); ?>
                        )</span>
                </td>
            </tr>
        <?PHP } ?>
        <tr>
            <td width="250" class="rubfrm" id="f_coderegc" align="right"><?PHP echo _("Mode règlement caution"); ?></td>
            <td>
                <?PHP
                // Création de la liste des Règlements
                $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
                $rech = "SELECT * FROM `" . TBREG . "` ORDER BY reg_desc";

                $rows = $db->get_results($rech, ARRAY_A);
                $db->disconnect();
                cre_select_tab('coderegc', 'coderegc', $rows, 'reg_code', 'reg_desc', '', $pdtl_coderegc, '', _("-- Faites votre choix --"));

                $pvht = $pdtlbl_caution;
                $tothtcaut = round($pvht * 100) / 100;
                $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
                $rech = "SELECT * FROM `" . TBTVA . "` WHERE tva_code='" . $pdtlbl_tvacaut . "'";
                $row = $db->get_row($rech, ARRAY_A);
                if ($row)
                    extract($row);
                $db->disconnect();
                $txtva = $tva_tx / 100;
                $totttccaut = round(($tothtcaut * (1 + $txtva)) * 100) / 100;

                $txt = '('._("Montant : ") . full_num_format($totttccaut, '', '', TRUE)  . ' '._("TTC").')';
                // echo '<br />';
                echo "<div class=\"annot_petit_it\">";
                echo $txt;
                echo "</span>";
                ?>
            </td>
        </tr>
        <tr>
            <td width="160" class="rubfrm" id="f_texte" align="right"><?PHP echo _("Commentaire départ"); ?></td>
            <td>
                <textarea name="noted" id="noted" rows="4"><?PHP echo $pdtl_noted; ?></textarea>
                <?PHP /*<input name="noter" type="hidden" id="noter" value="" readonly>*/ ?>
            </td>
        </tr>

        <?PHP
        // Mode retour ou visualisation
        if ($td == "ret") {
            ?>
            <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"><?PHP echo _("Réceptionné 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="">' . _("-- Faites votre choix --") . '</option>';
                        $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
                        $rech = "SELECT * FROM `" . TBTEC . "` WHERE `tec_codeage` = '$coloc_codeage' ORDER BY tec_nom";
                        $rows = $db->get_results($rech, ARRAY_A);

                        if ($rows) {
                            foreach ($rows as $row) {
                                extract($row);
                                echo '<option value="' . $tec_code . '"';
                                if ($pdtl_coderet == $tec_code)
                                    echo ' selected';
                                echo '>' . $tec_nom . ' ' . $tec_prenom . '</option>';
                            }
                        }
                        $db->disconnect();
                        echo '</select>';
                        echo ' <img src="../img/oblig.png" align="absmiddle" alt="' . _("Champ obligatoire") . '">';
                    } ?>
                </td>
            </tr>
            <tr>
                <td width="250" class="rubfrm" id="f_retpar" align="right"><?PHP echo _("Rendu par"); ?></td>
                <td>
                    <input name="retpar" type="text" id="retpar" value="<?php echo $pdtl_retpar; ?>" size="70" maxlength="70">
                     <img src="../img/oblig.png" align="absmiddle" alt="'<?PHP echo _("Champ obligatoire"); ?>">
                </td>
            </tr>
            <tr>
                <td width="250" class="rubfrm" id="f_dateret" align="right"><?PHP echo _("Date retour"); ?></td>
                <td>
                    <input name="dateretf" type="text" id="dateretf" value="<?php echo $pdtl_dateretf; ?>" size="10" readonly>
                    <?PHP
                    echo ' ';
                    cre_select('hret', 'hret', $tab_heures, substr($pdtl_heureret, 0, 5));
                    ?>
                <span id="addpen">
                <input name="bpen" type="button" id="bpen"class="bton_std" value="<?PHP echo _("Ajouter pénalité"); ?>">
                </span>
                 <div class="annot_petit_it"> (<?PHP echo _("La date doit être au moins la date de départ"); ?>)</div>
                </td>
            </tr>
            <?PHP if ((trim($udesc1) <> "") OR (trim($udesc2) <> "")) { ?>
                <tr>
                    <td width="250" class="rubfrm" id="f_didx" align="right"><?PHP echo _("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">
                            <input name="qci1" type="hidden" id="qci1" value="<?php echo $barloc_qconsi1; ?>">
                            <img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo _("Champ obligatoire"); ?>">
                            <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">
                            <input name="qci2" type="hidden" id="qci2" value="<?php echo $barloc_qconsi2; ?>">
                            <img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo _("Champ obligatoire"); ?>">
                        <?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 _("Ajouter Conso."); ?>">
		</span>
                        <br /><span
                            class="annot_petit_it"> (<?PHP echo _("Indexes de départ repris. Les nouveaux doivent être supérieurs ou égaux"); ?>
                            )</span>
                    </td>
                </tr>
            <?PHP } ?>
            <tr>
                <td width="250" class="rubfrm" id="f_rcaut" align="right"><?PHP echo _("Caution rendue ?"); ?></td>
                <td>
                    <?PHP
                    cre_select('rcaut', 'rcaut', $non_oui, $pdtl_rcaut);
                    ?>
                </td>
            </tr>
            <tr>
                <td width="250" class="rubfrm" id="f_reloc" align="right"><?PHP echo _("Remise en location ?"); ?></td>
                <td>
                    <?PHP
                    cre_select('reloc', 'reloc', $non_oui, $pdtl_reloc);
                    ?>
                </td>
            </tr>
            <tr>
                <td width="160" class="rubfrm" id="f_texte" align="right"><?PHP echo _("Commentaire retour"); ?></td>
                <td>
                    <textarea name="noter" id="noter" rows="4"><?PHP echo $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"><?PHP echo _("BAREMES"); ?></td>
        </tr>
    </table>
    <div id="detbarloc">
    </div>

    <div id="addbarloc" style="display: block">
        <!-- 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;
            cre_falselnk('', 'chx_bar', 'div', '', _("Choisir un barême"), $urlchoixbar, '../img/add.png', _("Choisir un barême"));
    	}
        ?>
    </div>
    <p align="center">
    <?PHP
    switch ($td)
    {
        case "add" :
        case "edit" :
        case "dep" :
        case "ret" :
            echo '<input name="RAZ" type="reset" class="bton_std" id="RAZ" value="'._("Réinitialiser").'">';
            echo '<input name="enr" ';
            if (count($_SESSION["pdtlbl"]) == 0)
                echo ' class="bton_fmarr_dis"';
            else
                echo ' class="bton_std"';
            echo ' type="button" class="bton_std" id="enr" value="'._("Enregistrer").'"';
            if (count($_SESSION["pdtlbl"]) == 0)
                echo ' disabled="disabled"';
            echo '>';
            echo '<input name="annul" type="button" class="bton_std" id="annul" value="'._("Annuler").'">';
            break;
        case "del" :
            echo '<input name="enr" type="submit" class="bton_std" id="enr" value="'._("Supprimer").'">';
            echo '<input name="annul" type="button" class="bton_std" id="annul" value="'._("Quitter").'">';
            break;
    }
    ?>
    </p>
    </form>
<?PHP
} else
    close_fen_auto('', 'fscomp');
?>
</body>
</html>
