<?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é tâche

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

    echo "<td>";
    echo $row["tac_code"];
    $rech2 = "SELECT * FROM `" . TBTACC . "` WHERE `tacc_code`='" . $row["tac_codetacc"] . "'";
    $row2 = $db->get_row($rech2, ARRAY_A);
    if ($row2) {
        $row2 = encode_str($row2);
        $txttacc = _("Type de tâche") . " : " . $row2["tacc_desc"] . " (" . $row2["tacc_code"] . ")";
        echo " <img src=\"" . $row2["tacc_img"] . "\" title=\"" . $txttacc . "\" height=\"16\" witdh=\"16\" border=\"0\" align=\"absmiddle\">";
    } else
        echo "&nbsp;";

    // Icône si tâche terminée
    if (datetolocal($row["tac_datefin"]) <> "")
        echo ' <img src="../img/ok.png" title ="' . _("Tâche terminée") . '" border="0">';
    // Détail de la tâche
    if (trim($row["tac_afaire"]) <> "") {
        echo '<div style="margin-left:10px;" class="annot_petit_it">';
        echo '-- ' . trim($row["tac_titre"]) . ' --';
        echo ' <a href="#" class="pop"><img src="../img/help.png" alt="' . _("Résumé") . '" border="0" align="absmiddle"><span>' . formatetxtbr(trim($row["tac_afaire"])) . '</span></a>';
        echo '</div>';
    }

    // Auteur
    echo "<div align=\"right\" class=\"annot_petit_it\">";
    echo "Auteur : ";
    if (trim($row["tac_codecrea"]) <> @$_SESSION["code_log"])
        echo $row["tac_codecrea"];
    else
        echo _("vous-même");
    echo "</div>";

    // Si rattachée
    if (trim($row["tac_coderat"]) <> "") {
        echo "<div align=\"right\" class=\"annot_petit_it\">";
        echo "Rattachée à ";
        switch ($row["tac_typrat"]) {
            case 1 :
                echo _("int.") . ' ';
                break;
            case 2 :
                echo _("cont. maint.") . ' ';
                break;
            case 3 :
                echo _("cont. loc.") . ' ';
                break;
            case 4 :
                echo _("dossier") . ' ';
                break;
            case 5 :
                echo _("Relevé") . ' ';
                break;
            case 6 :
                echo _("bon trav.") . ' ';
                break;
        }
        echo $row["tac_coderat"];
        echo "</div>";
    }
    echo "</td>\n";
    echo "<td align=\"center\">";;
    echo datetolocal($row["tac_datecrea"]);
    echo "</td>\n";
    echo "<td align=\"center\">";;
    echo datetolocal($row["tac_datefinp"]);
    // Icône si date de fin dépassée
    if (datetolocal($row["tac_datefin"]) == "") {
        if (echeance_depassee_date($datea, $row["tac_datefinp"]) == TRUE)
            echo " <img src=\"../img/warn.png\" title =\"" . _("Date dépassée") . "\" border=\"0\">";
    }
    echo "</td>\n";

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


    // Affichage destinataire
    echo "<td align=\"center\">";;
    if ($row["tac_codedest"] == "CGE")
        echo _("Centre de gestion");
    else
        echo $row["tac_codedest"];
    echo "</td>\n";
    // Fin affichage destinataire

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

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

    $voir = FALSE;

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

    if ($voir == FALSE) {
        if (url_ok('tac_maj.php?td=edit', FALSE) == TRUE) {
            $lst_maj = TRUE;
            cre_falselnk_img('', 'tac_edit_'.$row["tac_id"], 'span', 'center', _("Edition"), 'lnk', 'tac_maj.php?td=edit&ct=' . $row["tac_code"], '../img/edit.png');
        }
    } else {
        if (url_ok('tac_maj.php?td=view', FALSE) == TRUE) {
            $lst_voir = TRUE;
            cre_falselnk_img('', 'tac_view_'.$row["tac_id"], 'span', 'center', _("Visulisation"), 'lnk', 'tac_maj.php?td=view&ct=' . $row["tac_code"], '../img/view.png');
        }
    }

    if (datetolocal($row["tac_datefin"]) == "") {
        if (url_ok('tac_maj.php?td=del', FALSE) == TRUE) {
            if (($row["tac_codecrea"] == @$_SESSION["code_log"]) OR (@$_SESSION["niv_log"] == 9)) {
                $lst_del = TRUE;
                cre_falselnk_img('', 'tac_del_'.$row["tac_id"], 'span', 'center', _("Suppression"), 'lnk', 'tac_maj.php?td=del&ct=' . $row["tac_code"], '../img/del.png');
            }
        }
    } else {
        if (@$_SESSION["niv_log"] == 9) {
            $lst_reopen = TRUE;
            cre_falselnk_img('', 'tac_reopen_'.$row["ope_id"], 'span', 'center', _("Réouverture"), 'lnkwpop', 'tac_reopen.php?ct=' . $row["tac_code"] , '../img/reopen.png',900,400);
        }
    }
    echo "</td>\n";

    echo "</tr>\n";
    // Fin affichage résumé Tâche

    $i++;
}
