<?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/config.inc.php");
include_once("../inc/fic_droits.inc.php");
include_once("../inc/fic_prm.inc.php");
include_once("../inc/func.inc.php");
include_once("../inc/func_date.inc.php");
include_once("../inc/func_log.inc.php");
include_once("../inc/func_geo.inc.php");
include_once("../inc/func_txt.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"] = "pdtih";
?>
    <!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 _("Historiques Produits / Interventions"); ?></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 _("HISTORIQUES ARTICLES"); ?> </span></p>
<?PHP
// $fic_imp = "int_lsti.php";
$db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);

$rech = cree_strrechlstpdtih();
if ((@$_SESSION["niv_log"] == 4) OR (@$_SESSION["niv_log"] == 3)) {
    if (!stristr($rech, "WHERE "))
        $rech .= " WHERE " . TBINT . ".int_codeage='" . $_SESSION["code_log"] . "'";
    else
        $rech .= " AND " . TBINT . ".int_codeage='" . $_SESSION["code_log"] . "'";
}
$rech .= crestr_triord($pdti_titre_col, "pdti_codepdt", FALSE, $limit);

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

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

    $rech = modstr_triord($rech, $pdti_titre_col, "pdti_codepdt", FALSE, $limit);

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

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

    // *** Pagination d'entête
    pagine_lst($numrows, $limit);

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

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

    $i = 0;

    foreach ($rows as $row) {
        $row = encode_str($row);
        // Affichage résumé intervention

        // création de l'entête de ligne (TR)
        creetrlst($i);

        // Affichage Code Produit

        echo "<td>" . $row["pdti_codepdt"];

        // Affichage détail Produit

        $detailpdt = "->";
        if ($row["pdt_des"] <> "")
            $detailpdt .= $row["pdt_des"];
        echo "<br />";
        echo "<span class=\"annot_petit_it\">";
        echo $detailpdt;
        echo "</span>";

        // Fin affichage détail Produit

        echo "</td>\n";

        // Fin affichage Produit

        // Affichage Code Intervention

        echo "<td>" . $row["pdti_codeint"];

        // Affichage détail client

        $detailcli = _("Client").' : ';
        if ($row["cli_ste"] <> "")
            $detailcli .= $row["cli_ste"] . ", ";
        $detailcli .= $row["cli_civilite"] . " " . $row["cli_nom"];
        echo "<br />";
        echo "<span class=\"annot_petit_it\">";
        echo $detailcli;
        echo "</span>";

        // Fin affichage détail client

        // Affichage détail Intervention

        $detailint = _("Début"). ' : ' . datetolocal($row["int_datedde"]);
        echo "<br />";
        echo "<span class=\"annot_petit_it\">";
        if (datetolocal($row["int_datefin"]) <> "")
            $detailint .= ' / '._("Fin").' : ' . datetolocal($row["int_datefin"]);
        echo $detailint;
        echo "</span>";

        // Fin affichage détail Intervention

        echo "</td>\n";

        // Fin Affichage Code Intervention

        // Affichage Quantité

        echo "<td>";

        echo "<div align=\"center\">";
        echo full_num_format($row["pdti_qte"], '', '', FALSE, '', FALSE);
        // echo $row["pdti_qte"];
        echo "</div>";

        echo "</td>\n";

        // Fin affichage Quantité


        // Affichage PU

        echo "<td>";

        echo "<div align=\"center\">";
        echo full_num_format($row["pdti_puttc"], '', '', TRUE, '', FALSE);
        /*
        // On récupère le code devise de l'intervention
        $int_codeadev = give_dev_codea_defaut_int($row["int_code"], $_SESSION["lng"], FALSE);
        echo $row["pdti_puttc"] . ' ' . give_dev_ISO($int_codeadev, FALSE);
        */
        echo "</div>";

        echo "</td>\n";

        // Fin affichage PU

        echo "<td>" . $row["pdti_ns"] . "</td>\n";

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

        if (datetolocal($row["int_datefin"]) == "") {
            if ((@$_SESSION["niv_log"] == 7) OR (@$_SESSION["niv_log"] == 6)) {
                if (($row["int_codetec"] <> "") AND ($row["int_codetec"] <> "-1"))
                    $voir = TRUE;
            }

            if ((@$_SESSION["niv_log"] == 11) OR (@$_SESSION["niv_log"] == 10))
                $voir = TRUE;
        } else
            $voir = TRUE;

        if ($voir == FALSE) {
            $url_edit = 'int_maj.php?td=edit&ci=' . $row["int_code"] . '&cc=' . $row["int_codecli"] . '&ca=' . $row["int_codeage"];
            if (url_ok($url_edit, FALSE) == TRUE) {
                $lst_maj = TRUE;
                cre_falselnk_img('', 'pdtih_edit_'.$row["pdtih_id"], 'span', 'center', _("Edition"), 'lnk', $url_edit, '../img/edit.png');
            }
        } else {
            $url_view = 'int_maj.php?td=view&ci=' . $row["int_code"] . '&cc=' . $row["int_codecli"];
            if (url_ok($url_view, FALSE) == TRUE) {
                $lst_voir = TRUE;
                cre_falselnk_img('', 'pdtih_view_'.$row["pdtih_id"], 'span', 'center', _("Visualisation"), 'lnk', $url_view, '../img/eye.png');
            }
        }

        $lst_imp = TRUE;

        $alea = time();
        $urlimp = "int_pdf.php?token=" . $alea . "&ci=" . $row["int_code"];
        cre_falselnk_img('', 'pdtih_prn_'.$row["pdtih_id"], 'span', 'center', _("Impression"), 'lnk', $urlimp, '../img/print.png');

        $lst_impc = TRUE;

        $urlimp = "int_pdf.php?token=" . $alea . "&ci=" . $row["int_code"] . "&cgv=ok";
        cre_falselnk_img('', 'pdtih_prncgv_'.$row["pdtih_id"], 'span', 'center', _("Impression avec CGV"), 'lnk', $urlimp, '../img/printc.png');
        echo "</td>\n";

        echo "</tr>\n";
        // Fin affichage résumé intervention

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

    $db->disconnect();

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


    $taille_piedla = "";
    include_once("piedla.inc.php");
} else
    retpp();
include_once("pied.php");
?>