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

include_once("../inc/fic_cli.inc.php");
include_once("../inc/fic_cocl.inc.php");
include_once("../inc/fic_droits.inc.php");
include_once("../inc/fic_int.inc.php");
include_once("../inc/fic_tac.inc.php");
include_once("../inc/func.inc.php");
include_once("../inc/func_date.inc.php");
include_once("../inc/func_time.inc.php");
include_once("../inc/func_geo.inc.php");
include_once("../inc/func_txt.inc.php");
include_once("../inc/lst.inc.php");
include_once("../classes/ezSQL/shared/ez_sql_core.php");
include_once("../classes/ezSQL/mysqli/ez_sql_mysqli.php");
include_once("../inc/func_sql.inc.php");
Archivelog(@$_SESSION["code_log"]);
$_SESSION["typ_filtres"] = "cocla";

// Variables Formulaire
fix_magic_quotes();
$_GET = clean_str($_GET);

$pbm_cocl = FALSE;

$co= '';
if (isset($_GET['co']))
    $co = $_GET['co']; // Récupération code Contrat

if ($pbm_cocl == FALSE) {
    if ($co <> "") {
        // Récupération des informations contrat client
        $row = lit_enr_cocl($co);
        if (is_array($row)) {
            extract($row);

            // Récupération des informations client
            $row = lit_enr_cli($cocl_codecli);
            if (is_array($row))
                extract($row);

            // Contrôle qu'un client n'essaye pas de "hacker" un contrat
            if (@$_SESSION["niv_log"] == 1) {
                $tab_cli = give_tab_rcli($_SESSION["code_log"], TRUE);
                if (exist_in_array($cocl_codecli, $tab_cli) == FALSE)
                    $pbm_cocl = TRUE;
            }

            // Contrôle qu'une agence n'essaye pas de "hacker" un contrat
            if (((@$_SESSION["niv_log"] == 4) OR (@$_SESSION["niv_log"] == 3)) AND ($cocl_codeage <> @$_SESSION["code_age"]))
                $pbm_cocl = TRUE;
        } else
            $pbm_cocl = TRUE;
    }
}
?>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>

        <meta http-equiv="content-type" content="text/html; charset=UTF-8">
        <title>SMI - <?PHP echo _("ESPACE PRIVE"); ?> : <?PHP echo _("Liste Annexes Contrats Clients"); ?></title>

        <?PHP include_once("../inc/header.inc.php"); ?>

        <script type="text/javascript">
            <!--
            function init_all() {
                init_Body();
                init_autohref_classe('falselnkimg','');
                Focus_first();
            }

            $(document).ready(function () {
                init_all();
            });
            //-->
        </script>

    </head>

    <body>

<?php
include_once("../inc/entete.inc.php");

if ($pbm_cocl == FALSE) {
    $titre_lst = "";
    switch (@$_SESSION["niv_log"]) {
        case 1 :
            if (trim($co) <> "")
                $titre_lst = _("VOS ANNEXES AU CONTRAT").' ' . $co;
            else
                $titre_lst = _("ANNEXES DE VOS CONTRATS");
            $tab_cli = give_tab_rcli($_SESSION["code_log"], TRUE);
            echo '<p align="center"><span class="titrepage">' . $titre_lst . '</span></p>';
            break;
        default :
            if (trim($co) <> "")
                $titre_lst = _("ANNEXES AU CONTRAT").' ' . $co;
            else
                $titre_lst = _("ANNEXES DE CONTRATS");
            echo '<p align="center"><span class="titrepage">' . $titre_lst . '</span></p>';
            if ((@$_SESSION["niv_log"] == 4) OR (@$_SESSION["niv_log"] == 3))
                echo '<p align="center" class="annot_std_it">('._("Gérés par votre agence").')</p>';
            break;
    }

    switch (@$_SESSION["niv_log"]) {
        case 1 :
            $fic_imp = "cocla_lsti.php";
            break;
        case 3 :
        case 4 :
        case 5 :
        case 9 :
            $fic_imp = "cocla_lsti.php";
            break;
    }

    $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);

    $rech = cree_strrechlstcocla($co);
    switch (@$_SESSION["niv_log"]) {
        case 1 :
            break;
        case 3 :
        case 4 :
            if (!stristr($rech, "WHERE "))
                $rech .= " WHERE " . TBCOCL . ".cocl_codeage='" . @$_SESSION["code_age"] . "'";
            else
                $rech .= " AND " . TBCOCL . ".cocl_codeage='" . @$_SESSION["code_age"] . "'";
            break;
        default :
            break;
    }

    $rech .= crestr_triord($cocla_titre_col, "cocla_code", FALSE, $limit);

    $rows = $db->get_results($rech, ARRAY_A);

    $db->disconnect();

    if ($rows) {
        include_once("formr.inc.php");
        $numrows = count($rows);

        $rech = modstr_triord($rech, $cocla_titre_col, "cocla_code", TRUE, $limit);

        $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);

        $rows = $db->get_results($rech, ARRAY_A);

        // *** Pagination de pied
        pagine_lst($numrows, $limit);


        // *** Affichage de la table
        echo "<table class=\"Mtable\" border=\"0\" width=\"100%\" cellpadding=\"0\" cellspacing=\"0\">\n";

        // création entête
        titlst($cocla_titre_col);
        echo "<th>" . _("Cliquer") . "</th>\n";

        $i = 0;

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

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

            $echeance_ok = TRUE;
            echo "<td>" . $row["cocla_code"] . ' ('._("contrat").' ' . $row["cocla_codecocl"] . ')';

            // CREATION d'icône si signé
            if (datetolocal($row["cocla_datesig"]) <> "") {
                $lst_sig = TRUE;
                echo ' <a href="#" class="popa"><img src="../img/ok.png" alt="'._("Signé le").' ' . datetolocal($row["cocl_datesig"]) . '" border="0" align="absmiddle"><span>'._("Signé le").' ' . datetolocal($row["cocla_datesig"]) . '</span></a>';
            }

            echo "</td>\n";

            // création
            echo "<td>";
            echo "<div align=\"center\">";
            echo datetolocal($row["cocla_datecrea"]);
            echo "</div>";
            echo "</td>\n";
            // relancé le
            echo "<td>";
            echo "<div align=\"center\">";
            if (datetolocal($row["cocla_daterel"]) == "")
                echo "&nbsp;";
            else
                echo datetolocal($row["cocla_daterel"]);
            echo "</div>";
            echo "</td>\n";

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

            if (@$_SESSION["niv_log"] >= 4) // Edition, cloture, et annexes uniquement si >=agence
            {
                if (datetolocal($row["cocla_datesif"]) == "") {
                    if (url_ok('cocla_maj.php?td=edit&co=' . $row["cocla_codecocl"] . '&coa=' . $row["cocla_code"], FALSE) == TRUE) {
                        $lst_maj = TRUE;
                        cre_falselnk_img('', 'cocla_edit_'.$row["cocla_id"], 'span', 'center', _("Edition") , 'lnk', 'cocla_maj.php?td=edit&co=' . $row["cocla_codecocl"] . '&coa=' . $row["cocla_code"], '../img/edit.png');
                    }
                } else {
                    if (url_ok('cocla_maj.php?td=view&co=' . $row["cocla_codecocl"] . '&coa=' . $row["cocla_code"], FALSE) == TRUE) {
                        $lst_voir = TRUE;
                        cre_falselnk_img('', 'cocla_view_'.$row["cocla_id"], 'span', 'center', _("Visualisation") , 'lnk', 'cocla_maj.php?td=view&co=' . $row["cocla_codecocl"] . '&coa=' . $row["cocla_code"], '../img/eye.png');
                    }
                }
            }

            if (@$_SESSION["niv_log"] <= 3) // Voir si <=Technicien
            {
                if (url_ok('cocla_maj.php?td=view&co=' . $row["cocla_codecocl"] . '&coa=' . $row["cocla_code"], FALSE) == TRUE) {
                    $lst_voir = TRUE;
                    cre_falselnk_img('', 'cocla_view_'.$row["cocla_id"], 'span', 'center', _("Visualisation") , 'lnk', 'cocla_maj.php?td=view&co=' . $row["cocla_codecocl"] . '&coa=' . $row["cocla_code"], '../img/eye.png');
                }
            }

            $urlimp = "cocla_pdf.php?co=" . $row["cocla_codecocl"] . "&coa=" . $row["cocla_code"];
            if (url_ok($urlimp, FALSE) == TRUE) {
                $lst_imp = TRUE;
                cre_falselnk_img('', 'cocla_prn_'.$row["cocla_id"], 'span', 'center', _("Imprimer") , 'lnkpop', $urlimp, '../img/print.png');
            }

            $urlmail = "cocla_pdf.php?co=" . $row["cocla_codecocl"] . "&coa=" . $row["cocla_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('', 'cocla_mail_'.$row["cocla_id"], 'span', 'center', $title , 'lnkpop', $urlmail, '../img/mail.png',1,1);
            }

            if (@$_SESSION["niv_log"] >= 4) // Suppression uniquement si >=agence et si pas signé
            {
                if (datetolocal($row["cocla_datesig"]) == "") {
                    if (url_ok('cocla_maj.php?td=del&co=' . $row["cocla_codecocl"] . '&coa=' . $row["cocla_code"], FALSE) == TRUE) {
                        $lst_del = TRUE;
                        cre_falselnk_img('', 'cocla_del_'.$row["cocla_id"], 'span', 'center', _("Suppression") , 'lnk', 'cocla_maj.php?td=del&co=' . $row["cocla_codecocl"] . '&coa=' . $row["cocla_code"], '../img/del.png');
                    }
                }
            }

            echo "</td>\n";

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

            $i++;
        }
        echo "</table>\n";
        // *** Fin affichage de la table

        $db->disconnect();

        // *** Pagination de pied
        pagine_lst($numrows, $limit);

        $taille_piedla = "";
        include_once("piedla.inc.php");
    } else
        retpp();
} else
    pop_ret_auto(_("Problème de paramètres"), 'warn', "index.php");
include_once("pied.php");
?>