<?php
/****************************************************************************************
 * SMI (Services Maintenance Interventions) est une gestion libre de maintenance et de SAV
 *
 * Version 1.0.4
 *
 * Copyright (C) 2006-2016  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) {
    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_do.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_tra.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(valsession('code_log'));
// Variables Formulaire
fix_magic_quotes();
$_GET = clean_str($_GET);
$_POST = clean_str($_POST);

if (isset($_GET['td'])) {
    $td = valget('td');
} else {
    $td = '';
    if ((valpost('nbutton') == 'enr') OR (valpost('nbutton') == 'del')) {
        $td = valpost('td');
    }
}

if (isset($_GET['cd'])) {
    $codedo = valget('cd');
} else {
    $codedo = '';
    if ((valpost('nbutton') == 'enr') OR (valpost('nbutton') == 'del')) {
        $codedo = valpost('cd');
    }
}

if (isset($_GET['icd'])) {
    $idcdo = valget('icd');
} else {
    $idcdo = 0;
    if ((valpost('nbutton') == 'enr') OR (valpost('nbutton') == 'del')) {
        $idcdo = valpost('icd');
    }
}

$pbm_do = FALSE;
$totalcdo = 0;

$tx = '';
if (isset($_GET['tx'])) {
    $tx = valget('tx');
} else {
    if (isset($_POST['tx'])) {
        $tx = valpost('tx');
    } else {
        $pbm_do = TRUE;
    }
}

if (($td <> 'add') AND ($tx == 'dosd_cdo')) {
    $pbm_do = TRUE;
}

if ($codedo <> '') {
    $row = lit_enr_do($codedo);
    if (is_array($row)) {
        $row = encode_str($row);
        extract($row);

        $totalcdo = nb_cdo_in_do($codedo);
        if ($totalcdo == 0) {
            $td = 'add';
        }
        $retourliste = FALSE;

        if ((valpost('nbutton') == 'enr') OR (valpost('nbutton') == 'del')) {
            $titre = valpost('titre');
            $idcdo = valpost('icd');
            $code = valpost('cd');
            $civil = str_majuscules(valpost('civil'));
            $prenom = ucname(valpost('prenom'));
            $nom = str_majuscules(valpost('nom'));
            $fonction = str_majuscules(valpost('fonction'));
            $adr1 = str_majuscules(valpost('adr1'));
            $adr2 = str_majuscules(valpost('adr2'));
            $pays = str_majuscules(valpost('pays'));
            $dep = str_majuscules(valpost('dep'));
            $ville = str_majuscules(valpost('ville'));
            $telf = valpost('telf');
            $fax = valpost('fax');
            $telp = valpost('telp');
            $email = strtolower(valpost('email'));
            $mess = strtolower(valpost('mess'));
            $nota = valpost('nota');

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

            switch ($td) {
                case 'add' :
                    // données traçabilité
                    $titre_tra = _("Création du contact donneur d'ordres");
                    $desc_tra_default = $prenom;
                    $desc_tra_default .= chr(13) . chr(10);
                    $desc_tra_default .= $nom;

                    $rech = 'INSERT INTO `' . TBCDO . '`';
                    $rech .= ' (cdo_datecrea,cdo_datemod,cdo_codedo,cdo_codefonc,cdo_civilite,cdo_prenom,cdo_nom,';
                    $rech .= 'cdo_adr1,cdo_adr2,cdo_dep,cdo_ville,cdo_codepays,';
                    $rech .= 'cdo_telf,cdo_fax,cdo_telp,cdo_email,cdo_mess,cdo_nota) VALUES';
                    $rech .= " ('$datea','$datea','$code','$fonction','$civil','" . $db->escape($prenom) . "','" . $db->escape($nom) . "',";
                    $rech .= " '" . $db->escape($adr1) . "','" . $db->escape($adr2) . "','$dep','$ville','$pays',";
                    $rech .= "'$telf','$fax','$telp','$email','$mess','" . $db->escape($nota) . "')";
                    break;
                case 'edit' :
                    // On récupère l'enregistrement précédent (traçabilité)
                    $rech = 'SELECT * FROM `' . TBCDO . "` WHERE cdo_id = '$idcdo'";
                    $ex_enrcdo = $db->get_row($rech, ARRAY_A);

                    if (valsession('niv_log') >= 5) {
                        $rech = 'UPDATE `' . TBCDO . "` SET `cdo_datemod`='" . $datea . "', `cdo_codedo`='" . $code . "', `cdo_codefonc`='" . $fonction . "',";
                        $rech .= " `cdo_civilite`='" . $civil . "', `cdo_prenom`='" . $db->escape($prenom) . "', `cdo_nom`='" . $db->escape($nom) . "', `cdo_telf`='" . $telf . "', ";
                        $rech .= " `cdo_adr1`='" . $db->escape($adr1) . "', `cdo_adr2`='" . $db->escape($adr2) . "', `cdo_dep`='" . $dep . "', `cdo_ville`='" . $ville . "', `cdo_codepays`='" . $pays . "', ";
                        $rech .= " `cdo_fax`='" . $fax . "', `cdo_telp`='" . $telp . "', `cdo_email`='" . $email . "', `cdo_mess`='" . $mess . "', ";
                        $rech .= " `cdo_nota`='" . $db->escape($nota) . "'";
                        $rech .= "  WHERE `cdo_id` = '" . $idcdo . "'";
                    } else {
                        $rech = 'UPDATE `' . TBCDO . "` SET `cdo_datemod`='" . $datea . "', `cdo_codedo`='" . $code . "', `cdo_codefonc`='" . $fonction . "',";
                        $rech .= " `cdo_civilite`='" . $civil . "', `cdo_prenom`='" . $db->escape($prenom) . "', `cdo_nom`='" . $db->escape($nom) . "', `cdo_telf`='" . $telf . "', ";
                        $rech .= " `cdo_adr1`='" . $db->escape($adr1) . "', `cdo_adr2`='" . $db->escape($adr2) . "', `cdo_dep`='" . $dep . "', `cdo_ville`='" . $ville . "', `cdo_codepays`='" . $pays . "', ";
                        $rech .= " `cdo_fax`='" . $fax . "', `cdo_telp`='" . $telp . "', `cdo_email`='" . $email . "', `cdo_mess`='" . $mess . "' ";
                        $rech .= "  WHERE `cdo_id` = '" . $idcdo . "'";
                    }
                    break;
                case 'del' :
                    $rech = 'DELETE FROM `' . TBCDO . "` WHERE `cdo_id` = '$idcdo'";
                    break;
                default :
                    break;
            }
            if ($rech <> '') {
                $db->query($rech);
                switch ($td) {
                    case 'add' :
                        // Ajout traçabilité
                        $desc_tra = $desc_tra_default;
                        add_trace(3, $code, 'CRE', $titre_tra, $desc_tra, FALSE);
                        break;
                    case 'edit' :
                        // On récupère l'enregistrement actuel (traçabilité)
                        $rech = 'SELECT * FROM `' . TBCDO . "` WHERE cdo_id = '$idcdo'";
                        $nouv_enrcdo = $db->get_row($rech, ARRAY_A);

                        // On compare les éléments d'enregistrement pour traçabilité
                        $trace_added = analyse_trace('cdo', $ex_enrcdo, $nouv_enrcdo, '', FALSE);
                        break;
                    default :
                        break;
                }
                $retourliste = TRUE;
            }
            close_database();
        } else {
            if ($do_ouvert == FALSE) {
                $td = 'view';
            }
            switch ($td) {
                case 'add' :
                    $titre = _('CREATION CONTACT');
                    $cdo_adr1 = $do_adr1;
                    $cdo_adr2 = $do_adr2;
                    $cdo_dep = $do_dep;
                    $cdo_ville = $do_ville;
                    $cdo_codepays = $do_codepays;
                    $cdo_telf = $do_telf;
                    $cdo_fax = $do_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_cdo_id_in_do($idcdo, $codedo);
                    if ($row) {
                        $row = encode_str($row);
                        extract($row);
                    } else {
                        $pbm_do = TRUE;
                    }
                    break;
                case 'lst' :
                    $titre = _('LISTE CONTACTS');
                    break;
                default :
                    $pbm_do = TRUE;
                    break;
            }
        }
        // On recalcule le total contacts
        $totalcdo = nb_cdo_in_do($codedo);
        if ($totalcdo == 0) {
            $td = 'add';
        }
    } else {
        $pbm_do = TRUE;
    }
} else {
    $pbm_do = TRUE;
}
$lst_chp_readonly = '';
if ($do_ouvert == FALSE) {
    $lst_chp_readonly = 'pays-dep-ville';
}

?>
<!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 Donneur d'Ordres"); ?></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 (valsession('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_do == FALSE) { ?>
        <script type="text/javascript">
            <!--
            <?php
            if ($retourliste == TRUE)
            {
                switch ($tx) {
                    case 'dosd_cdo' :
                        cre_sel_ddeurs_cdo($codedo, 'window.opener.', 'cdo');
                        break;
                    default :
                        break;
                }
            }
            ?>


            $(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','cdo_maj','".valsession('date_fmtshort')."',tab_champ,'pays','');";
                            break;
                        case 'edit' :
                            echo "init_valid_form('enr','cdo_maj','".valsession('date_fmtshort')."',tab_champ,'pays','');";
                            break;
                        case 'del' :
                            echo "init_valid_form('del','cdo_maj','".valsession('date_fmtshort')."',tab_champ,'pays','');";
                            echo 'warn_del();';
                            echo 'readonly_all();';
                            break;
                        case 'view' :
                            echo 'readonly_all();';
                            break;
                    }
                }
                else{
                    switch ($tx) {
                        case 'dosd_cdo' :
                            echo 'update_sel_ddeurs();';
                            echo 'self.close();';
                            break;
                        default :
                            echo "ok_txt('" . str_escape(_('Fiche enregistrée')) . "',5000);\n";
                            echo "window.setTimeout(\"location=('cdo_maj.php?cd=" . $codedo . '&td=lst&tx=' . $tx."');\",500);\n";
                            break;
                    }
                }
                ?>
                init_ajax_ville();
                init_ajax_dep();
                init_autohref('lst', 'click', 'cdo_maj.php?cd=<?php echo $codedo; ?>&td=lst&tx=<?php echo $tx; ?>', false);
                init_autohref('add', 'click', 'cdo_maj.php?cd=<?php echo $codedo; ?>&td=add&tx=<?php echo $tx; ?>', false);
                add_func_click('quit', 'sclose', '');
                chk_contacts('1', 'ctact', '<?php echo $totalcdo; ?>');
                readonly_id('<?php echo $lst_chp_readonly; ?>', false);
                Focus_first();
            }

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

    <?php } ?>
</head>
<body>

<?php
if ($pbm_do == FALSE) {
    cre_ent_form($titre, '', '', '', FALSE);
    ?>
    <p align="center"><span class="titre_gras"><?php echo _("Pour le donneur d'ordres"); ?>
            : <?php echo $do_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 (($totalcdo > 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="cdo_maj" id="cdo_maj" method="post" action="cdo_maj.php">
                    <input name="icd" type="hidden" id="icd" value="<?php echo $cdo_id ?>">
                    <input name="cd" type="hidden" id="cd" value="<?php echo $codedo ?>">
                    <input name="td" type="hidden" id="td" value="<?php echo $td ?>">
                    <input name="tx" type="hidden" id="tx" value="<?php echo $tx ?>">
                    <input name="titre" type="hidden" id="titre" value="<?php echo $titre ?>">
                    <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, 'utf8');
                                $rech = 'SELECT * FROM `' . TBCIV . '` ORDER BY civ_desc';
                                $rows = $db->get_results($rech, ARRAY_A);
                                close_database();
                                cre_select_tab('civil', 'civil', $rows, 'civ_code', 'civ_desc', '', $cdo_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 $cdo_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 $cdo_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, 'utf8');
                                $rech = 'SELECT * FROM `' . TBFONC . '` ORDER BY fonc_desc';
                                $rows = $db->get_results($rech, ARRAY_A);
                                close_database();
                                cre_select_tab('fonction', 'fonction', $rows, 'fonc_code', 'fonc_desc', '', $cdo_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 $cdo_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 $cdo_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', '', $cdo_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($cdo_codepays);
                                cre_select_tab('dep', 'dep', $rows, 'dep_code', 'dep_code', 'dep_nom', $cdo_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($cdo_dep, $cdo_codepays);
                                cre_select_tab('ville', 'ville', $rows, 'villes_id', 'villes_nom', 'villes_cp', $cdo_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 $cdo_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 $cdo_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 $cdo_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 $cdo_email ?>" size="50"
                                       maxlength="50">
                                <?php if ($td == 'edit') { ?>
                                <a href="mailto:<?php echo $cdo_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 $cdo_mess ?>" size="50"
                                       maxlength="50"></td>
                        </tr>
                        <?php if (valsession('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 $cdo_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, 'utf8');
                $rech = 'SELECT * FROM `' . TBCDO . "` WHERE `cdo_codedo` = '" . $db->escape($codedo) . "' ORDER BY 'cdo_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">';

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

                    foreach ($rows as $row) {
                        $row = encode_str($row);
                        // création de l'entête de ligne (TR)
                        echo '<tr>';

                        echo '<td>';
                        echo $row['cdo_nom'] . ' ' . $row['cdo_prenom'];
                        echo '</td>';
                        echo '<td>';
                        $txtfonc = '&nbsp;';
                        $rech2 = 'SELECT fonc_desc FROM `' . TBFONC . "` WHERE `fonc_code` = '" . $row['cdo_codefonc'] . "'";
                        $row2 = $db->get_row($rech2, ARRAY_A);
                        if ($row2) {
                            $row2 = encode_str($row2);
                            $txtfonc = $row2['fonc_desc'];
                        }
                        echo $txtfonc;
                        echo '</td>';
                        echo '<td align="center">';
                        echo $row['cdo_telf'];
                        echo '</td>';
                        echo '<td align="center">';
                        echo ' <a href="mailto:' . $row['cdo_email'] . '">' . $row['cdo_email'] . '</a>';
                        echo '</td>';

                        echo '<td align="center">';
                        $lst_maj = TRUE;
                        cre_falselnk_img('', 'cdo_edit_' . $row['cdo_id'], 'span', 'center', _('Edition'), 'lnk', 'cdo_maj.php?td=edit&cd=' . $row['cdo_codedo'] . '&icd=' . $row['cdo_id'] . '&tx=' . $tx, '../img/edit.png');
                        $lst_del = TRUE;
                        cre_falselnk_img('', 'cdo_del_' . $row['cdo_id'], 'span', 'center', _('Suppression'), 'lnk', 'cdo_maj.php?td=del&cd=' . $row['cdo_codedo'] . '&icd=' . $row['cdo_id'] . '&tx=' . $tx, '../img/del.png');
                        echo '</td>';
                        echo '</tr>';
                    }

                    echo '</table>';
                    // 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
                }
                close_database();
                break;

            default :
                break;
        }
    }
} else {
    close_fen_auto('', '');
}
?>
</body>
</html>
