<?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_age.inc.php');
include_once('../inc/fic_cli.inc.php');
include_once('../inc/fic_droits.inc.php');
include_once('../inc/fic_int.inc.php');
include_once('../inc/fic_pdt.inc.php');
include_once('../inc/fic_zc.inc.php');
include_once('../inc/func.inc.php');
include_once('../inc/func_date.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(valsession('code_log'));
// Variables Formulaire
fix_magic_quotes();
$_GET = clean_str($_GET);

$export_ok = TRUE;
$retour_idx = FALSE;

$td = valget('td'); // On récupère le type en ligne de commande

// vérification du mode du connecté (pour éviter les hacks)
switch ($td) {
    case 'cli' :
    case 'scli' :
        // Clients et sites clients : export uniquement sur agences, centre de gestion, administrateur
        if (valsession('niv_log') <= 3) {
            $export_ok = FALSE;
        }
        break;
    case 'art' :
        // Articles  : export uniquement sur centre de gestion, administrateur
        if (valsession('niv_log') <= 4) {
            $export_ok = FALSE;
        }
        break;
    case 'int' :
        // Interventions : export uniquement sur administrateur
        if (valsession('niv_log') <> 9) {
            $export_ok = FALSE;
        }
        break;
    default :
        $export_ok = FALSE;
        break;
}

$titre = '';
if ($export_ok == TRUE) {
    switch ($td) {
        case 'cli' :
            $titre = _('EXPORTATION CLIENTS');
            break;
        case 'scli' :
            $titre = _('EXPORTATION SITES CLIENTS');
            break;
        case 'art' :
            $titre = _('EXPORTATION ARTICLES');
            break;
        case 'int' :
            $titre = _('EXPORTATION INTERVENTIONS');
            break;
        default :
            $export_ok = FALSE;
            break;
    }
}

$lst_id_readonly = '';
$age = '';
$tab_zc = [];
if (CheckNivLog('4')) {
    $lst_id_readonly = 'age-pays';
    $age = valsession('code_age');
    $tab_zc = tab_zcc_age_open_full($_SESSION['code_age'], TRUE);
}
?>
<!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 _('Exportation'); ?></title>

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

    <script language="javascript">
    <!--
    <?php
    switch ($td) {
        case 'cli' :
        case 'scli' :
        ?>
            var tab1_champ = ["nom:cat ; format:liste ; req:Y ; txt:<?php echo _('Catégorie'); ?> ; vmn:1 ; stok:frmok ; stbad:frmbad",
                <?php if (valsession('niv_log') <> 4)
                {
                ?>
                "nom:age ; format:liste ; req:Y ; txt:<?php echo _('Agence'); ?> ; vmn:1 ; stok:frmok ; stbad:frmbad",
                "nom:pays ; format:liste ; req:Y ; txt:<?php echo _('Pays'); ?> ; vmn:1 ; stok:frmok ; stbad:frmbad",
                <?php
                }
                else
                {
                ?>
                "nom:age ; format:alphanum ; req:Y ; txt:<?php echo _('Agence'); ?> ; stok:frmok ; stbad:frmbad",
                "nom:pays ; format:alphanum ; req:Y ; txt:<?php echo _('Pays'); ?> ; stok:frmok ; stbad:frmbad",
                <?php
                }
                ?>
                "nom:dep[] ; format:listem ; req:Y ; txt:<?php echo _('Départements'); ?> ; vmn:1 ; stok:frmok ; stbad:frmbad",
                "nom:champs[] ; format:checkbox ; req:Y ; txt:<?php echo _('Champs'); ?> ; stok:frmok ; stbad:frmbad"];
        <?php
        break;
        case 'art' :
        ?>
            var tab1_champ = ["nom:cat ; format:liste ; req:Y ; txt:<?php echo _('Catégorie'); ?> ; vmn:1 ; stok:frmok ; stbad:frmbad",
                "nom:fam[] ; format:listem ; req:N ; txt:<?php echo _('Familles'); ?> ; vmn:1 ; stok:frmok ; stbad:frmbad",
                "nom:champs[] ; format:checkbox ; req:Y ; txt:<?php echo _('Champs'); ?> ; stok:frmok ; stbad:frmbad"];
        <?php
        break;
        case 'int' :
        ?>
            function init_datepicker() {
                <?php include_once ('../jscript/datepicker_prm.js.php'); ?>
                $("#date1f").datepicker({
                    onSelect: function (datesel) {
                        $("#date1f").blur();
                        chk_datedif(datesel, this.id, '<?php echo valsession('date_fmtshort'); ?>', true, '', '', 'date2f', false);
                    }
                });
                $("#date2f").datepicker({
                    beforeShow: function() {
                        var mindate = $('#date1f').datepicker('getDate');
                        $(this).datepicker('option', 'minDate', mindate);
                    },
                    onSelect: function (datesel) {
                        $("#date2f").blur();
                        chk_datedif(datesel, this.id, '<?php echo valsession('date_fmtshort'); ?>', true, 'date1f', '', 'today', false);
                    }
                });
            }

            var tab1_champ = ["nom:cat ; format:liste ; req:Y ; txt:<?php echo _('Catégorie'); ?> ; vmn:1 ; stok:frmok ; stbad:frmbad",
                "nom:age ; format:liste ; req:Y ; txt:<?php echo _('Agence'); ?> ; vmn:1 ; stok:frmok ; stbad:frmbad",
                "nom:date1f ; format:date ; req:Y ; txt:<?php echo _('Date de demande (début)'); ?> ; masque:<?php echo $_SESSION['date_fmtfull']; ?> ; stok:frmok ; stbad:frmbad",
                "nom:date2f ; format:date ; req:Y ; txt:<?php echo _('Date de demande (fin)'); ?> ; masque:<?php echo $_SESSION['date_fmtfull']; ?> ; stok:frmok ; stbad:frmbad"];
        <?php
        break;
    }
    ?>

        function init_all() {
            init_Body();
            <?php
            switch ($td) {
                case 'int' :
                    echo 'init_datepicker();';
                    echo "init_autoraz('razdate1f', 'date1f', 'click');";
                    echo "init_autoraz('razdate2f', 'date2f', 'click');";
                    break;
                case 'cli' :
                case 'scli' :
                    echo 'init_ajax_dep_zc_pays_3();';
                    echo 'init_ajax_dep_zc_pays_4();';
                    echo "init_txtfromvalsel('dep', 'deptxt', 'click');";
                    break;
                case 'art' :
                    echo "init_txtfromvalsel('fam', 'famtxt', 'click');";
                    break;
                default :
                    break;
            }
            ?>
            readonly_id('<?php echo $lst_id_readonly; ?>', false);
            init_autohref('quit', 'click', 'index.php', false);
            init_valid_exp('exp', 'exp_maj', '<?php echo valsession('date_fmtshort'); ?>', tab1_champ, '', '');
            Focus_first();
        }

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

</head>

<body>
<?php
include_once('../inc/entete.inc.php');
cre_ent_form($titre, '', '', '', FALSE);
if ($export_ok == TRUE) {
    ?>
    <!-- Formulaire permettant la sélection l'exportation -->
    <form name="exp_maj" id="exp_maj" method="post" action="export.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="today" type="hidden" id="today" value="<?php echo $datef; ?>">
    <input name="nbutton" type="hidden" id="nbutton" value="">
    <?php
    switch ($td) {
        /******************************************************/
        /**                    CLIENTS                       **/
        /******************************************************/

        case 'cli' :
            if (nb_cli('')) {
                $url_link = 'exp_data.php?td=cli';
                ?>
                <!-- Liste des catégories -->
                <table width="100%" border="0">
                    <tr>
                        <td width="160" class="rubfrm" id="f_cat" align="right"><?php echo _('Catégorie'); ?></td>
                        <td>
                            <?php
                            // création de la liste des catégories
                            $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST, 'utf8');
                            $rech = 'SELECT * FROM `' . TBCCAT . '` ORDER BY cat_desc';
                            $rows = $db->get_results($rech, ARRAY_A);
                            close_database();
                            $tab_first_options = [
                                '*' => _('-- TOUTES LES CATEGORIES --')
                            ];
                            cre_select_tab('cat', 'cat', $rows, 'cat_code', 'cat_desc', '', $cat, '', _('-- Faites votre choix --'), 1, FALSE, '', '', TRUE, TRUE, FALSE, $tab_first_options);
                            ?>
                        </td>
                    </tr>
                    <tr>
                        <td width="160" class="rubfrm" id="f_age" align="right"><?php echo _('Agence'); ?></td>
                        <td>
                            <?php
                            // création de la liste des agences
                            $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST, 'utf8');
                            $rech = 'SELECT * FROM `' . TBAGE . "` WHERE `age_ouvert` = '1' ORDER BY age_nom";
                            $rows = $db->get_results($rech, ARRAY_A);
                            close_database();
                            $tab_first_options = [
                                '*' => _('-- TOUTES LES AGENCES --')
                            ];
                            cre_select_tab('age', 'age', $rows, 'age_code', 'age_nom', '', $age, '', _('-- Faites votre choix --'), 1, FALSE, '', '', TRUE, TRUE, FALSE, $tab_first_options);
                            ?>
                        </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', '', $age, '', _('-- Faites votre choix --'), 1, FALSE, '-1', _('-- Inconnu --'));
                            ?>
                        </td>
                    </tr>
                    <tr>
                        <td width="160" class="rubfrm" id="f_dep"
                            align="right"><?php echo _('Département/Région'); ?></td>
                        <td>
                            <?php
                            // création de la liste des Départements
                            cre_select('dep[]', 'dep', $tab_zc, '', '', _('-- Faites votre choix --'), 5, TRUE);
                            if (CheckNivLog('4')) {
                                echo '(' . _('Départements couverts par votre agence') . ')';
                            } else {
                                echo '(' . _('Départements couverts par les agences') . ')';
                            }
                            ?>
                            <input name="deptxt" type="hidden" id="deptxt" value="<?php echo $dep ?>" size="50"
                                   readonly>
                        </td>
                    </tr>
                </table>
                <br/>
                <?php
            } else {
                $retouridx = TRUE;
            }
            break;

        /******************************************************/
        /**                 SITES CLIENTS                    **/
        /******************************************************/

        case 'scli' :
            if (nb_scli('', '', TRUE)) {
                $url_link = 'exp_data.php?td=scli';
                ?>
                <!-- Liste des catégories -->
                <table width="100%" border="0">
                    <tr>
                        <td width="160" class="rubfrm" id="f_cat" align="right"><?php echo _('Catégorie'); ?></td>
                        <td>
                            <?php
                            // création de la liste des catégories
                            $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST, 'utf8');
                            $rech = 'SELECT * FROM `' . TBCCAT . '` ORDER BY cat_desc';
                            $rows = $db->get_results($rech, ARRAY_A);
                            close_database();
                            $tab_first_options = [
                                '*' => _('-- TOUTES LES CATEGORIES --')
                            ];
                            cre_select_tab('cat', 'cat', $rows, 'cat_code', 'cat_desc', '', $cat, '', _('-- Faites votre choix --'), 1, FALSE, '', '', TRUE, TRUE, FALSE, $tab_first_options);
                            ?>
                        </td>
                    </tr>
                    <tr>
                        <td width="160" class="rubfrm" id="f_age" align="right"><?php echo _('Agence'); ?></td>
                        <td>
                            <?php
                            // création de la liste des agences
                            $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST, 'utf8');
                            $rech = 'SELECT * FROM `' . TBAGE . "` WHERE `age_ouvert` = '1' ORDER BY age_nom";
                            $rows = $db->get_results($rech, ARRAY_A);
                            close_database();
                            $tab_first_options = [
                                '*' => _('-- TOUTES LES AGENCES --')
                            ];
                            cre_select_tab('age', 'age', $rows, 'age_code', 'age_nom', '', $age, '', _('-- Faites votre choix --'), 1, FALSE, '', '', TRUE, TRUE, FALSE, $tab_first_options);
                            ?>
                        </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', '', $cli_codepays, '', _('-- Faites votre choix --'), 1, FALSE, '-1', _('-- Inconnu --'));
                            ?>
                        </td>
                    </tr>
                    <tr>
                        <td width="160" class="rubfrm" id="f_dep"
                            align="right"><?php echo _('Département/Région'); ?></td>
                        <td>
                            <?php
                            // création de la liste des Départements
                            cre_select('dep[]', 'dep', $tab_zc, '', '', _('-- Faites votre choix --'), 5, TRUE);
                            if (CheckNivLog('4')) {
                                echo '(' . _('Départements couverts par votre agence') . ')';
                            } else {
                                echo '(' . _('Départements couverts par les agences') . ')';
                            }
                            ?>
                            <input name="deptxt" type="hidden" id="deptxt" value="<?php echo $dep ?>" size="50"
                                   readonly>
                        </td>
                    </tr>
                </table>
                <br/>
                <?php
            } else {
                $retouridx = TRUE;
            }
            break;

        /******************************************************/
        /**                    ARTICLES                      **/
        /******************************************************/

        case 'art' :
            if (nb_pdt() > 0) {
                $url_link = 'exp_data.php?td=art';
                ?>
                <!-- Liste des catégories -->
                <table width="100%" border="0">
                    <tr>
                        <td width="160" class="rubfrm" id="f_cat" align="right"><?php echo _('Catégorie'); ?></td>
                        <td>
                            <?php
                            $tab_options = [
                                '*' => _('-- TOUTES LES CATEGORIES --'),
                                '1' => _('Vendus'),
                                '0' => _('Non vendus')
                            ];
                            cre_select('cat', 'cat', $tab_options, '', '', _('-- Faites votre choix --'));
                            ?>
                        </td>
                    </tr>
                    <tr>
                        <td width="160" class="rubfrm" id="f_dep" align="right"><?php echo _('Famille(s)'); ?></td>
                        <td>
                            <?php
                            // création de la liste des familles
                            $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST, 'utf8');
                            $rech = 'SELECT * FROM `' . TBFAM . '` ORDER BY fam_desc';
                            $rows = $db->get_results($rech, ARRAY_A);
                            close_database();
                            cre_select_tab('fam[]', 'fam', $rows, 'fam_code', 'fam_desc', '', $fam, '', _('-- Faites votre choix --'), 5, TRUE);
                            echo ' <input name="famtxt" type="hidden" id="famtxt" value="' . $fam . '" size="50" readonly>';
                            ?>
                        </td>
                    </tr>
                </table>
                <br/>
                <?php
            } else {
                $retouridx = TRUE;
            }
            break;

        /******************************************************/
        /**                 INTERVENTIONS                    **/
        /******************************************************/

        case 'int' :
            if (nb_int('')) {
                $url_link = 'exp_data.php?td=int';
                ?>
                <!-- Liste des catégories -->
                <table width="100%" border="0">
                    <tr>
                        <td width="160" class="rubfrm" id="f_cat" align="right"><?php echo _('Catégorie'); ?></td>
                        <td>
                            <?php
                            // création de la liste des catégories
                            $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST, 'utf8');
                            $rech = 'SELECT * FROM `' . TBINTC . '` ORDER BY intc_desc';
                            $rows = $db->get_results($rech, ARRAY_A);
                            close_database();
                            $tab_first_options = [
                                '*' => _('-- TOUTES LES CATEGORIES --')
                            ];
                            cre_select_tab('cat', 'cat', $rows, 'intc_code', 'intc_desc', '', $cat, '', _('-- Faites votre choix --'), 1, FALSE, '', '', TRUE, TRUE, FALSE, $tab_first_options);
                            ?>
                        </td>
                    </tr>
                    <tr>
                        <td width="160" class="rubfrm" id="f_age" align="right"><?php echo _('Agence'); ?></td>
                        <td>
                            <?php
                            // création de la liste des agences
                            $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST, 'utf8');
                            $rech = 'SELECT * FROM `' . TBAGE . "` WHERE `age_ouvert` = '1' ORDER BY age_nom";
                            $rows = $db->get_results($rech, ARRAY_A);
                            close_database();
                            $tab_first_options = [
                                '*' => _('-- TOUTES LES AGENCES --')
                            ];
                            cre_select_tab('age', 'age', $rows, 'age_code', 'age_nom', '', $age, '', _('-- Faites votre choix --'), 1, FALSE, '', '', TRUE, TRUE, FALSE, $tab_first_options);
                            ?>
                        </td>
                    </tr>
                    <tr>
                        <td width="30" class="rubfrm" id="f_date1f" align="right"><?php echo _('Du (Demande)'); ?>...</td>
                        <td>
                            <input name="date1f" type="text" id="date1f" size="10" maxlength="10" readonly>
                            <img src="../img/oblig.png" align="absmiddle" alt="<?php echo _('Champ obligatoire'); ?>">
                            <img src="../img/raz.png" id="razdate1f" border="0" align="absmiddle">
                        </td>
                    </tr>
                    <tr>
                        <td width="30" class="rubfrm" id="f_date2f" align="right"><?php echo _('Au (Demande)'); ?>...</td>
                        <td>
                            <input name="date2f" type="text" id="date2f" size="10" maxlength="10" readonly>
                            <img src="../img/oblig.png" align="absmiddle" alt="<?php echo _('Champ obligatoire'); ?>">
                            <img src="../img/raz.png" id="razdate2f" border="0" align="absmiddle">
                        </td>
                    </tr>
                </table>
                <br/>
                <?php
            } else {
                $retouridx = TRUE;
            }
            break;

        default :
            break;
    }

    if ($retouridx == FALSE) {
        ?>
        <table width="100%" border="0">
            <tr>
                <td colspan="5">
                    <div align="center" class="titre_std_gras_jaune_frouge"><?php echo _('Champs à exporter'); ?></div>
                </td>
            </tr>
            <?php
            $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST, 'utf8');
            switch ($td) {
                case 'cli' :
                    $rech = 'DESCRIBE `' . TBCLI . '`';
                    break;
                case 'scli' :
                    $rech = 'DESCRIBE `' . TBSCLI . '`';
                    break;
                case 'art' :
                    $rech = 'DESCRIBE `' . TBPDT . '`';
                    break;
                case 'int' :
                    $rech = 'DESCRIBE `' . TBINT . '`';
                    break;
            }
            $fields = $db->get_results($rech, ARRAY_A);
            $j= 0;
            foreach ($fields as $field) {
                if (($j <> 0) AND (($j % 5) == 0)) {
                    echo '<tr>';
                }
                $nom = $field['Field'];
                $aexporter = TRUE;
                switch ($td) {
                    /******************************************************/
                    /**                    CLIENTS                       **/
                    /******************************************************/

                    case 'cli' :
                        if (CheckNivLog('5')) {
                            if (($nom == 'cli_id') OR ($nom == 'cli_pass')) {
                                $aexporter = FALSE;
                            }
                        }
                        if (CheckNivLog('4')) {
                            if (($nom == 'cli_id') OR ($nom == 'cli_prop') OR ($nom == 'cli_codedo') OR ($nom == 'cli_codecrea') OR ($nom == 'cli_codemod') OR ($nom == 'cli_pass') OR ($nom == 'cli_notaa')) {
                                $aexporter = FALSE;
                            }
                        }
                        if ($aexporter == TRUE) {
                            $id_champ = 'f_' . $nom;
                            $nom_champ = 'cb_' . $nom;
                            echo '<td width="20%" id="' . $id_champ . '">';
                            echo '<input type="checkbox" name="champs[]" value="' . $nom . '" style="background : #FFFFFF;" checked>';
                            echo $nom;
                            if ($nom == 'cli_ville') {
                                echo ' (CP + Ville)';
                            }
                            $j++;
                        }
                        break;
                    /******************************************************/
                    /**                 SITES CLIENTS                    **/
                    /******************************************************/

                    case 'scli' :
                        if (CheckNivLog('5')) {
                            if ($nom == 'scli_id') {
                                $aexporter = FALSE;
                            }
                        }
                        if (CheckNivLog('4')) {
                            if ($nom == 'scli_id') {
                                $aexporter = FALSE;
                            }
                        }
                        if ($aexporter == TRUE) {
                            $id_champ = 'f_' . $nom;
                            $nom_champ = 'cb_' . $nom;
                            echo '<td width="20%" id="' . $id_champ . '">';
                            echo '<input type="checkbox" name="champs[]" value="' . $nom . '" style="background : #FFFFFF;" checked>';
                            echo $nom;
                            if ($nom == 'scli_ville') {
                                echo ' (CP + Ville)';
                            }
                            $j++;
                        }
                        break;
                    /******************************************************/
                    /**                    ARTICLES                      **/
                    /******************************************************/

                    case 'art' :
                        if (CheckNivLog('5')) {
                            if ($nom == 'pdt_id') {
                                $aexporter = FALSE;
                            }
                        }
                        if ($aexporter == TRUE) {
                            $id_champ = 'f_' . $nom;
                            $nom_champ = 'cb_' . $nom;
                            echo '<td width="20%" id="' . $id_champ . '">';
                            echo '<input type="checkbox" name="champs[]" value="' . $nom . '" style="background : #FFFFFF;" checked>';
                            echo $nom;
                            $j++;
                        }
                        break;

                    /******************************************************/
                    /**                 INTERVENTIONS                    **/
                    /******************************************************/

                    case 'int' :
                        if (CheckNivLog('5')) {
                            if ($nom == 'int_id') {
                                $aexporter = FALSE;
                            }
                        }
                        if ($aexporter == TRUE) {
                            $id_champ = 'f_' . $nom;
                            $nom_champ = 'cb_' . $nom;
                            echo '<td width="20%" id="' . $id_champ . '">';
                            echo '<input type="checkbox" name="champs[]" value="' . $nom . '" style="background : #FFFFFF;" checked>';
                            echo $nom;
                            $j++;
                        }
                        break;
                }
                echo '</td>';
                // On ferme la ligne uniquement si dernière colonne atteinte
                if (($j <> 0) AND (($j % 5) == 0)) {
                    echo '</tr>';
                }
            }
            close_database();

            // On fini la ligne si pas sur dernière colonne
            if ($j <> 0) {
                if (($j % 5) <> 0) {
                    do {
                        echo '<td width="20%" id="">';
                        echo '&nbsp;';
                        echo '</td>';
                        $j++;
                    } while (($j % 5) <> 0);
                    echo '</tr>';
                }
            }
            ?>
        </table>
        <br/>
        <table width="100%" border="0">
            <tr>
                <td colspan="2">
                    <div align="center"
                         class="titre_std_gras_jaune_frouge"><?php echo _("Paramètres d'exportation"); ?></div>
                </td>
            </tr>
            <tr>
                <td width="30%" class="rubfrm" id="f_ligtitre"
                    align="right"><?php echo _('Nom des champs en 1ère ligne'); ?></td>
                <td>
                    <?php
                    cre_select('ligtitre', 'ligtitre', $non_oui4, 'O');
                    ?>
                </td>
            </tr>
            <tr>
                <td width="160" class="rubfrm" id="f_cadre" align="right"><?php echo _('Champs encadrés par'); ?></td>
                <td>
                    <?php
                    cre_select('cadre', 'cadre', $tab_typ_encadrement, 'G');
                    ?>
                </td>
            </tr>
            <tr>
                <td width="160" class="rubfrm" id="f_sep" align="right"><?php echo _('Champs séparés par des'); ?></td>
                <td>
                    <?php
                    cre_select('sep', 'sep', $tab_typ_separateur, 'P');
                    ?>
                </td>
            </tr>
            <tr>
                <td width="160" class="rubfrm" id="f_sep" align="right"><?php echo _('Lignes terminées par'); ?></td>
                <td>
                    <?php
                    cre_select('fl', 'fl', $tab_typ_fligne, 'N');
                    ?>
                </td>
            </tr>
        </table>
        <div align="center" id="boutons" style="display:block">
            <input name="exp" type="button" class="bton_std" id="exp" value="<?php echo _('Exporter'); ?>">
            <input name="RAZ" type="reset" class="bton_std" id="RAZ" value="<?php echo _('Réinitialiser'); ?>">
            <input name="quit" type="button" class="bton_std" id="quit" value="<?php echo _('Quitter'); ?>">
        </div>
        <div align="center" id="patience" style="display:none"><?php echo _('Merci de patienter...'); ?>
            <br/><?php echo _('Cliquez'); ?> <a
                href="<?php echo $url_link; ?>"><?php echo _('ici'); ?></a> <?php echo _('pour recommencer'); ?></div>
        </form>
        <!-- Fin du formulaire -->
        <?php
    } else {
        pop_ret_auto(_("Pas d'enregistrements"), 'warn', 'index.php');
    }
} else {
    pop_ret_auto(_("Type d'exportation incorrect"), 'warn', 'index.php');
}
include_once('pied.php');
?>
</body>
</html>