<?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/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_tac.inc.php");
include_once("../inc/fic_tec.inc.php");
include_once("../inc/fic_zc.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/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é
$cc = $_GET['cc']; // Récupération code Client
$select_age = TRUE;
$pbm_rel = FALSE;
$tab_cli = [];
$pbm = 0;
$idscli = -1;
$valg = 0;
$search = '';
$tab_cli = give_tab_rcli($_SESSION["code_log"], TRUE);

// Pour affichage de l'alert en cas de problème non affecté
$affwarn = TRUE;

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

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

// Récupération filtre validité/garantie
if (isset($_POST["valg"])) {
    $valg = intval($_POST['valg']);
    $affwarn = FALSE;
}

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


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

if ($cr <> "") {
    // Récupération des informations dossier relevé
    $row = lit_enr_rel($cr);
    if (is_array($row)) {
        $row = encode_str($row);
        extract($row);

        if ($td <> "add") {
            // Vérification des tentatives de hack
            switch (@$_SESSION["niv_log"]) {
                case 1 :
                    if ($rel_codecli <> $_SESSION["code_log"])
                        $pbm_rel = TRUE;
                    break;
                case 3 :
                    if ($rel_codeage <> $_SESSION["code_age"])
                        $pbm_rel = TRUE;
                    break;
                case 4 :
                    if ($rel_codeage <> $_SESSION["code_log"])
                        $pbm_rel = TRUE;
                    break;
                default :
                    break;
            }
        }

        if ($pbm_rel == FALSE) {
            $rel_datecreaf = datetolocal($rel_datecrea);
            $rel_datemodf = datetolocal($rel_datemod);
            $cc = $rel_codecli;

            $row = lit_enr_cli($rel_codecli, TRUE);
            if (is_array($row)) {
                $row = encode_str($row);
                extract($row);
                $ca = $cli_prop;
            }
        }
    } else
        $pbm_rel = TRUE;
} else {
    if (@$_SESSION["niv_log"] <> 1){
        if ($td <> "add")
            $pbm_rel = TRUE;
    }
}

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

            // Contrôle qu'on n'essaye pas de "hacker" un client
            switch (@$_SESSION["niv_log"]) {
                case 1 :
                    $tab_cli = give_tab_rcli($_SESSION["code_log"], TRUE);
                    if (exist_in_array($cc, $tab_cli) == FALSE)
                        $pbm_rel = TRUE;
                    $select_age = FALSE;
                    break;
                case 3 :
                case 4 :
                    if (client_age_ok($cli_code, @$_SESSION["code_age"], TRUE) == FALSE)
                        $pbm_rel = TRUE;
                    // On force l'agence
                    $select_age = FALSE;
                    $rel_codeage = @$_SESSION["code_age"];
                    break;
                default :
                    // Si agence propriétaire, on ne peut pas choisir l'agence
                    if (trim($cli_prop) <> NULL) {
                        $select_age = FALSE;
                        $rel_codeage = $cli_prop;
                    }
                    break;
            }

            $ca = $cli_prop;
        } else
            $pbm_rel = TRUE;
    } else
        $pbm_rel = TRUE;
}

switch ($td) {
    case "add" :
        $titre = _("CREATION DOSSIER RELEVE");
        break;
    case "edit" :
        $titre = _("MISE A JOUR DOSSIER RELEVE");
        if ($rel_codecli <> $cc)
            $pbm_rel = TRUE;
        break;
    case "view" :
        $titre = _("VOIR RELEVE DE PARC");
        if ($rel_codecli <> $cc)
            $pbm_rel = TRUE;
        break;
    case "del" :
        $titre = _("SUPPRESSION DOSSIER RELEVE");
        if ($rel_codecli <> $cc)
            $pbm_rel = TRUE;
        break;
    default :
        $pbm_rel = 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 _("Dossier Relevé"); ?></title>

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

    <script language="javascript">
        <!--
        var tab1_champ = ["nom:datecreaf ; 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:rnum ; format:alphanum ; req:Y ; txt:<?PHP echo _("Racine codage"); ?> ; stok:frmok ; stbad:frmbad",
            "nom:num ; format:unsigned ; req:Y ; txt:<?PHP echo _("Dernier Numéro machine"); ?> ; lmx:4 ; stok:frmok ; stbad:frmbad",
            "nom:nota ; format:txt ; req:N ; txt:<?PHP echo _("Notes"); ?> ; 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"); ?>"
            });
        }

        function init_all() {
            init_Body();
            $( "#onglets_relg" ).tabs();
            init_autohref('tac', 'change','',false);
            init_autohref('decl_pbm', 'click', '', true);
            init_autohref('add_rlic','click','',true);
            init_autohref('add_rpdt','click','',true);
            init_datepicker();
            <?php
            switch ($td)
            {
                case "add" :
                    echo '$("#datecreaf").datepicker({';
                    echo '    onSelect: function (datesel) {';
                    echo '        $("#datecreaf").blur();';
                    echo '    },';
                    echo '});';
                    echo "init_autoraz('razdatecreaf','datecreaf','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_typlic()."type','','back','','');";
                    echo "init_warn('".nb_media()."media','','back','','');";
                    echo "init_warn('".nb_etatpdt()."etatpdt','','back','','');";
                    echo "init_warn('".nb_catpdt()."catpdt','','back','','');";
                    echo "init_warn('".nb_age_actives()."age','','back','','');";
                    if ($select_age == FALSE)
                        echo "readonly_id('codeage',false);";
                    echo "init_valid_form('enr','rel_maj','".$_SESSION['date_fmtshort']."',tab1_champ,'','');";
                    echo "init_valid_form('enrimp','rel_maj','".$_SESSION['date_fmtshort']."',tab1_champ,'','');";
                    break;
                case "edit" :
                    if ($affwarn == TRUE)
                    {
                        if (exist_rpbm_actif("add", $cli_code, "") == TRUE)
                            echo "init_warn('rpbm','','','','');";
                    }

                    if (@$_SESSION["niv_log"] >= 3)
                        echo 'warn_cpta('.$cli_cpta.',"rel");';
                    if ($select_age == FALSE)
                        echo "readonly_id('codeage',false);";
                    echo "init_new_fen('etats','impression');";
                    echo "init_new_fen('imprim1','impression','click');";
                    echo "init_new_fen('imprim2','impression','click');";
                    echo "init_valid_form('enr','rel_maj','".$_SESSION['date_fmtshort']."',tab1_champ,'','');";
                    echo "init_valid_form('enrimp','rel_maj','".$_SESSION['date_fmtshort']."',tab1_champ,'','');";
                    break;
                case "del" :
                    echo "warn_del('');";
                    echo "readonly_all();";
                    break;
                case "view" :
                    if (@$_SESSION["niv_log"] >= 3)
                        echo 'warn_cpta('.$cli_cpta.',"rel");';
                    echo "init_new_fen('etats','impression');";
                    echo "init_new_fen('imprim1','impression','click');";
                    echo "init_new_fen('imprim2','impression','click');";
                    echo "readonly_all();";
                    echo "$('#etats').attr('disabled', false);";
                    break;
            }
            echo "init_fensaisie('aff_notesc',930,380);";
            ?>
            init_autosubmit('search','change','rel_lst');
            init_autoraz('razsearch','search','click');
            init_autosubmit('razsearch','click','rel_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>
<!-- affiché uniquement s'il y a un code client -->
<?PHP
if ($pbm_rel == FALSE) {
?>
    <table width="100%" border="0">
        <tr>
            <td width="33%">
                <?PHP
                $aff_liste = TRUE;
                switch (@$_SESSION["niv_log"]) {
                    case 1 :
                        if (count($tab_cli) == 1)
                            $aff_liste = FALSE;
                        break;
                }
                if ($aff_liste == TRUE) {
                    aff_lnk_lst_rech('rel_lst.php', _("Retour à la liste"), $_SERVER['HTTP_REFERER'], _("Retour à la page précédente"));
                    echo ' / ';
                }
                ?>
                <a href="#LST"
                    onclick="show_hide('detail', 'pas_detail');"><?PHP echo _("Licences & Matériels"); ?></a>
                <?PHP
                if (@$_SESSION["niv_log"] == 1)
                    cre_falselnk('', 'decl_pbm', 'span', '', '', 'dpbm.php?cc=' . $rel_codecli, '', _("Déclarer problème"), TRUE);
                ?>
            </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")) {
                    $urlimp = "rel_pdf.php?cr=" . $cr . "&pbm=0";
                    if (url_ok($urlimp, TRUE) == TRUE) {
                        echo '<select name="etats" size="1" id="etats" class="annot_petit">';
                        echo '<option value="" selected>&#187; ' . _("Etats") . ' &#171;</option>';

                        echo "<option value=\"" . $urlimp . "\" class=\"icone\" style=\"background-image: url(../img/sel_print.gif);\">" . _("Relevé") . "</option>\n";

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

    <form name="rel_maj" id="rel_maj" method="post" action="rel_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 $cc ?>">
    <input name="nbutton" type="hidden" id="nbutton" value="">
    <?PHP
    if ($td == "add")
        echo '<input name="code" type="hidden" id="code" value="'.$rel_code.'">';
    ?>
    <!-- Date de création -->
    <table width="100%" border="0">
        <tr>
            <td width="160" class="rubfrm" id="f_datecreaf" align="right"><?PHP echo _("Date Création"); ?> </td>
            <td>
                <input name="datecreaf" type="text" id="datecreaf" value="<?PHP echo $rel_datecreaf ?>" size="10"
                       maxlength="10" readonly>
                <?PHP
                if ($td == "add") {
                    echo '<img src="../img/oblig.png" align="absmiddle" alt="' . _("Champ obligatoire") . '">';
                    echo ' <img src="../img/raz.png" id ="razdatecreaf" border="0" align="absmiddle">';
                }
                ?>
            </td>
            <td align="right">
                <?PHP
                if (((@$_SESSION["niv_log"] == 5) OR (@$_SESSION["niv_log"] == 9) OR (@$_SESSION["niv_log"] == 4) OR (@$_SESSION["niv_log"] == 3)) AND ($td == "edit")) {
                    echo '<span id="strtac" style="visibility:visible">';
                    $nb_tac = nb_tac(5, $rel_code, TRUE);
                    if ($nb_tac > 0) {
                        echo "<span class=\"annot_petit_it\">";
                        if ($nb_tac > 1)
                            echo "( " . $nb_tac . " " . _("tâches");
                        else
                            echo "( " . $nb_tac . " " . _("tâche");
                        $nb_tac_actives = nb_tac_actives(5, $rel_code, TRUE);
                        if ($nb_tac_actives > 0) {
                            if ($nb_tac_actives > 1)
                                echo ", dont " . $nb_tac_actives . " non terminées";
                            else
                                echo ", dont " . $nb_tac_actives . " non terminée";
                        }
                        echo ")";
                        echo "</span>";
                    } else {
                        echo "<span class=\"annot_petit_gras\">";
                        echo _("Tâches") . " : ";
                        echo "</span>";
                    }
                    echo '</span>';

                    $tab_tac = [];
                    if ($nb_tac > 0) {
                        $url = 'tac_lst.php?ord=DES&tri=Code&fi=8&search=' . $ot_code;
                        if (url_ok($url, TRUE) == TRUE)
                            $tab_tac[$url] = _("Voir");
                    }
                    $url = 'tac_maj.php?td=add&tr=5&cr=' . $rel_code;
                    if (url_ok($url, TRUE) == TRUE)
                        $tab_tac[$url] = _("Ajouter");
                    cre_select('tac', 'tac', $tab_tac, '', '', _("-- Faites votre choix --"), 1, FALSE, '', '', '', TRUE);
                } else
                    echo "&nbsp;";
                ?>
            </td>
        </tr>
    </table>

    <!-- Code du relevé client (affiché uniquement si édition ou suppression) -->
    <?PHP if ($td <> "add") { ?>
        <table width="100%" border="0">
            <tr>
                <td width="160" class="rubfrm" id="f_coderlic" align="right"><?PHP echo _("Code"); ?></td>
                <td>
                    <input name="code" type="text" id="code" value="<?PHP echo $rel_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;
                    if (url_ok($url_affnotesc, TRUE) == TRUE)
                        cre_falselnk('', 'aff_notesc', 'span', '', _("Notes"), $url_affnotesc, '../img/eye.png', _("Notes"));
                } else
                    echo "&nbsp;";
                ?>
            </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 _("Géré par (Agence)"); ?></td>
            <td>
                <?PHP
                $tab_age = give_tab_age_cli($cli_code);
                cre_select('codeage', 'codeage', $tab_age, $rel_codeage, '', _("-- Faites votre choix --"), 1, FALSE, '', _("-- Pas d'agence --"), TRUE, TRUE);
                ?>
            </td>
        </tr>
    </table>

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

    <!-- Codage des machines-->
    <table width="100%" border="0">
        <tr>
            <td width="160" class="rubfrm" id="f_codemach" align="right"><?PHP echo _("Codage inventaire"); ?></td>
            <td>
                <?PHP
                if (($td <> "view") and ($td <> "del")) {
                    ?>
                    <?PHP echo _("Racine codage"); ?> :
                    <input name="rnum" type="text" id="rnum" value="<?PHP echo $rel_rnum ?>" size="10"
                           maxlength="10">
                    <img src="../img/oblig.png" align="absmiddle"
                         alt="<?PHP echo _("Champ obligatoire"); ?>">        /
                    <?PHP echo _("Dernier numéro machines"); ?> :
                    <?PHP
                    if (nb_rpdtc($cc) == 0) {
                        ?>
                        <input name="num" type="text" id="num" value="<?PHP echo $rel_num ?>" size="4"
                               maxlength="4">
                        <img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo _("Champ obligatoire"); ?>">
                    <?PHP
                    } else {
                        ?>
                        <input name="num" type="text" id="num" value="<?PHP echo $rel_num ?>" size="4" maxlength="4" readonly>
                        <div class="annot_petit_it">(<?PHP echo _("Dernier numéro non modifiable car des relevés machines ont déjà été saisis"); ?>)</div>
                    <?PHP
                    }
                } else {
                    ?>
                    <?PHP echo _("Racine codage"); ?> :
                    <input name="rnum" type="text" id="rnum" value="<?PHP echo $rel_rnum ?>" size="10" maxlength="10" readonly>
                    /
                    <?PHP echo _("Dernier numéro machines"); ?> :
                    <input name="num" type="text" id="num" value="<?PHP echo $rel_num ?>" size="4" maxlength="4" readonly>
                <?PHP
                }
                ?>
            </td>
        </tr>
    </table>

    <!-- Notes -->
    <table width="100%" border="0">
        <tr>
            <td width="160" valign="top" class="rubfrm" id="f_nota" align="right"><?PHP echo _("Notes"); ?></td>
            <td>
                <textarea name="nota" rows="5" id="nota"><?PHP echo $rel_nota ?></textarea>
            </td>
        </tr>
        <tr>
        <td colspan="2" align="center">
            <?PHP
            switch ($td)
            {
                case "add" :
                case "edit" :
                    echo '<input name="RAZ" type="reset" class="bton_std" id="RAZ" value="'._("Réinitialiser").'">';
                    echo '<input name="enr" type="button" class="bton_std" id="enr" value="'._("Enregistrer").'">';
                    echo '<input name="enrimp" type="button" class="bton_std" id="enrimp" value="'._("Enregistrer & Imprimer").'">';
                    break;
                case "del" :
                    echo '<input name="del" type="submit" class="bton_std" id="del" value="'._("Supprimer").'">';
                    break;
            }
            ?>
        </td>
        </tr>
    </table>
    </form>
    <br />

    <?PHP
    if (($td <> "add") AND ($td <> "del")) // Affichage du détail uniquement en édition ou visualisation
    {
        ?>
        <form name="rel_lst" id="rel_lst" method="post" action="rel_maj.php?td=<?PHP echo $td; ?>&cr=<?PHP echo $cr; ?>&cc=<?PHP echo $cc; ?>&ca=<?PHP echo $ca; ?>#detlm">
            <!-- Filtre sur site -->
            <table width="100%" border="0">
                <tr>
                    <td width="100%" class="rubfrm" colspan="2">
                        <a name="detlm"></a>

                        <div align="center"><a name="LST"></a><?PHP echo _("LISTE DES LICENCES & MATERIELS"); ?>
                        </div>
                    </td>
                </tr>
                <tr>
                    <td width="180" class="rubfrm" id="f_site"
                        align="right"><?PHP echo _("Filtre par lieu"); ?></td>
                    <td>
                        <?PHP
                        if ($cli_ste <> "") {
                            echo '<select name="site" id="site" onChange="document.getElementById(\'rel_lst\').submit();">';
                            echo '<option value="-1"';
                            if ($idscli == -1)
                                echo ' selected';
                            echo '>' . _("Tous les sites") . '</option>';
                            echo '<option value="0"';
                            if ($idscli == 0)
                                echo ' selected';
                            echo '>' . _("Site principal") . '</option>';

                            // 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) . ")";
                                    echo '<option value="' . $scli_id . '"';
                                    if ($idscli == $scli_id)
                                        echo ' selected';
                                    echo '>' . $nom_site . '</option>';
                                }
                            }
                            $db->disconnect();
                            echo '</select>';
                            if ($idscli <> -1) {
                                $urlimp1 = "rel_pdf.php?cr=" . $cr . "&pbm=0&site=" . $idscli;
                                if (url_ok($urlimp1) == TRUE) {
                                    echo '<span id="imprim" align="right" title="' . $urlimp1 . '" class="falselnk">';
                                    echo '<img src="../img/print.png" title="' . _("Imprimer relevé du site") . '" border="0" align="absmiddle">';
                                    echo '</span>';
                                }

                                $urlimp2 = "rel_pdf.php?cr=" . $cr . "&pbm=1&site=" . $idscli;
                                if (url_ok($urlimp2) == TRUE) {
                                    echo ' <span id="imprim" align="right" title="' . $urlimp2 . '" class="falselnk">';
                                    echo '<img src="../img/printc.png" title="' . _("Imprimer relevé du site avec détail problèmes") . '" border="0" align="absmiddle">';
                                    echo '</span>';
                                }
                            }
                        } else {
                            echo '<input name="site" type="hidden" id="site" value="0">';
                            echo '<input name="nsite" type="text" id="nsite" value="' . _("Site principal") . '" readonly>';
                        }
                        ?>
                    </td>
                </tr>
                <tr>
                    <td width="180" class="rubfrm" id="f_pbm"
                        align="right"><?PHP echo _("Filtre par problèmes"); ?></td>
                    <td>
                        <input type="radio" name="pbms" style="background : #FFFFFF;"
                               value="0" <?PHP if ($pbm == 0) echo "checked" ?>
                               onClick="document.getElementById('rel_lst').submit();">
                        <?PHP if ($pbm == 0) echo "<span class=\"annot_petit_gras\">"; else echo "<span class=\"annot_petit\">";
                        echo _("Toutes les fiches");
                        echo "</span>"; ?>
                        <input type="radio" name="pbms" style="background : #FFFFFF;"
                               value="1" <?PHP if ($pbm == 1) echo "checked" ?>
                               onClick="document.getElementById('rel_lst').submit();">
                        <?PHP if ($pbm == 1) echo "<span class=\"annot_petit_gras\">"; else echo "<span class=\"annot_petit\">";
                        echo _("Avec pbm(s) non traité(s)");
                        echo "</span>"; ?>
                        <input type="radio" name="pbms" style="background : #FFFFFF;"
                               value="2" <?PHP if ($pbm == 2) echo "checked" ?>
                               onClick="document.getElementById('rel_lst').submit();">
                        <?PHP if ($pbm == 2) echo "<span class=\"annot_petit_gras\">"; else echo "<span class=\"annot_petit\">";
                        echo _("Avec pbms(s) traité(s) ou en cours de traitement");
                        echo "</span>"; ?>
                        <br />
<span class="annot_upetit_it">
(<?PHP 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"); ?>
    )
</span>
                    </td>
                </tr>
                <tr>
                    <td width="180" class="rubfrm" id="f_pbm"
                        align="right"><?PHP echo _("Filtre par validité/gtie"); ?></td>
                    <td>
                        <input type="radio" name="valg" style="background : #FFFFFF;"
                               value="0" <?PHP if ($valg == 0) echo "checked" ?>
                               onClick="document.getElementById('rel_lst').submit();">
                        <?PHP if ($valg == 0) echo "<span class=\"annot_petit_gras\">"; else echo "<span class=\"annot_petit\">"; ?>
                        <?PHP echo _("Toutes les fiches"); ?>
                        <?PHP echo "</span>"; ?>
                        <input type="radio" name="valg" style="background : #FFFFFF;"
                               value="1" <?PHP if ($valg == 1) echo "checked" ?>
                               onClick="document.getElementById('rel_lst').submit();">
                        <?PHP if ($valg == 1) echo "<span class=\"annot_petit_gras\">"; else echo "<span class=\"annot_petit\">"; ?>
                        <?PHP echo _("Echéance <=30 jours"); ?>
                        <?PHP echo "</span>"; ?>
                        <input type="radio" name="valg" style="background : #FFFFFF;"
                               value="2" <?PHP if ($valg == 2) echo "checked" ?>
                               onClick="document.getElementById('rel_lst').submit();">
                        <?PHP if ($valg == 2) echo "<span class=\"annot_petit_gras\">"; else echo "<span class=\"annot_petit\">"; ?>
                        <?PHP echo("Echéance <=60 jours"); ?>
                        <?PHP echo "</span>"; ?>
                        <input type="radio" name="valg" style="background : #FFFFFF;"
                               value="3" <?PHP if ($valg == 3) echo "checked" ?>
                               onClick="document.getElementById('rel_lst').submit();">
                        <?PHP if ($valg == 3) echo "<span class=\"annot_petit_gras\">"; else echo "<span class=\"annot_petit\">"; ?>
                        <?PHP echo _("Echéance dépassée"); ?>
                        <?PHP echo "</span>"; ?>
                        <br />
<span class="annot_upetit_it">
(<?PHP echo _("'Echéance <=xx jours' = Dont la date de validité ou de garantie est supérieure ou égale à aujourd'hui et inférieure ou égale à xx jours"); ?>
    )
</span>
                    </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>
        <a name="PBM"></a>

        <div id="onglets_relg">
        <ul>
            <li><a href="#relg_lic"><?PHP echo _("Licences"); ?></a></li>
            <li><a href="#relg_mat"><?PHP echo _("Matériels"); ?></a></li>
        </ul>
        <div id="relg_lic">
        <table width="100%" border="0" cellspacing="0" cellpadding="0">
            <tr>
                <td>
                    <span
                        class="annot_petit_it">(<?PHP echo _("Laisser la souris sur les icônes pour le détail"); ?>
                        )</span>
                </td>
                <td align="right">
                    <?PHP
                    $lst_maj = FALSE;
                    $lst_voir = FALSE;
                    $lst_pbmrel = FALSE;
                    $lst_imp = FALSE;
                    $lst_impp = FALSE;
                    $lst_del = FALSE;
                    if (($td <> "del") and ($td <> "view")) {
                        $url_add = "rlic_maj.php?td=add&cc=" . $rel_codecli."&cr=".$rel_code;
                        if (url_ok($url_add, TRUE) == TRUE)
                            cre_falselnk('', 'add_rlic', 'span', '', _("Ajouter fiche licence"), $url_add, '../img/add.png', _("Ajouter fiche licence"));
                        /*
                        {
                            echo '<a href="' . $url_add . '"><img src="../img/add.png" title ="Ajouter fiche licence" border="0" align="absmiddle">';
                            echo ' ' . _("Ajouter fiche Licence") . '</a>';
                        }
                        */
                    } else
                        echo "&nbsp;";
                    ?>
                </td>
            </tr>
        </table>
        <?PHP
        $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);

        switch ($pbm) {
            case 0 :
                $rech = "SELECT * FROM `" . TBRLIC . "`, `" . TBMQUE . "` WHERE " . TBRLIC . ".rlic_codecli = '" . $rel_codecli . "' AND " . TBRLIC . ".rlic_codema = " . TBMQUE . ".mque_code";
                break;
            case 1 :
                $rech = "SELECT DISTINCT " . TBRLIC . ".rlic_code, " . TBRLIC . ".rlic_codecli, " . TBRLIC . ".rlic_dateout, " . TBRLIC . ".rlic_maxcli, " . TBRLIC . ".rlic_daterel, ";
                $rech .= TBRLIC . ".rlic_codema, " . TBRLIC . ".rlic_modele, " . TBRLIC . ".rlic_version, " . TBRLIC . ".rlic_dateval, " . TBRLIC . ".rlic_legal, ";
                $rech .= TBRPBM . ".rpbm_coderlp, " . TBRPBM . ".rpbm_codeint, ";
                $rech .= TBMQUE . ".mque_ste ";
                $rech .= "FROM `" . TBRLIC . "`, `" . TBRPBM . "`, `" . TBMQUE . "`";
                $rech .= " WHERE " . TBRLIC . ".rlic_codecli = '" . $rel_codecli . "' AND " . TBRLIC . ".rlic_code = " . TBRPBM . ".rpbm_coderlp AND " . TBRLIC . ".rlic_codema = " . TBMQUE . ".mque_code";
                $rech .= " AND (" . TBRPBM . ".rpbm_codeint IS NULL)";
                break;
            case 2 :
                $rech = "SELECT DISTINCT " . TBRLIC . ".rlic_code, " . TBRLIC . ".rlic_dateout, " . TBRLIC . ".rlic_maxcli, " . TBRLIC . ".rlic_daterel, ";
                $rech .= TBRLIC . ".rlic_codema, " . TBRLIC . ".rlic_modele, " . TBRLIC . ".rlic_version, " . TBRLIC . ".rlic_dateval, " . TBRLIC . ".rlic_legal, ";
                $rech .= TBRPBM . ".rpbm_coderlp, " . TBRPBM . ".rpbm_codeint, ";
                $rech .= TBMQUE . ".mque_ste ";
                $rech .= "FROM `" . TBRLIC . "`, `" . TBRPBM . "`, `" . TBMQUE . "`";
                $rech .= " WHERE " . TBRLIC . ".rlic_codecli = '" . $rel_codecli . "' AND " . TBRLIC . ".rlic_code = " . TBRPBM . ".rpbm_coderlp AND " . TBRLIC . ".rlic_codema = " . TBMQUE . ".mque_code";
                $rech .= " AND (" . TBRPBM . ".rpbm_codeint IS NOT NULL)";
                break;
        }

        switch ($valg) {
            case 0 :
                break;
            case 1 :
                $nouvdate = nouv_date_plus_jours($datea, 30);
                $rech .= " AND (" . TBRLIC . ".rlic_dateval <= '" . $nouvdate . "' AND " . TBRLIC . ".rlic_dateval >= '" . $datea . "' AND " . TBRLIC . ".rlic_dateval <> '0000-00-00' AND " . TBRLIC . ".rlic_dateout = '0000-00-00')";
                break;
            case 2 :
                $nouvdate = nouv_date_plus_jours($datea, 60);
                $rech .= " AND (" . TBRLIC . ".rlic_dateval <= '" . $nouvdate . "' AND " . TBRLIC . ".rlic_dateval >= '" . $datea . "' AND " . TBRLIC . ".rlic_dateval <> '0000-00-00' AND " . TBRLIC . ".rlic_dateout = '0000-00-00')";
                break;
            case 3 :
                $rech .= " AND (" . TBRLIC . ".rlic_dateval <= '" . $datea . "' AND " . TBRLIC . ".rlic_dateval <> '0000-00-00' AND " . TBRLIC . ".rlic_dateout = '0000-00-00')";
                break;
        }

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

        if ($search <> '') {
            $rech .= " AND (";
            $rech .= " " . TBRLIC . ".rlic_code LIKE '%" . $db->escape($search) . "%' OR";
            if (chkdate($search) == TRUE) {
                $daterech = datetomysql($search);
                $rech .= " " . TBRLIC . ".rlic_daterel LIKE '%" . $db->escape($daterech) . "%' OR";
                $rech .= " " . TBRLIC . ".rlic_dateval LIKE '%" . $db->escape($daterech) . "%' OR";
            }
            $rech .= " " . TBRLIC . ".rlic_modele LIKE '%" . $db->escape($search) . "%' OR";
            $rech .= " " . TBRLIC . ".rlic_version LIKE '%" . $db->escape($search) . "%' OR";
            $rech .= " " . TBMQUE . ".mque_ste LIKE '%" . $db->escape($search) . "%' OR";
            $rech = substr($rech, 0, strlen($rech) - 3);
            $rech .= ")";
        }
        $rech .= " ORDER BY " . TBRLIC . ".rlic_daterel";

        $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 _("Fiche créée le");
            echo "</th>\n";
            echo "<th>";
            echo _("Editeur");
            echo "</th>\n";
            echo "<th>";
            echo _("Modèle / Version");
            echo "</th>\n";
            echo "<th>";
            echo _("Validité");
            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 (datetolocal($row["rlic_dateout"]) == "") {
                    if ($row["rlic_legal"] == FALSE)
                        echo '<img src="../img/warn.png" title="'._("Licence illégale ou non confirmée").'" border="0" align="absmiddle">';
                    $rech2 = "SELECT COUNT(*) FROM `" . TBRPDT . "` WHERE `rpdt_codecli` = '" . $rel_codecli . "' AND `rpdt_coderlic` LIKE '%" . $row["rlic_code"] . "%'";
                    $nb_rlic_utilisees = $db->get_var($rech2);

                    if ($nb_rlic_utilisees >= $row["rlic_maxcli"]) {
                        $txtlic = _("Licences installées") . " : " . $nb_rlic_utilisees . " / " . _("autorisées") . " : " . $row["rlic_maxcli"];
                        echo " <img src=\"../img/cd.png\" title =\"" . $txtlic . "\" border=\"0\" align=\"absmiddle\">";
                    }

                    // Vérification si problème(s) non affecté(s)
                    if (($pbm == 0) OR ($pbm == 1)) {
                        $rexist2 = "SELECT COUNT(*) FROM `" . TBRPBM . "`  WHERE rpbm_coderlp = '" . $row["rlic_code"] . "' AND rpbm_codeint IS NULL";
                        $nbres2 = $db->get_var($rexist2);
                        if ($nbres2 > 0)
                            echo " <img src=\"../img/pbmna.png\" title =\"" . _("Problème(s) non affecté(s)") . "\" border=\"0\" align=\"absmiddle\">";
                    }

                    // Vérification si interventions en cours
                    if (($pbm == 0) OR ($pbm == 2)) {
                        $rexist2 = "SELECT COUNT(*) FROM `" . TBRPBM . "`  WHERE rpbm_coderlp = '" . $row["rlic_code"] . "' AND rpbm_codeint IS NOT NULL AND (rpbm_datett='0000-00-00' OR rpbm_datett IS NULL)";
                        $nbres2 = $db->get_var($rexist2);
                        if ($nbres2 > 0)
                            echo "<img src=\"../img/rpbmint.png\" border=\"0\" align=\"absmiddle\"  title =\"" . _("Intervention(s) en cours") . "\" border=\"0\">";
                    }
                } else
                    echo " <img src=\"../img/warn.png\" title =\"" . _("Sortie du parc depuis le") . " " . datetolocal($row["rlic_dateout"]) . ".\" border=\"0\" align=\"absmiddle\">";
                echo "</td>\n";
                echo "<td align=\"center\">\n";
                echo datetolocal($row["rlic_daterel"]);
                echo "</td>\n";

                echo "<td>\n";
                echo $row["mque_ste"];
                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"]);

                // vérification si date validité dépassée
                if ($valg == 0) {
                    if (datetolocal($row["rlic_dateout"]) == "") {
                        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 =\"" . _("Echéance dépassée") . "\" border=\"0\" align=\"absmiddle\">";
                        }
                    }
                }
                echo "</td>\n";
                echo "<td align=\"center\">\n";
                if ($td <> "del") {
                    if (datetolocal($row["rlic_dateout"]) == "") {
                        if ($td <> "view") {
                            if (url_ok('rlic_maj.php?td=edit', FALSE) == TRUE) {
                                $lst_maj = TRUE;
                                cre_falselnk_img('', 'rlic_edit_'.$row["rlic_id"], 'span', 'center', _("Edition"), 'lnk', 'rlic_maj.php?td=edit&cc='.$row["rlic_codecli"].'&cr='.$cr.'&crl=' . $row["rlic_code"], '../img/edit.png');
                            }
                        } else {
                            if (url_ok('rlic_maj.php?td=view', FALSE) == TRUE) {
                                $lst_voir = TRUE;
                                cre_falselnk_img('', 'rlic_view_'.$row["rlic_id"], 'span', 'center', _("Visualisation"), 'lnk', 'rlic_maj.php?td=view&cc='.$row["rlic_codecli"].'&cr='.$cr.'&crl=' . $row["rlic_code"], '../img/eye.png');
                            }
                        }
                        echo " ";
                        if (url_ok('rpbm_maj.php?td=add', FALSE) == TRUE) {
                            $lst_pbmrel = TRUE;
                            cre_falselnk_img('', 'rpbm_add_'.$row["rlic_id"], 'span', 'center', _("Déclaration problème"), 'lnk', 'rpbm_maj.php?td=add&tr=1&cr=' .$cr.'&crl='. $row["rlic_code"] . '&cap=0', '../img/addpbm.png');
                        }

                        $urlimp = "rlp_pdf.php?cr=" . $row["rlic_code"] . "&te=l&pbm=0";
                        if (url_ok($urlimp, FALSE) == TRUE) {
                            $lst_imp = TRUE;
                            cre_falselnk_img('', 'rlic_prn_'.$row["rlic_id"], 'span', 'center', _("Impression"), 'lnkpop', $urlimp, '../img/print.png');

                            $lst_impp = TRUE;
                            $urlimp = "rlp_pdf.php?cr=" . $row["rlic_code"] . "&te=l&pbm=1";
                            cre_falselnk_img('', 'rlic_prnp_'.$row["rlic_id"], 'span', 'center', _("Impression avec problèmes"), 'lnkpop', $urlimp, '../img/printc.png');
                        }

                        if ($td <> "view") {
                            if (url_ok('rlic_maj.php?td=del', FALSE) == TRUE) {
                                echo " ";
                                $lst_del = TRUE;
                                cre_falselnk_img('', 'rlic_del_'.$row["rlic_id"], 'span', 'center', _("Suppression"), 'lnk', 'rlic_maj.php?td=del&cc='.$row["rlic_codecli"].'&crl=' . $row["rlic_code"], '../img/del.png');
                            }
                        }
                    } else {
                        if (url_ok('rlic_maj.php?td=view', FALSE) == TRUE) {
                            $lst_voir = TRUE;
                            cre_falselnk_img('', 'rlic_view_'.$row["rlic_id"], 'span', 'center', _("Visualisation"), 'lnk', 'rlic_maj.php?td=view&cc='.$row["rlic_codecli"].'&crl=' . $row["rlic_code"] . '&cc=' . $row["rlic_codecli"] . '&ca=' . $row["rlic_codeage"], '../img/eye.png');
                        }
                    }
                } else
                    echo "-";
                echo "</tr>\n";

                $j++;
            }
            echo "</table>\n";
            // Fin affichage table détails licences

            $taille_piedla = "small";
            include("piedla.inc.php");
        } else {
            echo _("Aucune fiche relevé licence créée");
            if ($idscli != -1)
                echo " " . _("sur ce site");
            else
                echo " " . ("sur ces sites");
            echo ", " . _("avec les filtres demandés") . "<br />";
        }
        $db->disconnect();
        ?>
        </div>

        <div id="relg_mat">
        <table width="100%" border="0" cellspacing="0" cellpadding="0">
            <tr>
                <td>
                    <span
                        class="annot_petit_it">(<?PHP echo _("Laisser la souris sur les icônes pour le détail"); ?>
                        )</span>
                </td>
                <td align="right">
                    <?PHP
                    $lst_maj = FALSE;
                    $lst_voir = FALSE;
                    $lst_pbmrel = FALSE;
                    $lst_imp = FALSE;
                    $lst_impp = FALSE;
                    $lst_del = FALSE;
                    if (($td <> "del") AND ($td <> "view")) {
                        $url_add = "rpdt_maj.php?td=add&cc=" . $rel_codecli."&cr=".$rel_code;
                        if (url_ok($url_add, TRUE) == TRUE)
                            cre_falselnk('', 'add_rpdt', 'span', '', _("Ajouter fiche matériel"), $url_add, '../img/add.png', _("Ajouter fiche matériel"));
                        /*
                        {
                            echo '<a href="' . $url_add . '"><img src="../img/add.png" title ="' . _("Ajouter fiche matériel") . '" border="0" align="absmiddle">';
                            echo ' ' . _("Ajouter fiche matériel") . '</a>';
                        }
                        */
                    } else
                        echo "&nbsp;";
                    ?>
                </td>
            </tr>
        </table>
        <?PHP
        $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);

        switch ($pbm) {
            case 0 :
                $rech = "SELECT * FROM `" . TBRPDT . "`, `" . TBMQUE . "`, `" . TBRPCAT . "` WHERE " . TBRPDT . ".rpdt_codecli = '" . $rel_codecli . "' AND (" . TBRPDT . ".rpdt_codema = " . TBMQUE . ".mque_code AND " . TBRPDT . ".rpdt_codecat = " . TBRPCAT . ".rpcat_code)";
                break;
            case 1 :
                $rech = "SELECT DISTINCT " . TBRPDT . ".rpdt_code, " . TBRPDT . ".rpdt_codecli, " . TBRPDT . ".rpdt_dateout, " . TBRPDT . ".rpdt_daterel, " . TBRPDT . ".rpdt_codecat, ";
                $rech .= TBRPDT . ".rpdt_codema, " . TBRPDT . ".rpdt_modele, " . TBRPDT . ".rpdt_empl, " . TBRPDT . ".rpdt_codep, " . TBRPDT . ".rpdt_ns, " . TBRPDT . ".rpdt_fingar, ";
                $rech .= TBRPBM . ".rpbm_coderlp, " . TBRPBM . ".rpbm_codeint, ";
                $rech .= TBMQUE . ".mque_ste, ";
                $rech .= TBRPCAT . ".rpcat_desc ";
                $rech .= "FROM `" . TBRPDT . "`, `" . TBRPBM . "`, `" . TBMQUE . "`, `" . TBRPCAT . "`";
                $rech .= " WHERE " . TBRPDT . ".rpdt_codecli = '" . $rel_codecli . "' AND " . TBRPDT . ".rpdt_code = " . TBRPBM . ".rpbm_coderlp AND " . TBRPDT . ".rpdt_codema = " . TBMQUE . ".mque_code AND " . TBRPDT . ".rpdt_codecat = " . TBRPCAT . ".rpcat_code";
                $rech .= " AND " . TBRPBM . ".rpbm_codeint IS NULL";
                break;
            case 2 :
                $rech = "SELECT DISTINCT " . TBRPDT . ".rpdt_code, " . TBRPDT . ".rpdt_codecli, " . TBRPDT . ".rpdt_dateout, " . TBRPDT . ".rpdt_daterel, " . TBRPDT . ".rpdt_codecat, ";
                $rech .= TBRPDT . ".rpdt_codema, " . TBRPDT . ".rpdt_modele, " . TBRPDT . ".rpdt_empl, " . TBRPDT . ".rpdt_codep, " . TBRPDT . ".rpdt_ns, " . TBRPDT . ".rpdt_fingar, ";
                $rech .= TBRPBM . ".rpbm_coderlp, " . TBRPBM . ".rpbm_codeint, ";
                $rech .= TBMQUE . ".mque_ste, ";
                $rech .= TBRPCAT . ".rpcat_desc ";
                $rech .= "FROM `" . TBRPDT . "`, `" . TBRPBM . "`, `" . TBMQUE . "`, `" . TBRPCAT . "`";
                $rech .= " WHERE " . TBRPDT . ".rpdt_codecli = '" . $rel_codecli . "' AND " . TBRPDT . ".rpdt_code = " . TBRPBM . ".rpbm_coderlp AND " . TBRPDT . ".rpdt_codema = " . TBMQUE . ".mque_code AND " . TBRPDT . ".rpdt_codecat = " . TBRPCAT . ".rpcat_code";
                $rech .= " AND " . TBRPBM . ".rpbm_codeint IS NOT NULL";
                break;
        }

        switch ($valg) {
            case 0 :
                break;
            case 1 :
                $nouvdate = nouv_date_plus_jours($datea, 30);
                $rech .= " AND (" . TBRPDT . ".rpdt_fingar <= '" . $nouvdate . "' AND " . TBRPDT . ".rpdt_fingar >= '" . $datea . "' AND " . TBRPDT . ".rpdt_fingar <> '0000-00-00' AND " . TBRPDT . ".rpdt_dateout = '0000-00-00')";
                break;
            case 2 :
                $nouvdate = nouv_date_plus_jours($datea, 60);
                $rech .= " AND (" . TBRPDT . ".rpdt_fingar <= '" . $nouvdate . "' AND " . TBRPDT . ".rpdt_fingar >= '" . $datea . "' AND " . TBRPDT . ".rpdt_fingar <> '0000-00-00' AND " . TBRPDT . ".rpdt_dateout = '0000-00-00')";
                break;
            case 3 :
                $rech .= " AND (" . TBRPDT . ".rpdt_fingar <= '" . $datea . "' AND " . TBRPDT . ".rpdt_fingar <> '0000-00-00' AND " . TBRPDT . ".rpdt_dateout = '0000-00-00')";
                break;
        }

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

        if ($search <> '') {
            $rech .= " AND (";
            $rech .= " " . TBRPDT . ".rpdt_code LIKE '%" . $db->escape($search) . "%' OR";
            if (chkdate($search) == TRUE) {
                $daterech = datetomysql($search);
                $rech .= " " . TBRPDT . ".rpdt_daterel LIKE '%" . $db->escape($daterech) . "%' OR";
                $rech .= " " . TBRPDT . ".rpdt_fingar LIKE '%" . $db->escape($daterech) . "%' OR";
            }
            $rech .= " " . TBRPDT . ".rpdt_modele LIKE '%" . $db->escape($search) . "%' OR";
            $rech .= " " . TBRPDT . ".rpdt_empl LIKE '%" . $db->escape($search) . "%' OR";
            $rech .= " " . TBRPDT . ".rpdt_codep LIKE '%" . $db->escape($search) . "%' OR";
            $rech .= " " . TBRPDT . ".rpdt_ns LIKE '%" . $db->escape($search) . "%' OR";
            $rech .= " " . TBRPCAT . ".rpcat_desc LIKE '%" . $db->escape($search) . "%' OR";
            $rech .= " " . TBMQUE . ".mque_ste LIKE '%" . $db->escape($search) . "%' OR";
            $rech = substr($rech, 0, strlen($rech) - 3);
            $rech .= ")";
        }
        $rech .= " ORDER BY " . TBRPDT . ".rpdt_daterel";

        $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 matériels"
            echo "<th>";
            echo _("Code Fiche / Inventaire");
            echo "</th>\n";
            echo "<th>";
            echo _("Fiche créée le");
            echo "</th>\n";
            echo "<th>";
            echo _("Catégorie");
            echo "</th>\n";
            echo "<th>";
            echo _("Constructeur / Modèle / NS / Emplacement ");
            echo "</th>\n";
            echo "<th>";
            echo _("Fin Gar.");
            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["rpdt_code"] . "<br />";
                echo "(" . $row["rpdt_codep"] . ") ";
                if (datetolocal($row["rpdt_dateout"]) == "") {
                    // vérification si problème(s) non affecté(s)
                    if (($pbm == 0) OR ($pbm == 1)) {
                        $rexist2 = "SELECT COUNT(*) FROM `" . TBRPBM . "`  WHERE rpbm_coderlp = '" . $row["rpdt_code"] . "' AND rpbm_codeint IS NULL";
                        $nbres2 = $db->get_var($rexist2);
                        if ($nbres2 > 0)
                            echo " <img src=\"../img/pbmna.png\" title =\"" . _("Problème(s) non affecté(s)") . "\" border=\"0\" align=\"absmiddle\">";
                    }

                    // vérification si interventions en cours
                    if (($pbm == 0) OR ($pbm == 2)) {
                        $rexist2 = "SELECT COUNT(*) FROM `" . TBRPBM . "` WHERE rpbm_coderlp = '" . $row["rpdt_code"] . "' AND rpbm_codeint IS NOT NULL AND (rpbm_datett='0000-00-00' OR rpbm_datett IS NULL)";
                        $nbres2 = $db->get_var($rexist2);
                        if ($nbres2 > 0)
                            echo "<img src=\"../img/rpbmint.png\" align=\"absmiddle\" title =\"" . _("Intervention(s) en cours") . "\" border=\"0\">";
                    }
                } else
                    echo " <img src=\"../img/warn.png\" title =\"" . _("Sorti du parc depuis le") . " " . datetolocal($row["rpdt_dateout"]) . ".\" border=\"0\" align=\"absmiddle\">";
                echo "</td>\n";
                echo "<td align=\"center\">\n";
                echo datetolocal($row["rpdt_daterel"]);
                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 "<td align=\"center\">\n";
                echo datetolocal($row["rpdt_fingar"]);

                // vérification si date garantie dépassée
                if ($valg == 0) {
                    if (datetolocal($row["rlic_dateout"]) == "") {
                        if (datetolocal($row["rpdt_fingar"]) <> "") {
                            if ((echeance_depassee_date($datea, $row["rpdt_fingar"]) == TRUE)  AND (datetolocal($row["rpdt_dateout"]) == ""))
                                echo " <img src=\"../img/dateout.png\" title =\"" . _("Plus sous garantie") . "\" border=\"0\" align=\"absmiddle\">";
                        }
                    }
                }
                echo "</td>\n";

                echo "<td align=\"center\">\n";
                if ($td <> "del") {
                    if (datetolocal($row["rpdt_dateout"]) == "") {
                        if ($td <> "view") {
                            if (url_ok('rpdt_maj.php?td=edit', FALSE) == TRUE) {
                                $lst_maj = TRUE;
                                cre_falselnk_img('', 'rpdt_edit_'.$row["rpdt_id"], 'span', 'center', _("Edition"), 'lnk', 'rpdt_maj.php?td=edit&cc='.$row["rpdt_codecli"].'&cr='.$cr.'&crp=' . $row["rpdt_code"], '../img/edit.png');
                            }
                        } else {
                            if (url_ok('rpdt_maj.php?td=view', FALSE) == TRUE) {
                                $lst_voir = TRUE;
                                cre_falselnk_img('', 'rpdt_view_'.$row["rpdt_id"], 'span', 'center', _("Visualisation"), 'lnk', 'rpdt_maj.php?td=view&cc='.$row["rpdt_codecli"].'&cr='.$cr.'&crp=' . $row["rpdt_code"], '../img/eye.png');
                            }
                        }

                        if (url_ok('rpbm_maj.php?td=add', FALSE) == TRUE) {
                            $lst_pbmrel = TRUE;
                            cre_falselnk_img('', 'rpbm_add_'.$row["rpdt_id"], 'span', 'center', _("Déclaration problème"), 'lnk', 'rpbm_maj.php?td=add&tr=2&cc=&cr=' .$cr.'&crp='. $row["rpdt_code"] . '&cap=0', '../img/addpbm.png');
                        }

                        $urlimp = "rlp_pdf.php?cr=" . $row["rpdt_code"] . "&te=m&pbm=0";
                        if (url_ok($urlimp, FALSE) == TRUE) {
                            $lst_imp = TRUE;
                            cre_falselnk_img('', 'rpdt_prn_'.$row["rpdt_id"], 'span', 'center', _("Impression"), 'lnkpop', $urlimp, '../img/print.png');

                            $lst_impp = TRUE;
                            $urlimp2 = "rlp_pdf.php?cr=" . $row["rpdt_code"] . "&te=m&pbm=1";
                            cre_falselnk_img('', 'rpdt_prn_'.$row["rpdt_id"], 'span', 'center', _("Impression avec problèmes"), 'lnkpop', $urlimp2, '../img/printc.png');
                        }

                        echo " ";
                        if ($td <> "view") {
                            if (url_ok('rpdt_maj.php?td=del', FALSE) == TRUE) {
                                $lst_del = TRUE;
                                cre_falselnk_img('', 'rpdt_del_'.$row["rpdt_id"], 'span', 'center', _("Suppression"), 'lnk', 'rpdt_maj.php?td=del&cc='.$row["rpdt_codecli"].'&crp=' . $row["rpdt_code"], '../img/del.png');
                            }
                        }
                    } else {
                        $lst_voir = TRUE;
                        cre_falselnk_img('', 'rpdt_view_'.$row["rpdt_id"], 'span', 'center', _("Visualisation"), 'lnk', 'rpdt_maj.php?td=view&cc='.$row["rpdt_codecli"].'&crp=' . $row["rpdt_code"], '../img/eye.png');
                    }
                } else
                    echo "-";

                echo "</tr>\n";

                $j++;
            }

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

            $taille_piedla = "small";
            include("piedla.inc.php");
        } else {
            echo _("Aucune fiche relevé matériel créée");
            if ($idscli != -1)
                echo " " . _("sur ce site");
            else
                echo " " . _("sur ces sites");
            echo ", " . _("avec les filtres demandés") . "<br />";
        }
        $db->disconnect();
    }
    ?>
    </div>
    </div>

    <!-- Fin affichage uniquement si edition ou visualisation -->

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