<?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_loc.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"]);
if (!isset($_SESSION["pdtlbl"])) $_SESSION["pdtlbl"] = [];
if (!isset($_SESSION["pdtlpl"])) $_SESSION["pdtlpl"] = [];
if (!isset($_SESSION["pdtlcl"])) $_SESSION["pdtlcl"] = [];

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

$titre = @$_POST["titre"];
$td = @$_POST["td"];
$tab_enr = [];
$tab_enr["codecoloc"] = @$_POST["cl"];
$tab_enr["codeart"] = @$_POST["ca"];
$tab_enr["idbarloc"] = intval(@$_POST["ibl"]);
$tab_enr["qte"] = @$_POST["qte"];
$tab_enr["pvht"] = @$_POST["pvht"];
$tab_enr["codetva"] = @$_POST["tva"];
$tab_enr["caution"] = @$_POST["caution"];
$tab_enr["tvacaut"] = @$_POST["tvacaut"];
$tab_enr["avecass"] = @$_POST["assobl"];
$tab_enr["mtass"] = @$_POST["mtass"];
$tab_enr["codetvaass"] = @$_POST["tvaass"];
$tab_enr["qconsi1"] = @$_POST["qcons1"];
$tab_enr["pdtuconsi1"] = @$_POST["pdtucons1"];
$tab_enr["puconsi1"] = @$_POST["mtcons1"];
$tab_enr["qconsi2"] = @$_POST["qcons2"];
$tab_enr["pdtuconsi2"] = @$_POST["pdtucons2"];
$tab_enr["puconsi2"] = @$_POST["mtcons2"];
$tab_enr["dd"] = @$_POST["dd"];
$tab_enr["hd"] = @$_POST["hd"];
$tab_enr["df"] = @$_POST["df"];
$tab_enr["hf"] = @$_POST["hf"];
// données pour la pénalité
$codecoloc = @$_POST["cl"];
$codeart = @$_POST["ca"];
$codetva = @$_POST["tva"];
$penposs = @$_POST["cpen"];

$retourliste = TRUE;

switch ($td) {
    // Ajout du barème de location
    case "add" :
        if (count($_SESSION["pdtlbl"]) == 0) {
            $_SESSION["pdtlbl"][0] = $tab_enr;

            // Ajout de la pénalité rattachée
            $tab_enr = [];

            $tab_enr["codecoloc"] = $codecoloc;
            $tab_enr["codeart"] = $codeart;
            $tab_enr["codepen"] = "-1";
            $tab_enr["valeur"] = 0;
            $tab_enr["tva"] = $codetva;
            $tab_enr["penposs"] = $penposs;
            $_SESSION["pdtlpl"][0] = $tab_enr;

            $msg = _("Barême ajouté");
        } else {
            $retourliste = FALSE;
            $msg = _("Un seul barême par produit loué");
        }
        break;

    // MAJ du barème de location
    case "edit" :
        if (count($_SESSION["pdtlbl"]) == 1) {
            $_SESSION["pdtlbl"][0] = $tab_enr;

            // Ajout de la pénalité rattachée
            $tab_enr = [];

            $tab_enr["codecoloc"] = $codecoloc;
            $tab_enr["codeart"] = $codeart;
            $tab_enr["codepen"] = "-1";
            $tab_enr["valeur"] = 0;
            $tab_enr["tva"] = $codetva;
            $tab_enr["penposs"] = $penposs;
            $_SESSION["pdtlpl"][0] = $tab_enr;
            $msg = "barème mis à jour";
        } else {
            $retourliste = FALSE;
            $msg = _("Problème dans le nombre de barèmes enregistrés");
        }
        break;

    // Suppression du barème de location
    case "del" :
        if (count($_SESSION["pdtlbl"]) == 1) {
            $_SESSION["pdtlbl"] = [];
            $_SESSION["pdtlpl"] = [];
            $msg = _("Barême supprimé");
        } else {
            $retourliste = FALSE;
            $msg = _("Problème dans le nombre de barèmes enregistrés");
        }
        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 (Barême Location)"); ?></title>

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

    <script type="text/javascript">
        <!--
        <?PHP
        if ($retourliste == TRUE)
            cre_html_pdtlbl('detbarloc', 'edit', $_SESSION["pdtlbl"], $_SESSION["pdtlpl"], $_SESSION["pdtlcl"], 'window.opener.');
        ?>

        function init_all() {
            init_Body();
            <?PHP
            if ($retourliste == FALSE)
                echo "warn_txt('" . str_escape($msg) . "',5000);";
            else
            {
                echo "tbpbarloc();";
                echo "ok_txt('" . str_escape($msg) . "',5000);";
            }
            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>
