<?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_dos.inc.php");
include_once("../inc/fic_droits.inc.php");
include_once("../inc/fic_hum.inc.php");
include_once("../inc/fic_mque.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 = '';
$codemque = "";
$idcmque = 0;
$tx = '';

$action_to_do = '';
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 (trim(@$_POST["nbutton"]) == 'add') // On a cliqué sur ajouter
    $action_to_do = 'add';

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

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

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

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

if (isset($_GET['is']))
    $is = @$_GET['is'];
else {
    if (isset($_POST['is']))
        $is = @$_POST['is'];
}
$pbm_rlpma = FALSE;
$cmque_prop = "";
$cmquen_nota = "";

$codeuser = @$_SESSION["code_log"];

if (@$_SESSION["niv_log"] == 3)
    $codeuser = @$_SESSION["code_age"];

if (($td <> "add") AND ($tx == "dosd_cmque"))
    $pbm_rlpma = TRUE;

if ($codemque <> "") {
    $row = lit_enr_mque($codemque, TRUE);
    if (is_array($row)) {
        $row = encode_str($row);
        extract($row);

        $totalcmque = nb_cmque_in_mque($codemque);
        if ($totalcmque == 0)
            $td = "add";
        $retourliste = FALSE;

        if ($action_to_do <> '') {
            $idcmque = @$_POST["icm"];
            $prop = @$_POST["prop"];
            $code = @$_POST["cm"];
            $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"]);
            $notaa = @$_POST["notaa"];
            $notat = @$_POST["notat"];
            $notap = @$_POST["notap"];

            $rech = "";

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

            // Fiche contact Marque
            switch ($td) {
                case "add" :
                    $rech = "INSERT INTO `" . TBCMQUE . "`";
                    $rech .= " (cmque_codemque,cmque_codefonc,cmque_civilite,cmque_prenom,cmque_nom,";
                    $rech .= "cmque_adr1,cmque_adr2,cmque_dep,cmque_ville,cmque_codepays,";
                    $rech .= "cmque_telf,cmque_fax,cmque_telp,cmque_email,cmque_mess,cmque_notaa,cmque_notat,cmque_prop) VALUES";
                    $rech .= " ('$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($notaa) . "','" . $db->escape($notat) . "','$prop')";
                    break;
                case "edit" :
                    if (@$_SESSION["niv_log"] >= 5) {
                        $rech = "UPDATE `" . TBCMQUE . "` SET `cmque_codemque`='" . $code . "', `cmque_codefonc`='" . $fonction . "',";
                        $rech .= " `cmque_civilite`='" . $civil . "', `cmque_prenom`='" . $db->escape($prenom) . "', `cmque_nom`='" . $db->escape($nom) . "', `cmque_telf`='" . $telf . "', ";
                        $rech .= " `cmque_adr1`='" . $db->escape($adr1) . "', `cmque_adr2`='" . $db->escape($adr2) . "', `cmque_dep`='" . $dep . "', `cmque_ville`='" . $ville . "', `cmque_codepays`='" . $pays . "', ";
                        $rech .= " `cmque_fax`='" . $fax . "', `cmque_telp`='" . $telp . "', `cmque_email`='" . $email . "', `cmque_mess`='" . $mess . "', ";
                        $rech .= " `cmque_notaa`='" . $db->escape($notaa) . "', `cmque_notat`='" . $db->escape($notat) . "', `cmque_prop`='" . $prop . "'";
                        $rech .= "  WHERE `cmque_id` = '" . $idcmque . "'";
                    } else {
                        $rech = "UPDATE `" . TBCMQUE . "` SET `cmque_codemque`='" . $code . "', `cmque_codefonc`='" . $fonction . "',";
                        $rech .= " `cmque_civilite`='" . $civil . "', `cmque_prenom`='" . $db->escape($prenom) . "', `cmque_nom`='" . $db->escape($nom) . "', `cmque_telf`='" . $telf . "', ";
                        $rech .= " `cmque_adr1`='" . $db->escape($adr1) . "', `cmque_adr2`='" . $db->escape($adr2) . "', `cmque_dep`='" . $dep . "', `cmque_ville`='" . $ville . "', `cmque_codepays`='" . $pays . "', ";
                        $rech .= " `cmque_fax`='" . $fax . "', `cmque_telp`='" . $telp . "', `cmque_email`='" . $email . "', `cmque_mess`='" . $mess . "', ";
                        $rech .= " `cmque_notat`='" . $db->escape($notat) . "', `cmque_prop`='" . $prop . "'";
                        $rech .= "  WHERE `cmque_id` = '" . $idcmque . "'";
                    }
                    break;
                case "del" :
                    $rech = "DELETE FROM `" . TBCMQUE . "` WHERE `cmque_id` = '$idcmque'";
                    break;
                default :
                    break;
            }
            if ($rech <> "") {
                $db->query($rech);

                $rech = "";
                // Notes privées
                switch ($td) {
                    case "add" :
                        $id = $db->insert_id;
                        $rech = "INSERT INTO `" . TBCMQUEN . "` (cmquen_idcmque,cmquen_codeu,cmquen_nota)";
                        $rech .= " VALUES ('$id','$codeuser','" . $db->escape($notap) . "')";
                        break;
                    case "edit" :
                        $rech = "SELECT COUNT(*) FROM `" . TBCMQUEN . "` WHERE `cmquen_idcmque` = '$idcmque' AND `cmquen_codeu` = '$codeuser'";
                        $nbres = $db->get_var($rech);
                        if ($nbres > 0) {
                            $rech = "UPDATE `" . TBCMQUEN . "`";
                            $rech .= " SET `cmquen_nota`='" . $db->escape($notap) . "'";
                            $rech .= " WHERE (`cmquen_idcmque` = '" . $idcmque . "' AND `cmquen_codeu` = '" . $codeuser . "')";
                        } else {
                            $rech = "INSERT INTO `" . TBCMQUEN . "` (cmquen_idcmque,cmquen_codeu,cmquen_nota)";
                            $rech .= " VALUES ('$idcmque','$codeuser','" . $db->escape($notap) . "')";
                        }
                        break;
                    case "del" :
                        $rech = "DELETE FROM `" . TBCMQUEN . "` WHERE `cmquen_idcmque` = '$idcmque'";
                        break;
                    default :
                        break;
                }
                if ($rech <> "")
                    $db->query($rech);
                $retourliste = TRUE;
            }
            $db->disconnect();
            $td = "lst";
            // On recalcule le total contacts
            $totalcmque = nb_cmque_in_mque($codemque);
            if ($totalcmque == 0)
                $td = "add";
        }
    } else
        $pbm_rlpma = TRUE;

    switch ($td) {
        case "add" :
            $titre = _("CREATION CONTACT");
            $cmque_adr1 = $mque_adr1;
            $cmque_adr2 = $mque_adr2;
            $cmque_dep = $mque_dep;
            $cmque_ville = $mque_ville;
            $cmque_codepays = $mque_codepays;
            $cmque_telf = $mque_telf;
            $cmque_fax = $mque_fax;
            break;
        case "edit" :
        case "del" :
            if ($td == "edit")
                $titre = _("EDITION CONTACT");
            if ($td == "del")
                $titre = _("SUPPRESSION CONTACT");
            $row = lit_enr_cmque_id_in_mque($idcmque, $codemque);
            if (is_array($row)) {
                $row = encode_str($row);
                extract($row);
                $row = lit_enr_CMqueNPriv($cmque_id, $codeuser);
                if (is_array($row)) {
                    $row = encode_str($row);
                    extract($row);
                }
            } else
                $pbm_rlpma = TRUE;
            break;
        case "lst" :
            $titre = _("LISTE CONTACTS");
            break;
        default :
            $pbm_rlpma = TRUE;
            break;
    }

} else
    $pbm_rlpma = TRUE;

$affliste=TRUE;
if (((@$_SESSION["niv_log"]==3) OR (@$_SESSION["niv_log"]==4)) AND ($cmque_prop=="*"))
    $affliste=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 Marque"); ?></title>

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

    <script language="javascript">
        <!--
        var tab_champ = ["nom:prop ; format:liste ; req:Y ; txt:<?PHP echo _("Type de contact"); ?> ; vmn:1 ; stok:frmok ; stbad:frmbad",
            "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",
            "nom:mess; format:mail ; req:N ; txt:<?PHP echo _("Messagerie"); ?> ; stok:frmok ; stbad:frmbad",
            <?PHP if (@$_SESSION["niv_log"] >= 5)
                echo '"nom:notaa; format:txt ; req:N ; txt:'._("Notes Administration").' ; stok:frmok ; stbad:frmbad",';
            ?>
            "nom:notat; format:txt ; req:N ; txt:<?PHP echo _("Notes Agences"); ?> ; stok:frmok ; stbad:frmbad"];
        //-->
    </script>

    <?PHP if ($pbm_rlpma == FALSE) { ?>
        <script type="text/javascript">
            <!--
            <?PHP
            if ($retourliste == TRUE)
            {
                switch ($tx) {
                    case "dosd_cmque" :
                        cre_sel_ddeurs_cmque($codemque, "window.opener.", 'cmque');
                    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','');
                chk_contacts('1', 'ctact', '<?PHP echo $totalcmque; ?>');
                <?php
                if ($retourliste == FALSE)
                {
                    switch ($td)
                    {
                        case "add" :
                            echo "init_valid_form('enr','cmque_maj','".$_SESSION['date_fmtshort']."',tab_champ,'pays','');";
                            break;
                        case "edit" :
                            echo "init_valid_form('enr','cmque_maj','".$_SESSION['date_fmtshort']."',tab_champ,'pays','');";
                            break;
                        case "del" :
                            echo "init_valid_form('del','cmque_maj','".$_SESSION['date_fmtshort']."',tab_champ,'pays','');";
                            echo "warn_del();";
                            echo "readonly_all();";
                            break;
                        case "view" :
                            echo "readonly_all();";
                            break;
                    }
                    echo "init_ajax_ville();";
                    echo "init_ajax_dep();";
                    echo "add_func_click('quit', 'sclose','');";
                    echo "init_autohref('lst', 'click', 'cmque_maj.php?cm=".$codemque."&td=lst',false);";
                    echo "init_autohref('add', 'click', 'cmque_maj.php?cm=".$codemque."&td=add',false);";
                    if ($affliste == FALSE)
                        echo "readonly_id('prop',false);";
                    echo "Focus_first();";
                }
                else
                {
                    switch ($tx) {
                        case "dosd_cmque" :
                            echo "update_sel_ddeurs();";
                            echo "close_fen_auto('', 'fscomp2');";
                        break;
                        default :
                            echo "self.location.href=('cmque_maj.php?cm=" . $codemque . "&td=lst');";
                            break;
                    }
                }
                ?>
            }

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

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

<p align="center"><span class="titre_gras"><?PHP echo _("Pour la marque"); ?> : <?php echo $mque_ste; ?> </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"); ?>"
                   style="text-decoration: none; font-size: 11px; color:White ;font-weight:bold;background-color: #666666;">
            <?PHP if (($totalcmque > 0) AND ($td <> "lst") AND ($tx <> "dosd_cmque")) { ?>
                <input name="lst" type="button" class="bton_std" id="lst" value="<?PHP echo _("Revenir à la liste"); ?>"
                       style="text-decoration: none; font-size: 11px; color:White ;font-weight:bold;background-color: #666666;">
            <?PHP } ?>
        </td>
    </tr>
</table>
<?PHP
switch ($td)
{
case "add" :
case "edit" :
case "del" :
?>
<form name="cmque_maj" id="cmque_maj" method="post" action="cmque_maj.php">
<input name="icm" type="hidden" id="icm" value="<?PHP echo $cmque_id ?>">
<input name="cm" type="hidden" id="cm" value="<?PHP echo $codemque ?>">
<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="100%" border="0">
    <tr>
        <td width="160" class="rubfrm" id="f_prop" align="right"><?PHP echo _("Type de contact"); ?></td>
        <td>
            <?PHP
            $tab_typectact = [
                '*' => _("Public"),
                $codeuser => _("Privé")];

            $val_seltype = '*';
            if ($cmque_prop <> "*") {
                if (($cmque_prop == $codeuser) OR (@$_SESSION["niv_log"] >= 5))
                    $val_seltype = $codeuser;
            }

            cre_select('prop', 'prop', $tab_typectact, $val_seltype, '', _("-- Faites votre choix --"));
            echo "<br />";
            echo "<span class=\"annot_petit_it\">";
            if (($_SESSION["niv_log"] <> 3) AND ($_SESSION["niv_log"] <> 4))
                echo _("'Privé' signifie que vous seul pourrez voir cette fiche");
            else
                echo _("'Privé' signifie que seule l'agence pourra voir cette fiche");
            echo '<br />' . _("Si vous passez ce contact en 'public', il le restera (sauf modification de l'administrateur)");
            echo "</span>";
            ?>
        </td>
    </tr>
    <tr>
        <td width="160" class="rubfrm" id="f_civil" align="right"><?PHP echo _("Civilité"); ?></td>
        <td>
            <?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', '', $cmque_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 $cmque_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 $cmque_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>
            <?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', '', $cmque_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 $cmque_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 $cmque_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', '', $cmque_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($cmque_codepays);
            cre_select_tab('dep', 'dep', $rows, 'dep_code', 'dep_code', 'dep_nom', $cmque_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($cmque_dep,$cmque_codepays);
            cre_select_tab('ville', 'ville', $rows, 'villes_id', 'villes_nom', 'villes_cp', $cmque_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 $cmque_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 $cmque_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 $cmque_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 $cmque_email ?>" size="50" maxlength="50">
            <?PHP if ($td == "edit") { ?>
                <a href="mailto:<?PHP echo $cmque_email ?>"><img src="../img/mail.png"
                                                                 title="<?PHP echo _("Envoyer e-mail"); ?>" border="0"
                                                                 align="absmiddle"></a>
            <?PHP } ?>
        </td>
    </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 $cmque_mess ?>" size="50" maxlength="50"></td>
    </tr>
    <?PHP if (@$_SESSION["niv_log"] >= 5) {
        ?>
        <tr>
            <td width="160" class="rubfrm" id="f_notaa" align="right"><?PHP echo _("Notes Administration"); ?></td>
            <td><textarea name="notaa" id="notaa"><?PHP echo $cmque_notaa ?></textarea></td>
        </tr>
    <?PHP } ?>
    <tr>
        <td width="160" class="rubfrm" id="f_notat" align="right"><?PHP echo _("Notes publiques Agences"); ?><br /><span
                class="annot_petit_it">(<?PHP echo _("Saisies par l'administrateur ou"); ?>
                <br /><?PHP echo _("le centre de gestion"); ?>)</span></td>
        <td><textarea name="notat" id="notat"><?PHP echo $cmque_notat ?></textarea></td>
    </tr>
    <tr>
        <td width="160" class="rubfrm" id="f_notap">
            <div align="right"><?PHP echo _("Notes Personnelles"); ?><br /><span
                    class="annot_petit_it">(<?PHP echo _("Pour les techniciens ce sont"); ?>
                    <br /><?PHP echo _("celles de leur agence"); ?>)</span></div>
        </td>
        <td>
            <textarea name="notap" rows="5" id="notap"><?PHP echo $cmquen_nota ?></textarea>
            <span class="annot_petit_it"><?PHP echo _("Vous seul pourrez voir ces notes"); ?></span>
        </td>
    </tr>
</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 marques
    $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
    $rech = "SELECT * FROM `" . TBCMQUE . "` WHERE `cmque_codemque` = '" . $codemque . "'";
    switch (@$_SESSION["niv_log"]) {
        case 3 :
        case 4 :
            $rech .= " AND (`cmque_prop` = '*' OR `cmque_prop` = '" . $codeuser . "')";
            break;
        default :
            break;
    }
    $rech .= " ORDER BY 'cmque_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 marques
        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["cmque_nom"] . " " . $row["cmque_prenom"];
            echo "<div class=\"annot_petit_it\" align=\"right\">";
            if ($row["cmque_prop"] == "*")
                echo _("Contact public");
            else {
                echo _("Contact privé");
                if ($row["cmque_prop"] <> $codeuser) echo " (" . $row["cmque_prop"] . ")";
            }
            echo "</div>";
            echo "</td>\n";
            echo "<td>\n";
            $txtfonc = "&nbsp;";
            $rech2 = "SELECT fonc_desc FROM `" . TBFONC . "` WHERE `fonc_code` = '" . $row["cmque_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["cmque_telf"];
            echo "</td>\n";
            echo "<td align=\"center\">\n";
            echo "<a href=\"mailto:" . $row["cmque_email"] . "\">" . $row["cmque_email"] . "</a>";
            echo "</td>\n";

            echo "<td align=\"center\">\n";
            $lst_maj = TRUE;
            cre_falselnk_img('', 'cmque_edit_'.$row["cmque_id"], 'span', 'center', _("Edition"), 'lnk', 'cmque_maj.php?td=edit&cm=' . $row["cmque_codemque"] . '&icm=' . $row["cmque_id"] . '&tx=' . $tx , '../img/edit.png');
            $lst_del = TRUE;
            cre_falselnk_img('', 'cmque_del_'.$row["cmque_id"], 'span', 'center', _("Suppression"), 'lnk', 'cmque_maj.php?td=del&cm=' . $row["cmque_codemque"] . '&icm=' . $row["cmque_id"] . '&tx=' . $tx , '../img/del.png');
            echo "</td>\n";
            echo "</tr>\n";

            $j++;
        }

        echo "</table>\n";
        // Fin affichage table liste contacts marques
        $taille_piedla = "";
        include_once("piedla.inc.php");
        $db->disconnect();
    }
    ?>
    <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
    close_fen_auto('', '');
?>
</body>
</html>
