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


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


include_once("../inc/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(@$_SESSION["code_log"]);
// Variables Formulaire
fix_magic_quotes();
$_GET = clean_str($_GET);

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

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

if ((@$_SESSION["niv_log"] == 3) OR (@$_SESSION["niv_log"] == 4))
    $td = "view";

$nbordres = 0;
$pbm_st = FALSE;
$nbcoloc = 0;

$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 (@$_SESSION["niv_log"] >= 3) {
            if (@$_SESSION["niv_log"] == 10) {
                if ($coderech <> $_SESSION["code_st"])
                    $pbm_st = TRUE;
            }
        } else
            $pbm_st = 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 ((@$_SESSION["niv_log"] <> 5) AND (@$_SESSION["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 ((@$_SESSION["niv_log"] == 5) OR (@$_SESSION["niv_log"] == 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: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 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 ((@$_SESSION["niv_log"] == 5) OR (@$_SESSION["niv_log"] == 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','".$_SESSION['date_fmtshort']."',tab1_champ,'','');";
                    break;
                case "edit" :
                    echo "$('#ouverture').show();";
                    echo "init_valid_form('enr','st_maj','".$_SESSION['date_fmtshort']."',tab1_champ,'','');";
                    echo "init_fensaisie('add_ctact',950,560);";
                    echo "init_fensaisie('edit_ctact',950,560);";
                    break;
                case "del" :
                    echo "$('#ouverture').show();";
                    echo "readonly_all();";
                    echo "warn_del('tec');";
                    break;
                case "view" :
                    echo "$('#ouverture').show();";
                    echo "readonly_all();";
                    break;
            }
            ?>
            init_ajax_ville();
            <?PHP
            switch (@$_SESSION["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");
?>
<p align="center"><span class="titrepage"><?PHP echo $titre ?></span></p>
<!-- affiché uniquement s'il y a au moins une civilité -->
<?PHP
if ($pbm_st == FALSE) {
    if (nb_civ() <> 0) {
        ?>
        <table width="100%" border="0">
            <tr>
                <td width="33%" class="annot_gras_it">
                    <?PHP if ((@$_SESSION["niv_log"] == 5) OR (@$_SESSION["niv_log"] == 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 (@$_SESSION["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 (@$_SESSION["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>
            <?PHP if ((@$_SESSION["niv_log"] == 5) OR (@$_SESSION["niv_log"] == 9))
            {
                echo '<li><a href="#st_spe">'._("Spécialités").'</a></li>';
                echo '<li><a href="#st_note">'._("Notes").'</a></li>';
            }
            ?>
        </ul>
        <div id="st_coord">

        <!-- activité (avec dates) du donneur d'ordre -->
        <?PHP
        if ((@$_SESSION["niv_log"] == 5) OR (@$_SESSION["niv_log"] == 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
                    $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
                    $rech = "SELECT * FROM `" . TBPAYS . "` ORDER BY pays_nom";
                    $rows = $db->get_results($rech, ARRAY_A);
                    $db->disconnect();
                    cre_select_tab('pays', 'pays', $rows, 'pays_code', 'pays_nom', '', $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
                    $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
                    $rech = "SELECT * FROM `" . TBDEP . "` WHERE `dep_codepays`='" . $st_codepays . "' ORDER BY dep_code";
                    $rows = $db->get_results($rech, ARRAY_A);
                    $db->disconnect();
                    cre_select_tab('dep', 'dep', $rows, 'dep_code', 'dep_code', 'dep_nom', $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
                    $rech = "";
                    if ($st_dep <> "") {
                        if ($st_dep <> "-1") {
                            $filtre = $st_dep;
                            if (($filtre == "2A") OR ($filtre == "2B"))
                                $filtre = "20";
                            $rech = "SELECT * FROM `" . TBVILLES . "` WHERE `villes_dep` = '" . str_majuscules($filtre) . "' AND `villes_codepays`='" . str_majuscules($st_codepays) . "' ORDER BY villes_nom";
                        } else {
                            $rech = "SELECT * FROM `" . TBVILLES . "` WHERE `villes_codepays`='" . str_majuscules($st_codepays) . "' ORDER BY villes_nom";
                        }
                    }
                    $rows = [];
                    $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
                    if ($rech <> "")
                        $rows = $db->get_results($rech, ARRAY_A);
                    $db->disconnect();
                    cre_select_tab('ville', 'ville', $rows, 'villes_id', 'villes_nom', 'villes_cp', $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);
                        $rech = "SELECT * FROM `" . TBDEP . "` WHERE dep_codepays='" . str_majuscules($st_codepays) . "' ORDER BY dep_code";
                        $rows = $db->get_results($rech, ARRAY_A);
                        $db->disconnect();
                    }

                    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
                    $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
                    $rech = "SELECT dev_codea,dev_nom FROM `" . TBDEV . "` ORDER BY dev_nom";
                    $rows = $db->get_results($rech, ARRAY_A);
                    $db->disconnect();
                    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">
                <img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo _("Champ obligatoire"); ?>"><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>
        <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);
                $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', '', $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>
        <?PHP
        if ((@$_SESSION["niv_log"] == 5) OR (@$_SESSION["niv_log"] == 9)) {
            ?>
            <tr>
                <td width="160" class="rubfrm" id="f_factures" align="right"><?PHP echo _("Emet ses factures"); ?></td>
                <td>
                    <?PHP
                    if ($td == "add")
                        cre_select('factures', 'factures', $non_oui, 0);
                    else
                        cre_select('factures', 'factures', $non_oui, (int)$st_fact);
                    ?>
                </td>
            </tr>
        <?PHP
        }
        ?>
        </table>
        </div>

        <?PHP
        if ((@$_SESSION["niv_log"] == 5) OR (@$_SESSION["niv_log"] == 9)) {
            echo '<div id="st_spe">';
            // Création de la liste des spécialités
            $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
            $rech = "";
            $rech = "SELECT * FROM `" . TBSP . "` ORDER BY sp_desc";
            $rows = $db->get_results($rech, ARRAY_A);
            $db->disconnect();
            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_note">';
            echo '<textarea name="nota" id="nota">'.$st_nota.'</textarea>';
            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");
include_once("pied.php");
?>
</body>
</html>