<?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/fic_age.inc.php");
include_once("../inc/fic_cli.inc.php");
include_once("../inc/fic_do.inc.php");
include_once("../inc/fic_droits.inc.php");
include_once("../inc/fic_hum.inc.php");
include_once("../inc/fic_ope.inc.php");
include_once("../inc/fic_st.inc.php");
include_once("../inc/fic_tec.inc.php");
include_once("../inc/fic_txt.inc.php");
include_once("../inc/fic_zc.inc.php");
include_once("../inc/fic_zoc.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_mail.inc.php");
include_once("../inc/func_txt.inc.php");
include_once("../inc/func_txtcm.inc.php");
include_once("../inc/lst.inc.php");
include_once("../classes/phpmailer/class.phpmailer.php");
include_once("../classes/phpmailer/class.smtp.php");
include_once("../inc/mail.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();

// Ce champ ne doit pas être nettoyé (codes HTML)
if (isset($_POST['txtmail']))
    $txt = trim($_POST['txtmail']);

// Nettoyage du GET et du POST
$_GET = clean_str($_GET);
$_POST = clean_str($_POST);

$email_ok = TRUE;
$email_envoye = FALSE;
$retourliste = TRUE;
$nbsel = 0;
$td= '';
$url_link = '';

if (isset($_GET['td']) )
    $td = @$_GET['td']; // On récupère le type en ligne de commande
else
    if (isset($_POST['td']) )
        $td = $_POST['td'];
if ($td <> '')
    $url_link = "email_maj.php?td=" . $td;
else
    $email_ok = FALSE;

// vérification du mode du connecté (pour éviter les hacks)
switch (@$_SESSION["niv_log"]) {
    case 1 :
    case 2 :
    case 3 :
    case 7 :
    case 11 :
        $email_ok = FALSE;
        break;

    // Les agences n'ont droit qu'aux emailings clients et techniciens
    case 4 :
        if (($td <> "cli") AND ($td <> "tec"))
            $email_ok = FALSE;
        else {
            $row = lit_enr_age(@$_SESSION["code_age"], TRUE);
            if (is_array($row)) {
                $row = encode_str($row);
                extract($row);
                $age = $age_code;
                $pays = $age_codepays;
            }
        }
        break;

    // Les donneurs d'ordres n'ont droit qu'aux emailings techniciens donneurs d'ordres et de leurs clients
    case 6 :
        if (($td <> "tecd") AND ($td <> "cli"))
            $email_ok = FALSE;
        else {
            $row = lit_enr_do(@$_SESSION["code_do"]);
            if (is_array($row)) {
                $row = encode_str($row);
                extract($row);
                $age = $do_code;
                $pays = $do_codepays;
            }
        }
        break;

    // Les sous-traitants n'ont droit qu'aux emailings techniciens sous-traitants
    case 10 :
        if ($td <> "tecs")
            $email_ok = FALSE;
        else {
            $row = lit_enr_st(@$_SESSION["code_st"]);
            if (is_array($row)) {
                $row = encode_str($row);
                extract($row);
                $age = $st_code;
                $pays = $st_codepays;
            }
        }
        break;
}

$validp = FALSE;
if (@$_POST["nbutton"] == "suiv")
    $validp = TRUE;

$exped = FALSE;
$typeexp = "";
if (@$_POST["nbutton"] == "exp") {
    $exped = TRUE;
    if (!ini_get('safe_mode'))
        set_time_limit(0); // On demande à PHP de ne pas interrrompre le script pendant le traitement
    // Détermination de l'expéditeur
    switch (@$_SESSION["niv_log"]) {
        case 9 :
            $typeexp = "adm";
            break;
        case 5 :
            $typeexp = "cdg";
            break;
        case 4 :
            $typeexp = "age";
            break;
        case 6 :
            $typeexp = "do";
            break;
        case 10 :
            $typeexp = "st";
            break;
        default :
            break;
    }
}

$cv = "N";

if (($validp == TRUE) OR ($exped == TRUE)) {
    $sujet = @$_POST["sujet"];
    $cv = @$_POST["cv"];
}

switch ($td) {
    case "age" :
        $titre = _("EMAILING AGENCES");

        if (($validp == TRUE) OR ($exped == TRUE)) {
            $cat = @$_POST["cat"];
            $pays = @$_POST["pays"];
            $dep = @$_POST["deptxt"];
            $zone = @$_POST["zonetxt"];
            $tab_dep = explode("_", $dep);
            $tab_zone = explode("_", $zone);
            for ($i = 0; $i < count($_POST["type_dest"]); $i++) {
                $type_mail[$_POST["type_dest"][$i]] = 1;
            }

            if ($exped == TRUE) {
                if ($txt <> "") // Le texte envoyé doit exister
                {
                    if (count($_POST["type_dest"]) <> 0) // Il doit y avoir un type de destinataire
                    {
                        if (count($_POST["age_choisie"]) <> 0) // Il doit y avoir au moins une agence sélectionnée
                        {
                            $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
                            for ($i = 0; $i < count($_POST["age_choisie"]); $i++) {
                                $rech = "SELECT age_code FROM `" . TBAGE . "` WHERE `age_id`= '" . $_POST["age_choisie"][$i] . "'";
                                $row = $db->get_row($rech, ARRAY_A);
                                if ($row) {
                                    $row = encode_str($row);
                                    extract($row);
                                    $email_envoye = envoi_emailing("age", $type_mail, $age_code, $typeexp, (@$_SESSION["code_log"]), $txt, $sujet);
                                    if ($email_envoye == false) {
                                        $msg = _("Problème lors de l'envoi de l'emailing");
                                        $retourliste = FALSE;
                                        break;
                                    }
                                    sleep($smtp_pausem);
                                }
                            }
                            $db->disconnect();
                        } else {
                            $msg = _("Vous n'avez choisi aucune agence");
                            $retourliste = FALSE;
                            break;
                        }
                    } else {
                        $msg = _("Vous n'avez choisi aucun type de destinataire");
                        $retourliste = FALSE;
                        break;
                    }
                } else {
                    $msg = _("Le texte de votre email est vide");
                    $retourliste = FALSE;
                    break;
                }
            }
        }
        break;

    case "cli" :
        $titre = _("EMAILING CLIENTS");

        if (($validp == TRUE) OR ($exped == TRUE)) {
            $cat = @$_POST["cat"];
            $pays = @$_POST["pays"];
            $age = @$_POST["age"];
            $dep = @$_POST["deptxt"];
            $tab_dep = explode("_", $dep);
            for ($i = 0; $i < count($_POST["type_dest"]); $i++) {
                $type_mail[$_POST["type_dest"][$i] - 1] = 1;
            }

            if ($exped == TRUE) {
                if ($txt <> "") // Le texte envoyé doit exister
                {
                    if (count($_POST["type_dest"]) <> 0) // Il doit y avoir au moins un type de destinataire
                    {
                        if (count($_POST["cli_choisi"]) <> 0) // Il doit y avoir au moins un client de choisi
                        {
                            $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
                            for ($i = 0; $i < count($_POST["cli_choisi"]); $i++) {
                                $rech = "SELECT cli_code FROM `" . TBCLI . "` WHERE `cli_id`= '" . $_POST["cli_choisi"][$i] . "'";
                                $row = $db->get_row($rech, ARRAY_A);
                                if ($row) {
                                    $row = encode_str($row);
                                    extract($row);
                                    $email_envoye = envoi_emailing("cli", $type_mail, $cli_code, $typeexp, (@$_SESSION["code_log"]), $txt, $sujet);
                                    if ($email_envoye == false) {
                                        $msg = _("Problème lors de l'envoi de l'emailing");
                                        $retourliste = FALSE;
                                        break;
                                    }
                                    sleep($smtp_pausem);
                                }
                            }
                            $db->disconnect();
                        } else {
                            $msg = _("Vous n'avez choisi aucun client");
                            $retourliste = FALSE;
                            break;
                        }
                    } else {
                        $msg = _("Vous n'avez choisi aucun type de destinataire");
                        $retourliste = FALSE;
                        break;
                    }
                } else {

                    $msg = _("Le texte de votre email est vide");
                    $retourliste = FALSE;
                    break;
                }
            }
        }
        break;

    case "do" :
        $titre = _("EMAILING DONNEURS D'ORDRES");

        if (($validp == TRUE) OR ($exped == TRUE)) {
            $pays = @$_POST["pays"];
            $dep = @$_POST["deptxt"];
            $tab_dep = explode("_", $dep);
            for ($i = 0; $i < count($_POST["type_dest"]); $i++) {
                $type_mail[$_POST["type_dest"][$i] - 1] = 1;
            }

            if ($exped == TRUE) {
                if ($txt <> "") // Le texte envoyé doit exister
                {
                    if (count($_POST["type_dest"]) <> 0) // Il doit y avoir un type de destinataire
                    {
                        if (count($_POST["do_choisi"]) <> 0) // Il doit y avoir au moins un donneur d'ordre sélectionné
                        {
                            $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
                            for ($i = 0; $i < count($_POST["do_choisi"]); $i++) {
                                $rech = "SELECT do_code FROM `" . TBDO . "` WHERE `do_id`= '" . $_POST["do_choisi"][$i] . "'";
                                $row = $db->get_row($rech, ARRAY_A);
                                if ($row) {
                                    $row = encode_str($row);
                                    extract($row);
                                    $email_envoye = envoi_emailing("do", $type_mail, $do_code, $typeexp, (@$_SESSION["code_log"]), $txt, $sujet);
                                    if ($email_envoye == false) {
                                        $msg = _("Problème lors de l'envoi de l'emailing");
                                        $retourliste = FALSE;
                                        break;
                                    }
                                    sleep($smtp_pausem);
                                }
                            }
                            $db->disconnect();
                        } else {
                            $msg = _("Vous n'avez choisi aucun donneur d'ordres");
                            $retourliste = FALSE;
                            break;
                        }
                    } else {
                        $msg = _("Vous n'avez choisi aucun type de destinataire");
                        $retourliste = FALSE;
                        break;
                    }
                } else {
                    $msg = _("Le texte de votre email est vide");
                    $retourliste = FALSE;
                    break;
                }
            }
        }


        break;

    case "ope" :
        $titre = _("EMAILING OPERATEURS");

        if (($validp == TRUE) OR ($exped == TRUE)) {
            $pays = @$_POST["pays"];
            $dep = @$_POST["deptxt"];
            $sujet = @$_POST["sujet"];
            $tab_dep = explode("_", $dep);

            if ($exped == TRUE) {
                if ($txt <> "") // Le texte envoyé doit exister
                {
                    if (count($_POST["ope_choisi"]) <> 0) // Il doit y avoir au moins un Opérateur de choisi
                    {
                        $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
                        for ($i = 0; $i < count($_POST["ope_choisi"]); $i++) {
                            $rech = "SELECT ope_code FROM `" . TBOPE . "` WHERE `ope_id`= '" . $_POST["ope_choisi"][$i] . "'";
                            $row = $db->get_row($rech, ARRAY_A);
                            if ($row) {
                                $row = encode_str($row);
                                extract($row);
                                $email_envoye = envoi_emailing("ope", "", $ope_code, $typeexp, (@$_SESSION["code_log"]), $txt, $sujet);
                                if ($email_envoye == false) {
                                    $msg = _("Problème lors de l'envoi de l'emailing");
                                    $retourliste = FALSE;
                                    break;
                                }
                                sleep($smtp_pausem);
                            }
                        }
                        $db->disconnect();
                    } else {
                        $msg = _("Vous n'avez choisi aucun Opérateur");
                        $retourliste = FALSE;
                        break;
                    }
                } else {
                    $msg = _("Le texte de votre email est vide");
                    $retourliste = FALSE;
                    break;
                }
            }
        }
        break;

    case "st" :
        $titre = _("EMAILING SOUS-TRAITANTS");

        if (($validp == TRUE) OR ($exped == TRUE)) {
            $cat = @$_POST["cat"];
            $pays = @$_POST["pays"];
            $dep = @$_POST["deptxt"];
            $zone = @$_POST["zonetxt"];
            $tab_dep = explode("_", $dep);
            $tab_zone = explode("_", $zone);
            for ($i = 0; $i < count($_POST["type_dest"]); $i++) {
                $type_mail[$_POST["type_dest"][$i] - 1] = 1;
            }

            if ($exped == TRUE) {
                if ($txt <> "") // Le texte envoyé doit exister
                {
                    if (count($_POST["type_dest"]) <> 0) // Il doit y avoir un type de destinataire
                    {
                        if (count($_POST["st_choisi"]) <> 0) // Il doit y avoir au moins un sous-traitant sélectionné
                        {
                            $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
                            for ($i = 0; $i < count($_POST["st_choisi"]); $i++) {
                                $rech = "SELECT st_code FROM `" . TBST . "` WHERE `st_id`= '" . $_POST["st_choisi"][$i] . "'";
                                $row = $db->get_row($rech, ARRAY_A);
                                if ($row) {
                                    $row = encode_str($row);
                                    extract($row);
                                    $email_envoye = envoi_emailing("st", $type_mail, $st_code, $typeexp, (@$_SESSION["code_log"]), $txt, $sujet);
                                    if ($email_envoye == false) {
                                        $msg = _("Problème lors de l'envoi de l'emailing");
                                        $retourliste = FALSE;
                                        break;
                                    }
                                    sleep($smtp_pausem);
                                }
                            }
                            $db->disconnect();
                        } else {
                            $msg = _("Vous n'avez choisi aucun sous-traitant");
                            $retourliste = FALSE;
                            break;
                        }
                    } else {
                        $msg = _("Vous n'avez choisi aucun type de destinataire");
                        $retourliste = FALSE;
                        break;
                    }
                } else {
                    $msg = _("Le texte de votre email est vide");
                    $retourliste = FALSE;
                    break;
                }
            }
        }


        break;

    case "tec" :
    case "tecd" :
    case "tecs" :
        $titre = _("EMAILING TECHNICIENS");

        if (($validp == TRUE) OR ($exped == TRUE)) {
            $age = @$_POST["age"];
            $pays = @$_POST["pays"];
            $dep = @$_POST["deptxt"];
            $tab_dep = explode("_", $dep);

            if ($exped == TRUE) {
                if ($txt <> "") // Le texte envoyé doit exister
                {
                    if (count($_POST["tec_choisi"]) <> 0) // Il doit y avoir au moins un technicien de choisi
                    {
                        $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
                        for ($i = 0; $i < count($_POST["tec_choisi"]); $i++) {
                            $rech = "SELECT tec_code FROM `" . TBTEC . "` WHERE `tec_id`= '" . $_POST["tec_choisi"][$i] . "'";
                            $row = $db->get_row($rech, ARRAY_A);
                            if ($row) {
                                $row = encode_str($row);
                                extract($row);
                                $email_envoye = envoi_emailing($td, "", $tec_code, $typeexp, (@$_SESSION["code_log"]), $txt, $sujet);
                                if ($email_envoye == false) {
                                    $msg = _("Problème lors de l'envoi de l'emailing");
                                    $retourliste = FALSE;
                                    break;
                                }
                                sleep($smtp_pausem);
                            }
                        }
                        $db->disconnect();
                    } else {
                        $msg = _("Vous n'avez choisi aucun technicien");
                        $retourliste = FALSE;
                        break;
                    }
                } else {
                    $msg = _("Le texte de votre email est vide");
                    $retourliste = FALSE;
                    break;
                }
            }
        }
        break;
    default :
        $email_ok = FALSE;
        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 _("Emailing"); ?></title>

    <?PHP include_once("../inc/header.inc.php"); ?>
    <script language="javascript">
        <!--
        var tab1_champ = [];
        //-->
    </script>

    <script type="text/javascript">
        <!--
        function init_all() {
            init_Body();
            init_txtfromvalsel('dep', 'deptxt');
            init_txtfromvalsel('zone', 'zonetxt');
            init_autohref('init', 'click', '<?PHP echo $url_link; ?>',false);
            <?PHP
            if (($email_ok==TRUE) AND ($validp==FALSE))
            {
                switch ($td)
                {
                    case "age" :
                        echo 'init_ajax_dep2();';
                        echo 'init_ajax_dep_zc_pays();';
                        break;
                    case "st" :
                        echo 'init_ajax_dep2();';
                        echo 'init_ajax_dep_zc_pays_2();';
                        break;
                    case "cli" :
                        if ($typeexp<>"do")
                        {
                            echo 'init_ajax_age_dep_pays();';
                            echo 'init_ajax_dep2();';
                        }
                        break;
                    case "tec" :
                    case "tecd" :
                    case "tecs" :
                        echo 'init_ajax_dep2();';
                        if ((@$_SESSION["niv_log"] == 4) OR (@$_SESSION["niv_log"] == 6) AND (@$_SESSION["niv_log"] == 10))
                            echo "readonly_id('age-pays',false);";
                        break;
                    case "ope" :
                    case "do" :
                        echo 'init_ajax_dep2();';
                        break;
                }
                echo "init_valid_form('suiv','email_maj','".$_SESSION['date_fmtshort']."',tab1_champ,'','');";
            }

            if ($validp == TRUE)
            {
                echo "init_check_all('sel','email_maj','"._("Tous")."','"._("Aucun")."');";
                echo "$('#txtmail').ckeditor();";
                echo "init_valid_form('exp','email_maj','".$_SESSION['date_fmtshort']."',tab1_champ,'','');";
            }

            if (($email_ok == TRUE) AND ($email_envoye == FALSE) AND ($retourliste == FALSE))
                echo "warn_txt('" . str_escape($msg) . "');";
            ?>
            Focus_first();
        }

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

</head>
<body>
<?PHP include_once("../inc/entete.inc.php"); ?>
<p align="center"><span class="titrepage"><?PHP echo $titre ?></span></p>

<p>&nbsp;</p>
<?PHP
if ($email_ok == TRUE) {
    if ($email_envoye == FALSE) {
        echo '<form name="email_maj" id="email_maj" method="post" action="email_maj.php">';
        echo '<input name="titre" type="hidden" id="titre" value="'.$titre.'">';
        echo '<input name="td" type="hidden" id="td" value="'.$td.'">';
        echo '<input name="nbutton" type="hidden" id="nbutton" value="">';
        if ($validp == FALSE) {
            switch ($td) {
            /******************************************************/
            /**                    AGENCES                       **/
            /******************************************************/
            case "age" :
            ?>
                <!-- Liste des catégories -->
                <table width="100%" border="0">
                    <tr>
                        <td width="160" class="rubfrm" id="f_cat" align="right"><?PHP echo _("Catégorie"); ?></td>
                        <td>
                            <?PHP
                            // Création de la liste des catégories
                            $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
                            $sql = "SELECT * FROM `" . TBACAT . "` ORDER BY acat_desc";
                            $rows = $db->get_results($sql, ARRAY_A);
                            $db->disconnect();

                            cre_select_tab('cat', 'cat', $rows, 'acat_code', 'acat_desc', '', '*', '*', _("---------- Toutes ----------"), 5, TRUE);
                            ?>
                        </td>
                    </tr>
                    <tr>
                        <td class="rubfrm" id="f_pays" align="right"><?PHP echo _("Pays"); ?></td>
                        <td>
                            <?PHP
                            // Création de la liste des pays
                            $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
                            $rech = "SELECT * FROM `" . TBPAYS . "` ORDER BY pays_nom";
                            $rows = $db->get_results($rech, ARRAY_A);
                            $db->disconnect();
                            cre_select_tab('pays', 'pays', $rows, 'pays_code', 'pays_nom', '', $pays, '', _("-- Faites votre choix --"), 1, FALSE, '-1', _("-- Inconnu --"));
                            ?>
                        </td>
                    </tr>
                    <tr>
                        <td class="rubfrm" id="f_dep" align="right"><?PHP echo _("Département"); ?></td>
                        <td>
                            <?PHP
                            $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
                            $rech = "SELECT * FROM `" . TBDEP . "` WHERE dep_codepays='" . str_majuscules($pays) . "' ORDER BY dep_code";
                            $rows = $db->get_results($rech, ARRAY_A);
                            $db->disconnect();
                            cre_select_tab('dep[]', 'dep', $rows, 'dep_code', 'dep_code', 'dep_nom', $tab_dep, '', _("-- Faites votre choix --"), 5, TRUE);
                            ?>
                            <input name="deptxt" type="hidden" id="deptxt" value="<?PHP echo $dep ?>" size="50" readonly>
                        </td>
                    </tr>
                    <tr>
                        <td class="rubfrm" id="f_zone" align="right"><?PHP echo _("Zone de chalandise"); ?></td>
                        <td>
                            <?PHP
                            $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
                            $rech = "SELECT * FROM `" . TBZCC . "`, `" . TBDEP . "`";
                            $rech .= " WHERE " . TBZCC . ".zcc_codepays='" . str_majuscules($pays) . "' AND " . TBZCC . ".zcc_codedep=" . TBDEP . ".dep_code ORDER BY " . TBDEP . ".dep_code";
                            $rows = $db->get_results($rech, ARRAY_A);
                            $db->disconnect();
                            cre_select_tab('zone[]', 'zone', $rows, 'dep_code', 'dep_code', 'dep_nom', $tab_zone, '', _("-- Faites votre choix --"), 5, TRUE);
                            ?>
                            <input name="zonetxt" type="hidden" id="zonetxt" value="<?PHP echo $zone ?>" size="50" readonly>
                    </tr>
                </table>
                <?PHP
                break;

            /******************************************************/
            /**                SOUS-TRAITANTS                    **/
            /******************************************************/

            case "st" :
            ?>
                <!-- Liste des spécialités -->
                <table width="100%" border="0">
                    <tr>
                        <td width="160" class="rubfrm" id="f_cat"
                            align="right"><?PHP echo _("Spécialité"); ?></td>
                        <td>
                            <?PHP
                            $tab_first_options = [
                                "*" => _("-- TOUTES LES SPECIALITES --")
                            ];
                            // création de la liste des catégories
                            $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
                            $rech = "SELECT * FROM `" . TBSP . "` ORDER BY sp_desc";
                            $rows = $db->get_results($rech, ARRAY_A);
                            $db->disconnect();
                            cre_select_tab('cat', 'act', $rows, 'sp_code', 'sp_desc', '', $cat, '', _("-- Faites votre choix --"), 1, FALSE, '', '', TRUE, TRUE, FALSE, $tab_first_options);
                            ?>
                            <div class="annot_petit_it">(<?PHP echo("Ne s'afficheront que les sous-traitants actifs"); ?>)</div>
                        </td>
                    </tr>
                    <tr>
                        <td class="rubfrm" id="f_pays" align="right"><?PHP echo _("Pays"); ?></td>
                        <td>
                            <?PHP
                            // Création de la liste des pays
                            $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
                            $rech = "SELECT * FROM `" . TBPAYS . "` ORDER BY pays_nom";
                            $rows = $db->get_results($rech, ARRAY_A);
                            $db->disconnect();
                            cre_select_tab('pays', 'pays', $rows, 'pays_code', 'pays_nom', '', $pays, '', _("-- Faites votre choix --"), 1, FALSE, '-1', _("-- Inconnu --"));
                            ?>
                        </td>
                    </tr>
                    <tr>
                        <td class="rubfrm" id="f_dep" align="right"><?PHP echo _("Département"); ?></td>
                        <td>
                            <?PHP
                            $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
                            $rech = "SELECT * FROM `" . TBDEP . "` WHERE dep_codepays='" . str_majuscules($pays) . "' ORDER BY dep_code";
                            $rows = $db->get_results($rech, ARRAY_A);
                            $db->disconnect();
                            cre_select_tab('dep[]', 'dep', $rows, 'dep_code', 'dep_code', 'dep_nom', $tab_dep, '', _("-- Faites votre choix --"), 5, TRUE);
                            ?>
                            <input name="deptxt" type="hidden" id="deptxt" value="<?PHP echo $dep ?>" size="50"
                                   readonly>
                        </td>
                    </tr>
                    <tr>
                        <td class="rubfrm" id="f_zone" align="right"><?PHP echo _("Zone de chalandise"); ?></td>
                        <td>
                            <?PHP
                            $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
                            $rech = "SELECT * FROM `" . TBZOC . "`, `" . TBDEP . "`";
                            $rech .= " WHERE " . TBZOC . ".zoc_codepays='" . str_majuscules($pays) . "' AND " . TBZOC . ".zoc_codedep=" . TBDEP . ".dep_code ORDER BY " . TBDEP . ".dep_code";
                            $rows = $db->get_results($rech, ARRAY_A);
                            $db->disconnect();
                            cre_select_tab('zone[]', 'zone', $rows, 'dep_code', 'dep_code', 'dep_nom', $tab_zone, '', _("-- Faites votre choix --"), 5, TRUE);
                            ?>
                            <input name="zonetxt" type="hidden" id="zonetxt" value="<?PHP echo $zone ?>" size="50" readonly>
                    </tr>
                </table>
                <?PHP
                break;

            /******************************************************/
            /**               DONNEURS D'ORDRES                  **/
            /******************************************************/

            case "do" :
            ?>
                <!-- Liste des catégories -->
                <table width="100%" border="0">
                    <tr>
                        <td class="rubfrm" id="f_pays" align="right"><?PHP echo _("Pays"); ?></td>
                        <td>
                            <?PHP
                            // Création de la liste des pays
                            $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
                            $rech = "SELECT * FROM `" . TBPAYS . "` ORDER BY pays_nom";
                            $rows = $db->get_results($rech, ARRAY_A);
                            $db->disconnect();
                            cre_select_tab('pays', 'pays', $rows, 'pays_code', 'pays_nom', '', $pays, '', _("-- Faites votre choix --"), 1, FALSE, '-1', _("-- Inconnu --"));
                            ?>
                        </td>
                    </tr>
                    <tr>
                        <td class="rubfrm" id="f_dep" align="right"><?PHP echo _("Département"); ?></td>
                        <td>
                            <?PHP
                            $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
                            $rech = "SELECT * FROM `" . TBDEP . "` WHERE dep_codepays='" . str_majuscules($pays) . "' ORDER BY dep_code";
                            $rows = $db->get_results($rech, ARRAY_A);
                            $db->disconnect();
                            cre_select_tab('dep[]', 'dep', $rows, 'dep_code', 'dep_code', 'dep_nom', $tab_dep, '', _("-- Faites votre choix --"), 5, TRUE);
                            ?>
                            <input name="deptxt" type="hidden" id="deptxt" value="<?PHP echo $dep ?>" size="50"
                                   readonly>
                        </td>
                    </tr>
                </table>
                <?PHP
                break;

                /******************************************************/
                /**                    CLIENTS                       **/
                /******************************************************/

                case "cli" :
                ?>
                <!-- Liste des catégories -->
                <table width="100%" border="0">
                    <tr>
                        <td width="160" class="rubfrm" id="f_cat"
                            align="right"><?PHP echo _("Catégorie"); ?></td>
                        <td>
                            <?PHP
                            $tab_first_options = [
                                "*" => _("-- Toutes les catégories --")
                            ];
                            // création de la liste des catégories
                            $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
                            $rech = "SELECT * FROM `" . TBCCAT . "` ORDER BY cat_desc";
                            $rows = $db->get_results($rech, ARRAY_A);
                            $db->disconnect();
                            cre_select_tab('cat', 'act', $rows, 'cat_code', 'cat_desc', '', $cat, '', _("-- Faites votre choix --"), 1, FALSE, '', '', TRUE, TRUE, FALSE, $tab_first_options);
                            ?>
                        </td>
                    </tr>
                    <tr>
                        <td class="rubfrm" id="f_pays" align="right"><?PHP echo _("Pays"); ?></td>
                        <td>
                            <?PHP
                            switch (@$_SESSION["niv_log"]) {
                                case 4 :
                                case 6 :
                                    echo '<input name="pays" type="hidden" id="pays" value="' . $pays . '">';
                                    echo '<input name="npays" type="text" id="npays" value="' . Retournepays($pays, TRUE) . '" size="50" maxlength="50" readonly>';
                                    break;
                                default :
                                    // Création de la liste des pays
                                    $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
                                    $rech = "SELECT * FROM `" . TBPAYS . "` ORDER BY pays_nom";
                                    $rows = $db->get_results($rech, ARRAY_A);
                                    $db->disconnect();
                                    cre_select_tab('pays', 'pays', $rows, 'pays_code', 'pays_nom', '', $pays, '', _("-- Faites votre choix --"), 1, FALSE, '-1', _("-- Inconnu --"));
                                    break;
                            }
                            ?>
                        </td>
                    </tr>
                    <tr>
                        <td width="160" class="rubfrm" id="f_age" align="right"><?PHP echo _("Agence"); ?></td>
                        <td>
                            <?PHP
                            switch (@$_SESSION["niv_log"]) {
                                case 4 :
                                    $row = lit_enr_age($_SESSION["code_age"], TRUE);
                                    $row = encode_str($row);
                                    extract($row);
                                    echo '<input name="age" type="hidden" id="age" value="' . $_SESSION["code_age"] . '">';
                                    echo '<input name="nagence" type="text" id="nagence" value="' . $age_nom . '" size="50" maxlength="50" readonly>';
                                    break;

                                case 6 :
                                    $row = lit_enr_do($_SESSION["code_log"]);
                                    $row = encode_str($row);
                                    extract($row);
                                    echo '<input name="age" type="hidden" id="age" value="' . $_SESSION["code_do"] . '">';
                                    echo '<input name="nagence" type="text" id="nagence" value="' . $do_nom . '" size="50" maxlength="50" readonly>';
                                    break;
                                default :
                                    $rows = [];
                                    // création de la liste des agences
                                    if ($pays <> "") {
                                        $tab_first_options = [
                                            "*" => _("-- TOUTES LES AGENCES --")
                                        ];
                                        $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
                                        $rech = "SELECT * FROM `" . TBAGE . "` WHERE `age_ouvert` = '1' AND `age_codepays` = '" . str_majuscules($pays) . "' ORDER BY age_nom";
                                        $rows = $db->get_results($rech, ARRAY_A);
                                        $db->disconnect();
                                    }
                                    cre_select_tab('age', 'age', $rows, 'age_code', 'age_nom', 'age_code', $age, '', _("-- Faites votre choix --"), 1, FALSE, '', '', TRUE, TRUE, FALSE, $tab_first_options);
                                    break;
                            }
                            ?>
                        </td>
                    </tr>
                    <tr>
                        <td class="rubfrm" id="f_dep" align="right"><?PHP echo _("Département"); ?></td>
                        <td>
                            <?PHP
                            $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
                            switch (@$_SESSION["niv_log"]) {
                                case 4 :
                                    $rech = "SELECT * FROM `" . TBZCC . "`, `" . TBDEP . "`";
                                    $rech .= " WHERE " . TBZCC . ".zcc_codepays='" . str_majuscules($pays) . "' AND " . TBZCC . ".zcc_code='" . $age . "'";
                                    $rech .= " AND " . TBZCC . ".zcc_codedep=" . TBDEP . ".dep_code ORDER BY " . TBDEP . ".dep_code";
                                    break;
                                default :
                                    $rech = "SELECT * FROM `" . TBDEP . "` WHERE dep_codepays='" . str_majuscules($pays) . "' ORDER BY dep_code";
                                    break;
                            }
                            $rows = $db->get_results($rech, ARRAY_A);
                            $db->disconnect();
                            cre_select_tab('dep[]', 'dep', $rows, 'dep_code', 'dep_code', 'dep_nom', $tab_dep, '', _("-- Faites votre choix --"), 5, TRUE);
                            ?>
                            <input name="deptxt" type="hidden" id="deptxt" value="<?PHP echo $dep ?>" size="50"
                                   readonly>
                        </td>
                    </tr>
                </table>
                <?PHP
                break;

            /******************************************************/
            /**                  OPERATEURS                      **/
            /******************************************************/

            case "ope" :
            ?>
                <table width="100%" border="0">
                    <tr>
                        <td class="rubfrm" id="f_pays" align="right"><?PHP echo _("Pays"); ?></td>
                        <td>
                            <?PHP
                            // Création de la liste des pays
                            $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
                            $rech = "SELECT * FROM `" . TBPAYS . "` ORDER BY pays_nom";
                            $rows = $db->get_results($rech, ARRAY_A);
                            $db->disconnect();
                            cre_select_tab('pays', 'pays', $rows, 'pays_code', 'pays_nom', '', $pays, '', _("-- Faites votre choix --"), 1, FALSE, '-1', _("-- Inconnu --"));
                            ?>
                        </td>
                    </tr>
                    <tr>
                        <td class="rubfrm" id="f_dep" align="right"><?PHP echo _("Département"); ?></td>
                        <td>
                            <?PHP
                            $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
                            $rech = "SELECT * FROM `" . TBDEP . "` WHERE dep_codepays='" . str_majuscules($pays) . "' ORDER BY dep_code";
                            $rows = $db->get_results($rech, ARRAY_A);
                            $db->disconnect();
                            cre_select_tab('dep[]', 'dep', $rows, 'dep_code', 'dep_code', 'dep_nom', $tab_dep, '', _("-- Faites votre choix --"), 5, TRUE);
                            ?>
                            <input name="deptxt" type="hidden" id="deptxt" value="<?PHP echo $dep ?>" size="50" readonly>
                        </td>
                    </tr>
                </table>
                <?PHP
                break;

            /******************************************************/
            /**                  TECHNICIENS                     **/
            /******************************************************/

            case "tec" :
            case "tecd" :
            case "tecs" :
            ?>
                <table width="100%" border="0">
                    <tr>
                        <td width="160" class="rubfrm" id="f_age" align="right">
                            <?PHP
                            switch ($td) {
                                case "tecs" :
                                    echo _("Sous-traitant");
                                    $tous = _("TOUS LES SOUS-TRAITANTS");
                                    break;
                                case "tecd" :
                                    echo _("Donneur d'ordre");
                                    $tous = _("TOUS LES DONNEURS D'ORDRES");
                                    break;
                                default :
                                    echo _("Agence");
                                    $tous = _("TOUTES LES AGENCES");
                                    break;
                            }
                            ?>
                        </td>
                        <td>
                            <?PHP
                            $tab_values = [
                                "*" => "-- " . $tous . " --"
                            ];
                            // création de la liste des agences/donneurs d'ordres/sOus-traitants
                            $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
                            switch ($td) {
                                case "tec" :
                                    $rech = "SELECT * FROM `" . TBAGE . "` WHERE `age_ouvert` = '1' ORDER BY age_nom";
                                    break;
                                case "tecd" :
                                    $rech = "SELECT * FROM `" . TBDO . "` WHERE `do_ouvert` = '1' ORDER BY do_nom";
                                    break;
                                case "tecs" :
                                    $rech = "SELECT * FROM `" . TBST . "` WHERE `st_ouvert` = '1' ORDER BY st_nom";
                                    break;
                            }
                            $rows = $db->get_results($rech, ARRAY_A);

                            foreach ($rows as $row) {
                                $row = encode_str($row);
                                extract($row);
                                switch ($td) {
                                    case "tec" :
                                        $code = $age_code;
                                        $nom = $age_nom;
                                        break;
                                    case "tecd" :
                                        $code = $do_code;
                                        $nom = $do_nom;
                                        break;
                                    case "tecs" :
                                        $code = $st_code;
                                        $nom = $st_nom;
                                        break;
                                }

                                $tab_values[$code] = $nom;
                            }
                            $db->disconnect();
                            cre_select('age', 'age', $tab_values, $age, '', _("-- Faites votre choix --"));
                            ?>
                            <div class="annot_petit_it">(<?PHP echo _("Ne s'afficheront que les techniciens salariés"); ?>)</div>
                             <img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo _("Champ obligatoire"); ?>">
                        </td>
                    </tr>
                    <tr>
                        <td class="rubfrm" id="f_pays" align="right"><?PHP echo _("Pays"); ?></td>
                        <td>
                            <?PHP
                            // Création de la liste des pays
                            $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
                            $rech = "SELECT * FROM `" . TBPAYS . "` ORDER BY pays_nom";
                            $rows = $db->get_results($rech, ARRAY_A);
                            $db->disconnect();
                            cre_select_tab('pays', 'pays', $rows, 'pays_code', 'pays_nom', '', $pays, '', _("-- Faites votre choix --"), 1, FALSE, '-1', _("-- Inconnu --"));
                            ?>
                        </td>
                    </tr>
                    <tr>
                        <td class="rubfrm" id="f_dep" align="right"><?PHP echo _("Département"); ?></td>
                        <td>
                            <?PHP
                            $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
                            $rech = "SELECT * FROM `" . TBDEP . "` WHERE dep_codepays='" . str_majuscules($pays) . "' ORDER BY dep_code";
                            $rows = $db->get_results($rech, ARRAY_A);
                            $db->disconnect();
                            cre_select_tab('dep[]', 'dep', $rows, 'dep_code', 'dep_code', 'dep_nom', $tab_dep, '', _("-- Faites votre choix --"), 5, TRUE);
                            ?>
                            <input name="deptxt" type="hidden" id="deptxt" value="<?PHP echo $dep ?>" size="50" readonly>
                        </td>
                    </tr>
                </table>
                <?PHP
                break;
            }
        }
        else
        {
            switch ($td) {
                /******************************************************/
                /**                    AGENCES                       **/
                /******************************************************/
                case "age" :
                ?>
                <input name="cat" type="hidden" id="cat" value="<?PHP echo $cat; ?>">
                <input name="pays" type="hidden" id="pays" value="<?PHP echo $pays; ?>">
                <input name="deptxt" type="hidden" id="deptxt" value="<?PHP echo $dep; ?>">
                <input name="zonetxt" type="hidden" id="deptxt" value="<?PHP echo $zone; ?>">
                <input name="sujet" type="hidden" id="sujet" value="<?PHP echo $sujet; ?>">
                <input name="cv" type="hidden" id="cv" value="<?PHP echo $cv; ?>">

                <p align="center"
                   class="titre_gras_soul"><?PHP echo _("Listes des agences sélectionnées"); ?></p>
                <?PHP
                // *** Affichage de la table
                $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
                $rech = "SELECT * FROM `" . TBAGE . "`";
                if ($cv == "N")
                    $rech .= ", " . TBPW;
                if ($cat <> "*")
                    $rech .= " WHERE " . TBAGE . ".age_cat = '" . $cat . "' AND " . TBAGE . ".age_ouvert = '1'";
                else
                    $rech .= " WHERE " . TBAGE . ".age_ouvert = '1'";
                if ($dep <> "") {
                    $tab_dep = explode("_", $dep);

                    $rech .= " AND (";

                    foreach ($tab_dep as $idx => $value) {
                        $rech .= TBAGE . ".age_dep ='" . $db->escape($value) . "' OR ";
                    }
                    $rech = substr($rech, 0, strlen($rech) - 4);
                    $rech .= ")";
                }
                if ($cv == "N") {
                    $rech .= " AND " . TBAGE . ".age_code=" . TBPW . ".pw_code";
                    $rech .= " AND " . TBPW . ".pw_actif='1'";
                }
                $rows = $db->get_results($rech, ARRAY_A);
                if ($rows) {
                    $nbsel = count($rows);
                    ?>
                    <table width="100%" border="0">
                        <tr>
                            <td class="annot_std_gras" id="f_dest" valign="bottom"
                                align="right"><?PHP echo _("Services destinataires"); ?> :
                            </td>
                            <td>
                                <?PHP
                                foreach ($typmail_client as $key => $value) {
                                    echo $value . ' : ';
                                    echo '<input type="checkbox" name="type_dest[]" style="background : #FFFFFF;"';
                                    switch ($key) {
                                        case "dir" :
                                            /*
                                            if (verif_choix_dest("2"))
                                                echo ' checked="checked"';
                                            */
                                            echo ' value ="2"';
                                            break;
                                        case "cpta" :
                                            /*
                                            if (verif_choix_dest("3"))
                                                echo ' checked="checked"';
                                            */
                                            echo ' value ="3"';
                                            break;
                                        case "tec" :
                                            /*
                                            if (verif_choix_dest("4"))
                                                echo ' checked="checked"';
                                            */
                                            echo ' value ="4"';
                                            break;
                                    }
                                    echo '>';
                                }
                                echo ' <img src="../img/oblig.png" align="absmiddle" alt="' . _("Champ obligatoire") . '">';
                                ?>
                            </td>
                        </tr>
                    </table>
                    <?PHP
                    echo '<p align="center">';
                    echo "<input type=\"button\" name=\"sel\" id=\"sel\" value=\""._("Tous")."\" class=\"bton_fgris_petit\">";
                    echo "</p>";

                    echo "<div id=\"Layer1\" class=\"lst_fen\">";

                    // Définition et entête de la table
                    echo "<table class=\"Mtable\" border=\"0\" width=\"100%\" cellpadding=\"0\" cellspacing=\"0\">\n";

                    echo "<th>";
                    echo _("Code");
                    echo "</th>\n";
                    echo "<th>";
                    echo _("Nom");
                    echo "</th>\n";
                    echo "<th>";
                    echo _("Téléphone");
                    echo "</th>\n";
                    echo "<th>";
                    echo _("CP");
                    echo "</th>\n";
                    echo "<th>";
                    echo _("Choisir");
                    echo "</th>\n";

                    $i = 0;
                    $tab_zone = explode("_", $zone);

                    foreach ($rows as $row) {
                        $row = encode_str($row);
                        if ($zone <> "") {
                            $aff_ligne = FALSE; // On part du principe que l'agence n'est pas dans la zone recherchée
                            foreach ($tab_zone as $idx => $value) {
                                if (dep_in_zcc_age_open($value, $row["age_codepays"], $row["age_code"], FALSE) == TRUE)
                                    $aff_ligne = TRUE; // On a trouvé une correspondance, on valide l'affichage
                            }
                        } else
                            $aff_ligne = TRUE;

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

                            echo "<td>" . $row["age_code"];
                            echo "</td>\n";
                            echo "<td>" . $row["age_nom"] . "</td>\n";
                            echo "<td>" . $row["age_telf"] . "</td>\n";
                            echo "<td>" . Retournecp_Id($row["age_ville"], FALSE) . "</td>\n";
                            echo "<td align=\"center\">\n";
                            echo "<input type=\"checkbox\" name=\"age_choisie[]\"";
                            /*
                            if (verif_choix_age($row["age_id"]))
                                echo "checked ";
                            */
                            if ($i % 2 == 0)
                                echo " style=\"background : #32CD32;\"";
                            else
                                echo " style=\"background : #00FF00;\"";
                            echo "value=\"" . $row["age_id"] . "\">";
                            echo "</td>\n";
                            echo "</tr>\n";

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

                    echo "</div>";
                } else
                    echo _("Aucune agence sur ces critères");
                $db->disconnect();
                break;

                /******************************************************/
                /**                SOUS-TRAITANTS                    **/
                /******************************************************/

            case "st" :
            ?>
                <input name="cat" type="hidden" id="cat" value="<?PHP echo $cat; ?>">
                <input name="pays" type="hidden" id="pays" value="<?PHP echo $pays; ?>">
                <input name="deptxt" type="hidden" id="deptxt" value="<?PHP echo $dep; ?>">
                <input name="zonetxt" type="hidden" id="deptxt" value="<?PHP echo $zone; ?>">
                <input name="sujet" type="hidden" id="sujet" value="<?PHP echo $sujet; ?>">
                <input name="cv" type="hidden" id="cv" value="<?PHP echo $cv; ?>">

                <p align="center"
                   class="titre_gras_soul"><?PHP echo _("Listes des sous-traitants sélectionnés"); ?></p>
                <?PHP
                // *** Affichage de la table
                $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
                $rech = "SELECT * FROM `" . TBST . "`";
                if ($cv == "N")
                    $rech .= ", " . TBPW;
                if ($cat <> "*")
                    $rech .= " WHERE " . TBST . ".st_spe = '" . $cat . "' AND " . TBST . ".st_ouvert = '1'";
                else
                    $rech .= " WHERE " . TBST . ".st_ouvert = '1'";
                if ($dep <> "") {
                    $tab_dep = explode("_", $dep);

                    $rech .= " AND (";

                    foreach ($tab_dep as $idx => $value) {
                        $rech .= TBST . ".st_dep ='" . $db->escape($value) . "' OR ";
                    }
                    $rech = substr($rech, 0, strlen($rech) - 4);
                    $rech .= ")";
                }
                if ($cv == "N") {
                    $rech .= " AND " . TBST . ".st_code=" . TBPW . ".pw_code";
                    $rech .= " AND " . TBPW . ".pw_actif='1'";
                }
                $rows = $db->get_results($rech, ARRAY_A);
                if ($rows) {
                    $nbsel = count($rows);
                    ?>
                    <table width="100%" border="0">
                        <tr>
                            <td class="annot_std_gras" id="f_dest" valign="bottom"
                                align="right"><?PHP echo _("Services destinataires"); ?> :
                            </td>
                            <td>
                                <?PHP
                                foreach ($typmail_client as $key => $value) {
                                    echo $value . ' : ';
                                    echo '<input type="checkbox" name="type_dest[]" style="background : #FFFFFF;"';
                                    switch ($key) {
                                        case "dir" :
                                            /*
                                            if (verif_choix_dest("2"))
                                                echo ' checked="checked"';
                                            */
                                            echo ' value ="2"';
                                            break;
                                        case "cpta" :
                                            /*
                                            if (verif_choix_dest("3"))
                                                echo ' checked="checked"';
                                            */
                                            echo ' value ="3"';
                                            break;
                                        case "tec" :
                                            /*
                                            if (verif_choix_dest("4"))
                                                echo ' checked="checked"';
                                            */
                                            echo ' value ="4"';
                                            break;
                                    }
                                    echo '>';
                                }
                                echo ' <img src="../img/oblig.png" align="absmiddle" alt="' . _("Champ obligatoire") . '">';
                                ?>
                            </td>
                        </tr>
                    </table>
                    <?PHP
                    echo "<p align=\"center\">";
                    echo "<input type=\"button\" name=\"sel\" id=\"sel\" value=\""._("Tous")."\" class=\"bton_fgris_petit\">";
                    echo "</p>";

                    echo "<div id=\"Layer1\" class=\"lst_fen\">";

                    // Définition et entête de la table
                    echo "<table class=\"Mtable\" border=\"0\" width=\"100%\" cellpadding=\"0\" cellspacing=\"0\">\n";

                    echo "<th>";
                    echo _("Code");
                    echo "</th>\n";
                    echo "<th>";
                    echo _("Nom");
                    echo "</th>\n";
                    echo "<th>";
                    echo _("Téléphone");
                    echo "</th>\n";
                    echo "<th>";
                    echo _("CP");
                    echo "</th>\n";
                    echo "<th>";
                    echo _("Zone Chalandise");
                    echo "</th>\n";
                    echo "<th>";
                    echo _("Choisir");
                    echo "</th>\n";

                    $i = 0;
                    $tab_zone = explode("_", $zone);

                    foreach ($rows as $row) {
                        $row = encode_str($row);
                        if ($zone <> "") {
                            $aff_ligne = FALSE; // On part du principe que l'agence n'est pas dans la zone recherchée
                            foreach ($tab_zone as $idx => $value) {
                                if (dep_in_zoc_st_open($value, $row["st_codepays"], $row["st_code"], FALSE) == TRUE)
                                    $aff_ligne = TRUE; // On a trouvé une correspondance, on valide l'affichage
                            }
                        } else
                            $aff_ligne = TRUE;

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

                            echo "<td>" . $row["st_code"];
                            echo "</td>\n";
                            echo "<td>" . $row["st_nom"] . "</td>\n";
                            echo "<td>" . $row["st_telf"] . "</td>\n";
                            echo "<td>" . Retournecp_Id($row["st_ville"], FALSE) . "</td>\n";
                            echo "<td>";
                            $tab_zoneopen = tab_zoc_st_open($row["st_code"], FALSE);
                            foreach ($tab_zoneopen as $idx => $value) {
                                $rech2 = "SELECT * FROM `" . TBDEP . "` WHERE dep_code = '$value' AND dep_codepays = '" . $row["st_codepays"] . "'";
                                $row2 = $db->get_row($rech2, ARRAy_A);
                                if ($row2) {
                                    $row2 = encode_str($row2);
                                    extract($row2);
                                    if ($idx > 0) echo "<br />";
                                    echo $dep_code . " (" . $dep_nom . ")";
                                }
                            }
                            echo "</td>\n";
                            echo "<td align=\"center\">\n";
                            echo "<input type=\"checkbox\" name=\"st_choisi[]\"";
                            /*
                            if (verif_choix_st($row["st_id"]))
                                echo "checked ";
                            */
                            if ($i % 2 == 0)
                                echo " style=\"background : #32CD32;\"";
                            else
                                echo " style=\"background : #00FF00;\"";
                            echo "value=\"" . $row["st_id"] . "\">";
                            echo "</td>\n";
                            echo "</tr>\n";

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

                    echo "</div>";
                } else
                    echo _("Aucun sous-traitant  sur ces critères.");
                $db->disconnect();
                break;

            /******************************************************/
            /**               DONNEURS D'ORDRES                  **/
            /******************************************************/

            case "do" :
            ?>
                <input name="td" type="hidden" id="td" value="<?PHP echo $td ?>">
                <input name="pays" type="hidden" id="pays" value="<?PHP echo $pays; ?>">
                <input name="deptxt" type="hidden" id="deptxt" value="<?PHP echo $dep; ?>">
                <input name="sujet" type="hidden" id="sujet" value="<?PHP echo $sujet; ?>">
                <input name="cv" type="hidden" id="cv" value="<?PHP echo $cv; ?>">

                <p align="center" class="titre_gras_soul"><?PHP echo _("Listes des donneurs d'ordres sélectionnés"); ?></p>
                <?PHP
                // *** Affichage de la table
                $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
                $rech = "SELECT * FROM `" . TBDO . "`";
                if ($cv == "N")
                    $rech .= ", " . TBPW;
                $rech .= " WHERE " . TBDO . ".do_ouvert = '1'";
                if ($dep <> "") {
                    $tab_dep = explode("_", $dep);

                    $rech .= " AND (";

                    foreach ($tab_dep as $idx => $value) {
                        $rech .= TBDO . ".do_dep ='" . $db->escape($value) . "' OR ";
                    }
                    $rech = substr($rech, 0, strlen($rech) - 4);
                    $rech .= ")";
                }
                if ($cv == "N") {
                    $rech .= " AND " . TBDO . ".do_code=" . TBPW . ".pw_code";
                    $rech .= " AND " . TBPW . ".pw_actif='1'";
                }
                $rows = $db->get_results($rech, ARRAY_A);
                if ($rows) {
                    $nbsel = count($rows);
                    ?>
                    <table width="100%" border="0">
                        <tr>
                            <td class="annot_std_gras" id="f_dest" valign="bottom"
                                align="right"><?PHP echo _("Services destinataires"); ?> :
                            </td>
                            <td>
                                <?PHP
                                foreach ($typmail_client as $key => $value) {
                                    echo $value . ' : ';
                                    echo '<input type="checkbox" name="type_dest[]" style="background : #FFFFFF;"';
                                    switch ($key) {
                                        case "dir" :
                                            /*
                                            if (verif_choix_dest("2"))
                                                echo ' checked="checked"';
                                            */
                                            echo ' value ="2"';
                                            break;
                                        case "cpta" :
                                            /*
                                            if (verif_choix_dest("3"))
                                                echo ' checked="checked"';
                                            */
                                            echo ' value ="3"';
                                            break;
                                        case "tec" :
                                            /*
                                            if (verif_choix_dest("4"))
                                                echo ' checked="checked"';
                                            */
                                            echo ' value ="4"';
                                            break;
                                    }
                                    echo '>';
                                }
                                echo ' <img src="../img/oblig.png" align="absmiddle" alt="' . _("Champ obligatoire") . '">';
                                ?>
                            </td>
                        </tr>
                    </table>
                    <?PHP
                    echo "<p align=\"center\">";
                    echo "<input type=\"button\" name=\"sel\" id=\"sel\" value=\"".("Tous")."\" class=\"bton_fgris_petit\">";
                    echo "</p>";

                    echo "<div id=\"Layer1\" class=\"lst_fen\">";

                    // Définition et entête de la table
                    echo "<table class=\"Mtable\" border=\"0\" width=\"100%\" cellpadding=\"0\" cellspacing=\"0\">\n";

                    echo "<th>";
                    echo _("Code");
                    echo "</th>\n";
                    echo "<th>";
                    echo _("Nom");
                    echo "</th>\n";
                    echo "<th>";
                    echo _("Téléphone");
                    echo "</th>\n";
                    echo "<th>";
                    echo _("CP");
                    echo "</th>\n";
                    echo "<th>";
                    echo _("Choisir");
                    echo "</th>\n";

                    $i = 0;

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

                        echo "<td>" . $row["do_code"];
                        echo "</td>\n";
                        echo "<td>" . $row["do_nom"] . "</td>\n";
                        echo "<td>" . $row["do_telf"] . "</td>\n";
                        echo "<td>" . Retournecp_Id($row["do_ville"], FALSE) . "</td>\n";
                        echo "<td align=\"center\">\n";
                        echo "<input type=\"checkbox\" name=\"do_choisi[]\"";
                        /*
                        if (verif_choix_do($row["do_id"]))
                            echo "checked ";
                        */
                        if ($i % 2 == 0)
                            echo " style=\"background : #32CD32;\"";
                        else
                            echo " style=\"background : #00FF00;\"";
                        echo "value=\"" . $row["do_id"] . "\">";
                        echo "</td>\n";
                        echo "</tr>\n";

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

                    echo "</div>";
                } else
                    echo _("Aucun donneur d'ordres sur ces critères");
                $db->disconnect();
                break;

            /******************************************************/
            /**                    CLIENTS                       **/
            /******************************************************/

            case "cli" :
            ?>
                <input name="cat" type="hidden" id="cat" value="<?PHP echo $cat; ?>">
                <input name="age" type="hidden" id="age" value="<?PHP echo $age; ?>">
                <input name="pays" type="hidden" id="pays" value="<?PHP echo $pays; ?>">
                <input name="deptxt" type="hidden" id="deptxt" value="<?PHP echo $dep; ?>">
                <input name="sujet" type="hidden" id="sujet" value="<?PHP echo $sujet; ?>">
                <input name="cv" type="hidden" id="cv" value="<?PHP echo $cv; ?>">

                <p align="center" class="titre_gras_soul"><?PHP echo _("Listes des clients sélectionnés"); ?></p>
                <?PHP
                // *** Affichage de la table

                // Si agence choisie, on récupère les infos de cette agence
                if ($age <> "*") {
                    $row2 = lit_enr_age($age, TRUE);
                    if (is_array($row2)) {
                        $row2 = encode_str($row2);
                        extract($row2);
                    }
                }

                $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
                $rech = "SELECT * FROM `" . TBCLI . "`";
                if ($cv == "N")
                    $rech .= ", " . TBPW;
                if ($cat <> "*")
                    $rech .= " WHERE " . TBCLI . ".cli_cat = '" . $cat . "'";
                if ($age <> "*") {
                    switch (@$_SESSION["niv_log"]) {
                        case 6 :
                            if (!stristr($rech, "WHERE "))
                                $rech .= " WHERE " . TBCLI . ".cli_codedo = '" . $age . "'";
                            else
                                $rech .= " AND " . TBCLI . ".cli_codedo = '" . $age . "'";
                            break;
                        default :
                            if (!stristr($rech, "WHERE "))
                                $rech .= " WHERE (" . TBCLI . ".cli_prop = '" . $age . "' OR " . TBCLI . ".cli_prop IS NULL)";
                            else
                                $rech .= " AND (" . TBCLI . ".cli_prop = '" . $age . "' OR " . TBCLI . ".cli_prop IS NULL)";
                            break;
                    }
                }
                if ($dep <> "") {
                    $tab_dep = explode("_", $dep);

                    // WHERE existe ?
                    if (!stristr($rech, "WHERE "))
                        $rech .= " WHERE (";
                    else
                        $rech .= " AND (";

                    foreach ($tab_dep as $idx => $value) {
                        $rech .= TBCLI . ".cli_dep ='" . $db->escape($value) . "' OR ";
                    }
                    $rech = substr($rech, 0, strlen($rech) - 4);
                    $rech .= ")";
                }
                if ($cv == "N") {
                    if (!stristr($rech, "WHERE "))
                        $rech .= " WHERE ";
                    else
                        $rech .= " AND ";
                    $rech .= TBCLI . ".cli_code=" . TBPW . ".pw_code";
                    $rech .= " AND " . TBPW . ".pw_actif='1'";
                }
                $rech .= " ORDER BY " . TBCLI . ".cli_code";
                $rows = $db->get_results($rech, ARRAY_A);
                if ($rows) {
                    $nbsel = count($rows);
                    ?>
                    <table width="100%" border="0">
                        <tr>
                            <td class="annot_std_gras" id="f_dest" valign="bottom"
                                align="right"><?PHP echo _("Services destinataires"); ?> :
                            </td>
                            <td>
                                <?PHP
                                foreach ($typmail_client as $key => $value) {
                                    echo $value . ' : ';
                                    echo '<input type="checkbox" name="type_dest[]" style="background : #FFFFFF;"';
                                    switch ($key) {
                                        case "dir" :
                                            /*
                                            if (verif_choix_dest("2"))
                                                echo ' checked="checked"';
                                            */
                                            echo ' value ="2"';
                                            break;
                                        case "cpta" :
                                            /*
                                            if (verif_choix_dest("3"))
                                                echo ' checked="checked"';
                                                */
                                            echo ' value ="3"';
                                            break;
                                        case "tec" :
                                            /*
                                            if (verif_choix_dest("4"))
                                                echo ' checked="checked"';
                                            */
                                            echo ' value ="4"';
                                            break;
                                    }
                                    echo '>';
                                }
                                echo ' <img src="../img/oblig.png" align="absmiddle" alt="' . _("Champ obligatoire") . '">';
                                ?>
                            </td>
                        </tr>
                    </table>
                    <?PHP
                    echo "<p align=\"center\">";
                    echo "<input type=\"button\" name=\"sel\" id=\"sel\" value=\""._("Tous")."\" class=\"bton_fgris_petit\">";
                    echo "</p>";

                    echo "<div id=\"Layer1\" class=\"lst_fen\">";

                    // Définition et entête de la table
                    echo "<table class=\"Mtable\" border=\"0\" width=\"100%\" cellpadding=\"0\" cellspacing=\"0\">\n";

                    echo "<th>";
                    echo _("Code");
                    echo "</th>\n";
                    echo "<th>";
                    echo _("Nom");
                    echo "</th>\n";
                    echo "<th>";
                    echo _("Téléphone");
                    echo "</th>\n";
                    echo "<th>";
                    echo _("CP");
                    echo "</th>\n";
                    echo "<th>";
                    echo _("Choisir");
                    echo "</th>\n";

                    $i = 0;

                    foreach ($rows as $row) {
                        $row = encode_str($row);
                        $aff_ligne = TRUE;

                        if (($age <> "*") AND (@$_SESSION["niv_log"] <> 6)) // Tests si une agence a été choisie (uniquement si pas en mode donneur d'ordres)
                        {
                            // Vérifie que le Département du client est dans la zone de chalandise de l'agence
                            if (dep_in_zcc_age_open($row["cli_dep"], $row["cli_codepays"], $age, FALSE) == FALSE) {
                                // Si pas dans la zone de chalandise, on affiche pas
                                $aff_ligne = FALSE;
                            }
                        }

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

                            echo "<td>" . $row["cli_code"];
                            echo "</td>\n";
                            echo "<td>";
                            if ($row["cli_ste"] <> "")
                                $txt_cli = $row["cli_ste"] . ", " . $row["cli_civilite"] . " " . $row["cli_nom"] . " " . $row["cli_prenom"];
                            else
                                $txt_cli = $row["cli_civilite"] . " " . $row["cli_nom"] . " " . $row["cli_prenom"];
                            echo $txt_cli;
                            echo "</td>\n";
                            echo "<td>" . $row["cli_telf"] . "</td>\n";
                            echo "<td>" . Retournecp_Id($row["cli_ville"], FALSE) . "</td>\n";
                            echo "<td align=\"center\">\n";
                            echo "<input type=\"checkbox\" name=\"cli_choisi[]\"";
                            /*
                            if (verif_choix_cli($row["cli_id"]))
                                echo "checked ";
                            */
                            if ($i % 2 == 0)
                                echo " style=\"background : #32CD32;\"";
                            else
                                echo " style=\"background : #00FF00;\"";
                            echo "value=\"" . $row["cli_id"] . "\">";
                            echo "</td>\n";
                            echo "</tr>\n";

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

                    echo "</div>";
                } else
                    echo _("Aucun client sur ces critères");
                $db->disconnect();
                break;

            /******************************************************/
            /**                  OPERATEURS                      **/
            /******************************************************/

            case "ope" :
            ?>
                <input name="pays" type="hidden" id="pays" value="<?PHP echo $pays; ?>">
                <input name="deptxt" type="hidden" id="deptxt" value="<?PHP echo $dep; ?>">
                <input name="sujet" type="hidden" id="sujet" value="<?PHP echo $sujet; ?>">

                <p align="center"
                   class="titre_gras_soul"><?PHP echo _("Listes des opérateurs sélectionnés"); ?></p>
                <?PHP
                // *** Affichage de la table
                $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
                $rech = "SELECT * FROM `" . TBOPE . "`";
                if ($cv == "N")
                    $rech .= ", " . TBPW;
                if ($dep <> "") {
                    $tab_dep = explode("_", $dep);

                    // WHERE existe ?
                    if (!stristr($rech, "WHERE "))
                        $rech .= " WHERE (";
                    else
                        $rech .= " AND (";

                    foreach ($tab_dep as $idx => $value) {
                        $rech .= TBOPE . ".ope_dep ='" . $db->escape($value) . "' OR ";
                    }
                    $rech = substr($rech, 0, strlen($rech) - 4);
                    $rech .= ")";
                }
                if ($cv == "N") {
                    if (!stristr($rech, "WHERE "))
                        $rech .= " WHERE ";
                    else
                        $rech .= " AND ";
                    $rech .= TBOPE . ".ope_code=" . TBPW . ".pw_code";
                    $rech .= " AND " . TBPW . ".pw_actif='1'";
                }
                $rech .= " ORDER BY " . TBOPE . ".ope_code";
                $rows = $db->get_results($rech, ARRAY_A);
                if ($rows) {
                    $nbsel = count($rows);
                    echo "<p align=\"center\">";
                    echo "<input type=\"button\" name=\"sel\" id=\"sel\" value=\""._("Tous")."\" class=\"bton_fgris_petit\">";
                    echo "</p>";

                    echo "<div id=\"Layer1\" class=\"lst_fen\">";

                    // Définition et entête de la table
                    echo "<table class=\"Mtable\" border=\"0\" width=\"100%\" cellpadding=\"0\" cellspacing=\"0\">\n";

                    echo "<th>";
                    echo _("Code");
                    echo "</th>\n";
                    echo "<th>";
                    echo _("Nom");
                    echo "</th>\n";
                    echo "<th>";
                    echo _("Téléphone");
                    echo "</th>\n";
                    echo "<th>";
                    echo _("CP");
                    echo "</th>\n";
                    echo "<th>";
                    echo _("Choisir");
                    echo "</th>\n";

                    $i = 0;

                    foreach ($rows as $row) {
                        $row = encode_str($row);
                        if ($dep <> "") {
                            $dep_tab = explode("_", $dep);

                            if (exist_in_array($row["ope_dep"], $dep_tab))
                                $aff_ligne = TRUE;
                            else
                                $aff_ligne = FALSE;
                        } else
                            $aff_ligne = TRUE;

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

                            echo "<td>" . $row["ope_code"];
                            echo "</td>\n";
                            echo "<td>";
                            echo $row["ope_civilite"] . " " . $row["ope_nom"] . " " . $row["ope_prenom"];
                            echo "</td>\n";
                            echo "<td>" . $row["ope_telf"] . "</td>\n";
                            echo "<td>" . Retournecp_Id($row["ope_ville"], FALSE) . "</td>\n";
                            echo "<td align=\"center\">\n";
                            echo "<input type=\"checkbox\" name=\"ope_choisi[]\"";
                            /*
                            if (verif_choix_ope($row["ope_id"]))
                                echo "checked ";
                            */
                            if ($i % 2 == 0)
                                echo " style=\"background : #32CD32;\"";
                            else
                                echo " style=\"background : #00FF00;\"";
                            echo "value=\"" . $row["ope_id"] . "\">";
                            echo "</td>\n";
                            echo "</tr>\n";

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

                    echo "</div>";
                } else
                    echo _("Aucun Opérateur actif sur ce(s) Département(s)");
                $db->disconnect();
                break;

            /******************************************************/
            /**                  TECHNICIENS                     **/
            /******************************************************/

            case "tec" :
            case "tecd" :
            case "tecs" :
            ?>
                <input name="age" type="hidden" id="age" value="<?PHP echo $age; ?>">
                <input name="pays" type="hidden" id="pays" value="<?PHP echo $pays; ?>">
                <input name="deptxt" type="hidden" id="deptxt" value="<?PHP echo $dep; ?>">
                <input name="sujet" type="hidden" id="sujet" value="<?PHP echo $sujet; ?>">

                <p align="center" class="titre_gras_soul"><?PHP echo _("Listes des techniciens sélectionnés"); ?></p>
                <?PHP
                // *** Affichage de la table
                $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
                $rech = "SELECT * FROM `" . TBTEC . "`";
                if ($cv == "N")
                    $rech .= ", " . TBPW;
                if ($age <> "*") {
                    switch ($td) {
                        case "tec" :
                            $rech .= " WHERE tec_codeage = '" . $age . "'";
                            break;
                        case "tecd" :
                            $rech .= " WHERE tec_codedo = '" . $age . "'";
                            break;
                        case "tecs" :
                            $rech .= " WHERE tec_codest = '" . $age . "'";
                            break;
                    }
                } else {
                    switch ($td) {
                        case "tec" :
                            $rech .= " WHERE tec_codeage <> ''";
                            break;
                        case "tecd" :
                            $rech .= " WHERE tec_codedo <> ''";
                            break;
                        case "tecs" :
                            $rech .= " WHERE tec_codest <> ''";
                            break;
                    }
                }

                if ($dep <> "") {
                    $tab_dep = explode("_", $dep);

                    // WHERE existe ?
                    if (!stristr($rech, "WHERE "))
                        $rech .= " WHERE (";
                    else
                        $rech .= " AND (";

                    foreach ($tab_dep as $idx => $value) {
                        $rech .= TBTEC . ".tec_dep ='" . $db->escape($value) . "' OR ";
                    }
                    $rech = substr($rech, 0, strlen($rech) - 4);
                    $rech .= ")";
                }
                if ($cv == "N") {
                    if (!stristr($rech, "WHERE "))
                        $rech .= " WHERE ";
                    else
                        $rech .= " AND ";
                    $rech .= TBTEC . ".tec_code=" . TBPW . ".pw_code";
                    $rech .= " AND " . TBPW . ".pw_actif='1'";
                }
                $rech .= " ORDER BY " . TBTEC . ".tec_code";
                $rows = $db->get_results($rech, ARRAY_A);

                if ($rows) {
                    $nbsel = count($rows);
                    echo "<p align=\"center\">";
                    echo "<input type=\"button\" name=\"sel\" id=\"sel\" value=\"".("Tous")."\" class=\"bton_fgris_petit\">";
                    echo "</p>";

                    echo "<div id=\"Layer1\" class=\"lst_fen\">";

                    // Définition et entête de la table
                    echo "<table class=\"Mtable\" border=\"0\" width=\"100%\" cellpadding=\"0\" cellspacing=\"0\">\n";

                    echo "<th>";
                    echo _("Code");
                    echo "</th>\n";
                    echo "<th>";
                    echo _("Nom");
                    echo "</th>\n";
                    echo "<th>";
                    echo _("Téléphone");
                    echo "</th>\n";
                    echo "<th>";
                    echo _("CP");
                    echo "</th>\n";
                    echo "<th>";
                    echo _("Choisir");
                    echo "</th>\n";

                    $i = 0;

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

                        echo "<td>" . $row["tec_code"];
                        echo "</td>\n";
                        echo "<td>";
                        echo $row["tec_civilite"] . " " . $row["tec_nom"] . " " . $row["tec_prenom"];
                        if ((@$_SESSION["niv_log"] == 5) OR (@$_SESSION["niv_log"] == 9)) {
                            echo "<br />";
                            switch ($td) {
                                case "tec" :
                                    echo "(" . _("Agence") . " : " . $row["tec_codeage"] . ")";
                                    break;
                                case "tecd" :
                                    echo "(" . _("DO") . " : " . $row["tec_codedo"] . ")";
                                    break;
                                case "tecs" :
                                    echo "(" . _("ST") . " : " . $row["tec_codest"] . ")";
                                    break;
                            }
                        }
                        echo "</td>\n";
                        echo "<td>" . $row["tec_telf"] . "</td>\n";
                        echo "<td>" . Retournecp_Id($row["tec_ville"], FALSE) . "</td>\n";
                        echo "<td align=\"center\">\n";
                        echo "<input type=\"checkbox\" name=\"tec_choisi[]\"";
                        /*
                        if (verif_choix_tec($row["tec_id"]))
                            echo "checked ";
                        */
                        if ($i % 2 == 0)
                            echo " style=\"background : #32CD32;\"";
                        else
                            echo " style=\"background : #00FF00;\"";
                        echo "value=\"" . $row["tec_id"] . "\">";
                        echo "</td>\n";
                        echo "</tr>\n";

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

                    echo "</div>";
                } else
                    echo _("Aucun technicien actif pour ces paramètres");
                $db->disconnect();
                break;
            default :
                break;
            }
        }
        if ($validp == FALSE)
        {
            echo '<table width="100%" border="0">';
            echo '<tr>';
            echo '<td width="160" class="rubfrm" id="f_sujet" align="right">'._("Sujet du message").'</td>';
            echo '<td>';
            echo '<input name="sujet" type="text" id="sujet" size="50" maxlength="50" value="'.$sujet.'">';
            echo ' <img src="../img/oblig.png" align="absmiddle" alt="'._("Champ obligatoire").'">';
            echo '</td>';
            echo '</tr>';
            echo '<tr>';
            echo '<td width="160" class="rubfrm" id="f_sujet" align="right">'._("Inclus comptes verrouillés ?").'</td>';
            echo '<td>';
            echo '<input type="radio" name="cv" style="background : #FFFFFF;" value="O"> '._("Oui").' / ';
            echo '<input type="radio" name="cv" style="background : #FFFFFF;" value="N"> '._("Non");
            echo '</td>';
            echo '</tr>';
            echo '</table>';
        }
        else
        {
            echo '<table width="100%" border="0">';
            echo '<tr>';
            echo '<td align="center">';
            echo '<span class="titre_gras_soul">'._("Message à envoyer").'</span>';
            echo ' <img src="../img/oblig.png" align="absmiddle" alt="'._("Champ obligatoire").'">';
            echo '<div class="annot_std_it">('._("Sujet").' : '.$sujet.')</div>';
            echo '</td>';
            echo '</tr>';
            echo '<tr>';
            echo '<td>';
            echo '<textarea name="txtmail" id="txtmail" rows="10" cols="80">';
            echo $txt;
            echo '</textarea>';
            echo '</td>';
            echo '</tr>';
            echo '</table>';
        }
        echo '</form>';
        echo '<p align="center">';
        if ($validp == FALSE)
           echo '<input name="suiv" type="button" class="bton_std" id="suiv" value="'._("Suivant").'">';
        else
            if ($nbsel > 0)
                echo '<input name="exp" type="button" class="bton_std" id="exp" value="' . _("Expédier") . '">';
            echo '<input name="init" type="button" class="bton_std" id="init" value="'._("Recommencer").'">';
        echo '</p>';
    } else {
        if ($retourliste == TRUE)
            pop_ret_auto(_("Email correctement expédié"), 'ok', "email_maj.php?td=" . $td);
    }
} else
    pop_ret_auto(_("Problème de paramètres"), 'warn', "index.php");
include_once("pied.php");
?>
</body>
</html>