<?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/fic_int.inc.php");
include_once("../inc/fic_sig.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"]);
// Variables Formulaire
fix_magic_quotes();
$_GET = clean_str($_GET);
$_POST = clean_str($_POST);

$ci = $_GET['ci']; // Récupération code Intervention
$page = intval($_GET['page']); // Récupération du Numéro de page actuel
if ($page <= 0)
    $page = 1;
$idinth = intval($_GET['inth']); // Récupération de l'ID inth
$a_traiter = TRUE;

$pbm_rpbm = FALSE;
$last = 0;

$tab_pbm = explode('-', $_SESSION["pbm_choisis"]);

if (count($tab_pbm) > 0) {
    if ($idinth > 0) {
        $row2 = lit_enr_inth($idinth);
        if (is_array($row2)) {
            $row2 = encode_str($row2);
            extract($row2);
        } else
            $pbm_rpbm = TRUE;

        $row3 = lit_enr_sig_code(1, $ci, $idinth);
        if (is_array($row3)) {
            $row3 = encode_str($row3);
            $pbm_rpbm = TRUE;
        }
    }

    if ($pbm_rpbm == FALSE) {
        if ($ci <> "") {
            $row = lit_enr_int($ci);
            if (is_array($row)) {
                $row = encode_str($row);
                extract($row);
                if (datetolocal($int_datefin) == "") {
                    // On récupère le nombre d'enregistrements
                    $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
                    $rech = "SELECT * FROM `" . TBRPBM . "` WHERE ";
                    $rech .= "(";
                    foreach ($tab_pbm as $value) {
                        $rech .= " `rpbm_id` = " . intval($value) . " OR";
                    }
                    // Suppression du dernier 'OR'
                    $rech = substr($rech, 0, strlen($rech) - 3);
                    $rech .= ")";
                    $rech .= " AND (`rpbm_idinth`= 0 OR `rpbm_idinth`= " . intval($idinth) . ")";
                    $rows = $db->get_results($rech, ARRAY_A);
                    $last = count($rows); // Nombre de résultats à la requête
                    if ($page > $last)
                        $page = 1;

                    // On récupère la liste des problèmes non résolus (et affectés à cette intervention)
                    $rech .= " ORDER BY `rpbm_datecrea`";
                    $rech .= " LIMIT " . ($page - 1) . ",1";
                    $row = $db->get_row($rech, ARRAY_A);
                    if ($row) {
                        $row = encode_str($row);
                        extract($row);
                    }
                    $db->disconnect();

                    $daterpbmf = datetolocal($rpbm_datecrea);
                } else
                    $pbm_rpbm = TRUE;
            } else
                $pbm_rpbm = TRUE;
        } else
            $pbm_rpbm = TRUE;
    }
} else
    $pbm_rpbm = 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 _("Traitement Problèmes"); ?></title>

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

    <script language="javascript">
        <!--
        var tab1_champ = new Array(
            "nom:fait ; format:txt ; req:N ; txt:<?PHP echo _("Travail effectué"); ?> ; stok:frmok ; stbad:frmbad");
        //-->
    </script>

    <script type="text/javascript">
        <!--
        function init_all() {
            init_Body();
            <?PHP
            $txtfait = str_replace("'","\'",cre_str_pbmfait_int($_SESSION["pbm_faits"]));
            echo "update_fait_pbm(true,'travail','".$txtfait."','');";
            ?>
            init_valid_form('enr','rpbmtt_maj','<?PHP echo $_SESSION['date_fmtshort']; ?>',tab1_champ,'','');
            add_func_click('quit', 'sclose', '');
            Focus_first();
        }

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

<body>
<?PHP
if ($pbm_rpbm == FALSE) {
    ?>
    <p align="center"><span class="titrepage"><?PHP echo _("LISTE DES PROBLEMES AFFECTES"); ?></span></p>
    <p align="center"><?PHP echo _("Merci de détailler les solutions apportées aux les problèmes affectés à l'intervention"); ?>
        <span class="annot_std_gras"><?PHP echo $ci; ?></span></p>
    <p align="center"
       class="annot_gras_it"><?PHP echo _("ATTENTION : après validation définitive, la zone 'travail effectué' sera réinitialisée avec les nouvelles valeurs"); ?></p>
    <form name="rpbmtt_maj" id="rpbmtt_maj" method="post" action="rpbmtt_enr.php">
        <input name="ci" type="hidden" id="ci" value="<?PHP echo $ci; ?>">
        <input name="page" type="hidden" id="page" value="<?PHP echo $page; ?>">
        <input name="urlcour" type="hidden" id="urlcour" value="<?PHP echo $racine_web . $_SERVER['REQUEST_URI']; ?>">
        <input name="nrpbm" type="hidden" id="nrpbm" value="<?PHP echo $rpbm_id; ?>">
        <input name="idinth" type="hidden" id="idinth" value="<?PHP echo $idinth; ?>">
        <input name="nbutton" type="hidden" id="nbutton" value="">
        <table width="100%" border="0" align="center">
            <tr>
                <td width="33%">
                    <?PHP
                    echo ($page) . " / " . $last;
                    ?>
                </td>
                <?PHP
                $url_deb = $_SERVER["PHP_SELF"] . "?ci=" . @$_GET["ci"] . "&inth=" . $idinth . "&page=1";
                if (($page - 1) <= 0)
                    $npp = $last;
                else
                    $npp = $page - 1;
                $url_prec = $_SERVER["PHP_SELF"] . "?ci=" . @$_GET["ci"] . "&inth=" . $idinth . "&page=" . $npp;
                if (($page + 1) > $last)
                    $nps = 1;
                else
                    $nps = $page + 1;
                $url_suiv = $_SERVER["PHP_SELF"] . "?ci=" . @$_GET["ci"] . "&inth=" . $idinth . "&page=" . $nps;
                $url_fin = $_SERVER["PHP_SELF"] . "?ci=" . @$_GET["ci"] . "&inth=" . $idinth . "&page=" . $last;
                ?>
                <td width="33%" align="center" class="annot_petit_it">
                    <div id="oblig">(<img src="../img/oblig.png" align="absmiddle"
                                          alt="<?PHP echo _("Champ obligatoire"); ?>">
                        : <?PHP echo _("Saisie obligatoire"); ?>)
                    </div>
                </td>
                <td width="33%">
                    <div align="right">
                        <a href="<?PHP echo $url_deb; ?>"><img src="../img/deb.png" border="0"></a>
                        <a href="<?PHP echo $url_prec; ?>"><img src="../img/prec.png" border="0"></a>
                        <a href="<?PHP echo $url_suiv; ?>"><img src="../img/suiv.png" border="0"></a>
                        <a href="<?PHP echo $url_fin; ?>"><img src="../img/fin.png" border="0"></a>
                    </div>
                </td>
            </tr>
        </table>
        <table width="100%" border="0">
            <tr>
                <td width="160" class="rubfrm" id="f_numpbm" align="right"><?PHP echo _("Problème N°"); ?></td>
                <td>
                    <input name="numpbm" type="text" id="numpbm" value="<?PHP echo sprintf("%'010s", $rpbm_id) ?>"
                           size="15" maxlength="10" readonly>
                </td>
            </tr>
            <tr>
                <td width="160" class="rubfrm" id="f_signale" align="right"><?PHP echo _("Ajouté le"); ?></td>
                <td>
                    <input name="date" type="text" id="date" value="<?PHP echo $daterpbmf ?>" size="10" maxlength="10"
                           readonly>
                </td>
            </tr>
            <tr>
                <td width="160" class="rubfrm" id="f_signale" align="right"><?PHP echo _("Signalé par"); ?></td>
                <td>
                    <input name="signale" type="text" id="signale" value="<?PHP echo $rpbm_signale ?>" size="50"
                           readonly>
                </td>
            </tr>
            <tr>
                <td width="160" class="rubfrm" id="f_func" align="right"><?PHP echo _("Code Relevé"); ?></td>
                <td>
                    <input name="coderel" type="text" id="coderel" value="<?PHP echo $rpbm_coderlp ?>" size="20"
                           maxlength="20" readonly>
                    <?PHP
                    $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
                    if ($rpbm_typrel == 1) // C'est une licence
                        $rech = "SELECT * FROM `" . TBRLIC . "` WHERE `rlic_code`= '" . $rpbm_coderlp . "'";
                    else // C'est du matériel
                        $rech = "SELECT * FROM `" . TBRPDT . "` WHERE `rpdt_code`= '" . $rpbm_coderlp . "'";
                    $row = $db->get_row($rech, ARRAY_A);
                    if ($row) {
                        $row = encode_str($row);
                        extract($row);
                    }
                    $db->disconnect();
                    ?>
                    <br />
	<span class="annot_petit_it">
	<?PHP
    $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
    if ($rpbm_typrel == 1) // C'est une licence
    {
        $rech2 = "SELECT * FROM `" . TBMQUE . "` WHERE `mque_code` = '" . $rlic_codema . "'";
        $row2 = $db->get_row($rech2, ARRAY_A);
        if ($row2) {
            $row2 = encode_str($row2);
            extract($row2);
        }
        $txtreleve = $mque_ste . " " . $rlic_modele . " " . $rlic_version;
    } else // C'est du matériel
    {
        $rech2 = "SELECT * FROM `" . TBRPCAT . "` WHERE `rpcat_code` = '" . $rpdt_codecat . "'";
        $row2 = $db->get_row($rech2, ARRAY_A);
        if ($row2) {
            $row2 = encode_str($row2);
            extract($row2);
        }
        $rech2 = "SELECT * FROM `" . TBMQUE . "` WHERE `mque_code` = '" . $rpdt_codema . "'";
        $row2 = $db->get_row($rech2, ARRAY_A);
        if ($row2) {
            $row2 = encode_str($row2);
            extract($row2);
        }
        $txtreleve = $rpcat_desc . " / " . $mque_ste . " " . $rpdt_modele . " (" . $rpdt_codep . ")";
    }
    $db->disconnect();
    echo $txtreleve;
    ?>
	</span>
                </td>
            </tr>
            <tr>
                <td width="160" class="rubfrm" id="f_pbm" align="right"><?PHP Echo _("Problème noté"); ?></td>
                <td><textarea name="pbm" rows="5" id="pbm" readonly><?PHP echo $rpbm_pbm ?></textarea></td>
            </tr>
            <tr>
                <td width="160" class="rubfrm" id="f_fait" align="right"><?PHP echo _("Travail effectué"); ?></td>
                <td>
                    <textarea name="fait" rows="5"
                              id="fait"><?PHP echo str_replace("%%", chr(10) . chr(13), utf8_encode($_SESSION["pbm_faits"][intval($rpbm_id)])); ?></textarea>
                    <img src="../img/oblig.png" align="absmiddle" alt="<?PHP echo _("Champ obligatoire"); ?>">
                </td>
            </tr>
        </table>
        <p align="center">
            <input name="RAZ" type="reset" class="bton_std" id="RAZ" value="<?PHP echo _("Réinitialiser"); ?>">
            <input name="enr" type="button" class="bton_std" id="enr" value="<?PHP echo _("Valider"); ?>">
            <input name="quit" type="button" class="bton_std" id="quit" value="<?PHP echo _("Quitter"); ?>">
        </p>
    </form>
<?PHP
} else
    close_fen_auto('', '');
?>
</body>
</html>
