<?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/fic_age.inc.php");
include_once("../inc/fic_cocl.inc.php");
include_once("../inc/fic_droits.inc.php");
include_once("../inc/fic_fici.inc.php");
include_once("../inc/fic_hum.inc.php");
include_once("../inc/fic_loc.inc.php");
include_once("../inc/fic_st.inc.php");
include_once("../inc/fic_zc.inc.php");
include_once("../inc/func.inc.php");
include_once("../inc/func_date.inc.php");
include_once("../inc/func_geo.inc.php");
include_once("../inc/func_geol.inc.php");
include_once("../inc/func_txt.inc.php");
include_once("../classes/geoplugin/geoplugin.class.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);

if (isset($_SESSION['tab_tec_sel']))
    unset($_SESSION['tab_tec_sel']);

$td = @$_GET['td'];
$coderech = @$_GET['code'];
$age_dep = @$_GET['dep'];

if (@$_SESSION["niv_log"] == 4) {
    $coderech = @$_SESSION["code_log"];
    $td = "edit";
}

$nbinterventions = 0;
$nbcontacts = 0;
$pbm_age = FALSE;
$nbcoloc = 0;
$sel_loc = TRUE;
$sel_st = TRUE;
$sel_zc = TRUE;

$age_codeadev = give_dev_codea_defaut($_SESSION["lng"], TRUE);

if ($coderech <> "") {
    // vérification qu'il existe bien des interventions et nombre de celles-ci
    $nbinterventions = nb_int($coderech);

    // Nombre de contacts pour cette agence
    $nbcontacts = nb_cage_in_age($coderech);

    // Récupération des informations agence
    $row = lit_enr_age($coderech, TRUE);
    if (is_array($row)) {
        $row = encode_str($row);
        extract($row);
        $age_codeadev = give_dev_codea_defaut_age($age_code, $_SESSION["lng"]);

        $nbcoloc = nb_coloc_cli($coderech, $_SESSION["niv_log"], "");

        if (($td <> "del") AND ($age_ouvert == FALSE))
            $td = "view";

        if (@$_SESSION["niv_log"] >= 4) {
            if (@$_SESSION["niv_log"] == 4) {
                if ($coderech <> $_SESSION["code_age"])
                    $pbm_age = TRUE;
            }
        } else
            $pbm_age = TRUE;

        if (exist_age_in_coloc($age_code) == TRUE)
            $sel_loc = FALSE;
        if (exist_age_st($age_code) == TRUE)
            $sel_st = FALSE;

    } else
        $pbm_age = TRUE;
} else {
    if ($td <> "add")
        $pbm_age = TRUE;
}

$lst_id_readonly = '';
switch ($td) {
    case "add" :
        $age_ouvert = TRUE;
        $age_codepays = pays_connect_code($_SERVER['REMOTE_ADDR']);
        $titre = _("CREATION AGENCE");
        break;
    case "edit" :
        $titre = _("MISE A JOUR AGENCE");
        break;
    case "del" :
        $titre = _("SUPPRESSION AGENCE");
        break;
    case "view" :
        $titre = _("VISUALISATION AGENCE");
        break;
    default :
        $pbm_age = TRUE;
        break;
}

switch ($_SESSION["niv_log"])
{
    case 4 :
        $lst_id_readonly .= 'nom-rcs-ape-tvai-tcom-adr1-adr2-pays-dep-ville-codeadev';
        $sel_zc = FALSE;
        break;
    case 5 :
    case 9 :
        break;
}

if ($sel_loc == FALSE)
    $lst_id_readonly .= '-loc';

if ($sel_st == FALSE)
    $lst_id_readonly .= '-st';
?>

<!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 _("Fiche Agence"); ?></title>

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

    <script language="javascript">
        <!--
        var tab1_champ = [
            <?PHP
            if (@$_SESSION["niv_log"] >= 5)
                echo '"nom:acat ; format:liste ; req:Y ; txt:'._("Catégorie").'; vmn:1; stok:frmok ; stbad:frmbad",';

            if ($td=="add")
                echo '"nom:code ; format:alphanum ; req:Y ; txt:'._("Code").' ; lmn:1 ; lmx:9; stok:frmok ; stbad:frmbad",';
            ?>
            "nom:nom ; format:txt ; req:Y ; txt:<?PHP echo _("Code"); ?>; lmn:1 ; lmx:50; stok:frmok ; stbad:frmbad",
            "nom:rcs ; format:siret ; req:N ; txt:<?PHP echo _("Siret"); ?> ; lmx:50; stok:frmok ; stbad:frmbad",
            "nom:ape ; format:naf ; req:N ; txt:<?PHP echo _("APE"); ?> ; lmx:10; stok:frmok ; stbad:frmbad",
            "nom:tvai ; format:tva ; req:N ; txt:<?PHP echo _("TVA intra."); ?> ; lmx:50; stok:frmok ; stbad:frmbad",
            "nom:tcom ; format:txt ; req:N ; txt:<?PHP echo _("Tribunal de commerce"); ?>; lmn:1 ; lmx:70; 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 _("Pays"); ?> ; vmn:1; stok:frmok ; stbad:frmbad",
            "nom:pays ; format:liste ; req:Y ; txt:<?PHP echo _("Pays"); ?> ; vmn:1; stok:frmok ; stbad:frmbad",
            <?PHP
            if ((@$_SESSION["niv_log"] == 5) OR (@$_SESSION["niv_log"] == 9))
            {
            ?>
            "nom:ccpta ; format:txt ; req:N ; txt:<?PHP echo _("Code compta"); ?>; lmx:15 ; stok:frmok ; stbad:frmbad",
            <?PHP
            }
            ?>
            "nom:codeadev ; format:liste ; req:Y ; txt:<?PHP echo _("Devise"); ?> ; vmn:1; stok:frmok ; stbad:frmbad",
            "nom:telf ; format:tel ; req:Y ; txt:<?PHP echo _("Téléphone Fixe"); ?>; stok:frmok ; stbad:frmbad",
            "nom:txttelf ; format:txt ; req:N ; txt:<?PHP echo _("Commentaire téléphone fixe"); ?>; lmx:100 ; stok:frmok ; stbad:frmbad",
            "nom:fax ; format:tel ; req:Y ; txt:<?PHP echo _("Télécopieur"); ?>; stok:frmok ; stbad:frmbad",
            "nom:txtfax ; format:txt ; req:N ; txt:<?PHP echo _("Commentaire télécopieur"); ?>; lmx:100 ; stok:frmok ; stbad:frmbad",
            "nom:web ; format:url_npref ; req:N ; txt:<?PHP echo _("Adresse site web"); ?>; lmx:200; stok:frmok ; stbad:frmbad",
            "nom:heures ; format:txt ; req:Y ; txt:<?PHP echo _("Horaires"); ?>; lmx:200; stok:frmok ; stbad:frmbad",
            "nom:txtent ; format:txt ; req:N ; txt:<?PHP echo _("Texte d'entête"); ?>; stok:frmok ; stbad:frmbad",
            "nom:rcivil ; format:liste ; req:Y ; txt:<?PHP echo _("Civilité responsable d'agence"); ?> ; vmn:1; stok:frmok ; stbad:frmbad",
            "nom:rprenom ; format:txt ; req:Y ; txt:<?PHP echo _("Prénom responsable d'agence"); ?> ; lmn:1; lmx:50; stok:frmok ; stbad:frmbad",
            "nom:rnom ; format:txt ; req:Y ; txt:<?PHP echo _("Nom responsable d'agence"); ?>; lmn:1; lmx:50; stok:frmok ; stbad:frmbad",
            "nom:rtelf ; format:tel ; req:Y ; txt:<?PHP echo _("N° tel fixe responsable d'agence"); ?>; stok:frmok ; stbad:frmbad",
            "nom:rtelp ; format:telp ; req:N ; txt:<?PHP echo _("N° tel portable responsable d'agence"); ?>; stok:frmok ; stbad:frmbad",
            "nom:email ; format:mail ; req:Y ; txt:<?PHP echo _("Email")." "._("Général"); ?> ; lmx:50; stok:frmok ; stbad:frmbad",
            "nom:emaild ; format:mail ; req:Y ; txt:<?PHP echo _("Email")." "._("Direction"); ?> ; lmx:50; stok:frmok ; stbad:frmbad",
            "nom:emailc ; format:mail ; req:Y ; txt:<?PHP echo _("Email")." "._("Comptabilité"); ?> ; lmx:50; 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:emailt ; format:mail ; req:Y ; txt:<?PHP echo _("Email")." "._("Technique"); ?> ; lmx:50; stok:frmok ; stbad:frmbad"];
        //-->
    </script>

    <?PHP if ($pbm_age == FALSE) { ?>

        <script type="text/javascript">
            <!--
            $(function () {
                $('.nyroModal').nyroModal();
            });
            //-->
        </script>

        <script type="text/javascript">
            <!--
            $(function () {
                $("#code").Setcase({caseValue: 'upper', changeonFocusout: true});
                $("#nom").Setcase({caseValue: 'upper', changeonFocusout: true});
                $("#rcs").Setcase({caseValue: 'upper', changeonFocusout: true});
                $("#ape").Setcase({caseValue: 'upper', changeonFocusout: true});
                $("#tvai").Setcase({caseValue: 'upper', changeonFocusout: true});
                $("#tcom").Setcase({caseValue: 'upper', changeonFocusout: true});
                $("#adr1").Setcase({caseValue: 'upper', changeonFocusout: true});
                $("#adr2").Setcase({caseValue: 'upper', changeonFocusout: true});
                $("#rnom").Setcase({caseValue: 'upper', changeonFocusout: true});
                $("#email").Setcase({caseValue: 'lower', changeonFocusout: true});
                $("#emaild").Setcase({caseValue: 'lower', changeonFocusout: true});
                $("#emailc").Setcase({caseValue: 'lower', changeonFocusout: true});
                $("#emailt").Setcase({caseValue: 'lower', changeonFocusout: true});
                $("#rprenom").Setcase({caseValue: 'pascal', changeonFocusout: true});
            });

            function init_all() {
                init_Body();
                <?php
                switch ($td)
                {
                    case "add" :
                        echo "$('#ouverture').hide();";
                        echo "init_valid_form('enr','age_maj','".$_SESSION['date_fmtshort']."',tab1_champ,'pays','');";
                        break;
                    case "edit" :
                        echo "$('#ouverture').show();";
                        echo "init_warn('".nb_agepr($coderech,TRUE)."agepr','','','','');";
                        echo "chk_contacts('0','ctact','".$nbcontacts."');";
                        echo "init_new_fen('etats','impression');";
                        echo "init_valid_form('enr','age_maj','".$_SESSION['date_fmtshort']."',tab1_champ,'pays','');";
                        break;
                    case "view" :
                        echo "$('#ouverture').show();";
                        echo "chk_contacts('0','ctact','".$nbcontacts."');";
                        echo "init_new_fen('etats','impression');";
                        echo "readonly_all();";
                        break;
                    case "del" :
                        echo "$('#ouverture').show();";
                        echo "chk_contacts('0','ctact','".$nbcontacts."');";
                        echo "warn_del('age');";
                        echo "readonly_all();";
                        break;
                }
                if ($sel_zc == FALSE)
                    echo "readonly_all_id('age_zc');";
                ?>
                readonly_id('<?PHP echo $lst_id_readonly; ?>',false);
                $( "#onglets_age" ).tabs();
                init_ajax_ville();
                init_ajax_dep();
                init_ajax_depzc();
                init_ajax_add_depzc();
                init_ajax_del_depzc();
                init_fensaisie('add_cage', 950, 560);
                init_fensaisie('edit_cage', 950, 560);
                init_fensaisie('edit_pla', 1020, 760);
                init_fensaisie('edit_pr', 800, 500);
                init_autohref('repage', 'click', '', true);
                init_autohref('add_coloc', 'click', '', true);
                init_autohref('view_coloc', 'click', '', true);
                init_back('annul', 'click');
                Focus_first();
            }

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

<?PHP
include_once("../inc/entete.inc.php");
?>
<p align="center"><span class="titrepage"><?PHP echo $titre ?></span></p>
<!-- affiché uniquement s'il y a au moins une catégorie agence et au moins une civilité -->
<?PHP
if ($pbm_age == FALSE) {
    if ((nb_acat() <> 0) AND (nb_civ() <> 0)) {
        ?>
        <table width="100%" border="0">
            <tr>
                <td width="33%">
                    <?PHP if (@$_SESSION["niv_log"] >= 5)
                        aff_lnk_lst_rech('age_lst.php', _("Retour à la liste"), $_SERVER['HTTP_REFERER'], _("Retour à la page précédente"));
                    else
                        echo "&nbsp;";
                    ?>
                </td>
                <td width="33%">&nbsp;</td>
                <td width="33%" align="right">
                    <?PHP
                    switch ($td) {
                        case "edit" :
                        case "view" :
                            echo '<select name="etats" size="1" id="etats" class="annot_petit">';
                            echo '<option value="" selected>'._("-- Etats --").'</option>';
                            $urlimp = "age_maji.php?ca=" . $coderech;
                            if (url_ok($urlimp) == TRUE)
                                echo "<option value=\"" . $urlimp . "\"  class=\"icone\" style=\"background-image: url(../img/sel_fiche.gif);\">"._("Fiche Agence")."</option>\n";

                            if ($nbinterventions <> 0) {
                                echo "<optgroup label=\""._("Interventions")."\" class=\"icone\" style=\"background-image: url(../img/sel_int.gif);\">\n";
                                if ((@$_SESSION["niv_log"] == 5) OR (@$_SESSION["niv_log"] == 9))
                                    $url_inter = "int_lsti.php?ord=DES&tri=Code&search=" . $age_code . "&rech=Rechercher";
                                else
                                    $url_inter = "int_lsti.php?ord=DES&tri=Code";
                                echo "<option value=\"" . $url_inter . "\">"._("Liste")."</option>\n";
                                echo "</optgroup>\n";
                            }

                            if (nb_cocl($age_code) <> 0) {
                                echo "<optgroup label=\""._("Contrats")."\" class=\"icone\" style=\"background-image: url(../img/sel_con.gif);\">\n";
                                if ((@$_SESSION["niv_log"] == 5) OR (@$_SESSION["niv_log"] == 9))
                                    $url_cocl = "cocl_lsti.php?ord=DES&tri=Code&search=" . $age_code . "&rech=Rechercher";
                                else
                                    $url_cocl = "cocl_lsti.php?ord=DES&tri=Code";
                                echo "<option value=\"" . $url_cocl . "\">"._("Liste")."</option>\n";
                                echo "</optgroup>\n";
                            }
                            echo '</select>';
                            break;
                        default :
                            echo '&nbsp;';
                            break;
                    }
                    ?>
                </td>
            </tr>
            <tr>
                <td width="33%">
                    <?PHP
                    if ($td == "edit") {
                        $url_cage = "cage_maj.php?td=add&ca=" . $age_code . "&tx=age";
                        cre_falselnk('', 'add_cage', 'span', '', _("Ajouter un contact"), $url_cage, '../img/ctacts.png', _("Ajouter un contact"));
                        $url_cage = "cage_maj.php?td=lst&ca=" . $age_code . "&tx=age";
                        echo '<span id="ctact"';
                        if ($nbcontacts == 0)
                            echo ' style="display:none"';
                        else
                            echo ' style="display:inline"';
                        echo '>';
                        cre_falselnk('', 'edit_cage', 'span', '', _("Edition contacts"), $url_cage, '', _("Editions contacts"),true);
                        echo '</span>';
                    } else
                        echo '&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%">&nbsp;</td>
            </tr>
            <tr>
                <td width="33%">
                    <?PHP
                    if ($td == "edit") {
                        $url_repage = "fic_down.php?dir=agences/" . strtolower($age_code);
                        cre_falselnk('', 'repage', 'div', '', _("Aller dans le répertoire privé"), $url_repage, '../img/rep_priv.png', _("Aller dans le répertoire privé"));
                    } else
                        echo '&nbsp;';
                    ?>
                </td>
                <td width="33%" align="center">
                    <?PHP
                    if (($td == "edit") AND (@$_SESSION["niv_log"] >= 5)) {
                        $url_addcoloc = "coloc_maj.php?td=add&tc=1&cc=" . $age_code . "&ca=";
                        cre_falselnk('', 'add_coloc', 'span', '', _("Saisir contrat location"), $url_addcoloc, '../img/coloc.png', _("Saisir contrat location"));
                        if ($nbcoloc <> 0) {
                            $url_coloc = "coloc_lst.php?ord=DES&tri=Code&search=" . $age_code . "&rech=Rechercher";
                            $texte = _("Voir contrats location") . ' (' . sprintf("%'03s", $nbcoloc);
                            cre_falselnk('', 'view_coloc', 'span', '', '', $url_coloc, '', $texte, TRUE);
                        }
                    } else
                        echo '&nbsp;';
                    ?>
                </td>
                <td width="33%" align="right">&nbsp;</td>
            </tr>
        </table>

        <!-- Formulaire de saisie de la fiche -->
        <form name="age_maj" id="age_maj" method="post" action="age_enr.php">
        <input name="titre" type="hidden" id="titre" value="<?PHP echo $titre ?>">
        <input name="td" type="hidden" id="td" value="<?PHP echo $td ?>">
        <?PHP if ($td == "add") { ?>
            <input name="ouvert" type="hidden" id="ouvert" value="1">
        <?PHP } ?>
        <input name="nbutton" type="hidden" id="nbutton" value="">
        <div id="onglets_age">
            <ul>
                <li><a href="#age_coord"><?PHP echo _("Coordonnées"); ?></a></li>
                <li><a href="#age_contacts"><?PHP echo _("Contacts"); ?></a></li>
                <li><a href="#age_zc"><?PHP echo _("Zone Chalandise"); ?></a></li>
                <li><a href="#age_div"><?PHP echo _("Divers"); ?></a></li>
            </ul>
            <div id="age_coord">
                <!-- Ouverture (avec dates) de l'agence -->
                <?PHP if (@$_SESSION["niv_log"] >= 5) { ?>
                    <div id="ouverture" style="display: none;">
                    <table width="100%" border="0">
                        <tr>
                            <td width="160" class="rubfrm" id="f_ouvert"
                                align="right"><?PHP echo _("Agence Ouverte"); ?></td>
                            <td>
                                <?PHP
                                cre_select('ouvert', 'ouvert', $non_oui, intval($age_ouvert));
                                echo "<span class=\"annot_petit_it\">";
                                if ($age_ouvert == TRUE) {
                                    echo "  " . _("(Depuis le") . " : " . datetolocal($age_datecrea) . ")";
                                    echo "<br />";
                                    echo _("Le fait de fermer cette agence implique le licenciement des techniciens y travaillant") . "<br />";
                                    echo _("Faites si besoin les modifications sur les fiches techniciens AVANT de fermer l'agence");
                                } else
                                    echo "  (" . _("Ouverte le") . " : " . datetolocal($age_datecrea) . ", " . _("fermée le") . " : " . datetolocal($age_datec) . ")";
                                echo "</span>";
                                ?>
                            </td>
                            <td align="right" valign="top">
                                <?PHP
                                $url_img_logo = $chemin_logos . "/log" . strtolower($age_code) . ".png";
                                if (exist_logo($age_code)) {
                                    echo '<a href="' . $url_img_logo . '" class="nyroModal" title="' . _("Logo Agence") . ' (' . $age_code . ')">';
                                    echo '<img src="../img/vlogo.png" border="0" align="absmiddle"> ' . _("Voir le logo");
                                    echo '</a>';
                                } else {
                                    echo '<div class="annot_petit_it">';
                                    echo _("Pas de logo pour cette agence");
                                    echo '<br />(<a href="logo_maj.php?td=age">' . _("Configurer") . '</a>)';
                                    echo '</div>';
                                }
                                ?>
                            </td>
                        </tr>
                    </table>
                    </div>
                    <table width="100%" border="0">
                        <tr>
                            <td width="160" class="rubfrm" id="f_acat" align="right"><?PHP echo _("Catégorie"); ?></td>
                            <td>
                                <?PHP
                                $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
                                $rech = "SELECT * FROM `" . TBACAT . "` ORDER BY acat_desc";
                                $rows = $db->get_results($rech, ARRAY_A);
                                $db->disconnect();
                                cre_select_tab('acat', 'acat', $rows, 'acat_code', 'acat_desc', '', $age_cat, '', _("-- Faites votre choix --"));
                                ?>
                            </td>
                        </tr>
                    </table>
                    <?PHP
                }
                ?>

                <!-- Fiche principale -->
                <table width="100%" border="0">
                <tr>
                    <td width="160" class="rubfrm" id="f_code" align="right"><?PHP echo _("Code"); ?></td>
                    <td>
                        <?PHP
                        if ($td == "add") {
                            echo '<strong>A</strong>';
                            echo '<input name="code" type="text" id="code" value="' . $age_code . '" size="9" maxlength="9">';
                            echo ' <img src="../img/oblig.png" align="absmiddle" alt="' . _("Champ obligatoire") . '">';
                        } else {
                            echo '<input name="code" type="text" id="code" value="' . $age_code . '" size="10" maxlength="10" readonly="1">';
                            if (((@$_SESSION["niv_log"] == 4) OR (@$_SESSION["niv_log"] == 5) OR (@$_SESSION["niv_log"] == 9)) AND (($td == "edit") OR ($td == "view"))) {
                                // On vérifie si le module planning est bien en place
                                if ($mod_planning == TRUE) {
                                    $url_planning = 'plan_maj.php?typ=typd&coded=' . $age_code . '&typr=-1&tx=age&from=age';
                                    echo '<a href="' . $url_planning . '" id="edit_pla" title="' . _("Planning") . '"><img src="../img/planning.png" border="0" align="top" title="'._("Planning / Agenda").'"> ' . _("Planning") . '</a>';
                                }
                            }
                        }
                        ?>
                    </td>
                </tr>
                <tr>
                    <td width="160" class="rubfrm" id="f_nom" align="right"><?PHP echo _("Nom"); ?></td>
                    <td>
                        <?PHP
                        echo '<input name="nom" type="text" id="nom" value="' . $age_nom . '" size="50">';
                        echo ' <img src="../img/oblig.png" align="absmiddle" alt="' . _("Champ obligatoire") . '">';
                        ?>
                    </td>
                </tr>
                <tr>
                    <td class="rubfrm" id="f_rcs" align="right"><?PHP echo _("Siret"); ?></td>
                    <td>
                        <?PHP
                        echo '<input name="rcs" type="text" id="rcs" value="' . $age_rcs . '" size="50">';
                        ?>
                    </td>
                </tr>
                <tr>
                    <td class="rubfrm" id="f_ape" align="right"><?PHP echo _("APE"); ?></td>
                    <td>
                        <?PHP
                        echo '<input name="ape" type="text" id="ape" value="' . $age_ape . '" size="10">';
                        ?>
                    </td>
                </tr>
                <tr>
                    <td class="rubfrm" id="f_tvai" align="right"><?PHP echo _("TVA intra."); ?></td>
                    <td>
                        <?PHP
                        echo '<input name="tvai" type="text" id="tvai" value="' . $age_tvai . '" size="50">';
                        ?>
                    </td>
                </tr>
                <tr>
                    <td class="rubfrm" id="f_tcom" align="right"><?PHP echo _("Tribunal com."); ?></td>
                    <td>
                        <?PHP
                        echo '<input name="tcom" type="text" id="tcom" value="' . $age_tcom . '" size="70">';
                        echo ' <img src="../img/oblig.png" align="absmiddle" alt="' . _("Champ obligatoire") . '">';
                        ?>
                    </td>
                </tr>
                <tr>
                    <td width="160" class="rubfrm" id="f_adr1" align="right"><?PHP echo _("Adresse"); ?></td>
                    <td>
                        <?PHP
                        echo '<input name="adr1" type="text" id="adr1" value="' . $age_adr1 . '" size="50">';
                        echo ' <img src="../img/oblig.png" align="absmiddle" alt="' . _("Champ obligatoire") . '">';
                        ?>
                    </td>
                </tr>
                <tr>
                    <td width="160" class="rubfrm" id="f_adr2" align="right"><?PHP echo _("Adresse (2)"); ?></td>
                    <td>
                        <?PHP
                        echo '<input name="adr2" type="text" id="adr2" value="' . $age_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', '', $age_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($age_codepays);
                        cre_select_tab('dep', 'dep', $rows, 'dep_code', 'dep_code', 'dep_nom', $age_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($age_dep,$age_codepays);
                        cre_select_tab('ville', 'ville', $rows, 'villes_id', 'villes_nom', 'villes_cp', $age_ville, '', _("-- Faites votre choix --"), 1, FALSE, '-1', _("-- Inconnu --"));
                        ?>
                    </td>
                </tr>
                <tr>
                    <td class="rubfrm" id="f_codeadev" align="right"><?PHP echo _("Devise"); ?></td>
                    <td>
                        <?PHP
                        // Création de la liste des devises
                        $rows = give_rows_devises();
                        cre_select_tab('codeadev', 'codeadev', $rows, 'dev_codea', 'dev_nom', 'dev_codea', $age_codeadev, '', _("-- Faites votre choix --"));
                        ?>
                    </td>
                </tr>
                <tr>
                    <td width="160" class="rubfrm" id="f_telf" align="right">
                        <?PHP echo _("Téléphone Fixe"); ?><br />
                        (<?PHP echo _("Commentaire"); ?>)
                </td>
                <td>
                    <input name="telf" type="text" id="telf" value="<?PHP echo $age_telf ?>" size="20" maxlength="20">
                    <img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo _("Champ obligatoire"); ?>"><br />
                    <input name="txttelf" type="text" id="txttelf" value="<?PHP echo $age_txttelf ?>" size="100">
                </td>
                </tr>
                <tr>
                    <td width="160" class="rubfrm" id="f_fax" align="right">
                        <?PHP echo _("Télécopieur"); ?><br />
                        (<?PHP echo _("Commentaire"); ?>)
                    </td>
                    <td>
                        <input name="fax" type="text" id="fax" value="<?PHP echo $age_fax ?>" size="20" maxlength="20">
                        <img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo _("Champ obligatoire"); ?>"><br />
                        <input name="txtfax" type="text" id="txtfax" value="<?PHP echo $age_txtfax ?>" size="100">
                    </td>
                </tr>
                <tr>
                    <td class="rubfrm" id="f_web" align="right"><?PHP echo _("Site Web"); ?><span
                            class="annot_petit_it">(<?PHP echo _("Sans préfixe"); ?>)</span></td>
                    <td>
                        <input name="web" type="text" id="web" value="<?PHP echo $age_web ?>" size="80" maxlength="200">
                    </td>
                </tr>
                <tr>
                    <td class="rubfrm" id="f_heures" align="right"><?PHP echo _("Horaires"); ?></td>
                    <td>
                        <input name="heures" type="text" id="heures" value="<?PHP echo $age_heures ?>" size="80">
                        <img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo _("Champ obligatoire"); ?>">
                    </td>
                </tr>
                <tr>
                    <td class="rubfrm" id="f_com" align="right"><?PHP echo _("Texte d'entête"); ?></td>
                    <td><textarea name="txtent" id="txtent"><?PHP echo $age_txtent ?></textarea></td>
                </tr>
                </table>
            </div>

            <div id="age_contacts">
                <table width="100%" border="0">
                    <tr>
                        <td colspan="2" class="rubfrm" id="f_web" align="center">
                            <?PHP echo _("Responsable d'agence"); ?>
                            <?PHP
                            if ($td == "edit") {
                                $url_agepr = "agepr_maj.php?td=add&ca=" . $age_code;
                                echo '<a href="' . $url_agepr . '" id="edit_pr" title="' . _("Prix de revient") . '"><img src="../img/pr.png" border="0" align="top" title="' . _("Prix de revient") . '"></a>';
                            }
                            ?>
                        </td>
                    </tr>
                    <tr>
                        <td class="rubfrm" id="f_rcivil" 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('rcivil', 'rcivil', $rows, 'civ_code', 'civ_desc', '', $age_resp_civilite, '', _("-- Faites votre choix --"));
                            ?>
                        </td>
                    </tr>
                    <tr>
                        <td class="rubfrm" id="f_rprenom" align="right"><?PHP echo _("Prénom"); ?></td>
                        <td>
                            <input name="rprenom" type="text" id="rprenom" value="<?PHP echo $age_resp_prenom ?>" size="50">
                            <img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo _("Champ obligatoire"); ?>">
                        </td>
                    </tr>
                    <tr>
                        <td class="rubfrm" id="f_rnom" align="right"><?PHP echo _("Nom"); ?></td>
                        <td>
                            <input name="rnom" type="text" id="rnom" value="<?PHP echo $age_resp_nom ?>" size="50">
                            <img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo _("Champ obligatoire"); ?>">
                        </td>
                    </tr>
                    <tr>
                        <td class="rubfrm" id="f_rtelf" align="right"><?PHP echo _("Téléphone Fixe"); ?></td>
                        <td>
                            <input name="rtelf" type="text" id="rtelf" value="<?PHP echo $age_resp_telf ?>" size="20"
                                   maxlength="20">
                            <img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo _("Champ obligatoire"); ?>">
                        </td>
                    </tr>
                    <tr>
                        <td class="rubfrm" id="f_rtelp" align="right"><?PHP echo _("Téléphone portable"); ?></td>
                        <td>
                            <input name="rtelp" type="text" id="rtelp" value="<?PHP echo $age_resp_telp ?>" size="20" maxlength="20">
                        </td>
                    </tr>
                    <tr>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                    </tr>
                    <tr>
                        <td colspan="2" class="rubfrm" align="center"><?PHP echo _("Emails"); ?></td>
                    </tr>
                    <tr>
                        <td width="160" class="rubfrm" id="f_email" align="right"><?PHP echo _("Général"); ?></td>
                        <td>
                            <input name="email" type="text" id="email" value="<?PHP echo $age_email ?>" size="50" maxlength="50">
                            <?PHP if ($td == "edit") { ?>
                                <a href="mailto:<?PHP echo $age_email ?>"><img src="../img/mail.png"
                                                                               title="<?PHP echo _("Envoyer e-mail"); ?>"
                                                                               border="0" align="absmiddle"></a>
                            <?PHP } ?>
                            <img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo _("Champ obligatoire"); ?>"> <span
                                class="annot_std_it">(<?PHP echo _("Pour contacts clients"); ?>)</span>
                        </td>
                    </tr>
                    <tr>
                        <td width="160" class="rubfrm" id="f_emaild" align="right"><?PHP echo _("Direction"); ?></td>
                        <td>
                            <input name="emaild" type="text" id="emaild" value="<?PHP echo $age_emaild ?>" size="50"
                                   maxlength="50">
                            <?PHP if ($td == "edit") { ?>
                                <a href="mailto:<?PHP echo $age_emaild ?>"><img src="../img/mail.png"
                                                                                title="<?PHP echo _("Envoyer e-mail"); ?>"
                                                                                border="0" align="absmiddle"></a>
                            <?PHP } ?>
                            <img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo _("Champ obligatoire"); ?>">
                        </td>
                    </tr>
                    <tr>
                        <td width="160" class="rubfrm" id="f_emailc" align="right"><?PHP echo _("Comptabilité"); ?></td>
                        <td>
                            <input name="emailc" type="text" id="emailc" value="<?PHP echo $age_emailc ?>" size="50"
                                   maxlength="50">
                            <?PHP if ($td == "edit") { ?>
                                <a href="mailto:<?PHP echo $age_emailc ?>"><img src="../img/mail.png"
                                                                                title="<?PHP echo _("Envoyer e-mail"); ?>"
                                                                                border="0" align="absmiddle"></a>
                            <?PHP } ?>
                            <img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo _("Champ obligatoire"); ?>">
                        </td>
                    </tr>
                    <tr>
                        <td width="160" class="rubfrm" id="f_emailt" align="right"><?PHP echo _("Technique"); ?></td>
                        <td>
                            <input name="emailt" type="text" id="emailt" value="<?PHP echo $age_emailt ?>" size="50"
                                   maxlength="50">
                            <?PHP if ($td == "edit") { ?>
                                <a href="mailto:<?PHP echo $age_emailt ?>"><img src="../img/mail.png"
                                                                                title="<?PHP echo _("Envoyer e-mail"); ?>"
                                                                                border="0" align="absmiddle"></a>
                            <?PHP } ?>
                            <img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo _("Champ obligatoire"); ?>">
                        </td>
                    </tr>
                </table>
            </div>

            <div id="age_zc">
                <table width="100%" border="0">
                    <tr>
                        <td colspan="3" align="center">
                            <?PHP
                            echo '<div class="annot_std_gras">'._("Pays") . '<div>';
                            // 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('payszc', 'payszc', $rows, 'pays_code', 'pays_nom', '', '', '',_("-- Faites votre choix --"));
                            ?>
                        </td>
                    </tr>
                    <tr>
                        <td align="center" width="40%">
                            <?PHP
                            echo '<div class="annot_std_gras">'._("Départements à choisir") . '<div>';
                            $tab_vide = [];
                            cre_select('depzc', 'depzc', $tab_vide, '', '', _("-- Faites votre choix --"), 10, TRUE);
                            ?>
                        </td>

                        <td align="center" width="20%">
                            <?PHP
                                if ($sel_zc == TRUE)
                                {
                                    echo '<input type="button" id="addzc" class="bton_std" value="'._("Ajouter").'>>>">';
                                    echo '<br />';
                                    echo '<br />';
                                    echo '<input type="button" id="delzc" class="bton_std" value="&lt;&lt;&lt; '._("Supprimer").'">';
                                }
                                else
                                    echo "&nbsp;";
                            ?>
                        </td>
                        <td align="center">
                            <?PHP
                            echo '<div class="annot_std_gras">'._("Départements couverts") . '<div>';
                            // On crée le tableau des Départements couverts
                            $tab_zone = tab_zcc_age_open_full($age_code, TRUE);
                            $_SESSION['txtzc'] = str_zcc_age_open($age_code, TRUE);
                            cre_select('zone[]', 'zone', $tab_zone, '', '', '', 10,TRUE);
                            ?>
                        </td>
                    </tr>
                </table>
            </div>

            <div id="age_div">
                <table width="100%" border="0">
                    <tr>
                        <td width="160" class="rubfrm" id="f_nota" align="right"><?PHP echo _("Notes"); ?></td>
                        <td><textarea name="nota" id="nota"><?PHP echo $age_nota ?></textarea></td>
                    </tr>
                </table>

                <?PHP
                if (@$_SESSION["niv_log"] >= 5) {
                    ?>
                    <table width="100%" border="0">
                        <tr>
                            <td width="160" class="rubfrm" id="f_ccpta" align="right"><?PHP echo _("Code compta"); ?></td>
                            <td>
                                <input name="ccpta" type="text" id="ccpta" value="<?PHP echo $age_ccpta; ?>">
                            </td>
                        </tr>
                        <tr>
                            <td width="160" class="rubfrm" id="f_factures"
                                align="right"><?PHP echo _("Emet ses factures"); ?></td>
                            <td>
                                <?PHP
                                cre_select('factures', 'factures', $non_oui, $age_fact);
                                ?>
                                <br /><span
                                    class="annot_petit_it"><?PHP echo _("'Non' : Le centre de gestion sera prévenu pour facturer"); ?></span>
                            </td>
                            <td width="160" class="rubfrm" id="f_dloc"
                                align="right"><?PHP echo _("Location / Prêt"); ?></td>
                            <td>
                                <?PHP
                                cre_select('loc', 'loc', $non_oui, $age_loc);
                                ?>
                                <br /><span
                                    class="annot_petit_it"><?PHP echo _("'Oui' : L'agence loue ou prête du matériel"); ?></span>
                            </td>
                        </tr>
                        <tr>
                            <td width="160" class="rubfrm" id="f_st" align="right"><?PHP echo _("Sous-traitant ?"); ?></td>
                            <td>
                                <?PHP
                                cre_select('st', 'st', $non_oui, intval($sel_st == FALSE));

                                if ($sel_st == FALSE) {
                                    $row = lit_enr_stage($age_code);
                                    if (is_array($row)) {
                                        $row = encode_str($row);
                                        extract($row);
                                        echo "<span class=\"annot_petit_it\">";
                                        echo " " . _("Rattachée au sous-traitant") . "  " . $st_code;
                                        echo " <a href=\"st_maj.php?td=edit&code=" . $st_code . "&dep=" . $st_dep . "\"><img src=\"../img/edit.png\" border=\"0\" align=\"absmiddle\"></a>";
                                        echo "</span>";
                                    }
                                }
                                ?>
                                <br /><span
                                    class="annot_petit_it"><?PHP echo _("'Oui' : L'agence est aussi sous-traitant"); ?></span>
                            </td>
                        </tr>
                    </table>
                <?PHP
                }
                ?>
            </div>

        </div>

        <p align="center">
            <?PHP
            switch ($td)
            {
                case "add" :
                case "edit" :
                    if ($nu <> -1)
                        echo '<input name="enr" type="button" class="bton_std" id="enr" value="'._("Enregistrer").'">';
                    else
                        echo '<input name="enr" type="button" class="bton_std" id="enr" value="'._("Valider").'">';
                    echo ' <input name="RAZ" type="reset" class="bton_std" id="RAZ" value="'._("Réinitialiser").'">';
                    break;
                case "del" :
                    echo '<input name="del" type="submit" class="bton_std" id="del" value="'._("Supprimer").'">';
                    echo '<input name="annul" type="button" class="bton_std" id="annul" value="'._("Annuler").'">';
                    break;
            }
            ?>
        </p>
        </form>
        <!-- Fin affiché uniquement s'il y a au moins une catégorie agence et au moins une civilité -->
    <?PHP
    } else {
        if (nb_acat() == 0)
            pop_ret_auto(_("Aucune catégorie agence"), 'warn', "acat_lst.php");

        if (nb_civ() == 0)
            pop_ret_auto(_("Aucune civilité"), 'warn', "acat_lst.php");
    }
} else
    pop_ret_auto(_("Problème de paramètres"), 'warn', "index.php");
include_once("pied.php");
?>
</body>
</html>