<?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/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('../inc/fic_droits.inc.php');
include_once('../inc/fic_ret.inc.php');
include_once('../inc/lst.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);

$_SESSION['typ_filtres'] = 'rete';

$fi = '';
if (isset($_GET['fi']) && (trim($_GET['fi']) <> '')) {
    $fi = (int)$_GET['fi'];
}
?>
<!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 _('Liste renvois de produits'); ?></title>

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

    <script type="text/javascript">
        <!--
        function init_all() {
            init_Body();
            init_autohref_classe('falselnkimg', '');
            <?php if (($td=='view') OR ($td=='del')) {echo 'readonly_all();';} ?>
            <?php if ($td=='del') {echo "warn_del('');";} ?>
            Focus_first();
        }

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

<body>

<?php include_once('../inc/entete.inc.php');
cre_ent_form(_('LISTE DES RENVOIS DE PRODUITS'), '', '', '', FALSE);
$fic_imp = 'rete_lsti.php';
$url_add = 'mque_lst.php?td=r';
$tab_fi[] = _('Tous les renvois');
$tab_fi[] = _('Renvois non expédiés');

$db = open_database(DBUSER, DBPASS, DBNAME, DBHOST, 'utf8');

$rech = cree_strrechlstrete();
if (CheckNivLog('4')) {
    if (!stristr($rech, 'WHERE ')) {
        $rech .= ' WHERE ' . TBRETE . ".rete_codeage='" . valsession('code_age') . "'";
    } else {
        $rech .= ' AND ' . TBRETE . ".rete_codeage='" . valsession('code_age') . "'";
    }
}
switch ($fi) {
    case '1' :
        if (!stristr($rech, 'WHERE ')) {
            $rech .= " WHERE rete_clos='0'";
        } else {
            $rech .= " AND rete_clos='0'";
        }
        break;
    default :
        break;
}
$rech .= crestr_triord($rete_titre_col, 'rete_code', FALSE, $limit);

$rows = $db->get_results($rech, ARRAY_A);
close_database();

if ($rows) {
    $numrows = count($rows);
    include_once('formr.inc.php');

    $rech = modstr_triord($rech, $rete_titre_col, 'rete_code', TRUE, $limit);

    $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST, 'utf8');

    $rows = $db->get_results($rech, ARRAY_A);

    // *** Pagination de pied
    pagine_lst($numrows, $limit);

    // *** Affichage de la table
    echo '<table class="Mtable" border="0" width="100%" cellpadding="0" cellspacing="0">';

    // création entête
    titlst($rete_titre_col);
    echo '<th>' . _('Cliquer') . '</th>';

    $i = 0;

    foreach ($rows as $row) {
        $row = encode_str($row);
        // Affichage list renvois

        // création de l'entête de ligne (TR)
        echo '<tr>';

        echo '<td>';
        echo $row['rete_code'];
        if (envoi_solde($row['rete_code'], FALSE) == TRUE) {
            $lst_envs = TRUE;
            echo ' <img src="../img/ok.png" title ="' . _('Tous les produits ont été traités') . '" border="0" align="absmiddle">';
        }
        echo '</td>';
        echo '<td>';
        echo $row['rete_codeage'];
        echo '</td>';
        echo '<td>';
        echo $row['mque_ste'];
        echo ' <a href=\"mque_maj.php?td=edit&code=' . $row['mque_code'] . '"><img src="../img/eye.png" width="14" height="14" border="0" align="absmiddle" title="' . _('Voir fiche') . '"></a>';
        echo '</td>';
        echo '<td align="center">';
        echo datetolocal($row['rete_dateenv']);
        echo '</td>';
        echo '<td align="center">';
        $row2 = lit_enr_me($row['rete_codeme'], FALSE);
        if (is_array($row2)) {
            $row2 = encode_str($row2);
            echo $row2['me_nom'];
        }
        echo '</td>';
        echo '<td align="center">';
        echo $row['rete_bord'];
        echo '</td>';

        // CREATION lien dynamique sur icône (édition, suppression, etc...)
        echo '<td>';
        echo '<div align="center">';

        $voir = FALSE;

        if ((int)$row['rete_clos'] == 1) {
            $voir = TRUE;
        }

        if ($voir == FALSE) {
            $lst_maj = TRUE;
            cre_falselnk_img('', 'rete_edit_' . $row['retd_id'], 'span', 'center', _('Edition'), 'lnk', 'rete_maj.php?td=edit&ce=' . $row['rete_code'], '../img/edit.png');
        } else {
            if (envoi_solde($row['rete_code'], FALSE) == TRUE) {
                $lst_voir = TRUE;
                cre_falselnk_img('', 'rete_view_' . $row['retd_id'], 'span', 'center', _('Visualisation'), 'lnk', 'rete_maj.php?td=view&ce=' . $row['rete_code'], '../img/eye.png');
            } else {
                $lst_voire = TRUE;
                cre_falselnk_img('', 'rete_view_' . $row['retd_id'], 'span', 'center', _('Saisir traitement retour'), 'lnk', 'rete_maj.php?td=view&ce=' . $row['rete_code'], '../img/retr.png');
            }
            echo ' ';
        }
        $lst_imp = TRUE;
        $urlimp = 'rete_pdf.php?ce=' . $row['rete_code'];
        cre_falselnk_img('', 'rete_prn_' . $row['retd_id'], 'span', 'center', _('Impression bordereau de renvoi'), 'lnk', $urlimp, '../img/print.png');
        if ($voir == FALSE) {
            $lst_del = TRUE;
            cre_falselnk_img('', 'rete_del_' . $row['retd_id'], 'span', 'center', _('Suppression'), 'lnk', 'rete_maj.php?td=del&ce=' . $row['rete_code'], '../img/del.png');
        }

        echo '</div>';
        echo '</td>';

        echo '</tr>';

        $i++;
    }
    echo '</table>';
    // *** Fin affichage de la table

    close_database();

    // *** Pagination de pied
    pagine_lst($numrows, $limit);

    $taille_piedla = '';
    include_once('piedla.inc.php');
} else {
    retpp();
}

include_once('pied.php');
?>
</body>
</html>