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

/**********************************************/
/* MAJ traçabilité envoi mail interne		  */
/**********************************************/

session_start();
sleep(1);
if (array_key_exists('prm', $_REQUEST)) {
    $tomorrow = 0; //60*60*24; // en nb de secondes
    header("Cache-Control: max-age=$tomorrow");
    exp_mail();
} else {
    print "Usage : $_SERVER[PHP_SELF]?prm=dest&cc&bcc";
}

function exp_mail()
{
    header('Content-type: text/html; charset=UTF-8');
    $tab_prm = explode('&', $_REQUEST['prm']);

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

    $titre = _('Envoi mail externe');
    $desc = _('Destinataires :');
    $desc .= chr(13) . chr(10) . '.' . _('Envoi à') . ' -> ' . $tab_prm[2];
    if (trim($tab_prm[3]) <> '') {
        $desc .= chr(13) . chr(10) . '.' . _('Copie à') . ' -> ' . $tab_prm[3];
    }
    if (trim($tab_prm[4]) <> '') {
        $desc .= chr(13) . chr(10) . '.' . _('Copie cachée à') . ' -> ' . $tab_prm[4];
    }

    if (CheckNivLog('9')) {
        $code_session = _('Administrateur');
    } else {
        $code_session = $_SESSION['code_log'];
    }
    $datecourante = date('Y-m-d');
    $heurecourante = date('H:i:s');


    $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST, 'utf8');
    $rech = 'INSERT INTO `' . TBTRA . '`';
    $rech .= ' (tra_codeutil,tra_date,tra_heure,tra_codeta,tra_titre,tra_desc,tra_typrat,tra_coderat) VALUES';
    $rech .= " ('$code_session','$datecourante','$heurecourante','EEE','" . $db->escape($titre) . "','" . $db->escape($desc) . "','" . $tab_prm[0] . "','" . $tab_prm[1] . "')";
    // On se connecte a la base
    $db->query($rech);
    close_database();
}
