<?php
/****************************************************************************************
 * SMI (Services Maintenance Interventions) est une gestion libre de maintenance et de SAV
 *
 * Version 1.0.2
 *
 * Copyright (C) 2006-2015  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/func.inc.php");
include_once("../inc/func_geo.inc.php");
include_once("../inc/func_txt.inc.php");
include_once("../inc/fic_st.inc.php");
include_once("../inc/fic_dos.inc.php");
include_once("../inc/fic_droits.inc.php");
include_once("../inc/fic_hum.inc.php");
include_once("../inc/fic_int.inc.php");
include_once("../inc/lst.inc.php");
include_once("../classes/ezSQL/shared/ez_sql_core.php");
include_once("../classes/ezSQL/mysqli/ez_sql_mysqli.php");
include_once("../inc/func_sql.inc.php");
Archivelog(@$_SESSION["code_log"]);
// Variables Formulaire
fix_magic_quotes();
$_GET = clean_str($_GET);
$_POST = clean_str($_POST);

$td = '';
$codeage = '';
$idcst = 0;
$pbm_st = FALSE;
$totalcst = 0;
$action_to_do = '';
$retourliste = FALSE;

if (isset($_POST['nbutton']))
{
    if (trim(@$_POST["nbutton"]) == 'enr') // On a cliqué sur valider
        $action_to_do = 'valid';
    if (trim(@$_POST["nbutton"]) == 'del') // On a cliqué sur supprimer
        $action_to_do = 'delete';
}

if (isset($_GET['td']))
    $td = @$_GET['td'];
else {
    $td = "";
    if ($action_to_do <> '')
        $td = @$_POST['td'];
}

if (isset($_GET['cs']))
    $codest = @$_GET['cs'];
else {
    $codest = "";
    if ($action_to_do <> '')
        $codest = @$_POST['cs'];
}

if (isset($_GET['ics']))
    $idcst = intval(@$_GET['ics']);
else {
    if ($action_to_do <> '')
        $idcst = intval(@$_POST['ics']);
}

$tx = '';
if (isset($_GET['tx']))
    $tx = @$_GET['tx'];
else {
    if (isset($_POST['tx']))
        $tx = @$_POST['tx'];
    else
        $pbm_st = TRUE;
}

if (($td <> "add") AND (($tx == "dosd_cst") OR ($tx == "coloc")))
    $pbm_st = TRUE;

if ($codest <> "") {
    $row = lit_enr_st($codest);
    if (is_array($row)) {
        $row = encode_str($row);
        extract($row);

        $totalcst = nb_cst_in_st($codest);
        if ($totalcst == 0)
            $td = "add";
        $retourliste = FALSE;

        if ($action_to_do <> '') {
            $titre = @$_POST["titre"];
            $idcst = @$_POST["ics"];
            $code = @$_POST["cs"];
            $civil = str_majuscules(@$_POST["civil"]);
            $prenom = ucname(@$_POST["prenom"]);
            $nom = str_majuscules(@$_POST["nom"]);
            $fonction = str_majuscules(@$_POST["fonction"]);
            $adr1 = str_majuscules(@$_POST["adr1"]);
            $adr2 = str_majuscules(@$_POST["adr2"]);
            $pays = str_majuscules(@$_POST["pays"]);
            $dep = str_majuscules(@$_POST["dep"]);
            $ville = str_majuscules(@$_POST["ville"]);
            $telf = @$_POST["telf"];
            $fax = @$_POST["fax"];
            $telp = @$_POST["telp"];
            $email = strtolower(@$_POST["email"]);
            $mess = strtolower(@$_POST["mess"]);
            $nota = @$_POST["nota"];

            $rech = "";
            $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);

            switch ($td) {
                case "add" :
                    $rech = "INSERT INTO `" . TBCST . "`";
                    $rech .= " (cst_datecrea,cst_datemod,cst_codest,cst_codefonc,cst_civilite,cst_prenom,cst_nom,cst_telf,";
                    $rech .= "cst_adr1,cst_adr2,cst_dep,cst_ville,cst_codepays,";
                    $rech .= "cst_fax,cst_telp,cst_email,cst_mess,cst_nota) VALUES";
                    $rech .= " ('$datea','$datea','$code','$fonction','$civil','" . $db->escape($prenom) . "','" . $db->escape($nom) . "','$telf',";
                    $rech .= " '" . $db->escape($adr1) . "','" . $db->escape($adr2) . "','$dep','$ville','$pays',";
                    $rech .= "'$fax','$telp','$email','$mess','" . $db->escape($nota) . "')";
                    break;
                case "edit" :
                    if (@$_SESSION["niv_log"] >= 5) {
                        $rech = "UPDATE `" . TBCST . "` SET `cst_datemod`='" . $datea . "', `cst_codest`='" . $code . "', `cst_codefonc`='" . $fonction . "',";
                        $rech .= " `cst_civilite`='" . $civil . "', `cst_prenom`='" . $db->escape($prenom) . "', `cst_nom`='" . $db->escape($nom) . "', `cst_telf`='" . $telf . "', ";
                        $rech .= " `cst_adr1`='" . $db->escape($adr1) . "', `cst_adr2`='" . $db->escape($adr2) . "', `cst_dep`='" . $dep . "', `cst_ville`='" . $ville . "', `cst_codepays`='" . $pays . "', ";
                        $rech .= " `cst_fax`='" . $fax . "', `cst_telp`='" . $telp . "', `cst_email`='" . $email . "', `cst_mess`='" . $mess . "', ";
                        $rech .= " `cst_nota`='" . $db->escape($nota) . "'";
                        $rech .= "  WHERE `cst_id` = '" . $idcst . "'";
                    } else {
                        $rech = "UPDATE `" . TBCST . "` SET `cst_datemod`='" . $datea . "', `cst_codest`='" . $code . "', `cst_codefonc`='" . $fonction . "',";
                        $rech .= " `cst_civilite`='" . $civil . "', `cst_prenom`='" . $db->escape($prenom) . "', `cst_nom`='" . $db->escape($nom) . "', `cst_telf`='" . $telf . "', ";
                        $rech .= " `cst_adr1`='" . $db->escape($adr1) . "', `cst_adr2`='" . $db->escape($adr2) . "', `cst_dep`='" . $dep . "', `cst_ville`='" . $ville . "', `cst_codepays`='" . $pays . "', ";
                        $rech .= " `cst_fax`='" . $fax . "', `cst_telp`='" . $telp . "', `cst_email`='" . $email . "', `cst_mess`='" . $mess . "' ";
                        $rech .= "  WHERE `cst_id` = '" . $idcst . "'";
                    }
                    break;
                case "del" :
                    $rech = "DELETE FROM `" . TBCST . "` WHERE `cst_id` = '$idcst'";
                    break;
                default :
                    break;
            }
            if ($rech <> "") {
                $db->query($rech);
                $retourliste = TRUE;
            }
            $db->disconnect();
        } else {
            if ($st_ouvert == FALSE)
                $td = "view";
            switch ($td) {
                case "add" :
                    $titre = _("CREATION CONTACT");
                    $cst_adr1 = $st_adr1;
                    $cst_adr2 = $st_adr2;
                    $cst_dep = $st_dep;
                    $cst_ville = $st_ville;
                    $cst_codepays = $st_codepays;
                    $cst_telf = $st_telf;
                    $cst_fax = $st_fax;
                    break;
                case "edit" :
                case "del" :
                case "view" :
                    if ($td == "edit")
                        $titre = _("EDITION CONTACT");
                    if ($td == "del")
                        $titre = _("SUPPRESSION CONTACT");
                    if ($td == "view")
                        $titre = _("VISUALISATION CONTACT");
                    $row = lit_enr_cst_id_in_st($idcst, $codest);
                    if (is_array($row)) {
                        $row = encode_str($row);
                        extract($row);
                    } else
                        $pbm_st = TRUE;
                    break;
                case "lst" :
                    $titre = _("LISTE CONTACTS");
                    break;
                default :
                    $pbm_st = TRUE;
                    break;
            }
        }
        // On recalcule le total contacts
        $totalcst = nb_cst_in_st($codest);
        if ($totalcst == 0)
            $td ="add";
    } else
        $pbm_st = TRUE;
} else
    $pbm_st = TRUE;
?>
<!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 _("Contact Sous-traitant"); ?></title>

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

    <script language="javascript">
        <!--
        var tab_champ = ["nom:civil ; format:liste ; req:Y ; txt:<?PHP echo _("Civilité"); ?> ; vmn:1 ; stok:frmok ; stbad:frmbad",
            "nom:prenom; format:txt ; req:Y ; txt:<?PHP echo _("Prénom"); ?>; lmx:50; stok:frmok ; stbad:frmbad",
            "nom:nom; format:txt ; req:Y ; txt:<?PHP echo _("Nom"); ?> ; lmx:50; stok:frmok ; stbad:frmbad",
            "nom:fonction ; format:liste ; req:Y ; txt:<?PHP echo _("Fonction"); ?> ; vmn:1; stok:frmok ; stbad:frmbad",
            "nom:adr1 ; format:txt ; req:Y ; txt:<?PHP echo _("Adresse"); ?> ; lmn:1 ; lmx:50; stok:frmok ; stbad:frmbad",
            "nom:adr2 ; format:txt ; req:N ; txt:<?PHP echo _("Adresse (2)"); ?> ; lmx:50; stok:frmok ; stbad:frmbad",
            "nom:ville ; format:liste ; req:Y ; txt:<?PHP echo _("Ville"); ?> ; vmn:1; stok:frmok ; stbad:frmbad",
            "nom:dep ; format:liste ; req:Y ; txt:<?PHP echo _("Département"); ?> ; vmn:1; stok:frmok ; stbad:frmbad",
            "nom:pays ; format:liste ; req:Y ; txt:<?PHP echo _("Pays"); ?> ; vmn:1; stok:frmok ; stbad:frmbad",
            "nom:telf; format:tel ; req:Y ; txt:<?PHP echo _("Téléphone Fixe"); ?>; stok:frmok ; stbad:frmbad",
            "nom:fax; format:tel ; req:N ; txt:<?PHP echo _("Télécopieur"); ?>; stok:frmok ; stbad:frmbad",
            "nom:telp; format:telp ; req:N ; txt:<?PHP echo _("Téléphone portable"); ?>; stok:frmok ; stbad:frmbad",
            "nom:email; format:mail ; req:N ; txt:<?PHP echo _("Email"); ?>; stok:frmok ; stbad:frmbad",
            "nom:mess; format:mail ; req:N ; txt:<?PHP echo _("Messagerie"); ?> ; stok:frmok ; stbad:frmbad",
            <?PHP if (@$_SESSION["niv_log"] >= 5) { ?>
            "nom:nota; format:txt ; req:N ; txt:<?PHP echo _("Notes"); ?>; stok:frmok ; stbad:frmbad",
            <?PHP } ?>
            "nom:mess; format:mail ; req:N ; txt:<?PHP echo _("Messagerie"); ?> ; stok:frmok ; stbad:frmbad"];
        //-->
    </script>

    <?PHP if ($pbm_st == FALSE) { ?>
        <script type="text/javascript">
            <!--
            <?PHP
            if ($retourliste == TRUE)
            {
                switch ($tx) {
                    case "dosd_cst" :
                        cre_sel_ddeurs_cst($codest, 'window.opener.', 'cst');
                        break;
                    default :
                        break;
                }
            }
                cre_sel_ddeurs_st($codest, 'window.opener.', 'ddeur');
            ?>
            $(function () {
                $("#nom").Setcase({caseValue: 'upper', changeonFocusout: true});
                $("#adr1").Setcase({caseValue: 'upper', changeonFocusout: true});
                $("#adr2").Setcase({caseValue: 'upper', changeonFocusout: true});
                $("#email").Setcase({caseValue: 'lower', changeonFocusout: true});
                $("#mess").Setcase({caseValue: 'lower', changeonFocusout: true});
                $("#prenom").Setcase({caseValue: 'allfirst', changeonFocusout: true});
            });

            function init_all() {
                init_Body();
                init_autohref_classe('falselnkimg','');
                <?php
                if ($retourliste == FALSE)
                {
                    switch ($td)
                    {
                        case "add" :
                            echo "init_valid_form('enr','cst_maj','".$_SESSION['date_fmtshort']."',tab_champ,'pays','');";
                            break;
                        case "edit" :
                            echo "init_valid_form('enr','cst_maj','".$_SESSION['date_fmtshort']."',tab_champ,'pays','');";
                            break;
                        case "view" :
                            echo "readonly_all();";
                            break;
                        case "del" :
                            echo "init_valid_form('del','cst_maj','".$_SESSION['date_fmtshort']."',tab_champ,'pays','');";
                            echo "readonly_all();";
                            echo "warn_del('ope');";
                            break;
                    }
                    echo 'init_ajax_ville();';
                    echo 'init_ajax_dep();';
                    echo "chk_contacts('1', 'ctact', '".$totalcst."');";
                    echo "init_autohref('lst', 'click', 'cst_maj.php?ca=".$codest."&td=lst&tx=".$tx."',false);";
                    echo "init_autohref('add', 'click', 'cst_maj.php?ca=".$codest."&td=add&tx=".$tx."',false);";
                    echo "add_func_click('quit', 'sclose', '');";
                    echo "Focus_first();";
                }
                else
                {
                    switch ($tx)
                    {
                        case "age" :
                            echo "self.location.href=('cst_maj.php?cc=".$codest."&td=lst&tx=".$tx."');";
                            break;
                        default :
                            echo 'update_sel_ddeurs();';
                            echo "self.close();";
                            break;
                    }
                }
                ?>
            }

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

<?PHP

if ($pbm_st == FALSE)
{
?>
<p align="center"><span class="titrepage"><?PHP echo $titre ?></span></p>

<p align="center"><span class="titre_gras"><?PHP echo _("Pour le sous-traitant"); ?> : <?php echo $st_nom; ?> </span>
</p>
<table width="890" border="0">
    <tr>
        <td width="33%">&nbsp;</td>
        <td width="33%" align="center" class="annot_petit_it">
            <div id="oblig">(<img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo _("Champ obligatoire"); ?>">
                : <?PHP echo _("Saisie obligatoire"); ?>)
            </div>
        </td>
        <td width="33%" align="right">
            <input name="quit" type="button" class="bton_std" id="quit" value="<?PHP echo _("Quitter"); ?>">
            <?PHP if (($totalcst > 0) AND ($td <> "lst")) { ?>
                <input name="lst" type="button" class="bton_std" id="lst"
                       value="<?PHP echo _("Revenir à la liste"); ?>">
            <?PHP } ?>
        </td>
    </tr>
</table>
<?PHP
if ($retourliste == FALSE)
{
switch ($td)
{
case "add" :
case "edit" :
case "del" :
?>
<form name="cst_maj" id="cst_maj" method="post" action="cst_maj.php">
    <input name="titre" type="hidden" id="titre" value="<?PHP echo $titre; ?>">
    <input name="ics" type="hidden" id="ics" value="<?PHP echo $cst_id ?>">
    <input name="cs" type="hidden" id="cs" value="<?PHP echo $codest ?>">
    <input name="td" type="hidden" id="td" value="<?PHP echo $td ?>">
    <input name="tx" type="hidden" id="tx" value="<?PHP echo $tx ?>">
    <input name="nbutton" type="hidden" id="nbutton" value="">
    <table width="890" border="0">
        <tr>
            <td width="160" class="rubfrm" id="f_civil" align="right"><?PHP echo _("Civilité"); ?></td>
            <td width="84%">
                <?PHP
                // Création de la liste des civilités
                $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
                $rech = "SELECT * FROM `" . TBCIV . "` ORDER BY civ_desc";
                $rows = $db->get_results($rech, ARRAY_A);
                $db->disconnect();
                cre_select_tab('civil', 'civil', $rows, 'civ_code', 'civ_desc', '', $cst_civilite, '', _("-- Faites votre choix --"));
                ?>
            </td>
        </tr>
        <tr>
            <td width="160" class="rubfrm" id="f_prenom" align="right"><?PHP echo _("Prénom"); ?></td>
            <td><input name="prenom" type="text" id="prenom" value="<?PHP echo $cst_prenom ?>" size="50" maxlength="50">
                <img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo _("Champ obligatoire"); ?>"></td>
        </tr>
        <tr>
            <td width="160" class="rubfrm" id="f_nom" align="right"><?PHP echo _("Nom"); ?></td>
            <td><input name="nom" type="text" id="nom" value="<?PHP echo $cst_nom ?>" size="50" maxlength="50">
                <img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo _("Champ obligatoire"); ?>"></td>
        </tr>
        <tr>
            <td width="160" class="rubfrm" id="f_func" align="right"><?PHP echo _("Fonction"); ?></td>
            <td width="84%">
                <?PHP
                // création de la liste des fonctions
                $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
                $rech = "SELECT * FROM `" . TBFONC . "` ORDER BY fonc_desc";
                $rows = $db->get_results($rech, ARRAY_A);
                $db->disconnect();
                cre_select_tab('fonction', 'fonction', $rows, 'fonc_code', 'fonc_desc', '', $cst_codefonc, '', _("-- Faites votre choix --"));
                ?>
            </td>
        </tr>
        <tr>
            <td width="160" class="rubfrm" id="f_adr1" align="right"><?PHP echo _("Adresse"); ?></td>
            <td>
                <input name="adr1" type="text" id="adr1" value="<?PHP echo $cst_adr1; ?>" size="50">
                <img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo _("Champ obligatoire"); ?>">
            </td>
        </tr>
        <tr>
            <td width="160" class="rubfrm" id="f_adr2" align="right"><?PHP echo _("Adresse (2)"); ?></td>
            <td>
                <input name="adr2" type="text" id="adr2" value="<?PHP echo $cst_adr2; ?>" size="50">
            </td>
        </tr>
        <tr>
            <td class="rubfrm" id="f_pays" align="right"><?PHP echo _("Pays"); ?></td>
            <td>
                <?PHP
                // Création de la liste des pays
                $rows = give_rows_pays();
                cre_select_tab('pays', 'pays', $rows, 'pays_code', 'pays_nom', '', $cst_codepays, '', _("-- 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
                // Création de la liste des départements
                $rows = give_rows_dep($cst_codepays);
                cre_select_tab('dep', 'dep', $rows, 'dep_code', 'dep_code', 'dep_nom', $cst_dep, '', _("-- Faites votre choix --"), 1, FALSE, '-1', _("-- Inconnu --"));
                ?>
            </td>
        </tr>
        <tr>
            <td class="rubfrm" id="f_ville" align="right"><?PHP echo _("Ville"); ?></td>
            <td>
                <?PHP
                // Création de la liste des villes
                $rows = give_rows_villes($cst_dep,$cst_codepays);
                cre_select_tab('ville', 'ville', $rows, 'villes_id', 'villes_nom', 'villes_cp', $cst_ville, '', _("-- Faites votre choix --"), 1, FALSE, '-1', _("-- Inconnu --"));
                ?>
            </td>
        </tr>
        <tr>
            <td width="160" class="rubfrm" id="f_telf" align="right"><?PHP echo _("Tél. Fixe"); ?></td>
            <td><input name="telf" type="text" id="telf" value="<?PHP echo $cst_telf ?>" size="20" maxlength="20">
                <img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo _("Champ obligatoire"); ?>"></td>
        </tr>
        <tr>
            <td width="160" class="rubfrm" id="f_fax" align="right"><?PHP echo _("Télécopieur"); ?></td>
            <td><input name="fax" type="text" id="fax" value="<?PHP echo $cst_fax ?>" size="20" maxlength="20"></td>
        </tr>
        <tr>
            <td width="160" class="rubfrm" id="f_telp" align="right"><?PHP echo _("Téléphone portable"); ?></td>
            <td><input name="telp" type="text" id="telp" value="<?PHP echo $cst_telp ?>" size="20" maxlength="20">
            </td>
        </tr>
        <tr>
            <td width="160" class="rubfrm" id="f_email" align="right"><?PHP echo _("Email"); ?></td>
            <td><input name="email" type="text" id="email" value="<?PHP echo $cst_email ?>" size="50" maxlength="50">
                <?PHP if ($td == "edit") { ?>
                <a href="mailto:<?PHP echo $cst_email ?>"><img src="../img/mail.png"
                                                               title="<?PHP echo _("Envoyer e-mail"); ?>" border="0"
                                                               align="absmiddle"></a></td>
            <?PHP } ?>
        </tr>
        <tr>
            <td width="160" class="rubfrm" id="f_mess" align="right"><?PHP echo _("Messagerie"); ?></td>
            <td><input name="mess" type="text" id="mess" value="<?PHP echo $cst_mess ?>" size="50" maxlength="50"></td>
        </tr>
        <?PHP if (@$_SESSION["niv_log"] >= 5) {
            ?>
            <tr>
                <td width="160" class="rubfrm" id="f_nota" align="right"><?PHP echo _("Notes"); ?></td>
                <td><textarea name="nota" id="nota"><?PHP echo $cst_nota ?></textarea></td>
            </tr>
        <?PHP } ?>
    </table>
    <p align="center">
        <?PHP
        switch ($td)
        {
            case "add" :
            case "edit" :
                echo '<input name="enr" type="button" class="bton_std" id="enr" value="'._("Valider").'">';
                break;
            case "del" :
                echo '<input name="del" type="button" class="bton_std" id="del" value="'._("Supprimer").'">';
                break;
        }
        echo '<input name="RAZ" type="reset" class="bton_std" id="RAZ" value="'._("Réinitialiser").'">';

        if ($td == "edit")
        {
            echo '<br />';
            echo '<br />';
            echo '<input name="add" type="button" class="bton_std" id="add" value="'. _("Saisir un nouveau contact").'">';
        }
        ?>
    </p>
</form>
<?PHP
break;
case "lst" :
    // création de la liste des contacts donneur d'ordres
    $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
    $rech = "SELECT * FROM `" . TBCST . "` WHERE `cst_codest` = '" . $codest . "' ORDER BY 'cst_nom'";

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

    if (($rows) AND (count($rows) > 0)) {
        echo "<table class=\"MtableD\" border=\"0\" width=\"890\" cellpadding=\"0\" cellspacing=\"0\" align=\"center\">\n";

        // création de l'entête de la table contacts clients
        echo "<th>";
        echo _("Nom, Prénom");
        echo "</th>\n";
        echo "<th>";
        echo _("Fonction");
        echo "</th>\n";
        echo "<th>";
        echo _("Téléphone");
        echo "</th>\n";
        echo "<th>";
        echo _("Email");
        echo "</th>\n";
        echo "<th>";
        echo _("Choisir");
        echo "</th>\n";

        $j = 0;

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

            echo "<td>\n";
            echo $row["cst_nom"] . " " . $row["cst_prenom"];
            echo "</td>\n";
            echo "<td>\n";
            $txtfonc = "&nbsp;";
            $rech2 = "SELECT * FROM `" . TBFONC . "` WHERE `fonc_code` = '" . $row["cst_codefonc"] . "'";
            $row2 = $db->get_row($rech2, ARRAY_A);
            if ($row2) {
                $row2 = encode_str($row2);
                $txtfonc = $row2["fonc_desc"];
            }
            echo $txtfonc;
            echo "</td>\n";
            echo "<td align=\"center\">\n";
            echo $row["cst_telf"];
            echo "</td>\n";
            echo "<td align=\"center\">\n";
            echo "<a href=\"mailto:" . $row["cst_email"] . "\">" . $row["cst_email"] . "</a>";
            echo "</td>\n";

            echo "<td align=\"center\">\n";
            $lst_maj = TRUE;
            cre_falselnk_img('', 'cst_edit_'.$row["cst_id"], 'span', 'center', _("Edition"), 'lnk', 'cst_maj.php?td=edit&cs=' . $row["cst_codest"] . '&ics=' . $row["cst_id"] . '&tx=' . $tx, '../img/edit.png');
            $lst_del = TRUE;
            cre_falselnk_img('', 'cst_del_'.$row["cst_id"], 'span', 'center', _("Suppression"), 'lnk', 'cst_maj.php?td=del&cs=' . $row["cst_codest"] . '&ics=' . $row["cst_id"] . '&tx=' . $tx, '../img/del.png');
            echo "</tr>\n";

            $j++;
        }

        echo "</table>\n";
        // Fin affichage table liste contacts donneurs d'ordres
        $taille_piedla = "";
        include_once("piedla.inc.php");
        ?>
        <p align="center">
            <input name="add" type="button" class="bton_std" id="add"
                   value="<?PHP echo _("Saisir un nouveau contact"); ?>">
        </p>
    <?PHP
    }
    break;

default :
    break;
}
}
/*
else {
    switch ($tx) {
        default :
            pop_ret_auto(_("Fiche enregistrée"), '', 'cst_maj.php?cs=' . $codest . '&td=lst&tx=' . $tx);
            break;
    }
}
*/
}
/*
else
    close_fen_auto('', '');
*/
?>
</body>
</html>
