<?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_cocl.inc.php");
include_once("../inc/fic_droits.inc.php");
include_once("../inc/fic_int.inc.php");
include_once("../inc/fic_ot.inc.php");
include_once("../inc/fic_prm.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_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_ot = FALSE;
$pbm_cli = FALSE;

$msg1_err_type = "Aucun sous-traitant pour cette spécialité dans le département du client";

$url_query = $_SERVER['QUERY_STRING'];
$tx = $_GET['tx']; // Source de l'appel m:depuis le menu, i:depuis l'intervention
$td = $_GET['td']; // Récupération type demande
$ca = $_GET['ca']; // Récupération code Agence gestionnaire du compte client
$cc = $_GET['cc']; // Récupération code Client
$ci = $_GET['ci']; // Récupération code Intervention
$si = $_GET['si']; // Récupération id du site
$tr = $_GET['tr']; // Récupération code technicien responsable
$co = $_GET['co']; // Récupération code contrat
$tl = 1;
if (isset($_GET["tl"]))
    $tl = intval($_GET['tl']); // Récupération type liste
if (($tl <> 1) AND ($tl <> 2))
    $tl = 1;
if ((@$_SESSION["niv_log"] == 10) OR (@$_SESSION["niv_log"] == 11))
    $tl = 1;

if (($tx <> "m") AND ($tx <> "i"))
    $pbm_ot = TRUE;

if ((@$_SESSION["niv_log"] <> 3) AND (@$_SESSION["niv_log"] <> 4) AND (@$_SESSION["niv_log"] <> 5) AND (@$_SESSION["niv_log"] <> 9) AND (@$_SESSION["niv_log"] <> 10) AND (@$_SESSION["niv_log"] <> 11))
    $pbm_ot = TRUE;

if ($pbm_ot == FALSE) {
    if ($ci <> "") {
        // Récupération des informations Intervention
        $row = lit_enr_int($ci);
        if (is_array($row)) {
            $row = encode_str($row);
            extract($row);

            if ($int_codecli == $cc) {
                $row2 = lit_enr_cli($int_codecli, TRUE);
                if (is_array($row2)) {
                    $row2 = encode_str($row2);
                    extract($row2);
                    if ($si > 0) {
                        $row3 = lit_enr_scli_id($si, TRUE);
                        if (is_array($row3)) {
                            $row3 = encode_str($row3);
                            extract($row3);
                            if ($scli_codecli <> $cc)
                                $pbm_cli = TRUE;
                        } else
                            $pbm_cli = TRUE;
                    } else {
                        $scli_codepays = $cli_codepays;
                        $scli_dep = $cli_dep;
                    }
                } else
                    $pbm_cli = TRUE;
            } else
                $pbm_cli = TRUE;
        } else
            $pbm_ot = TRUE;
    } else {
        if ($tx == "i")
            $pbm_ot = TRUE;
    }
}

if (($pbm_ot == FALSE) AND ($pbm_cli == FALSE)) {
    if ($tr <> "") {
        $row = lit_enr_tec($tr, TRUE);
        if (is_array($row)) {
            $row = encode_str($row);
            extract($row);
            switch (@$_SESSION["niv_log"]) {
                case 3 :
                case 11 :
                    if (@$_SESSION["code_log"] <> $tec_code)
                        $pbm_ot = TRUE;
                    break;
                case 4 :
                    if (@$_SESSION["code_age"] <> $tec_codeage) $pbm_ot = TRUE;
                    break;
                case 10 :
                    if (@$_SESSION["code_st"] <> $tec_codest) $pbm_ot = TRUE;
                    break;
                default :
                    break;
            }
        } else
            $pbm_ot = TRUE;
    } else {
        if ($tx == "i")
            $pbm_ot = TRUE;
    }
}

if (($pbm_ot == FALSE) AND ($pbm_cli == FALSE)) {
    if ($ca <> "") {
        $row = lit_enr_age($ca, TRUE);
        if (is_array($row)) {
            $row = encode_str($row);
            extract($row);
        } else
            $pbm_ot = TRUE;
    } else {
        if ($tx == "i")
            $pbm_ot = TRUE;
    }
}

$fi = "";
if (isset($_GET['fi']) && (trim($_GET['fi']) <> ""))
    $fi = intval($_GET['fi']);
?>
<!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 Ordres Sous-traitants"); ?></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
$titre = "BONS DE TRAVAIL";
switch (@$_SESSION["niv_log"]) {
    case 3 :
    case 4 :
        if ($tl == 2)
            $titre .= " "._("A REGULARISER");
        else
            $titre .= " "._("REGULARISES");
        entimplst($titre);
        echo '<p align="center"><span class="annot_gras_it">' . _("Dont vous assurez le suivi de l'intervention") . '</span></p>';
        break;
    case 5 :
    case 9 :
        if ($tl == 2)
            $titre .= " " . _("A REGULARISER");
        else
            $titre .= " " . _("REGULARISES");
        entimplst($titre);
        break;
    case 10 :
    case 11 :
        entimplst(_("VOS") . ' ' . $titre);
        break;
}

if (($pbm_ot == FALSE) AND ($pbm_cli == FALSE)) {
    if ($tl == 2) {
        $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);

        switch (@$_SESSION["niv_log"]) {
            case 10 :
            case 11 :
                $rech = cree_strrechlstotst();
                if (!stristr($rech, "WHERE "))
                    $rech .= " WHERE " . TBOT . ".ot_codest='" . @$_SESSION["code_st"] . "'";
                else
                    $rech .= " AND " . TBOT . ".ot_codest='" . @$_SESSION["code_st"] . "'";
                break;
            case 3 :
                $rech = cree_strrechlstot_ar();
                if (!stristr($rech, "WHERE "))
                    $rech .= " WHERE " . TBCLI . ".cli_prop='" . @$_SESSION["code_age"] . "'";
                else
                    $rech .= " AND " . TBCLI . ".cli_prop='" . @$_SESSION["code_age"] . "'";
                if (!stristr($rech, "WHERE "))
                    $rech .= " WHERE " . TBOT . ".ot_codeint='--AR--'";
                else
                    $rech .= " AND " . TBOT . ".ot_codeint='--AR--'";
                break;
            case 4 :
                $rech = cree_strrechlstot_ar();
                if (!stristr($rech, "WHERE "))
                    $rech .= " WHERE " . TBCLI . ".cli_prop='" . @$_SESSION["code_age"] . "'";
                else
                    $rech .= " AND " . TBCLI . ".cli_prop='" . @$_SESSION["code_age"] . "'";
                if (!stristr($rech, "WHERE "))
                    $rech .= " WHERE " . TBOT . ".ot_codeint='--AR--'";
                else
                    $rech .= " AND " . TBOT . ".ot_codeint='--AR--'";
                break;
            default :
                $rech = cree_strrechlstot_ar();
                if (!stristr($rech, "WHERE "))
                    $rech .= " WHERE " . TBOT . ".ot_codeint='--AR--'";
                else
                    $rech .= " AND " . TBOT . ".ot_codeint='--AR--'";
                break;
        }

        if ($tx == "i") {
            if (!stristr($rech, "WHERE ")) {
                $rech .= " WHERE (" . TBOT . ".ot_codecli='" . $cc . "'";
                $rech .= " AND " . TBOT . ".ot_idsite='" . $si . "')";
            } else {
                $rech .= " AND " . TBOT . ".ot_codecli='" . $cc . "'";
                $rech .= " AND " . TBOT . ".ot_idsite='" . $si . "'";
            }
        }

        switch ($fi) {
            case "1" :
                if (!stristr($rech, "WHERE "))
                    $rech .= " WHERE ot_datefin='0000-00-00'";
                else
                    $rech .= " AND ot_datefin='0000-00-00'";
                break;
            case "2" :
                if (!stristr($rech, "WHERE "))
                    $rech .= " WHERE ot_datefin<>'0000-00-00'";
                else
                    $rech .= " AND ot_datefin<>'0000-00-00'";
                break;
            case "3" :
                if (!stristr($rech, "WHERE "))
                    $rech .= " WHERE ot_codeint='--AR--'";
                else
                    $rech .= " AND ot_codeint='--AR--'";
                break;
            default :
                break;
        }

        $rech .= crestr_triord($ot_titre_col, "ot_code", FALSE, $limit);

        $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
        if ((@$_SESSION["niv_log"] <> 11) AND (@$_SESSION["niv_log"] <> 10))
            titlst($ot_titre_col);
        else
            titlst($ot2_titre_col);

        $i = 0;

        foreach ($rows as $row) {
            $row = encode_str($row);
            // Affichage résumé ordre

            echo "<tr>";

            echo "<td>";
            echo $row["ot_code"];

            $detfic = ">>" . _("Matériel") . " :<br />" . $row["ot_mat"] . "<br /><br />>>" . _("Travail à effectuer") . " :<br />" . $row["ot_pbm"];
            if ($detfic <> "")
                echo ' <a href="#" class="pop"><img src="../img/help.png" alt="'._("Détail").'" border="0" align="absmiddle"><span>' . formatetxtbr($detfic) . '</span></a>';

            // Affichage détail intervention rattachée
            if ($tx == "m") {
                // icône si tâche rattachée
                $nb_tac_actives = nb_tac_actives(6, $row["ot_code"], FALSE);
                if ($nb_tac_actives > 0) {
                    $url_taclst = "tac_lst.php?ord=DES&tri=Code&fi=8&search=" . $row["ot_code"];
                    $txt_tac = $nb_tac_actives . " " . _("tâche");
                    if ($nb_tac_actives > 1)
                        $txt_tac .= "s";
                    if ($nb_tac_actives > 1)
                        $txt_tac .= " "._("non terminées");
                    else
                        $txt_tac .= " "._("non terminée");
                    $txt_tac .= " (cliquez pour la liste des tâches rattachées à ce bon de travail)";
                    echo " <a href=\"" . $url_taclst . "\"><img src=\"../img/tacwarn.png\" title=\"" . $txt_tac . "\" border=\"0\" align=\"absmiddle\"></a>";
                }
                if ((@$_SESSION["niv_log"] <> 11) AND (@$_SESSION["niv_log"] <> 10)) {
                    echo "<div class=\"annot_petit_it\" align=\"right\">";
                    echo _("Client") . ' ' . $row["ot_codecli"];
                    echo " <a href=\"cli_maj.php?td=edit&cc=" . $row["ot_codecli"] . "\"><img src=\"../img/edit.png\" width=\"14\" height=\"14\" border=\"0\" align=\"absmiddle\" title=\"" . _("Editer client") . "\"></a>";
                    echo "</div>";
                }

            }
            echo "</td>\n";

            echo "<td align=\"center\">";
            echo datetolocal($row["ot_datedde"]);
            echo "</td>\n";
            echo "<td align=\"center\">";
            echo datetolocal($row["ot_daterdv"]);
            if (datetolocal($row["ot_daterdv"]) <> "") {
                echo "<div class=\"annot_petit_it\">";
                echo substr($row["ot_hrdv"], 0, 5);
                echo "</div>";
            }
            echo "</td>\n";

            // Affichage icône Lieu
            echo "<td>";
            $lieu = $row["ot_codelieu"];
            $rech2 = "SELECT * FROM `" . TBLIEU . "` WHERE lieu_code = '$lieu'";

            $row2 = $db->get_row($rech2, ARRAY_A);

            if ($row2) {
                $row2 = encode_str($row2);
                extract($row2);
                if ($lieu_img <> "") {
                    $lieuint = $lieu_desc . " (" . $lieu . ")";
                    echo "<div style=\"float:left;width:40px;\">";
                    echo "<img src=\"" . $lieu_img . "\" title=\"" . $lieuint . "\" border=\"0\" align=\"absmiddle\">";
                    echo "</div>";
                } else {
                    echo "<span class=\"annot_std_it\" style=\"float:left;\">";
                    echo $lieu;
                    echo "</span>";
                }
            }

            // Affichage site client
            $sitecli = "";
            switch (trim($row["ot_idsite"])) {
                case "0" :
                    $row2 = lit_enr_cli($row["ot_codecli"], FALSE);
                    if (is_array($row2)) {
                        $row2 = encode_str($row2);
                        extract($row2);
                        $sitecli .= "<strong>";
                        if ($cli_ste <> "")
                            $sitecli .= $cli_ste . "<br />";
                        else
                            $sitecli .= $cli_civilite . " " . $cli_prenom . " " . $cli_nom . "<br />";
                        $sitecli .= "</strong>";
                        $sitecli .= $cli_adr1 . "<br />";
                        if ($cli_adr2 <> "")
                            $sitecli .= $cli_adr2 . "<br />";
                        $sitecli .= Retournecp_Id($cli_ville, FALSE) . " " . Retourneville_Id($cli_ville, FALSE) . "<br />";
                    }
                    break;
                default :
                    $rech2 = "SELECT * FROM `" . TBSCLI . "` WHERE `scli_id` = '" . trim($row["ot_idsite"]) . "'";
                    $row2 = $db->get_row($rech2);
                    if ($row2) {
                        extract($row2);
                        $sitecli .= "<strong>";
                        $sitecli .= $scli_ste . "<br />";
                        $sitecli .= "</strong>";
                        $sitecli .= $scli_adr1 . "<br />";
                        if ($scli_adr2 <> "")
                            $sitecli .= $scli_adr2 . "<br />";
                        $sitecli .= Retournecp_Id($scli_ville, FALSE) . " " . Retourneville_Id($scli_ville, FALSE) . "<br />";
                    }
            }

            if ($sitecli <> "") {
                echo "<div class=\"annot_petit_it\" style=\"float:left;\">";
                echo $sitecli;
                echo "</div>";
            }

            echo "</td>\n";

            // Affichage détail urgence
            echo '<td ';
            $couleur = give_coul_urg($row["ot_urg"], FALSE);
            if ($couleur <> "XX")
                echo ' style="background:' . $couleur . '"';
            echo ' align="center">';
            echo give_nom_urg($row["ot_urg"], FALSE);;
            echo "</td>\n";
            // Fin affichage détail urgence

            if ((@$_SESSION["niv_log"] <> 11) AND (@$_SESSION["niv_log"] <> 10)) {
                echo "<td align=\"center\">";
                echo $row["ot_codest"];
                if ($tx == "m") {
                    $rech2 = "SELECT st_dep FROM `" . TBST . "` WHERE `st_code`='" . $row["ot_codest"] . "'";
                    $row2 = $db->get_row($rech2, ARRAY_A);
                    if ($row2)
                        echo " <a href=\"st_maj.php?td=edit&code=" . $row["ot_codest"] . "&dep=" . $row2["st_dep"] . "\"><img src=\"../img/edit.png\" width=\"14\" height=\"14\" border=\"0\" align=\"absmiddle\" title=\"Editer sous-traitant\"></a>";
                }

                // Affichage détail sous-traitant
                $detailst = $row["st_nom"] . ", ";
                $detailst .= $row["st_resp_civilite"] . " " . $row["st_resp_nom"];
                echo "<div class=\"annot_petit_it\" style=\"margin-left:5px;\">";
                echo $detailst;
                echo "</div>";
                // Fin affichage détail sous-trainat
                echo "</td>\n";
            }

            // Affichage technicien traitant
            echo "<td align=\"center\">";
            if (($row["ot_codetec"] <> "") AND ($row["ot_codetec"] <> "-1"))
                echo $row["ot_codetec"];
            else
                echo "&nbsp;";
            echo "</td>\n";

            // Affichage icône Statut
            echo "<td align=\"center\">";
            echo str_div_ico_statut($row["ot_codestatut"], '', FALSE);
            if ($statut == "CLOT") {
                echo "<div class=\"annot_upetit_it\">";
                echo datetolocal($row["ot_datefin"]);
                echo "</div>";
            }
            echo "</td>\n";

            echo "</tr>\n";
            // Fin affichage résumé ordre

            $i++;
        }
        echo "</table>\n";
        // *** Fin affichage de la table

        $db->disconnect();
    }

    if ($tl == 1) {
        $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);

        switch (@$_SESSION["niv_log"]) {
            case 10 :
            case 11 :
                $rech = cree_strrechlstotst();
                if (!stristr($rech, "WHERE "))
                    $rech .= " WHERE " . TBOT . ".ot_codest='" . @$_SESSION["code_st"] . "'";
                else
                    $rech .= " AND " . TBOT . ".ot_codest='" . @$_SESSION["code_st"] . "'";
                break;
            case 3 :
                $rech = cree_strrechlstot();
                if (!stristr($rech, "WHERE ")) {
                    $rech .= " WHERE (" . TBINT . ".int_codeage='" . @$_SESSION["code_age"] . "'";
                    $rech .= " OR " . TBINT . ".int_codeages='" . @$_SESSION["code_age"] . "')";
                    $rech .= " AND " . TBINT . ".int_codetec='" . @$_SESSION["code_log"] . "'";
                } else {
                    $rech .= " AND (" . TBINT . ".int_codeage='" . @$_SESSION["code_age"] . "'";
                    $rech .= " OR " . TBINT . ".int_codeages='" . @$_SESSION["code_age"] . "')";
                    $rech .= " AND " . TBINT . ".int_codetec='" . @$_SESSION["code_log"] . "'";
                }
                break;
            case 4 :
                $rech = cree_strrechlstot();
                if (!stristr($rech, "WHERE ")) {
                    $rech .= " WHERE (" . TBINT . ".int_codeage='" . @$_SESSION["code_age"] . "'";
                    $rech .= " OR " . TBINT . ".int_codeages='" . @$_SESSION["code_age"] . "')";
                } else {
                    $rech .= " AND (" . TBINT . ".int_codeage='" . @$_SESSION["code_age"] . "'";
                    $rech .= " OR " . TBINT . ".int_codeages='" . @$_SESSION["code_age"] . "')";
                }
                if (!stristr($rech, "WHERE "))
                    $rech .= " WHERE " . TBOT . ".ot_codeint<>'--AR--'";
                else
                    $rech .= " AND " . TBOT . ".ot_codeint<>'--AR--'";
                break;
            default :
                $rech = cree_strrechlstot();
                if (!stristr($rech, "WHERE "))
                    $rech .= " WHERE " . TBOT . ".ot_codeint<>'--AR--'";
                else
                    $rech .= " AND " . TBOT . ".ot_codeint<>'--AR--'";
                break;
        }

        if ($ci <> "") {
            if (!stristr($rech, "WHERE "))
                $rech .= " WHERE " . TBOT . ".ot_codeint='" . $ci . "'";
            else
                $rech .= " AND " . TBOT . ".ot_codeint='" . $ci . "'";
        }

        switch ($fi) {
            case "1" :
                if (!stristr($rech, "WHERE "))
                    $rech .= " WHERE ot_datefin='0000-00-00'";
                else
                    $rech .= " AND ot_datefin='0000-00-00'";
                break;
            case "2" :
                if (!stristr($rech, "WHERE "))
                    $rech .= " WHERE ot_datefin<>'0000-00-00'";
                else
                    $rech .= " AND ot_datefin<>'0000-00-00'";
                break;
            case "3" :
                if (!stristr($rech, "WHERE "))
                    $rech .= " WHERE ot_codeint='--AR--'";
                else
                    $rech .= " AND ot_codeint='--AR--'";
                break;
            default :
                break;
        }

        $rech .= crestr_triord($ot_titre_col, "ot_code", FALSE, $limit);

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

        // *** Pagination de pied
        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
        if ((@$_SESSION["niv_log"] <> 11) AND (@$_SESSION["niv_log"] <> 10))
            titlst($ot_titre_col);
        else
            titlst($ot2_titre_col);

        $i = 0;


        foreach ($rows as $row) {
            $row = encode_str($row);
            // Affichage résumé ordre

            // création de l'entête de ligne (TR)
            creetrlst($i);

            echo "<td>";
            echo $row["ot_code"];

            // Affichage détail intervention rattachée
            if ($tx == "m") {
                if ((@$_SESSION["niv_log"] <> 11) AND (@$_SESSION["niv_log"] <> 10)) {
                    echo "<div class=\"annot_petit_it\" align=\"right\">";
                    $txtint = "";
                    if ($row["int_codedo"] <> "")
                        $txtint = _("Ordre intervention");
                    else
                        $txtint = _("Intervention");
                    echo $txtint . " " . $row["ot_codeint"];
                    if (datetolocal($row["int_datefin"]) <> "")
                        echo " <img src=\"../img/ok.png\" border=\"0\" align=\"absmiddle\" title=\"" . _("Terminé") . "\">";
                    else {
                        if (datetolocal($row["int_dateprev"]) <> "")
                            echo " <img src=\"../img/phone.png\" border=\"0\" align=\"absmiddle\" title=\"" . _("Client prévenu") . "\">";
                    }
                    echo "</div>";
                    if ($row["int_codedo"] <> "") {
                        echo "<div align=\"right\" class=\"annot_upetit_it\">";
                        echo _("Ordre de") . " " . $row["int_codedo"];
                        echo "</div>";
                    }
                    if ($row["int_codeman"] <> "") {
                        echo "<div align=\"right\" class=\"annot_upetit_it\">";
                        echo _("Saisie manuelle") . " : " . $row["int_codeman"];
                        echo "</div>";
                    }
                    if ($row["int_codeext"] <> "") {
                        echo "<div align=\"right\" class=\"annot_upetit_it\">";
                        echo _("Dossier") . " : " . $row["int_codeext"];
                        echo "</div>";
                    }
                    echo "<div class=\"annot_petit_it\" align=\"right\">";
                    echo _("Client") . " " . $row["int_codecli"];
                    echo "</div>";
                }

            }
            echo "</td>\n";

            echo "<td align=\"center\">";
            echo datetolocal($row["ot_datedde"]);
            echo "</td>\n";
            echo "<td align=\"center\">";
            echo datetolocal($row["ot_daterdv"]);
            if (datetolocal($row["ot_daterdv"]) <> "") {
                echo "<div class=\"annot_petit_it\">";
                echo substr($row["ot_hrdv"], 0, 5);
                echo "</div>";
            }
            echo "</td>\n";

            // Affichage icône Lieu
            echo "<td>";
            $lieu = $row["ot_codelieu"];
            $rech2 = "SELECT * FROM `" . TBLIEU . "` WHERE lieu_code = '$lieu'";

            $row2 = $db->get_row($rech2, ARRAY_A);

            if ($row2) {
                $row2 = encode_str($row2);
                extract($row2);
                if ($lieu_img <> "") {
                    $lieuint = $lieu_desc . " (" . $lieu . ")";
                    echo "<div style=\"float:left;width:40px;\">";
                    echo "<img src=\"" . $lieu_img . "\" title=\"" . $lieuint . "\" border=\"0\" align=\"absmiddle\">";
                    echo "</div>";
                } else {
                    echo "<span class=\"annot_std_it\" style=\"float:left;\">";
                    echo $lieu;
                    echo "</span>";
                }
            }

            // Affichage site client
            $sitecli = "";
            switch (trim($row["ot_idsite"])) {
                case "0" :
                    $row2 = lit_enr_cli($row["ot_codecli"], FALSE);
                    if (is_array($row2)) {
                        $row2 = encode_str($row2);
                        extract($row2);
                        $sitecli .= "<strong>";
                        if ($cli_ste <> "")
                            $sitecli .= $cli_ste . "<br />";
                        else
                            $sitecli .= $cli_civilite . " " . $cli_prenom . " " . $cli_nom . "<br />";
                        $sitecli .= "</strong>";
                        $sitecli .= $cli_adr1 . "<br />";
                        if ($cli_adr2 <> "")
                            $sitecli .= $cli_adr2 . "<br />";
                        $sitecli .= Retournecp_Id($cli_ville, FALSE) . " " . Retourneville_Id($cli_ville, FALSE) . "<br />";
                    }
                    break;
                default :
                    $rech2 = "SELECT * FROM `" . TBSCLI . "` WHERE `scli_id` = '" . trim($row["ot_idsite"]) . "'";
                    $row2 = $db->get_row($rech2, ARRAY_A);
                    if ($row2) {
                        extract($row2);
                        $sitecli .= "<strong>";
                        $sitecli .= $scli_ste . "<br />";
                        $sitecli .= "</strong>";
                        $sitecli .= $scli_adr1 . "<br />";
                        if ($scli_adr2 <> "")
                            $sitecli .= $scli_adr2 . "<br />";
                        $sitecli .= Retournecp_Id($scli_ville, FALSE) . " " . Retourneville_Id($scli_ville, FALSE) . "<br />";
                    }
            }

            if ($sitecli <> "") {
                echo "<div class=\"annot_petit_it\" style=\"float:left;\">";
                echo $sitecli;
                echo "</div>";
            }

            echo "</td>\n";

            // Affichage détail urgence
            echo '<td ';
            $couleur = give_coul_urg($row["ot_urg"], FALSE);
            if ($couleur <> "XX")
                echo ' style="background:' . $couleur . '"';
            echo ' align="center">';
            echo give_nom_urg($row["ot_urg"], FALSE);;
            echo "</td>\n";
            // Fin affichage détail urgence

            if ((@$_SESSION["niv_log"] <> 11) AND (@$_SESSION["niv_log"] <> 10)) {
                echo "<td align=\"center\">";
                echo $row["ot_codest"];

                // Affichage détail sous-traitant
                $detailst = $row["st_nom"] . ", ";
                $detailst .= $row["st_resp_civilite"] . " " . $row["st_resp_nom"];
                echo "<div class=\"annot_petit_it\" style=\"margin-left:5px;\">";
                echo $detailst;
                echo "</div>";
                // Fin affichage détail sous-trainat
                echo "</td>\n";
            }

            // Affichage technicien traitant
            echo "<td align=\"center\">";
            if (($row["ot_codetec"] <> "") AND ($row["ot_codetec"] <> "-1"))
                echo $row["ot_codetec"];
            else
                echo "&nbsp;";
            echo "</td>\n";

            // Affichage icône Statut
            echo "<td align=\"center\">";
            echo str_div_ico_statut($row["ot_codestatut"], '', FALSE);
            if ($statut == "CLOT") {
                echo "<div class=\"annot_upetit_it\">";
                echo datetolocal($row["ot_datefin"]);
                echo "</div>";
            }
            echo "</td>\n";

            echo "</tr>\n";
            // Fin affichage résumé ordre

            $i++;
        }
        echo "</table>\n";
        // *** Fin affichage de la table

        $db->disconnect();

    }
} else
    close_fen_auto(_("Problème de paramètres"), 'fscomp');
echo '</body>';
echo '</html>';
?>
