<?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/fic_droits.inc.php");
include_once("../inc/func.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"] = "tpf";

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

$ta = $_GET['ta']; // Source de l'appel m:depuis le menu, p:depuis un produit, i:depuis une intervention
$td = $_GET['td']; // Récupération type demande
$cp = $_GET['cp']; // Récupération code Produit
$ci = $_GET['ci']; // Récupération code Intervention
$cih = intval($_GET['cih']); // Récupération ID Historique Intervention

$pbm_tpf = FALSE;

if (($ta <> "p") AND ($ta <> "m") AND ($ta <> "i") AND ($ta <> "ih"))
    $pbm_tpf = TRUE;
else
    $codeadev = give_dev_codea_defaut($_SESSION["lng"], TRUE);
?>
<!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 _("Liste Taxes Parafiscales"); ?></title>

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

    <script type="text/javascript">
        <!--
        function init_all() {
            init_Body();
            init_autohref_classe('falselnkimg','');
            add_func_click('Submit', 'sclose', '');
            Focus_first();
        }

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

</head>

<body>
<?php
if ($ta == "m")
    include_once("../inc/entete.inc.php");
?>
<p align="center"><span class="titrepage"><?PHP echo _("LISTE DES TAXES PARAFISCALES"); ?></span></p>
<?PHP
if ($pbm_tpf == FALSE) {
    $retour_saisie = FALSE;

    echo '<div align="center">';
    switch ($ta) {
        case "p" :
            $retour_saisie = TRUE;
            echo '<span class="titre_gras">' . _("Choisissez une taxe pour le produit") . ' ' . $cp . ' ' . _("dans la liste suivante") . '</span><br />';
            echo '<span class="annot_petit_it">' . _("Hors taxe(s) déjà saisie(s) dans ce produit") . '</span>';
            break;
        case "i" :
        case "ih" :
            $retour_saisie = TRUE;
            echo '<span class="titre_gras">' . _("Choisissez une taxe pour l'intervention") . ' ' . $ci . ' ' . _("dans la liste suivante") . '</span><br />';
            echo '<span class="annot_petit_it">' . _("Hors Taxe(s) déjà saisie(s) dans cette intervention") . '</span>';
            break;
        default :
            $fic_imp = "tpf_lsti.php";
            $url_add = "tpf_maj.php?td=add&code=";
            break;
    }
    echo '</div>';

    if ($retour_saisie == TRUE) {
        echo '<p align="center">';
        echo '<input type="button" class="bton_std" name="Submit" id="Submit" value="' . _("Revenir à la saisie en cours") . '">';
        echo '</p>';
    }

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

    $rech = cree_strrechlsttpf();
    switch ($ta) {
        case "p" :
            if (!stristr($rech, "WHERE "))
                $rech .= " WHERE `tpf_global`=0";
            else
                $rech .= " AND `tpf_global`=0";
            $rech .= " AND `tpf_actif`=1";
            break;
        case "i" :
        case "ih" :
            if (!stristr($rech, "WHERE "))
                $rech .= " WHERE `tpf_global`=1";
            else
                $rech .= " AND `tpf_global`=1";
            $rech .= " AND `tpf_actif`=1";
            break;
        default :
            break;
    }

    $rech .= crestr_triord($tpf_titre_col, "tpf_code", FALSE, $limit);
    $rows = $db->get_results($rech, ARRAY_A);
    $db->disconnect();

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

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

        $rech = modstr_triord($rech, $tpf_titre_col, "tpf_code", TRUE, $limit);

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

        // *** Pagination de pied
        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($tpf_titre_col);
        echo "<th>" . _("Cliquer") . "</th>\n";

        $i = 0;

        foreach ($rows as $row) {
            $row = encode_str($row);
            $affok = TRUE;
            switch ($ta) {
                case "p" :
                    $rech2 = "SELECT COUNT(*) FROM `" . TBTPFA . "` WHERE `tpfa_codetpf` = '" . $row["tpf_code"] . "' AND `tpfa_codepdt` = '" . $cp . "'";
                    $nbres2 = $db->get_var($rech2);
                    if ($nbres2 <> 0)
                        $affok = FALSE;
                    break;
                case "i" :
                    $rech2 = "SELECT COUNT(*) FROM `" . TBTPFI . "` WHERE `tpfi_codetpf` = '" . $row["tpf_code"] . "' AND `tpfi_codeint` = '" . $ci . "'";
                    $nbres2 = $db->get_var($rech2);
                    if ($nbres2 <> 0)
                        $affok = FALSE;
                    break;
                case "ih" :
                    $rech2 = "SELECT COUNT(*) FROM `" . TBTPFIH . "` WHERE `tpfih_codetpf` = '" . $row["tpf_code"] . "' AND `tpfih_codeint` = '" . $ci . "' AND `tpfih_idhisto` = '" . $cih . "'";
                    $nbres2 = $db->get_var($rech2);
                    if ($nbres2 <> 0)
                        $affok = FALSE;
                    break;
                default :
                    break;
            }

            if ($affok == TRUE) {
                // création de l'entête de ligne (TR)
                creetrlst($i);

                echo "<td>" . $row["tpf_code"] . "</td>\n";
                echo "<td>" . $row["tpf_desc"];
                if ($row["tpf_actif"] == 0)
                    echo ' <img src="../img/inactif.png" border="0" align="absmiddle" title="'.("Inactive").'">';
                echo "</td>\n";
                echo "<td align=\"center\">";
                echo $non_oui[$row["tpf_pour"]];
                echo "</td>\n";
                echo "<td align=\"center\">";
                echo $row["tpf_valeur"];
                if ($row["tpf_pour"] == 1)
                    echo "%";
                echo "</td>\n";
                echo "<td align=\"center\">";
                echo $non_oui[$row["tpf_asaisir"]];
                echo "</td>\n";

                // CREATION lien dynamique sur icône (édition, suppression, etc...)
                echo "<td>";
                echo "<div align=\"center\">";
                switch ($ta) {
                    case "m" :
                        $lst_maj = TRUE;
                        cre_falselnk_img('', 'tpf_edit_'.$row["tpf_id"], 'span', 'center', _("Edition"), 'lnk', 'tpf_maj.php?td=edit&code=' . $row["tpf_code"], '../img/edit.png');
                        $lst_del = TRUE;
                        cre_falselnk_img('', 'tpf_del_'.$row["tpf_id"], 'span', 'center', _("Suppression"), 'lnk', 'tpf_maj.php?td=del&code=' . $row["tpf_code"], '../img/del.png');
                        break;
                    case "p" :
                        $lst_taxe = TRUE;
                        cre_falselnk_img('', 'tpfa_add_'.$row["tpf_id"], 'span', 'center', _("Ajouter"), 'lnk', 'tpfa_maj.php?td=add&cp=' . $cp . '&tpf=' . $row["tpf_code"], '../img/taxe.png');
                        break;
                    case "i" :
                        $lst_taxe = TRUE;
                        cre_falselnk_img('', 'tpfi_add_'.$row["tpf_id"], 'span', 'center', _("Ajouter"), 'lnk', 'tpfi_maj.php?td=add&ci=' . $ci . '&tpf=' . $row["tpf_code"], '../img/taxe.png');
                        break;
                    case "ih" :
                        $lst_taxe = TRUE;
                        cre_falselnk_img('', 'tpfih_add_'.$row["tpf_id"], 'span', 'center', _("Ajouter"), 'lnk', 'tpfih_maj.php?td=add&ci=' . $ci . '&tpf=' . $row["tpf_code"], '../img/taxe.png');
                        break;
                    default :
                        break;
                }
                echo "</div>";
                echo "</td>\n";

                echo "</tr>\n";

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

        $db->disconnect();

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

        $taille_piedla = "";
        include_once("../inc/piedla.inc.php");
    } else
        retpp();
} else
    pop_ret_auto(_("Problème de paramètres"), 'warn', "index.php");

if ($ta == "m")
    include_once("pied.php");
?>
</body>
</html>