<?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_mt.inc.php");
include_once("../inc/fic_prm.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'];
$codemt = @$_GET['code'];

$pbm_mt = FALSE;

if ($codemt <> "") {
    // Récupération des données du moyen de transport
    $row = lit_enr_mt($codemt);
    if (is_array($row)) {
        $row = encode_str($row);
        extract($row);
    } else
        $pbm_mt = TRUE;
} else
    if ($td <> "add")
        $pbm_mt = TRUE;

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

$titre = '';
switch ($td) {
    case "add" :
        $titre = _("SAISIE MOYEN DE TRANSPORT");
        break;
    case "edit" :
        $titre = _("EDITION MOYEN DE TRANSPORT");
        break;
    case "del" :
        $titre = _("SUPPRESSION MOYEN DE TRANSPORT");
        break;
    default :
        $pbm_mt = 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 _("Moyen de transport"); ?></title>

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

    <script language="javascript">
        <!--
        var tab1_champ = ["nom:code; format:txt ; req:Y ; txt:<?PHP echo _("Code"); ?> ; lmx:20 ; stok:frmok ; stbad:frmbad",
            "nom:des; format:txt ; req:Y ; txt:<?PHP echo _("Libellé"); ?> ; lmx:50 ; stok:frmok ; stbad:frmbad",
            "nom:notes; format:txt ; req:N ; txt:<?PHP echo _("Notes"); ?> ; stok:frmok ; stbad:frmbad",
            "nom:coutk; format:reel_ns ; req:N ; txt:<?PHP echo _("Coût kilométrique"); ?> ; lmx:10 ; stok:frmok ; stbad:frmbad",
            "nom:coutf; format:reel_ns ; req:N ; txt:<?PHP echo _("Coût forfaitaire"); ?> ; lmx:10 ; stok:frmok ; stbad:frmbad",
            "nom:kmi; format:reel_ns ; req:Y ; txt:<?PHP echo _("Kilométrage inclus"); ?> ; lmx:10 ; stok:frmok ; stbad:frmbad",
            "nom:coutc; format:reel_ns ; req:Y ; txt:<?PHP echo _("Coût complémentaire"); ?>; stok:frmok ; stbad:frmbad",
            "nom:tpsdi; format:liste ; req:Y ; txt:<?PHP echo _("Temps déplacement inclus"); ?>; stok:frmok ; stbad:frmbad"];
        //-->
    </script>

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

            function init_all() {
                init_Body();
                init_fdeci('coutk', <?PHP echo $_SESSION['num_nbdec']; ?>);
                init_fdeci('coutf', <?PHP echo $_SESSION['num_nbdec']; ?>);
                init_fdeci('kmi', <?PHP echo $_SESSION['num_nbdec']; ?>);
                init_fdeci('kms', <?PHP echo $_SESSION['num_nbdec']; ?>);
                init_fdeci('coutc', <?PHP echo $_SESSION['num_nbdec']; ?>);
                init_veriftmt('chxint', true, 'click');
                init_veriftmt('chxext', false, 'click');
                init_chkval_lnk_checkfield('coutf', 'coutas');
                init_chkval_lnk_checkfield('kmi', 'kmill');
                init_chkval_lnk_checkfield('kms', 'kmill');
                init_chk_lnk_valfield('coutas', 'coutf');
                init_chk_lnk_valfield('kmill', 'kmi');
                init_chk_lnk_valfield('kmill', 'kms');
                add_func_click('annul', 'sclose', 'fscomp2');
                <?php
                if ($mt_coutk>0) echo "$('#chxint').trigger('click');"; else echo "$('#chxext').trigger('click');";
                switch ($td)
                {
                    case "add" :
                        echo "init_valid_mt('enr','mt_maj','".$_SESSION['date_fmtshort']."',tab1_champ,'','');";
                        break;
                    case "edit" :
                        echo "init_valid_mt('enr','mt_maj','".$_SESSION['date_fmtshort']."',tab1_champ,'','');";
                        break;
                    case "view" :
                        echo "readonly_all();";
                        break;
                    case "del" :
                        echo "readonly_all();";
                        echo "warn_del('');";
                        break;
                }
                ?>
                Focus_first();
            }

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

<body>

<?PHP
include_once("../inc/entete.inc.php");
if ($pbm_mt == FALSE) {
    cre_ent_form($titre, 'mt_lst.php', $_SERVER['HTTP_REFERER'], '');
    ?>
    <form name="mt_maj" method="post" id="mt_maj"  action="mt_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="mt" type="hidden" id="mt" value="1">
        <input name="nbutton" type="hidden" id="nbutton" value="">
        <table width="100%" border="0">
            <tr>
                <td width="25%" class="rubfrm" id="f_code" align="right"><?PHP echo _("Code"); ?></td>
                <td width="75%">
                    <?PHP if ($td == "add") { ?>
                        <input name="code" type="text" id="code" value="<?PHP echo $mt_code ?>" size="20"
                               maxlength="20">
                        <img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo _("Champ obligatoire"); ?>">
                    <?PHP } else { ?>
                        <input name="code" type="text" id="code" value="<?PHP echo $mt_code ?>" size="20" readonly>
                    <?PHP } ?>
                </td>
            </tr>
            <tr>
                <td class="rubfrm" id="f_des" align="right"><?PHP echo _("Libellé"); ?></td>
                <td>
                    <input name="des" type="text" id="des" value="<?PHP echo $mt_des; ?>" size="50">
                    <img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo _("Champ obligatoire"); ?>">
                </td>
            </tr>
            <tr>
                <td class="rubfrm" id="f_notes" align="right"><?PHP echo _("Notes"); ?></td>
                <td>
                    <textarea name="notes" rows="5" id="notes"><?PHP echo $mt_notes ?></textarea>
                </td>
            </tr>
            <tr>
                <td width="20%" class="rubfrm" id="f_valid" align="right"><?PHP echo _("Actif ?"); ?></td>
                <td width="30%">
                    <?PHP
                    cre_select('valid', 'valid', $non_oui, (int)$mt_valid);
                    ?>
                </td>
            </tr>
            <tr>
                <td class="rubfrm" colspan="2" align="center"><?PHP echo _("Type de moyen de transport"); ?></td>
            </tr>
            <tr>
                <td colspan="2">
                    <table width="100%" border="0">
                        <tr>
                            <td width="100%" align="center" colspan="4" class="annot_petit_it">
                                (<?PHP echo _("Cliquez sur le type de moyen de transport"); ?>)
                            </td>
                        </tr>
                        <tr>
                            <td width="50%" align="center" colspan="2">
                                <div id="chxint" class="falselnk"><?PHP echo _("Interne"); ?> <span id="chx1"
                                                                                                    style="display:inline;"><img
                                            src="../img/ok.png" align="absmiddle"></span></div>
                            </td>
                            <td align="center" colspan="2">
                                <div id="chxext" class="falselnk"><?PHP echo _("Sous-traité"); ?> <span id="chx2"
                                                                                                        style="display:inline;"><img
                                            src="../img/ok.png" align="absmiddle"></span></div>

                            </td>
                        </tr>
                        <tr>
                            <td width="20%" class="rubfrm" id="f_coutk"
                                align="right"><?PHP echo _("Coût kilométrique"); ?></td>
                            <td width="30%">
                                <?PHP cre_input_num('coutk', $mt_coutk, TRUE, FALSE); ?>
                            </td>
                            <td width="20%" class="rubfrm" id="f_coutf"
                                align="right"><?PHP echo _("Coût forfaitaire"); ?></td>
                            <td width="30%">
                                <?PHP
                                cre_input_num('coutf', $mt_coutf, TRUE, FALSE);
                                echo ' / ';
                                echo '<span class="annot_petit_it">';
                                echo '<input type="checkbox" id="coutas" name="coutas" value="ok"';
                                if ($mt_coutas == TRUE)
                                    echo ' checked';
                                echo '> ' . _("A saisir");
                                echo '</span>';
                                ?>
                            </td>
                        </tr>
                        <tr>
                            <td width="50%" colspan="2">&nbsp;</td>
                            <td width="20%" class="rubfrm" id="f_kmi"
                                align="right"><?PHP echo _("Kilométrage inclus"); ?></td>
                            <td width="30%">
                                <?PHP
                                cre_input_num('kmi', $mt_kmi, FALSE, FALSE, FALSE, FALSE);
                                echo ' '._("km").' / ';
                                echo '<span class="annot_petit_it">';
                                echo '<input type="checkbox" id="kmill" name="kmill" value="ok"';
                                if ($mt_kmill == TRUE)
                                    echo ' checked';
                                echo '> ' . _("Illimité");
                                echo '</span>';
                                ?>
                                <br /><span class="annot_petit_it">(<?PHP echo _("Pour le forfait ci-dessus"); ?>)</span>
                            </td>
                        </tr>
                        <tr>
                            <td width="50%" colspan="2">&nbsp;</td>
                            <td width="20%" class="rubfrm" id="f_kms"
                                align="right"><?PHP echo _("Kilomètre suppl."); ?></td>
                            <td width="30%">
                                <?PHP cre_input_num('kms', $mt_coutk, TRUE, FALSE); ?>
                                <span class="annot_petit_it">(<?PHP echo _("Pour le forfait ci-dessus"); ?>)</span>
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
            <tr>
                <td class="rubfrm" colspan="2" align="center"><?PHP echo _("Calculs"); ?></td>
            </tr>
            <tr>
                <td colspan="2">
                    <table width="100%" border="0">
                        <tr>
                            <td width="20%" class="rubfrm" id="f_coutc"
                                align="right"><?PHP echo _("Coût complémentaire"); ?></td>
                            <td width="30%">
                                <?PHP cre_input_num('coutc', $mt_couc, TRUE); ?>
                            </td>
                            <td width="20%" class="rubfrm" id="f_tpsdi"
                                align="right"><?PHP echo _("Temps déplacement inclus"); ?></td>
                            <td width="30%">
                                <?PHP
                                cre_select('tpsdi', 'tpsdi', $non_oui, (int)$mt_tpsdi);
                                ?>
                                <br />
                                <span
                                    class="annot_petit_it">(<?PHP echo _("Si 'Non', le coût salarial du déplacement sera décompté dans le prix de revient"); ?></span>
                            </td>
                        </tr>
                    </table>
                </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
    pop_ret_auto(_("Problème de paramètres"), 'warn', "index.php");
include_once("pied.php");
?>
</body>
</html>