<?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
 ****************************************************************************************/

/*************************************************************************/
/* Récupération détail pièce rattachée sur planning (choix depuis pièce) */
/*************************************************************************/

session_start();
sleep(1);
if (array_key_exists("rat", $_REQUEST)) {
    $tomorrow = 0; //60*60*24; // en nb de secondes
    header("Cache-Control: max-age=$tomorrow");
    print_plain();
} else {
    print "Usage : $_SERVER[PHP_SELF]?rat=un-type-rattachement_un-code-rattachement";
}

function print_plain()
{
    header("Content-type: text/html; charset=UTF-8");
    $tab_rat = explode("_", $_REQUEST["rat"]);
    $detail = get_ratdetail($tab_rat[0], $tab_rat[1]);
    print $detail;
}

/**
 * @param $typ
 * @param $code
 * @return string
 */
function get_ratdetail($typ, $code)
{

    require_once("../lib/gettext/gettext.inc");
    include_once("../inc/config.inc.php");
    include_once("../inc/func_date.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");

    // On génère le code SQL
    $rech = "";
    $detail = "";
    switch ($typ) {
        // Rien
        case -1 :
            break;
        // Interventions
        case 1 :
            $rech = "SELECT int_mat, int_pbm FROM `" . TBINT . "` WHERE int_code='" . $code . "'";
            break;
        // Bon de travail
        case 2 :
            break;
    }

    // On recupere les enregistrements
    if ($rech <> "") {
        // On se connecte a la base
        $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
        $row = $db->get_row($rech, ARRAY_A);
        if ($row) {
            $row = encode_str($row);
            extract($row);
            switch ($typ) {
                // Rien
                case -1 :
                    break;
                // Interventions
                case 1 :
                    $detail = _("Matériel")." :\n" . $int_mat . "\n\n"._("Travail à effectuer")." :\n" . $int_pbm;
                    break;
                // Bons de travail
                case 2 :
                    break;
            }
        }
        $db->disconnect();
    }
    return $detail;
}

?>