<?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_droits.inc.php");
include_once("../inc/func.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("../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 = "RELANCE CONTRAT NON RECU";
?>
    <!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 _("Relance contrat"); ?></title>

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

        <script language="javascript">
            <!--
            var tab1_champ = new Array(
                "nom:codecocl ; format:liste ; req:Y ; txt:<?PHP echo _("Contrat envoyé mais non reçu"); ?> ; vmn:1 ; stok:frmok ; stbad:frmbad");
            //-->
        </script>

        <script type="text/javascript">
            <!--
            function init_all() {
                init_Body();
                <?PHP
                echo "init_valid_form('enr','coclrel_maj','".$_SESSION['date_fmtshort']."',tab1_champ,'','');";
                ?>
                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="coclrel_maj" id="coclrel_maj" method="post" action="coclrel_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);
        if ((@$_SESSION["niv_log"] == 4) OR (@$_SESSION["niv_log"] == 3))
            $rech = "SELECT * FROM `" . TBCOCL . "` WHERE `cocl_datefin` = '0000-00-00' AND `cocl_dateenv` <> '0000-00-00' AND `cocl_daterec` = '0000-00-00' AND `cocl_codeage`='" . @$_SESSION["code_age"] . "' ORDER BY cocl_code DESC";
        else
            $rech = "SELECT * FROM `" . TBCOCL . "` WHERE `cocl_datefin` = '0000-00-00' AND `cocl_dateenv` <> '0000-00-00' AND `cocl_daterec` = '0000-00-00' ORDER BY cocl_code DESC";

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

        if (($rows) AND (count($rows) > 0))
        {
        ?>
        <br />
        <table width="360" border="0" cellspacing="0" cellpadding="0" align="center">
            <tr>
                <td class="rubfrm" id="f_codecocl">
                    <div align="center"><?PHP echo _("Choisissez un contrat envoyé mais non reçu"); ?> :</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);
                            if (datetolocal($cocl_daterel) <> "")
                                $texte .= ', '._("relancé le"). ' ' . datetolocal($cocl_daterel);
                            $texte .= ")";
                            $tab_cocl[$cocl_code] = $texte;
                        }
                        cre_select('codecocl', 'codecocl', $tab_cocl, '', '', _("-- Faites votre choix --"));
                        ?>
                    </div>
                </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 signé");
                echo "</div>";
                echo "</span>";
            }

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