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

foreach ($rows as $row) {
    // Affichage résumé Relevé

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

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

    // Vérification si problème(s) non affecté(s)
    $rexist2 = "SELECT COUNT(*) FROM `" . TBRPBM . "`  WHERE rpbm_codecli = '" . $row["cli_code"] . "' AND rpbm_codeint IS NULL";
    $nbres2 = $db->get_var($rexist2);
    if ($nbres2 > 0)
        echo ' <img src="../img/pbmna.png" title ="'._("Problème(s) non affecté(s)").'" border="0" align="absmiddle">';

    // Icône si tâche rattachée
    $nb_tac_actives = nb_tac_actives(5, $row["rel_code"], FALSE);
    if ($nb_tac_actives > 0) {
        $url_taclst = "tac_lst.php?ord=DES&tri=Code&fi=7&search=" . $row["rel_code"];
        if ($nb_tac_actives > 1)
            $txt_tac = $nb_tac_actives . ' ' . _("tâches non terminées");
        else
            $txt_tac = $nb_tac_actives . ' ' . _("tâche non terminée");
        $txt_tac .= ' ('._("cliquez pour la liste des tâches rattachées à ce Relevé").' )';
        if (url_ok($url_taclst, FALSE) == TRUE)
            echo " <a href=\"" . $url_taclst . "\"><img src=\"../img/tacwarn.png\" title=\"" . $txt_tac . "\" border=\"0\" align=\"absmiddle\"></a>";
    }
    echo "</td>\n";
    echo "<td>" . datetolocal($row["rel_datecrea"]) . "</td>\n";
    echo "<td>" . datetolocal($row["rel_datemod"]) . "</td>\n";
    echo "<td>";
    echo $row["rel_codecli"];
    $rech2 = "SELECT cli_dep FROM `" . TBCLI . "` WHERE `cli_code`='" . $row["rel_codecli"] . "'";
    $row2 = $db->get_row($rech2, ARRAY_A);
    if ($row2) {
        if (url_ok('cli_maj.php?td=edit', FALSE) == TRUE)
            cre_falselnk_img('', 'cli_edit_'.$row["rel_id"], 'span', 'center', _("Edition client"), 'lnk', 'cli_maj.php?td=edit&cc=' . $row["rel_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 "<br />";
    echo "<span class=\"annot_std_it\">";
    echo $detailcli;
    echo "</span>";

    // Fin affichage détail client

    echo "</td>\n";
    if ($row["rel_codeage"] <> "")
        echo "<td>" . $row["rel_codeage"] . "</td>\n";
    else
        echo "<td>&nbsp;</td>\n";

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

    if (url_ok('rel_maj.php?td=edit', FALSE) == TRUE) {
        $lst_maj = TRUE;
        cre_falselnk_img('', 'rel_maj_'.$row["rel_id"], 'span', 'center', _("Edition"), 'lnk', 'rel_maj.php?td=edit&cc='.$row["rel_codecli"].'&cr=' . $row["rel_code"], '../img/edit.png');
    }

    $urlimp = "rel_pdf.php?cr=" . $row["rel_code"] . "&pbm=0";
    if (url_ok($urlimp, FALSE) == TRUE) {
        $lst_imp = TRUE;
        cre_falselnk_img('', 'rel_prn_'.$row["rel_id"], 'span', 'center', _("Impression"), 'lnk', $urlimp, '../img/print.png');

        $lst_impp = TRUE;
        $urlimp = "rel_pdf.php?cr=" . $row["rel_code"] . "&pbm=1";
        cre_falselnk_img('', 'rel_prnp_'.$row["rel_id"], 'span', 'center', _("Impression avec les problèmes"), 'lnk', $urlimp, '../img/printc.png');
    }

    if (url_ok('rel_maj.php?td=del', FALSE) == TRUE) {
        $lst_del = TRUE;
        cre_falselnk_img('', 'rel_del_'.$row["rel_id"], 'span', 'center', _("Suppression"), 'lnk', 'rel_maj.php?td=del&cc='.$row["rel_codecli"].'&cr=' . $row["rel_code"], '../img/del.png');
    }

    echo "</div>";
    echo "</td>\n";

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

    $i++;
}
?>
