<?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) {

    $row = encode_str($row);

    // Affichage résumé Relevé

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

    echo "<td>";
    echo $row["rpat_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["rpat_code"],FALSE);
   if ($nb_tac_actives>0)
   {
       $url_taclst="tac_lst.php?ord=DES&tri=Code&fi=7&search=".$row["rpat_code"];
       $txt_tac=$nb_tac_actives." "._("tâche");
       if ($nb_tac_actives>1)
           $txt_tac.="s";
       $txt_tac.=" non terminée";
       if ($nb_tac_actives>1)
           $txt_tac.="s";
       $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["rpat_datecrea"]) . "</td>\n";
    echo "<td>" . datetolocal($row["rpat_datemod"]) . "</td>\n";
    echo "<td>";
    echo $row["rpat_codecli"];
    $rech2 = "SELECT cli_dep FROM `" . TBCLI . "` WHERE `cli_code`='" . $row["rpat_codecli"] . "'";
    $row2 = $db->get_row($rech2, ARRAY_A);
    if ($row2) {
        $row2 = encode_str($row2);
        if (url_ok('cli_maj.php?td=edit', FALSE) == TRUE)
            cre_falselnk_img('', 'cli_edit_'.$row["rpat_id"], 'span', 'center', _("Edition client"), 'lnk', 'cli_maj.php?td=edit&cc=' . $row["rpat_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["rpat_codeage"] <> "")
        echo "<td>" . $row["rpat_codeage"] . "</td>\n";
    else
        echo "<td>&nbsp;</td>\n";

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

    if (url_ok('rpat_maj.php?td=edit', FALSE) == TRUE) {
        $lst_maj = TRUE;
        cre_falselnk_img('', 'rpat_edit_'.$row["rpat_id"], 'span', 'center', _("Edition"), 'lnk', 'rpat_maj.php?td=edit&cr=' . $row["rpat_code"], '../img/edit.png');
    }

    $urlimp = "rpat_pdf.php?cr=" . $row["rpat_code"] . "&pbm=0";
    if (url_ok($urlimp, FALSE) == TRUE) {
        $lst_imp = TRUE;
        cre_falselnk_img('', 'rpat_prn_'.$row["rpat_id"], 'span', 'center', _("Impression"), 'lnkpop', $urlimp, '../img/print.png');

        $lst_impp = TRUE;
        $urlimp = "rpat_pdf.php?cr=" . $row["rpat_code"] . "&pbm=1";
        cre_falselnk_img('', 'rpat_prnp_'.$row["rpat_id"], 'span', 'center', _("Impression avec problèmes"), 'lnkpop', $urlimp, '../img/printc.png');
    }

    if (url_ok('rpat_maj.php?td=del', FALSE) == TRUE) {
        $lst_del = TRUE;
        cre_falselnk_img('', 'rpat_del_'.$row["rpat_id"], 'span', 'center', _("Suppression"), 'lnk', 'rpat_maj.php?td=del&cr=' . $row["rpat_code"], '../img/del.png');
    }

    echo "</td>\n";

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

    $i++;
}
?>
