<?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/func.inc.php");
include_once("../inc/func_geo.inc.php");
include_once("../inc/func_txt.inc.php");
include_once("../inc/fic_age.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 = '';
$idcage = 0;
$pbm_age = FALSE;
$totalcage = 0;
$action_to_do = '';

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 {
    if ($action_to_do <> '')
        $td = @$_POST['td'];
}

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

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

if (isset($_GET['tx']))
    $tx = @$_GET['tx'];
else {
    if (isset($_POST['tx']))
        $tx = @$_POST['tx'];
    else
        $pbm_age = TRUE;
}
if (($td <> "add") AND (($tx == "dosd_cage") OR ($tx == "coloc")))
    $pbm_age = TRUE;

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

        $totalcage = nb_cage_in_age($codeage);
        if ($totalcage == 0)
            $td = "add";
        $retourliste = FALSE;
        if ($action_to_do <> '') {
            $titre = @$_POST["titre"];
            $idcage = @$_POST["ica"];
            $code = @$_POST["ca"];
            $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 `" . TBCAGE . "`";
                    $rech .= " (cage_datecrea,cage_datemod,cage_codeage,cage_codefonc,cage_civilite,cage_prenom,cage_nom,";
                    $rech .= "cage_adr1,cage_adr2,cage_dep,cage_ville,cage_codepays,";
                    $rech .= "cage_telf,cage_fax,cage_telp,cage_email,cage_mess,cage_nota) VALUES";
                    $rech .= " ('$datea','$datea','" . $db->escape($code) . "','" . $db->escape($fonction) . "','" . $db->escape($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" :
                    if (@$_SESSION["niv_log"] >= 5) {
                        $rech = "UPDATE `" . TBCAGE . "` SET `cage_datemod`='" . $datea . "', `cage_codeage`='" . $db->escape($code) . "', `cage_codefonc`='" . $db->escape($fonction) . "',";
                        $rech .= " `cage_civilite`='" . $db->escape($civil) . "', `cage_prenom`='" . $db->escape($prenom) . "', `cage_nom`='" . $db->escape($nom) . "', `cage_telf`='" . $telf . "', ";
                        $rech .= " `cage_adr1`='" . $db->escape($adr1) . "', `cage_adr2`='" . $db->escape($adr2) . "', `cage_dep`='" . $dep . "', `cage_ville`='" . $ville . "', `cage_codepays`='" . $pays . "', ";
                        $rech .= " `cage_fax`='" . $fax . "', `cage_telp`='" . $telp . "', `cage_email`='" . $email . "', `cage_mess`='" . $mess . "', ";
                        $rech .= " `cage_nota`='" . $db->escape($nota) . "'";
                        $rech .= "  WHERE `cage_id` = '" . $idcage . "'";
                    } else {
                        $rech = "UPDATE `" . TBCAGE . "` SET `cage_datemod`='" . $datea . "', `cage_codeage`='" . $db->escape($code) . "', `cage_codefonc`='" . $db->escape($fonction) . "',";
                        $rech .= " `cage_civilite`='" . $db->escape($civil) . "', `cage_prenom`='" . $db->escape($prenom) . "', `cage_nom`='" . $db->escape($nom) . "', `cage_telf`='" . $telf . "', ";
                        $rech .= " `cage_adr1`='" . $db->escape($adr1) . "', `cage_adr2`='" . $db->escape($adr2) . "', `cage_dep`='" . $dep . "', `cage_ville`='" . $ville . "', `cage_codepays`='" . $pays . "', ";
                        $rech .= " `cage_fax`='" . $fax . "', `cage_telp`='" . $telp . "', `cage_email`='" . $email . "', `cage_mess`='" . $db->escape($mess) . "' ";
                        $rech .= "  WHERE `cage_id` = '" . $idcage . "'";
                    }
                    break;
                case "del" :
                    $rech = "DELETE FROM `" . TBCAGE . "` WHERE `cage_id` = '$idcage'";
                    break;
                default :
                    break;
            }
            if ($rech <> "") {
                $db->query($rech);
                $retourliste = TRUE;
            }
            $db->disconnect();
        } else {
            if ($age_ouvert == FALSE)
                $td = "view";
            switch ($td) {
                case "add" :
                    $titre = _("CREATION CONTACT");
                    $cage_adr1 = $age_adr1;
                    $cage_adr2 = $age_adr2;
                    $cage_dep = $age_dep;
                    $cage_ville = $age_ville;
                    $cage_codepays = $age_codepays;
                    $cage_telf = $age_telf;
                    $cage_fax = $age_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_cage_id_in_age($idcage, $codeage);
                    if (is_array($row))
                    {
                        $row = encode_str($row);
                        extract($row);
                    }
                    else
                        $pbm_age = TRUE;
                    break;
                case "lst" :
                    $titre = _("LISTE CONTACTS");
                    break;
                default :
                    $pbm_age = TRUE;
                    break;
            }
        }
        // On recalcule le total contacts
        $totalcage = nb_cage_in_age($codeage);
        if ($totalcage == 0)
            $td="add";
    } else
        $pbm_age = TRUE;
} else
    $pbm_age = 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 Agence"); ?></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_age == FALSE) { ?>
        <script type="text/javascript">
            <!--
            <?PHP
            if ($retourliste == TRUE)
            {
                switch ($tx) {
                    case "coloc" :
                    case "dosd_cage" :
                        cre_sel_ddeurs_age($codeage, 'window.opener.', 'ddeur');
                        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','cage_maj','".$_SESSION['date_fmtshort']."',tab_champ,'','');";
                            break;
                        case "edit" :
                            echo "init_warn('".nb_cagepr($idcage,TRUE)."agespr','','','','');";
                            echo "init_valid_form('enr','cage_maj','".$_SESSION['date_fmtshort']."',tab_champ,'','');";
                            break;
                        case "del" :
                            echo "init_valid_form('del','cage_maj','".$_SESSION['date_fmtshort']."',tab_champ,'','');";
                            echo "warn_del('ope');";
                            echo "readonly_all();";
                            break;
                        case "view" :
                            echo "readonly_all();";
                            break;
                    }
                    echo 'init_ajax_ville();';
                    echo 'init_ajax_dep();';
                    echo "init_fensaisie('edit_pr', 780, 480);";
                    echo "chk_contacts('1', 'ctact', '".$totalcage."');";
                    echo "init_autohref('lst', 'click', 'cage_maj.php?ca=".$codeage."&td=lst&tx=".$tx."',false);";
                    echo "init_autohref('add', 'click', 'cage_maj.php?ca=".$codeage."&td=add&tx=".$tx."',false);";
                    echo "add_func_click('quit', 'sclose', '');";
                    echo "Focus_first();";
                }
                else
                {
                    switch ($tx)
                    {
                        case "age" :
                            echo "self.location.href=('cage_maj.php?cc=".$codeage."&td=lst&tx=".$tx."');";
                            break;
                        case "coloc" :
                        case "dosd_cage" :
                            echo 'update_sel_ddeurs();';
                            echo "self.close();";
                            break;
                        default :
                            break;
                    }
                }
                ?>
            }

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

    <?PHP } ?>
</head>
<body>


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

<p align="center"><span class="titre_gras"><?PHP echo _("Pour l'agence"); ?> : <?php echo $age_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 (($totalcage > 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="cage_maj" id="cage_maj" method="post" action="cage_maj.php">
    <input name="ica" type="hidden" id="ica" value="<?PHP echo $cage_id ?>">
    <input name="ca" type="hidden" id="ca" value="<?PHP echo $codeage ?>">
    <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);
                $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', '', $cage_civilite, '', _("-- Faites votre choix --"));

                if (($td == "edit") AND ((@$_SESSION["niv_log"] == 4) OR (@$_SESSION["niv_log"] == 5) OR (@$_SESSION["niv_log"] == 9))) {
                    $url_cagepr = "cagepr_maj.php?td=add&ca=" . $codeage . "&ica=" . $cage_id;
                    cre_falselnk('', 'edit_pr', 'span', '', _("Prix de revient"), $url_cagepr, '../img/pr.png', _("Prix de revient"));
                }
                ?>
            </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 $cage_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 $cage_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', '', $cage_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 $cage_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 $cage_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
                $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', '', $cage_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
                $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
                $rech = "SELECT * FROM `" . TBDEP . "` WHERE `dep_codepays`='" . $cage_codepays . "' 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', $cage_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
                $rech = "";
                if ($cage_dep <> "") {
                    if ($cage_dep <> "-1") {
                        $filtre = $cage_dep;
                        if (($filtre == "2A") OR ($filtre == "2B"))
                            $filtre = "20";
                        $rech = "SELECT * FROM `" . TBVILLES . "` WHERE `villes_dep` = '" . str_majuscules($filtre) . "' AND `villes_codepays`='" . str_majuscules($cage_codepays) . "' ORDER BY villes_nom";
                    } else {
                        $rech = "SELECT * FROM `" . TBVILLES . "` WHERE `villes_codepays`='" . str_majuscules($cage_codepays) . "' ORDER BY villes_nom";
                    }
                }
                $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
                if ($rech <> "")
                    $rows = $db->get_results($rech, ARRAY_A);
                $db->disconnect();
                cre_select_tab('ville', 'ville', $rows, 'villes_id', 'villes_nom', 'villes_cp', $cage_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 $cage_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 $cage_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 $cage_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 $cage_email ?>" size="50" maxlength="50">
                <?PHP if ($td == "edit") { ?>
                <a href="mailto:<?PHP echo $cage_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 $cage_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 $cage_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 agence
    $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
    $rech = "SELECT * FROM `" . TBCAGE . "` WHERE `cage_codeage` = '" . $db->escape($codeage) . "' ORDER BY 'cage_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["cage_nom"] . " " . $row["cage_prenom"];
            // CREATION d'icône si manque prix de revient
            if (nb_cagepr($row["cage_id"], FALSE) == 0)
                echo ' <img src="../img/warn.png" title ="'._("Manque prix de revient").'" border="0" align="absmiddle">';
            echo "</td>\n";
            echo "<td>\n";
            $txtfonc = "&nbsp;";
            $rech2 = "SELECT fonc_desc FROM `" . TBFONC . "` WHERE `fonc_code` = '" . $row["cage_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["cage_telf"];
            echo "</td>\n";
            echo "<td align=\"center\">\n";
            echo "<a href=\"mailto:" . $row["cage_email"] . "\">" . $row["cage_email"] . "</a>";
            echo "</td>\n";

            echo "<td align=\"center\">\n";
            $lst_maj = TRUE;
            cre_falselnk_img('', 'cage_edit_'.$row["cage_id"], 'span', 'center', _("Edition"), 'lnk', 'cage_maj.php?td=edit&ca=' . $row["cage_codeage"] . '&ica=' . $row["cage_id"] . '&tx=' . $tx , '../img/edit.png');
            $lst_del = TRUE;
            cre_falselnk_img('', 'cage_del_'.$row["cage_id"], 'span', 'center', _("Suppression"), 'lnk', 'cage_maj.php?td=edit&ca=' . $row["cage_codeage"] . '&ica=' . $row["cage_id"] . '&tx=' . $tx , '../img/del.png');
            echo "</td>\n";
            echo "</tr>\n";

            $j++;
        }

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

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