<?php
/****************************************************************************************
 * SMI (Services Maintenance Interventions) est une gestion libre de maintenance et de SAV
 *
 * Version 1.0.4
 *
 * Copyright (C) 2006-2016  Sylvain FATOME
 * This program is free software; you can redistribute it and/or modify it under the terms
 * of the GNU General Public License as published by the Free Software Foundation;
 * either version 2 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with this program
 * (in the directory docs);
 * if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA  02110-1301, USA.
 *
 * Contact : galawa@free.fr
 *
 * Web : http://smi.no-ip.org
 ****************************************************************************************/


// vérification des tentatives de hack
$pos = strpos($_SERVER['PHP_SELF'], 'inc.php');
$ok_inc = FALSE;
if ($pos === FALSE) {
    $ok_inc = TRUE;
}
if ($ok_inc == FALSE) {
    header('Location: ../index.php');
}


include_once('../inc/config.inc.php');
include_once('../inc/fic_age.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_prm.inc.php');
include_once('../inc/fic_st.inc.php');
include_once('../inc/fic_zoc.inc.php');
include_once('../inc/func.inc.php');
include_once('../inc/func_date.inc.php');
include_once('../inc/func_log.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(valsession('code_log'));
// Variables Formulaire
fix_magic_quotes();
$_GET = clean_str($_GET);

$td = valget('td');
$coderech = valget('code');
$st_dep = valget('dep');

if (CheckNivLog('10')) {
    $coderech = valsession('code_log');
    $td = 'edit';
}

if (CheckNivLog('3-4')) {
    $td = 'view';
}

$nbordres = 0;
$pbm_st = FALSE;
$pbm_zoc = FALSE;
$pbm_sp = FALSE;
$nbcoloc = 0;
$nbciv = nb_civ();

$st_codeadev = give_dev_codea_defaut($_SESSION['lng'], TRUE);

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

    // Récupération des informations sous-traitant
    $row = lit_enr_st($coderech);
    if (is_array($row)) {
        $row = encode_str($row);
        extract($row);
        $st_codeadev = give_dev_codea_defaut_st($st_code, $_SESSION['lng']);

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

        // vérification qu'il existe bien des contacts et nombre de ceux-ci
        $nbcontacts = nb_cst_in_st($coderech);

        if (($td <> 'del') AND ($st_ouvert == FALSE)) {
            $td = 'view';
        }

        if (valsession('niv_log') >= 3) {
            if (CheckNivLog('10')) {
                if ($coderech <> $_SESSION['code_st']) {
                    $pbm_st = TRUE;
                }
            }
        } else {
            $pbm_st = TRUE;
        }

        if(nb_zoc_st($coderech) == 0) {
            $pbm_zoc = TRUE;
        }

        if(nb_sp_st($coderech) == 0) {
            $pbm_sp = TRUE;
        }

    } else {
        $pbm_st = TRUE;
    }
} else {
    if ($td == 'add') {
        $st_ouvert = TRUE;
        $st_codepays = pays_connect_code($_SERVER['REMOTE_ADDR']);
    } else {
        $pbm_st = TRUE;
    }
}

$lst_chp_readonly = '';
if ((valsession('niv_log') <> 5) AND (valsession('niv_log') <> 9)) {
    $lst_chp_readonly = 'nom-rcs-ape-tvai-tcom-adr1-adr2-zone';
}
if ($st_ouvert == FALSE) {
    $lst_chp_readonly .= '-pays-dep-ville';
}

if ($pbm_st == FALSE) {
    // On récupère les spécialités du sous-traitant
    if ($td <> 'add') {
        $_SESSION['tab_spdes'] = give_tab_sp_st($coderech);
    }
}

switch ($td) {
    case 'add' :
        $titre = _('CREATION SOUS-TRAITANT');
        break;
    case 'edit' :
        $titre = _('MISE A JOUR SOUS-TRAITANT');
        $lst_chp_readonly .= '-code';
        break;
    case 'del' :
        $titre = _('SUPPRESSION SOUS-TRAITANT');
        break;
    case 'view' :
        $titre = _('VISUALISATION SOUS-TRAITANT');
        break;
    default :
        $pbm_st = TRUE;
        break;
}

?>

<!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 sous-traitant'); ?></title>

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

    <script language="javascript">
        <!--
        var tab1_champ = [
            <?php
            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 _('Département'); ?> ; vmn:1; stok:frmok ; stbad:frmbad",
            "nom:pays ; format:liste ; req:Y ; txt:<?php echo _('Pays'); ?> ; vmn:1; stok:frmok ; stbad:frmbad",
            <?php
            if (($td=='add') OR ($td=='edit'))
            {
                if (CheckNivLog('5-9'))
                    {echo '"nom:zone[] ; format:listem ; req:Y ; txt:'._('Zone couverte').'; vmn:1; stok:frmok ; stbad:frmbad",';}
            }
            ?>
            "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:N ; 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 contact principal'); ?>; stok:frmok ; stbad:frmbad",
            "nom:rtelp ; format:telp ; req:N ; txt:<?php echo _('N° tel portable contact principal'); ?>; 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 (CheckNivLog('5-9'))
                {echo '"nom:nota ; format:txt ; req:N ; txt:'._('Notes').'; stok:frmok ; stbad:frmbad",';}
            ?>
            "nom:emailt ; format:mail ; req:Y ; txt:<?php echo _('Email').' '._('Technique'); ?> ; lmx:50; stok:frmok ; stbad:frmbad"];
        //-->
    </script>

    <?php if (($pbm_st == FALSE) AND ($st_ouvert == 1)) { ?>
        <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();
                $("#onglets_st").tabs();
                init_txtfromvalsel('zone', 'zonetxt');
                <?php
                switch ($td)
                {
                    case 'add' :
                        echo "$('#ouverture').hide();";
                        echo "init_valid_form('enr','st_maj','".valsession('date_fmtshort')."',tab1_champ,'pays','');";
                        break;
                    case 'edit' :
                        echo "$('#ouverture').show();";
                        echo "init_valid_form('enr','st_maj','".valsession('date_fmtshort')."',tab1_champ,'pays','');";
                        echo "init_fensaisie('add_ctact',950,560);";
                        echo "init_fensaisie('edit_ctact',950,560);";
                        if ($pbm_zoc == TRUE) {
                            echo "init_warn('zoc', '', '', '', '');";
                        }
                        if ($pbm_sp == TRUE) {
                            echo "init_warn('sp', '', '', '', '');";
                        }
                        break;
                    case 'view' :
                        echo "$('#ouverture').show();";
                        if ($pbm_zoc == TRUE) {
                            echo "init_warn('zoc', '', '', '', '');";
                        }
                        if ($pbm_sp == TRUE) {
                            echo "init_warn('sp', '', '', '', '');";
                        }
                        echo 'readonly_all();';
                        break;
                    case 'del' :
                        echo "$('#ouverture').show();";
                        echo 'readonly_all();';
                        echo "warn_del('tec');";
                        break;
                }
                ?>
                init_ajax_ville();
                <?php
                switch (valsession('niv_log'))
                {
                    case 5 :
                    case 9 :
                        echo 'init_ajax_dep_et_zc();';
                        echo "init_ajax_st1('add_sp','tab_sp');";
                        echo "init_autoajax_classe_st2('falselnkimgajax','tab_sp');";
                        echo "init_autoajax_classe_st3('falselnksel','tab_sp');";
                        break;
                    case 10 :
                        echo 'init_ajax_dep();';
                        break;
                    default :
                        break;
                }
                ?>
                init_back('annul', 'click');
                init_autohref('add_coloc', 'click', '', true);
                init_autohref('view_coloc', 'click', '', true);
                init_autohref('view_ot', 'click', '', true);
                readonly_id('<?php echo $lst_chp_readonly; ?>', false);
                Focus_first();
            }

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

    <script language="javascript">
        <!--

        //-->
    </script>

</head>
<body>

<?php
include_once('../inc/entete.inc.php');
cre_ent_form($titre, '', '', '', FALSE);
?>
<!-- affiché uniquement s'il y a au moins une civilité -->
<?php
if ($pbm_st == FALSE) {
    if ($nbciv <> 0) {
        ?>
        <table width="100%" border="0">
            <tr>
                <td width="33%" class="annot_gras_it">
                    <?php if (CheckNivLog('5-9')) {
                        aff_lnk_lst_rech('st_lst.php', _('Retour à la liste'), $_SERVER['HTTP_REFERER'], _('Retour à la page précédente'));
                    } 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%" align="right">
                    <?php
                    if (($td == 'edit') OR ($td == 'view')) {
                        $urlimp = 'st_maji.php?cs=' . $coderech;
                        if (url_ok($urlimp) == TRUE) {
                            echo '<div id="imprim" align="right" title="' . $urlimp . '" class="falselnk">';
                            echo ' <img src="../img/print.png" title="' . _('Imprimer') . '" border="0" align="absmiddle"> ' . _('Imprimer');
                            echo '</div>';
                        } else {
                            echo '&nbsp;';
                        }
                    } else {
                        echo '&nbsp;';
                    }
                    ?>
                </td>
            </tr>
            <tr>
                <td width="33%">
                    <?php if ($td == 'edit') {
                        $url_cst = 'cst_maj.php?td=add&cs=' . $st_code . '&tx=st';
                        cre_falselnk('', 'add_ctact', 'span', '', _('Ajouter un contact'), $url_cst, '../img/ctacts.png', _('Ajouter un contact'));

                        $url_cst = 'cst_maj.php?td=lst&cs=' . $st_code . '&tx=st';
                        if ($nbcontacts == 0) {
                            echo '<span id="ctact" style="display:none">';
                        } else {
                            echo '<span id="ctact" style="display:inline">';
                        }
                        cre_falselnk('', 'edit_ctact', 'span', '', _('Edition contacts'), $url_cst, '', _('Edition contacts'), true);
                        echo '</span>';
                    }
                    ?>
                </td>
                <td width="33%" align="center">
                    <?php
                    if (($td == 'edit') AND (valsession('niv_log') >= 5)) {
                        $url_addcoloc = 'coloc_maj.php?td=add&tc=3&cc=' . $st_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=' . $st_code . '&rech=Rechercher';
                            cre_falselnk('', 'view_coloc', 'span', '', '', $url_coloc, '', _('Saisir contrat location'), TRUE);
                        }
                    } else {
                        echo '&nbsp;';
                    }
                    ?>
                </td>
                <td width="33%" align="right">
                    <?php
                    if (($td == 'edit') AND ($nbordres <> 0) AND (valsession('niv_log') <> 6)) {
                        $url_ord = 'ot_lst.php?tx=m&ord=DES&tri=Code&search=' . $st_code . '&rech=Rechercher';
                        $texte = _('Voir ses bons') . ' ' . sprintf("%'03s", $nbordres);
                        cre_falselnk('', 'view_ot', 'span', '', '', $url_ord, '', $texte, TRUE);
                    } else {
                        echo '&nbsp;';
                    }
                    ?>
                </td>
            </tr>
        </table>

        <!-- Formulaire de saisie de la fiche -->
        <form name="st_maj" id="st_maj" method="post" action="st_enr.php">
            <input name="titre" type="hidden" id="titre" value="<?php echo $titre ?>">
            <input name="td" type="hidden" id="td" value="<?php echo $td ?>">
            <input name="nbutton" type="hidden" id="nbutton" value="">
            <?php if ($td == 'add') { ?>
                <input name="actif" type="hidden" id="actif" value="1">
            <?php } else { ?>
                <input name="codeage" type="hidden" id="codeage" value="<?php echo $st_codeage; ?>">
                <?php
            }
            ?>

            <div id="onglets_st">
                <ul>
                    <li><a href="#st_coord"><?php echo _('Coordonnées'); ?></a></li>
                    <li><a href="#st_contacts"><?php echo _('Contacts'); ?></a></li>
                    <?php if (CheckNivLog('5-9')) {
                        echo '<li><a href="#st_spe">' . _('Spécialités') . '</a></li>';
                        echo '<li><a href="#st_div">' . _('Notes') . '</a></li>';
                    }
                    ?>
                </ul>
                <div id="st_coord">

                    <!-- activité (avec dates) du donneur d'ordre -->
                    <?php
                    if (CheckNivLog('5-9')) {
                        if (($td == 'edit') OR ($td == 'del')) {
                            ?>
                            <div id="ouverture" style="display: none;">
                                <table width="100%" border="0">
                                    <tr>
                                        <td width="160" class="rubfrm" id="f_ouvert"
                                            align="right"><?php echo _('Actif'); ?></td>
                                        <td>
                                            <?php
                                            if (($td == 'edit') OR ($td == 'del')) {
                                                cre_select('actif', 'actif', $non_oui, (int)$st_ouvert);
                                            } else {
                                                echo '<input name="actif" type="text" id="actif" value="Non" size="3" maxlength="3" readonly="1">';
                                            }

                                            echo '<span class="annot_petit_it">';
                                            if ($st_ouvert == 1) {
                                                echo ' (' . _('Depuis le') . ' : ' . datetolocal($st_datecrea) . ')';
                                            } else {
                                                echo ' (' . _('Ouverte le') . ' : ' . datetolocal($st_datecrea) . ', ' . _('fermée le') . ' : ' . datetolocal($st_datec) . ')';
                                            }
                                            echo '</span>';
                                            ?>
                                        </td>
                                        <?php
                                        if (($td == 'edit') OR ($td == 'del') OR ($td == 'view')) {
                                            echo '<td align="right" valign="top">';
                                            $url_img_logo = $chemin_logos . '/log' . strtolower($st_code) . '.png';
                                            if (exist_logo($st_code)) {
                                                echo ' <a href="' . $url_img_logo . '" class="nyroModal" title="' . _('Logo Sous-traitant') . ' (' . $st_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=st">' . _('Configurer') . '</a>)';
                                                echo '</div>';
                                            }
                                            echo '</td>';
                                        }
                                        ?>
                                    </tr>
                                </table>
                            </div>
                            <?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') { ?>
                                    <strong>S</strong>
                                    <input name="code" type="text" id="code" value="<?php echo $st_code ?>" size="9"
                                           maxlength="9">
                                    <img src="../img/oblig.png" align="absmiddle"
                                         alt="<?php echo _('Champ obligatoire'); ?>">
                                <?php } else { ?>
                                    <input name="code" type="text" id="code" value="<?php echo $st_code ?>" size="10"
                                           maxlength="10"
                                           readonly>
                                    <?php
                                }
                                ?>
                            </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 $st_nom; ?>" size="50">
                                <img src="../img/oblig.png" align="absmiddle"
                                     alt="<?php echo _('Champ obligatoire'); ?>">
                            </td>
                        </tr>
                        <tr>
                            <td class="rubfrm" id="f_rcs" align="right"><?php echo _('Siret'); ?></td>
                            <td>
                                <input name="rcs" type="text" id="rcs" value="<?php echo $st_rcs ?>" size="50">
                            </td>
                        </tr>
                        <tr>
                            <td class="rubfrm" id="f_ape" align="right"><?php echo _('APE'); ?></td>
                            <td>
                                <input name="ape" type="text" id="ape" value="<?php echo $st_ape ?>" size="10">
                            </td>
                        </tr>
                        <tr>
                            <td class="rubfrm" id="f_tvai" align="right"><?php echo _('TVA intra.'); ?></td>
                            <td>
                                <input name="tvai" type="text" id="tvai" value="<?php echo $st_tvai ?>" size="50">
                            </td>
                        </tr>
                        <tr>
                            <td class="rubfrm" id="f_tcom" align="right"><?php echo _('Tribunal com.'); ?></td>
                            <td>
                                <input name="tcom" type="text" id="tcom" value="<?php echo $st_tcom ?>" size="70">
                                <img src="../img/oblig.png" align="absmiddle"
                                     alt="<?php echo _('Champ obligatoire'); ?>">
                            </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 $st_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 $st_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', '', $st_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($st_codepays);
                                cre_select_tab('dep', 'dep', $rows, 'dep_code', 'dep_code', 'dep_nom', $st_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($st_dep, $st_codepays);
                                cre_select_tab('ville', 'ville', $rows, 'villes_id', 'villes_nom', 'villes_cp', $st_ville, '', _('-- Faites votre choix --'), 1, FALSE, '-1', _('-- Inconnu --'));
                                ?>
                            </td>
                        </tr>
                        <tr>
                            <td class="rubfrm" id="f_zone" align="right"><?php echo _('Zone couverte'); ?></td>
                            <td>
                                <?php
                                // Liste des départements couverts
                                $zone = str_zoc_st_open($st_code, TRUE);
                                $tab_zone = explode('_', $zone);

                                // création de la liste des Départements
                                if ($st_codepays <> '') {
                                    $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST, 'utf8');
                                    $rech = 'SELECT * FROM `' . TBDEP . "` WHERE dep_codepays='" . str_majuscules($st_codepays) . "' ORDER BY dep_code";
                                    $rows = $db->get_results($rech, ARRAY_A);
                                    close_database();
                                }

                                cre_select_tab('zone[]', 'zone', $rows, 'dep_code', 'dep_code', 'dep_nom', $tab_zone, '', _('-- Faites votre choix --'), 5, TRUE);

                                echo '<br />';
                                echo '<input name="zonetxt" type="hidden" id="zonetxt" value="' . $zone . '" size="50" readonly>';
                                ?>
                            </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', $st_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 $st_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 $st_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 $st_fax ?>" size="20"
                                       maxlength="20">
                                <br/>
                                <input name="txtfax" type="text" id="txtfax" value="<?php echo $st_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 $st_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 $st_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 $st_txtent ?></textarea></td>
                        </tr>
                        <tr>
                            <td colspan="2">&nbsp;</td>
                        </tr>
                    </table>
                    </div>

                    <div id="st_contacts">
                        <table width="100%" border="0">
                        <tr>
                            <td colspan="2" class="rubfrm" id="f_web"
                                align="center"><?php echo _('Contact principal'); ?></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, 'utf8');
                                $rech = 'SELECT * FROM `' . TBCIV . '` ORDER BY civ_desc';
                                $rows = $db->get_results($rech, ARRAY_A);
                                close_database();
                                cre_select_tab('rcivil', 'rcivil', $rows, 'civ_code', 'civ_desc', '', $st_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 $st_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 $st_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 $st_resp_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_telp"
                                align="right"><?php echo _('Téléphone portable'); ?></td>
                            <td>
                                <input name="rtelp" type="text" id="rtelp" value="<?php echo $st_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 $st_email ?>" size="50"
                                       maxlength="50">
                                <?php if ($td == 'edit') { ?>
                                    <a href="mailto:<?php echo $st_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_petit_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 $st_emaild ?>" size="50"
                                       maxlength="50">
                                <?php if ($td == 'edit') { ?>
                                    <a href="mailto:<?php echo $st_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 $st_emailc ?>" size="50"
                                       maxlength="50">
                                <?php if ($td == 'edit') { ?>
                                    <a href="mailto:<?php echo $st_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 $st_emailt ?>" size="50"
                                       maxlength="50">
                                <?php if ($td == 'edit') { ?>
                                    <a href="mailto:<?php echo $st_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>

                <?php
                if (CheckNivLog('5-9')) {
                    echo '<div id="st_spe">';

                    // Création de la liste des spécialités
                    $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST, 'utf8');
                    $rech = '';
                    $rech = 'SELECT * FROM `' . TBSP . '` ORDER BY sp_desc';
                    $rows = $db->get_results($rech, ARRAY_A);
                    close_database();
                    echo '<div align="center">';
                    cre_select_tab('spec', 'spec', $rows, 'sp_code', 'sp_desc', '', '', '', _('-- Faites votre choix --'));
                    echo '</div>';

                    echo '<div align="center" style="padding-top:10px;">';
                    echo ' <img id="add_sp" src="../img/sel_dn.png" border="0" align="absmiddle" title="' . _('Transférer') . '">';
                    echo '</div>';

                    echo '<div id="tab_sp" align="center" style="padding-top:10px;">';
                    echo '<table width="80%" id="t_spec" class="MtableD">';
                    echo '<tr>';
                    echo '<th width="500">' . _('Spécialité') . '</th>';
                    echo '<th witdh="300">' . _('Niveau de compétences') . '</th>';
                    echo '<th witdh="100">' . _('Supprimer') . '</th>';
                    echo '</tr>';
                    if (count($_SESSION['tab_spdes']) > 0) {
                        foreach ($_SESSION['tab_spdes'] as $key => $value) {
                            echo '<tr>';
                            echo '<td align="center">' . $value['des'] . '</td>';
                            echo '<td align="center">';
                            cre_select('niv_' . $key, 'niv_' . $key, $sp_niveau_st, $value['niv'], '', '', 1, FALSE, '', '', TRUE, FALSE, 'falselnksel');
                            echo '</td>';
                            echo '<td align="center">';
                            cre_falselnk_img_ajax('', 'sp_del_' . $key, 'span', 'center', _('Suppression'), 'prmajax', $key, '../img/del.png');
                            echo '</td>';
                            echo '</tr>';
                        }
                    }
                    echo '</table>';
                    echo '</div>';

                    echo '</div>';

                    echo '<div id="st_div">';

                    echo '<table width="100%" border="0">';

                    echo '<tr>';
                    echo '<td width="160" class="rubfrm" id="f_nota" align="right">';
                    echo _('Notes');
                    echo '</td>';
                    echo '<td>';
                    echo '<textarea name="nota" id="nota">' . $st_nota . '</textarea>';
                    echo '</td>';
                    echo '</tr>';

                    echo '<tr>';
                    echo '<td width="160" class="rubfrm" id="f_factures" align="right">';
                    echo _('Emet ses factures');
                    echo '</td>';
                    echo '<td>';
                    cre_select('factures', 'factures', $non_oui, (int)$st_fact);
                    echo '</td>';
                    echo '</tr>';

                    echo '</table>';

                    echo '</div>';
                }
                ?>
            </div>
            <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="submit" class="bton_std" id="del" value="' . _('Supprimer') . '">';
                        break;
                }
                echo '<input name="RAZ" type="reset" class="bton_std" id="RAZ" value="' . _('Réinitialiser') . '">';
                ?>
            </p>
        </form>
        <!-- Fin affiché uniquement s'il y a au moins une catégorie agence et au moins une civilité -->
        <?php
    } else {
        pop_ret_auto(_('Aucune civilité'), 'warn', 'civ_lst.php');
    }
} else {
    pop_ret_auto(_('Problème de paramètres'), 'warn', 'index.php');
}
/** @noinspection PhpIncludeInspection */
include_once('pied.php');
?>
</body>
</html>