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

$aff_sfact = FALSE;
switch ($_SESSION["niv_log"]) {
    // Agences
    case 4 :
        $row = lit_enr_age($_SESSION["code_age"], FALSE);
        if (is_array($row)) {
            extract($row);
            if (intval($age_fact) == 1)
                $aff_sfact = TRUE;
        }
        break;

    case 5 :
    case 9 :
        $aff_sfact = TRUE;
        break;
    default :
        break;
}

$num_col = 1;

foreach ($rows as $row) {
    $row = encode_str($row);
    $aff_ligne = TRUE;

    // Au cas où l'intervention n'est pas encore affectée et que l'on est en mode technicien agence ou agence,
    // il faut vérifier si le client fait partie de la zone de chalandise de l'agence
    if ((($_SESSION["niv_log"] == 3) OR ($_SESSION["niv_log"] == 4)) AND (trim($row["int_codeage"]) == "")) {
        if (trim($row["cli_prop"]) == "") {
            $rech2 = "SELECT * FROM `" . TBZCC . "` WHERE `zcc_code` = '" . $_SESSION["code_age"] . "' AND `zcc_codepays` = '" . $row["cli_codepays"] . "' AND `zcc_codedep` = '" . $row["cli_dep"] . "'";
            $rows2 = $db->get_results($rech2, ARRAY_A);
            if (count($rows2) == 0)
                $aff_ligne = FALSE;
        } else {
            if (trim($row["cli_prop"]) <> $_SESSION["code_age"])
                $aff_ligne = FALSE;
        }
    }

    if ($aff_ligne == TRUE) {
        // Création de l'entête de ligne (TR)
        creetrlst($i);

        // Urgence
        if ((@$_SESSION["niv_log"] == 5) OR (@$_SESSION["niv_log"] == 9) OR (@$_SESSION["niv_log"] == 4) OR (@$_SESSION["niv_log"] == 3) OR (@$_SESSION["niv_log"] == 6) OR (@$_SESSION["niv_log"] == 7)) {
            $couleur = give_coul_urg($row["int_urg"], FALSE);
            $detail = give_nom_urg($row["int_urg"], FALSE);;
            echo '<td align="center"';
            if ($couleur <> "XX")
                echo ' style ="background:' . $couleur . ';"';
            echo '>';
            echo '<a href="#" class="pop"><img src="../img/none.gif" alt="' . _("Détail") . '" border="0" align="absmiddle"><span>' . formatetxtbr($detail) . '</span></a>';
            echo "</td>\n";
        }

        echo '<td align="center">';
        echo $row["int_code"];
        if ((@$_SESSION["niv_log"] == 5) OR (@$_SESSION["niv_log"] == 9) OR (@$_SESSION["niv_log"] == 4) OR (@$_SESSION["niv_log"] == 3) OR (@$_SESSION["niv_log"] == 6) OR (@$_SESSION["niv_log"] == 7)) {
            $detfic = ">>" . _("Matériel") . " :<br />" . $row["int_mat"] . "<br /><br />>>" . _("Travail à effectuer") . " :<br />" . $row["int_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>';

            // traçabilité
            if ((@$_SESSION["niv_log"] == 9) OR (@$_SESSION["niv_log"] == 5)) {
                $url_detint = "tra_lst.php?tx=r&tl=i&cr=" . $row["int_code"];
                if (url_ok($url_detint, FALSE) == TRUE)
                    cre_falselnk_img('', 'int_tra_'.$row["int_id"], 'span', '', _("Traçabilité"), 'lnkpop', $url_detint, '../img/trace.gif', 800 , 500);
            }

            if ((@$_SESSION["niv_log"] <> 6) AND (@$_SESSION["niv_log"] <> 7)) {
                // On vérifie si le module planning est bien en place
                if ($mod_planning == TRUE) {
                    if (datetolocal($row["int_dateprev"]) == "") {
                        $url_edit = 'int_maj.php?td=edit&ci=' . $row["int_code"] . '&cc=' . $row["int_codecli"] . '&ca=' . $row["int_codeage"] . '&tong=2';
                        if (url_ok($url_edit, FALSE) == TRUE) {
                            echo ' ';
                            echo '<a href="' . $url_edit . '"><img src="../img/planning.png" border="0" align="absmiddle" title="' . _("Planifier") . '"></a>';
                        }
                    }
                }
            }
        }
        if ((datetolocal($row["int_dateprev"]) <> "") AND (datetolocal($row["int_datefin"]) == "")) {
            echo " <img src=\"../img/phone.png\" border=\"0\" align=\"absmiddle\"";
            if (@$_SESSION["niv_log"] <> 1)
                echo " title=\"" . _("Client prévenu le") . " " . datetolocal($row["int_dateprev"]) . "\"";
            else
                echo " title=\"" . _("Vous avez été prévenu(e) le") . " " . datetolocal($row["int_dateprev"]) . "\"";
            echo ">";
        }
        if ((@$_SESSION["niv_log"] == 5) OR (@$_SESSION["niv_log"] == 9) OR (@$_SESSION["niv_log"] == 4) OR (@$_SESSION["niv_log"] == 3)) {
            $rech2 = "SELECT * FROM `" . TBOT . "` WHERE `ot_codeint` = '" . $row["int_code"] . "'";
            $rows2 = $db->get_results($rech2, ARRAY_A);
            $nbexist_ot = count($rows2);
            if ($nbexist_ot > 0) {
                if ($nbexist_ot > 1)
                    $txt_ot = $nbexist_ot . " " . _("bons de travail rattachés");
                else
                    $txt_ot = $nbexist_ot . " " . _("bon de travail rattaché");
                $rech3 = "SELECT * FROM `" . TBOT . "` WHERE `ot_codeint` = '" . $row["int_code"] . "' AND `ot_datefin` = '0000-00-00'";
                $rows3 = $db->get_results($rech3, ARRAY_A);
                $nbexist_oto = count($rows3);
                if ($nbexist_oto > 0) {
                    if ($nbexist_oto > 1)
                        $txt_ot .= ", " . _("dont") . " " . $nbexist_oto . " " . _("non terminés");
                    else
                        $txt_ot .= ", " . _("dont") . " " . $nbexist_oto . " " . _("non terminé");
                    echo " <img src=\"../img/otolink.png\" title=\"" . $txt_ot . "\" border=\"0\" align=\"absmiddle\">";
                } else
                    echo " <img src=\"../img/otlink.png\" title=\"" . $txt_ot . "\" border=\"0\" align=\"absmiddle\">";
            }

            $nb_tac_actives = nb_tac_actives(1, $row["int_code"], FALSE);
            if ($nb_tac_actives > 0) {
                $url_taclst = "tac_lst.php?ord=DES&tri=Code&fi=3&search=" . $row["int_code"];
                if (url_ok($url_taclst, FALSE) == TRUE) {
                    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 à cette intervention") . ")";
                echo " <a href=\"" . $url_taclst . "\"><img src=\"../img/tacwarn.png\" title=\"" . $txt_tac . "\" border=\"0\" align=\"absmiddle\"></a>";
            }
        }
        echo "<div style=\"margin-left:7px;\">";
        if ((@$_SESSION["niv_log"] == 5) OR (@$_SESSION["niv_log"] == 9) OR (@$_SESSION["niv_log"] == 4) OR (@$_SESSION["niv_log"] == 3) OR (@$_SESSION["niv_log"] == 1)) {
            if ($row["int_codeman"] <> "") {
                echo "<div class=\"annot_petit_it\">";
                echo _("S.I.") . " : " . $row["int_codeman"];
                echo "</div>";
            }

            if ($row["int_codeocli"] <> "") {
                echo "<div class=\"annot_petit_it\">";
                echo _("O.C.") . " : " . $row["int_codeocli"];
                echo "</div>";
            }
        }
        if ((@$_SESSION["niv_log"] == 5) OR (@$_SESSION["niv_log"] == 9) OR (@$_SESSION["niv_log"] == 4) OR (@$_SESSION["niv_log"] == 3)) {
            if ($row["int_codeage"] <> "") {
                echo "<div class=\"annot_petit_it\">";
                echo _("Gestion") . " : " . $row["int_codeage"] . " / ";
                if (trim($row["int_codeages"]) <> "")
                    echo $row["int_codeages"];
                else
                    echo $row["int_codeage"];
                echo "</div>";
            }
        }

        if ((@$_SESSION["niv_log"] <> 7) AND (@$_SESSION["niv_log"] <> 6) AND (@$_SESSION["niv_log"] <> 2) AND (@$_SESSION["niv_log"] <> 1)) {
            if ($row["int_codedo"] <> "") {
                echo "<div class=\"annot_petit_it\">";
                echo _("D.O.") . " " . $row["int_codedo"];
                echo "</div>";
            }
        }
        if ((@$_SESSION["niv_log"] <> 2) AND (@$_SESSION["niv_log"] <> 1)) {
            if ($row["int_codeext"] <> "") {
                echo "<div class=\"annot_petit_it\">";
                echo _("Dossier") . " : " . $row["int_codeext"];
                echo "</div>";
            }
        }
        echo '</div>';
        echo "</td>\n";

        // Catégorie
        if ((@$_SESSION["niv_log"] == 5) OR (@$_SESSION["niv_log"] == 9) OR (@$_SESSION["niv_log"] == 4) OR (@$_SESSION["niv_log"] == 3) OR (@$_SESSION["niv_log"] == 6) OR (@$_SESSION["niv_log"] == 7)) {
            echo "<td align=\"center\">";
            $cat = $row["int_codecat"];
            $rech2 = "SELECT * FROM `" . TBINTC . "` WHERE intc_code = '$cat'";

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

            if ($row2) {
                $row2 = encode_str($row2);
                extract($row2);
                $url_cat = "intcat_maj.php?ci=" . $row["int_code"];
                if ($intc_img <> "") {
                    $catint = $intc_desc . " (" . $cat . ")";
                    echo '<img src="' . $intc_img . '" title="' . $catint . '" border="0" align="absmiddle"';
                    switch ($_SESSION["niv_log"]) {
                        case 3 :
                        case 4 :
                            if (($row["int_codeage"] == @$_SESSION["code_age"]) OR ($row["int_codeages"] == @$_SESSION["code_age"])) {
                                if (url_ok($url_cat, FALSE) == TRUE)
                                    echo " onclick=\"init_new_window('".$url_cat."','intc_edit_".$row["int_code"]."',600,300,'yes')\")";
                            }
                            break;
                        case 5 :
                        case 9 :
                            echo " onclick=\"init_new_window('".$url_cat."','intc_edit_".$row["int_code"]."',600,300,'yes')\")";
                            break;
                    }
                    echo '>';
                } else {
                    echo "<span class=\"annot_std_it\">";
                    echo $cat;
                    echo "</span>";
                }
            }
            echo "</td>\n";
        }

        // Date
        echo '<td align="center">';
        echo datetolocal($row["int_datedde"]);
        // Date fin prévue
        if ((@$_SESSION["niv_log"] == 5) OR (@$_SESSION["niv_log"] == 9) OR (@$_SESSION["niv_log"] == 4) OR (@$_SESSION["niv_log"] == 3) OR (@$_SESSION["niv_log"] == 6) OR (@$_SESSION["niv_log"] == 7)) {
            if (datetolocal($row["int_datefinp"]) <> "") {
                echo '<div align="center">';
                $pbm_ech = FALSE;
                if ((comp_date($row["int_datefinp"], $datea) == TRUE) AND (datetolocal($row["int_dateprev"]) == ""))
                    $pbm_ech = TRUE;
                if ($pbm_ech == TRUE)
                    echo '<a href="#" class="pop" style="font-size: 9px;color:#FF0000;font-weight:bold;"><span>' . _("A échéance") . '</span>';
                echo datetolocal($row["int_datefinp"]);
                if ($pbm_ech == TRUE)
                    echo '</a>';
                echo '</div>';
            } else
                echo "&nbsp;";
        }

        echo "</td>\n";

        // Prochain RDV
        echo '<td align="center" valign="top"';
        $row2 = next_rdv('1', $row["int_code"], FALSE);
        if (is_array($row2)) {
            $row2 = encode_str($row2);
            if ((@$_SESSION["niv_log"] == 5) OR (@$_SESSION["niv_log"] == 9) OR (@$_SESSION["niv_log"] == 4) OR (@$_SESSION["niv_log"] == 3) OR (@$_SESSION["niv_log"] == 6) OR (@$_SESSION["niv_log"] == 7))
                $couleur = give_coul_urg($row2["rdv_nivurg"], FALSE);
            if ((@$_SESSION["niv_log"] == 5) OR (@$_SESSION["niv_log"] == 9) OR (@$_SESSION["niv_log"] == 4) OR (@$_SESSION["niv_log"] == 3) OR (@$_SESSION["niv_log"] == 6) OR (@$_SESSION["niv_log"] == 7)) {
                if ($couleur <> "XX")
                    echo ' style="border: 2px solid ' . $couleur . ';"';
            }
        }
        echo '>';
        if ((@$_SESSION["niv_log"] == 5) OR (@$_SESSION["niv_log"] == 9) OR (@$_SESSION["niv_log"] == 4) OR (@$_SESSION["niv_log"] == 3) OR (@$_SESSION["niv_log"] == 6) OR (@$_SESSION["niv_log"] == 7)) {
            $missed = missed_rdv('1', $row["int_code"], FALSE);
            echo '<div style="float:right;z-index:1000;">';
            if ($missed > 0)
                echo '<img src="../img/warn.png" title ="' . _("Il existe des RDV non honorés ou du travail effectué est non saisi") . '" border="0" align="absmiddle">';
            else
                echo '<img src="../img/none.gif"border="0" align="absmiddle">';
            echo '</div>';
        }

        if (is_array($row2)) {
            $row2 = encode_str($row2);
            $planifie = est_planifie_rdv($row2["rdv_id"], FALSE);
            echo '<div style="clear:both;">';
            if (datetolocal($row2["rdv_date"]) <> "") {
                if ($planifie == FALSE)
                    echo '<a href="#" class="pop" style="font-size: 9px;color:#FF0000;font-weight:bold;"><span>' . _("RDV non planifié") . '</span>';
                echo datetolocal($row2["rdv_date"]);
                if ($planifie == FALSE)
                    echo '</a>';
                if ($row2["rdv_heure"] <> "00:00:00") {
                    echo '<div class="annot_petit_it" style="margin-bottom : 3px;">';
                    echo substr($row2["rdv_heure"], 0, 5);
                    echo '</div>';
                }
            } else
                echo "&nbsp;";
            echo '</div>';
        }
        echo "</td>\n";

        switch (@$_SESSION["niv_log"]) {
            case 1 :
                // Agence
                echo "<td align=\"center\">\n" . substr($row["int_codeage"], 1) . "</td>\n";

                // Site
                echo "<td>";

                // Si groupement de clients, on affiche le détail de chaque compte client
                if (count($tab_cli) > 1) {
                    echo $row["int_codecli"];
                    if (url_ok('cli_maj.php?td=edit&cc=' . $row["int_codecli"] . '&dep=' . $row2["cli_dep"], FALSE) == TRUE) {
                        $rech2 = "SELECT cli_dep FROM `" . TBCLI . "` WHERE `cli_code`='" . $row["int_codecli"] . "'";
                        $row2 = $db->get_row($rech2, ARRAY_A);
                        if ($row2) {
                            $row2 = encode_str($row2);
                            echo " <a href=\"cli_maj.php?td=edit&cc=" . $row["int_codecli"] . "&dep=" . $row2["cli_dep"] . "\"><img src=\"../img/edit.png\" width=\"14\" height=\"14\" border=\"0\" align=\"absmiddle\" title=\"" . _("Editer client") . "\"></a>";
                        }
                    }

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

                // Affichage site client
                $sitecli = "";
                switch (trim($row["int_idsite"])) {
                    case "0" :
                        $sitecli = _("Site principal");
                        break;
                    default :
                        $rech2 = "SELECT * FROM `" . TBSCLI . "` WHERE `scli_id` = '" . trim($row["int_idsite"]) . "'";
                        $row2 = $db->get_row($rech2, ARRAY_A);
                        if ($row2) {
                            $row2 = encode_str($row2);
                            extract($row2);
                            $sitecli .= $scli_ste . "<br />";
                            $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_itsoul\" style=\"margin-left:5px;padding-top:2px;\">";
                    echo "Site";
                    echo "</div>";
                    echo "<div class=\"annot_petit_it\" style=\"margin-left:7px;\">";
                    echo $sitecli;
                    echo "</div>";
                }

                echo "</td>\n";

                // Terminée
                echo "<td align=\"center\">\n";
                if ((datetolocal($row["int_datefin"]) <> "") OR (datetolocal($row["int_dateprev"]) <> "")) {
                    echo "<span class=\"annot_std_gras\">";
                    echo _("Terminée");
                    echo "</span>";
                } else {
                    echo "<span class=\"annot_std_it\">";
                    echo _("En cours");
                    echo "</span>";
                }
                echo "</td>\n";

                break;
            default :
                echo "<td>";
                echo $row["int_codecli"];
                if (url_ok('cli_maj.php?td=edit&cc=' . $row["int_codecli"] . '&dep=' . $row2["cli_dep"], FALSE) == TRUE) {
                    $rech2 = "SELECT cli_dep FROM `" . TBCLI . "` WHERE `cli_code`='" . $row["int_codecli"] . "'";
                    $row2 = $db->get_row($rech2, ARRAY_A);
                    if ($row2) {
                        $row2 = encode_str($row2);
                        echo " <a href=\"cli_maj.php?td=edit&cc=" . $row["int_codecli"] . "&dep=" . $row2["cli_dep"] . "\"><img src=\"../img/edit.png\" width=\"14\" height=\"14\" border=\"0\" align=\"absmiddle\" title=\"" . _("Editer client") . "\"></a>";
                    }
                }

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

                // Affichage site client
                $sitecli = "";
                switch (trim($row["int_idsite"])) {
                    case "0" :
                        $sitecli = _("Site principal");
                        break;
                    default :
                        $rech2 = "SELECT * FROM `" . TBSCLI . "` WHERE `scli_id` = '" . trim($row["int_idsite"]) . "'";
                        $row2 = $db->get_row($rech2, ARRAY_A);
                        if ($row2) {
                            $row2 = encode_str($row2);
                            extract($row2);
                            $sitecli .= $scli_ste . "<br />";
                            $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 <> "") {
                    if (trim($row["int_idsite"]) <> "0") {
                        echo "<div class=\"annot_petit_itsoul\" style=\"margin-left:5px;padding-top:2px;\">";
                        echo _("Site");
                        if (trim($scli_code) <> "")
                            echo " (" . $scli_code . ")";
                        echo "</div>";
                    }
                    echo "<div class=\"annot_petit_it\" style=\"margin-left:7px;\">";
                    echo $sitecli;
                    echo "</div>";
                }

                // Fin affichage détail client
                echo "</td>\n";
                break;
        }

        // Technicien / Agence traitants
        echo "<td align=\"center\">";
        if (($row["int_codetec"] <> "") AND ($row["int_codetec"] <> "-1")) {
            echo $row["int_codetec"];
            $row2 = lit_enr_tec($row["int_codetec"], FALSE);
            if (is_array($row2)) {
                $row2 = encode_str($row2);
                extract($row2);
                echo "<div class=\"annot_petit_it\">";
                echo "(" . $tec_civilite . " " . $tec_prenom . " " . $tec_nom . " - " . $tec_codeage . ")";
                echo "</div>";
            }
        } else
            echo "-";
        echo "</td>\n";

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

        $url_statut = "ints_maj.php?ci=" . $row["int_code"];
        switch ($_SESSION["niv_log"]) {
            case 3 :
            case 4 :
                if (($row["int_codeage"] == @$_SESSION["code_age"]) OR ($row["int_codeages"] == @$_SESSION["code_age"])) {
                    if (url_ok($url_statut, FALSE) == FALSE)
                        $url_statut = '';
                }
                else
                    $url_statut = '';
                break;
            case 5 :
            case 9 :
                if (url_ok($url_statut, FALSE) == FALSE)
                    $url_statut = '';
                break;
        }

        echo str_div_ico_statut($row["int_codestatut"], $url_statut , FALSE);

        echo "</td>\n";

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

            if (@$_SESSION["niv_log"] <> 1) {
                $voir = FALSE;

                if (datetolocal($row["int_datefin"]) == "") {
                    if ((@$_SESSION["niv_log"] == 7) OR (@$_SESSION["niv_log"] == 6)) {
                        if (($row["int_codetec"] <> "") AND ($row["int_codetec"] <> "-1"))
                            $voir = TRUE;
                    }

                    if ((@$_SESSION["niv_log"] == 11) OR (@$_SESSION["niv_log"] == 10))
                        $voir = TRUE;
                } else
                    $voir = TRUE;

                if ($voir == FALSE) {
                    $url_edit = 'int_maj.php?td=edit&ci=' . $row["int_code"] . '&cc=' . $row["int_codecli"] . '&ca=' . $row["int_codeage"];
                    if (url_ok($url_edit, FALSE) == TRUE) {
                        $lst_maj = TRUE;
                        cre_falselnk_img('', 'int_edit_'.$row["int_id"], 'span', 'center', _("Edition"), 'lnk', $url_edit , '../img/edit.png');
                    }
                } else {
                    $url_view = 'int_maj.php?td=view&ci=' . $row["int_code"] . '&cc=' . $row["int_codecli"];
                    if (url_ok($url_view, FALSE) == TRUE) {
                        $lst_voir = TRUE;
                        cre_falselnk_img('', 'int_view_'.$row["int_id"], 'span', 'center', _("Edition"), 'lnk', $url_view , '../img/eye.png');
                    }
                }

                if ($aff_sfact == TRUE) {
                    $affok = TRUE;
                    if ((@$_SESSION["niv_log"] == 4) AND (@$_SESSION["code_log"] <> $row["int_codeage"]))
                        $affok = FALSE;
                    if ($affok == TRUE) {
                        $nb_intf = nb_intf_int($row["int_code"], FALSE);
                        $txt_fact = _("facture");
                        if ($nb_intf > 0) {
                            if ($nb_intf > 1)
                                $txt_fact .= "s";
                            $url_sfact = 'intf_lst.php?tx=m&ci=' . $row["int_code"] . '&ord=ASC&tri=Facture';
                            if (url_ok($url_sfact, FALSE) == TRUE) {
                                $lst_sfact = TRUE;
                                cre_falselnk_img('', 'int_sfact_'.$row["int_id"], 'span', 'center', _("Suivi facturation"). ' (' . $nb_intf . ' ' . $txt_fact . ')', 'lnk', $url_sfact , '../img/sfact.png');
                            }
                        } else {
                            $url_sfact = 'intf_lst.php?tx=m&ci=' . $row["int_code"] . '&ord=ASC&tri=Facture';
                            if (url_ok($url_sfact, FALSE) == TRUE) {
                                $lst_sfacta = TRUE;
                                cre_falselnk_img('', 'int_sfacta_'.$row["int_id"], 'span', 'center', _("Ajout facturation"). ' (' . $nb_intf . ' ' . $txt_fact . ')', 'lnk', $url_sfact , '../img/sfact_add.png');
                            }
                        }
                    }
                }
            } else {
                $url_view = 'int_maj.php?td=view&ci=' . $row["int_code"] . '&cc=' . $row["int_codecli"];
                if (url_ok($url_view, FALSE) == TRUE) {
                    $lst_voir = TRUE;
                    cre_falselnk_img('', 'int_view_'.$row["int_id"], 'span', 'center', _("Visualisation"), 'lnk', $url_view , '../img/eye.png');
                }
            }


            $alea = time();
            $urlimp = "int_pdf.php?token=" . $alea . "&ci=" . $row["int_code"] . "&timp=0";
            if (url_ok($urlimp, FALSE) == TRUE) {
                $lst_imp = TRUE;
                cre_falselnk_img('', 'int_prn_'.$row["int_id"], 'span', 'center', _("Impression"), 'lnkpop', $urlimp , '../img/print.png');
            }

            if (((@$_SESSION["niv_log"] == 4) OR (@$_SESSION["niv_log"] == 3)  OR (@$_SESSION["niv_log"] == 5) OR (@$_SESSION["niv_log"] == 9)) AND ($row["int_forfait"] > 0)) {
                $urlimp = "int_pdf.php?token=" . $alea . "&ci=" . $row["int_code"] . "&timp=0&te=cli";
                if (url_ok($urlimp, FALSE) == TRUE) {
                    $lst_impcl = TRUE;
                    cre_falselnk_img('', 'int_prnc_'.$row["int_id"], 'span', 'center', _("Impression pour le client"), 'lnkpop', $urlimp , '../img/printcl.png');
                }
            }

            $mail = TRUE;
            if ($_SESSION["code_age"] <> $row["int_codeage"]) {
                if ((@$_SESSION["niv_log"] == 4) OR (@$_SESSION["niv_log"] == 3))
                    $mail = FALSE;
            }

            if ($mail == TRUE) {
                $alea = time();
                $urlmail = "int_pdf.php?token=" . $alea . "&ci=" . $row["int_code"] . "&timp=1&tact=cop";
                if (url_ok($urlmail, FALSE) == TRUE) {
                    $lst_mail = TRUE;
                    if (@$_SESSION["niv_log"] <> 1)
                        $title=  _("Renvoyer une copie par email au client");
                    else
                        $title= _("Obtenir une copie par email");
                    cre_falselnk_img('', 'int_mail_'.$row["int_id"], 'span', 'center', $title, 'lnkpop', $urlmail , '../img/mail.png',1,1);
                }
            }

            if (@$_SESSION["niv_log"] <> 1) {
                $del = FALSE;
                if (datetolocal($row["int_datefin"]) == "") {
                    $del = TRUE;

                    // Le créateur et l'administrateur peuvent toujours supprimer une intervention
                    if (($row["int_codecrea"] <> $_SESSION["code_log"]) AND ($_SESSION["niv_log"] <> 9)) {
                        switch ($_SESSION["niv_log"]) {
                            // On vérifie que le technicien connecté est bien celui qui est responsable du dossier
                            // S'il n'y a pas de responsable de dossier, il ne peut pas supprimer l'intervention
                            case 3 :
                                if ($row["int_codetec"] <> "-1") {
                                    if ($row["int_codetec"] <> $_SESSION["code_log"])
                                        $del = FALSE;
                                } else
                                    $del = FALSE;
                                if ($row["int_codedo"] <> "")
                                    $del = FALSE;
                                break;
                            // Si l'agence traitante et différente de l'agence connectée, on vérifie s'il y a un technicien responsable
                            // Si le technicien responsable appartient à l'agence, l'agence peut supprimer l'intervention
                            case 4 :
                                if ($_SESSION["code_age"] <> $row["int_codeage"]) {
                                    if (($row["int_codetec"] <> "-1") AND ($row["int_codetec"] <> "")) {
                                        $row2 = lit_enr_tec($row["int_codetec"], FALSE);
                                        if (is_array($row2)) {
                                            $row2 = encode_str($row2);
                                            extract($row2);
                                            if ($tec_codeage <> $_SESSION["code_age"])
                                                $del = FALSE;
                                        }
                                    } else
                                        $del = FALSE;
                                }
                                if ($row["int_codedo"] <> "")
                                    $del = FALSE;
                                break;
                            // Seul le donneur d'ordres peut supprimer son propre ordre
                            case 6 :
                            case 7 :
                                if (($row["int_codedo"] <> "") AND ($row["int_codedo"] <> $_SESSION["code_do"]))
                                    $del = FALSE;
                                break;
                            default :
                                break;
                        }
                    }

                    if ($del == TRUE) {
                        $url_del = 'int_maj.php?td=del&ci=' . $row["int_code"] . '&cc=' . $row["int_codecli"] . '&ct=' . $row["int_codetec"];
                        if (url_ok($url_del, FALSE) == TRUE) {
                            $lst_del = TRUE;
                            cre_falselnk_img('', 'int_del_'.$row["int_id"], 'span', 'center', _("Suppression"), 'lnk', $url_del , '../img/del.png');
                        }
                    }
                } else {
                    if (@$_SESSION["niv_log"] == 9) {
                        $lst_reopen = TRUE;
                        cre_falselnk_img('', 'int_reopen_'.$row["int_id"], 'span', 'center', _("Réouverture"), 'lnkwpop', 'int_reopen.php?ci=' . $row["int_code"] , '../img/reopen.png',900,400);
                    }
                }
            }
            echo "</div>";
            echo "</td>\n";
        }

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

        $i++;
    }
}
?>
