<?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_pen.inc.php");
include_once("../inc/fic_prm.inc.php");
include_once("../inc/fic_taxes.inc.php");
include_once("../inc/func.inc.php");
include_once("../inc/func_date.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'];
$codep = @$_GET['codep'];
$idpb = intval(@$_GET['npb']);
$nextmin = intval(@$_GET['nm']);
$pour = intval(@$_GET['po']);
$ud = intval(@$_GET['ud']);
$pbm_pb = FALSE;
if (($pour <> 0) AND ($pour <> 1))
    $pbm_pb = TRUE;


if ((trim($codep) <> "") AND ($pbm_pb == FALSE)) {
    // Récupération des données de la pénalité
    $row = lit_enr_pen($codep);
    if (is_array($row)) {
        $row = encode_str($row);
        extract($row);

        $row = lit_enr_pen($penbar_codepen);
        if (is_array($row)) {
            $row = encode_str($row);
            extract($row);
        }

        if ($idpb > 0) {
            if ($idpb == last_id_penbar_in_pen($codep, TRUE)) {
                // Récupération des données du tarif consommable
                $row = lit_enr_penbar_id($idpb);
                if (is_array($row)) {
                    $row = encode_str($row);
                    extract($row);
                } else
                    $pbm_pb = TRUE;
            } else
                $pbm_pb = TRUE;
        } else {
            if ($idpb < 0)
                $pbm_pb = TRUE;
            else {
                if ($td <> "add")
                    $pbm_pb = TRUE;
            }
        }
    } else
        $pbm_pb = TRUE;
} else
    $pbm_pb = TRUE;

$codeadev = give_dev_codea_defaut($_SESSION["lng"], TRUE);

switch ($td) {
    case "add" :
        $titre = _("AJOUT PENALITE");
        if (exist_infini_penbar($codep, TRUE) == FALSE) {
            $penbar_codepen = $codep;
            $penbar_min = $nextmin;
            $penbar_max = $nextmin + 1;
        } else
            $pbm_pb = TRUE;
        break;
    case "edit" :
        $titre = _("EDITION PENALITE");
        break;
    case "del" :
        $titre = _("SUPPRESSION PENALITE");
        break;
    default :
        $pbm_pb = 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 _("Penalité Location"); ?></title>

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

    <script language="javascript">
        <!--
        var tab1_champ = ["nom:mini; format:unsigned ; req:Y ; txt:<?PHP echo _("Minimum"); ?> ; lmx:10 ; stok:frmok ; stbad:frmbad",
            "nom:maxi; format:unsigned ; req:Y ; txt:<?PHP echo _("Maximum"); ?> ; lmx:10 ; stok:frmok ; stbad:frmbad",
            "nom:valeur; format:reel_ns ; req:Y ; txt:<?PHP echo _("Valeur"); ?> ; lmx:10 ; vmn : 0.01; stok:frmok ; stbad:frmbad"];
        //-->
    </script>

    <script type="text/javascript">
        <!--
        <?PHP cre_html_penbar('detbarpen', $td, $codep, $pour, 'window.opener.'); ?>

        function init_all() {
            init_Body();
            init_fdeci('valeur', <?PHP echo $_SESSION['num_nbdec']; ?>);
            <?PHP
            switch ($td)
            {
                case "add" ;
                    echo "init_valid_tcons_penbar('enr','penbar_maj','".$_SESSION['date_fmtshort']."',tab1_champ,'','');";
                    break;
                case "edit" :
                    echo "init_valid_tcons_penbar('enr','penbar_maj','".$_SESSION['date_fmtshort']."',tab1_champ,'','');";
                    break;
                case "view" :
                    echo 'readonly_all();';
                    break;
                case "del" :
                    echo 'readonly_all();';
                    echo "warn_del('');";
                    break;
            }
            ?>
            tbpenbar();
            add_func_click('annul', 'sclose','');
            Focus_first();
        }

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

<?PHP
if ($pbm_pb == FALSE) {
    ?>
    <p align="center"><span class="titrepage"><?PHP echo $titre ?></span></p>
    <p align="center"><?PHP echo _("Pour la pénalité"); ?> : <span class="titre_gras"><?php echo $pen_desc; ?></span></p>

    <form name="penbar_maj" id ="penbar_maj" method="post" action="penbar_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="codep" type="hidden" id="codep" value="<?PHP echo $codep ?>">
        <input name="ud" type="hidden" id="ud" value="<?PHP echo $ud ?>">
        <input name="pour" type="hidden" id="pour" value="<?PHP echo $pour ?>">
        <input name="npb" type="hidden" id="npb" value="<?PHP echo $idpb; ?>">
        <input name="nbutton" type="hidden" id="nbutton" value="">
        <table width="100%" border="0">
            <tr>
                <td width="25%" class="rubfrm" id="f_mini" align="right"><?PHP echo _("Retard - Minimum"); ?></td>
                <td>
                    <input name="mini" type="text" id="mini" style="text-align:right" value="<?PHP echo intval($penbar_min); ?>" size="10" readonly="1">
                     <span class="annot_gras_it"><?PHP echo $lng_tduree[$ud]; ?></span>
                </td>
            </tr>
            <tr>
                <td class="rubfrm" id="f_maxi" align="right"><?PHP echo _("Retard - Maximum"); ?></td>
                <td>
                    <input name="maxi" type="text" id="maxi" style="text-align:right" value="<?PHP echo intval($penbar_max); ?>" size="10">
                     <span class="annot_gras_it"><?PHP echo $lng_tduree[$ud]; ?></span>
                    <?PHP if ($td <> "del") { ?>
                        <span class="annot_petit_it">(<?PHP echo _("Au moins"); ?> <?PHP echo $penbar_max; ?>
                            , <?PHP echo _("ou '0' pour infini"); ?>)</span>
                    <?PHP } ?>
                </td>
            </tr>
            <tr>
                <td class="rubfrm" id="f_valeur" align="right"><?PHP echo _("Pénalité de"); ?></td>
                <td>
                    <?PHP
                    cre_input_num('valeur', $penbar_valeur, TRUE);
                    ?>
                </td>
            </tr>
        </table>
        <p align="center">
            <?PHP
            switch ($td)
            {
                case "add" :
                case "edit" :
                    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('', 'fscomp2');
?>
</body>
</html>
