<?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_do.inc.php");
include_once("../inc/fic_droits.inc.php");
include_once("../inc/fic_ope.inc.php");
include_once("../inc/fic_cli.inc.php");
include_once("../inc/fic_st.inc.php");
include_once("../inc/fic_tec.inc.php");
include_once("../inc/func.inc.php");
include_once("../inc/func_log.inc.php");
include_once("../inc/func_geo.inc.php");
include_once("../inc/func_txt.inc.php");
include_once("../classes/ezSQL/shared/ez_sql_core.php");
include_once("../classes/ezSQL/mysqli/ez_sql_mysqli.php");
include_once("../inc/func_sql.inc.php");
Archivelog(@$_SESSION["code_log"]);
// Variables Formulaire
fix_magic_quotes();
$_GET = clean_str($_GET);

$orig = $_GET['ori']; // Récupération origine ('Public / Privé')

$ddeok = TRUE;

// Si origine de la demande est "privée", on récupère le code du Département du connecté et les données du demandeur
if ($orig == "pr") {
    switch (@$_SESSION["niv_log"]) {
        // Sous-traitant
        case 10 :
            $row = lit_enr_st(@$_SESSION["code_log"]);
            if (is_array($row)) {
                $row = encode_str($row);
                extract($row);

                $ste = $st_nom;
                $nom = '';
                $prenom = '';
                $adr1 = $st_adr1;
                $adr2 = $st_adr2;
                $dep = $st_dep;
                $ville = $st_ville;
                $pays = $st_codepays;
                $telf = str_replace(" ", "", $st_telf);
                $fax = str_replace(" ", "", $st_fax);
                $email = $st_emaild;
            } else
                $ddeok = FALSE;
            break;

        // Donneur d'ordres
        case 6 :
            $row = lit_enr_do(@$_SESSION["code_log"]);
            if (is_array($row)) {
                $row = encode_str($row);
                extract($row);

                $ste = $do_nom;
                $nom = '';
                $prenom = '';
                $adr1 = $do_adr1;
                $adr2 = $do_adr2;
                $dep = $do_dep;
                $ville = $do_ville;
                $pays = $do_codepays;
                $telf = str_replace(" ", "", $do_telf);
                $fax = str_replace(" ", "", $do_fax);
                $email = $do_emaild;
            } else
                $ddeok = FALSE;
            break;

        //Centre de gestion
        case 5 :
            $row = lit_enr_cdg();
            if (is_array($row)) {
                $row = encode_str($row);
                extract($row);

                $ste = $cge_nom;
                $nom = '';
                $prenom = '';
                $adr1 = $cge_adr1;
                $adr2 = $cge_adr2;
                $dep = $cge_dep;
                $ville = $cge_ville;
                $pays = $cge_codepays;
                $telf = str_replace(" ", "", $cge_telf);
                $fax = str_replace(" ", "", $cge_fax);
                $email = $cge_emaild;
            } else
                $ddeok = FALSE;
            break;

        //Agence
        case 4 :
            $row = lit_enr_age(@$_SESSION["code_log"], TRUE);
            if (is_array($row)) {
                $row = encode_str($row);
                extract($row);

                $ste = $age_nom;
                $nom = '';
                $prenom = '';
                $adr1 = $age_adr1;
                $adr2 = $age_adr2;
                $dep = $age_dep;
                $ville = $age_ville;
                $pays = $age_codepays;
                $telf = str_replace(" ", "", $age_telf);
                $fax = str_replace(" ", "", $age_fax);
                $email = $age_emaild;
            } else
                $ddeok = FALSE;
            break;

        // Technicien agence/sous-traitant/donneur d'ordres
        case 3 :
        case 11 :
        case 7 :
            $row = lit_enr_tec(@$_SESSION["code_log"], TRUE);
            if (is_array($row)) {
                $row = encode_str($row);
                extract($row);

                $civilite = $tec_civilite;
                $prenom = $tec_prenom;
                $nom = $tec_nom;
                $adr1 = $tec_adr1;
                $adr2 = $tec_adr2;
                $dep = $tec_dep;
                $ville = $tec_ville;
                $pays = $tec_codepays;
                $telf = str_replace(" ", "", $tec_telf);
                $telp = str_replace(" ", "", $tec_telp);
                $fax = str_replace(" ", "", $tec_fax);
                $email = $tec_email;
            } else
                $ddeok = FALSE;
            break;

        //Opérateur
        case 2 :
            $row = lit_enr_ope(@$_SESSION["code_log"]);
            if (is_array($row)) {
                $row = encode_str($row);
                extract($row);

                $civilite = $ope_civilite;
                $prenom = $ope_prenom;
                $nom = $ope_nom;
                $adr1 = $ope_adr1;
                $adr2 = $ope_adr2;
                $dep = $ope_dep;
                $ville = $ope_ville;
                $pays = $ope_codepays;
                $telf = str_replace(" ", "", $ope_telf);
                $telp = str_replace(" ", "", $ope_telfp);
                $email = $ope_email;
            } else
                $ddeok = FALSE;
            break;

        //Client
        case 1 :
            $row = lit_enr_cli(@$_SESSION["code_log"], TRUE);
            if (is_array($row)) {
                $row = encode_str($row);
                extract($row);

                $ste = $cli_ste;
                $civilite = $cli_civilite;
                $prenom = $cli_prenom;
                $nom = $cli_nom;
                $adr1 = $cli_adr1;
                $adr2 = $cli_adr2;
                $dep = $cli_dep;
                $ville = $cli_ville;
                $pays = $cli_codepays;
                $telf = str_replace(" ", "", $cli_telf);
                $fax = str_replace(" ", "", $cli_fax);
                $telp = str_replace(" ", "", $cli_telfp);
                $email = $cli_email;
            } else
                $ddeok = FALSE;
            break;

        default :
            $ddeok = FALSE;
            break;
    }
}
$titre = _("MESSAGES & DEMANDES");
?>
<!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 _("Demande"); ?></title>

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

    <!-- affiché uniquement si demande cohérente -->
    <script language="javascript">
        <!--
        var tab1_champ = ["nom:objet ; format:liste ; req:Y ; txt:<?PHP echo _("Objet de la demande"); ?> ; vmn:1 ; stok:frmok ; stbad:frmbad",
            "nom:dest ; format:liste ; req:Y ; txt:<?PHP echo _("Destinataire"); ?> ; vmn:1 ; stok:frmok ; stbad:frmbad",
            "nom:ste ; format:txt ; req:N ; txt:<?PHP echo _("Société"); ?> ; stok:frmok ; stbad:frmbad",
            "nom:civilite ; format:liste ; req:Y ; txt:<?PHP echo _("Civilité"); ?> ; vmn:1 ; stok:frmok ; stbad:frmbad",
            "nom:prenom ; format:txt ; req:Y ; txt:<?PHP echo _("Prénom"); ?> ; lmx:50 ; stok:frmok ; stbad:frmbad",
            "nom:nom ; format:txt ; req:Y ; txt:<?PHP echo _("Prénom"); ?> ; lmx:50 ; stok:frmok ; stbad:frmbad",
            "nom:adr1 ; format:txt ; req:Y ; txt:<?PHP echo _("Adresse"); ?> ; lmx:50 ; stok:frmok ; stbad:frmbad",
            "nom:adr2 ; format:txt ; req:N ; txt:<?PHP echo _("Adresse (2)"); ?> ; lmx:50 ; stok:frmok ; stbad:frmbad",
            <?PHP
            // Espace privé
            if (@$_SESSION["niv_log"] <> "")
            {
            ?>
            "nom:pays ; format:txt ; req:Y ; txt:<?PHP echo _("Ville"); ?> ; stok:frmok ; stbad:frmbad",
            "nom:dep ; format:txt ; req:Y ; <?PHP echo _("Département"); ?> ; stok:frmok ; stbad:frmbad",
            "nom:ville ; format:txt ; req:Y ; txt:<?PHP echo _("Ville"); ?> ; stok:frmok ; stbad:frmbad",
            <?PHP
            } else {
            ?>
            "nom:pays ; format:liste ; req:Y ; txt:<?PHP echo _("Pays"); ?> ; vmn:1 ; stok:frmok ; stbad:frmbad",
            "nom:dep ; format:liste ; req:Y ; <?PHP echo _("Département"); ?> ; vmn:1 ; stok:frmok ; stbad:frmbad",
            "nom:ville ; format:liste ; req:Y ; txt:<?PHP echo _("Ville"); ?> ; vmn:1 ; stok:frmok ; stbad:frmbad",
            <?PHP
            }
            ?>
            "nom:telf ; format:tel ; req:Y ; txt:<?PHP echo _("Téléphone Fixe"); ?> ; stok:frmok ; stbad:frmbad",
            "nom:fax ; format:tel ; req:N ; txt:<?PHP echo _("Télécopieur"); ?> ; stok:frmok ; stbad:frmbad",
            "nom:telp ; format:telp ; req:N ; txt:<?PHP echo _("Téléphone portable"); ?> ; stok:frmok ; stbad:frmbad",
            "nom:email ; format:mail ; req:Y ; txt:<?PHP echo _("Email"); ?> ; stok:frmok ; stbad:frmbad",
            <?PHP if ((@$_SESSION["niv_log"] <> "") AND (@$_SESSION["niv_log"]==1)) { ?>
            "nom:site ; format:liste ; req:Y ; txt:<?PHP echo _("Site concerné"); ?> ; vmn:1 ; stok:frmok ; stbad:frmbad",
            <?PHP } ?>
            "nom:txtdde ; format:txt ; req:Y ; txt:<?PHP echo _("Votre demande"); ?> ; stok:frmok ; stbad:frmbad"];
        //-->
    </script>

    <script type="text/javascript">
        <!--
        $(function () {
            $("#adr1").Setcase({caseValue: 'upper', changeonFocusout: true});
            $("#adr2").Setcase({caseValue: 'upper', changeonFocusout: true});
            $("#nom").Setcase({caseValue: 'upper', changeonFocusout: true});
            $("#email").Setcase({caseValue: 'lower', changeonFocusout: true});
            $("#prenom").Setcase({caseValue: 'allfirst', changeonFocusout: true});
        });

        function init_all() {
            init_Body();
            <?PHP
            echo "init_valid_form('enr','dde_maj','".$_SESSION['date_fmtshort']."',tab1_champ,'','');";
            // Espace Publique
            if (@$_SESSION["niv_log"] == "") { ?>
            init_ajax_ville();
            init_ajax_dep();
            <?PHP } ?>
            Focus_first();
        }

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

</head>

<body>
<?php
include_once("../inc/entete.inc.php");
?>
<p align="center"><span class="titrepage"><?PHP echo $titre ?></span></p>
<?PHP
if ($ddeok == TRUE) {
    ?>
    <form name="dde_maj" id="dde_maj" method="post" action="dde_enr.php">
    <input name="titre" type="hidden" id="titre" value="<?PHP echo $titre ?>">
    <input name="ori" type="hidden" id="ori" value="<?PHP echo $orig ?>">
    <input name="nbutton" type="hidden" id="nbutton" value="">

    <!-- Objet -->
    <table width="100%" border="0">
        <tr>
            <td width="160" class="rubfrm" id="f_obj" align="right"><?PHP echo _("Objet"); ?></td>
            <td>
                <?PHP
                // création de la liste des type de demandes
                $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
                if (@$_SESSION["niv_log"] <> "") // Espace privé
                {
                    switch (@$_SESSION["niv_log"]) {
                        // Si Demandeur = Technicien sous-traitant
                        case 11 :
                            $rech = "SELECT * FROM `" . TBDDET . "` WHERE `ddet_stt` = '1' ORDER BY ddet_desc";
                            break;

                        // Si Demandeur = Sous-traitant
                        case 10 :
                            $rech = "SELECT * FROM `" . TBDDET . "` WHERE `ddet_st` = '1' ORDER BY ddet_desc";
                            break;

                        // Si Demandeur = Technicien donneur d'ordres
                        case 7 :
                            $rech = "SELECT * FROM `" . TBDDET . "` WHERE `ddet_dot` = '1' ORDER BY ddet_desc";
                            break;

                        // Si Demandeur = Donneur d'ordres
                        case 6 :
                            $rech = "SELECT * FROM `" . TBDDET . "` WHERE `ddet_do` = '1' ORDER BY ddet_desc";
                            break;

                        // Si Demandeur = Centre de gestion
                        case 5 :
                            $rech = "SELECT * FROM `" . TBDDET . "` WHERE `ddet_cge` = '1' ORDER BY ddet_desc";
                            break;

                        // Si Demandeur = Agence
                        case 4 :
                            $rech = "SELECT * FROM `" . TBDDET . "` WHERE `ddet_age` = '1' ORDER BY ddet_desc";
                            break;

                        // Si Demandeur = Client
                        case 1 :
                            $rech = "SELECT * FROM `" . TBDDET . "` WHERE `ddet_cli` = '1' ORDER BY ddet_desc";
                            break;

                        // Si Demandeur = Opérateur
                        case 2 :
                            $rech = "SELECT * FROM `" . TBDDET . "` WHERE `ddet_ope` = '1' ORDER BY ddet_desc";
                            break;

                        // Si Demandeur = Technicien
                        case 3 :
                            $rech = "SELECT * FROM `" . TBDDET . "` WHERE `ddet_tec` = '1' ORDER BY ddet_desc";
                            break;
                    }
                } else
                    $rech = "SELECT * FROM `" . TBDDET . "` WHERE `ddet_pub` = '1' ORDER BY ddet_desc";

                $rows = $db->get_results($rech, ARRAY_A);
                $db->disconnect();
                cre_select_tab('objet', 'objet', $rows, 'ddet_code', 'ddet_desc', '', '', '', _("-- Faites votre choix --"));
                ?>
            </td>
        </tr>
    </table>

    <!-- Destinataire -->
    <table width="100%" border="0">
        <tr>
            <td width="160" class="rubfrm" id="f_dest" align="right"><?PHP echo _("Destinataire"); ?></td>
            <td>
                <?PHP
                // création de la liste des destinataires demandes
                $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
                if (@$_SESSION["niv_log"] <> "") // Espace privé
                {
                    switch (@$_SESSION["niv_log"]) {
                        // Si Demandeur = Technicien sous-traitant
                        case 11 :
                            $rech = "SELECT * FROM `" . TBDDED . "` WHERE `dded_stt` = '1' ORDER BY dded_desc";
                            break;

                        // Si Demandeur = Sous-traitant
                        case 10 :
                            $rech = "SELECT * FROM `" . TBDDED . "` WHERE `dded_st` = '1' ORDER BY dded_desc";
                            break;

                        // Si Demandeur = Technicien donneur d'ordres
                        case 7 :
                            $rech = "SELECT * FROM `" . TBDDED . "` WHERE `dded_dot` = '1' ORDER BY dded_desc";
                            break;

                        // Si Demandeur = Donneur d'ordres
                        case 6 :
                            $rech = "SELECT * FROM `" . TBDDED . "` WHERE `dded_do` = '1' ORDER BY dded_desc";
                            break;

                        // Si Demandeur = Centre de gestion
                        case 5 :
                            $rech = "SELECT * FROM `" . TBDDED . "` WHERE `dded_cge` = '1' ORDER BY dded_desc";
                            break;

                        // Si Demandeur = Agence
                        case 4 :
                            $rech = "SELECT * FROM `" . TBDDED . "` WHERE `dded_age` = '1' ORDER BY dded_desc";
                            break;

                        // Si Demandeur = Client
                        case 1 :
                            $rech = "SELECT * FROM `" . TBDDED . "` WHERE `dded_cli` = '1' ORDER BY dded_desc";
                            break;

                        // Si Demandeur = Opérateur
                        case 2 :
                            $rech = "SELECT * FROM `" . TBDDED . "` WHERE `dded_ope` = '1' ORDER BY dded_desc";
                            break;

                        // Si Demandeur = Technicien agence
                        case 3 :
                            $rech = "SELECT * FROM `" . TBDDED . "` WHERE `dded_tec` = '1' ORDER BY dded_desc";
                            break;
                    }
                } else {
                    $rech = "SELECT * FROM `" . TBDDED . "` WHERE `dded_pub` = '1' ORDER BY dded_desc";
                }
                $rows = $db->get_results($rech, ARRAY_A);
                $db->disconnect();
                cre_select_tab('dest', 'dest', $rows, 'dded_code', 'dded_desc', '', '', '', _("-- Faites votre choix --"));
                ?>
            </td>
        </tr>
    </table>
    <br />

    <!-- détails expéditeur-->
    <table width="100%" border="0">
        <tr>
            <td class="rubfrm" align="center">
                <?PHP echo _("Vos coordonnées"); ?>
            </td>
        </tr>
    </table>

    <!-- Catégorie -->
    <?PHP
    // Espace privé
    if (@$_SESSION["niv_log"] <> "") {
        ?>
        <input name="cat" type="hidden" id="cat" value="<?PHP echo str_majuscules($ddeur); ?>">
    <?PHP
    } else {
        ?>
        <table width="100%" border="0">
            <tr>
                <td width="160" class="rubfrm" id="f_cat" align="right"><?PHP echo _("Vous êtes"); ?></td>
                <td>
                    <?PHP
                    // création de la liste des catégories de demandeurs (espace privé uniquement)
                    $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
                    $rech = "SELECT ddec_code,ddec_desc FROM `" . TBDDEC . "` WHERE `ddec_pub` = '0' ORDER BY ddec_desc";
                    $rows = $db->get_results($rech, ARRAY_A);
                    $db->disconnect();
                    cre_select_tab('cat', 'cat', $rows, 'ddec_code', 'ddec_desc', '', '', '', _("-- Faites votre choix --"));
                    ?>
                </td>
            </tr>
        </table>
    <?PHP
    }
    ?>

    <!-- Coordonnées -->
    <table width="100%" border="0">
        <tr>
            <td width="160" class="rubfrm" id="f_ste" align="right"><?PHP echo _("Société"); ?></td>
            <td>
                <input name="ste" type="text" id="ste" value="<?PHP echo $ste ?>" size="50" maxlength="50">
            </td>
        </tr>
        <tr>
            <td width="160" class="rubfrm" id="f_civilite" 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('civilite', 'civilite', $rows, 'civ_code', 'civ_desc', '', $civilite, '', _("-- Faites votre choix --"));
                ?>
            </td>
        </tr>
        <tr>
            <td width="160" class="rubfrm" id="f_prenom" align="right"><?PHP echo _("Prénom"); ?></td>
            <td>
                <input name="prenom" type="text" id="prenom" value="<?PHP echo $prenom ?>" size="50"">
                <img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo _("Champ obligatoire"); ?>">
            </td>
        </tr>
        <tr>
            <td width="160" class="rubfrm" id="f_nom" align="right"><?PHP echo _("Nom"); ?></td>
            <td>
                <input name="nom" type="text" id="nom" value="<?PHP echo $nom ?>" size="50">
                <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 $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 $adr2 ?>" size="50">
            </td>
        </tr>
        <tr>
            <td class="rubfrm" id="f_pays" align="right"><?PHP echo _("Pays"); ?></td>
            <td>
                <?PHP
                if (@$_SESSION["niv_log"] == "") // Espace publique
                {
                    // 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', '', $pays, '', _("-- Faites votre choix --"), 1, FALSE, '-1', _("-- Inconnu --"));
                } else {
                    echo '<input name="pays" type="hidden" id="pays" value="' . $pays . '">';
                    echo '<input name="npays" type="text" id="npays" value="' . str_majuscules(Retournepays($pays, TRUE)) . '" size="50" readonly>';
                }
                ?>
            </td>
        </tr>
        <tr>
            <td class="rubfrm" id="f_dep" align="right"><?PHP echo _("Département"); ?></td>
            <td>
                <?PHP
                if (@$_SESSION["niv_log"] == "") // Espace publique
                {
                    // Création de la liste des départements
                    $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
                    $rech = "SELECT dep_code FROM `" . TBDEP . "` WHERE `dep_codepays`='" . $pays . "' 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', $dep, '', _("-- Faites votre choix --"), 1, FALSE, '-1', _("-- Inconnu --"));
                } else {
                    $dep_nom = Retournedep($dep, $pays, TRUE);
                    if ($dep_code <> $dep_nom)
                        $ndep = $dep . " (" . $dep_nom . ")";
                    else
                        $ndep = $dep_nom;
                    echo '<input name="dep" type="hidden" id="dep" value="' . $dep . '">';
                    echo '<input name="ndep" type="text" id="ndep" value="' . str_majuscules($ndep) . '" size="50" readonly>';
                }
                ?>
            </td>
        </tr>
        <tr>
            <td class="rubfrm" id="f_ville" align="right"><?PHP echo _("Ville"); ?></td>
            <td>
                <?PHP
                if (@$_SESSION["niv_log"] == "") // Espace publique
                {
                    // Création de la liste des villes
                    $rech = "";
                    if ($dep <> "") {
                        if ($dep <> "-1") {
                            $filtre = $cli_dep;
                            if (($filtre == "2A") OR ($filtre == "2B"))
                                $filtre = "20";
                            $rech = "SELECT * FROM `" . TBVILLES . "` WHERE `villes_dep` = '" . str_majuscules($filtre) . "' AND `villes_codepays`='" . str_majuscules($pays) . "' ORDER BY villes_nom";
                        } else {
                            $rech = "SELECT * FROM `" . TBVILLES . "` WHERE `villes_codepays`='" . str_majuscules($pays) . "' ORDER BY villes_nom";
                        }
                    }
                    $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
                    if ($rech <> "")
                        $rows = $db->get_results($rech, ARRAY_A);
                    $db->disconnect();
                    cre_select_tab('ville', 'ville', $rows, 'villes_id', 'villes_nom', 'villes_cp', $ville, '', _("-- Faites votre choix --"), 1, FALSE, '-1', _("-- Inconnu --"));
                } else {
                    echo '<input name="ville" type="hidden" id="ville" value="' . $ville . '">';
                    echo '<input name="nville" type="text" id="nville" value="' . Retourneville_Id($ville, TRUE) . " (" . Retournecp_Id($ville, TRUE) . ")" . '" size="40" readonly>';
                }
                ?>
            </td>
        </tr>
        <tr>
            <td class="rubfrm" id="f_telf" align="right"><?PHP echo _("Téléphone Fixe"); ?> </td>
            <td>
                <input name="telf" type="text" id="telf" value="<?PHP echo $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_fax" align="right"><?PHP echo _("Télécopieur"); ?></td>
            <td>
                <input name="fax" type="text" id="fax" value="<?PHP echo $fax ?>" size="20" maxlength="20">
            </td>
        </tr>
        <tr>
            <td class="rubfrm" id="f_telp" align="right"><?PHP echo _("Téléphone portable"); ?></td>
            <td>
                <input name="telp" type="text" id="telp" value="<?PHP echo $telp ?>" size="20" maxlength="20">
            </td>
        </tr>
        <tr>
            <td class="rubfrm" id="f_email" align="right"><?PHP echo _("Email"); ?></td>
            <td>
                <input name="email" type="text" id="email" value="<?PHP echo $email ?>" size="50" maxlength="50">
                <img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo _("Champ obligatoire"); ?>">
            </td>
        </tr>
        <?PHP
        // Site uniquement si demande client depuis espace privé
        if ((@$_SESSION["niv_log"] <> "") AND (@$_SESSION["niv_log"] == 1)) {
            ?>
            <tr>
                <td class="rubfrm" id="f_site" align="right"><?PHP echo _("Site concerné"); ?></td>
                <td>
                    <?PHP
                    echo '<select name="site" size="1" id="site">';
                    echo "<option>" . _("-- Faites votre choix --") . "</option>";
                    echo "<option value=\"-1\">" . _("-- Aucun site en particulier --") . "</option>";
                    echo "<option value=\"0\">" . _("-- Faites votre choix --") . "</option>";

                    // création de la liste des site actifs du client
                    $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
                    $rech = "SELECT * FROM `" . TBSCLI . "` WHERE `scli_codecli` = '" . @$_SESSION["code_log"] . "' AND `scli_actif`='1' ORDER BY scli_ste";
                    $rows = $db->get_results($rech, ARRAY_A);
                    if (($rows) AND (count($rows) > 0)) {
                        foreach ($rows as $row) {
                            $row = encode_str($row);
                            extract($row);
                            $txt_scli = str_majuscules($scli_ste) . ", " . str_majuscules($scli_adr1);
                            if (trim($scli_adr2) <> "")
                                $txt_scli .= " " . $scli_adr2;
                            $txt_scli .= ", " . Retournecp_Id($scli_ville, FALSE) . " " . Retourneville_Id($scli_ville, FALSE);
                            $txt_scli .= " (" . $scli_telf . ")";
                            echo '<option value="' . $scli_id . '">' . $txt_scli . '</option>';
                        }
                    }
                    $db->disconnect();
                    echo '</select>';
                    echo ' <img src="../img/oblig.png" align="absmiddle" alt="' . _("Champ obligatoire") . '">';
                    ?>
                </td>
            </tr>
        <?PHP
        }
        ?>
        <tr>
            <td class="rubfrm" id="f_urg" align="right"><?PHP echo _("Niveau d'urgence"); ?></td>
            <td>
                <?PHP
                // création de la liste des Niveaux d'urgence
                $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
                $rech = "SELECT * FROM `" . TBURG . "` ORDER BY urg_niveau";
                $rows = $db->get_results($rech, ARRAY_A);
                $db->disconnect();
                cre_select_tab('urgence', 'urgence', $rows, 'urg_niveau', 'urg_des', '', '');
                ?>
            </td>
        </tr>
    </table>
    <br />
    <!-- Texte de la demande -->
    <table width="100%" border="0">
        <tr>
            <td class="rubfrm" id="f_txtdde" align="center"><?PHP echo _("Votre message"); ?>
                <img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo _("Champ obligatoire"); ?>">
            </td>
        </tr>
        <tr>
            <td>
                <textarea name="txtdde" rows="5" id="txtdde"><?PHP echo $txtdde ?></textarea>
            </td>
        </tr>
    </table>

    <p align="center">
        <?PHP
        echo '<input name="enr" type="button" class="bton_std" id="enr" value="'._("Envoyer").'">';
        echo '<input name="RAZ" type="reset" class="bton_std" id="RAZ" value="'._("Réinitialiser").'">';
        ?>
    </p>
    </form>
    <!-- Fin affiché uniquement si demande cohérente -->
<?PHP
} else
    pop_ret_auto(_("Problème de paramètres"), 'warn', "index.php");
include_once("pied.php");
?>
</body>
</html>