<?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_pdt.inc.php");
include_once("../inc/fic_taxes.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_time.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();
$_GET = clean_str($_GET);

$td = @$_GET['td'];
$codepdt = @$_GET['cp'];
$codetpf = @$_GET['tpf'];

$pbm_tpf = FALSE;

if (($codepdt <> "") AND ($codetpf <> "")) {
    // Récupération des données de la fiche article
    $row = lit_enr_pdt($codepdt);
    if (is_array($row)) {
        $row = encode_str($row);
        extract($row);

        $row = lit_enr_tpf($codetpf);

        if (is_array($row)) {
            $row = encode_str($row);
            extract($row);

            if ($tpf_global == FALSE) {
                if ($td == "add") {
                    $tpfa_codetpf = $codetpf;
                    $tpfa_codepdt = $pdt_code;
                    $tpfa_mt = $tpf_valeur;
                }

                if ($td == "edit") {
                    $row = lit_enr_tpf_in_pdt($codetpf, $codepdt);
                    if (is_array($row))
                        extract($row);
                    else
                        $pbm_tpf = TRUE;
                }

                if ($td == "del") {
                    $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
                    $rech = "SELECT * FROM `" . TBTPFA . "` WHERE `tpfa_codepdt` = '" . $db->escape($codepdt) . "' AND `tpfa_codetpf` = '" . $db->escape($codetpf) . "'";
                    $row = $db->get_row($rech, ARRAY_A);
                    if ($row)
                        extract($row);
                    else
                        $pbm_tpf = TRUE;
                    $db->disconnect();
                }
            } else
                $pbm_tpf = TRUE;
        } else
            $pbm_tpf = TRUE;
    } else
        $pbm_tpf = TRUE;
} else
    $pbm_tpf = TRUE;

switch ($td) {
    case "add" :
        $titre = _("SAISIE TAXE");
        break;
    case "edit" :
        $titre = _("EDITION TAXE");
        break;
    case "del" :
        $titre = _("SUPPRESSION TAXE");
        break;
    default :
        $pbm_tpf = TRUE;
        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 _("Taxes Produit"); ?></title>

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

    <?PHP if ($tpf_asaisir == TRUE) { ?>
        <script language="javascript">
            <!--
            var tab1_champ = new Array(
                "nom:valeur; format:reel_ns ; req:Y ; txt:<?PHP echo _("Valeur"); ?> ; vmn:0.01 ; stok:frmok ; stbad:frmbad");
            //-->
        </script>
    <?PHP } ?>


    <?PHP if ($pbm_tpf == FALSE) { ?>
        <script type="text/javascript">
            <!--
            function init_all() {
                init_Body();
                init_fdeci('valeur', <?PHP echo $_SESSION['num_nbdec']; ?>);
                <?PHP
                switch ($td)
                {
                    case "add" :
                    case "edit" :
                        if ($tpf_asaisir == TRUE)
                            echo "init_valid_form('enr','tpfa_maj','".$_SESSION['date_fmtshort']."',tab1_champ,'','');";
                        break;
                    case "del" :
                        echo "readonly_all();";
                        echo "warn_del('');";
                        break;
                    case "view" :
                        echo "readonly_all();";
                        break;
                }
                ?>
                add_func_click('annul', 'sclose','');
                Focus_first();
            }

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

<body>
<?PHP
if ($pbm_tpf == FALSE) {
    ?>
    <p align="center"><span class="titrepage"><?PHP echo $titre ?></span></p>
    <p align="center"><?PHP echo _("Pour le produit"); ?> : <br /><span class="titre_gras"><?php echo $pdt_des; ?> </span></p>

    <form name="tpfa_maj" id="tpfa_maj" method="post" action="tpfa_enr.php">
        <input name="titre" type="hidden" id="titre" value="<?PHP echo $titre ?>">
        <input name="td" type="hidden" id="td" value="<?PHP echo $td ?>">
        <input name="codepdt" type="hidden" id="codepdt" value="<?PHP echo $tpfa_codepdt ?>">
        <input name="nbutton" type="hidden" id="nbutton" value="">
        <table width="600" border="0">
            <tr>
                <td width="160" class="rubfrm" id="f_code"><?PHP echo _("Code"); ?></td>
                <td width="84%">
                    <input name="code" type="text" id="code" value="<?PHP echo $tpf_code ?>" size="10" maxlength="10"
                           readonly="1">
                </td>
            </tr>
            <tr>
                <td width="160" class="rubfrm" id="f_des"><?PHP echo _("Libellé"); ?></td>
                <td>
                    <input name="des" type="text" id="des" value="<?PHP echo $tpf_desc; ?>" size="40" maxlength="40"
                           readonly="1">
                </td>
            </tr>
            <tr>
                <td width="160" class="rubfrm" id="f_valeur"><?PHP if ($tpf_pour == FALSE) echo _("Valeur TTC"); else echo _("Pourcentage"); ?></td>
                <td>
                <?PHP
                $readonly = FALSE;
                if ($tpf_asaisir == FALSE)
                    $readonly = TRUE;
                if ($tpf_pour == TRUE)
                {
                    cre_input_num('valeur', $tpfa_mt, FALSE, $readonly);
                    echo "%";
                }
                else
                    cre_input_num('valeur', $tpfa_mt, TRUE, $readonly);
                if ($tpf_typmt == TRUE)
                        echo '<div class="annot_petit_it">'._("La valeur saisie ou calculée sera unique").'</div>';
                else
                    echo '<div class="annot_petit_it">'._("La valeur saisie ou calculée sera proportionnelle au nombre d'unités vendues").'</div>';
                if ($tpf_asaisir == FALSE)
                    echo '<div class="annot_petit_it">'._("Cette valeur n'est pas modifiable").'</div>';
                ?>
                </td>
            </tr>
        </table>
        <p align="center">
            <?PHP
            switch ($td)
            {
                case "add" :
                case "edit" :
                    if ($tpf_asaisir == TRUE)
                    {
                        echo '<input name="enr" type="button" class="bton_std" id="enr" value="'._("Valider").'">';
                        echo '<input name="RAZ" type="reset" class="bton_std" id="RAZ" value="'._("Réinitialiser").'">';
                    }
                    break;
                case "del" :
                    echo '<input name="del" type="submit" class="bton_std" id="del" value="'._("Supprimer").'">';
                    break;
            }
            echo '<input name="annul" type="button" class="bton_std" id="annul" value="'._("Annuler").'">';
            ?>
        </p>
    </form>
<?PHP
} else
    close_fen_auto('', '');
?>
</body>
</html>
