<?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)
$crl = $_GET['crl']; // Récupération code relevé Licence
$cc = $_GET['cc']; // Récupération code Client
$ca = $_GET['ca']; // Récupération code Agence
$sais_dteout = TRUE;
$sais_dteval = TRUE;
$sais_mdval = TRUE;
$sais_mdlmaj = TRUE;
$sais_scli = TRUE;
$select_age = TRUE;
$nb_rlic_utilisees = 0;
$pbm = 0;
$idscli = -1;
$search = '';

$pbm_rlic = 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 <> "") {
    // Contrôle qu'un client n'essaye pas de "hacker" un relevé

    $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_rlic = 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_rlic = TRUE;
                if (($rlic_codeage <> @$_SESSION["code_age"]) OR ($cli_prop <> @$_SESSION["code_age"]))
                    $pbm_rlic = TRUE;
                $select_age = FALSE;
                $rlic_codeage = @$_SESSION["code_age"];
                break;
        }

        if ($td == "add")
        {
            $row = lit_enr_rel_cli($cli_code);
            if (is_array($row)) {
                extract($row);
                if ($cli_ste <> "")
                    $rlic_idsite = -2;
                else {
                    $rlic_idsite = 0;
                    $sais_scli = FALSE;
                }
                $ca = $cli_prop;
            }

            $rlic_daterelf = $datef;
            $rlic_dateoutf = "";
            $rlic_code = crecodesession("RL");
            $rlic_coderel = $rel_code;
            $rlic_codecli = $cc;
            $rlic_codeage = $ca;
            $rlic_maxcli = 1;
        }
    } else
        $pbm_rlic = TRUE;
} else
    $pbm_rlic = TRUE;

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

            if ($cc <> '')
            {
                if ($rel_codecli <> $cc)
                    $pbm_rlic = TRUE;
            }
            else
                $cc = $rel_codecli;
        } else
            $pbm_rlic = TRUE;
    }
}

if ($pbm_rlic == FALSE)
{
    if ($crl <> "") {
        // Récupération des informations de la fiche de relevé licence
        $row = lit_enr_rlic($crl);
        if (is_array($row)) {
            $row = encode_str($row);
            extract($row);

            if ($rlic_codecli <> $cc)
                $pbm_rlic = TRUE;

            $ca = $rlic_codeage;
            $cc = $rlic_codecli;

            if ($pbm_rlic == FALSE)
            {
                if ($td <> "add") {
                    /*
                    $row = lit_enr_cli($rlic_codecli, TRUE);
                    if (is_array($row))
                        extract($row);
                    */

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

                if ($pbm_rlic == FALSE) {
                    // Récupération du nombre de licences utilisées
                    $nb_rlic_utilisees = nb_rlic($rlic_codecli, $rlic_code);

                    $exist_in_rpbm = exist_rlic_in_rpbm($crl);
                    if ($exist_in_rpbm == TRUE)
                        $exist_in_rpbm = 1;
                    else
                        $exist_in_rpbm = 0;

                    $rlic_daterelf = datetolocal($rlic_daterel);
                    $rlic_datevalf = datetolocal($rlic_dateval);
                    $rlic_dateoutf = datetolocal($rlic_dateout);
                    $rlic_mdvalf = datetolocal($rlic_mdval);
                    $rlic_mdlmajf = datetolocal($rlic_mdlmaj);

                    // On ne peut pas modifier si licence sortie
                    if (($rlic_dateoutf <> "") AND ($td == "edit"))
                        $td = "view";
                }
            }
        } else
            $pbm_rlic = TRUE;
    } else
    {
        if ($td <>"add")
            $pbm_rlic = TRUE;
    }
}

switch ($td) {
    case "add":
        $titre = _("AJOUT FICHE RELEVE LICENCE");
        $sais_dteout = FALSE;
        break;
    case "edit":
        $titre = _("MISE A JOUR FICHE RELEVE LICENCE");
        break;
    case "view":
        $titre = _("DETAIL FICHE RELEVE LICENCE");
        $sais_dteout = FALSE;
        break;
    case "del":
        $titre = _("SUPPRESSION FICHE RELEVE LICENCE");
        $sais_dteout = FALSE;
        break;
    default :
        $pbm_rlic = 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é Licence"); ?></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:codema ; format:liste ; req:Y ; txt:<?PHP echo _("Editeur"); ?> ; vmn:1 ; stok:frmok ; stbad:frmbad",
        "nom:codetl ; format:liste ; req:Y ; txt:<?PHP echo _("Type de licence"); ?>  ; vmn:1 ; stok:frmok ; stbad:frmbad",
        "nom:codemed ; format:liste ; req:Y ; txt:<?PHP echo _("Type de média"); ?>  ; vmn:1 ; stok:frmok ; stbad:frmbad",
        "nom:modele ; format:txt ; req:Y ; txt:<?PHP echo _("Modèle"); ?> ; lmx:40 ; stok:frmok ; stbad:frmbad",
        "nom:version ; format:txt ; req:Y ; txt:<?PHP echo _("Version"); ?> ; lmx:10 ; stok:frmok ; stbad:frmbad",
        "nom:maxcli ; format:unsigned ; req:Y ; txt:<?PHP echo _("Nombre maximum de postes"); ?> ; lmx:4 ; stok:frmok ; stbad:frmbad",
        "nom:numlic ; format:txt ; req:N ; txt:<?PHP echo _("Numéro de licence"); ?> ; lmx:40 ; stok:frmok ; stbad:frmbad",
        "nom:cleflic ; format:txt ; req:N ; txt:<?PHP echo _("Clef de débridage"); ?> ; lmx:40 ; stok:frmok ; stbad:frmbad",
        "nom:nota ; format:txt ; req:N ; txt:<?PHP echo _("Notes"); ?> ; 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_dteval == TRUE) { ?>
        $("#datevalf").datepicker({
            onSelect: function () {
                $("#datevalf").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, '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, 'today,mdvalf', '', '',false);
            }
        });
        <?PHP } ?>
    }

    function init_all() {
        init_Body();
        init_autohref_classe('falselnkimg','');
        init_datepicker();
        img_checkpw('tmdp', 'nivpwt');
        img_checkpw('mmdp', 'nivpwm');
        <?PHP
        switch ($td)
        {
            case "add" :
                echo '$("#daterelf").datepicker({';
                echo '    onSelect: function (datesel) {';
                echo '        $("#daterelf").blur();';
                echo '    },';
                echo '});';
                echo "init_autoraz('razdaterelf','daterelf','click');";
                echo "$('#datesortie').hide();";
                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_age_actives()."age','','back','','');";
                echo "init_checkpw('tmdp','nivpwt',true);";
                echo "init_checkpw('mmdp','nivpwm',true);";
                echo "init_warn_scli_change_rel('site','".$exist_in_rpbm."','site',".$rlic_idsite.");";
                echo "init_ajax_tec2();";
                if ($sais_scli == FALSE)
                    echo "readonly_id('site',false);";
                if ($select_age == FALSE)
                    echo "readonly_id('codeage',false);";
                echo "init_valid_form('enr','rlic_maj','".$_SESSION['date_fmtshort']."',tab1_champ,'','');";
                break;
            case "edit" :
                if (@$_SESSION["niv_log"] >= 3)
                    echo 'warn_cpta('.$cli_cpta.',"rel");';
                echo "chk_affwarnmaxi('maxcli','warn_nblic','nblicutil');";
                echo "init_chk_affwarnmaxi('maxcli','warn_nblic','nblicutil');";
                echo "init_checkpw('tmdp','nivpwt',true);";
                echo "init_checkpw('mmdp','nivpwm',true);";
                if (exist_rpbm($rlic_code) == TRUE)
                {
                    echo "init_autosubmit('sitepbm','change','pbm_lst');";
                    echo "init_autosubmit('pbms','change','pbm_lst');";
                }
                echo "init_warn_scli_change_rel('site','".$exist_in_rpbm."','site',".$rlic_idsite.");";
                echo "init_ajax_tec2();";
                if ($sais_scli == FALSE)
                    echo "readonly_id('site',false);";
                if ($select_age == FALSE)
                    echo "readonly_id('codeage',false);";
                echo "init_new_fen('etats','impression');";
                echo "init_valid_form('enr','rlic_maj','".$_SESSION['date_fmtshort']."',tab1_champ,'','');";
                break;
            case "del" :
                echo "warn_del('scli');";
                echo "readonly_all();";
                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',".$rlic_idsite.");";
                echo "init_new_fen('etats','impression');";
                echo "readonly_all();";
                echo "readok_id('etats',false);";
                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('razdatevalf','datevalf','click');";
        echo "chk_date_affwarnech('mdvalf','warn_ech','".$_SESSION["date_fmtshort"]."','','','today');";
        echo "init_chk_date_affwarnech('mdvalf','warn_ech','".$_SESSION["date_fmtshort"]."','','','today');";
        echo "init_autoraz('razmdlmajf','mdlmajf','click');";

        if (@$_SESSION["niv_log"] >= 3)
            echo "init_fensaisie('aff_notesc',930,380);";
        if (($idscli != -1) OR ($pbm != 0) OR ($search != ''))
            echo '$( "#onglets_rlic" ).tabs({ active: 5 });';
        else
            echo '$( "#onglets_rlic" ).tabs();';
        ?>
        init_autosubmit('search','change','pbm_lst');
        init_autoraz('razsearch','search','click');
        init_autosubmit('razsearch','click','pbm_lst');
        init_ajax_types();
        init_autohref_classe('falselnkimg','');
        Focus_first();
    }

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

</head>
<body>
<?PHP
include_once("../inc/entete.inc.php");
if ($pbm_rlic == FALSE) {
    ?>
    <p align="center"><span class="titrepage"><?PHP echo $titre ?></span></p>
    <!-- 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")) {
                        $urlimp = "rlp_pdf.php?cr=" . $crl . "&te=l&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 = "rlp_pdf.php?cr=" . $crl . "&te=l&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;";
                    } else
                        echo "&nbsp;";
                    ?>
                </td>
            </tr>
        </table>

        <form name="rlic_maj" id="rlic_maj" method="post" action="rlic_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 $rlic_codecli ?>">
        <?PHP if ($td == "add") { ?>
            <input name="code" type="hidden" id="code" value="<?PHP echo $rlic_code ?>">
            <input name="dateoutf" type="hidden" id="dateoutf" value="<?PHP echo $rlic_dateoutf ?>">
        <?PHP } else { ?>
            <input name="code" type="hidden" id="code" value="<?PHP echo $rlic_code ?>">
            <input name="codeage" type="hidden" id="codeage" value="<?PHP echo $rlic_codeage ?>">
            <input name="codetec" type="hidden" id="codetec" value="<?PHP echo $rlic_codetec ?>">
        <?PHP } ?>
        <input name="today" type="hidden" id="today" value="<?PHP echo $datef; ?>">
        <input name="nblicutil" type="hidden" id="nblicutil" value="<?PHP echo $nb_rlic_utilisees; ?>">
        <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 $rlic_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 $rlic_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 la licence est sortie du parc, la fiche n'est plus modifiable"); ?>
                            <br />
                            <?PHP 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>
                    <input name="coderel" type="text" id="coderel" value="<?PHP echo $rlic_coderel ?>" size="20"
                           maxlength="20" readonly>
                </td>
            </tr>
        </table>

        <!-- Code du relevé licence 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 $rlic_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>

        <!-- Site d'usage de la licence -->
        <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" colspan="2" 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
                    $tab_age = give_tab_age_cli($rlic_codecli);
                    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, $rlic_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" colspan="2" align="center">
                    <?PHP echo _("Détail du relevé"); ?>
                </td>
            </tr>
        </table>

        <!-- Marque/Nom de l'éditeur -->
        <table width="100%" border="0">
            <tr>
                <td width="160" class="rubfrm" id="f_codema" align="right"><?PHP echo _("Editeur"); ?></td>
                <td>
                    <?PHP
                    $tab_mque = give_tab_marques("rlic");
                    cre_select_tab('codema', 'codema', $tab_mque, 'mque_code', 'mque_ste', '', $rlic_codema, '', _("-- Faites votre choix --"), 1, FALSE, '', _("Inconnu"));
                    ?>
                </td>
            </tr>
        </table>

        <!-- Type de la licence -->
        <table width="100%" border="0">
            <tr>
                <td width="160" class="rubfrm" id="f_codetl" align="right"><?PHP echo _("Type"); ?></td>
                <td>
                    <?PHP
                    // création de la liste des types
                    $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
                    $rech = "SELECT * FROM `" . TBRLTL . "` WHERE rltl_codema='" . $rlic_codema . "' OR rltl_codema='*'  ORDER BY rltl_desc";
                    $rows = $db->get_results($rech, ARRAY_A);
                    $db->disconnect();
                    cre_select_tab('codetl', 'codetl', $rows, 'rltl_code', 'rltl_desc', '', $rlic_codetl, '', _("-- Faites votre choix --"));
                    ?>
                </td>
            </tr>
        </table>

        <!-- Modèle de la licence -->
        <table width="100%" border="0">
            <tr>
                <td width="160" class="rubfrm" id="f_modele" align="right">
                    <?PHP echo _("Modèle"); ?>
                </td>
                <td>
                    <input name="modele" type="text" id="modele" value="<?PHP echo $rlic_modele; ?>" size="40">
                     <img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo _("Champ obligatoire"); ?>">
                </td>
            </tr>
        </table>

        <!-- Version de la licence -->
        <table width="100%" border="0">
            <tr>
                <td width="160" class="rubfrm" id="f_version" align="right">
                    <?PHP echo _("Version"); ?>
                </td>
                <td>
                    <input name="version" type="text" id="version" value="<?PHP echo $rlic_version; ?>" size="10">
                     <img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo _("Champ obligatoire"); ?>">
                </td>
            </tr>
        </table>

        <!-- Nb Maximum de clients -->
        <table width="100%" border="0">
            <tr>
                <td width="160" class="rubfrm" id="f_maxcli" align="right">
                    <?PHP echo _("Maximum de postes"); ?>
                </td>
                <td>
                    <input name="maxcli" type="text" id="maxcli" value="<?PHP echo $rlic_maxcli ?>" size="4"
                           maxlength="4" align="right">
                    <img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo _("Champ obligatoire"); ?>">
                    <?PHP
                    echo '<span id="warn_nblic" style="display:none;">';
                    echo ' <img src="../img/warn.png" title ="' . _("Maximum atteint") . ' : ' . $nb_rlic_utilisees . '" border="0" align="absmiddle">';
                    echo '</span>';
                    ?>
                </td>
            </tr>
        </table>

        <!-- Type de média -->
        <table width="100%" border="0">
            <tr>
                <td width="160" class="rubfrm" id="f_codemed" align="right"><?PHP echo _("Type Média"); ?></td>
                <td>
                    <?PHP
                    // création de la liste des types
                    $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
                    $rech = "SELECT * FROM `" . TBRLMED . "` ORDER BY rlmed_desc";
                    $rows = $db->get_results($rech, ARRAY_A);
                    $db->disconnect();
                    cre_select_tab('codemed', 'codemed', $rows, 'rlmed_code', 'rlmed_desc', '', $rlic_codemed, '', _("-- Faites votre choix --"));
                    ?>
                </td>
            </tr>
        </table>

        <!-- Numéro de la licence -->
        <table width="100%" border="0">
            <tr>
                <td width="160" class="rubfrm" id="f_numlic" align="right">
                    <?PHP echo _("Numéro"); ?>
                </td>
                <td>
                    <input name="numlic" type="text" id="numlic" value="<?PHP echo $rlic_numlic; ?>" size="40">
                </td>
            </tr>
        </table>


        <!-- Clef de la licence -->
        <table width="100%" border="0">
            <tr>
                <td width="160" class="rubfrm" id="f_cleflic" align="right">
                    <?PHP echo _("Clef Activation"); ?>
                </td>
                <td>
                    <input name="cleflic" type="text" id="cleflic" value="<?PHP echo $rlic_cleflic; ?>" size="40">
                </td>
            </tr>
        </table>

        <!-- Licence à jour ? -->
        <!-- Licence Légale ? -->
        <table width="100%" border="0">
            <tr>
                <td width="160" class="rubfrm" id="f_ajour" align="right">
                    <?PHP echo _("A Jour ?"); ?>
                </td>
                <td width="100">
                    <?PHP cre_select('ajour', 'ajour', $non_oui, $rlic_ajour); ?>
                </td>
                <td width="160" class="rubfrm" id="f_legale" align="right">
                    <?PHP echo _("Légale ?"); ?>
                </td>
                <td>
                    <?PHP cre_select('legale', 'legale', $non_oui, $rlic_legal); ?>
                    <span class="annot_petit_it">
                    (<?PHP echo _("Non : pas légale ou pas pu avoir de confirmation"); ?>)
                    </span>
                </td>
            </tr>
        </table>

        <!-- Date de validité -->
        <table width="100%" border="0">
            <tr>
                <td width="160" class="rubfrm" id="f_datevalf" align="right"><?PHP echo _("Date Validité"); ?></td>
                <td>
                    <input name="datevalf" type="text" id="datevalf" value="<?PHP echo $rlic_datevalf ?>" size="10"
                           maxlength="10" readonly>
                    <img src="../img/raz.png" id="razdatevalf" border="0" align="absmiddle">
                    <?PHP
                    echo '<span id="warn_val" style="display:none;">';
                    echo " <img src=\"../img/warn.png\" title =\"" . _("Echéance dépassée") . "\" border=\"0\" align=\"absmiddle\">";
                    echo '</span>';
                    ?>
                </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 $rlic_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 "add" :
                case "edit" :
                    echo '<input name="RAZ" type="reset" class="bton_std" id="RAZ" value="' . _("Tout réinitialiser") . '">';
                    echo ' <input name="enr" type="button" 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_rlic">
        <ul>
            <li><a href="#rlic_notes"><?PHP echo _("Notes"); ?></a></li>
            <li><a href="#rlic_mat"><?PHP echo _("Matériels"); ?></a></li>
            <li><a href="#rlic_telem"><?PHP echo _("Télémaintenance"); ?></a></li>
            <li><a href="#rlic_maj"><?PHP echo _("Mises à jour"); ?></a></li>
            <li><a href="#rlic_con"><?PHP echo _("Contrats"); ?></a></li>
            <li><a href="#rlic_pbm"><?PHP echo _("Problèmes"); ?></a></li>
        </ul>
        <div id="rlic_notes">
            <!-- Notes -->
            <table width="100%" border="0">
                <tr>
                    <td>
                        <textarea name="nota" rows="5" id="nota"><?PHP echo $rlic_nota ?></textarea>
                    </td>
                </tr>
            </table>
        </div>

        <div id="rlic_mat">
            <?PHP
            // création de la liste des relevés produits utilisant ce relevé licences
            $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
            $rech = "SELECT * FROM `" . TBRPDT . "` WHERE rpdt_dateout = '0000-00-00' AND rpdt_codecli = '" . $rlic_codecli . "'";
            $rech .= " AND rpdt_coderlic LIKE '%" . $rlic_code . "%'";
            $rech .= " ORDER BY rpdt_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 matériels"
                echo "<th>";
                echo _("Code Fiche");
                echo "</th>\n";
                echo "<th>";
                echo _("Catégorie");
                echo "</th>\n";
                echo "<th>";
                echo _("Marque / Modèle / NS / Emplacement");
                echo "</th>\n";
                echo "<th>";
                echo _("Fin Gar.");
                echo "</th>\n";
                echo "<th>";
                echo _("Editer");
                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"] . " ";
                    echo "</td>\n";

                    echo "<td>\n";
                    $rech2 = "SELECT rpcat_desc FROM `" . TBRPCAT . "` WHERE `rpcat_code` = '" . $row["rpdt_codecat"] . "'";
                    $row2 = $db->get_row($rech2, ARRAY_A);
                    if ($row2) {
                        $row2 = encode_str($row2);
                        echo $row2["rpcat_desc"];
                    } else
                        echo "-";
                    echo "</td>\n";

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

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

                    echo "<td align=\"center\">\n";
                    echo datetolocal($row["rpdt_fingar"]);
                    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 ="' . _("Hors garantie") . '" border="0" align="absmiddle">';
                    }
                    echo "</td>\n";

                    echo "<td align=\"center\">\n";
                    if (($td <> "view") AND ($td <> "del")) {
                        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&crp=' . $row["rpdt_code"] . '&cc=' . $row["rpdt_codecli"] . '&ca=' . $row["rpdt_codeage"] , '../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&crp=' . $row["rpdt_code"] . '&cc=' . $row["rpdt_codecli"] . '&ca=' . $row["rpdt_codeage"] , '../img/eye.png');
                        }
                    }
                    if (($rlic_dateoutf == "") AND ($td <> "del")) {
                        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 de problème"), 'lnk', 'rpbm_maj.php?td=add&tr=2&cr=' . $row["rpdt_code"] . '&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");
                ?>
            <?PHP
            } else
                echo _("Pas de matériel utilisant cette licence");
            $db->disconnect();
            ?>
        </div>

        <div id="rlic_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', '', $rlic_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, $rlic_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', '', $rlic_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, $rlic_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 $rlic_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 $rlic_tlogin; ?>" size="40"> /
                        <input name="tmdp" type="text" id="tmdp" value="<?PHP echo $rlic_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, $rlic_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, $rlic_tred); ?>
                    </td>
                </tr>
            </table>
        </div>

        <div id="rlic_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', '', $rlic_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, $rlic_mper, '', _("-- Faites votre choix --"), 1, FALSE, '', _("Pas de fréquence"));
                        echo ' / ';
                        cre_select('mtype', 'mtype', $maj_types, $rlic_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 $rlic_mlogin; ?>" size="40"> /
                        <input name="mmdp" type="text" id="mmdp" value="<?PHP echo $rlic_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 $rlic_mdvalf ?>" size="10"
                               maxlength="10" readonly>
                        <img src="../img/raz.png" id="raz mdvalf" border="0" align="absmiddle">
                        <span class="annot_petit_it">(<?PHP echo _("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 $rlic_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, $rlic_mae); ?>
                    </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, $rlic_mred); ?>
                    </td>
                </tr>
            </table>
        </div>
        </form>

        <div id="rlic_con">
            <!-- Liste des contrats gérant cette licence -->
            <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 '%" . $rlic_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)) {
                                        if (url_ok('cocl_maj.php?td=edit', FALSE) == TRUE) {
                                            $lst_maj = TRUE;
                                            cre_falselnk_img('', 'cocl_edit_'.$row["rlic_id"], 'span', 'center', _("Edition"), 'lnk', 'cocl_maj.php?td=edit&co=' . $row["cocl_code"] . '&cc=' . $row["cocl_codecli"] , '../img/edit.png');
                                        }
                                    } else {
                                        if (url_ok('cocl_maj.php?td=view', FALSE) == TRUE) {
                                            $lst_voir = TRUE;
                                            cre_falselnk_img('', 'cocl_view_'.$row["rlic_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
                                {
                                    if (url_ok('cocl_maj.php?td=view', FALSE) == TRUE) {
                                        $lst_voir = TRUE;
                                        cre_falselnk_img('', 'cocl_view_'.$row["rlic_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)) {
                                        $url_int = "int_maj.php?td=add&ci=&cc=" . $row["cocl_codecli"] . "&ca=" . $row["cocl_codeage"] . "&co=" . $row["cocl_code"];
                                        if (url_ok($url_int, FALSE) == TRUE) {
                                            $lst_int = TRUE;
                                            cre_falselnk_img('', 'int_add_'.$row["rlic_id"], 'span', 'center', _("Saisir intervention sur le contrat") . $row["cocl_code"], 'lnk', $url_int , '../img/int.png');
                                        }
                                    }
                                }


                                $urlimp = "cocl_pdf.php?code=" . $row["cocl_code"];
                                if (url_ok($urlimp, FALSE) == TRUE) {
                                    $lst_imp = TRUE;
                                    cre_falselnk_img('', 'cocl_prn_'.$row["rlic_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 cette licence") . '<br />';
                        $db->disconnect();
                        ?>
                    </td>
                </tr>
            </table>
        </div>

        <div id="rlic_pbm">
        <!-- Liste des problèmes déclarés -->
        <?PHP
        if (exist_rpbm($rlic_code) == TRUE) {
            ?>
            <table width="100%" border="0">
                <tr>
                    <td class="rubfrm" colspan="2" align="center">
                        <?PHP echo _("Historique des problèmes"); ?>
                    </td>
                </tr>
            </table>

            <form name="pbm_lst" id="pbm_lst" method="post" action="rlic_maj.php?td=<?PHP echo $td; ?>&cr=<?PHP echo $cr; ?>&cc=<?PHP echo $cc; ?>&crl=<?PHP echo $crl; ?>">
                <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 cette licence"); ?></span>
                        (<img src="../img/rpbmint.png" border="0" align="absmiddle">
                        = <?PHP echo _("en cours d'intervention"); ?>)</span>
                    </td>
                    <td align="right">
                        <?PHP
                        if (($td <> "del") AND ($rlic_dateoutf == "")) {
                            $url_add = "rpbm_maj.php?td=add&tr=1&cr=" . $rlic_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;";
                        ?>
                    </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` = '" . $rlic_code . "'";
                                break;
                            case 1 :
                                $rech = "SELECT * FROM `" . TBRPBM . "` WHERE `rpbm_coderlp` = '" . $rlic_code . "'";
                                $rech .= " AND (" . TBRPBM . ".rpbm_codeint IS NULL)";
                                break;
                            case 2 :
                                $rech = "SELECT * FROM `" . TBRPBM . "` WHERE `rpbm_coderlp` = '" . $rlic_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(trim($_POST['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";
                                echo datetolocal($row["rpbm_datett"]);
                                if (datetolocal($row["rpbm_datett"]) <> "") {
                                    echo "<span class=\"annot_petit_it\">";
                                    echo '<br />'._("Int.").' '  . $row["rpbm_codeint"];
                                    echo "</span>";
                                }
                                echo "</td>\n";

                                echo "<td align=\"center\">\n";
                                if ($td <> "del") {
                                    if ($row["rpbm_codeint"] == "") // On peut éditer ou supprimer uniquement si aucune intervention n'est rattachée
                                    {
                                        if (url_ok('rpbm_maj.php?td=edit', FALSE) == TRUE) {
                                            $lst_maj = TRUE;
                                            cre_falselnk_img('', 'rpbm_edit_'.$row["rlic_id"], 'span', 'center', _("Edition"), 'lnk', 'rpbm_maj.php?td=edit&tr=1&cr=' . $cr.'&crl='.$row["rpbm_coderlp"] . '&id=' . $row["rpbm_id"] . '&cap=1' , '../img/edit.png');
                                        }

                                        if (url_ok('rpbm_maj.php?td=del', FALSE) == TRUE) {
                                            $lst_del = TRUE;
                                            cre_falselnk_img('', 'rpbm_del_'.$row["rlic_id"], 'span', 'center', _("Suppression"), 'lnk', 'rpbm_maj.php?td=del&tr=1&cr=' .  $cr.'&crl='.$row["rpbm_coderlp"] . '&id=' . $row["rpbm_id"] . '&cap=1' , '../img/del.png');
                                        }
                                    } else {
                                        if (url_ok('rpbm_maj.php?td=view', FALSE) == TRUE) {
                                            $lst_voir = TRUE;
                                            cre_falselnk_img('', 'rpbm_view_'.$row["rlic_id"], 'span', 'center', _("Visualisation"), 'lnk', 'rpbm_maj.php?td=view&tr=1&cr=' .  $cr.'&crl='.$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 ($rlic_dateoutf == "")) {
                                $url_add = "rpbm_maj.php?td=add&tr=1&cr=" . $rlic_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>
        </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(_("Problème de paramètres"), 'warn', "index.php");
    else
        pop_ret_auto(_("Problème de paramètres"), 'warn', "rel_lst.php");
}
include_once("pied.php");
?>
</body>
</html>