<?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");

// Tout est ok...on lance la routine
include_once("../inc/fic_age.inc.php");
include_once("../inc/fic_cli.inc.php");
include_once("../inc/fic_cocl.inc.php");
include_once("../inc/fic_do.inc.php");
include_once("../inc/fic_droits.inc.php");
include_once("../inc/fic_pw.inc.php");
include_once("../inc/fic_zc.inc.php");
include_once("../inc/lst.inc.php");
include_once("../inc/func.inc.php");
include_once("../inc/func_date.inc.php");
include_once("../inc/func_geo.inc.php");
include_once("../inc/func_txt.inc.php");
include_once("../classes/ezSQL/shared/ez_sql_core.php");
include_once("../classes/ezSQL/mysqli/ez_sql_mysqli.php");
include_once("../inc/func_sql.inc.php");
Archivelog(@$_SESSION["code_log"]);
check_modules();

$_SESSION["typ_filtres"] = "cli";
$_SESSION['tab_tec_sel'] = [];
$_SESSION['tab_sites_sel'] = [];

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

$td = $_GET['td']; // Récupération type demande
$ntab = 1;
$init = 0;
if (isset($_GET["tl"]))
    $ntab = intval($_GET['ntab']); // Récupération type liste
if (($ntab <> 0) AND ($ntab <> 1))
    $ntab = 0;
if (isset($_GET['init']) && ($_GET['init'] <> ""))
    $init = intval($_GET['init']);


$pbm_cli = FALSE;

switch (@$_SESSION["niv_log"]) {
    case 1 :
        $tab_cli = give_tab_rcli(@$_SESSION["code_log"], TRUE);
        if (exist_in_array(@$_SESSION["code_log"], $tab_cli) == FALSE)
            $pbm_cli = TRUE;
        break;
    case 3 :
    case 4 :
        $ca = @$_SESSION["code_age"];

        $row = lit_enr_age($ca, TRUE);
        if (is_array($row)) {
            $row = encode_str($row);
            extract($row);
        } else
            $pbm_cli = TRUE;
        break;
    case 6 :
    case 7 :
        $cd = @$_SESSION["code_do"];

        $row = lit_enr_do($cd);
        if (is_array($row)) {
            $row = encode_str($row);
            extract($row);
        } else
            $pbm_cli = TRUE;
        break;
}

// Construction de la table d'entête pour les filtres par colonnes
if ((count($_SESSION["tri_col"]) <= 0) OR ($init == 1))
    $_SESSION["tri_col"] = give_tab_tri_col($cli_titre_col, $cli_titre_col_rech);
if ($ntab == 0)
    $_SESSION["typ_filtres"] = "cli";
else
    $_SESSION["typ_filtres"] = "scli";
$_SESSION["lnk_lst"] = $lnk_cli_lst;

?>
<!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 _("Liste Clients"); ?></title>

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

    <script type="text/javascript">
        <!--
        function init_all() {
            init_Body();
            init_autohref_classe('falselnkimg','');
            init_Tabs('onglets_lstcli');
            Focus_first();
        }

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

</head>

<body>

<?php include_once("../inc/entete.inc.php"); ?>
<div id="loading" style="position:absolute; z-index:1000;">
    <div id='loading-image'></div>
    <div id='loading-content'></div>
</div>
<div id='loading-debug' style="position:absolute; z-index:1000;"></div>
<?php
if ($pbm_cli == FALSE) {
    echo '<p align="center"><span class="titrepage">' . _("COMPTES et SITES CLIENTS") . '</span></p>';

    if ((@$_SESSION["niv_log"] == 1) OR (@$_SESSION["niv_log"] == 4) OR (@$_SESSION["niv_log"] == 3) OR (@$_SESSION["niv_log"] == 7) OR (@$_SESSION["niv_log"] == 6))
        echo '<p align="center" class="annot_std_it">(' . _("Que vous gérez") . ')</p>';

    $txt = '<p align="center" class="annot_gras_it">' . _("Merci de choisir un client pour saisir") . ' ';
    switch ($td) {
        case "con" :
            $txt .= ' ' . _("un contrat") . '</p>';
            echo $txt;
            break;
        case "int" :
            $txt .= ' ' . _("une intervention") . '</p>';
            echo $txt;
            break;
        case "loc" :
            $txt .= ' ' . _("un contrat de location") . '</p>';
            echo $txt;
            break;
        case "rel" :
            $txt .= ' ' . _("ou éditer un relevé") . '</p>';
            echo $txt;
            break;
        case "rpat" :
            $txt .= ' ' . _("ou éditer un patrimoine") . '</p>';
            echo $txt;
            break;
        default :
            break;
    }
    if (($td <> "int") AND ($td <> "con") AND ($td <> "rel") AND ($td <> "rpat") AND ($td <> "loc")) {
        if (@$_SESSION["niv_log"] >= 3)
            $fic_imp = "cli_lsti.php";
    }
    $url_add = "cli_maj.php?td=add";

    include_once("formr.inc.php");
    ?>
    <div id="onglets_lstcli">
        <ul>
            <li><a href="#lst_cli"><?PHP echo _("Clients"); ?></a></li>
            <li><a href="#lst_scli"><?PHP echo _("Sites Clients"); ?></a></li>
        </ul>
        <div id="lst_cli">
        <?PHP
        $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);

        switch (@$_SESSION["niv_log"]) {
            case 1 :
                $rech = cree_strrechlstclicli($tab_cli);
                $rechnum = cree_strrechlstclicli($tab_cli, TRUE);
                $rech .= crestr_triord($cli_titre_col, "cli_code", TRUE, $limit);
                break;
            case 2 :
                $rech = cree_strrechlstcliope();
                $rechnum = cree_strrechlstcliope(TRUE);
                $rech .= crestr_triord($cliope_titre_col, "cli_code", TRUE, $limit);
                break;
            default :
                $rech = cree_strrechlstcli(@$_SESSION["niv_log"], @$_SESSION["code_age"], @$_SESSION["code_do"],FALSE);
                $rechnum = cree_strrechlstcli(@$_SESSION["niv_log"], @$_SESSION["code_age"], @$_SESSION["code_do"], FALSE, TRUE);
                // Modification de la chaine de recherche en fonction des filtres par colonne
                $rech = cree_strrechlst_filtre_col($rech);
                $rechnum = cree_strrechlst_filtre_col($rechnum);
                $rech .= crestr_triord($cli_titre_col, "cli_code", TRUE, $limit);
                break;
        }
        // Exécution de la requête
        $numrows = $db->get_var($rechnum);
        $db->disconnect();
        if ($numrows > 0) {
            $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);

            $rows = $db->get_results($rech, ARRAY_A);

            // *** Pagination de pied
            pagine_lst($numrows, $limit);


            // *** Affichage de la table
            echo "<table class=\"Mtable\" border=\"0\" width=\"100%\" cellpadding=\"0\" cellspacing=\"0\">\n";

            // création entête
            switch (@$_SESSION["niv_log"]) {
                case 2 :
                    titlst($cliope_titre_col);
                    break;
                default :
                    titlst($cli_titre_col);
                    break;
            }

            echo "<th>" . _("Cliquer") . "</th>\n";

            $i = 0;
            foreach ($rows as $row) {
                $row = encode_str($row);
                $affcli = TRUE;

                if (($td == "int") OR ($td == "con") OR ($td == "rel") OR ($td == "rpat") OR ($td == "loc")) {
                    if ((account_locked($row["cli_code"], FALSE) == TRUE) OR ($row["cli_cpta"] == 3))
                        $affcli = FALSE;
                }

                if ($affcli == TRUE) {
                    // création de l'entête de ligne (TR)
                    creetrlst($i);

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

                    // traçabilité
                    if ((@$_SESSION["niv_log"] == 9) OR (@$_SESSION["niv_log"] == 5)) {
                        $url_detcli = "tra_lst.php?tx=r&tl=c&cr=" . $row["cli_code"];
                        if (url_ok($url_detcli, FALSE) == TRUE)
                            cre_falselnk_img('', 'cli_tra_'.$row["cli_id"], 'span', 'center', _("Traçabilité"), 'lnkpop', $url_detcli , '../img/trace.gif');
                    }

                    // CREATION d'icône en cas de problème potentiel
                    if (@$_SESSION["niv_log"] <> 1) {
                        if ($row["cli_cpta"] >= 1) {
                            $lst_sta = TRUE;
                            echo ' <a href="#" class="popw"><img src="../img/' . $ico_cpta[$row["cli_cpta"]] . '" alt="' . $mess_cpta[$row["cli_cpta"]] . '" border="0" align="absmiddle"><span>' . $mess_cpta[$row["cli_cpta"]] . '</span></a>';
                        }
                    }

                    // CREATION d'icône si client sous contrat
                    if (@$_SESSION["niv_log"] <> 2) {
                        if (nb_cocl_actifs_in_cli($row["cli_code"], FALSE) > 0) {
                            $url_cocl = "cocl_lst.php?ord=DES&tri=Code&search=" . $row["cli_code"] . "&rech=Rechercher";
                            cre_falselnk_img('', 'cli_detcocl_'.$row["cli_id"], 'span', 'center', _("Client sous contrat actif. Cliquez pour la liste des contrats"), 'lnk', $url_cocl , '../img/cli_con.png');
                        }
                    }

                    // Verrouillé ?
                    if ((@$_SESSION["niv_log"] == 5) OR (@$_SESSION["niv_log"] == 9)) {
                        if (account_locked($row["cli_code"], FALSE) == TRUE) {
                            echo ' <a href="#" class="popw"><img src="../img/locked.png" alt="' . _("Compte désactivé") . '" border="0" align="absmiddle"><span>' . _("Compte désactivé") . '</span></a>';
                            $locked = TRUE;
                        }
                    }

                    // icône du planning
                    if ((@$_SESSION["niv_log"] == 4) OR (@$_SESSION["niv_log"] == 5) OR (@$_SESSION["niv_log"] == 9) OR (@$_SESSION["niv_log"] == 10)) {
                        // On vérifie si le module planning est bien en place
                        if ($mod_planning == TRUE) {
                            $url_planning = 'plan_maj.php?typd=0&coded=' . $row["cli_code"] . '&typr=-1&tx=clil&from=clil';
                            cre_falselnk_img('', 'cli_pla_'.$row["cli_id"], 'span', 'center', _("Planning/Agenda"), 'lnkpop', $url_planning , '../img/planning.png',1020,760);
                        }
                    }

                    // détail propriétaire
                    if ((@$_SESSION["niv_log"] == 5) OR (@$_SESSION["niv_log"] == 9)) {
                        echo "<div class=\"annot_petit_it\" align=\"right\">";
                        if ($row["cli_prop"] <> NULL) {
                            $txt = _("Géré par") . " " . $row["cli_prop"];
                        } else
                            $txt = "(Non affecté)";
                        echo $txt;
                        echo "</div>";
                        if ($row["cli_codedo"] <> NULL) {
                            echo "<div class=\"annot_petit_it\" align=\"right\">";
                            $txt = _("DO") . " " . $row["cli_codedo"];
                            echo $txt;
                            echo "</div>";
                        }
                    }
                    echo "</td>\n";

                    echo "<td>";
                    if ($row["cli_ste"] <> "")
                        echo $row["cli_ste"];
                    else
                        echo "&nbsp;";
                    echo "</td>\n";
                    echo "<td>";
                    echo $row["cli_civilite"] . " " . $row["cli_nom"] . " " . $row["cli_prenom"];
                    echo "</td>\n";
                    switch (@$_SESSION["niv_log"]) {
                        case 2 :
                            break;
                        default :
                            echo "<td align=\"center\">" . $row["cli_telf"] . "</td>\n";
                            echo "<td align=\"center\">";
                            if ($row["cli_telp"] <> "")
                                echo $row["cli_telp"];
                            else
                                echo "-";
                            echo "</td>\n";

                            // CREATION lien dynamique sur email
                            echo "<td align=\"center\">";
                            echo "<a href=\"mailto:" . $row["cli_email"] . "\">" . $row["cli_email"] . "</a>";
                            echo "</td>\n";
                            break;
                    }

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

                    if (($td <> "int") AND ($td <> "con") AND ($td <> "rel") AND ($td <> "rpat") AND ($td <> "loc") AND ($td <> "dos") AND ($td <> "ot")) {
                        // Un Opérateur ne peut pas modifier un compte bloqué
                        $editok = TRUE;
                        if (@$_SESSION["niv_log"] == 2) {
                            if ($row["cli_cpta"] == 3)
                                $editok = FALSE;
                        }
                        if ($editok == TRUE) {
                            if (url_ok('cli_maj.php?td=edit&cc=' . $row["cli_code"], FALSE) == TRUE) {
                                $lst_maj = TRUE;
                                cre_falselnk_img('', 'cli_edit_'.$row["cli_id"], 'span', 'center', _("Edition"), 'lnk', 'cli_maj.php?td=edit&cc=' . $row["cli_code"] , '../img/edit.png');
                            }
                        }
                    }

                    if (($td == "int") OR ($td == "")) {
                        if (@$_SESSION["niv_log"] <> 1) {
                            if (url_ok('int_maj.php?td=add&ci=&cc=' . $row["cli_code"], FALSE) == TRUE) {
                                $lst_int = TRUE;
                                cre_falselnk_img('', 'cli_addint_'.$row["cli_id"], 'span', 'center', _("Ajouter intervention"), 'lnk', 'int_maj.php?td=add&ci=&cc=' . $row["cli_code"] , '../img/int.png');
                                // On vérifie si le module planning est bien en place
                                if ($mod_planning == TRUE) {
                                    if ((@$_SESSION["niv_log"] == 4) OR (@$_SESSION["niv_log"] == 5) OR (@$_SESSION["niv_log"] == 9)) {
                                        $lst_intp = TRUE;
                                        cre_falselnk_img('', 'cli_addpint_'.$row["cli_id"], 'span', 'center', _("Programmer interventions"), 'lnk', 'intp_maj.php?cc=' . $row["cli_code"] , '../img/intp.png');
                                    }
                                }
                            }
                        }
                    }

                    // création de contrats uniquement pour agences, centre de gestion, et administrateur
                    if ((@$_SESSION["niv_log"] == 4) OR (@$_SESSION["niv_log"] == 5) OR (@$_SESSION["niv_log"] == 9)) {
                        if (($td == "con") OR ($td == "")) {
                            if (url_ok('cocl_maj.php?td=add', FALSE) == TRUE) {
                                $lst_cocl = TRUE;
                                cre_falselnk_img('', 'cli_addcocl_'.$row["cli_id"], 'span', 'center', _("Ajouter contrat maintenance"), 'lnk', 'cocl_maj.php?td=add&co=&cc=' . $row["cli_code"] . '&ca=' , '../img/contrat.png');
                            }
                        }
                    }

                    // création de dossiers uniquement pour agences, centre de gestion, et administrateur
                    if ((@$_SESSION["niv_log"] == 3) OR (@$_SESSION["niv_log"] == 4) OR (@$_SESSION["niv_log"] == 5) OR (@$_SESSION["niv_log"] == 9)) {
                        if (($td == "dos") OR ($td == "")) {
                            if (url_ok('dos_maj.php?td=add', FALSE) == TRUE) {
                                $lst_dos = TRUE;
                                cre_falselnk_img('', 'cli_adddos_'.$row["cli_id"], 'span', 'center', _("Ajouter dossier"), 'lnk', 'dos_maj.php?td=add&cd=&cc=' . $row["cli_code"] . '&ca=' , '../img/dossier.png');
                            }
                        }
                    }

                    // création de contrats de location uniquement pour techniciens, agences, centre de gestion, et administrateur
                    // création de relevés uniquement pour agences, techniciens agences, centre de gestion, et administrateur
                    if ((@$_SESSION["niv_log"] == 3) OR (@$_SESSION["niv_log"] == 4) OR (@$_SESSION["niv_log"] == 5) OR (@$_SESSION["niv_log"] == 9)) {
                        if (($td == "loc") OR ($td == "")) {
                            if (url_ok('coloc_maj.php?td=add', FALSE) == TRUE) {
                                $lst_coloc = TRUE;
                                cre_falselnk_img('', 'cli_addcoloc_'.$row["cli_id"], 'span', 'center', _("Ajouter contrat location"), 'lnk', 'coloc_maj.php?td=add&tc=0&co=&cc=' . $row["cli_code"] . '&ca=' , '../img/coloc.png');
                            }
                        }

                        if (($td == "rel") OR ($td == "")) {
                            echo " ";
                            $rech2 = "SELECT * FROM `" . TBREL . "` WHERE `rel_codecli` = '" . $row["cli_code"] . "'";
                            $row2 = $db->get_row($rech2, ARRAY_A);
                            if ($row2) {
                                if (url_ok('rel_maj.php?td=edit', FALSE) == TRUE) {
                                    $lst_relexist = TRUE;
                                    cre_falselnk_img('', 'cli_relmaj_'.$row["cli_id"], 'span', 'center', _("Editer relevé de parc"), 'lnk', 'rel_maj.php?td=edit&cr=' . $row2["rel_code"].'&cc='.$row2["rel_codecli"], '../img/relexist.png');
                                }
                            } else {
                                if (url_ok('rel_maj.php?td=add', FALSE) == TRUE) {
                                    $lst_relcreer = TRUE;
                                    cre_falselnk_img('', 'cli_relmaj_'.$row["cli_id"], 'span', 'center', _("Ajouter relevé de parc"), 'lnk', 'rel_maj.php?td=add&cc=' . $row["cli_code"], '../img/rel.png');
                                }
                            }
                        }

                        if ($mod_patrimoine == TRUE) {
                            if (($td == "rpat") OR ($td == "")) {
                                echo " ";
                                $rech2 = "SELECT * FROM `" . TBRPAT . "` WHERE `rpat_codecli` = '" . $row["cli_code"] . "'";
                                $row2 = $db->get_row($rech2, ARRAY_A);
                                if ($row2) {
                                    if (url_ok('rpat_maj.php?td=edit', FALSE) == TRUE) {
                                        $lst_rpatexist = TRUE;
                                        cre_falselnk_img('', 'cli_rpatmaj_'.$row["cli_id"], 'span', 'center', _("Editer patrimoine"), 'lnk', 'rpat_maj.php?td=edit&cr=' . $row2["rel_code"] , '../img/rpatexist.gif');
                                    }
                                } else {
                                    if (url_ok('rpat_maj.php?td=add', FALSE) == TRUE) {
                                        $lst_rpatcreer = TRUE;
                                        cre_falselnk_img('', 'cli_rpatmaj_'.$row["cli_id"], 'span', 'center', _("Ajouter patrimoine"), 'lnk', 'rpat_maj.php?td=add&cc=' . $row["cli_code"] , '../img/rpat.gif');
                                    }
                                }
                            }
                        }
                    }

                    // Création d'OT uniquement pour agences propriétaires, centre de gestion, et administrateur
                    if ((@$_SESSION["niv_log"] == 4) OR (@$_SESSION["niv_log"] == 5) OR (@$_SESSION["niv_log"] == 9)) {
                        if ((($td == "ot") OR ($td == "")) AND ($row["cli_prop"] <> NULL)) {
                            if (url_ok('ot_maj.php?td=add', FALSE) == TRUE) {
                                $lst_otadd = TRUE;
                                cre_falselnk_img('', 'cli_addot_'.$row["cli_id"], 'span', 'center', _("Ajouter bon de travail"), 'lnk', 'ot_maj.php?td=add&tx=m&cc=' . $row["cli_code"] . '&ci=&co=&si=0&tr=' , '../img/ot_add.png');
                            }
                        }
                    }

                    if (($td <> "int") AND ($td <> "con") AND ($td <> "rel") AND ($td <> "loc") AND ($td <> "dos") AND ($td <> "ot")) {
                        // Possibilité de suppression uniquement à partir du niveau "technicien"
                        if (@$_SESSION["niv_log"] >= 3) {
                            if (url_ok('cli_maj.php?td=del', FALSE) == TRUE) {
                                $lst_del = TRUE;
                                cre_falselnk_img('', 'cli_del_'.$row["cli_id"], 'span', 'center', _("Suppression"), 'lnk', 'cli_maj.php?td=del&cc=' . $row["cli_code"] , '../img/del.png');
                            }
                            if (url_ok('cli_maji.php', FALSE) == TRUE) {
                                $lst_imp = TRUE;
                                $urlimp = "cli_maji.php?cc=" . $row["cli_code"];
                                cre_falselnk_img('', 'cli_prn_'.$row["cli_id"], 'span', 'center', _("Impresion fiche"), 'lnkpop', $urlimp , '../img/print.png');
                            }
                        }
                    }

                    echo "</td>\n";

                    echo "</tr>\n";
                }
                $i++;
            }
            echo "</table>\n";
            // *** Fin affichage de la table

            $db->disconnect();

            if ($locked == TRUE) {
                echo ' <img src="../img/locked.png" alt="' . _("Compte désactivé") . '" border="0" align="absmiddle">';
                echo " : " . _("Compte désactivé");
            }

            // *** Pagination de pied
            pagine_lst($numrows, $limit);

            $taille_piedla = "";
            include_once("piedla.inc.php");
        } else
            retpp();
        ?>
        </div>

        <div id="lst_scli">
        <?PHP
        $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);

        switch (@$_SESSION["niv_log"]) {
            case 1 :
                $rech2 = cree_strrechlstsclicli($tab_cli);
                $rechnum2 = cree_strrechlstsclicli($tab_cli, TRUE);
                $rech2 .= crestr_triord($scli_titre_col2, "scli_ste", TRUE, $limit);
                break;
            case 2 :
                $rech2 = cree_strrechlstscliope();
                $rechnum2 = cree_strrechlstscliope(TRUE);
                $rech2 .= crestr_triord($scliope_titre_col2, "scli_ste", TRUE, $limit);
                break;
            default :
                $rech2 = cree_strrechlstscli(@$_SESSION["niv_log"], @$_SESSION["code_age"], @$_SESSION["code_do"]);
                $rechnum2 = cree_strrechlstscli(@$_SESSION["niv_log"], @$_SESSION["code_age"], @$_SESSION["code_do"], TRUE);
                $rech2 .= crestr_triord($scli_titre_col2, "scli_ste", TRUE, $limit);
                break;
        }

        // Exécution de la requête
        $numrows2 = $db->get_var($rechnum2);
        $db->disconnect();

        if ($numrows2 > 0) {
            $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);

            $rows = $db->get_results($rech2, ARRAY_A);

            // *** Pagination de pied
            pagine_lst($numrows2, $limit);


            // *** Affichage de la table
            echo "<table class=\"Mtable\" border=\"0\" width=\"100%\" cellpadding=\"0\" cellspacing=\"0\">\n";

            // création de l'entête de la table "sites secondaires"
            switch (@$_SESSION["niv_log"]) {
                case 2 :
                    titlst($scliope_titre_col2);
                    break;
                default :
                    titlst($scli_titre_col2);
                    break;
            }
            echo "<th>" . _("Cliquer") . "</th>\n";

            $i = 0;
            foreach ($rows as $row) {
                $row = encode_str($row);
                $affcli = TRUE;

                $row2 = lit_enr_cli($row["scli_codecli"], FALSE);
                if (is_array($row2)) {
                    $row2 = encode_str($row2);
                    extract($row2);
                    if (($td == "int") OR ($td == "con") OR ($td == "rel") OR ($td == "loc") OR ($_SESSION["niv_log"] == 2)) {
                        if ((account_locked($cli_code, FALSE) == TRUE) OR ($cli_cpta == 3))
                            $affcli = FALSE;
                    }

                    if ($affcli == TRUE) {
                        // création de l'entête de ligne (TR)
                        creetrlst($i);

                        echo "<td>\n";
                        echo $row["scli_codecli"];
                        echo "<div class=\"annot_petit_it\" style=\"padding-left: 10px;\">";
                        if ($row["cli_ste"] <> "")
                            echo $row["cli_ste"] . "<br />";
                        echo $row["cli_civilite"] . " " . $row["cli_nom"] . " " . $row["cli_prenom"];
                        echo "</div>";
                        echo "</td>\n";
                        echo "<td>\n";
                        echo $row["scli_ste"];
                        echo "<br />";
                        echo $row["scli_adr1"];
                        echo "<br />";
                        if ($row["scli_adr2"] <> "") {
                            echo $row["scli_adr2"];
                            echo "<br />";
                        }
                        echo Retournecp_Id($row["scli_ville"], FALSE) . " " . Retourneville_Id($row["scli_ville"], FALSE);
                        // détail propriétaire
                        if (((@$_SESSION["niv_log"] == 5) OR (@$_SESSION["niv_log"] == 9)) OR (((@$_SESSION["niv_log"] == 4) OR (@$_SESSION["niv_log"] == 3)) AND ($cli_prop = @$_SESSION["code_age"]))) {
                            echo "<div class=\"annot_petit_it\" align=\"right\">";
                            $txt = _("Géré par") . " ";
                            switch ($row["scli_prop"]) {
                                case "-1" :
                                    $txt .= _("agences couvrant le département");
                                    break;
                                case "0" :
                                    if (trim($cli_prop) <> "")
                                        $txt .= $cli_prop;
                                    else
                                        $txt = _("Non affecté");
                                    break;
                                default :
                                    if (trim($row["scli_prop"]) <> "")
                                        $txt .= $row["scli_prop"];
                                    else {
                                        if (trim($cli_prop) <> "")
                                            $txt .= $cli_prop;
                                        else
                                            $txt = _("Non affecté");
                                    }
                                    break;
                            }
                            echo $txt;
                            echo "</div>";
                        }
                        echo "</td>\n";
                        if ($_SESSION["niv_log"] <> 2) {
                            echo "<td align=\"center\">\n";
                            echo _("T.") . $row["scli_telf"];
                            echo "</td>\n";
                            echo "<td align=\"center\">\n";
                            if ($row["scli_fax"] <> "")
                                echo _("F.") . $row["scli_fax"];
                            else
                                echo "-";
                            echo "</td>\n";
                            echo "<td align=\"center\">\n";
                            echo "<a href=\"mailto:" . $row["scli_email"] . "\">" . $row["scli_email"] . "</a>";
                            echo "</td>\n";
                            echo "<td align=\"center\">\n";
                            echo $row["scli_rcivil"] . " " . $row["scli_rprenom"] . " " . $row["scli_rnom"];
                            echo "<br />";
                            echo _("T.") . $row["scli_rtelf"];
                            if ($row["scli_rfax"] <> "") {
                                echo "<br />";
                                echo _("F.") . $row["scli_rfax"];
                            }
                            if ($row["scli_rtelp"] <> "") {
                                echo "<br />";
                                echo _("P.") . $row["scli_rtelp"];
                            }
                            echo "</td>\n";
                        }

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

                        if (@$_SESSION["niv_log"] <> 1) {
                            if ((($td == "int") OR ($td == "")) AND ($row["scli_actif"] == 1)) {
                                $lst_int = TRUE;
                                cre_falselnk_img('', 'scli_addint_'.$row["scli_id"], 'span', 'center', _("Ajouter intervention"), 'lnk', 'int_maj.php?td=add&ci=&cc=' . $cli_code . '&sid=' . $row["scli_id"] , '../img/int.png');
                            }
                        } else
                            echo "-";

                        // création d'OT uniquement pour agences propriétaires, centre de gestion, et administrateur
                        if ((@$_SESSION["niv_log"] == 4) OR (@$_SESSION["niv_log"] == 5) OR (@$_SESSION["niv_log"] == 9)) {
                            if (((($td == "ot") OR ($td == "")) AND (trim($cli_prop) <> "")) AND ($row["scli_actif"] == 1)) {
                                $lst_otadd = TRUE;
                                cre_falselnk_img('', 'scli_addot_'.$row["scli_id"], 'span', 'center', _("Ajouter bon de travail"), 'lnk', 'ot_maj.php?td=add&tx=m&cc=' . $cli_code . '&ci=&co=&si=' . $row["scli_id"] . '&tr=' , '../img/ot_add.png');
                            }
                        }

                        echo "</td>\n";

                        echo "</tr>\n";
                    }
                    $i++;
                }
            }
            echo "</table>\n";
            // *** Fin affichage de la table

            $db->disconnect();

            if ($locked == TRUE) {
                echo ' <img src="../img/locked.png" alt="' . _("Compte désactivé") . '" border="0" align="absmiddle">';
                echo " : " . _("Compte désactivé");
            }

            // *** Pagination de pied
            pagine_lst($numrows2, $limit);

            $taille_piedla = "";
            include_once("piedla.inc.php");
        } else
            retpp();
        ?>
        </div>

    </div>

    <?PHP
} else
    pop_ret_auto(_("Problème de paramètres"), 'warn', "index.php");
include_once("pied.php");
?>
</body>
</html>