<?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/fic_droits.inc.php");
include_once("fic_hum.inc.php");
include_once("fic_mque.inc.php");
include_once("func.inc.php");
include_once("func_geo.inc.php");
include_once("func_geol.inc.php");
include_once("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'];

$pbm_rlpm = FALSE;

if (@$_SESSION["niv_log"] < 3)
    $pbm_rlpm = TRUE;

$mquen_nota = "";
$codeuser = @$_SESSION["code_log"];
if (@$_SESSION["niv_log"] == 3)
{
    $codeuser = @$_SESSION["code_age"];
    $td= "view";
}

if ($coderech <> "") {
    // vérification qu'il existe bien des contacts et nombre de ceux-ci
    $nbcontacts = nb_cmque_in_mque($coderech);

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

    $row = lit_enr_mque($coderech, TRUE);
    if (is_array($row)) {
        $row = encode_str($row);
        extract($row);
        $row = lit_enr_MqueNPriv($coderech, $codeuser);
        if (is_array($row)) {
            $row = encode_str($row);
            extract($row);
        }
    } else
        $pbm_rlpm = TRUE;
} else {
    if ($td == "add") {
        $mque_code = "";
        $mque_ste = "";
        $mque_codepays = pays_connect_code($_SERVER['REMOTE_ADDR']);
    } else
        $pbm_rlpm = TRUE;
}
switch ($td) {
    case "add" :
        $titre = _("AJOUT FABRIQUANT/EDITEUR/DISTRIBUTEUR/ASSUREUR");
        break;
    case "edit" :
        $titre = _("MODIFICATION FABRIQUANT/EDITEUR/DISTRIBUTEUR/ASSUREUR");
        break;
    case "view" :
        $titre = _("VISUALISATION FABRIQUANT/EDITEUR/DISTRIBUTEUR/ASSUREUR");
        break;
    case "del" :
        $titre = _("SUPPRESSION FABRIQUANT/EDITEUR/DISTRIBUTEUR/ASSUREUR");
        break;
    default :
        $pbm_rlpm = 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 _("Relevés - Fiche Marque"); ?></title>

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

    <script language="javascript">
        <!--
        var tab1_champ = ["nom:type; format:liste ; req:Y ; txt:<?PHP echo _("Type"); ?> ; vmn:1 ; stok:frmok ; stbad:frmbad",
            "nom:code ; format:alphanum ; req:Y ; txt:<?PHP echo _("Code"); ?> ; lmx:20 ; stok:frmok ; stbad:frmbad",
            "nom:ste; format:txt ; req:Y ; txt:<?PHP echo _("Nom"); ?> ; 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: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",
            "nom:ville ; format:liste ; req:Y ; txt:<?PHP echo _("Ville"); ?> ; vmn:1; stok:frmok ; stbad:frmbad",
            "nom:dep ; format:liste ; req:Y ; txt:<?PHP echo _("Département"); ?>; vmn:1 ; stok:frmok ; stbad:frmbad",
            "nom:pays ; format:liste ; req:Y ; txt:<?PHP echo _("Pays"); ?> ; vmn:1; stok:frmok ; stbad:frmbad",
            "nom:telf ; format:tel ; req:Y ; txt:<?PHP echo _("Téléphone Fixe"); ?>; stok:frmok ; stbad:frmbad",
            <?PHP if (@$_SESSION["niv_log"] >= 5)
            {
            ?>
            "nom:notaa ; format:txt ; req:N ; txt:<?PHP echo _("Notes administration"); ?> ; stok:frmok ; stbad:frmbad",
            <?PHP
            }
            if (@$_SESSION["niv_log"] >= 3)
            {
            ?>
            "nom:notat ; format:txt ; req:N ; txt:<?PHP echo _("Notes techniques"); ?> ; stok:frmok ; stbad:frmbad",
            <?PHP
            }
            ?>
            "nom:fax ; format:tel ; req:N ; txt:<?PHP echo _("Télécopieur"); ?>; stok:frmok ; stbad:frmbad"];
        //-->
    </script>

    <?PHP if ($pbm_rlpm == FALSE) { ?>
        <script type="text/javascript">
            <!--
            $(function () {
                $("#code").Setcase({caseValue: 'upper', changeonFocusout: true});
                $("#ste").Setcase({caseValue: 'upper', changeonFocusout: true});
                $("#rcs").Setcase({caseValue: 'upper', changeonFocusout: true});
                $("#ape").Setcase({caseValue: 'upper', changeonFocusout: true});
                $("#tvai").Setcase({caseValue: 'upper', changeonFocusout: true});
                $("#adr1").Setcase({caseValue: 'upper', changeonFocusout: true});
                $("#adr2").Setcase({caseValue: 'upper', changeonFocusout: true});
            });

            function init_all() {
                init_Body();
                <?php
                switch ($td)
                {
                    case "add" :
                        echo "init_valid_form('enr','mque_maj','".$_SESSION['date_fmtshort']."',tab1_champ,'','');";
                        break;
                    case "edit" :
                        echo "init_valid_form('enr','mque_maj','".$_SESSION['date_fmtshort']."',tab1_champ,'','');";
                        echo "readonly_id('code',false);";
                        echo "init_fensaisie('add_cmque',950,560);";
                        echo "init_fensaisie('edit_cmque',950,560);";
                        echo "init_fensaisie('add_lnk',950,560);";
                        echo "init_fensaisie('edit_lnk',950,560);";
                        break;
                    case "del" :
                        echo "readonly_all();";
                        echo "warn_del();";
                        break;
                    case "view" :
                        echo "readonly_all();";
                        break;
                }
                ?>
                init_ajax_ville();
                init_ajax_dep();
                Focus_first();
            }

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

    <?PHP } ?>
</head>

<body>

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

if ($pbm_rlpm == FALSE) {
    if (nb_civ() <> 0) {
        ?>
        <p align="center"><span class="titrepage"><?PHP echo $titre ?></span></p>
        <table width="100%" border="0">
            <tr>
                <td width="33%"
                    class="annot_gras_it"><?PHP aff_lnk_lst_rech('mque_lst.php', _("Retour à la liste"), $_SERVER['HTTP_REFERER'], _("Retour à la page précédente")); ?></td>
                <td width="33%">&nbsp;</td>
                <td width="33%" align="right">&nbsp;</td>
            </tr>
        </table>
        <table width="100%" border="0">
            <tr>
                <td width="31%">
                    <?PHP if ($td == "edit") {
                        $url_crlpma = "cmque_maj.php?td=add&cm=" . $mque_code . "&tx=mque";
                        cre_falselnk('', 'add_cmque', 'span', '', _("Ajouter un contact"), $url_crlpma, '../img/ctacts.png', _("Ajouter un contact"));

                        $url_crlpma = "cmque_maj.php?td=lst&cm=" . $mque_code . "&tx=mque";
                        if (nb_cmque_in_mque($mque_code) == 0)
                            echo '<span id="ctact" style="display:none">';
                        else
                            echo '<span id="ctact" style="display:inline">';
                        cre_falselnk('', 'edit_cmque', 'span', '', _("Edition contacts"), $url_crlpma, '', _("Edition contacts"),true);
                        echo '</span>';
                    }
                    ?>
                </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="30%" align="right">
                    <?PHP if ($td == "edit") {
                        $url_wrlpma = "wmque_maj.php?td=add&cm=" . $mque_code;
                        cre_falselnk('', 'add_lnk', 'span', '', _("Ajouter un lien"), $url_wrlpma, '../img/web_link.png', _("Ajouter un lien"));

                        $url_wrlpma = "wmque_maj.php?td=lst&cm=" . $mque_code;
                        if (nb_wmque_in_mque($mque_code) == 0)
                            echo '<span id="wmque" style="display:none">';
                        else
                            echo '<span id="wmque" style="display:inline">';

                        echo ' / ';
                        cre_falselnk('', 'edit_lnk', 'span', '', _("Edition liens"), $url_wrlpma, '', _("Edition liens"));
                        echo '</span>';
                    }
                    ?>
                </td>
            </tr>
        </table>
        <table width="100%" border="0">
            <tr>
                <td width="31%">&nbsp;

                </td>
                <td width="39%" valign="top">&nbsp;

                </td>
                <td width="30%" align="right">
                    <?PHP
                    if ($td == "edit")
                        echo "<a href=\"retp_maj.php?td=add&cm=" . $mque_code . "\"><img src=\"../img/retp.png\" border=\"0\" align=\"absmiddle\" title=\"" . _("Saisir produit à retourner") . "\"> " . _("Saisir produit à retourner") . "</a>";
                    else
                        echo "&nbsp;";
                    ?>
                </td>
            </tr>
        </table>
        <br />
        <form id="mque_maj"  name="mque_maj" method="post" action="mque_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="">
            <table width="100%" border="0">
                <tr>
                    <td class="rubfrm" id="f_type" width="160" align="right"><?PHP echo _("Type"); ?></td>
                    <td>
                        <?PHP
                        $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
                        $rech = "SELECT * FROM `" . TBMQUET . "`";
                        $rows = $db->get_results($rech, ARRAY_A);
                        $db->disconnect();
                        cre_select_tab('type', 'type', $rows, 'mquet_code', 'mquet_desc', '', $mque_codemquet, '', _("-- Faites votre choix --"), 1, FALSE, '', "-- Inconnu --");
                        ?>
                    </td>
                </tr>
                <tr>
                    <td class="rubfrm" id="f_code" align="right"><?PHP echo _("Code"); ?></td>
                    <td>
                        <input name="code" type="text" id="code" value="<?PHP echo $mque_code ?>" size="20" maxlength="20">
                        <?PHP if ($td == "add")
                            echo' <img src="../img/oblig.png" align="absmiddle" alt="'._("Champ obligatoire").'">';
                        ?>
                    </td>
                </tr>
                <tr>
                    <td class="rubfrm" id="f_desc" align="right"><?PHP echo _("Nom"); ?></td>
                    <td><input name="ste" type="text" id="ste" value="<?PHP echo $mque_ste ?>" 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 $mque_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 $mque_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 $mque_tvai ?>" size="50">
                    </td>
                </tr>
                <tr>
                    <td class="rubfrm" id="f_adr1" align="right"><?PHP echo _("Adresse"); ?></td>
                    <td>
                        <input name="adr1" type="text" id="adr1" value="<?PHP echo $mque_adr1 ?>" size="50">
                        <img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo _("Champ obligatoire"); ?>">
                    </td>
                </tr>
                <tr>
                    <td class="rubfrm" id="f_adr2" align="right"><?PHP echo _("Adresse (2)"); ?></td>
                    <td>
                        <input name="adr2" type="text" id="adr2" value="<?PHP echo $mque_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', '', $mque_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`='" . $mque_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', $mque_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 ($mque_dep <> "") {
                            if ($mque_dep <> "-1") {
                                $filtre = $mque_dep;
                                if (($filtre == "2A") OR ($filtre == "2B"))
                                    $filtre = "20";
                                $rech = "SELECT * FROM `" . TBVILLES . "` WHERE `villes_dep` = '" . str_majuscules($filtre) . "' AND `villes_codepays`='" . str_majuscules($mque_codepays) . "' ORDER BY villes_nom";
                            } else {
                                $rech = "SELECT * FROM `" . TBVILLES . "` WHERE `villes_codepays`='" . str_majuscules($mque_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', $mque_ville, '', _("-- Faites votre choix --"), 1, FALSE, '-1', _("-- Inconnu --"));
                        ?>
                    </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 $mque_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 $mque_fax ?>" size="20" maxlength="20">
                    </td>
                </tr>
                <?PHP if (@$_SESSION["niv_log"] >= 5) {
                    ?>
                    <tr>
                        <td class="rubfrm" id="f_notaa" align="right"><?PHP echo _("Notes Administration"); ?></td>
                        <td>
                            <textarea name="notaa" rows="5" id="notaa"><?PHP echo $mque_notaa ?></textarea>
                        </td>
                    </tr>
                <?PHP
                }
                ?>
                <tr>
                    <td height="37" class="rubfrm" id="f_notat"
                        align="right"><?PHP echo _("Notes publiques Agences"); ?><br /><span
                            class="annot_petit_it">(<?PHP echo _("Saisies par l'administrateur ou"); ?>
                            <br /><?PHP echo _("le centre de gestion"); ?>)</span></td>
                    <td>
                        <textarea name="notat" rows="5"
                                  id="notat" <?PHP if ((@$_SESSION["niv_log"] == 3) OR (@$_SESSION["niv_log"] == 4)) {
                            echo "readonly=\"readonly\"";
                        } ?>><?PHP echo $mque_notat ?></textarea>
                    </td>
                </tr>
                <tr>
                    <td height="37" class="rubfrm" id="f_notap">
                        <div align="right"><?PHP echo _("Notes Personnelles"); ?><br /><span
                                class="annot_petit_it">(<?PHP echo _("Pour les techniciens ce sont"); ?>
                                <br /><?PHP echo _("celles de leur agence"); ?>)</span></div>
                    </td>
                    <td>
                        <textarea name="notap" rows="5" id="notap"><?PHP echo $mquen_nota ?></textarea>
                    </td>
                </tr>
            </table>
            <p align="center">
            <?PHP
            switch ($td)
            {
                case "add" :
                case "edit" :
                    echo '<input name="enr" type="button" class="bton_std" id="enr" value="'._("Valider").'">';
                    break;
                case "del" :
                    echo '<input name="del" type="submit" class="bton_std" id="del" value="'._("Supprimer").'">';
                    break;
            }
            if ($td <> 'view')
                echo '<input name="RAZ" type="reset" class="bton_std" id="RAZ" value="'._("Réinitialiser").'">';
            ?>
            </p>
        </form>
    <?PHP
    } else {
        if (@$_SESSION["niv_log"] >= 5) {
            if (nb_fonc() == 0)
                pop_ret_auto(_("Aucune fonction"), 'warn', 'fonc_lst.php');
        } else
            pop_ret_auto(_("SMI n'est pas configuré") . '<br />' . _("Merci de contacter l'administrateur ou le centre de gestion"), 'warn', "index.php");
    }
} else
    pop_ret_auto(_("Problème de paramètres"), 'warn', "mque_lst.php");
include_once("pied.php");
?>
</body>
</html>