<?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/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/fic_cli.inc.php");
include_once("../inc/fic_co.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/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);

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

$contrat_ok = TRUE;

if ($codecocl <> "") {
    // Récupération des informations client
    $row = lit_enr_cocl($codecocl);
    if (is_array($row)) {
        $row = encode_str($row);
        extract($row);

        if (CheckNivLog("1-3-4-5-9") == TRUE) {
            if (CheckNivLog("3-4") == TRUE) {
                if ($cocl_codeage <> @$_SESSION["code_age"])
                    $contrat_ok = FALSE;
            }

            if (CheckNivLog("1") == TRUE) {
                if ($cocl_codecli <> @$_SESSION["code_log"])
                    $contrat_ok = FALSE;
            }
        } else
            $contrat_ok = FALSE;
    } else
        $contrat_ok = FALSE;
} else
    $contrat_ok = FALSE;
?>

<!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 _("Résumé contrat"); ?></title>

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

    <script type="text/javascript">
        <!--
        function init_all() {
            init_Body();
            init_Tabs('onglets_rescocl');
            add_func_click('ferm', 'sclose', '');
            add_func_click('ferm2', 'sclose', '');
            Focus_first();
        }

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

</head>

<body>
<?PHP
if ($contrat_ok == TRUE) {
    $cocl_datecreaf = datetolocal($cocl_datecrea);
    $cocl_datemodf = datetolocal($cocl_datemod);
    $cocl_dateenvf = datetolocal($cocl_dateenv);
    $cocl_daterecf = datetolocal($cocl_daterec);
    $cocl_datesigf = datetolocal($cocl_datesig);
    $cocl_datedf = datetolocal($cocl_dated);
    $cocl_dateff = datetolocal($cocl_datef);
    $cocl_daterelf = datetolocal($cocl_daterel);
    $cocl_datefinf = datetolocal($cocl_datefin);

    $nbh = sec_heure($cocl_nbs, 3, TRUE);
    $soldeh = sec_heure(solde_contrat_sec($codecocl, TRUE), 3, TRUE);
    ?>

    <p align="center"><span class="titrepage"><?PHP echo _("RESUME CONTRAT"); ?></span></p>

    <table width="100%" border="0">
        <tr>
            <td width="33%" align="left">&nbsp;</td>
            <td width="33%" align="center"><span class="titre_gras"><?PHP echo _("Numéro"); ?> <?php echo $codecocl; ?></span></td>
            <td width="33%" align="right"><input name="ferm" type="button" class="bton_std" id="ferm"  value="<?PHP echo _("Quitter"); ?>"></td>
        </tr>
    </table>

    <div id="onglets_rescocl">
        <ul>
            <li><a href="#rescocl_data"><?PHP echo _("Données du contrat"); ?></a></li>
            <li><a href="#rescocl_sclic"><?PHP echo _("Sites couverts"); ?></a></li>
        </ul>
        <div id="rescocl_data">
        <!-- Date de création -->
        <table width="100%" border="0">
            <tr>
                <td width="160" class="rubfrm" id="f_datecreaf" align="right"><?PHP echo _("Date Création"); ?> </td>
                <td>
                    <input name="datecreaf" type="text" id="datecreaf" value="<?PHP echo $cocl_datecreaf ?>" size="10"
                           maxlength="10" readonly>
                </td>
            </tr>
        </table>

        <!-- Type de contrat -->
        <table width="100%" border="0">
            <tr>
                <td width="160" class="rubfrm" id="f_co" align="right"><?PHP echo _("Contrat Type"); ?></td>
                <td>
                    <?PHP
                    $row = lit_enr_co($cocl_codeco);
                    if ($row) {
                        $row = encode_str($row);
                        extract($row);
                    }
                    ?>
                    <input name="nomco" type="text" id="nomco" value="<?PHP echo $co_nom ?>" size="50" readonly>
                </td>
            </tr>
        </table>

        <!-- périodicité du contrat -->
        <table width="100%" border="0">
            <tr>
                <td width="160" class="rubfrm" id="f_cope" align="right"><?PHP echo _("Fréquence"); ?></td>
                <td>
                    <?PHP
                    $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
                    $rech = "SELECT * FROM `" . TBPER . "` WHERE `per_code` = '" . $cocl_codeper . "'";
                    $row = $db->get_row($rech, ARRAY_A);
                    if ($row) {
                        $row = encode_str($row);
                        extract($row);
                    }
                    $db->disconnect();
                    ?>
                    <input name="tcope" type="text" id="tcope" value="<?PHP echo $per_desc ?>" size="20" readonly>
                </td>
            </tr>
        </table>

        <!-- Délai d'intervention -->
        <table width="100%" border="0">
            <tr>
                <td width="160" class="rubfrm" id="f_delai" align="right">
                    <?PHP echo _("Délai Interv."); ?>
                </td>
                <td>
                    <input name="delai" type="text" id="delai" value="<?PHP echo $cocl_delai ?>" size="2" maxlength="2"
                           align="right" readonly>
                    <span class="annot_petit_it"><?PHP echo _("heures ouvrées"); ?></span>
                </td>
            </tr>
        </table>

        <!-- Nombre d'heures par contrat -->
        <table width="100%" border="0">
            <tr>
                <td width="160" class="rubfrm" id="f_nbheures" align="right"><?PHP echo _("Nb heures"); ?></td>
                <td>
                    <input name="nbh" type="text" id="nbh" value="<?PHP echo heure_to_hhmm($nbh); ?>" size="6" maxlength="6"
                           readonly>
                    <span class="annot_std_gras">,</span>
                    <input name="typh" type="text" id="typh" value="<?PHP echo $typ_horaire[$cocl_typh]; ?>" size="20"
                           maxlength="20" readonly>
                    <?PHP
                    if ($cocl_typh == 1) {
                        ?>
                        <span class="annot_std_it"><?PHP echo _("Solde"); ?> :</span>
                        <input name="soldeh" type="text" id="soldeh" value="<?PHP echo heure_to_hhmm($soldeh); ?>" size="6"
                               maxlength="6" readonly>
                        <span class="annot_std_it"> <span class="annot_petit_it">(<?PHP echo _("Heures à sortir"); ?>
                                : <?PHP echo heure_to_hhmm(sec_heure(tps_trav_non_clot_sec($cocl_code, TRUE), 3, TRUE)); ?></span>)</span>

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

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

                        if ($rows) {
                            echo "<table class=\"MtableD\" border=\"0\" width=\"600\" cellpadding=\"0\" cellspacing=\"0\">\n";

                            // création de l'entête de la table "détails reports"
                            echo "<th>";
                            echo _("Détails des reports affectés à ce contrat");
                            echo "</th>\n";
                            echo "<th>";
                            echo _("Durée");
                            echo "</th>\n";

                            $j = 0;

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

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

                                echo "<td>\n";
                                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 $txt;
                                echo "</td>\n";

                                echo "<td align=\"center\">\n";
                                echo heure_to_hhmm(sec_heure($coclr_nbsrep, 3, TRUE));
                                echo "</td>\n";

                                echo "</tr>\n";

                                $j++;
                            }

                            echo "</table>\n";
                            // Fin affichage table détails reports
                        }

                        // création de la liste des reports affectés depuis ce contrat (s'il y en a)
                        $rech = "SELECT * FROM `" . TBCOCLR . "` WHERE coclr_coclori = '" . $db->escape($codecocl) . "' ORDER BY coclr_codeint";
                        $rows = $db->get_results($rech, ARRAY_A);

                        if ($rows) {
                            echo "<table class=\"MtableD\" border=\"0\" width=\"600\" cellpadding=\"0\" cellspacing=\"0\">\n";

                            // création de l'entête de la table "détails reports"
                            echo "<th>";
                            echo _("Détails des reports affectés depuis ce contrat");
                            echo "</th>\n";
                            echo "<th>";
                            echo _("Durée");
                            echo "</th>\n";

                            $j = 0;

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

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

                                echo "<td>\n";
                                if ($coclr_nbsrep > 0)
                                    $txt = _("Report non consommé vers contrat");
                                else
                                    $txt = _("Déduction sur-consommé vers contrat");
                                $txt .= " " . $coclr_cocldest;
                                if ($coclr_codeint <> '')
                                    $txt .= " (" . _("Intervention") . " " . $coclr_codeint . ")";
                                else
                                    $txt .= " (" . _("Clôture manuelle") . " ";
                                echo $txt;
                                echo "</td>\n";

                                echo "<td align=\"center\">\n";
                                echo heure_to_hhmm(sec_heure($coclr_nbsrep, 3, TRUE));
                                echo "</td>\n";

                                echo "</tr>\n";

                                $j++;
                            }

                            echo "</table>\n";
                            // Fin affichage table détails reports
                        }
                        $db->disconnect();
                    }
                    ?>
            </tr>
        </table>

        <!-- Dates de "vie" du contrat -->
        <table width="100%" border="0">
            <tr>
                <td width="160" class="rubfrm" id="f_validite" align="right"><?PHP echo _("Validité"); ?></td>
                <td>
                    <span class="annot_petit_gras"><?PHP echo _("Du"); ?></span>
                    <input name="datedf" type="text" id="datedf" value="<?PHP echo $cocl_datedf ?>" size="10" maxlength="10"
                           readonly>
                    <span class="annot_petit_gras"><?PHP echo _("au"); ?></span>
                    <input name="dateff" type="text" id="dateff" value="<?PHP echo $cocl_dateff ?>" size="10" maxlength="10"
                           readonly>
                </td>
            </tr>
        </table>

        <!-- Nombre de jours de préavis -->
        <table width="100%" border="0">
            <tr>
                <td width="160" class="rubfrm" id="f_preavis" align="right"><?PHP echo _("Préavis"); ?></td>
                <td>
                    <input name="preavis" type="text" id="preavis" value="<?PHP echo $cocl_preavis ?>" size="3"
                           maxlength="3" align="right" readonly>
                    <span class="annot_std_gras"><?PHP echo _("jours avant date d'échéance"); ?></span>
                </td>
            </tr>
        </table>

        <!-- détail matériel concerné -->
        <table width="100%" border="0">
            <tr>
                <td width="160" valign="top" class="rubfrm" id="f_matos"
                    align="right"><?PHP echo _("Matériel Concerné"); ?></td>
                <td>
                    <textarea name="matos" rows="20" id="matos" readonly><?PHP echo $cocl_matos ?></textarea>
                </td>
            </tr>
        </table>
    </div>

    <div id="rescocl_sclic">
        <!-- Sites couverts -->
        <?PHP
        // création de la liste des sites secondaires
        $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);

        // vérification si site principal couvert
        $sitep = FALSE;
        $rech = "SELECT cocl_sitep FROM `" . TBCOCL . "` WHERE `cocl_code`= '" . $db->escape($codecocl) . "'";
        $row = $db->get_row($rech, ARRAY_A);

        if ($row) {
            if ($row["cocl_sitep"] == 1)
                $sitep = TRUE;
        }

        $db->disconnect();

        // On vérifie la liste des sites possibles pour ce contrat
        $tab_sites = [];
        $lstsites = cree_str_lstsites_cocl($codecocl);

        if (trim($lstsites) <> '')
            $tab_sites = explode("-", $lstsites);

        // Affichage de la liste
        if ((count($tab_sites) > 0) OR ($sitep == TRUE)) {
            echo "<table class=\"MtableD\" border=\"0\" width=\"850\" cellpadding=\"0\" cellspacing=\"0\" align=\"center\">\n";

            // création de l'entête de la table "sites d'intervention"
            echo "<th>";
            echo _("Coordonnées");
            echo "</th>\n";

            $j = 0;

            if ($sitep == TRUE) {
                // création de l'entête de ligne (TR)
                creetrlstdet($j);

                echo "<td>\n";
                echo _("Site principal");
                echo "</td>\n";

                echo "</tr>\n";

                $j++;
            }

            if (count($tab_sites)>0) {
                foreach ($tab_sites as $value)
                {
                    // création de l'entête de ligne (TR)
                    creetrlstdet($j);

                    echo "<td>\n";
                    echo nom_scli($value, TRUE);
                    echo "</td>\n";

                    echo "</tr>\n";

                    $j++;
                }
            }

            echo "</table>\n";
            // Fin affichage table liste sites
        } else {
            echo "<div class=\"annot_std_it\" align=\"center\">";
            echo _("Site principal non couvert");
            echo "<br />" . _("Aucun site secondaire");
            echo "</div>";
        }
    ?>
    </div>
    </div>
    <!-- bouton de fermeture de la fenêtre -->
    <p align="center">
        <input name="ferm2" type="button" class="bton_std" id="ferm2" value="<?PHP echo _("Quitter"); ?>">
    </p>
<?PHP
} else
    close_fen_auto('', '', '');
?>

</body>
</html>
