<?php
/****************************************************************************************
 * SMI (Services Maintenance Interventions) est une gestion libre de maintenance et de SAV
 *
 * Version 1.0.2
 *
 * Copyright (C) 2006-2015  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/func.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_mque.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(@$_SESSION["code_log"]);
$_SESSION["typ_filtres"] = "mque";

// Variables Formulaire
fix_magic_quotes();
$_GET = clean_str($_GET);

$td = "";
if (isset($_GET['td']))
    $td = $_GET['td']; // Récupération type demande (td=r -> uniquement si renvois en attente)
$pbm_mque = FALSE;

switch ($td) {
    case "r" :
        $titre = _("FABRIQUANTS/EDITEURS/DISTRIBUTEURS AVEC ATTENTE DE RETOUR");
        if (@$_SESSION["niv_log"] == 3)
            $pbm_mque = TRUE;
        break;
    default :
        $titre = _("LISTE FABRIQUANTS/EDITEURS/DISTRIBUTEURS");
        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 - Liste Fabriquants/Editeurs"); ?></title>

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

    <script type="text/javascript">
        <!--
        function init_all() {
            init_Body();
            init_autohref_classe('falselnkimg','');
            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 ($pbm_mque == FALSE) {
    if (($td == "") AND (@$_SESSION["niv_log"] <> 3))
        $url_add = "mque_maj.php?td=add&code=";

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

    if ($td == "")
        $rech = cree_strrechlstrrlpma();
    else
        $rech = cree_strrechlstrrlpmar();
    $rech .= crestr_triord($mque_titre_col, "mque_code", FALSE, $limit);

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

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

    $db->disconnect();

    if ($numrows == 0) {
        if ($td == "")
            retpp();
        else
            echo '<br /><span class="annot_std_gras">'._("Aucun numéro de retour en attente de renvoi").'</span><br />';
    } else {
        include_once("../inc/formr.inc.php");

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

        $rech = modstr_triord($rech, $mque_titre_col, "mque_code", TRUE, $limit);

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

        if ($td == "") {
            if ($numrows > 0)
                echo '<a href="mque_lst.php?td=r">' . _("Effectuer les renvois de produits") . '</a>';
        } else
            echo '<a href="mque_lst.php">' . _("Liste globale") . '</a>';

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

        // création entête
        titlst($mque_titre_col);
        echo "<th>" . _("Cliquer") . "</th>\n";

        $i = 0;

        foreach ($rows as $row) {
            $row = encode_str($row);
            if ($row["mque_code"] <> "*") //on affiche pas le code "Tous les éditeurs"
            {
                // création de l'entête de ligne (TR)
                creetrlst($i);

                echo "<td>" . $row["mque_code"] . "</td>\n";
                echo "<td>" . $row["mque_ste"];
                if (nb_envoi_nonclos($row["mque_code"], FALSE) > 0) {
                    $lst_reteex = TRUE;
                    echo " ";
                    echo '<a href="rete_lst.php?search=' . $row["mque_ste"] . '"><img src="../img/retns.png" title ="' . _("Renvois non soldés") . '" border="0" align="absmiddle"></a>';
                }
                echo "</td>\n";
                echo '<td align="center">';
                echo $row["mquet_desc"];
                echo "</td>\n";

                // CREATION lien dynamique sur icône (édition, suppression, etc...)
                echo "<td>";
                echo "<div align=\"center\">";
                if ($td == "") {
                    if (@$_SESSION["niv_log"] <> 3)
                    {
                        $lst_maj = TRUE;
                        cre_falselnk_img('', 'mque_edit_'.$row["mque_id"], 'span', 'center', _("Edition"), 'lnk', 'mque_maj.php?td=edit&code=' . $row["mque_code"], '../img/edit.png');
                        $lst_retp = TRUE;
                        cre_falselnk_img('', 'mque_retp_'.$row["mque_id"], 'span', 'center', _("Saisir produit à retourner"), 'lnk', 'retp_maj.php?td=add&cm=' . $row["mque_code"], '../img/retp.png');
                        $lst_del = TRUE;
                        cre_falselnk_img('', 'mque_del_'.$row["mque_id"], 'span', 'center', _("Suppression"), 'lnk', 'mque_maj.php?td=del&code=' . $row["mque_code"], '../img/del.png');
                    }
                    else
                    {
                        $lst_view = TRUE;
                        cre_falselnk_img('', 'mque_view_'.$row["mque_id"], 'span', 'center', _("Visualisation"), 'lnk', 'mque_maj.php?td=view&code=' . $row["mque_code"], '../img/eye.png');
                    }
                } else {
                    $lst_rete = TRUE;
                    cre_falselnk_img('', 'mque_rete_'.$row["mque_id"], 'span', 'center', _("Créer bon de renvoi"), 'lnk', 'rete_maj.php?td=add&cm=' . $row["mque_code"], '../img/rete.png');
                }
                echo "</div>";
                echo "</td>\n";

                echo "</tr>\n";

                $i++;
            }
        }
        echo "</table>\n";
        // *** Fin affichage de la table

        $db->disconnect();

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


        $taille_piedla = "";
        include_once("../inc/piedla.inc.php");
    }
} else
    pop_ret_auto(_("Problème de paramètres"), 'warn', "mque_lst.php");
include_once("pied.php");
?>
</body>
</html>