<?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_int.inc.php");
include_once("../inc/func.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("../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"]);
// Variables Formulaire
fix_magic_quotes();
$_POST = clean_str($_POST);

$titre = @$_POST["titre"];
$td = @$_POST["td"];
$codeint = @$_POST["codeint"];
$idinth = intval(@$_POST["inth"]);

$code = str_majuscules(@$_POST["code"]);
$des = str_majuscules(@$_POST["des"]);
$qte = floatval(@$_POST["qte"]);
$tva = @$_POST["tva"];
$pu = floatval(@$_POST["pu"]);
$ns = @$_POST["ns"];
$texte = @$_POST["texte"];
$facture = intval(@$_POST["facture"]);

$retourliste = TRUE;

$new_tab = [];
$newrow = [];
$newrow["pdtih_codeint"] = $codeint;
$newrow["pdtih_idhisto"] = $idinth;
$newrow["pdtih_codepdt"] = $code;
$newrow["pdtih_frompdt"] = NULL;
$newrow["pdtih_puttc"] = $pu;
$newrow["pdtih_codetva"] = $tva;
$newrow["pdtih_qte"] = $qte;
$newrow["pdtih_ns"] = $ns;
$newrow["pdtih_texte"] = $texte;
$newrow["pdtih_facture"] = $facture;

switch ($td) {
    // Ajout de la fiche Produit Historique Intervention
    case "add" :
        $_SESSION["pdtih"][] = $newrow;

        $msg = _("Historique produit mis à jour");
        break;

    // MAJ de la fiche Produit Historique Intervention
    case "edit" :
        foreach ($_SESSION["pdtih"] as $row) {
            // C'est le code produit édité ?
            if ($row["pdtih_codepdt"] == $code)
                $new_tab[] = $newrow;
            else
                $new_tab[] = $row;
        }

        $_SESSION["pdtih"] = $new_tab;

        $msg = _("Historique produit mis à jour");
        break;

    // Suppression de la fiche Produit de l'historique intervention
    case "del" :
        foreach ($_SESSION["pdtih"] as $row) {
            // C'est le code produit édité ?
            if ($row["pdtih_codepdt"] <> $code)
                $new_tab[] = $row;
        }

        $_SESSION["pdtih"] = $new_tab;

        $msg = _("Historique produit supprimé");
        break;

    default :
        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 _("Article Historique Intervention"); ?></title>

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

    <script type="text/javascript">
        <!--
        function init_all() {
            init_Body();
            <?PHP
            if ($retourliste == FALSE)
                echo "warn_txt('" . str_escape($msg) . "')";
            else
            {
                echo "cre_html_pdtih('detpdti', 'edit', $codeint, 'window.opener.');";
                echo "updatpdti();";
                echo "pop_txt('".str_escape($msg)."');";
                echo "self.close();";
            }
            ?>
            Focus_first();
        }

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

</head>
<body>
<p align="center"><span class="titrepage"><?PHP echo $titre ?></span></p>
</body>
</html>
