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

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

include_once('../inc/fic_droits.inc.php');
include_once('../inc/fic_hum.inc.php');
include_once('../inc/fic_mque.inc.php');
include_once('../inc/func.inc.php');
include_once('../inc/func_geo.inc.php');
include_once('../inc/func_geol.inc.php');
include_once('../inc/func_txt.inc.php');
include_once('../classes/geoplugin/geoplugin.class.php');
include_once('../classes/ezSQL/shared/ez_sql_core.php');
include_once('../classes/ezSQL/mysqli/ez_sql_mysqli.php');
include_once('../inc/func_sql.inc.php');
Archivelog(valsession('code_log'));
// Variables Formulaire
fix_magic_quotes();
$_GET = clean_str($_GET);

$td = $_GET['td'];
$coderech = $_GET['code'];

$pbm_rlpm = FALSE;

if (valsession('niv_log') < 3) {
    $pbm_rlpm = TRUE;
}

$mquen_nota = '';
$codeuser = valsession('code_log');
if (CheckNivLog('3')) {
    $codeuser = valsession('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);
        $row2 = lit_enr_MqueNPriv($coderech, $codeuser);
        if (is_array($row2)) {
            $row2 = encode_str($row2);
            extract($row2);
        }
    } else {
        $pbm_rlpm = TRUE;
    }
} else {
    if ($td == 'add') {
        $mque_code = '';
        $mque_ste = '';
        $mque_codepays = pays_connect_code($_SERVER['REMOTE_ADDR']);
    } else {
        $pbm_rlpm = TRUE;
    }
}

$titre = '';
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 (valsession('niv_log') >= 5)
            {
            ?>
            "nom:notaa ; format:txt ; req:N ; txt:<?php echo _('Notes administration'); ?> ; stok:frmok ; stbad:frmbad",
            <?php
            }
            if (valsession('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','".valsession('date_fmtshort')."',tab1_champ,'pays','');";
                        break;
                    case 'edit' :
                        echo "init_valid_form('enr','mque_maj','".valsession('date_fmtshort')."',tab1_champ,'pays','');";
                        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) {
        cre_ent_form($titre, '', '', '', FALSE);
        ?>
        <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, 'utf8');
                        $rech = 'SELECT * FROM `' . TBMQUET . '`';
                        $rows = $db->get_results($rech, ARRAY_A);
                        close_database();
                        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
                        $rows = give_rows_pays();
                        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
                        $rows = give_rows_dep($mque_codepays);
                        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
                        $rows = give_rows_villes($mque_dep, $mque_codepays);
                        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 (valsession('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 (CheckNivLog('3-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 (valsession('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>