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

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

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

    echo "<td>";
    echo $row["dos_code"];
    $rech2 = "SELECT * FROM `" . TBDOSC . "` WHERE `dosc_code`='" . $row["dos_codedosc"] . "'";
    $row2 = $db->get_row($rech2, ARRAY_A);
    if ($row2) {
        $txtdosc = _("Type de dossier") . " : " . $row2["dosc_desc"] . " (" . $row2["dosc_code"] . ")";
        echo " <img src=\"" . $row2["dosc_img"] . "\" title=\"" . $txtdosc . "\" height=\"16\" witdh=\"16\" border=\"0\" align=\"absmiddle\">";
    }

    // Détail du dossier
    if (trim($row["dos_res"]) <> "")
        echo ' <a href="#" class="pop"><img src="../img/help.png" alt="' . _("Résumé") . '" border="0" align="absmiddle"><span>' . $row["dos_res"] . '</span></a>';

    // Icône si dossier terminé
    if (datetolocal($row["dos_datefin"]) <> "")
        echo " <img src=\"../img/ok.png\" title =\"" . _("Dossier terminé") . "\" border=\"0\">";

    // Icône si tâche rattachée
    $nb_tac_actives = nb_tac_actives(4, $row["dos_code"], FALSE);
    if ($nb_tac_actives > 0) {
        $url_taclst = "tac_lst.php?ord=DES&tri=Code&fi=6&search=" . $row["dos_code"];
        $txt_tac = $nb_tac_actives . " " . _("tâche");
        if ($nb_tac_actives > 1) {
            $txt_tac = $nb_tac_actives . " " . _("tâches");
            $txt_tac .= " "._("non terminées");
        } else {
            $txt_tac = $nb_tac_actives . " " . _("tâche");
            $txt_tac .= " "._("non terminée");
        }
        $txt_tac .= " (" . _("cliquez pour la liste des tâches rattachées à ce dossier") . ")";
        echo " <a href=\"" . $url_taclst . "\"><img src=\"../img/tacwarn.png\" title=\"" . $txt_tac . "\" border=\"0\" align=\"absmiddle\"></a>";
    }
    echo "</td>\n";
    echo "<td>";
    echo "<div align=\"center\">";
    echo datetolocal($row["dos_datedde"]);
    echo "</div>";
    echo "</td>\n";
    echo "<td>";
    echo "<div align=\"center\">";
    echo datetolocal($row["dos_datefinp"]);
    // Icône si date de fin dépassée
    if (datetolocal($row["dos_datefin"]) == "") {
        if (echeance_depassee_date($datea, $row["dos_datefinp"]) == TRUE)
            echo " <img src=\"../img/warn.png\" title =\"" . _("Date dépassée") . "\" border=\"0\">";
    }
    echo "</div>";
    echo "</td>\n";

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

    echo "<td>";
    echo $row["dos_codecli"];
    $rech2 = "SELECT cli_dep FROM `" . TBCLI . "` WHERE `cli_code`='" . $row["dos_codecli"] . "'";
    $row2 = $db->get_row($rech2, ARRAY_A);
    if ($row2) {
        $row2 = encode_str($row2);
        cre_falselnk_img('', 'cli_edit_'.$row["dos_id"], 'span', 'center', _("Edition client"), 'lnk', 'cli_maj.php?td=edit&cc=' . $row["dos_codecli"] . '&dep=' . $row2["cli_dep"], '../img/edit.png');
    }

    // Affichage détail client
    $detailcli = "";
    if ($row["cli_ste"] <> "")
        $detailcli .= $row["cli_ste"] . ", ";
    $detailcli .= $row["cli_civilite"] . " " . $row["cli_nom"];
    echo "<div class=\"annot_petit_it\" style=\"margin-left:5px;\">";
    echo $detailcli;
    echo "</div>";

    // Fin affichage détail client

    echo "</td>\n";

    // Technicien / Agence traitants
    echo "<td>";
    if (($row["dos_codesuiv"] <> "") AND ($row["dos_codesuiv"] <> "-1")) {
        echo $row["dos_codesuiv"];
        if ((@$_SESSION["niv_log"] <> 4) AND (@$_SESSION["niv_log"] <> 3))
            echo "<br /> " . _("agence") . " : " . $row["dos_codeage"];
    } else
        echo '<span class="annot_petit_it">'._("Non affecté").'</span>';
    echo "</td>\n";

    // Affichage Icône Probabilité
    echo "<td>";
    echo "<div align=\"center\">";
    echo "<img src=\"../img/1pour" . $row["dos_proba"] . ".png\" title=\"" . $row["dos_proba"] . "%\" border=\"0\" align=\"absmiddle\">";
    echo "</div>";
    echo "</td>\n";

    // Affichage Icône Avancement
    echo "<td>";
    echo "<div align=\"center\">";
    echo "<img src=\"../img/2pour" . $row["dos_avance"] . ".png\" title=\"" . $row["dos_avance"] . "%\" border=\"0\" align=\"absmiddle\">";
    echo "</div>";
    echo "</td>\n";

    // Affichage Icône Statut
    echo "<td>";
    echo "<div align=\"center\">";

    $rech2 = "SELECT * FROM `" . TBDOSS . "` WHERE doss_code = '" . $row["dos_codedoss"] . "'";
    $row2 = $db->get_row($rech2, ARRAY_A);
    if ($row2) {
        $row2 = encode_str($row2);
        if ($row2["doss_img"] <> "") {
            $statint = $row2["doss_desc"] . " (" . $row["dos_codedoss"] . ")";
            echo "<img src=\"" . $row2["doss_img"] . "\" title=\"" . $statint . "\" border=\"0\" align=\"absmiddle\">";
        } else {
            echo "<span class=\"annot_std_it\">";
            echo $row["dos_codedoss"];
            echo "</span>";
        }
    }
    echo "</div>";
    echo "</td>\n";

    // CREATION lien dynamique sur icône (édition, suppression, etc...)
    if ($imprim == FALSE) {
        echo "<td>";
        echo "<div align=\"center\">";

        $voir = FALSE;

        if (datetolocal($row["dos_datefin"]) <> "")
            $voir = TRUE;

        if ($voir == FALSE) {
            $lst_maj = TRUE;
            cre_falselnk_img('', 'dos_edit_'.$row["dos_id"], 'span', 'center', _("Edition"), 'lnk', 'dos_maj.php?td=edit&cd=' . $row["dos_code"] . '&cc=' . $row["dos_codecli"] . '&ca=' . $row["dos_codeage"], '../img/edit.png');
        } else {
            $lst_voir = TRUE;
            cre_falselnk_img('', 'dos_view_'.$row["dos_id"], 'span', 'center', _("Visualisation"), 'lnk', 'dos_maj.php?td=view&cd=' . $row["dos_code"] . '&cc=' . $row["dos_codecli"] . '&ca=' . $row["dos_codeage"], '../img/eye.png');            echo "<a href=\"dos_maj.php?td=view&cd=" . $row["dos_code"] . "&cc=" . $row["dos_codecli"] . "\"><img src=\"../img/eye.png\" border=\"0\" align=\"absmiddle\" title=\"" . _("Voir") . "\"></a>";
        }

        $lst_imp = TRUE;
        $alea = time();
        $urlimp = "dos_pdf.php?token=".$alea."&cd=" . $row["dos_code"];
        cre_falselnk_img('', 'dos_prn_'.$row["dos_id"], 'span', 'center', _("Impression"), 'lnkpop', $urlimp, '../img/print.png');
        echo " ";

        if (datetolocal($row["dos_datefin"]) == "") {
            $lst_del = TRUE;
            cre_falselnk_img('', 'dos_del_'.$row["dos_id"], 'span', 'center', _("Suppression"), 'lnk', 'dos_maj.php?td=del&cd=' . $row["dos_code"] . '&cc=' . $row["dos_codecli"] . '&ca=' . $row["dos_codeage"], '../img/del.png');
        } else {
            if (@$_SESSION["niv_log"] == 9) {
                $lst_reopen = TRUE;
                cre_falselnk_img('', 'dos_reopen_'.$row["ope_id"], 'span', 'center', _("Réouverture"), 'lnkwpop', 'dos_reopen.php?cd=' . $row["dos_code"] , '../img/reopen.png',900,400);
            }
        }
        echo "</div>";
        echo "</td>\n";
    }
    echo "</tr>\n";
    // Fin affichage résumé Dossier

    $i++;
}
