<?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/config.inc.php");
include_once("../inc/fic_droits.inc.php");
include_once("../inc/func.inc.php");
include_once("../inc/func_date.inc.php");
include_once("../inc/func_log.inc.php");
include_once("../inc/func_geo.inc.php");
include_once("../inc/func_txt.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"]);
$titre = "RECEPTION ANNEXE CONTRAT SIGNEE";
?>
<!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 _("Accusé réception annexe contrat"); ?></title>

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

    <script language="javascript">
        <!--
        var tab1_champ = ["nom:codecocl ; format:liste ; req:Y ; txt:<?PHP echo _("Annexe non encore signée"); ?> ; stok:frmok ; stbad:frmbad",
            "nom:signataire ; format:txt ; req:Y ; txt:<?PHP echo _("Signé par"); ?> ; lmx:70 ; stok:frmok ; stbad:frmbad"];
        //-->
    </script>

    <script type="text/javascript">
        <!--
        function init_datepicker() {
            $.datepicker.setDefaults({
                closeText: "<?PHP echo _("Fermer"); ?>",
                prevText: "<?PHP echo _("Précédent"); ?>",
                nextText: "<?PHP echo _("Suivant"); ?>",
                currentText: "<?PHP echo _("Aujourd'hui"); ?>",
                monthNames: ["<?PHP echo implode('","',$lng_tmoisf); ?>"],
                monthNamesShort: ["<?PHP echo implode('","',$lng_tmoism); ?>"],
                dayNames: ["<?PHP echo implode('","',$lng_tjourf); ?>"],
                dayNamesShort: ["<?PHP echo implode('","',$lng_tjourm); ?>"],
                dayNamesMin: ["<?PHP echo implode('","',$lng_tjours); ?>"],
                weekHeader: "<?PHP echo _("Sem."); ?>",
                dateFormat: "<?PHP echo $_SESSION['date_fmtshort']; ?>",
                firstDay: 1,
                isRTL: !1,
                changeMonth: true,
                changeYear: true,
                showMonthAfterYear: !1,
                yearSuffix: "",
                showButtonPanel: true,
                showOn: "both",
                buttonImageOnly: true,
                buttonImage: "../img/calendar.png",
                buttonText: "<?PHP echo _("Calendrier"); ?>"
            });
            $("#datesigf").datepicker({
                onSelect: function () {
                    $("#datesigf").blur();
                }
            });
        }

        function init_all() {
            init_Body();
            init_datepicker();
            <?PHP
            echo "init_valid_form('enr','coclreca_maj','".$_SESSION['date_fmtshort']."',tab1_champ,'','');";
            ?>
            init_autoraz('razdatesigf', 'datesigf', 'click');
            init_back('annul', 'click');
            Focus_first();
        }

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

</head>

<body>

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

<p align="center"><span class="titrepage"><?PHP echo $titre ?></span></p>

<form name="coclreca_maj" id="coclreca_maj" method="post" action="coclreca_enr.php">
    <input name="titre" type="hidden" id="titre" value="<?PHP echo $titre ?>">
    <input name="nbutton" type="hidden" id="nbutton" value="">
    <?PHP
    $rien_a_receptionner = TRUE;

    // création de la liste des contrats non terminés, envoyés et non reçus
    $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
    $rech = "SELECT * FROM `" . TBCOCL . "`, `" . TBCOCLA . "` WHERE " . TBCOCL . ".cocl_datefin = '0000-00-00' AND " . TBCOCLA . ".cocla_dateenv <> '0000-00-00' AND " . TBCOCLA . ".cocla_daterec = '0000-00-00'";
    $rech .= " AND " . TBCOCL . ".cocl_code = " . TBCOCLA . ".cocla_codecocl";
    if ((@$_SESSION["niv_log"] == 4) OR (@$_SESSION["niv_log"] == 3))
        $rech .= " AND " . TBCOCL . ".cocl_codeage = '" . @$_SESSION["code_age"] . "'";
    $rech .= " ORDER BY " . TBCOCL . ".cocl_code DESC";

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

    if (($rows) AND (count($rows) > 0))
    {
    $rien_a_receptionner = FALSE;
    ?>
    <table width="360" border="0" cellspacing="0" cellpadding="0" align="center">
        <tr>
            <td class="rubfrm" id="f_codecocl">
                <div align="center"><?PHP echo _("Choisissez une annexe non encore signée"); ?> :</div>
            </td>
        </tr>
        <tr>
            <td>
                <div align="center">
                    <?PHP
                    /*
                    echo '<select name="codecocl" id="codecocl">';
                    echo '<option value="">-- Choisissez une annexe --</option>';

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

                        $rech2 = "SELECT cli_ste,cli_nom FROM `" . TBCLI . "` WHERE `cli_code` = '" . $cocl_codecli . "'";
                        $row2 = $db->get_row($rech2);

                        if ($row2)
                            extract($row2);
                        $texte = $cocl_code . "-" . $cocla_code . " - ";
                        if ($cli_ste <> "")
                            $texte .= $cli_ste;
                        else
                            $texte .= $cli_nom;
                        $texte .= ' ('._("envoyée le").' '  . datetolocal($cocla_dateenv) . ")";
                        echo "<option value=\"" . $cocla_id . "\">" . $texte . "</option>";
                    }
                    echo '</select>';
                    */
                    $tab_cocl = [];
                    foreach ($rows as $row) {
                        $row = encode_str($row);
                        extract($row);

                        $rech2 = "SELECT cli_ste,cli_nom FROM `" . TBCLI . "` WHERE `cli_code` = '" . $cocl_codecli . "'";
                        $row2 = $db->get_row($rech2, ARRAY_A);

                        if ($row2) {
                            $row2 = encode_str($row2);
                            extract($row2);
                        }

                        $texte = $cocl_code . " - " . $cocla_code . " - ";
                        if ($cli_ste <> "")
                            $texte .= $cli_ste;
                        else
                            $texte .= $cli_nom;
                        $texte .= " ("._("envoyée le")." " . datetolocal($cocla_dateenv) . ")";
                        $tab_cocl[$cocla_id] = $texte;
                    }
                    cre_select('codecocl', 'codecocl', $tab_cocl, '', '', _("-- Faites votre choix --"));
                    ?>
                </div>
            </td>
        </tr>
    </table>
    <br />
    <table width="120" border="0" cellspacing="0" cellpadding="0" align="center">
        <tr>
            <td align="center" class="rubfrm" id="f_datesig">
                <?PHP echo _("Signé le :"); ?>
            </td>
        </tr>
        <tr>
            <td align="center">
                <input name="datesigf" type="text" id="datesigf" value="" size="10" maxlength="10" readonly>
                <img src="../img/raz.png" id="razdatesigf" border="0" align="absmiddle">
            </td>
        </tr>
    </table>
    <br />
    <table width="500" border="0" cellspacing="0" cellpadding="0" align="center">
        <tr>
            <td align="center" class="rubfrm" id="f_signataire">
                <?PHP echo _("Signé par :"); ?>
            </td>
        </tr>
        <tr>
            <td align="center">
                <input name="signataire" type="text" id="signataire" value="" size="70" maxlength="70">
            </td>
        </tr>
    </table>
    <p align="center">
        <?PHP
            echo '<input name="enr" type="button" class="bton_std" id="enr" value="'._("Valider").'">';
            echo '<input name="annul" type="button" class="bton_std" id="annul" value="'._("Annuler").'">';
        }
        else {
            echo "<span class=\"annot_gras_it\">";
            echo "<div align=\"center\">";
            echo _("Pas d'annexe de contrat ouverte, envoyée et non reçue");
            echo "</div>";
            echo "</span>";
        }

        $db->disconnect();
        ?>
    </p>
</form>
<?PHP
include_once("pied.php");
?>
</body>
</html>