<?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_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'];
$coderech = $_GET['code'];

$pbm_per = FALSE;

if ($coderech <> "") {
    // Récupération des informations période
    $row = lit_enr_perloc($coderech);
    if (is_array($row)) {
        $row = encode_str($row);
        extract($row);
    } else
        $pbm_per = TRUE;
} else {
    if ($td <> "add")
        $pbm_per = TRUE;
}

switch ($td) {
    case "add" :
        $titre = _("CREATION PERIODE DE LOCATION");
        $perloc_jourd1 = -1;
        $perloc_jourd2 = -1;
        $perloc_valide = 1;
        break;
    case "edit" :
        $titre = _("MODIFICATION PERIODE DE LOCATION");
        break;
    case "del" :
        $titre = _("SUPPRESSION PERIODE DE LOCATION");
        break;
    default :
        $pbm_per = 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ériode de Location"); ?></title>

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

    <script language="javascript">
        <!--
        var tab1_champ = ["nom:code ; format:alphanum ; req:Y ; txt:<?PHP echo _("Code"); ?> ; lmx:10 ; stok:frmok ; stbad:frmbad",
            "nom:desc; format:txt ; req:Y ; txt:<?PHP echo _("Libellé"); ?> ; lmx:50 ; stok:frmok ; stbad:frmbad",
            "nom:jourd1; format:entier ; req:Y ; txt:<?PHP echo _("Premier jour période"); ?> ; vmn:1 ; stok:frmok ; stbad:frmbad",
            "nom:jourd2; format:entier ; req:Y ; txt:<?PHP echo _("Seconde jour période"); ?> ; vmn:1 ; stok:frmok ; stbad:frmbad",
            "nom:nduree; format:unsigned ; req:Y ; txt:<?PHP echo _("Durée"); ?> ; vmn:1 ; lmx:3 ; stok:frmok ; stbad:frmbad",
            "nom:tduree; format:entier ; req:Y ; txt:<?PHP echo _("Type durée"); ?> ; vmn:1 ; stok:frmok ; stbad:frmbad"];
        //-->
    </script>

    <?PHP if ($pbm_per == FALSE) { ?>
        <script type="text/javascript">
            <!--
            $(function () {
                $("#code").Setcase({caseValue: 'upper', changeonFocusout: true});
                $("#desc").Setcase({caseValue: 'upper', changeonFocusout: true});
            });

            function init_all() {
                init_Body();
                <?php
                switch ($td)
                {
                    case "add" :
                        echo "init_valid_form('enr','perloc_maj','".$_SESSION['date_fmtshort']."',tab1_champ,'','');";
                        echo "init_chk_jour('jourd1','jourd1','jourd2',1);";
                        echo "init_chk_jour('jourd2','jourd1','jourd2',2);";
                        break;
                    case "edit" :
                        echo "init_valid_form('enr','perloc_maj','".$_SESSION['date_fmtshort']."',tab1_champ,'','');";
                        echo "init_chk_jour('jourd1','jourd1','jourd2',1);";
                        echo "init_chk_jour('jourd2','jourd1','jourd2',2);";
                        break;
                    case "view" :
                        echo "readonly_all();";
                        break;
                    case "del" :
                        echo "init_valid_form('enr','perloc_maj','".$_SESSION['date_fmtshort']."',tab1_champ,'','');";
                        echo "readonly_all();";
                        echo "warn_del('perloc');";
                        break;
                }
                ?>
                init_ajax_ville();
                init_ajax_dep();
                init_back('annul', 'click');
                Focus_first();
            }

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

    <?PHP } ?>
</head>
<body>
<?PHP include_once("../inc/entete.inc.php");
if ($pbm_per == FALSE) {
    cre_ent_form($titre, 'perloc_lst.php?ta=m', $_SERVER['HTTP_REFERER'], '');
    ?>
    <form name="perloc_maj" id="perloc_maj" method="post" action="perloc_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="">
        <table width="100%" border="0">
            <tr>
                <td width="160" class="rubfrm" id="f_code" align="right"><?PHP echo _("Code"); ?></td>
                <td>
                   <input name="code" type="text" id="code" value="<?PHP echo $perloc_code ?>" size="10" maxlength="10">
                    <?PHP if ($td == "add")
                        echo '<img src="../img/oblig.png" align="absmiddle" alt="'._("Champ obligatoire").'">';
                    ?>
                </td>
            </tr>
            <tr>
                <td width="160" class="rubfrm" id="f_desc" align="right"><?PHP echo _("Libellé"); ?></td>
                <td>
                    <input name="desc" type="text" id="desc" value="<?PHP echo $perloc_desc ?>" size="50">
                     <img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo _("Champ obligatoire"); ?>">
                </td>
            </tr>
            <tr>
                <td width="160" class="rubfrm" id="f_jourd1" align="right"><?PHP echo _("Commence entre un"); ?>
                <td>
                    <?PHP
                    cre_select('jourd1', 'jourd1', $lng_tjouri, intval($perloc_jourd1), '', _("-- Faites votre choix --"));
                    echo ' <span class="annot_petit_it">('._("inclus").')</span>';
                    echo ' <span class="rubfrm" style="margin-right:5px"> '._("et un").' </span>';
                    cre_select('jourd2', 'jourd2', $lng_tjouri, intval($perloc_jourd2), '', _("-- Faites votre choix --"));
                    echo ' <span class="annot_petit_it">('._("inclus").')</span>';
                    echo '<div class="annot_petit_it">('._("Jours consécutifs").')</div>';
                    ?>
                </td>
            </tr>
            <tr>
                <td width="160" class="rubfrm" id="f_duree" align="right"><?PHP echo _("Sur une durée de"); ?></td>
                <td>
                    <?PHP
                    echo '<input name="nduree" type="text" id="nduree" value="'.$perloc_nduree.'" size="3">';
                    echo ' ';
                    cre_select('tduree', 'tduree', $lng_tduree, intval($perloc_tduree), '', _("-- Faites votre choix --"));
                    echo '<div class="annot_petit_it">('._("A partir du jour de location").')</div>';
                    ?>
                </td>
            </tr>
            <tr>
                <td width="160" class="rubfrm" id="f_valide" align="right"><?PHP echo _("Valide ?"); ?></td>
                <td>
                    <?PHP
                    cre_select('valide', 'valide', $non_oui, (int)$perloc_valide);
                    ?>
                </td>
            </tr>
        </table>
        <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 "view" :
                    break;
                case "del" :
                    echo '<input name="enr" type="button" class="bton_std" id="enr" value="'. _("Supprimer").'">';
                    echo ' <input name="annul" type="button" class="bton_std" id="annul" value="'._("Annuler").'">';
                    break;
            }
            ?>
        </p>
    </form>
<?PHP
} else
    pop_ret_auto(_("Problème de paramètres"), 'warn', "perloc_lst.php");
include_once("pied.php");
?>
</body>
</html>