<?php
/****************************************************************************************
 * SMI (Services Maintenance Interventions) est une gestion libre de maintenance et de SAV
 *
 * Version 1.0.2
 *
 * Copyright (C) 2006-2015  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_age.inc.php");
include_once("../inc/fic_droits.inc.php");
include_once("../inc/fic_zc.inc.php");
include_once("../inc/func.inc.php");
include_once("../inc/func_log.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);
$_POST = clean_str($_POST);

$titre = _("EDITION FICHE VIERGE DE RELEVE");
$pbm_rel = FALSE;
$urlimp = '';

switch (intval($_SESSION["niv_log"]))
{
    case 4 :
        $row = lit_enr_age(@$_SESSION["code_age"], TRUE);
        if (is_array($row)) {
            $row = encode_str($row);
            extract($row);

            if (@$_POST["nbutton"] == "enr") // On a validé
            {
                if ((@$_POST["tfr"] <> "") AND (@$_POST["client"] <> ""))
                    $urlimp = "rel_pdf_vierge.php?tfr=" . @$_POST["tfr"] . "&cc=" . @$_POST["client"];
            }
        } else
            $pbm_rel = TRUE;
        break;
    case 5 :
    case 9 :
        if (@$_POST["nbutton"] == "enr") // On a validé
        {
            if ((@$_POST["tfr"] <> "") AND (@$_POST["client"] <> ""))
                $urlimp = "rel_pdf_vierge.php?tfr=" . @$_POST["tfr"] . "&cc=" . @$_POST["client"];
        }
        break;
    default :
        $pbm_rel = 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 _("Relevés - Etat Vierge"); ?></title>

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

    <script language="javascript">
        <!--
        var tab1_champ = ["nom:tfr ; format:liste ; req:Y ; txt:<?PHP echo _("Etat à imprimer"); ?> ; vmn:1 ; stok:frmok ; stbad:frmbad",
            "nom:client ; format:liste ; req:Y ; txt:<?PHP echo _("Client"); ?> ; vmn:1 ; stok:frmok ; stbad:frmbad"];
        //-->
    </script>

    <script type="text/javascript">
        <!--
        function init_all() {
            init_Body();
            <?PHP
            if ($urlimp <> '')
                echo "init_fenimp('".$urlimp."');";
            echo "init_valid_form('enr','rel_vierge','".$_SESSION['date_fmtshort']."',tab1_champ,'','');";
            ?>
            Focus_first();
        }

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

<body>

<?php
include_once("../inc/entete.inc.php");
if ($pbm_rel == FALSE) {
?>
    <p align="center"><span class="titrepage"><?PHP echo $titre ?></span></p>
    <form name="rel_vierge" id="rel_vierge" method="post" action="rel_vierge.php">
    <input name="nbutton" type="hidden" id="nbutton" value="">
    <table width="360" border="0" cellspacing="0" cellpadding="0" align="center">
        <tr>
            <td class="rubfrm" id="f_tfr">
                <div align="center"><?PHP echo _("Choisissez l'état à imprimer"); ?></div>
            </td>
        </tr>
        <tr>
            <td>
                <div align="center">
                    <?PHP
                    cre_select('tfr', 'tfr', $tab_typ_rel, '', '', _("-- Faites votre choix --"), 1, FALSE, '', '', FALSE);
                    ?>
                </div>
            </td>
        </tr>
    </table>
    <br />
    <table width="360" border="0" cellspacing="0" cellpadding="0" align="center">
        <tr>
            <td class="rubfrm" id="f_client">
                <div align="center"><?PHP echo _("Choisissez un client"); ?></div>
            </td>
        </tr>
        <tr>
            <td>
                <div align="center">
                    <?PHP
                    $tab_cli = [];
                    // Création de la liste des clients
                    $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
                    switch ($_SESSION["niv_log"])
                    {
                        // Agence
                        case 4 :
                            $rech = "SELECT * FROM `" . TBCLI . "` WHERE `cli_prop` = '" . @$_SESSION["code_age"] . "' OR ((`cli_prop` = '' OR `cli_prop` IS NULL) AND `cli_codepays`='" . $age_codepays . "') ORDER BY cli_ste, cli_nom";
                            break;
                        case 5 :
                        case 9 :
                            $rech = "SELECT * FROM `" . TBCLI . "` ORDER BY cli_ste, cli_nom";
                            break;
                    }
                    $rows = $db->get_results($rech, ARRAY_A);
                    if ($rows) {
                        if ($_SESSION["niv_log"] == 4)
                            $tab_depzc = tab_zcc_age_open(@$_SESSION["code_age"], FALSE);
                        foreach ($rows as $row) {
                            $row = encode_str($row);
                            extract($row);
                            if ($cli_ste <> "")
                                $texte = $cli_ste . " (" . $cli_code . ")";
                            else
                                $texte = $cli_nom . " " . $cli_prenom . " (" . $cli_code . ")";
                            switch ($_SESSION["niv_log"])
                            {
                                // Agence
                                case 4 :
                                    if ($cli_prop == @$_SESSION["code_age"])
                                        $tab_cli[$cli_code] = $texte;
                                    else {
                                        if (count($tab_depzc) > 0) {
                                            if (exist_in_array($cli_dep . "_" . $cli_codepays, $tab_depzc))
                                                $tab_cli[$cli_code] = $texte;
                                        }
                                    }
                                    break;
                                case 5 :
                                case 9 :
                                    $tab_cli[$cli_code] = $texte;
                                break;
                            }

                        }
                    }
                    $db->disconnect();
                    cre_select('client', 'client', $tab_cli, '', '', _("-- Faites votre choix --"), 1, FALSE, '', '', FALSE);
                    ?>
                </div>
            </td>
        </tr>
    </table>
    <p align="center"><input type="button" class="bton_std" name="enr" id="enr" value="<?PHP echo _("Valider"); ?>"></p>
    </form>
<?PHP
} else
    pop_ret_auto(_("Problème de paramètres"), 'warn', "index.php");
include_once("pied.php");
?>
</body>
</html>