<?php
/****************************************************************************************
 * SMI (Services Maintenance Interventions) est une gestion libre de maintenance et de SAV
 *
 * Version 1.0.0
 *
 * Copyright (C) 2006-2014  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/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_txt.inc.php");
include_once("../inc/fic_age.inc.php");
include_once("../inc/fic_cli.inc.php");
include_once("../inc/fic_age.inc.php");
include_once("../inc/fic_cli.inc.php");
include_once("../inc/fic_droits.inc.php");
include_once("../inc/fic_mque.inc.php");
include_once("../inc/fic_rel.inc.php");
include_once("../inc/fic_tec.inc.php");
include_once("../inc/fic_rel.inc.php");
include_once("../inc/fic_tec.inc.php");
include_once("../inc/fic_zc.inc.php");
include_once("../inc/lst.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"]);
// Variables Formulaire
fix_magic_quotes();
$_GET = clean_str($_GET);
$_POST = clean_str($_POST);

$td = $_GET['td']; // Récupération type demande
$cr = $_GET['cr']; // Récupération code relevé (uniquement sur création)
$crp = $_GET['crp']; // Récupération code relevé Produit
$cc = $_GET['cc']; // Récupération code Client
$ca = $_GET['ca']; // Récupération code Agence
$sais_dteout = TRUE;
$sais_dteach = TRUE;
$sais_dtefgar = TRUE;
$sais_mdval = TRUE;
$sais_mdlmaj = TRUE;
$sais_scli = TRUE;
$select_age = TRUE;
$pbm = 0;
$idscli = -1;
$search = '';

$pbm_rpdt = FALSE;

if (@$_SESSION["niv_log"] == 1)
    $td = "view";

// Récupération id site
if (isset($_POST["sitepbm"]))
    $idscli = intval($_POST['sitepbm']);

// Récupération filtre problème
if (isset($_POST["pbms"]))
    $pbm = intval($_POST['pbms']);

// Récupération texte recherché
if (isset($_POST['search']))
    $search = trim($_POST['search']);

if ((@$_SESSION["niv_log"] == 3) OR (@$_SESSION["niv_log"] == 4))
    $ca = @$_SESSION["code_age"];

if ($cc <> "") {
    $row = lit_enr_cli($cc, TRUE);
    if (is_array($row)) {
        $row = encode_str($row);
        extract($row);

        // Vérification des tentatives de hack
        switch (@$_SESSION["niv_log"]) {
            // Contrôle qu'un client n'essaye pas de "hacker" un relevé
            case 1 :
                /*
                if ($cli_code <> @$_SESSION["code_log"])
                    $pbm_rlic = TRUE;
                */
                $tab_cli = give_tab_rcli($_SESSION["code_log"], TRUE);
                if (exist_in_array($cli_code, $tab_cli) == FALSE)
                    $pbm_rpdt = TRUE;
                $select_age = FALSE;
                break;
            // Contrôle qu'une agence n'essaye pas de "hacker" un relevé
            case 3 :
            case 4 :
                if (client_age_ok($cli_code, @$_SESSION["code_age"], TRUE) == FALSE)
                    $pbm_rpdt = TRUE;
                if (($rpdt_codeage <> @$_SESSION["code_age"]) OR ($cli_prop <> @$_SESSION["code_age"]))
                    $pbm_rpdt = TRUE;
                $select_age = FALSE;
                $rpdt_codeage = @$_SESSION["code_age"];
                break;
        }

        if ($td == "add")
        {
            $row = lit_enr_rel_cli($cli_code);
            if (is_array($row)) {
                $row = encode_str($row);
                extract($row);
                if ($cli_ste <> "")
                    $rpdt_idsite = -2;
                else {
                    $rpdt_idsite = 0;
                    $sais_scli = FALSE;
                }
                $ca = $cli_prop;
                $num = $row["rel_num"] + 1;
                $rpdt_codep = $row["rel_rnum"] . sprintf("%'04s", $num);
            }

            $rpdt_daterelf = $datef;
            $rpdt_dateoutf = "";
            $rpdt_code = crecodesession("RP");
            $rpdt_coderel = $rel_code;
            $rpdt_codecli = $cc;
            $rpdt_codeage = $ca;
            $rpdt_mac = "00:00:00:00:00:00";
            $rpdt_ip1 = "000.000.000.000";
            $rpdt_ip2 = "000.000.000.000";
            $rpdt_mdhcp = "000.000.000.000";
            $rpdt_ip = "000.000.000.000";
            $rpdt_masq = "000.000.000.000";
            $rpdt_pass = "000.000.000.000";
        }
    } else
        $pbm_rpdt = TRUE;
} else
    $pbm_rpdt = TRUE;

if ($pbm_rpdt == FALSE)
{
    if ($cr <> "") {
        $row = lit_enr_rel($cr);
        if (is_array($row)) {
            $row = encode_str($row);
            extract($row);

            if ($rel_codecli <> $cc)
                $pbm_rpdt = TRUE;
        } else
            $pbm_rpdt = TRUE;
    }
}

if ($pbm_rpdt == FALSE)
{
    if ($crp <> "") {
        // Récupération des informations dossier relevé
        $row = lit_enr_rpdt($crp);
        if (is_array($row)) {
            $row = encode_str($row);
            extract($row);

            if ($rpdt_codecli <> $cc)
                $pbm_rpdt = TRUE;

            $ca = $rpdt_codeage;
            $cc = $rpdt_codecli;

            if ($pbm_rpdt == FALSE)
            {
                if ($td <> "add") {
                    /*
                    $row = lit_enr_cli($rpdt_codecli, TRUE);
                    if (is_array($row)) {
                        $row = encode_str($row);
                        extract($row);
                    }
                    */

                    // Vérification des tentatives de hack
                    switch (@$_SESSION["niv_log"]) {
                        case 1 :
                            if ($rpdt_codecli <> $_SESSION["code_log"])
                                $pbm_rpdt = TRUE;
                            break;
                        case 3 :
                        case 4 :
                            if ($rpdt_codeage <> $_SESSION["code_log"])
                                $pbm_rpdt = TRUE;
                            break;
                        default :
                            break;
                    }
                }

                if ($pbm_rpdt == FALSE) {
                    $exist_in_rpbm = exist_rpdt_in_rpbm($crp);
                    if ($exist_in_rpbm == TRUE)
                        $exist_in_rpbm = 1;
                    else
                        $exist_in_rpbm = 0;

                    $rpdt_daterelf = datetolocal($rpdt_daterel);
                    $rpdt_dateachf = datetolocal($rpdt_dateach);
                    $rpdt_fingarf = datetolocal($rpdt_fingar);
                    $rpdt_dateoutf = datetolocal($rpdt_dateout);
                    $rpdt_mdvalf = datetolocal($rpdt_mdval);
                    $rpdt_mdlmajf = datetolocal($rpdt_mdlmaj);

                    // On ne peut pas modifier si produit sorti
                    if (($rpdt_dateoutf <> "") AND ($td == "edit"))
                        $td = "view";
                }
            }
        } else
            $pbm_rpdt = TRUE;
    } else
    {
        if ($td <> "add")
            $pbm_rpdt = TRUE;
    }
}

switch ($td) {
    case "add":
        $titre = _("AJOUT FICHE RELEVE MATERIEL");
        $rpdt_gars = FALSE;
        $rpdt_prop = FALSE;
        $sais_dteout = FALSE;
        break;
    case "edit":
        $titre = _("MISE A JOUR FICHE RELEVE MATERIEL");
        break;
    case "view":
        $titre = _("DETAIL FICHE RELEVE MATERIEL");
        $sais_dteout = FALSE;
        $sais_dteach = FALSE;
        $sais_dtefgar = FALSE;
        $sais_mdval = FALSE;
        $sais_mdlmaj = FALSE;
        break;
    case "del":
        $titre = _("SUPPRESSION FICHE RELEVE MATERIEL");
        $sais_dteout = FALSE;
        $sais_dteach = FALSE;
        $sais_dtefgar = FALSE;
        $sais_mdval = FALSE;
        $sais_mdlmaj = FALSE;
        break;
    default :
        $pbm_rpdt = 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 _("Fiche Relevé Matériel"); ?></title>

<?PHP include_once("../inc/header.inc.php"); ?>
<script language="javascript">
    <!--
    var tab1_champ = ["nom:daterelf ; format:date ; masque:<?PHP echo $_SESSION['date_fmtfull']; ?> ; req:Y ; txt:<?PHP echo _("Date création"); ?> ; stok:frmok ; stbad:frmbad",
        "nom:codeage ; format:liste ; req:Y ; txt:<?PHP echo _("Agence"); ?> ; vmn:1 ; stok:frmok ; stbad:frmbad",
        "nom:site ; format:liste ; req:Y ; txt:<?PHP echo  _("Lieu d'utilisation"); ?> ; vmn:1 ; stok:frmok ; stbad:frmbad",
        "nom:codetec ; format:liste ; req:Y ; txt:<?PHP echo _("Technicien"); ?> ; vmn:1 ; stok:frmok ; stbad:frmbad",
        "nom:codecat ; format:liste ; req:Y ; txt:<?PHP echo _("Catégorie"); ?> ; vmn:1 ; stok:frmok ; stbad:frmbad",
        "nom:codema ; format:liste ; req:Y ; txt:<?PHP echo _("Marque"); ?> ; vmn:1 ; stok:frmok ; stbad:frmbad",
        "nom:codeet ; format:liste ; req:Y ; txt:<?PHP echo _("Etat constaté"); ?> ; vmn:1 ; stok:frmok ; stbad:frmbad",
        "nom:codeta ; format:liste ; req:N ; txt:<?PHP echo _("Type d'accès"); ?> ; vmn:0 ; stok:frmok ; stbad:frmbad",
        "nom:codel ; format:liste ; req:N ; txt:<?PHP echo _("Log. Télémaintenance"); ?> ; vmn:0 ; stok:frmok ; stbad:frmbad",
        "nom:codem ; format:liste ; req:N ; txt:<?PHP echo _("Mode mises à jour"); ?> ; vmn:0 ; stok:frmok ; stbad:frmbad",
        "nom:mper ; format:liste ; req:N ; txt:<?PHP echo _("Fréquence mises à jour"); ?>  ; vmn:0 ; stok:frmok ; stbad:frmbad",
        "nom:mtype ; format:liste ; req:N ; txt:<?PHP echo _("Type mises à jour"); ?>  ; vmn:0 ; stok:frmok ; stbad:frmbad",
        "nom:modele ; format:txt ; req:Y ; txt:<?PHP echo _("Modèle"); ?> ; lmx:40 ; stok:frmok ; stbad:frmbad",
        "nom:ns ; format:txt ; req:Y ; txt:<?PHP echo _("Numéro de série"); ?> ; lmx:40 ; stok:frmok ; stbad:frmbad",
        "nom:empl ; format:txt ; req:Y ; txt:<?PHP echo _("Emplacement"); ?> ; lmx:40 ; stok:frmok ; stbad:frmbad",
        "nom:codep ; format:txt ; req:Y ; txt:<?PHP echo _("Codage produit"); ?> ; lmx:20 ; stok:frmok ; stbad:frmbad",
        "nom:util ; format:txt ; req:Y ; txt:<?PHP echo _("Utilisateur"); ?> ; lmx:40 ; stok:frmok ; stbad:frmbad",
        "nom:nomp ; format:txt ; req:N ; txt:<?PHP echo _("Nom du poste"); ?> ; lmx:20 ; stok:frmok ; stbad:frmbad",
        "nom:gt ; format:txt ; req:N ; txt:<?PHP echo _("Groupe de travail"); ?> ; lmx:40 ; stok:frmok ; stbad:frmbad",
        "nom:dom ; format:txt ; req:N ; txt:<?PHP echo _("Domaine"); ?> ; lmx:40 ; stok:frmok ; stbad:frmbad",
        "nom:login ; format:txt ; req:N ; txt:<?PHP echo _("Login"); ?> ; lmx:40 ; stok:frmok ; stbad:frmbad",
        "nom:mdp ; format:txt ; req:N ; txt:<?PHP echo _("Mot de Passe"); ?> ; lmx:40 ; stok:frmok ; stbad:frmbad",
        "nom:mac ; format:mac ; req:N ; txt:<?PHP echo _("Adresse MAC"); ?> ; lmx:17 ; stok:frmok ; stbad:frmbad",
        "nom:ip1 ; format:ip ; req:N ; txt:<?PHP echo _("Adresse IP DHCP N°1"); ?>; lmx:16 ; stok:frmok ; stbad:frmbad",
        "nom:ip2 ; format:ip ; req:N ; txt:<?PHP echo _("Adresse IP DHCP N°2"); ?>; lmx:16 ; stok:frmok ; stbad:frmbad",
        "nom:mdhcp ; format:ip ; req:N ; txt:<?PHP echo _("Masque IP DHCP"); ?>; lmx:16 ; stok:frmok ; stbad:frmbad",
        "nom:ip ; format:ip ; req:N ; txt:<?PHP echo _("Adresse IP"); ?> ; lmx:16 ; stok:frmok ; stbad:frmbad",
        "nom:masq ; format:ip ; req:N ; txt:<?PHP echo _("Masque IP"); ?> ; lmx:16 ; stok:frmok ; stbad:frmbad",
        "nom:pass ; format:ip ; req:N ; txt:<?PHP echo _("Adresse IP passerelle"); ?> ; lmx:16 ; stok:frmok ; stbad:frmbad",
        "nom:sid ; format:txt ; req:N ; txt:<?PHP echo _("SID"); ?> ; lmx:80 ; stok:frmok ; stbad:frmbad",
        "nom:wep ; format:txt ; req:N ; txt:<?PHP echo _("Clef WEP"); ?> ; lmx:80 ; stok:frmok ; stbad:frmbad",
        "nom:tlien ; format:txt ; req:N ; txt:<?PHP echo _("Lien d'accès"); ?>; lmx:40 ; stok:frmok ; stbad:frmbad",
        "nom:tlogin ; format:txt ; req:N ; txt:<?PHP echo _("Login télémaintenance"); ?> ; lmx:40 ; stok:frmok ; stbad:frmbad",
        "nom:tmdp ; format:txt ; req:N ; txt:<?PHP echo _("Mot de passe télémaintenance"); ?> ; lmx:40 ; stok:frmok ; stbad:frmbad",
        "nom:mlogin ; format:txt ; req:N ; txt:<?PHP echo _("Login mises à jour"); ?> ; lmx:40 ; stok:frmok ; stbad:frmbad",
        "nom:mmdp ; format:txt ; req:N ; txt:<?PHP echo _("Mot de passe mises à jour"); ?> ; lmx:40 ; stok:frmok ; stbad:frmbad",
        "nom:signataire ; format:txt ; req:Y ; txt:<?PHP echo _("Validé par"); ?> ; lmx:50 ; stok:frmok ; stbad:frmbad"];
    //-->
</script>

<script type="text/javascript">
    <!--
    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"); ?>"
        });
        <?PHP if ($sais_dteout == TRUE) { ?>
        $("#dateoutf").datepicker({
            onSelect: function (datesel) {
                $("#dateoutf").blur();
                chk_datedif(datesel, this.id, '<?PHP echo $_SESSION['date_fmtshort']; ?>', true, 'daterelf', '', '',false);
            }
        });
        <?PHP }
        if ($sais_dteach == TRUE) { ?>
        $("#dateachf").datepicker({
            onSelect: function () {
                $("#dateachf").blur();
            }
        });
        <?PHP }
        if ($sais_dtefgar == TRUE) { ?>
        $("#datefgarf").datepicker({
            onSelect: function () {
                $("#datefgarf").blur();
                chk_date_affwarnech(this.id, 'warn_gar', '<?PHP echo $_SESSION['date_fmtshort']; ?>', '', '', 'today');
            }
        });
        <?PHP }
        if ($sais_mdval == TRUE) { ?>
        $("#mdvalf").datepicker({
            onSelect: function (datesel) {
                $("#mdlmajf").blur();
                if (chk_datedif(datesel, this.id, '<?PHP echo $_SESSION['date_fmtshort']; ?>', true, 'dateachf,today', '', '',false)) {
                    chk_date_affwarnech(this.id, 'warn_ech', '<?PHP echo $_SESSION['date_fmtshort']; ?>', '', '', 'today');
                }
            }
        });
        <?PHP }
        if ($sais_mdlmaj == TRUE) { ?>
        $("#mdlmajf").datepicker({
            onSelect: function (datesel) {
                $("#mdlmajf").blur();
                chk_datedif(datesel, this.id, '<?PHP echo $_SESSION['date_fmtshort']; ?>', true, 'dateachf,today,mdvalf', '', '',false);
            }
        });
        <?PHP } ?>
    }

    function init_all() {
        init_Body();
        init_autohref_classe('falselnkimg','');
        init_datepicker();
        img_checkpw('mdp', 'nivpw');
        img_checkpw('tmdp', 'nivpwt');
        img_checkpw('mmdp', 'nivpwm');
        chk_modeip('modeip');
        chk_sdhcp('sdhcp');
        <?php
        switch ($td)
        {
            case "add" :
                echo '$("#daterelf").datepicker({';
                echo '    onSelect: function (datesel) {';
                echo '        $("#daterelf").blur();';
                echo '    },';
                echo '});';
                echo "init_autoraz('razdaterelf','daterelf','click');";

                echo "init_warn('".nb_cli('')."cli','','back','','');";
                echo "init_warn('".nb_tec_actifs()."tec','','back','','');";
                echo "init_warn('".nb_marques("","rel")."mque','','back','','');";
                echo "init_warn('".nb_etatpdt()."etatpdt','','back','','');";
                echo "init_warn('".nb_catpdt()."catpdt','','back','','');";
                echo "init_warn('".nb_age_actives()."age','','back','','');";

                echo "init_chk_modeip('modeip');";
                echo "init_chk_sdhcp('sdhcp');";
                echo "init_checkpw('mdp','nivpw',true);";
                echo "init_checkpw('tmdp','nivpwt',true);";
                echo "init_checkpw('mmdp','nivpwm',true);";
                echo "init_warn_scli_change_rel('site','".$exist_in_rpbm."','site',".$rpdt_idsite.");";
                echo "init_ajax_tec2();";
                if ($select_age == FALSE)
                    echo "readonly_id('codeage',false);";
                echo "init_valid_form('enr','rpdt_maj','".$_SESSION['date_fmtshort']."',tab1_champ,'','');";
                if ($sais_scli == FALSE)
                   echo "readonly_id('site',false);";
                break;
            case "edit" :
                if (@$_SESSION["niv_log"] >= 3)
                    echo 'warn_cpta('.$cli_cpta.',"rel");';
                echo "init_chk_modeip('modeip');";
                echo "init_chk_sdhcp('sdhcp');";
                echo "init_checkpw('mdp','nivpw',true);";
                echo "init_checkpw('tmdp','nivpwt',true);";
                echo "init_checkpw('mmdp','nivpwm',true);";
                echo "init_warn_scli_change_rel('site','".$exist_in_rpbm."','site',".$rpdt_idsite.");";
                echo "init_ajax_tec2();";
                if (exist_rpbm($rpdt_code) == TRUE)
                {
                    echo "init_autosubmit('sitepbm','change','pbm_lst');";
                    echo "init_autosubmit('pbms','change','pbm_lst');";
                }
                echo "init_valid_form('enr','rpdt_maj','".$_SESSION['date_fmtshort']."',tab1_champ,'','');";
                if ($sais_scli == FALSE)
                   echo "readonly_id('site',false);";
                if ($select_age == FALSE)
                    echo "readonly_id('codeage',false);";
                echo "init_new_fen('etats','impression');";
                break;
            case "view" :
                if (@$_SESSION["niv_log"] >= 3)
                    echo 'warn_cpta('.$cli_cpta.',"rel");';
                echo "init_warn_scli_change_rel('site','".$exist_in_rpbm."','site',".$rpdt_idsite.");";
                echo "readonly_all();";
                echo "readok_id('etats',false);";
                echo "init_new_fen('etats','impression');";
                break;
            case "del" :
                echo "warn_del('');";
                echo "readonly_all();";
                break;

        }
        echo "init_autohref('add_pbm', 'click', '', true);";
        if ($sais_dteout == TRUE)
            echo "init_autoraz('razdateoutf','dateoutf','click');";
        else
            echo "$('#datesortie').hide();";
        echo "init_autoraz('razdateachf','dateachf','click');";
        echo "init_autoraz('razdatefgarf','datefgarf','click');";
        echo "init_autoraz('razmdvalf','mdvalf','click');";
        echo "init_autoraz('razmdlmajf','mdlmajf','click');";
        echo "chk_date_affwarnech('datefgarf','warn_gar','".$_SESSION["date_fmtshort"]."','','','today');";
        echo "init_chk_date_affwarnech('datefgarf','warn_gar','".$_SESSION["date_fmtshort"]."','','','today');";
        echo "chk_date_affwarnech('mdvalf','warn_ech','".$_SESSION["date_fmtshort"]."','','','today');";
        echo "init_chk_date_affwarnech('mdvalf','warn_ech','".$_SESSION["date_fmtshort"]."','','','today');";
        if (@$_SESSION["niv_log"] >= 3)
            echo "init_fensaisie('aff_notesc',930,380);";
        if (($idscli != -1) OR ($pbm != 0) OR ($search != ''))
            echo '$( "#onglets_rpdt" ).tabs({ active: 7 });';
        else
            echo '$( "#onglets_rpdt" ).tabs();';
        ?>
        init_autosubmit('search','change','pbm_lst');
        init_autoraz('razsearch','search','click');
        init_autosubmit('razsearch','click','pbm_lst');
        init_autohref_classe('falselnkimg','');
        Focus_first();
    }

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

<body>
<?PHP include_once("../inc/entete.inc.php"); ?>
<p align="center"><span class="titrepage"><?PHP echo $titre ?></span></p>
<?PHP
if ($pbm_rpdt == FALSE) {
    ?>
    <!-- affiché uniquement s'il y a un code client -->
    <?PHP
    if ($cc <> "") {
        ?>
        <table width="100%" border="0">
            <tr>
                <td width="33%">
                    <?PHP
                    echo '<a href="rel_maj.php?td=edit&cr=' . $cr . '&cc='.$cc.'">' . _("Retour au dossier de relevé");
                    ?>
                </td>
                <td width="33%" align="center" class="annot_petit_it">
                    <div id="oblig">(<img src="../img/oblig.png" align="absmiddle"
                                          alt="<?PHP echo _("Champ obligatoire"); ?>">
                        : <?PHP echo _("Saisie obligatoire"); ?>)
                    </div>
                </td>
                <td width="33%" align="right">
                    <?PHP
                    if (($td == "edit") OR ($td == "view")) {
                        ?>
                        <select name="etats" size="1" id="etats" class="annot_petit">
                            <option value="" selected>&#187; <?PHP echo _("Etats"); ?> &#171;</option>
                            <?PHP
                            $urlimp = "rlp_pdf.php?cr=" . $crp . "&te=m&pbm=0";
                            echo "<option value=\"" . $urlimp . "\" class=\"icone\" style=\"background-image: url(../img/sel_print.gif);\">" . _("Relevé") . "</option>\n";

                            $urlimp = "rlp_pdf.php?cr=" . $crp . "&te=m&pbm=1";
                            echo "<option value=\"" . $urlimp . "\" class=\"icone\" style=\"background-image: url(../img/sel_rel.gif);\">" . _("Relevé et problèmes") . "</option>\n";
                            ?>
                        </select>
                    <?PHP
                    } else
                        echo "&nbsp;";
                    ?>
                </td>
            </tr>
        </table>

        <form name="rpdt_maj" id="rpdt_maj" method="post" action="rpdt_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="codecli" type="hidden" id="codecli" value="<?PHP echo $rpdt_codecli ?>">
        <?PHP if ($td == "add") { ?>
            <input name="code" type="hidden" id="code" value="<?PHP echo $rpdt_code ?>">
            <input name="dateoutf" type="hidden" id="dateoutf" value="<?PHP echo $rpdt_dateoutf ?>">
        <?PHP } else { ?>
            <input name="code" type="hidden" id="code" value="<?PHP echo $rpdt_code ?>">
            <input name="codeage" type="hidden" id="codeage" value="<?PHP echo $rpdt_codeage ?>">
            <input name="codetec" type="hidden" id="codetec" value="<?PHP echo $rpdt_codetec ?>">
        <?PHP } ?>
        <input name="today" type="hidden" id="today" value="<?PHP echo $datef; ?>">
        <input name="nbutton" type="hidden" id="nbutton" value="">

        <!-- Date de création -->
        <table width="100%" border="0">
            <tr>
                <td width="160" class="rubfrm" id="f_daterelf" align="right"><?PHP echo _("Date Création"); ?> </td>
                <td>
                    <input name="daterelf" type="text" id="daterelf" value="<?PHP echo $rpdt_daterelf ?>" size="10"
                           maxlength="10" readonly>
                    <img src="../img/raz.png" id="razdaterelf" border="0" align="absmiddle">
                </td>
            </tr>
        </table>

        <div id="datesortie">
            <!-- Date de sortie du produit -->
            <table width="100%" border="0">
                <tr>
                    <td width="160" class="rubfrm" id="f_dateoutf" align="right"
                        align="right"><?PHP echo _("Sorti du parc le"); ?></td>
                    <td>
                        <input name="dateoutf" type="text" id="dateoutf" value="<?PHP echo $rpdt_dateoutf ?>" size="10"
                               maxlength="10" readonly>
                        <img src="../img/raz.png" id="razdateoutf" border="0" align="absmiddle">

                        <div class="annot_petit_it">
                            <?PHP
                            echo _("ATTENTION : dès que le matériel est sorti du parc, la fiche n'est plus modifiable");
                            echo '<br />';
                            echo _("Pensez à désinstaller les licences AVANT si vous voulez les réaffecter");
                            ?>
                        </div>
                    </td>
                </tr>
            </table>
        </div>

        <!-- Code du dossier de relevé -->
        <table width="100%" border="0">
            <tr>
                <td width="160" class="rubfrm" id="f_coderel" align="right"><?PHP echo _("Dossier de relevé"); ?></td>
                <td width="240">
                    <input name="coderel" type="text" id="coderel" value="<?PHP echo $rpdt_coderel ?>" size="20"
                           maxlength="20" readonly>
                </td>
            </tr>
        </table>

        <!-- Code du relevé matériel client (affiché uniquement si édition ou suppression) -->
        <?PHP if ($td <> "add") { ?>
            <table width="100%" border="0">
                <tr>
                    <td width="160" class="rubfrm" id="f_code" align="right"><?PHP echo _("Code Fiche"); ?></td>
                    <td>
                        <input name="code" type="text" id="code" value="<?PHP echo $rpdt_code ?>" size="20"
                               maxlength="20" readonly>
                    </td>
                </tr>
            </table>
        <?PHP } ?>

        <!-- Affichage du client -->
        <table width="100%" border="0">
            <tr>
                <td class="rubfrm" id="f_codecli" align="center"><?PHP echo _("Client"); ?>
                    <?PHP
                    if ((@$_SESSION["niv_log"] == 5) OR (@$_SESSION["niv_log"] == 9) OR (@$_SESSION["niv_log"] == 4) OR (@$_SESSION["niv_log"] == 3))
                        echo " <img src=\"../img/" . $ico_cpta[$cli_cpta] . "\" title =\"" . $mess_cpta[$cli_cpta] . "\" border=\"0\" align=\"absmiddle\">";
                    ?>
                </td>
            </tr>
        </table>

        <!-- détails client -->
        <table width="100%" border="0">
            <tr>
                <td valign="top" bgcolor="#C5CED7">
                    <?PHP
                    echo "<span class=\"annot_std_gras\">";
                    if ($cli_ste <> "")
                        echo $cli_ste . "<br />";
                    else
                        echo $cli_civilite . " " . $cli_prenom . " " . $cli_nom . "<br />";
                    echo "</span>";
                    echo $cli_adr1 . "<br />";
                    if ($cli_adr2 <> "")
                        echo $cli_adr2 . "<br />";
                    echo Retournecp_Id($cli_ville, TRUE) . " " . Retourneville_Id($cli_ville, TRUE) . "<br />";
                    $chemin_imagesco = $chemin_images . "/telc.png";
                    echo "<img src=\"" . $chemin_imagesco . "\" align=\"bottom\">";
                    echo " " . $cli_telf . "<br />";
                    ?>
                </td>
                <td width="60" valign="top">
                    <?PHP
                    if (@$_SESSION["niv_log"] >= 3) {
                        $url_affnotesc = "aff_notesc.php?cc=" . $cc;
                        cre_falselnk('', 'aff_notesc', 'span', '', _("Notes"), $url_affnotesc, '../img/eye.png', _("Notes"));
                    } else
                        echo "&nbsp;";
                    ?>
                </td>
            </tr>
        </table>

        <!-- Site d'usage du produit -->
        <table width="100%" border="0">
            <tr>
                <td width="160" class="rubfrm" id="f_site" align="right"><?PHP echo _("Lieu d'utilisation"); ?></td>
                <td>
                    <?PHP
                    $tab_sel = [];
                    $tab_sel [-1] = _("Tous les sites");
                    $tab_sel [0] = _("Site principal");
                    // création de la liste des sites actifs
                    $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
                    $rech = "SELECT * FROM `" . TBSCLI . "` WHERE `scli_actif` = '1' AND `scli_codecli`='" . $cc . "' ORDER BY scli_ste";
                    $rows = $db->get_results($rech, ARRAY_A);

                    if ($rows) {
                        foreach ($rows as $row) {
                            extract($row);

                            if ($scli_adr2 <> "")
                                $nom_site = $scli_ste . " (" . $scli_adr1 . ", " . $scli_adr2 . ", " . Retournecp_Id($scli_ville, FALSE) . " " . Retourneville_Id($scli_ville, FALSE) . ")";
                            else
                                $nom_site = $scli_ste . " (" . $scli_adr1 . ", " . Retournecp_Id($scli_ville, FALSE) . " " . Retourneville_Id($scli_ville, FALSE) . ")";
                            $tab_sel[$scli_id] = $nom_site;
                        }
                    }
                    $db->disconnect();
                    cre_select('site', 'site', $tab_sel, intval($rlic_idsite), '', _("-- Faites votre choix --"));
                    ?>
                </td>
            </tr>
        </table>

        <table width="100%" border="0">
            <tr>
                <td class="rubfrm" id="f_codecli" align="center">
                    <?PHP echo _("Relevé effectué par"); ?>
                </td>
            </tr>
        </table>

        <!-- Code de l'agence (choisi uniquement si création, affiché uniquement si édition ou suppression) -->
        <table width="100%" border="0">
            <tr>
                <td width="160" class="rubfrm" id="f_codeage" align="right"><?PHP echo _("Agence"); ?></td>
                <td>
                    <?PHP
                    // Création de la liste des agences ouvertes et couvrant le client
                    $tab_age = give_tab_age_cli($cli_code);
                    cre_select('codeage', 'codeage', $tab_age, $ca, '', _("-- Faites votre choix --"), 1, FALSE, '', _("-- Pas d'agence --"), TRUE, TRUE);
                    ?>
                </td>
            </tr>
        </table>

        <!-- Code du technicien (choisi uniquement si création, affiché uniquement si édition ou suppression) -->
        <table width="100%" border="0">
            <tr>
                <td width="160" class="rubfrm" id="f_codetec" align="right"><?PHP echo _("Technicien"); ?></td>
                <td>
                    <?PHP
                    $tab_res = [];
                    if ($ca <> '') {
                        // création de la liste des techniciens actifs
                        $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
                        $rech = "SELECT * FROM `" . TBTEC . "` WHERE `tec_dateout`='0000-00-00' AND `tec_codeage` = '" . $ca . "' ORDER BY tec_nom ";
                        $rows = $db->get_results($rech, ARRAY_A);
                        $db->disconnect();
                        if ($rows) {
                            foreach ($rows as $row) {
                                $row = encode_str($row);
                                extract($row);
                                $tab_res[$tec_code] = $tec_nom . " " . $tec_prenom . " (" . $tec_codeage . ")";
                            }
                        }
                    }
                    cre_select('codetec', 'codetec', $tab_res, $rpdt_codetec, '', _("-- Faites votre choix --"), 1, FALSE, '', _("-- Pas de technicien --"), TRUE);
                    ?>
                </td>
            </tr>
        </table>


        <!-- Délai du relevé -->
        <table width="100%" border="0">
            <tr>
                <td class="rubfrm">
                    <?PHP echo _("Détail du relevé"); ?>
                </td>
            </tr>
        </table>

        <!-- Catégorie -->
        <table width="100%" border="0">
            <tr>
                <td width="160" class="rubfrm" id="f_codecat" align="right"><?PHP echo _("Catégorie"); ?></td>
                <td>
                    <?PHP
                    // if (($rpdt_dateoutf == "") and ($td <> "view") and ($td <> "del")) // zone modifiable si pas sorti du parc et si pas en visualisation
                    $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
                    // création de la liste des catégories
                    $rech = "SELECT * FROM `" . TBRPCAT . "` ORDER BY rpcat_desc";
                    $rows = $db->get_results($rech, ARRAY_A);
                    $db->disconnect();
                    cre_select_tab('codecat', 'codecat', $rows, 'rpcat_code', 'rpcat_desc', '', $rpdt_codecat, '', _("-- Faites votre choix --"));
                    ?>
                </td>
            </tr>
        </table>


        <!-- Marque/Nom du fabricant -->
        <table width="100%" border="0">
            <tr>
                <td width="160" class="rubfrm" id="f_codema" align="right"><?PHP echo _("Constructeur"); ?></td>
                <td>
                    <?PHP
                    $tab_first_options = [];
                    $tab_first_options ['*'] = _("Toutes les marques");
                    $tab_mque = give_tab_marques("rpdt");
                    cre_select_tab('codema', 'codema', $tab_mque, 'mque_code', 'mque_ste', '', $rpdt_codema, '', _("-- Faites votre choix --"), 1, FALSE, '', _("-- Inconnu --"), TRUE, TRUE, FALSE, $tab_first_options);
                    ?>
                </td>
            </tr>
        </table>


        <!-- Modèle du produit -->
        <!-- Numéro de série -->
        <table width="100%" border="0">
            <tr>
                <td width="160" class="rubfrm" id="f_modele">
                    <?PHP echo _("Modèle / NS"); ?>
                </td>
                <td>
                    <input name="modele" type="text" id="modele" value="<?PHP echo $rpdt_modele; ?>" size="40"> <img
                        src="../img/oblig.png" align="absmiddle" alt="<?PHP echo _("Champ obligatoire"); ?>"> /
                    <input name="ns" type="text" id="ns" value="<?PHP echo $rpdt_ns; ?>" size="40"> <img
                        src="../img/oblig.png" align="absmiddle" alt="<?PHP echo _("Champ obligatoire"); ?>">
                </td>
            </tr>
        </table>

        <!-- Etat du produit -->
        <table width="100%" border="0">
            <tr>
                <td width="160" class="rubfrm" id="f_codeet" align="right"><?PHP echo _("Etat constaté"); ?></td>
                <td>
                    <?PHP
                    // création de la liste des états
                    $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
                    $rech = "SELECT * FROM `" . TBRPET . "` ORDER BY rpet_desc";
                    $rows = $db->get_results($rech, ARRAY_A);
                    $db->disconnect();
                    cre_select_tab('codeet', 'codeet', $rows, 'rpet_code', 'rpet_desc', '', $rpdt_codeet, '', _("-- Faites votre choix --"));
                    ?>
                </td>
            </tr>
        </table>

        <!-- Localisation -->
        <table width="100%" border="0">
            <tr>
                <td class="rubfrm" align="center">
                    <?PHP echo _("Repérage / Garantie / Propriété"); ?>
                </td>
            </tr>
        </table>

        <!-- Emplacement -->
        <table width="100%" border="0">
            <tr>
                <td width="160" class="rubfrm" id="f_empl" align="right">
                    <?PHP echo _("Emplacement"); ?>
                </td>
                <td>
                    <input name="empl" type="text" id="empl" value="<?PHP echo $rpdt_empl; ?>" size="40">
                    <img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo _("Champ obligatoire"); ?>"> <span
                        class="annot_petit_it">(<?PHP echo _("Pièce, bureau, étage, etc..."); ?>)</span>
                </td>
            </tr>
        </table>


        <!-- Codage produit -->
        <table width="100%" border="0">
            <tr>
                <td width="160" class="rubfrm" id="f_codep" align="right">
                    <?PHP echo _("Codage inventaire"); ?>
                </td>
                <td>
                    <input name="codep" type="text" id="codep" value="<?PHP echo $rpdt_codep; ?>" size="40">
                    <img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo _("Champ obligatoire"); ?>"> <span
                        class="annot_petit_it"><br />
                        <?PHP echo _("Code suggéré en fonction du paramétrage du dossier de relevé rattaché et du nombre de fiches relevés matériels déjà saisies"); ?>
                        <br />
                        <?PHP echo _("On peut saisir autre chose, notamment si le client utilise son propre codage"); ?></span>
                </td>
            </tr>
        </table>

        <!-- Utilisateur -->
        <table width="100%" border="0">
            <tr>
                <td width="160" class="rubfrm" id="f_util" align="right">
                    <?PHP echo _("Utilisateur"); ?>
                </td>
                <td>
                    <input name="util" type="text" id="util" value="<?PHP echo $rpdt_util ?>" size="40">
                    <img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo _("Champ obligatoire"); ?>">
                </td>
            </tr>
        </table>

        <!-- Date d'achat -->
        <table width="100%" border="0">
            <tr>
                <td width="160" class="rubfrm" id="f_dateachf" align="right"><?PHP echo _("Date d'achat"); ?></td>
                <td>
                    <input name="dateachf" type="text" id="dateachf" value="<?PHP echo $rpdt_dateachf ?>" size="10"
                           maxlength="10" readonly>
                    <img src="../img/raz.png" id="razdateachf" border="0" align="absmiddle">
                </td>
            </tr>
        </table>

        <!-- Fin de garantie -->
        <table width="100%" border="0">
            <tr>
                <td width="160" class="rubfrm" id="f_datefgarf" align="right"><?PHP echo _("Fin de garantie"); ?></td>
                <td>
                    <input name="datefgarf" type="text" id="datefgarf" value="<?PHP echo $rpdt_fingarf ?>" size="10"
                           maxlength="10" readonly>
                    <img src="../img/raz.png" id="razdatefgarf" border="0" align="absmiddle">
                    <?PHP
                    echo '<span id="warn_gar" style="display:none;">';
                    echo " <img src=\"../img/warn.png\" title =\"" . _("Plus sous garantie") . "\" border=\"0\" align=\"absmiddle\">";
                    echo '</span>';
                    ?>
                </td>
            </tr>
        </table>


        <!-- Garantie sur site ? -->
        <!-- Propriétaire ? -->
        <table width="100%" border="0">
            <tr>
                <td width="160" class="rubfrm" id="f_gars" align="right">
                    <?PHP echo _("Gar/site"); ?> ?
                </td>
                <td width="100">
                    <?PHP cre_select('gars', 'gars', $non_oui, $rpdt_gars); ?>
                </td>
                <td width="160" class="rubfrm" id="f_prop">
                    <div align="right"><?PHP echo _("Propriétaire ?"); ?></div>
                </td>
                <td>
                    <?PHP cre_select('prop', 'prop', $non_oui, $rpdt_prop); ?>
                </td>
            </tr>
        </table>

        <!-- signé par -->
        <table width="100%" border="0">
            <tr>
                <td width="160" class="rubfrm" id="f_signataire" align="right">
                    <?PHP echo _("Validé par"); ?>
                </td>
                <td>
                    <input name="signataire" type="text" id="signataire" value="<?PHP echo $rpdt_signataire; ?>"
                           size="50">
                    <img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo _("Champ obligatoire"); ?>">
                </td>
            </tr>
        </table>

        <p align="center">
            <?PHP
            switch ($td) {
                case "edit" :
                case "add" :
                    echo '<input name="RAZ" type="reset" class="bton_std" id="RAZ" value="' . _("Tout réinitialiser") . '">';
                    echo '<input name="enr" type="submit" class="bton_std" id="enr" value="' . _("Enregistrer") . '">';
                    break;
                case "del" :
                    echo '<input name="del" type="submit" class="bton_std" id="del" value="' . _("Supprimer") . '">';
                    break;
            }
            ?>
        </p>

        <!-- Compléments -->
        <table width="100%" border="0" cellspacing="0">
            <tr>
                <td height="25" class="rubfrm" align="center">
                    <?PHP echo _("Informations complémentaires"); ?>
                </td>
            </tr>
        </table>

        <div id="onglets_rpdt">
        <ul>
            <li><a href="#rpdt_notes"><?PHP echo _("Notes"); ?></a></li>
            <li><a href="#rpdt_lic"><?PHP echo _("Licences"); ?></a></li>
            <li><a href="#rpdt_rsx"><?PHP echo _("Réseau"); ?></a></li>
            <li><a href="#rpdt_telem"><?PHP echo _("Télémaintenance"); ?></a></li>
            <li><a href="#rpdt_maj"><?PHP echo _("Mises à jour"); ?></a></li>
            <li><a href="#rpdt_cnx"><?PHP echo _("Connexions"); ?></a></li>
            <li><a href="#rpdt_con"><?PHP echo _("Contrats"); ?></a></li>
            <li><a href="#rpdt_pbm"><?PHP echo _("Problèmes"); ?></a></li>
        </ul>
        <div id="rpdt_notes">
        <!-- Notes -->
        <table width="100%" border="0">
            <tr>
                <td>
                    <textarea name="nota" rows="5" id="nota"><?PHP echo $rpdt_nota; ?></textarea>
                </td>
            </tr>
        </table>
        </div>

        <div id="rpdt_lic">
            <!-- Licences utilisées -->
            <?PHP
            // création de la liste des relevés licences actifs
            $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
            $rech = "SELECT * FROM `" . TBRLIC . "` WHERE rlic_dateout = '0000-00-00' AND rlic_codecli = '" . $rpdt_codecli . "' ORDER BY rlic_code";
            $rows = $db->get_results($rech, ARRAY_A);

            if ($rows) {
                echo "<table class=\"MtableD\" border=\"0\" width=\"100%\" cellpadding=\"0\" cellspacing=\"0\">\n";

                // création de l'entête de la table "détails licences"
                echo "<th>";
                echo _("Code Fiche");
                echo "</th>\n";
                echo "<th>";
                echo _("Marque");
                echo "</th>\n";
                echo "<th>";
                echo _("Modèle / Version");
                echo "</th>\n";
                echo "<th>";
                echo _("Validité");
                echo "</th>\n";
                echo "<th>";
                echo _("Utilisée");
                echo "</th>\n";
                echo "<th>";
                echo _("Cliquer");
                echo "</th>\n";

                $j = 0;

                foreach ($rows as $row) {
                    $row = encode_str($row);
                    // création de l'entête de ligne (TR)
                    creetrlstdet($j);

                    echo "<td>\n";
                    echo $row["rlic_code"] . " ";
                    if ($row["rlic_legal"] == FALSE)
                        echo '<img src="../img/warn.png" title="' . _("Licence illégale") . '" border="0" align="absmiddle">';
                    $nb_rpdt_utilisees = 0;
                    $rech2 = "SELECT * FROM `" . TBRPDT . "` WHERE `rpdt_codecli` = '" . $rpdt_codecli . "'";
                    $rows2 = $db->get_results($rech2, ARRAY_A);
                    if ($rows2) {
                        foreach ($rows2 as $row2) {
                            if (strpos($row2["rpdt_coderlic"], $row["rlic_code"]) !== false)
                                $nb_rpdt_utilisees++;
                        }
                    }
                    if ($nb_rpdt_utilisees >= $row["rlic_maxcli"]) {
                        $txtlic = _("Licences installées") . ' : ' . $nb_rpdt_utilisees . ' / ' . _("autorisées") . ' : ' . $row["rlic_maxcli"];
                        echo ' <img src="../img/cd.png" title ="' . $txtlic . '" border="0" align="absmiddle">';
                    }
                    echo "</td>\n";

                    echo "<td>\n";
                    $rech2 = "SELECT * FROM `" . TBMQUE . "` WHERE `mque_code` = '" . $row["rlic_codema"] . "'";
                    $row2 = $db->get_row($rech2, ARRAY_A);
                    if ($row2) {
                        $row2 = encode_str($row2);
                        echo $row2["mque_ste"];
                    } else
                        echo "-";
                    echo "</td>\n";

                    echo "<td>\n";
                    echo $row["rlic_modele"];
                    if ($row["rlic_version"] <> "") {
                        echo "<br />";
                        echo _("Version") . ' : ' . $row["rlic_version"];
                    }
                    echo "</td>\n";

                    echo "<td align=\"center\">\n";
                    echo datetolocal($row["rlic_dateval"]);
                    if (datetolocal($row["rlic_dateval"]) <> "") {
                        if ((echeance_depassee_date($datea, $row["rlic_dateval"]) == TRUE)  AND (datetolocal($row["rlic_dateout"]) == ""))
                            echo ' <img src="../img/dateout.png" title ="' . _("validité dépassée") . '" border="0" align="absmiddle">';
                    }
                    echo "</td>\n";

                    echo "<td align=\"center\">\n";
                    if ($j % 2 == 0)
                        $classe_aff = "TRalter1D";
                    else
                        $classe_aff = "TRalter2D";
                    if (strpos($rpdt_coderlic, $row["rlic_code"]) !== false) {
                        if (($td <> "view") and ($td <> "del")) // zone modifiable si pas sorti du parc et si pas en visualisation
                            echo "<input type=\"checkbox\" name=\"rlic_choisi[]\" value=\"" . $row["rlic_code"] . "\" class=\"" . $classe_aff . "\" checked>";
                        else
                            echo "<input type=\"checkbox\" name=\"rlic_choisi[]\" value=\"" . $row["rlic_code"] . "\" class=\"" . $classe_aff . "\" checked disabled>";
                    } else {
                        if (($td <> "view") and ($td <> "del")) // zone modifiable si pas sorti du parc et si pas en visualisation
                            echo "<input type=\"checkbox\" name=\"rlic_choisi[]\" value=\"" . $row["rlic_code"] . "\" class=\"" . $classe_aff . "\">";
                        else
                            echo "<input type=\"checkbox\" name=\"rlic_choisi[]\" value=\"" . $row["rlic_code"] . "\" class=\"" . $classe_aff . "\" disabled>";
                    }
                    echo "</td>\n";
                    echo "<td align=\"center\">\n";
                    if (($td <> "view") AND ($td <> "del")) {
                        $lst_maj = TRUE;
                        cre_falselnk_img('', 'rlic_edit_'.$row["rpdt_id"], 'span', 'center', _("Edition"), 'lnk', 'rlic_maj.php?td=edit&crl=' . $row["rlic_code"], '../img/edit.png');
                    } else {
                        $lst_voir = TRUE;
                        cre_falselnk_img('', 'rlic_view_'.$row["rpdt_id"], 'span', 'center', _("Visualisation"), 'lnk', 'rlic_maj.php?td=view&crl=' . $row["rlic_code"], '../img/eye.png');
                    }
                    if (($rlic_dateoutf == "") AND ($td <> "del")) {
                        if (strpos($rpdt_coderlic, $row["rlic_code"]) !== false) {
                            $lst_pbmrel = TRUE;
                            cre_falselnk_img('', 'rpbm_add_'.$row["rpdt_id"], 'span', 'center', _("Déclaration problème"), 'lnk', 'rpbm_maj.php?td=add&tr=1&cr=' . $row["rpdt_code"] . '&ca=' . $row["rpdt_codeage"] . '&cap=1', '../img/addpbm.png');
                        }
                    } else
                        echo "&nbsp;";
                    echo "</td>\n";

                    echo "</tr>\n";

                    $j++;
                }

                echo "</table>\n";
                // Fin affichage table détails licences
                $taille_piedla = "small";
                include_once("piedla.inc.php");
            } else
                echo _("Pas de licence active installée sur ce matériel");
            $db->disconnect();
            ?>
        </div>

        <div id="rpdt_rsx" style="display:none">
            <!-- détail réseau -->

            <!-- Nom du poste -->
            <table width="100%" border="0">
                <tr>
                    <td width="160" class="rubfrm" id="f_nomp" align="right">
                        <?PHP echo _("Nom du poste"); ?>
                    </td>
                    <td>
                        <input name="nomp" type="text" id="nomp" value="<?PHP echo $rpdt_nomp; ?>" size="20">
                    </td>
                </tr>
            </table>

            <!-- Groupe de travail -->
            <table width="100%" border="0">
                <tr>
                    <td width="160" class="rubfrm" id="f_gt" align="right">
                        <?PHP echo _("Groupe de travail"); ?>
                    </td>
                    <td>
                        <input name="gt" type="text" id="gt" value="<?PHP echo $rpdt_gt; ?>" size="40">
                    </td>
                </tr>
            </table>


            <!-- Domaine -->
            <table width="100%" border="0">
                <tr>
                    <td width="160" class="rubfrm" id="f_dom" align="right">
                        <?PHP echo _("Domaine"); ?>
                    </td>
                    <td>
                        <input name="dom" type="text" id="dom" value="<?PHP echo $rpdt_dom; ?>" size="40">
                    </td>
                </tr>
            </table>

            <!-- Login / MDP -->
            <table width="100%" border="0">
                <tr>
                    <td width="160" class="rubfrm" id="f_login" align="right">
                        <?PHP echo _("Login / MDP"); ?>
                    </td>
                    <td>
                        <input name="login" type="text" id="login" value="<?PHP echo $rpdt_login; ?>" size="40"> /
                        <input name="mdp" type="text" id="mdp" value="<?PHP echo $rpdt_mdp; ?>" size="40">
                        <span id="nivpw"></span>
                    </td>
                </tr>
            </table>


            <!-- Adresse MAC -->
            <table width="100%" border="0">
                <tr>
                    <td width="160" class="rubfrm" id="f_mac" align="right">
                        <?PHP echo _("Adresse MAC"); ?>
                    </td>
                    <td>
                        <input name="mac" type="text" id="mac" value="<?PHP echo $rpdt_mac ?>" size="19"> /
                        <span class="annot_petit_it">(<?PHP echo _("Format"); ?>
                            xx:xx:xx:xx:xx:xx ou xx-xx-xx-xx-xx-xx)</span>
                    </td>
                </tr>
            </table>

            <!-- Mode IP  -->
            <!-- Serveur DHCP + Plage IP -->
            <!-- IP / MASQ / PASSERELLE -->
            <table width="100%" border="0">
                <tr>
                    <td width="160" class="rubfrm" id="f_modeip" align="right">
                        <?PHP echo _("Mode IP"); ?>
                    </td>
                    <td>
                        <?PHP cre_select('modeip', 'modeip', $maj_modeip, $rpdt_modeip); ?>
                    </td>
                </tr>
                <tr>
                    <td width="160" class="rubfrm" id="f_sdhcp" align="right">
                        <?PHP echo _("Serveur DHCP ?"); ?>
                    </td>
                    <td>
                        <?PHP cre_select('sdhcp', 'sdhcp', $non_oui, $rpdt_sdhcp); ?>
                    </td>
                </tr>
                <tr>
                    <td width="160" class="rubfrm" id="f_pdhcp" align="right">
                        <?PHP echo _("Plage DHCP (IP1/IP2/MASQ.)"); ?>
                    </td>
                    <td>
                        <input name="ip1" type="text" id="ip1" value="<?PHP echo $rpdt_ip1 ?>" size="17"> /
                        <input name="ip2" type="text" id="ip2" value="<?PHP echo $rpdt_ip2 ?>" size="17"> /
                        <input name="mdhcp" type="text" id="mdhcp" value="<?PHP echo $rpdt_mdhcp ?>" size="17"> /
                        <span class="annot_petit_it">(<?PHP echo _("Formats"); ?> xxx.xxx.xxx.xxx)</span>
                    </td>
                </tr>
                <tr>
                    <td width="160" class="rubfrm" id="f_ip" align="right">
                        <?PHP echo _("IP / Masque / Pass."); ?>
                    </td>
                    <td>
                        <input name="ip" type="text" id="ip" value="<?PHP echo $rpdt_ip ?>" size="17"> /
                        <input name="masq" type="text" id="masq" value="<?PHP echo $rpdt_masq ?>" size="17"> /
                        <input name="pass" type="text" id="pass" value="<?PHP echo $rpdt_pass ?>" size="17">
                        <span class="annot_petit_it">(<?PHP echo _("Formats"); ?> xxx.xxx.xxx.xxx)</span>
                    </td>
                </tr>
            </table>

            <!-- Numéro de ports -->
            <table width="100%" border="0">
                <tr>
                    <td width="160" class="rubfrm" id="f_np" align="right">
                        <?PHP echo _("Numéro de prise"); ?>
                    </td>
                    <td>
                        <?PHP echo _("Murale"); ?> : <input name="npm" type="text" id="npm"
                                                            value="<?PHP echo $rpdt_npm; ?>" size="14">
                        <?PHP echo _("Baie"); ?> : <input name="npb" type="text" id="npb"
                                                          value="<?PHP echo $rpdt_npb; ?>" size="14">
                        <?PHP echo _("Commutateur"); ?> : <input name="npc" type="text" id="npc"
                                                                 value="<?PHP echo $rpdt_npc; ?>" size="14">
                    </td>
                </tr>
            </table>

            <!-- SNMP ? -->
            <!-- WOL ? -->
            <table width="100%" border="0">
                <tr>
                    <td width="160" class="rubfrm" id="f_snmp" align="right">
                        <?PHP echo _("SNMP ?"); ?>
                    </td>
                    <td width="100">
                        <?PHP cre_select('snmp', 'snmp', $non_oui, $rpdt_snmp); ?>
                    </td>
                    <td width="160" class="rubfrm" id="f_wol" align="right">
                        <?PHP echo _("Wake-On-Lan ?"); ?>
                    </td>
                    <td>
                        <?PHP cre_select('wol', 'wol', $non_oui, $rpdt_wol); ?>
                    </td>
                </tr>
            </table>

            <!-- SID / WEP -->
            <table width="100%" border="0">
                <tr>
                    <td width="160" class="rubfrm" id="f_sid" rowspan="2" align="right">
                        <?PHP echo _("WiFi"); ?>
                    </td>
                    <td width="40" align="right">
                        <?PHP echo _("SID") . ' : '; ?>
                    </td>
                    <td>
                        <input name="sid" type="text" id="sid" value="<?PHP echo $rpdt_sid; ?>" size="80">
                    </td>
                </tr>
                <tr>
                    <td width="40" align="right">
                        <?PHP echo _("WEP") . ' : '; ?>
                    </td>
                    <td>
                        <input name="wep" type="text" id="wep" value="<?PHP echo $rpdt_wep; ?>" size="80">
                    </td>
                </tr>
            </table>
        </div>


        <div id="rpdt_telem">
            <!-- détail télémaintenance -->

            <!-- Type d'accès -->
            <table width="100%" border="0">
                <tr>
                    <td width="160" class="rubfrm" id="f_ta" align="right">
                        <?PHP echo _("Type d'accès"); ?>
                    </td>
                    <td>
                        <?PHP
                        $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
                        // création de la liste des types d'accès
                        $rech = "SELECT * FROM `" . TBRLPTMTA . "` ORDER BY rlptmta_desc";
                        $rows = $db->get_results($rech, ARRAY_A);
                        $db->disconnect();
                        cre_select_tab('codeta', 'codeta', $rows, 'rlptmta_code', 'rlptmta_desc', '', $rpdt_codeta, '', _("-- Faites votre choix --"));
                        ?>
                    </td>
                </tr>
            </table>

            <!-- Mode d'accès -->
            <table width="100%" border="0">
                <tr>
                    <td width="160" class="rubfrm" id="f_tma" align="right">
                        <?PHP echo _("Mode d'accès"); ?>
                    </td>
                    <td>
                        <?PHP cre_select('tma', 'tma', $maj_typesma, $rpdt_tma); ?>
                    </td>
                </tr>
            </table>

            <!-- Logiciel de télémaintenance -->
            <table width="100%" border="0">
                <tr>
                    <td width="160" class="rubfrm" id="f_tl" align="right">
                        <?PHP echo _("Logiciel télém."); ?>
                    </td>
                    <td>
                        <?PHP
                        $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
                        // création de la liste des logiciels télémaintenance
                        $rech = "SELECT * FROM `" . TBRLPTML . "` ORDER BY rlptml_desc";
                        $rows = $db->get_results($rech, ARRAY_A);
                        $db->disconnect();
                        cre_select_tab('codel', 'codel', $rows, 'rlptml_code', 'rlptml_desc', '', $rpdt_codel, '', _("-- Faites votre choix --"));
                        ?>
                    </td>
                </tr>
            </table>

            <!-- Mode service ? -->
            <table width="100%" border="0">
                <tr>
                    <td width="160" class="rubfrm" id="f_tser" align="right">
                        <?PHP echo _("Mode service ?"); ?>
                    </td>
                    <td>
                        <?PHP cre_select('tser', 'tser', $non_oui, $rpdt_tser); ?>
                    </td>
                </tr>
            </table>

            <!-- Lien accès -->
            <table width="100%" border="0">
                <tr>
                    <td width="160" class="rubfrm" id="f_tlien" align="right">
                        <?PHP echo _("Lien d'accès"); ?>
                    </td>
                    <td>
                        <input name="tlien" type="text" id="tlien" value="<?PHP echo $rpdt_tlien; ?>" size="40">
                    </td>
                </tr>
            </table>

            <!-- Login / MDP -->
            <table width="100%" border="0">
                <tr>
                    <td width="160" class="rubfrm" id="f_tlogin" align="right">
                        <?PHP echo _("Login / MDP"); ?>
                    </td>
                    <td>
                        <input name="tlogin" type="text" id="tlogin" value="<?PHP echo $rpdt_tlogin; ?>" size="40"> /
                        <input name="tmdp" type="text" id="tmdp" value="<?PHP echo $rpdt_tmdp; ?>" size="40">
                        <span id="nivpwt"></span>
                    </td>
                </tr>
            </table>

            <!-- Arrêt d'exploitation ? -->
            <table width="100%" border="0">
                <tr>
                    <td width="160" class="rubfrm" id="f_tae" align="right">
                        <?PHP echo _("Arrêt exploitation ?"); ?>
                    </td>
                    <td>
                        <?PHP cre_select('tae', 'tae', $non_oui, $rpdt_tae); ?>
                    </td>
                </tr>
            </table>

            <!-- Redémarrage ? -->
            <table width="100%" border="0">
                <tr>
                    <td width="160" class="rubfrm" id="f_tred" align="right">
                        <?PHP echo _("Redémarrage ?"); ?>
                    </td>
                    <td>
                        <?PHP cre_select('tred', 'tred', $non_oui, $rpdt_tred); ?>
                    </td>
                </tr>
            </table>
        </div>

        <div id="rpdt_maj">
            <!-- détail Mises à jour -->

            <!-- Mode  -->
            <table width="100%" border="0">
                <tr>
                    <td width="160" class="rubfrm" id="f_mode" align="right">
                        <?PHP echo _("Mode"); ?>
                    </td>
                    <td>
                        <?PHP
                        $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
                        // création de la liste des modes de mises à jour
                        $rech = "SELECT * FROM `" . TBRLPMM . "` ORDER BY rlpmm_desc";
                        $rows = $db->get_results($rech, ARRAY_A);
                        $db->disconnect();
                        cre_select_tab('codem', 'codem', $rows, 'rlpmm_code', 'rlpmm_desc', '', $rpdt_codem, '', _("-- Faites votre choix --"));
                        ?>
                    </td>
                </tr>
            </table>

            <!-- Fréquence et type  -->
            <table width="100%" border="0">
                <tr>
                    <td width="160" class="rubfrm" id="f_per" align="right">
                        <?PHP echo _("Fréquence / Type"); ?>
                    </td>
                    <td>
                        <?PHP
                        $tab_per = [];
                        // création de la liste des fréquence
                        $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
                        $rech = "SELECT * FROM `" . TBPER . "` ORDER BY per_nbj";
                        $rows = $db->get_results($rech, ARRAY_A);

                        if ($rows) {
                            foreach ($rows as $row) {
                                $row = encode_str($row);
                                extract($row);

                                if ($per_nbj <> 0)
                                    $txt_nbj = '(' . _("tous les") . ' ' . $per_nbj . ' ' . _("jours") . ')';
                                else
                                    $txt_nbj = '(' . _("à la demande") . ')';
                                $tab_per[$per_code] = $per_desc . ' ' . $txt_nbj;
                            }
                        }
                        $db->disconnect();
                        cre_select('mper', 'mper', $tab_per, $rpdt_mper, '', _("-- Faites votre choix --"), 1, FALSE, '', _("Pas de fréquence"));
                        echo ' / ';
                        cre_select('mtype', 'mtype', $maj_types, $rpdt_mmode, '', _("-- Faites votre choix --"));
                        ?>
                    </td>
                </tr>
            </table>

            <!-- Login / MDP -->
            <table width="100%" border="0">
                <tr>
                    <td width="160" class="rubfrm" id="f_mlogin" align="right">
                        <?PHP echo _("Login / MDP"); ?>
                    </td>
                    <td>
                        <input name="mlogin" type="text" id="mlogin" value="<?PHP echo $rpdt_mlogin; ?>" size="40"> /
                        <input name="mmdp" type="text" id="mmdp" value="<?PHP echo $rpdt_mmdp; ?>" size="40">
                        <span id="nivpwm"></span>
                    </td>
                </tr>
            </table>

            <!-- Date validité -->
            <table width="100%" border="0">
                <tr>
                    <td width="160" class="rubfrm" id="f_mdval" align="right">
                        <?PHP echo _("Date d'échéance"); ?>
                    </td>
                    <td>
                        <input name="mdvalf" type="text" id="mdvalf" value="<?PHP echo $rpdt_mdvalf ?>" size="10"
                               maxlength="10" readonly>
                        <img src="../img/raz.png" id="razmdvalf" border="0" align="absmiddle">
                        <span class="annot_petit_it">(Ne rien mettre si illimité)</span>
                        <?PHP
                        echo '<span id="warn_ech" style="display:none;">';
                        echo " <img src=\"../img/warn.png\" title =\"" . _("Echéance dépassée") . "\" border=\"0\" align=\"absmiddle\">";
                        echo '</span>';
                        ?>
                    </td>
                </tr>
            </table>

            <!-- Date dernière mise à jour -->
            <table width="100%" border="0">
                <tr>
                    <td width="160" class="rubfrm" id="f_mlmaj" align="right">
                        <?PHP echo _("Dernière mise à jour"); ?>
                    </td>
                    <td>
                        <input name="mdlmajf" type="text" id="mdlmajf" value="<?PHP echo $rpdt_mdlmajf ?>" size="10"
                               maxlength="10" readonly>
                        <img src="../img/raz.png" id="razmdlmajf" border="0" align="absmiddle">
                    </td>
                </tr>
            </table>

            <!-- Arrêt d'exploitation ? -->
            <table width="100%" border="0">
                <tr>
                    <td width="160" class="rubfrm" id="f_mae" align="right">
                        <?PHP echo _("Arrêt exploitation ?"); ?>
                    </td>
                    <td>
                        <?PHP cre_select('mae', 'mae', $non_oui, $rpdt_mae);
                        echo '<span class="annot_petit_it">' . _("Doit-on arrêter l'exploitation de ce matériel en cas de mise à jour ?") . '</span>';
                        ?>
                    </td>
                </tr>
            </table>

            <!-- Redémarrage ? -->
            <table width="100%" border="0">
                <tr>
                    <td width="160" class="rubfrm" id="f_mred" align="right">
                        <?PHP echo _("Redémarrage ?"); ?>
                    </td>
                    <td>
                        <?PHP cre_select('mred', 'mred', $non_oui, $rpdt_mred);
                        echo '<span class="annot_petit_it">' . _("Doit-on redémarrer ce matériel en cas de mise à jour ?") . '</span>';
                        ?>
                    </td>
                </tr>
            </table>
        </div>

        <div id="rpdt_cnx">
            <!-- Liste des connexions de ce matériel -->
            <table width="100%" border="0">
                <tr>
                    <td>
                        <?PHP
                        // création de la liste des connexions
                        $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
                        $rech = "SELECT * FROM `" . TBRPDT . "`, `" . TBMQUE . "`, `" . TBRPCAT . "` WHERE ";
                        $rech .= TBRPDT . ".rpdt_codema = " . TBMQUE . ".mque_code AND " . TBRPDT . ".rpdt_codecat = " . TBRPCAT . ".rpcat_code";
                        $rech .= " AND " . TBRPDT . ".rpdt_codecli='" . $rpdt_codecli . "' AND " . TBRPDT . ".rpdt_dateout='0000-00-00' AND " . TBRPDT . ".rpdt_code<>'" . $rpdt_code . "'";
                        $rech .= " ORDER BY " . TBRPDT . ".rpdt_code";
                        $rows = $db->get_results($rech, ARRAY_A);

                        if ($rows) {
                            echo '<a href="#" class="pop">' . _("Légende") . '<span>';
                            echo _("Connecté sur : Vous considérez que") . ' ' . $rpdt_code . ' ' . _("est un accessoire ou un périphérique du matériel") . '<br />';
                            echo _("Contrôleur de : Vous considérez le matériel est un accessoire ou un périphérique de") . ' ' . _("$rpdt_code") . '<br />';
                            echo _("Installé dans : Vous considérez que") . ' ' . $rpdt_code . ' ' . _("est installé dans le matériel") . '<br />';
                            echo _("Conteneur de : Vous considérez le matériel est installé dans") . ' ' . $rpdt_code . '<br />';
                            echo _("Relié à : Vous considérez que") . ' ' . $rpdt_code . ' ' . _("est relié au matériel (exemple du réseau)") . '<br />';
                            echo '</span></a>';

                            echo "<table class=\"MtableD\" border=\"0\" width=\"100%\" cellpadding=\"0\" cellspacing=\"0\">\n";

                            // création de l'entête de la table "détails connexions"
                            echo "<th>";
                            echo $rpdt_code . ' ' . _("est");
                            echo "</th>\n";
                            echo "<th>";
                            echo _("Code Fiche / Inventaire");
                            echo "</th>\n";
                            echo "<th>";
                            echo _("Catégorie");
                            echo "</th>\n";
                            echo "<th>";
                            echo _("Marque / Modèle / NS / Emplacement");
                            echo "</th>\n";

                            $j = 0;

                            foreach ($rows as $row) {
                                $row = encode_str($row);
                                // création de l'entête de ligne (TR)
                                creetrlstdet($j);

                                $rexist2 = "SELECT * FROM `" . TBCNX . "`  WHERE (cnx_p1 = '" . $rpdt_code . "' AND cnx_p2 = '" . $row["rpdt_code"] . "'";
                                $rexist2 .= " AND (cnx_type = '1' OR cnx_type = '2' OR cnx_type = '3' OR cnx_type = '4'))";
                                $rexist2 .= " OR ((cnx_p1 = '" . $rpdt_code . "' AND cnx_p2 = '" . $row["rpdt_code"] . "')";
                                $rexist2 .= " OR  (cnx_p1 = '" . $row["rpdt_code"] . "' AND cnx_p2 = '" . $rpdt_code . "')";
                                $rexist2 .= " AND cnx_type = '5')";
                                $row2 = $db->get_row($rexist2, ARRAY_A);
                                if ($row2) {
                                    $row2 = encode_str($row2);
                                    extract($row2);
                                } else
                                    $cnx_type = 0;

                                echo "<td align=\"center\">\n";
                                echo "<select id=\"" . $row["rpdt_code"] . "\" name=\"" . $row["rpdt_code"] . "\">";
                                foreach ($cnxm_types as $key => $value) {
                                    echo "<option value=\"" . $key . "\"";
                                    if ($key == $cnx_type)
                                        echo " selected=\"selected\"";
                                    echo ">" . $value . "</option>";
                                }
                                echo "</select>";
                                echo "</td>\n";

                                echo "<td>\n";
                                echo $row["rpdt_code"] . "<br />";
                                echo "(" . $row["rpdt_codep"] . ") ";
                                echo "</td>\n";

                                echo "<td>\n";
                                echo $row["rpcat_desc"];
                                echo "</td>\n";

                                echo "<td>\n";
                                echo $row["mque_ste"];
                                if ($row["rpdt_modele"] <> "") {
                                    echo "<br />";
                                    echo $row["rpdt_modele"];
                                }
                                if ($row["rpdt_empl"] <> "") {
                                    echo "<br />";
                                    echo _("Empl.") . ' : ' . $row["rpdt_empl"];
                                }
                                if ($row["rpdt_ns"] <> "") {
                                    echo "<br />";
                                    echo _("NS") . ' : ' . $row["rpdt_ns"];
                                }
                                echo "</td>\n";

                                echo "</tr>\n";

                                $j++;
                            }

                            echo "</table>\n";
                            // Fin affichage table détails licences

                            $taille_piedla = "small";
                            include_once("piedla.inc.php");
                        } else
                            echo _("Aucun matériel autre que celui-ci") . '<br />';
                        $db->disconnect();
                        ?>
                    </td>
                </tr>
            </table>
        </div>
        </form>

        <div id="rpdt_con">
            <!-- Liste des contrats gérant ce matériel -->
            <table width="100%" border="0">
                <tr>
                    <td>
                        <?PHP
                        // création de la liste des contrats actifs
                        $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
                        $rech = "SELECT * FROM `" . TBCOCL . "` WHERE `cocl_coderlp` LIKE '%" . $rpdt_code . "%'";
                        $rech .= " ORDER BY `cocl_code`";
                        $rows = $db->get_results($rech, ARRAY_A);

                        if ($rows) {
                            echo "<table class=\"MtableD\" border=\"0\" width=\"100%\" cellpadding=\"0\" cellspacing=\"0\">\n";

                            // création de l'entête de la table "détails contrats"
                            echo "<th>";
                            echo _("Code");
                            echo "</th>\n";
                            echo "<th>";
                            echo _("Créé le");
                            echo "</th>\n";
                            echo "<th>";
                            echo _("Début");
                            echo "</th>\n";
                            echo "<th>";
                            echo _("Fin");
                            echo "</th>\n";
                            echo "<th>";
                            echo _("Cliquer");
                            echo "</th>\n";

                            $j = 0;

                            foreach ($rows as $row) {
                                $row = encode_str($row);
                                // création de l'entête de ligne (TR)
                                creetrlstdet($j);

                                $echeance_ok = TRUE;
                                if (datetolocal($row["cocl_datef"]) <> "") {
                                    if (echeance_depassee_date($datea, $row["cocl_datef"]) == TRUE)
                                        $echeance_ok = FALSE;
                                }

                                echo "<td>" . $row["cocl_code"];

                                // CREATION d'icône si signé
                                if (datetolocal($row["cocl_datesig"]) <> "") {
                                    $lst_sig = TRUE;
                                    echo ' <img src="../img/ok.png" title ="' . _("signé le") . ' ' . datetolocal($row["cocl_datesig"]) . '" border="0" align="absmiddle">';
                                }

                                // CREATION d'icône si terminé
                                if ((datetolocal($row["cocl_datefin"]) <> "") OR ($echeance_ok == FALSE)) {
                                    $lst_fini = TRUE;
                                    if (datetolocal($row["cocl_datefin"]) <> "")
                                        echo ' <img src="../img/warn.png" title ="' . _("terminé le") . ' ' . datetolocal($row["cocl_datefin"]) . '" border="0" align="absmiddle">';
                                    else
                                        echo ' <img src="../img/warn.png" title ="' . _("terminé le") . ' ' . datetolocal($row["cocl_datef"]) . '" border="0" align="absmiddle">';
                                }

                                // détail contrat
                                echo "<br />";
                                echo "<span class=\"annot_petit_it\">";
                                $rech2 = "SELECT * FROM `" . TBCO . "` WHERE co_code = '" . $row["cocl_codeco"] . "'";
                                $row2 = $db->get_row($rech2, ARRAY_A);
                                if ($row2) {
                                    $row2 = encode_str($row2);
                                    $txt = formatetxt($row2["co_nom"]);
                                    echo "->" . $txt;
                                }

                                echo "</span>";
                                echo "</td>\n";

                                echo "<td>";
                                echo "<div align=\"center\">";
                                echo datetolocal($row["cocl_datecrea"]);
                                echo "</div>";
                                echo "</td>\n";
                                echo "<td>";
                                echo "<div align=\"center\">";
                                echo datetolocal($row["cocl_dated"]);
                                echo "</div>";
                                echo "</td>\n";
                                echo "<td>";
                                echo "<div align=\"center\">";
                                if (datetolocal($row["cocl_datef"]) == "")
                                    echo "&nbsp;";
                                else
                                    echo datetolocal($row["cocl_datef"]);
                                echo "</div>";
                                echo "</td>\n";

                                // CREATION lien dynamique sur icône (édition, impression, etc...)
                                echo "<td align=\"center\">";


                                if (@$_SESSION["niv_log"] >= 4) // Edition uniquement si >=agence
                                {
                                    if ((datetolocal($row["cocl_datefin"]) == "") AND ($echeance_ok == TRUE)) {
                                        $lst_maj = TRUE;
                                        cre_falselnk_img('', 'cocl_edit_'.$row["rpdt_id"], 'span', 'center', _("Edition"), 'lnk', 'cocl_maj.php?td=edit&co=' . $row["cocl_code"] . '&cc=' . $row["cocl_codecli"], '../img/edit.png');
                                    } else {
                                        $lst_voir = TRUE;
                                        cre_falselnk_img('', 'cocl_view_'.$row["rpdt_id"], 'span', 'center', _("Visualisation"), 'lnk', 'cocl_maj.php?td=view&co=' . $row["cocl_code"] . '&cc=' . $row["cocl_codecli"], '../img/eye.png');
                                    }
                                }

                                if (@$_SESSION["niv_log"] <= 3) // Voir si <=Technicien
                                {
                                    $lst_voir = TRUE;
                                    cre_falselnk_img('', 'cocl_view_'.$row["rpdt_id"], 'span', 'center', _("Visualisation"), 'lnk', 'cocl_maj.php?td=view&co=' . $row["cocl_code"] . '&cc=' . $row["cocl_codecli"], '../img/eye.png');
                                }

                                if (@$_SESSION["niv_log"] >= 3) // création intervention uniquement si  >=technicien et pas fini
                                {
                                    if ((datetolocal($row["cocl_datefin"]) == "") AND (datetolocal($row["cocl_datesig"]) <> "") AND ($echeance_ok == TRUE)) {
                                        $lst_int = TRUE;
                                        $url_int = "int_maj.php?td=add&ci=&cc=" . $row["cocl_codecli"] . "&ca=" . $row["cocl_codeage"] . "&co=" . $row["cocl_code"];
                                        cre_falselnk_img('', 'int_add_'.$row["rpdt_id"], 'span', 'center', _("Saisir intervention sur le contrat") . ' ' . $row["cocl_code"], 'lnk', $url_int, '../img/int.png');
                                    }
                                }

                                $lst_imp = TRUE;

                                $urlimp = "cocl_pdf.php?code=" . $row["cocl_code"];
                                cre_falselnk_img('', 'cocl_prn_'.$row["rpdt_id"], 'span', 'center', _("Impression"), 'lnkpop', $urlimp, '../img/print.png');

                                echo "</td>\n";

                                echo "</tr>\n";

                                $j++;
                            }

                            echo "</table>\n";
                            // Fin affichage table détails licences

                            $taille_piedla = "small";
                            include_once("piedla.inc.php");
                        } else
                            echo _("Aucun contrat couvrant ce matériel") . '<br />';
                        $db->disconnect();
                        ?>
                    </td>
                </tr>
            </table>
        </div>

        <div id="rpdt_pbm">
        <!-- Liste des problèmes déclarés -->
        <?PHP
        if (exist_rpbm($rpdt_code) == TRUE) {
            ?>
            <form name="pbm_lst" id="pbm_lst" method="post" action="rpdt_maj.php?td=<?PHP echo $td; ?>&cr=<?PHP echo $cr; ?>&cc=<?PHP echo $cc; ?>&crp=<?PHP echo $crp; ?>">
                <table width="100%" border="0">
                    <tr>
                        <td width="180" class="rubfrm" id="f_site"
                            align="right"><?PHP echo _("Filtre par lieu"); ?></td>
                        <td>
                            <?PHP
                            $tab_sites = [];
                            $tab_sites[-1] = _("Tous les sites");
                            $tab_sites[0] = _("Site Principal");

                            if ($cli_ste <> "")
                            {
                                // création de la liste des sites actifs
                                $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
                                $rech = "SELECT * FROM `" . TBSCLI . "` WHERE `scli_actif` = '1' AND `scli_codecli`='" . $cli_code . "' ORDER BY scli_ste";
                                $rows = $db->get_results($rech, ARRAY_A);

                                if ($rows) {
                                    foreach ($rows as $row) {
                                        $row = encode_str($row);
                                        extract($row);

                                        if ($scli_adr2 <> "")
                                            $nom_site = $scli_ste . " (" . $scli_adr1 . ", " . $scli_adr2 . ", " . Retournecp_Id($scli_ville, FALSE) . " " . Retourneville_Id($scli_ville, FALSE) . ")";
                                        else
                                            $nom_site = $scli_ste . " (" . $scli_adr1 . ", " . Retournecp_Id($scli_ville, FALSE) . " " . Retourneville_Id($scli_ville, FALSE) . ")";

                                        $tab_sites[$scli_id] = $nom_site;
                                    }
                                }
                                $db->disconnect();
                            }

                            cre_select('sitepbm', 'sitepbm', $tab_sites, $idscli);
                            ?>
                        </td>
                    </tr>
                    <tr>
                        <td width="180" class="rubfrm" id="f_pbm"
                            align="right"><?PHP echo _("Filtre par problèmes"); ?></td>
                        <td>
                            <?PHP
                            cre_select('pbms', 'pbms', $rel_typpbm, $pbm);
                            echo '<div class="annot_upetit_it">';
                            echo _("Avec pbm(s) non traité(s) = contient des problèmes non affectés à des interventions / Avec pbm(s) traité(s) ou en cours de traitement = contient des problème résolus ou affectés");
                            echo '</div>';
                            ?>
                        </td>
                    </tr>
                    <tr>
                        <td width="180" class="rubfrm" id="f_search"
                            align="right"><?PHP echo _("Filtre par mot"); ?></td>
                        <td>
                            <input type="text" id="search" name="search" value="<?PHP echo encode_str($search); ?>">
                            <img id="razsearch" src="../img/raz.png" border="0" align="absmiddle">
                        </td>
                    </tr>
                </table>
            </form>

            <table width="100%" border="0">
                <tr>
                    <td>
                        <span class="annot_gras_it"><?PHP echo _("Liste des problèmes déclarés sur ce matériel"); ?></span>
                        (<img src="../img/rpbmint.png" border="0" align="absmiddle">
                        = <?PHP echo _("en cours d'intervention"); ?>)
                    </td>
                    <td align="right">
                        <?PHP
                        if (($td <> "del") AND ($rpdt_dateoutf == "")) {
                            $url_add = "rpbm_maj.php?td=add&tr=2&cr=" . $rpdt_code . "&cap=1";
                            ?>
                            <a href="<?PHP echo $url_add; ?>"><img src="../img/add.png"
                                                                   title="<?PHP echo _("Déclarer un problème"); ?>"
                                                                   border="0" align="absmiddle"></a>
                            <a href="<?PHP echo $url_add; ?>"> <?PHP echo _("Déclarer un problème"); ?></a>
                        <?PHP } else { ?>
                            &nbsp;
                        <?PHP } ?>
                    </td>
                </tr>
            </table>

            <table width="100%" border="0">
                <tr>
                    <td>
                        <?PHP
                        // création de la liste des problèmes déclarés
                        $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);

                        switch ($pbm) {
                            case 0 :
                                $rech = "SELECT * FROM `" . TBRPBM . "` WHERE `rpbm_coderlp` = '" . $rpdt_code . "'";
                                break;
                            case 1 :
                                $rech = "SELECT * FROM `" . TBRPBM . "` WHERE `rpbm_coderlp` = '" . $rpdt_code . "'";
                                $rech .= " AND (" . TBRPBM . ".rpbm_codeint IS NULL)";
                                break;
                            case 2 :
                                $rech = "SELECT * FROM `" . TBRPBM . "` WHERE `rpbm_coderlp` = '" . $rpdt_code . "'";
                                $rech .= " AND (" . TBRPBM . ".rpbm_codeint IS NOT NULL)";
                                break;
                        }

                        if ($idscli != -1)
                            $rech .= " AND (" . TBRPBM . ".rpbm_idsite = '" . $idscli . "' OR " . TBRPBM . ".rpbm_idsite = '-1')";

                        if ($search <> '') {
                            $rech .= " AND (";
                            if (chkdate($search) == TRUE) {
                                $daterech = datetomysql($search);
                                $rech .= " rpbm_datecrea LIKE '%" . $db->escape($daterech) . "%' OR";
                                $rech .= " rpbm_datett LIKE '%" . $db->escape($daterech) . "%' OR";
                            }
                            $rech .= " rpbm_signale LIKE '%" . $db->escape($search) . "%' OR";
                            $rech .= " rpbm_pbm LIKE '%" . $db->escape($search) . "%' OR";
                            $rech .= " rpbm_codeint LIKE '%" . $db->escape($search) . "%' OR";
                            $rech = substr($rech, 0, strlen($rech) - 3);
                            $rech .= ")";
                        }
                        $rech .= " ORDER BY `rpbm_datecrea`";
                        $rows = $db->get_results($rech, ARRAY_A);

                        if ($rows) {
                            echo "<table class=\"MtableD\" border=\"0\" width=\"100%\" cellpadding=\"0\" cellspacing=\"0\">\n";

                            // création de l'entête de la table "détails problèmes"
                            echo "<th>";
                            echo _("Déclaré le");
                            echo "</th>\n";
                            echo "<th>";
                            echo _("Déclaré par");
                            echo "</th>\n";
                            echo "<th>";
                            echo _("Problème");
                            if ($idscli < 0)
                                echo '<div align="right">(' . _("site") . ')</div>';
                            echo "</th>\n";
                            echo "<th>";
                            echo _("Résolu le");
                            echo "</th>\n";
                            echo "<th>";
                            echo _("Cliquer");
                            echo "</th>\n";

                            $j = 0;

                            foreach ($rows as $row) {
                                $row = encode_str($row);
                                // création de l'entête de ligne (TR)
                                creetrlstdet($j);

                                echo "<td align=\"center\">\n";
                                echo datetolocal($row["rpbm_datecrea"]);
                                if (($row["rpbm_codeint"] <> "") AND (datetolocal($row["rpbm_datett"]) == ""))
                                    echo '<img src="../img/rpbmint.png" border="0" align="absmiddle" title ="' . _("Intervention") . ' ' . $row["rpbm_codeint"] . '" border="0">';
                                echo "</td>\n";
                                echo "<td>\n";
                                echo $row["rpbm_signale"];
                                echo "</td>\n";
                                echo "<td>\n";
                                $tab_txtpbm = cesuretxt_tab($row["rpbm_pbm"], 100);
                                $txtpbm = "";
                                foreach ($tab_txtpbm as $index_ligne => $ligne)
                                    $txtpbm .= $ligne . "<br />";
                                echo $txtpbm;
                                if ($idscli < 0) {
                                    if ($row["rpbm_idsite"] <> 0) {
                                        $row2 = lit_enr_scli_id($row["rpbm_idsite"], FALSE);
                                        if (is_array($row2)) {
                                            $row2 = encode_str($row2);
                                            extract($row2);
                                            echo "<div align=\"right\" class=\"annot_petit_it\">";
                                            if ($scli_adr2 <> "")
                                                $nom_site = $scli_ste . "<br />" . $scli_adr1 . "<br />" . $scli_adr2 . "<br />" . Retournecp_Id($scli_ville, FALSE) . " " . Retourneville_Id($scli_ville, FALSE);
                                            else
                                                $nom_site = $scli_ste . "<br />" . $scli_adr1 . "<br />" . Retournecp_Id($scli_ville, FALSE) . " " . Retourneville_Id($scli_ville, FALSE);
                                            echo $nom_site;
                                            echo "</div>";
                                        }
                                    } else {
                                        echo "<div align=\"right\" class=\"annot_petit_it\">";
                                        echo _("Site principal");
                                        echo "</div>";
                                    }
                                }
                                echo "</td>\n";
                                echo "<td align=\"center\">\n";
                                if (datetolocal($row["rpbm_datett"]) <> "") {
                                    echo datetolocal($row["rpbm_datett"]);
                                    echo "<span class=\"annot_petit_it\">";
                                    echo '<br />' . _("Int.") . ' ' . $row["rpbm_codeint"];
                                    echo "</span>";
                                } else
                                    echo "&nbsp;";
                                echo "</td>\n";

                                echo "<td align=\"center\">\n";
                                if ($td <> "del") {
                                    // On peut éditer ou supprimer uniquement si aucune intervention n'est rattachée
                                    // et si la fiche n'est pas sortie du parc
                                    if (($row["rpbm_codeint"] == "") AND ($rpdt_dateoutf == "")) {
                                        $lst_maj = TRUE;
                                        cre_falselnk_img('', 'rpbm_edit_'.$row["rpdt_id"], 'span', 'center', _("Edition"), 'lnk', 'rpbm_maj.php?td=edit&tr=2&cr=' . $cr.'&crp='.$row["rpbm_coderlp"] . '&id=' . $row["rpbm_id"] . '&cap=1', '../img/edit.png');
                                        $lst_del = TRUE;
                                        cre_falselnk_img('', 'rpbm_del_'.$row["rpdt_id"], 'span', 'center', _("Suppression"), 'lnk', 'rpbm_maj.php?td=del&tr=2&cr=' . $cr.'&crp='.$row["rpbm_coderlp"] . '&id=' . $row["rpbm_id"] . '&cap=1', '../img/del.png');
                                    } else {
                                        $lst_voir = TRUE;
                                        cre_falselnk_img('', 'rpbm_view_'.$row["rpdt_id"], 'span', 'center', _("Visualisation"), 'lnk', 'rpbm_maj.php?td=view&tr=2&cr=' . $cr.'&crp='.$row["rpbm_coderlp"] . '&id=' . $row["rpbm_id"] . '&cap=1', '../img/eye.png');
                                    }
                                } else {
                                    echo "-";
                                }
                                echo "</tr>\n";

                                $j++;
                            }

                            echo "</table>\n";
                            // Fin affichage table détails licences

                            $taille_piedla = "small";
                            include_once("piedla.inc.php");
                        } else
                            echo _("Aucun problème avec le filtre demandé") . '<br />';
                        $db->disconnect();
                        ?>
                    </td>
                </tr>
            </table>
        <?PHP
        } else {
            if ($td <> "add") {
                ?>
                <table width="100%" border="0">
                    <tr>
                        <td>
                            <span class="annot_gras_it"><?PHP echo _("Aucun problème déclaré"); ?></span>
                        </td>
                        <td align="right">
                            <?PHP
                            if (($td <> "del") AND ($rpdt_dateoutf == "")) {
                                $url_add = "rpbm_maj.php?td=add&tr=2&cr=" . $rpdt_code . "&cap=1";
                                if (url_ok($url_add, TRUE) == TRUE)
                                    cre_falselnk('', 'add_pbm', 'span', '', _("Déclarer un problème"), $url_add, '../img/add.png', _("Déclarer un problème"));
                                else
                                    echo "&nbsp;";
                            } else
                                echo "&nbsp;";
                            ?>
                        </td>
                    </tr>
                </table>
            <?PHP
            }
        }
        ?>
        </div>

        <!-- Fin affiché uniquement s'il y a un code client -->
    <?PHP
    } else
        pop_ret_auto(_("Merci de choisir un client"), 'warn', $lnk_cli_lst);
} else {
    if (@$_SESSION["niv_log"] == 1)
        pop_ret_auto(_("Merci de choisir votre compte"), 'warn', "index.php");
    else
        pop_ret_auto(_("Problème de paramètres"), 'warn', "rel_lst.php");
}
include_once("pied.php");
?>
</body>
</html>