<?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/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 CONTRAT SIGNE");
?>
<!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 contrat"); ?></title>

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

    <script language="javascript">
        <!--
        var tab1_champ = ["nom:codecocl ; format:liste ; req:Y ; txt:<?PHP echo _("Contrat non encore signé"); ?> ; vmn:1 ; stok:frmok ; stbad:frmbad",
            "nom:datesigf ; format:date ; masque:<?PHP echo $_SESSION['date_fmtfull']; ?> ; req:Y ; txt:<?PHP echo _("Date signature"); ?> ; 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','coclrec_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="coclrec_maj" id="coclrec_maj" method="post" action="coclrec_enr.php">
    <input name="titre" type="hidden" id="titre" value="<?PHP echo $titre ?>">
    <input name="nbutton" type="hidden" id="nbutton" value="">
    <?PHP
    // 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 . "` WHERE `cocl_datefin` = '0000-00-00' AND `cocl_dateenv` <> '0000-00-00' AND `cocl_daterec` = '0000-00-00'";
    if ((@$_SESSION["niv_log"] == 4) OR (@$_SESSION["niv_log"] == 3))
        $rech .= " AND `cocl_codeage`='" . @$_SESSION["code_age"] . "'";
    $rech .= " ORDER BY cocl_code DESC";

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

    if (($rows) AND (count($rows) > 0))
    {
    ?>
    <br />
    <table width="50%" border="0" cellspacing="0" cellpadding="0" align="center">
        <tr>
            <td class="rubfrm" id="f_codecocl">
                <div align="center"><?PHP echo _("Choisissez un contrat non encore signé"); ?> :</div>
            </td>
        </tr>
        <tr>
            <td>
                <div align="center">
                    <?PHP
                    $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 . " - ";
                        if ($cli_ste <> "")
                            $texte .= $cli_ste;
                        else
                            $texte .= $cli_nom;
                        $texte .= " ("._("envoyé le")." " . datetolocal($cocl_dateenv) . ")";
                        $tab_cocl[$cocl_code] = $texte;
                    }
                    cre_select('codecocl', 'codecocl', $tab_cocl, '', '', _("-- Faites votre choix --"));
                    ?>
                </div>
            </td>
        </tr>
        <tr>
            <td colspan="2">&nbsp;</td>
        </tr>
        <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>
        <tr>
            <td colspan="2">&nbsp;</td>
        </tr>
        <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">
                <img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo _("Champ obligatoire"); ?>">
            </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 de contrat ouvert, envoyé et non reçu");
            echo "</div>";
            echo "</span>";
        }

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