<?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/func_time.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"]);
$txtcorps = trim(@$_SESSION["txt"]); // Récupération corps texte

$pbm_pcli = FALSE;

if ($txtcorps == "")
    $pbm_pcli = TRUE;

if ($pbm_pcli == FALSE) {
    include_once('../classes/tcpdf/config/tcpdf_config.php');
    include_once('../classes/tcpdf/tcpdf.php');
    include_once('../inc/tcpdf_ext.inc.php');


    $pdf = new PDF_SMI(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
    $pdf->setFontLng('fr');
    $pdf->set_add_margin();
    $pdf->SetCreator(PDF_CREATOR);
    $pdf->SetAuthor('SMI');
    $pdf->SetTitle('Courrier client');
    $pdf->SetSubject('Courrier client');
    $pdf->settgen();
    $pdf->settheader("prev");

    // set default monospaced font
    $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);

    //set margins
    $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
    $pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
    $pdf->SetFooterMargin(PDF_MARGIN_FOOTER);

    //set auto page breaks
    $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);

    $pdf->SetLeftMargin(10);
    $pdf->SetLineWidth(0.2);
    $pdf->AddPage();

    // Récupération Coordonnées sous entête
    $Pos_Entete = $pdf->GetY();

    $pdf->SetLineWidth(0.4);
    $pdf->SetFont('', '', 10);

    $pdf->WriteHTML($txtcorps, true, false, true);

    $url_pdf = $url_gfc . "/pj/"._("courrier_client") . $cocl_code;
    $pdf->Output($url_pdf, 'FI');
    @unlink($url_pdf);

    unset($_SESSION["txt"]);
}
