<?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');
if ($pos !== FALSE) {
    header('Location: ../index.php');
}

include_once('../inc/fic_droits.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(valsession('code_log'));
// Variables Formulaire
fix_magic_quotes();
$_GET = clean_str($_GET);

$td = $_GET['td'];
$ndev = (int)$_GET['ndev'];
$tx = valget('tx'); // Source de l'appel (tx="f" -> depuis une fiche)

$pbm_dev = FALSE;

if ($ndev > 0) {
    $row = lit_enr_dev_id($ndev);
    if (is_array($row)) {
        $row = encode_str($row);
        extract($row);
    } else {
        $pbm_dev = TRUE;
    }
} else {
    if ($td <> 'add') {
        $pbm_dev = TRUE;
    }
}

$titre = '';
switch ($td) {
    case 'add' :
        $titre = _('CREATION DEVISE');
        $dev_lng = str_majuscules($_SESSION['lng']);
        break;
    case 'edit' :
        $titre = _('MODIFICATION DEVISE');
        break;
    case 'del' :
        $titre = _('SUPPRESSION DEVISE');
        break;
    default :
        $pbm_dev = 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 Devise'); ?></title>

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

    <script language="javascript">
        <!--
        var tab_champ = ["nom:codea ; format:alpha ; req:Y ; txt:<?php echo _('Code Alphabétique'); ?> ; lmx:3; stok:frmok ; stbad:frmbad",
            "nom:coden ; format:unsigned ; req:Y ; txt:<?php echo _('Code Numérique'); ?> ; lmx:3; stok:frmok ; stbad:frmbad",
            "nom:nom ; format:txt ; req:Y ; txt:<?php echo _('Nom'); ?> ; lmx:50; stok:frmok ; stbad:frmbad",
            "nom:symiso; format:txt ; req:N ; txt:<?php echo _('Symbole ISO'); ?> ; lmx:10; stok:frmok ; stbad:frmbad",
            "nom:symtxt; format:txt ; req:N ; txt:<?php echo _('Symbole texte'); ?> ; lmx:10; stok:frmok ; stbad:frmbad"];
        //-->
    </script>

    <?php if ($pbm_ta == FALSE) { ?>
        <script type="text/javascript">
            <!--
            function init_all() {
                init_Body();
                <?php
                switch ($td)
                {
                    case 'add' :
                        echo "init_valid_form('enr','dev_maj','".valsession('date_fmtshort')."',tab_champ,'','');";
                        break;
                    case 'edit' :
                        echo "init_valid_form('enr','dev_maj','".valsession('date_fmtshort')."',tab_champ,'','');";
                        echo "readonly_id('codea-lng',false);";
                        break;
                    case 'del' :
                        echo "warn_del('');";
                        echo 'readonly_all();';
                        break;
                    case 'view' :
                        echo 'readonly_all();';
                        break;
                }
                ?>
                add_func_click('quit', 'sclose', 'fscomp');
                Focus_first();
            }

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

<body>
<?php
if ($tx <> 'f') {
    include_once('../inc/entete.inc.php');
}
if ($pbm_dev == FALSE) {
    cre_ent_form($titre, 'dev_lst.php', $_SERVER['HTTP_REFERER'], '');
    ?>
    <form name="dev_maj" id="dev_maj" method="post" action="dev_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="tx" type="hidden" id="tx" value="<?php echo $tx ?>">
        <input name="nbutton" type="hidden" id="nbutton" value="">
        <table width="100%" border="0">
            <tr>
                <td width="10%" class="rubfrm" id="f_codea" align="right"><?php echo _('Code Alphabétique'); ?></td>
                <td width="43%">
                    <input name="codea" type="text" id="codea" value="<?php echo $dev_codea ?>" size="3">
                    <?php if ($td == 'add') {
                        echo ' <img src="../img/oblig.png" align="absmiddle" alt="' . _('Champ obligatoire') . '">';
                    }
                    ?>
                </td>
            </tr>
            <tr>
                <td class="rubfrm" id="f_coden" align="right"><?php echo _('Code Numérique'); ?></td>
                <td><input name="coden" type="text" id="coden" value="<?php echo $dev_coden ?>" size="3">
                    <img src="../img/oblig.png" align="absmiddle" alt="<?php echo _('Champ obligatoire'); ?>"></td>
            </tr>
            <tr>
                <td class="rubfrm" id="f_nom" align="right"><?php echo _('Nom'); ?></td>
                <td><input name="nom" type="text" id="nom" value="<?php echo $dev_nom ?>" size="50">
                    <img src="../img/oblig.png" align="absmiddle" alt="<?php echo _('Champ obligatoire'); ?>"></td>
            </tr>
            <tr>
                <td class="rubfrm" id="f_symiso" align="right"><?php echo _('Symbole ISO'); ?></td>
                <td><input name="symiso" type="text" id="symiso" value="<?php echo $dev_symiso ?>" size="10">
                </td>
            </tr>
            <tr>
                <td class="rubfrm" id="f_symtxt" align="right"><?php echo _('Symbole texte'); ?></td>
                <td><input name="symtxt" type="text" id="symtxt" value="<?php echo $dev_symtxt ?>" size="10">
                </td>
            </tr>
            <tr>
                <td width="160" class="rubfrm" id="f_defaut" align="right"><?php echo _('Défaut ?'); ?></td>
                <td>
                    <?php
                    cre_select('defaut', 'defaut', $non_oui, $dev_defaut);
                    ?>
                </td>
            </tr>
            <tr>
                <td width="160" class="rubfrm" id="f_lng" align="right"><?php echo _('Langue'); ?></td>
                <td>
                    <?php
                    cre_select('lng', 'lng', $tab_lngdisp, strtolower($dev_lng));
                    ?>
                </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="' . _('Enregistrer') . '">';
                    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;
            }
            if ($tx == 'f') {
                echo ' <input name="quit" type="button" class="bton_std" id="quit" value="' . _('Quitter') . '">';
            }
            ?>
        </p>
    </form>
    <?php
} else {
    if ($tx == 'r') {
        close_fen_auto('', 'fscomp');
    } else {
        pop_ret_auto(_('Problème de paramètres'), 'warn', 'index.php');
    }
}
if ($tx <> 'f') {
    include_once('pied.php');
}
?>
</body>
</html>