<?php
/****************************************************************************************
 * SMI (Services Maintenance Interventions) est une gestion libre de maintenance et de SAV
 *
 * Version 1.0.4
 *
 * Copyright (C) 2006-2016  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');
$ok_inc = FALSE;
if ($pos === FALSE) {
    $ok_inc = TRUE;
}
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(valsession('code_log'));
// Variables Formulaire
fix_magic_quotes();
$_GET = clean_str($_GET);

$td = valget('td');
$codepdt = valget('cp');
$codetpf = valget('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($row2)) {
            $row2 = encode_str($row2);
            extract($row2);

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

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

                if ($td == 'del') {
                    $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST, 'utf8');
                    $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;
                    }
                    close_database();
                }
            } 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 valsession('num_nbdec'); ?>);
                <?php
                switch ($td)
                {
                    case 'add' :
                    case 'edit' :
                        if ($tpf_asaisir == TRUE)
                            {echo "init_valid_form('enr','tpfa_maj','".valsession('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) {
    cre_ent_form($titre, '', '', '', FALSE);
    ?>
    <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>
