<?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');
}

include_once('../inc/config.inc.php');
include_once('../inc/fic_age.inc.php');
include_once('../inc/fic_cli.inc.php');
include_once('../inc/fic_do.inc.php');
include_once('../inc/fic_droits.inc.php');
include_once('../inc/fic_hum.inc.php');
include_once('../inc/fic_int.inc.php');
include_once('../inc/fic_ope.inc.php');
include_once('../inc/fic_st.inc.php');
include_once('../inc/fic_tec.inc.php');
include_once('../inc/fic_tra.inc.php');
include_once('../inc/func.inc.php');
include_once('../inc/func_fic.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/phpmailer/class.phpmailer.php');
include_once('../classes/phpmailer/class.smtp.php');
include_once('../inc/mail.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(valsession('code_log'));
// Variables Formulaire
fix_magic_quotes();
$_GET = clean_str($_GET);

$pbm_mail = FALSE;

$id = 0;
if (isset($_GET['id'])) {
    $id = (int)$_GET['id'];
} // Récupération id
else {
    $pbm_mail = TRUE;
}

if ($pbm_mail == FALSE) {
    // On vérifie si le code intervention existe
    $row = lit_trace_mail($id, TRUE);
    if (is_array($row)) {
        extract($row);
    } else {
        $pbm_mail = TRUE;
    }
}

$titre = _('DETAIL MESSAGE');
?>
<!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 _('Message'); ?></title>

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

    <script type="text/javascript">
        <!--
        function init_all() {
            init_Body();
            add_func_click('quit', 'sclose', '');
        }

        $(document).ready(function () {
            init_all();
        });

        //-->
    </script>

</head>

<body>
<?php
cre_ent_form($titre, '', '', '', FALSE);
if ($pbm_mail == FALSE) {
?>
<form name="mailint_detail" id="mailint_detail" method="post" action="mailint_detail.php"">
<input name="titre" type="hidden" id="titre" value="<?php echo $titre ?>">

<?php
// On crée la liste des destinataires possibles
$tab_contacts_cli = [];
$tab_ctact = [];

if ($cli_ste <> '') {
    // On récupère le code maître (si le client fait partie d'un regroupement)
    $tab_maitre = [];
    $tab_maitre = give_tab_maitre_cli($cli_code, TRUE);

    // création de la liste des contacts du client
    $txt_ccli = $cli_nom . ' ' . $cli_prenom . ' ('._('Contact principal');
    $txt_ccli .= ' - ' . $cli_telf;
    if ($cli_telp <> '')
        {$txt_ccli .= ' / ' . $cli_telp;}
    $txt_ccli .= ')';
    $tab_ctact[0] = $cli_email;
    $tab_ctact[1] = $txt_ccli;
    $tab_contacts_cli[] = $tab_ctact;

    $db = new ezSQL_mysqli(DBUSER, DBPASS, DBNAME, DBHOST,'utf8');

    // données site client
    if ((int)$int_idsite > 0) {
        $rech = 'SELECT * FROM `' . TBSCLI . "` WHERE `scli_id` = '$int_idsite'";
        $row = $db->get_row($rech, ARRAY_A);
        if ($$row) {
            $row = encode_str($row);
            extract($row);
            $txt_ccli = $scli_rnom . ' ' . $scli_rprenom . ' ('._('Contact site');
            $txt_ccli .= ' - ' . $scli_telf;
            if ($scli_telp <> '')
                {$txt_ccli .= ' / ' . $scli_telp;}
            $txt_ccli .= ')';
            $tab_ctact[0] = $scli_email;
            $tab_ctact[1] = $txt_ccli;
            $tab_contacts_cli[] = $tab_ctact;
        }
    }

    // Filtre sur client
    $rech = 'SELECT * FROM `' . TBCCLI . "` WHERE `ccli_codecli` = '" . $cli_code . "'";
    if (count($tab_maitre) > 0) {
        foreach ($tab_maitre as $key => $value) {
            $rech .= " OR `ccli_codecli` = '" . $value . "'";
        }
    }
    $rech .= ' ORDER BY ccli_nom';
    $rows = $db->get_results($rech, ARRAY_A);
    if ($rows) {
        foreach ($rows as $row) {
            $row = encode_str($row);
            extract($row);

            $txt_ccli = $ccli_nom . ' ' . $ccli_prenom;
            $row2 = lit_enr_fonc($ccli_codefonc, FALSE);
            if (is_array($row2)) {
                $row2 = encode_str($row2);
                extract($row2);
                $txt_fonc = $fonc_desc;
            } else
                {$txt_fonc = $ccli_codefonc;}
            $txt_ccli .= ' (';
            if (count($tab_maitre) > 0) {
                $nomcli = '';
                $rech3 = 'SELECT cli_ste FROM `' . TBCLI . "` WHERE `cli_code` = '$ccli_codecli'";
                $row3 = $db->get_row($rech3, ARRAY_A);
                if ($row3)
                    {$nomcli = $row3['cli_ste'];}
                if ($nomcli <> '')
                    {$txt_ccli .= $nomcli . ' - ';}
            }
            $txt_ccli .= $txt_fonc;
            $txt_ccli .= ' - ' . $ccli_telf;
            if ($ccli_telp <> '')
                {$txt_ccli .= ' / ' . $ccli_telp;}
            $txt_ccli .= ')';
            $tab_ctact[0] = $ccli_email;
            $tab_ctact[1] = $txt_ccli;
            $tab_contacts_cli[] = $tab_ctact;
        }
    }
    close_database();
} else {
    $txt_ccli = '';
    $row = lit_enr_cli($cli_code, TRUE);
    if (is_array($row)) {
        $row = encode_str($row);
        extract($row);
        $txt_ccli = $cli_nom . ' ' . $cli_prenom . ' (' . $cli_codefonc;
        $row2 = lit_enr_fonc($cli_codefonc, TRUE);
        if (is_array($row2)) {
            $row2 = encode_str($row2);
            extract($row2);
            $txt_fonc = $fonc_desc;
        } else
            {$txt_fonc = $ccli_codefonc;}
        $txt_ccli .= ' (' . $txt_fonc;
        $txt_ccli .= ' - ' . $cli_telf;
        if ($cli_telp <> '')
            {$txt_ccli .= ' / ' . $cli_telp;}
        $txt_ccli .= ')';
    }
    if ($txt_ccli <> '') {
        $tab_ctact[0] = $cli_email;
        $tab_ctact[1] = $txt_ccli;
        $tab_contacts_cli[] = $tab_ctact;
    }
}

echo '<table width="100%"  border="0">';
echo '<tr>';
echo '<td width="130" class="rubfrm" id="f_mailurg" align="right">'._('Urgence').'</td>';
echo '<td align="left">';
echo '<input name="mailurg" type="text" id="mailurg" value="' . $tra_urg[$tramail_mailurg] . '" size="20" readonly="1">';
echo '</td>';
echo '</tr>';
echo '<tr>';
echo '<td class="rubfrm" id="f_maildest" align="right">'._('Destinataire').'</td>';
echo '<td align="left">';
echo '<input name="maildest" type="text" id="maildest" value="' . $tramail_maildest . '" size="50" readonly="1">';
echo '</td>';
echo '</tr>';
echo '<tr>';
echo '<td class="rubfrm" id="f_mailcc" align="right">'._('Copie à').'</td>';
echo '<td align="left">';
echo '<input name="mailcc" type="text" id="mailcc" value="' . $tramail_mailcc . '" size="50" readonly="1">';
echo '</td>';
echo '</tr>';
echo '<tr>';
echo '<td class="rubfrm" id="f_mailbcc" align="right">'._('Copie cachée à').'</td>';
echo '<td align="left">';
echo '<input name="mailbcc" type="text" id="mailbcc" value="' . $tramail_mailcc . '" size="50" readonly="1">';
echo '</td>';
echo '</tr>';
echo '<tr>';
echo '<td class="rubfrm" id="f_mailsujet" align="right">'._('Sujet').'</td>';
echo '<td align="left">';
echo '<input name="mailsujet" type="text" id="mailsujet" value="' . $tramail_mailsujet . '" size="50" readonly="1">';
echo '</td>';
echo '</tr>';
echo '<tr>';
echo '<td class="rubfrm" id="f_mailtxt" align="right">'._('Texte').'</td>';
echo '<td align="left">';
echo '<div id="mailtxt">';
echo $tramail_mailtxt;
echo '</div>';
echo '</td>';
echo '</tr>';
echo '</table>';

echo '</ br>';
echo '<div id="butmailext" align="center" style="margin-top:10px;">';
echo '<input name="quit" type="button" class="bton_fgris_petit" id="quit" value="' . _('Quitter') . '">';
echo '</div>';
?>

</form>
<!-- Fin affiché uniquement si demande cohérente -->
<?php
} else
    {close_fen_auto(_('Problème de paramètres'), 'fscomp2', 5000);}
include_once('pied.php');
?>
</body>
</html>