<?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_age.inc.php");
include_once("../inc/fic_do.inc.php");
include_once("../inc/fic_droits.inc.php");
include_once("../inc/fic_st.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("../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_tec = FALSE;

$tl = intval(@$_GET['tl']);

if (($tl < 1) AND ($tl > 2))
    $pbm_tec = TRUE;

if (@$_SESSION["niv_log"] < 4)
    $pbm_tec = TRUE;

if (@$_SESSION["niv_log"] == 4) {
    $row = lit_enr_age(@$_SESSION["code_age"], TRUE);
    if (is_array($row)) {
        $row = encode_str($row);
        extract($row);
        $tl = 1;
    } else
        $pbm_tec = TRUE;
}

if (@$_SESSION["niv_log"] == 6) {
    $row = lit_enr_do(@$_SESSION["code_do"]);
    if (is_array($row)) {
        $row = encode_str($row);
        extract($row);
        $tl = 2;
    } else
        $pbm_tec = TRUE;
}
?>
<!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 _("Impression Liste Techniciens"); ?></title>

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

    <script type="text/javascript">
        <!--
        function init_all() {
            init_Body();
            warn_print(1);
        }

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


</head>

<body>
<?php
if ($pbm_tec == FALSE) {
    switch ($_SESSION["niv_log"]) {
        case 4 :
        case 6 :
        case 10 :
            $titre = _("LISTE DE VOS TECHNICIENS");
            break;
        case 5 :
        case 9 :
            switch ($tl) {
                case 1 :
                    $titre = _("LISTE DES TECHNICIENS AGENCES");
                    break;
                case 2 :
                    $titre = _("LISTE DES TECHNICIENS DONNEURS D'ORDRES");
                    break;
                case 3 :
                    $titre = _("LISTE DES TECHNICIENS SOUS-TRAITANTS");
                    break;
                default :
                    break;
            }
            break;
        default :
            break;
    }
    entimplst($titre);

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

    $rech = cree_strrechlsttec(@$_SESSION["niv_log"]);

    switch ($_SESSION["niv_log"]) {
        case 4 :
            if (!stristr($rech, "OR "))
                $rech .= " WHERE tec_codeage = '" . @$_SESSION["code_age"] . "'";
            else
                $rech .= " AND tec_codeage = '" . @$_SESSION["code_age"] . "'";
            $rech .= crestr_triord($tec_titre_col, "tec_codeage", FALSE, $limit);
            break;
        case 6 :
            if (!stristr($rech, "OR "))
                $rech .= " WHERE tec_codedo = '" . @$_SESSION["code_do"] . "'";
            else
                $rech .= " AND tec_codedo = '" . @$_SESSION["code_do"] . "'";
            $rech .= crestr_triord($tec2_titre_col, "tec_codedo", FALSE, $limit);
            break;
        case 10 :
            if (!stristr($rech, "OR "))
                $rech .= " WHERE tec_codest = '" . @$_SESSION["code_st"] . "'";
            else
                $rech .= " AND tec_codest = '" . @$_SESSION["code_st"] . "'";
            $rech .= crestr_triord($tec3_titre_col, "tec_codest", FALSE, $limit);
            break;
        case 5 :
        case 9 :
            switch ($tl) {
                case 1 :
                    if (!stristr($rech, "OR "))
                        $rech .= " WHERE tec_codeage LIKE 'A%'";
                    else
                        $rech .= " AND tec_codeage LIKE 'A%'";
                    $rech .= crestr_triord($tec_titre_col, "tec_codeage", FALSE, $limit);
                    break;
                case 2 :
                    if (!stristr($rech, "OR "))
                        $rech .= " WHERE tec_codedo LIKE 'D%'";
                    else
                        $rech .= " AND tec_codedo LIKE 'D%'";
                    $rech .= crestr_triord($tec2_titre_col, "tec_codedo", FALSE, $limit);
                    break;
                case 3 :
                    if (!stristr($rech, "OR "))
                        $rech .= " WHERE tec_codest LIKE 'S%'";
                    else
                        $rech .= " AND tec_codest LIKE 'S%'";
                    $rech .= crestr_triord($tec3_titre_col, "tec_codest", FALSE, $limit);
                    break;
                default :
                    break;
            }
            break;
        default :
            break;
    }

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

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

    // création entête
    switch ($tl) {
        case 1 :
            titimplst($tec_titre_col);
            break;
        case 2 :
            titimplst($tec2_titre_col);
            break;
        case 3 :
            titimplst($tec3_titre_col);
            break;
        default :
            break;
    }

    foreach ($rows as $row) {
        $row = encode_str($row);
        echo "<tr>";
        echo "<td>";
        switch ($tl) {
            case 1 :
                echo $row["tec_codeage"];
                break;
            case 2 :
                echo $row["tec_codedo"];
                break;
            case 3 :
                echo $row["tec_codest"];
                break;
            default :
                echo "&nbsp;";
                break;
        }
        echo "</td>\n";
        echo "<td>" . $row["tec_code"] . "</td>\n";
        echo "<td>" . $row["tec_prenom"] . "</td>\n";
        echo "<td>" . $row["tec_nom"] . "</td>\n";
        echo "<td>" . $row["tec_telf"] . "</td>\n";
        echo "<td>" . $row["tec_telp"] . "</td>\n";
        echo "<td>" . $row["tec_email"] . "</td>\n";
        echo "</tr>\n";
    }
    echo "</table>\n";
    // *** Fin affichage de la table

    $db->disconnect();
} else {
    ?>
    <script type="text/javascript">
        <!--
        window.close();
        //-->
    </script>
<?PHP
}
?>
</body>
</html>