<?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
 ****************************************************************************************/

session_start();

include_once("../inc/config.inc.php");
include_once("../inc/func_log.inc.php");
if (CheckURLLog(FALSE) == FALSE) header("Location: ../index.php");
if (CheckNivLog("5-9") == FALSE) header("Location: ../index.php");
include_once("../inc/func.inc.php");
include_once("../inc/func_date.inc.php");
include_once("../inc/func_geo.inc.php");
include_once("../inc/func_txt.inc.php");
include_once("../inc/fic_age.inc.php");
include_once("../inc/fic_cli.inc.php");
include_once("../inc/fic_droits.inc.php");
include_once("../inc/fic_tec.inc.php");
include_once("../inc/lst.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);

$pbm_syn = FALSE;
$ts_ok = FALSE;
$ts = '';

if (isset($_GET['ts'])) {
    $ts = intval($_GET['ts']);
    $ts_ok = TRUE;

    switch ($ts) {
        case 1 :
        case 2 :
        case 3 :
        case 4 :
        case 5 :
        case 6 :
        case 7 :
            // Les dates sont remplies sur un formulaire validé, donc on peut afficher les statistiques
            if ((isset($_GET['date1f'])) AND (isset($_GET['date2f']))) {
                $age_select = "";
                for ($i = 0; $i < count($_GET["age"]); $i++) {
                    $age_select .= $_GET["age"][$i] . "-";
                }
                $age_select_tab = explode("-", substr($age_select, 0, strlen($age_select) - 1));

                $cat = @$_GET["cat"];

                $date1 = datetomysql($_GET['date1f']);
                $date2 = datetomysql($_GET['date2f']);
            }
            break;
        default :
            $pbm_syn = TRUE;
            $ts_ok = FALSE;
            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 _("Synthèses Interventions"); ?></title>

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

    <script language="javascript">
    <!--
    var tab_champ = [];
    //-->
    </script>

    <script type="text/javascript">
        <!--
        function init_datepicker() {
            $.datepicker.setDefaults({
                closeText: "<?PHP echo _("Fermer"); ?>",
                prevText: "<?PHP echo _("Précédent"); ?>",
                nextText: "<?PHP echo _("Suivant"); ?>",
                currentText: "<?PHP echo _("Aujourd'hui"); ?>",
                monthNames: ["<?PHP echo implode('","',$lng_tmoisf); ?>"],
                monthNamesShort: ["<?PHP echo implode('","',$lng_tmoism); ?>"],
                dayNames: ["<?PHP echo implode('","',$lng_tjourf); ?>"],
                dayNamesShort: ["<?PHP echo implode('","',$lng_tjourm); ?>"],
                dayNamesMin: ["<?PHP echo implode('","',$lng_tjours); ?>"],
                weekHeader: "<?PHP echo _("Sem."); ?>",
                dateFormat: "<?PHP echo $_SESSION['date_fmtshort']; ?>",
                firstDay: 1,
                isRTL: !1,
                changeMonth: true,
                changeYear: true,
                showMonthAfterYear: !1,
                yearSuffix: "",
                showButtonPanel: true,
                showOn: "both",
                buttonImageOnly: true,
                buttonImage: "../img/calendar.png",
                buttonText: "<?PHP echo _("Calendrier"); ?>"
            });
            $("#date1f").datepicker({
                onSelect: function (datesel) {
                    $("#date1f").blur();
                    chk_datedif(datesel, this.id, '<?PHP echo $_SESSION['date_fmtshort']; ?>', true, '', '', 'date2f',false);
                }
            });
            $("#date2f").datepicker({
                onSelect: function (datesel) {
                    $("#date2f").blur();
                    chk_datedif(datesel, this.id, '<?PHP echo $_SESSION['date_fmtshort']; ?>', true, 'date1f', '', '',false);
                }
            });
        }

        function init_all() {
            init_Body();
            init_datepicker();
            <?PHP
            if ($ts_ok == TRUE)
                echo "readonly_id('ts',false);";
            ?>
            init_valid_form('enr','inter','<?PHP echo $_SESSION['date_fmtshort']; ?>',tab_champ,'','');
            init_autohref('new','click','int_syn.php',false);
            Focus_first();
        }

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

</head>

<body>
<?php include_once("../inc/entete.inc.php"); ?>
<p align="center"><span class="titrepage"><?PHP echo _("SYNTHESE INTERVENTIONS"); ?></span></p>
<?PHP
if ($pbm_syn == FALSE) {
    echo '<form name="inter" id="inter"';
    if ($ts_ok == FALSE)
        echo ' method="get" action="int_syn.php"';
    else
    {
        echo ' method="get" action="int_syn_lst.php"';
        echo ' target="_blank"';
    }
    echo '>';
    echo '<input name="nbutton" type="hidden" id="nbutton" value="">';
    echo '<br />';
    echo '<div align="center">';
    cre_select('ts', 'ts', $tab_txt_syn_int, intval($ts), '', _("-- Faites votre choix --"), 1, FALSE, '', '', FALSE);

    switch ($ts) {
        // Synthèse des interventions, pour un client, sur une période donnée
        case 1 :
            echo '<br />';
            echo '<br />';
            if (nb_cli('') > 0) {
                echo '<select name="cli" id="cli">';
                echo '<option value="">' . _("-- Faites votre choix --") . '</option>';
                $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
                $rech = "SELECT * FROM `" . TBCLI . "` ORDER BY cli_ste,cli_nom";
                $rows = $db->get_results($rech, ARRAY_A);
                if ($rows) {
                    foreach ($rows as $row) {
                        $row = encode_str($row);
                        extract($row);
                        if ($cli_ste <> "")
                            $txt_cli = $cli_ste . " (" . Retournecp_Id($cli_ville, FALSE) . ", " . Retourneville_Id($cli_ville, FALSE) . ") - " . $cli_code;
                        else
                            $txt_cli = $cli_nom . " " . $cli_prenom . " (" . Retournecp_Id($cli_ville, FALSE) . ", " . Retourneville_Id($cli_ville, FALSE) . ") - " . $cli_code;
                        echo '<option value="' . $cli_code . '">' . $txt_cli . '</option>';
                    }
                }
                $db->disconnect();
                echo '</select>';
            }
            break;

        // Synthèse des interventions, pour une agence, sur une période donnée
        case 2 :
            // Synthèse des interventions, pour une agence gestionnaire, sur une période donnée
        case 3 :
            // Synthèse des interventions, pour une agence responsable de site, sur une période donnée
        case 4 :
            echo '<br />';
            echo '<br />';
            if (nb_age() > 0) {
                echo '<select name="age" id="age">';
                echo '<option value="">' . _("-- Faites votre choix --") . '</option>';
                $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
                $rech = "SELECT * FROM `" . TBAGE . "` ORDER BY age_nom";
                $rows = $db->get_results($rech, ARRAY_A);
                if ($rows) {
                    foreach ($rows as $row) {
                        $row = encode_str($row);
                        extract($row);
                        $txt_age = $age_nom . " (" . $age_code;
                        if ($age_ouvert == 1)
                            $txt_age .= " - "._("ouvert");
                        else
                            $txt_age .= " - "._("fermée");
                        $txt_age .= ")";
                        echo '<option value="' . $age_code . '">' . $txt_age . '</option>';
                    }
                }
                $db->disconnect();
                echo '</select>';
            }
            break;

        // Synthèse des interventions, pour un technicien, sur une période donnée
        case 5 :
            // Synthèse des interventions, pour un technicien responsable, sur une période donnée
        case 6 :
            // Synthèse des interventions, pour un technicien intervenant, sur une période donnée
        case 7 :
            echo '<br />';
            echo '<br />';
            $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
            $rech = "SELECT * FROM `" . TBTEC . "`";
            $rech .= " WHERE tec_codeage <> ''";
            $rech .= " ORDER BY tec_nom, tec_prenom";
            $rows = $db->get_results($rech, ARRAY_A);
            $db->disconnect();
            cre_select_tab('tec', 'tec', $rows, 'tec_code', 'tec_nom', 'tec_prenom-tec_codeage', '', '', _("-- Faites votre choix --"));
            break;
    }

    if ($ts_ok == TRUE)
    {
        echo '<br />';
        echo '<br />';
        ?>
        <table width="400" border="0" align="center">
            <tr>
                <td width="30" class="rubfrm" id="f_date1" align="right"><?PHP echo _("Du"); ?>...</td>
                <td>
                    <input name="date1f" type="text" id="date1f" size="10" maxlength="10" readonly>
                     <img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo _("Champ obligatoire"); ?>">
                </td>
                <td width="30" class="rubfrm" id="f_date2f" align="right"><?PHP echo _("Au"); ?>...</td>
                <td>
                    <input name="date2f" type="text" id="date2f" size="10" maxlength="10" readonly>
                     <img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo _("Champ obligatoire"); ?>">
                </td>
            </tr>
        </table>
<?PHP
    }

echo '</div>';
echo '<p align="center">';
echo '<input name="enr" type="button" class="bton_std" id="enr" value="' . _("Valider") . '">';
echo '<input name="init" type="reset" class="bton_std" id="init" value="' . _("Réinitialiser") . '">';
if ($ts_ok == TRUE)
    echo '<input name="new" type="button" class="bton_std" id="new" value="' . _("Nouvelle synthèse") . '">';
echo '</p>';
echo '</form>';

} else
    pop_ret_auto(_("Problème de paramètres"), 'warn', "index.php");
include_once("pied.php")
?>
