<?php
/****************************************************************************************
 * SMI (Services Maintenance Interventions) est une gestion libre de maintenance et de SAV
 *
 * Version 1.0.4
 *
 * Copyright (C) 2006-2016  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) {
    header('Location: ../index.php');
}

/******************************************************/
/* Fonctions pour les accès aux fichiers textes types */
/******************************************************/

/**
 * Lecture d'un enregistrement texte type
 *
 * @param $code
 * @param bool $open
 * @return array|null
 */
function lit_enr_txt($code, $open = TRUE)
{
    global
    $db;

    if ($open == TRUE) {
        $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST, 'utf8');
    }
    $rech2 = 'SELECT * FROM `' . TBTXT . "` WHERE `txt_code` = '" . $db->escape($code) . "'";
    $row2 = $db->get_row($rech2, ARRAY_A);
    if ($open == TRUE) {
        close_database();
    }

    return $row2;
}

/**
 * Formatage du code et lecture du texte correspondant
 *
 * @param $type
 * @param $mode
 * @param $orig
 * @param $dest
 * @param bool $open
 * @return string
 */
function lit_enr_txtf($type, $mode, $orig, $dest, $open = TRUE)
{
    $txt_texte = '';
    $codetxt = str_majuscules($type);

    $codetxt .= '_' . str_majuscules($mode);
    $codetxt .= '_' . str_majuscules($orig);
    $codetxt .= '_' . str_majuscules($dest);

    $row = lit_enr_txt($codetxt, $open);
    if (is_array($row)) {
        extract($row);
    }

    return $txt_texte;
}
