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

include_once("../inc/func.inc.php");
include_once("../inc/func_time.inc.php");
include_once("../inc/func_date.inc.php");
include_once("../inc/func_geo.inc.php");
include_once("../inc/func_txt.inc.php");
include_once("../inc/func_txtcm.inc.php");
include_once("../inc/fic_age.inc.php");
include_once("../inc/fic_hum.inc.php");
include_once("../inc/fic_cli.inc.php");
include_once("../inc/fic_co.inc.php");
include_once("../inc/fic_cocl.inc.php");
include_once("../inc/fic_do.inc.php");
include_once("../inc/fic_droits.inc.php");
include_once("../inc/fic_int.inc.php");
include_once("../inc/fic_ope.inc.php");
include_once("../inc/fic_prm.inc.php");
include_once("../inc/fic_st.inc.php");
include_once("../inc/fic_taxes.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"]);
// Variables Formulaire
fix_magic_quotes();
$_GET = clean_str($_GET);

$co = $_GET['co']; // Récupération code contrat

$pbm_cocl = FALSE;

if ($co == "")
    $pbm_cocl = TRUE;

// Niveau =2 interdit
if (@$_SESSION["niv_log"] == 2)
    $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 _("Synthèse contrat"); ?></title>

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

    <script type="text/javascript">
        <!--
        function init_all() {
            init_Body();
            warn_print(1);
        }

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


</head>

<body>

<?PHP
if ($pbm_cocl == FALSE) {
    if (!ini_get('safe_mode'))
        set_time_limit(0); // On demande à PHP de ne pas interrrompre le script pendant le traitement

    // Récupération des informations contrat client
    $row = lit_enr_cocl($co);
    if (is_array($row)) {
        $row = encode_str($row);
        extract($row);
        // 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;

        if ($pbm_cocl == FALSE) {
            $codeadev = give_dev_codea_defaut_cocl($cocl_code, $_SESSION["lng"]);

            $cocl_datecreaf = datetolocal($cocl_datecrea);
            $cocl_datesigf = datetolocal($cocl_datesig);
            $cocl_datefinf = datetolocal($cocl_datefin);

            $row = lit_enr_co($cocl_codeco);
            $row = encode_str($row);
            extract($row);

            // Récupération des données client
            $row = lit_enr_cli($cocl_codecli, TRUE);
            $row = encode_str($row);
            extract($row);

            echo '<div align="center" class="titrerubrique3" style="font-size: 14px;">';
            echo _("SYNTHESE DE CONTRAT");
            echo '</div>';
            echo '<table border="1" width="100%">';
            echo '<tr>';
            echo '<td align="center" class="annot_std_gras">';
            echo _("CLIENT");
            echo '</td>';
            echo '</tr>';
            echo '<tr>';
            echo '<td>';
            $ent_cli = ""; // détail
            if ($cli_ste <> "") {
                $ent_cli .= $cli_ste . "<br />";
                $ent_cli .= $cli_civilite . " " . $cli_prenom . " " . $cli_nom . "<br />";
            } else {
                $ent_cli .= $cli_civilite . " " . $cli_prenom . " " . $cli_nom . "<br /><br />"; // Double saut pour compenser le manque de la société
            }

            $ent_cli .= $cli_adr1 . "<br />"; // Suite...
            if (trim($cli_adr2) <> "")
                $ent_cli .= $cli_adr2 . "<br />";
            $ent_cli .= Retournecp_Id($cli_ville, TRUE) . " " . Retourneville_Id($cli_ville, TRUE) . "<br />";
            $ent_cli .= _("Tel") . ' : ' . $cli_telf . '<br />';
            $ent_cli .= _("Fax") . ' : ' . $cli_fax;
            if (trim($cli_tvai) <> "")
                $ent_cli .= '<br />' . _("TVA") . ' : ' . $cli_tvai;
            echo $ent_cli;
            echo '</td>';
            echo '</tr>';
            echo '</table>';

            /**********************************/
            /* Impression de la fiche contrat */
            /**********************************/

            echo '<br />';
            echo '<div align="center">';
            echo '<span class="annot_std_gras">';
            echo $cocl_code;
            echo '</span>';

            $echeance_ok = TRUE;
            $txterr = "";
            if (datetolocal($cocl_datef) <> "") {
                if (echeance_depassee_date($datea, $cocl_datef) == TRUE)
                    $echeance_ok = FALSE;
            }
            if ((datetolocal($cocl_datesig) == "") OR (datetolocal($cocl_datefin) <> "") OR ($echeance_ok == FALSE)) {
                if (datetolocal($cocl_datesig) == "") {
                    $txterr .= _("Non signé");
                    if ((datetolocal($cocl_datefin) <> "") OR ($echeance_ok == FALSE))
                        $txterr .= " / ";
                }
                if ((datetolocal($cocl_datefin) <> "") OR ($echeance_ok == FALSE))
                    $txterr .= _("terminé");
            }
            if ($txterr <> "") {
                echo '<span class="annot_petit_gras_rouge">';
                echo ' ' . $txterr;
                echo '</span>';
            }
            echo '<span class="annot_petit_it">';
            echo ' ' . _("créé le") . ' ' . datetolocal($cocl_datecrea);
            echo '</span>';
            echo '</div>';

            echo '<br />';

            echo '<table border="0" width="100%">';
            echo '<tr>';
            echo '<td align="right">';
            echo _("Site Principal") . ' : ';
            echo '</td>';
            echo '<td>';

            if ($cocl_sitep == 1)
                echo _("oui");
            else
                echo _("non");
            echo '</td>';
            echo '</tr>';

            echo '<tr>';

            // Liste des sites, inclues les annexes
            $lstsites = cree_str_lstsites_cocl($cocl_code);
            if ($lstsites <> "") {
                echo '<td align="right">';
                echo _("Sites Secondaires") . ' : ';
                echo '</td>';
                echo '<td>';
                $tab_scli = explode("-", $lstsites);
                $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
                foreach ($tab_scli as $key => $value) {
                    $nom_site = "";
                    $rech2 = "SELECT scli_ste,scli_adr1,scli_adr2,scli_ville FROM `" . TBSCLI . "` WHERE `scli_id` = '$value'";
                    $row2 = $db->get_row($rech2, ARRAY_A);
                    if ($row2) {
                        extract($row2);
                        $nom_site .= $scli_ste;
                        $nom_site .= ", ";
                        $nom_site .= $scli_adr1;
                        $nom_site .= ", ";
                        if ($scli_adr2 <> "") {
                            $nom_site .= $scli_adr2;
                            $nom_site .= ", ";
                        }
                        $nom_site .= Retournecp_Id($scli_ville, FALSE) . " " . Retourneville_Id($scli_ville, FALSE);
                    }
                    echo $nom_site . '<br />';
                }
                $db->disconnect();
                echo '</td>';
            }
            echo '</tr>';

            // Agence
            echo '<tr>';
            echo '<td align="right">';
            echo _("Agence") . ' : ';
            echo '</td>';
            echo '<td>';
            $row = lit_enr_age($cocl_codeage, TRUE);
            extract($row);
            $age_nomcode = $age_nom . " (" . $age_code . ")";
            echo $age_nomcode;
            echo '</td>';
            echo '</tr>';
            // Contrat type
            echo '<tr>';
            echo '<td align="right">';
            echo _("Contrat type") . ' : ';
            echo '</td>';
            echo '<td>';
            echo $co_nom;
            echo '</td>';
            echo '</tr>';
            // Fréquence
            echo '<tr>';
            echo '<td align="right">';
            echo _("Fréquence") . ' : ';
            $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
            $rech = "SELECT per_desc FROM `" . TBPER . "` WHERE `per_code` = '" . $cocl_codeper . "'";
            $row = $db->get_row($rech, ARRAY_A);
            if ($row) {
                $row = encode_str($row);
                extract($row);
            }
            $db->disconnect();
            echo '</td>';
            echo '<td>';
            echo $per_desc;
            echo '</td>';
            echo '</tr>';
            // Délai
            echo '<tr>';
            echo '<td align="right">';
            echo _("Délai") . ' : ';
            echo '</td>';
            echo '<td>';
            echo $cocl_delai . ' ' . _("heures ouvrées");
            echo '</td>';
            echo '</tr>';
            // Temps / Type
            echo '<tr>';
            echo '<td align="right">';
            echo _("Temps initial / Type") . ' : ';
            echo '</td>';
            echo '<td>';
            echo heure_to_hhmm(sec_heure($cocl_nbs, 3, TRUE)) . " / " . $typ_horaire[$cocl_typh];
            echo '</td>';
            echo '</tr>';
            echo '<tr>';
            echo '<td align="right">';
            echo '&nbsp;';
            echo '</td>';
            echo '<td>';
            if ($cocl_typh == 1)
                echo _("Solde réel") . ' : ' . heure_to_hhmm(sec_heure(solde_contrat_sec($cocl_code, TRUE), 3, TRUE)) . ' <span class="annot_petit_it">(' . _("Heures à sortir") . ' : ' . heure_to_hhmm(sec_heure(tps_trav_non_clot_sec($cocl_code, TRUE), 3, TRUE)) . ')</span>';
            echo '</td>';
            echo '</tr>';

            // création de la liste des reports affectés à ce contrat (s'il y en a)
            $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
            $rech = "SELECT * FROM `" . TBCOCLR . "` WHERE coclr_cocldest = '" . $cocl_code . "' ORDER BY coclr_codeint";
            $rows = $db->get_results($rech, ARRAY_A);

            if ($rows) {
                $totalreport = 0;

                // Titres
                echo '<tr>';
                echo '<td align="center" colspan="2">';
                echo '<table style="border-collapse:collapse;" width="90%" align="center">';
                echo '<tr class="annot_petit_gras_soul">';
                echo '<td align="center">';
                echo _("détails des reports affectés à ce contrat");
                echo '</td>';
                echo '<td align="center">';
                echo _("Durée");
                echo '</td>';
                echo '</tr>';

                foreach ($rows as $row) {
                    $row = encode_str($row);
                    extract($row);
                    echo '<tr class="annot_petit">';
                    if ($coclr_nbsrep > 0)
                        $txt = _("Report non consommé du contrat");
                    else
                        $txt = _("Déduction sur-consommé du contrat");
                    $txt .= ' ' . $coclr_coclori;
                    if ($coclr_codeint <> '')
                        $txt .= ' (' . _("Intervention") . ' ' . $coclr_codeint . ')';
                    else
                        $txt .= ' (' . _("Clôture manuelle") . ')';
                    echo '<td style="border:1px solid grey;">';
                    echo $txt;
                    echo '</td>';

                    echo '<td align="center" style="border:1px solid grey;">';
                    if ($coclr_nbsrep > 0)
                        echo heure_to_hhmm(sec_heure($coclr_nbsrep, 3, TRUE));
                    else
                        echo heure_to_hhmm(sec_heure($coclr_nbsrep, 3, TRUE), 0, 6);
                    $totalreport += $coclr_nbsrep;
                    echo '</td>';
                    echo '</tr>';
                }
                echo '<tr class="annot_petit_itgras">';
                echo '<td align="right" style="border:1px solid grey;">';
                echo _("Total général") . ' : ';
                echo '</td>';
                echo '<td align="center" style="border:1px solid grey;">';
                if ($totalreport > 0)
                    echo heure_to_hhmm(sec_heure($totalreport, 3, TRUE));
                else
                    echo heure_to_hhmm(sec_heure($totalreport, 3, TRUE));
                echo '</td>';
                echo '</table>';
                echo '</td>';
                echo '</tr>';
            }
            $db->disconnect();

            // Report heures non consommées
            echo '<tr>';
            echo '<td align="right">';
            echo _("Report heures non cons.").' : ';
            echo '</td>';
            echo '<td>';
            echo $non_oui[$cocl_nbsnc];
            echo '</td>';
            echo '</tr>';
            // Report heures dépassées
            echo '<tr>';
            echo '<td align="right">';
            echo _("Report heures dépassées") . ' : ';
            echo '</td>';
            echo '<td>';
            echo $non_oui[$cocl_nbsdep];
            echo '</td>';
            echo '</tr>';
            // validité
            echo '<tr>';
            echo '<td align="right">';
            echo _("Validité : ");
            echo '</td>';
            echo '<td>';
            $txtval = datetolocal($cocl_dated);
            if (datetolocal($cocl_datef) <> "")
                $txtval .= ' ' . _("au") . ' ' . datetolocal($cocl_datef);
            else
                $txtval .= ' <span class="annot_petit_it">(' . _("pas de date limite") . ')</span>';
            echo $txtval . ', ' . _("avec préavis de") . ' ' . $cocl_preavis . ' ' . _("jours") . '.';
            echo '</td>';
            echo '</tr>';
            // Renouvellement automatique
            echo '<tr>';
            echo '<td align="right">';
            echo _("Renouvellement auto.") . ' : ';
            echo '</td>';
            echo '<td>';
            echo $non_oui[$cocl_renauto];
            echo '</td>';
            echo '</tr>';
            // matériel
            echo '<tr>';
            echo '<td align="right">';
            echo _("Matériel") . ' : ';
            echo '</td>';
            echo '<td>';
            echo $cocl_matos;
            echo '</td>';
            echo '</tr>';
            // Date Signature
            echo '<tr>';
            echo '<td align="right">';
            echo _("Signé le") . ' : ';
            echo '</td>';
            echo '<td>';
            echo datetolocal($cocl_datesig);
            echo '</td>';
            echo '</tr>';
            // signé par
            echo '<tr>';
            echo '<td align="right">';
            echo _("Signé par") . ' : ';
            echo '</td>';
            echo '<td>';
            echo $cocl_signe;
            echo '</td>';
            echo '</tr>';
            // relancé
            if (datetolocal($cocl_daterel) <> "") {
                echo '<tr>';
                echo '<td align="right">';
                echo _("Relancé") . ' : ';
                echo '</td>';
                echo '<td>';
                echo datetolocal($cocl_daterel) . '(' . $cocl_nivrel . ' ' . _("fois") . ')';
                echo '</td>';
                echo '</tr>';
            }
            if (datetolocal($cocl_datesig) <> "") {
                // renouvelé
                echo '<tr>';
                echo '<td align="right">';
                echo _("Renouvelé") . ' : ';
                echo '</td>';
                echo '<td>';
                $txtrnum = $non_oui[$cocl_renouv];
                if ($cocl_rnum <> "")
                    $txtrnum .= ' <span class="annot_petit_it">(' . _("Nouveau contrat") . ' : ' . $cocl_rnum . ')</span>';
                echo $txtrnum;
                echo '</td>';
                echo '</tr>';

                // Clôt
                echo '<tr>';
                echo '<td align="right">';
                echo _("Clôt le") . ' : ';
                echo '</td>';
                echo '<td>';
                echo datetolocal($cocl_datefin);
                echo '</td>';
                echo '</tr>';
            }
            // Prix HT
            echo '<tr>';
            echo '<td align="right">';
            echo _("PV HT") . ' : ';
            echo '</td>';
            echo '<td>';
            echo $cocl_pvht . " " . give_dev_TXT($codeadev);
            echo '</td>';
            echo '</tr>';
            // TVA
            echo '<tr>';
            echo '<td align="right">';
            echo _("TVA") . ' : ';
            echo '</td>';
            echo '<td>';
            $row = lit_enr_tva($cocl_codetva, TRUE);
            if (is_array($row)) {
                $row = encode_str($row);
                extract($row);
            }

            echo $tva_desc . " (" . full_num_format($tva_tx, '', '', FALSE, '', TRUE, TRUE) . "%)";
            echo '</td>';
            echo '</tr>';
            // Prix TTC
            echo '<tr>';
            echo '<td align="right">';
            echo _("PV TTC") . ' : ';
            echo '</td>';
            echo '<td>';
            $txtva = $tva_tx / 100;
            $pvttc = round(($cocl_pvht * (1 + $txtva)) * 100) / 100;
            echo full_num_format($pvttc, '', '', TRUE, '', TRUE, TRUE);
            echo '</td>';
            echo '</tr>';
            echo '</table>';
            echo '<br /><br />';
            echo '<div align="center" class="titrerubrique3" style="font-size: 14px;">';
            echo _("HISTORIQUE");
            echo '</div>';
            echo '<br /><br />';

            // Détail des interventions

            $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
            // On construit la liste des interventions
            $rech = cree_strrechlstcoclh();
            $rech .= crestr_triord($coclh_titre_col, "int_code", FALSE, $limit);

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

            if (($rows) AND (count($rows) > 0)) {
                $offert = FALSE;
                $indice = FALSE;

                // Titres
                echo '<table border="0" width="100%">';
                echo '<tr class="annot_petit_gras" style="background-color:#000000;color:#FFFFFF;">';
                echo '<td align="center">';
                echo _("Intervention");
                echo '</td>';
                echo '<td align="center">';
                echo _("Saisie le");
                echo '</td>';
                echo '<td align="center">';
                echo _("Fin le");
                echo '</td>';
                echo '<td align="center">';
                echo _("Agence");
                echo '</td>';
                echo '<td align="center">';
                echo _("Statut");
                echo '</td>';
                echo '<td align="center">';
                echo _("Durée");
                echo '</td>';
                echo '<td align="center">';
                echo _("Retenu");
                echo '</td>';
                echo '</tr>';

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

                    $tab_inth = cre_tab_inth_int($row["int_code"],FALSE);
                    //echo $row["int_code"].' : ';print_r($tab_inth);echo '<br>';
                    // Affichage résumé Contrat Client

                    // Récupération du total travaillé
                    $tpstotalsec = 0;
                    $tpsoffsec = 0;
                    $tpsretsec = 0;

                    $rech2 = "SELECT * FROM `" . TBINTH . "` WHERE `inth_codeint`= '" . $row["int_code"] . "'";
                    $rows2 = $db->get_results($rech2, ARRAY_A);
                    if (($rows2) AND (count($rows2) > 0)) {
                        foreach ($rows2 as $row2) {
                            $row2 = encode_str($row2);
                            $tpspassesec = diff_time_sec($row2["inth_heurea"], $row2["inth_heured"]);
                            // Calcul du temps réellement passé
                            $tpstotalsec = $tpstotalsec + $tpspassesec;
                            // C'est du temps offert ?
                            // Oui : on ajoute juste au temps total offert
                            // Non : on ajoute au temps total retenu
                            if ($row2["inth_offert"] == 1) {
                                // Calcul du temps offert
                                $tpsoffsec = $tpsoffsec + $tpspassesec;
                                $offert = TRUE;
                            } else {
                                // Calcul du temps retenu
                                $ind_coeff = 1;
                                if ($row2["inth_codeind"] == "-1")
                                    $tpsretsec = $tpsretsec + $tpspassesec;
                                else {
                                    $indice = TRUE;
                                    $row3 = lit_enr_ind($row2["inth_codeind"], FALSE);
                                    if (is_array($row3)) {
                                        $row3 = encode_str($row3);
                                        extract($row3);
                                        $tpsretsec = $tpsretsec + ($tpspassesec * $ind_coeff);
                                    }
                                }
                            }
                        }
                    }

                    /*
                    // Si un utilisateur a quitté avant de sauver (bien qu'ayant modifié le détail horaire),
                    // on remet en état car seul le détail horaire et technicien enregistré est valable
                    if ($row["int_durees"] <> $tpsretsec) {
                        $rech2 = "UPDATE `" . TBINT . "` SET `int_datemod`='" . $datea . "', `int_codemod`='" . $codeuser . "',`int_durees`='" . $tpsretsec . "'";
                        $rech2 .= " WHERE `int_code` = '" . $db->escape($ci) . "'";
                        $db->query($rech2);
                        $row["int_durees"] = $tpsretsec;
                    }
                    */

                    echo "<td align=\"center\">";
                    echo $row["int_code"];
                    // Date demande
                    echo "</td>";
                    echo "<td align=\"center\">";
                    echo datetolocal($row["int_datedde"]);
                    echo "</td>";
                    //Date Fin
                    echo "<td align=\"center\">";
                    if (datetolocal($row["int_datefin"]) <> "")
                        echo datetolocal($row["int_datefin"]);
                    else
                        echo "-";
                    echo "</td>";
                    // Agence
                    echo "<td align=\"center\">" . $row["int_codeage"] . "</td>";
                    // Statut
                    echo "<td align=\"center\">";
                    $txtstatut = $row["int_codestatut"];
                    $rech2 = "SELECT statut_desc FROM `" . TBSTA . "` WHERE statut_code = '".$row["int_codestatut"]."'";
                    $row2 = $db->get_row($rech2, ARRAY_A);
                    if ($row2) {
                        $row2 = encode_str($row2);
                        extract($row2);
                        $txtstatut = $statut_desc;
                    }
                    echo $txtstatut;
                    echo "</td>";

                    echo "<td align=\"center\">";
                    echo "&nbsp;";
                    echo "</td>";
                    echo "<td align=\"center\">";
                    echo "&nbsp;";
                    echo "</td>";

                    echo "</tr>";

                    // Détail
                    $exist_offert = FALSE;
                    if (count($tab_inth) > 0)
                    {
                        foreach ($tab_inth as $tab_detail)
                        {
                            echo '<tr class="annot_petit_it">';
                            echo '<td align="right" colspan="5">';
                            echo $tab_detail['txt'];
                            echo '</td>';
                            echo '<td align="center">';
                            echo heure_to_hhmm(sec_heure($tab_detail['duree']));
                            echo '</td>';
                            echo '<td align="center">';
                            echo heure_to_hhmm(sec_heure($tab_detail['dureeret']));
                            //echo '00:00*';
                            echo '</td>';
                            echo "</tr>";
                        }
                    }

                    // Sous-total par intervention
                    echo '<tr class="annot_petit_gras">';
                    echo '<td align="right" colspan="5">';
                    echo _("Sous-total") . ' ' . $row["int_code"];
                    echo '</td>';
                    echo "<td align=\"center\">";
                    if ($tpstotalsec <> 0)
                        echo heure_to_hhmm(sec_heure($tpstotalsec, 3, TRUE));
                    else
                        echo "-";
                    echo "</td>";

                    echo "<td align=\"center\">";
                    if ($tpsretsec <> 0)
                        echo heure_to_hhmm(sec_heure($tpsretsec, 3, TRUE));
                    else
                        echo "-";
                    echo "</td>";

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

                    $i++;
                }
                echo '</table>';
            } else
                echo _("Aucun historique interventions sur ce contrat") ;

            /*
            if ($rows) {

                $nlig = 0;
                $idcurr = 0;
                $total_travail_site_sec = 0;
                $total_travail_site_sec_ret = 0;
                foreach ($rows as $row) {
                    $row = encode_str($row);
                    extract($row);
                    // On teste si sous-total à afficher par site
                    if ($nlig <> 0) {
                        if ($int_idsite <> $idcurr) {
                            // Texte du temps de travail général
                            $txttps = "";
                            if ($total_travail_site_sec <> 0)
                                $txttps .= heure_to_hhmm(sec_heure($total_travail_site_sec, 3, TRUE));
                            else
                                $txttps .= "-";

                            // Texte du temps de travail retenu pour sous-total
                            $txttps_ret = "";
                            if ($total_travail_site_sec_ret <> 0)
                                $txttps_ret .= heure_to_hhmm(sec_heure($total_travail_site_sec_ret, 3, TRUE));
                            else
                                $txttps_ret = "-";

                            echo '<tr class="annot_petit_itgras" style="background-color:grey;">';
                            echo '<td align="right" colspan="5">';
                            echo _("Sous-total par site") . ' : ';
                            echo '</td>';
                            echo '<td align="center">';
                            echo $txttps;
                            echo '</td>';
                            echo '<td align="center">';
                            echo $txttps_ret;
                            echo '</td>';
                            echo '</tr>';

                            $total_travail_site_sec = 0;
                            $total_travail_site_sec_ret = 0;
                        }
                    }

                    $idcurr = $int_idsite;

                    $total_travail_int_sec = 0;
                    $total_travail_int_sec_ret = 0;
                    $total_offert_int_sec = 0;

                    // Ligne "Intervention"
                    echo '<tr class="annot_petit_gras">';
                    echo '<td>';
                    echo $int_code;
                    echo '</td>';
                    echo '<td align="center">';
                    echo datetolocal($int_datedde);
                    echo '</td>';
                    echo '<td align="center">';
                    if (datetolocal($int_datefin) <> "")
                        echo datetolocal($int_datefin);
                    else
                        echo "-";
                    echo '</td>';
                    echo '<td align="center">';
                    echo $int_codeage;
                    echo '</td>';

                    echo '<td align="center" colspan="2">';
                    echo '&nbsp;';
                    echo '</td>';
                    echo '</tr>';
                    if (intval($int_idsite) <> -1) {
                        echo '<tr class="annot_petit_it">';
                        echo '<td style="padding-left:10px;" colspan="7">';
                        echo nom_scli($int_idsite, FALSE, FALSE, FALSE);
                        echo '</td>';
                        echo '</tr>';
                    }

                    // lignes de détail
                    $rech2 = "SELECT inth_date, inth_heurea, inth_heured, inth_offert, inth_codeind";
                    $rech2 .= " FROM `" . TBINTH . "`";
                    $rech2 .= " WHERE inth_codeint = '" . $int_code . "'";
                    $rech2 .= " ORDER BY inth_date, inth_heurea";

                    $rows2 = $db->get_results($rech2, ARRAY_A);

                    if (($rows2) AND (count($rows2) > 0)) {
                        foreach ($rows2 as $row2) {
                            $row2 = encode_str($row2);
                            echo '<tr class="annot_petit">';
                            echo '<td align="right" colspan="5">';
                            $txtinth = "";
                            extract($row2);
                            $txtinth = _("Le") . ' ' . datetolocal($inth_date) . ' ' . _("de") . ' ' . substr($inth_heurea, 0, 5) . ' ' . _("à") . ' ' . substr($inth_heured, 0, 5);
                            $ind_coeff = 1;
                            if (intval($inth_codeind) <> -1) {
                                $rech3 = "SELECT ind_coeff,ind_desc FROM `" . TBIND . "` WHERE ind_code = '" . $inth_codeind . "'";
                                $row3 = $db->get_row($rech3, ARRAY_A);
                                if ($row3) {
                                    $row3 = encode_str($row3);
                                    extract($row3);
                                    $txtinth .= ' (' . $ind_desc . ')';
                                }
                            }
                            echo $txtinth;
                            $duree_sec = heure_sec($inth_heured) - heure_sec($inth_heurea);
                            $duree_hhmm = heure_to_hhmm(sec_heure($duree_sec));

                            $duree_sec_ret = $duree_sec * $ind_coeff;
                            $duree_hhmm_ret = heure_to_hhmm(sec_heure($duree_sec_ret));

                            echo '</td>';
                            if (intval($inth_offert) == 1) {
                                $exist_offert = TRUE;
                                echo '<td align="center">';
                                echo $duree_hhmm;
                                echo '</td>';
                                echo '<td align="center">';
                                echo '00:00*';
                                echo '</td>';

                                // MAJ du total temps travaillé pour cette intervention
                                $total_offert_int_sec += $duree_sec;
                            } else {
                                echo '<td align="center">';
                                echo $duree_hhmm;
                                echo '</td>';
                                echo '<td align="center">';
                                echo $duree_hhmm_ret;
                                echo '</td>';
                            }
                            echo '</tr>';

                            // MAJ des temps travaillés et retenus pour cette intervention
                            $total_travail_int_sec += $duree_sec;
                            if (intval($inth_offert) == 0)
                                $total_travail_int_sec_ret += $duree_sec_ret;
                        }
                    }

                    // Ligne de total

                    // Texte du temps de travail physique pour le sous-total par intervention
                    $txttps = "";
                    if ($total_travail_int_sec <> 0)
                        $txttps .= heure_to_hhmm(sec_heure($total_travail_int_sec, 3, TRUE));
                    else
                        $txttps .= "-";
                    $total_travail_site_sec += $total_travail_int_sec;

                    // Texte du temps de travail retenu pour le sous-total par intervention
                    $txttps_ret = "";
                    if ($total_travail_int_sec_ret <> 0)
                        $txttps_ret .= heure_to_hhmm(sec_heure($total_travail_int_sec_ret, 3, TRUE));
                    else
                        $txttps_ret = "-";
                    $total_travail_site_sec_ret += $total_travail_int_sec_ret;

                    // Affiche du sous-total
                    echo '<tr class="annot_petit_it">';
                    echo '<td align="right" colspan="5">';
                    echo _("Sous-total") . ' ' . $int_code;
                    echo '</td>';
                    echo '<td align="center">';
                    echo $txttps;;
                    echo '</td>';
                    echo '<td align="center">';
                    echo $txttps_ret;
                    echo '</td>';

                    // On met à jour le total général
                    $total_travail_con_sec += $total_travail_int_sec;
                    $total_travail_con_sec_ret += $total_travail_int_sec_ret;
                    $total_offert_con_sec += $total_offert_int_sec;

                    echo '</tr>';

                    $nlig++;
                }

                // Dernière ligne de sous-total par site
                $txttps = "";
                if ($total_travail_site_sec <> 0)
                    $txttps .= heure_to_hhmm(sec_heure($total_travail_site_sec, 3, TRUE));
                else
                    $txttps .= "-";

                // Texte du temps de travail retenu pour sous-total
                $txttps_ret = "";
                if ($total_travail_site_sec_ret <> 0)
                    $txttps_ret .= heure_to_hhmm(sec_heure($total_travail_site_sec_ret, 3, TRUE));
                else
                    $txttps_ret = "-";

                echo '<tr class="annot_petit_itgras" style="background-color:grey;">';
                echo '<td align="right" colspan="5">';
                echo _("Sous-total par site") . ' : ';
                echo '</td>';
                echo '<td align="center">';
                echo $txttps;
                echo '</td>';
                echo '<td align="center">';
                echo $txttps_ret;
                echo '</td>';
                echo '</tr>';

                // Totaux

                // Texte du temps de travail général
                $txttps = "";
                if ($total_travail_con_sec <> 0)
                    $txttps .= heure_to_hhmm(sec_heure($total_travail_con_sec, 3, TRUE));
                else
                    $txttps .= "-";

                // Texte du temps de travail retenu pour total général
                $txttps_ret = "";
                if ($total_travail_con_sec_ret <> 0)
                    $txttps_ret .= heure_to_hhmm(sec_heure($total_travail_con_sec_ret, 3, TRUE));
                else
                    $txttps_ret = "-";

                echo '<tr class="annot_petit_itgras">';
                echo '<td align="right" colspan="5">';
                echo _("Total général") . ' : ';
                echo '</td>';
                echo '<td align="center">';
                echo $txttps;
                echo '</td>';
                echo '<td align="center">';
                echo $txttps_ret;
                echo '</td>';
                echo '</tr>';

                if ($total_offert_con_sec <> 0) {
                    echo '<tr class="annot_petit_itgras">';
                    echo '<td align="right" colspan="5">';
                    echo _("Dont offert") . ' : ';
                    echo '</td>';
                    echo '<td align="center">';
                    echo heure_to_hhmm(sec_heure($total_offert_con_sec, 3, TRUE));
                    echo '</td>';
                    echo '<td align="center">';
                    echo '&nbsp;';
                    echo '</td>';
                    echo '</tr>';
                }
                echo '</table>';

                // Si existe temps offert
                if ($exist_offert == TRUE) {
                    echo '<div class="annot_upetit_it">';
                    echo '*' . _("Temps offert");
                    echo '</div>';
                }
            } else
                echo _("Aucun historique pour ce contrat");
            */
            $db->disconnect();
        }
    } else
        $pbm_cocl = TRUE;

}
?>
</body>
</html>