<?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_age.inc.php");
include_once("../inc/fic_cli.inc.php");
include_once("../inc/fic_droits.inc.php");
include_once("../inc/fic_int.inc.php");
include_once("../inc/fic_plan.inc.php");
include_once("../inc/fic_rdv.inc.php");
include_once("../inc/fic_statut.inc.php");
include_once("../inc/fic_tac.inc.php");
include_once("../inc/fic_tec.inc.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_time.inc.php");
include_once("../inc/func_txt.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");
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"]);
$_SESSION["lnk_lst"] = '';
check_modules();

// Variables Formulaire
fix_magic_quotes();
$_GET = clean_str($_GET);

$fi = "";
$cat = "";
$urg = "";
$dateddef1 = "";
$dateddef2 = "";
$dateddefp1 = "";
$dateddefp2 = "";
$init = 0;
if (isset($_GET['fi']) && ($_GET['fi'] <> ""))
    $fi = intval($_GET['fi']);
if (isset($_GET['cat']) && ($_GET['cat'] <> ""))
    $cat = $_GET['cat'];
if (isset($_GET['urg']) && ($_GET['urg'] <> ""))
    $urg = intval($_GET['urg']);
if (isset($_GET['dateddef1']) && ($_GET['dateddef1'] <> "")) {
    if (chkdate($_GET['dateddef1']) == TRUE)
        $dateddef1 = $_GET['dateddef1'];
}
if (isset($_GET['dateddef2']) && ($_GET['dateddef2'] <> "")) {
    if (chkdate($_GET['dateddef2']) == TRUE)
        $dateddef2 = $_GET['dateddef2'];
}
if (isset($_GET['dateddefp1']) && ($_GET['dateddefp1'] <> "")) {
    if (chkdate($_GET['dateddefp1']) == TRUE)
        $dateddefp1 = $_GET['dateddefp1'];
}
if (isset($_GET['dateddefp2']) && ($_GET['dateddefp2'] <> "")) {
    if (chkdate($_GET['dateddefp2']) == TRUE)
        $dateddefp2 = $_GET['dateddefp2'];
}
if (isset($_GET['init']) && ($_GET['init'] <> ""))
    $init = intval($_GET['init']);

$tab_cli = [];
if (@$_SESSION["niv_log"] == 1)
    $tab_cli = give_tab_rcli($_SESSION["code_log"], TRUE);

// Construction de la table d'entête pour les filtres par colonnes
if ((count($_SESSION["tri_col"]) <= 0) OR ($init == 1))
    $_SESSION["tri_col"] = give_tab_tri_col($int_titre_col, $int_titre_col_rech);
$_SESSION["typ_filtres"] = "int";
$_SESSION["lnk_lst"] = $lnk_int_lst;
?>
<!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 _("Liste Interventions"); ?></title>

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

    <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"); ?>"
            });

            <?PHP if (@$_GET['ta'] <> "i") { ?>
            $("#dateddef1").datepicker();
            $("#dateddef2").datepicker();
            $("#dateddefp1").datepicker();
            $("#dateddefp2").datepicker();
            <?PHP } ?>
        }

        function init_all() {
            init_Body();
            init_autohref_classe('falselnkimg','<?PHP echo str_escape(_("Merci de confirmer<br />Sinon, cliquez sur 'Annuler'")); ?>');
            init_datepicker();
            <?PHP
            if (@$_GET['ta'] <> "i") {
                echo "init_autoraz('razdateddef1','dateddef1','click');";
                echo "init_autoraz('razdateddef2','dateddef2','click');";
                echo "init_autoraz('razdateddefp1','dateddefp1','click');";
                echo "init_autoraz('razdateddefp2','dateddefp2','click');";
            }
            ?>
            Focus_first();
        }

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

</head>

<body>
<?php // <iframe id="iframePhpExcel" src=""></iframe>	?>
<?php include_once("../inc/entete.inc.php"); ?>
<div id="loading" style="position:absolute; z-index:1000;">
    <div id='loading-image'></div>
    <div id='loading-content'></div>
</div>
<div id='loading-debug' style="position:absolute; z-index:1000;"></div>

<?php
if (@$_SESSION["niv_log"] >= 5)
    echo '<p align="center"><span class="titrepage">' . _("LISTE DES INTERVENTIONS") . '</span></p>';
else
    echo '<p align="center"><span class="titrepage">' . _("VOS INTERVENTIONS") . '</span></p>';

$fic_imp = "int_lsti.php";
if ((@$_SESSION["niv_log"] <> 1) AND (@$_SESSION["niv_log"] <> 11) AND (@$_SESSION["niv_log"] <> 10))
    $url_add = "cli_lst.php?td=int&tl=1";
if ((@$_SESSION["niv_log"] == 5) OR (@$_SESSION["niv_log"] == 9))
    $fic_exp = TRUE;
if (@$_SESSION["id_ccli"] == 0)
    $url_rss = lien_rss(@$_SESSION["code_log"], @$_SESSION["niv_log"], "int");

$tab_fi = [];
$tab_int = [];

switch ($_SESSION["niv_log"]) {
    case 1 :
        $tab_fi = $tab_fi_int_std;
        break;
    default :
        // création du tableau des interventions affichables
        if ($_SESSION["niv_log"] == 3)
            $tab_int = give_tab_int_ok_tec(@$_SESSION["code_log"], @$_SESSION["code_age"], TRUE);
        $tab_fi = $tab_fi_int_full;
        // On vérifie si le module planning est bien en place
        if ($mod_planning == TRUE) {
            $tab_fi[99] = _("Interventions à planifier (en cours)");
            $tab_fi[100] = _("7 prochains jours (à planifier)");
            $tab_fi[101] = _("2 prochaines semaines (à planifier)");
        }
        break;
}
$db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);

// création de la commande MySQL initiale
$rechnum = cree_strrechlstintfi(TRUE);
$rech = cree_strrechlstintfi();
// Modification de la chaine de recherche en fonction des filtres par colonne
$rechnum = cree_strrechlst_filtre_col($rechnum);
$rech = cree_strrechlst_filtre_col($rech);
// Modification de cette chaine pour tenir compte des filtres spécifiques N°cessitant des accès à des
// bases complémentaires
// $rech = cree_strrechlstintfi2($rech,TRUE);
// $rechnum = cree_strrechlstintfi2($rechnum);
// Rajout des tris
switch (@$_SESSION["niv_log"]) {
    case 1 :
        if (count($tab_cli) <= 1) {
            $rech .= crestr_triord($intcli_titre_col, "int_code", TRUE, $limit);
        } else
            $rech .= crestr_triord($int_titre_col, "int_code", TRUE, $limit);
        break;
    default :
        $rech .= crestr_triord($int_titre_col, "int_code", TRUE, $limit);
        break;
}
// Exécution de la requête
$numrows = $db->get_var($rechnum);
$db->disconnect();

switch (@$_SESSION["niv_log"]) {
    case 3 :
        if (count($tab_int) == 0)
            $numrows = 0;
        break;
    default :
        // $numrows = count($rows);
        break;
}

if ($numrows > 0) {
    include_once("formr.inc.php");

    $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);

    $rows = $db->get_results($rech, ARRAY_A);

    // *** Pagination de début
    pagine_lst($numrows, $limit);

    // *** Affichage de la table
    echo "<table class=\"Mtable\" border=\"0\" width=\"100%\" cellpadding=\"0\" cellspacing=\"0\">\n";

    // création entête
    switch (@$_SESSION["niv_log"]) {
        case 1 :
            titlst($intcli_titre_col);
            break;
        default :
            titlst($int_titre_col);
            break;
    }
    echo "<th>" . _("Cliquer") . "</th>\n";


    $i = 0;

    // Inclusion module affichage liste interventions
    include("../inc/intr_lst.inc.php");

    echo "</table>\n";
    // *** Fin affichage de la table

    $db->disconnect();

    // *** Pagination de pied
    pagine_lst($numrows, $limit);

    $taille_piedla = "";
    include_once("piedla.inc.php");
} else
    retpp();

include_once("pied.php");
?>
</body>
</html>