<?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/fic_pen.inc.php");
include_once("../inc/fic_prm.inc.php");
include_once("../inc/func.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();
$_GET = clean_str($_GET);

$td = $_GET['td'];
$coderech = $_GET['code'];

$pbm_pen = FALSE;
$penmod = TRUE;
$pendesact = TRUE;

if ($coderech <> "") {
    $row = lit_enr_pen($coderech);
    if (is_array($row)) {
        $row = encode_str($row);
        extract($row);
        if ((pen_modifiable($coderech, TRUE) == FALSE) AND ($td <> "del"))
            $td = "view";
        $pendesact = pen_desactivable($coderech, TRUE);
    } else
        $pbm_pen = TRUE;
} else {
    if ($td <> "add") $pbm_pen = TRUE;
}

if ($pbm_pen == FALSE) {
    $codeadev = give_dev_codea_defaut($_SESSION["lng"], TRUE);

    switch ($td) {
        case "add" :
            $titre = _("CREATION PENALITE");
            break;
        case "edit" :
            $titre = _("MODIFICATION PENALITE");
            $nextmin = next_min_penbar($pen_code, TRUE);
            break;
        case "del" :
            $titre = _("SUPPRESSION PENALITE");
            break;
        default :
            $pbm_pen = 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 _("Fiche Pénalité Location"); ?></title>

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

    <script language="javascript">
        <!--
        var tab_champ = ["nom:code ; format:alphanum ; req:Y ; txt:<?PHP echo _("Code"); ?> ; lmn:1 ; lmx:10; stok:frmok ; stbad:frmbad",
            <?PHP if ($td<>"add") { ?>
            "nom:valeur; format:reel_ns ; req:N ; txt:<?PHP echo _("Valeur"); ?>; lmx:10; stok:frmok ; stbad:frmbad",
            <?PHP } ?>
            "nom:desc ; format:txt ; req:Y ; txt:<?PHP echo _("Libellé"); ?>; lmn:1 ; lmx:40; stok:frmok ; stbad:frmbad"];
        //-->
    </script>

    <script type="text/javascript">
        <!--
        <?PHP cre_html_penbar('detbarpen', $td, $pen_code, $pen_pour, ''); ?>

        $(function () {
            $("#code").Setcase({caseValue: 'upper', changeonFocusout: true});
            $("#desc").Setcase({caseValue: 'upper', changeonFocusout: true});
        });

        function init_all() {
            init_Body();
            init_fdeci('valeur', <?PHP echo $_SESSION['num_nbdec']; ?>,'');
            chk_tbar('tbar');
            chk_pour('pour', 'sympour', 'pas_sympour');
            chk_pour('pour', 'txtpour2', 'pas_txtpour2');
            <?php
             switch ($td)
             {
                case "add":
                    echo "init_valid_form('enr','pen_maj','".$_SESSION['date_fmtshort']."',tab_champ,'','');";
                    echo "init_chk_tbar('tbar');";
                    echo "init_chk_pour('pour','sympour','pas_sympour');";
                    echo "init_chk_pour('pour','txtpour2','pas_txtpour2');";
                    break;
                case "edit":
                    echo "init_valid_form('enr','pen_maj','".$_SESSION['date_fmtshort']."',tab_champ,'','');";
                    echo "init_chk_tbar('tbar');";
                    echo "init_chk_pour('pour','sympour','pas_sympour');";
                    echo "init_chk_pour('pour','txtpour2','pas_txtpour2');";
                    echo "init_fen_penbar_pen('addpbar','add','".$pen_code."',0);";
                    break;
                case "del":
                    echo "readonly_all();";
                    echo "warn_del('');";
                    break;
                case "view":
                    echo "readonly_all();";
                    break;

             }
            ?>
            tbpenbar();
            Focus_first();
        }

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

<?PHP include_once("../inc/entete.inc.php");
if ($pbm_pen == FALSE) {
    cre_ent_form($titre, 'pen_lst.php?ta=m', $_SERVER['HTTP_REFERER'], '');
    ?>
    <form name="pen_maj" id="pen_maj" method="post" action="pen_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="nbutton" type="hidden" id="nbutton" value="">
        <?PHP if ($td <> "add") { ?>
            <input name="nextmin" type="hidden" id="nextmin" value="<?PHP echo $nextmin; ?>">
        <?PHP } ?>
        <table width="100%" border="0">
            <tr>
                <td width="10%" class="rubfrm" align="right" id="f_code"><?PHP echo _("Code"); ?></td>
                <td width="47%">
                    <input name="code" type="text" id="code" value="<?PHP echo $pen_code ?>" size="10">
                    <?PHP
                    if ($td == "add")
                        echo ' <img src="../img/oblig.png" align="absmiddle" alt="'._("Champ obligatoire").'">';
                    ?>
                </td>
            </tr>
            <tr>
                <td class="rubfrm" align="right" id="f_desc"><?PHP echo _("Libellé"); ?></td>
                <td><input name="desc" type="text" id="desc" value="<?PHP echo $pen_desc; ?>" size="50">
                    <img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo _("Champ obligatoire"); ?>"></td>
            </tr>
            <?PHP if ($td <> "add") { ?>
                <tr>
                    <td class="rubfrm" align="right" id="f_tbar"><?PHP echo _("Type barême"); ?></td>
                    <td>
                        <?PHP
                        $tab_tbar = [];
                        $tab_tbar['0'] = _("Valeur unique");
                        $tab_tbar['1'] = _("Grille de valeurs");
                        cre_select('tbar', 'tbar', $tab_tbar, $pen_tbar);
                        echo '<div class="annot_petit_it">';
                        echo _("'Valeur unique' : La pénalité est une valeur unique");
                        echo '<br />';
                        echo _("'Grille de valeurs' : La pénalité est établie selon une grille");
                        echo '</div>';
                        ?>
                    </td>
                </tr>
                <tr>
                    <td class="rubfrm" align="right" id="f_valeur" align="left">
                        <span id="txtpour2" style="display:none"><?PHP echo _("Valeur"); ?></span>
                        <span id="pas_txtpour2" style="display:block"><?PHP echo _("Valeur HT"); ?></span>
                    </td>
                    <td>
                        <input name="valeur" type="text" id="valeur" style="text-align:right"
                               value="<?PHP echo $pen_valeur; ?>" size="10">
                        <span id="sympour" style="visibility:visible" align="left"><?PHP echo _("%"); ?></span>
                        <span id="pas_sympour" style="visibility:visible"
                              align="left"><?PHP echo trim(give_dev_ISO()); ?></span>
                    </td>
                </tr>
                <tr>
                    <td class="rubfrm" align="right" id="f_pour"><?PHP echo _("Pourcentage ?"); ?></td>
                    <td>
                        <?PHP
                        cre_select('pour', 'pour', $non_oui, (int)$pen_pour);
                        echo '<div class="annot_petit_it">';
                        echo _("'Oui' : la valeur est un pourcentage du barême");
                        echo '<br />' . _("'Non' : la valeur est un montant");
                        echo '</div>';
                        ?>
                    </td>
                </tr>
                <tr>
                    <td width="160" class="rubfrm" align="right" id="f_udec"
                        align="right"><?PHP echo _("Unité de décompte"); ?></td>
                    <td>
                        <?PHP
                        cre_select('udec', 'udec', $lng_tduree, $pen_udec);
                        ?>
                    </td>
                </tr>
                <tr>
                    <td class="rubfrm" align="right" id="f_prop"><?PHP echo _("Proportionnel ?"); ?></td>
                    <td>
                        <?PHP
                        cre_select('prop', 'prop', $non_oui, (int)$pen_prop);
                        echo '<div class="annot_petit_it">';
                        echo _("'Non' : la valeur sera valable quelque soit le nombre d'unités de retard");
                        echo '<br />';
                        echo _("'Oui' : la valeur sera proportionnelle au nombre d'unités de retard");
                        echo '</div>';
                        ?>
                    </td>
                </tr>
                <tr>
                    <td class="rubfrm" align="right" id="f_actif"><?PHP echo _("Active"); ?></td>
                    <td>
                        <?PHP
                        cre_select('actif', 'actif', $non_oui, (int)$pen_actif);
                        echo '<div class="annot_petit_it">';
                        echo _("Vous ne pouvez pas désactiver une pénalité déjà utilisée dans une location non close");
                        echo '</div>';
                        ?>
                    </td>
                </tr>
            <?PHP } ?>
        </table>
        <!-- Zone de saisie de la grille tarifaire des pénalités -->
        <div id="detpenbar">
            <?PHP
            if (($td == "edit") OR ($td == "del") OR ($td == "view")) {
                ?>
                <table width="100%" border="0">
                    <tr>
                        <td class="rubfrm" colspan="2" align="center">
                            <?PHP echo _("GRILLE DE TARIFICATION"); ?>
                        </td>
                    </tr>
                </table>
                <div id="detbarpen">
                </div>

                <!-- Lien d'ajout de barèmes -->
                <?PHP
                if ($td == "edit") {
                    ?>
                    <div id="addbp" style="<?PHP if (exist_infini_penbar_code($pen_code) OR ($pen_tbar == 0)) echo "display:none"; else echo "display:block"; ?>">
                        <?PHP
                        cre_falselnk('addpbar', 'addpbar', 'span', '', _("Ajouter barême"), '', '../img/add.png', _("Ajouter barême"));
                        ?>
                    </div>
                <?PHP
                }
            }
            ?>
        </div>
        <p align="center">
        <?PHP
        switch ($td)
        {
            case "add" :
            case "edit" :
                echo '<input name="RAZ" type="reset" class="bton_std" id="RAZ" value="'._("Réinitialiser").'">';
                echo '<input name="enr" type="button" class="bton_std" id="enr" value="'._("Enregistrer").'">';
                break;
            case "del" :
                echo '<input name="enr" type="button" class="bton_std" id="enr" value="'._("Supprimer").'">';
                break;
        }
        ?>
        </p>
    </form>
<?PHP
} else
    pop_ret_auto(_("Problème de paramètres"), 'warn', "pen_lst.php?ta=m");
include_once("pied.php");
?>
</body>
</html>