<?php
/****************************************************************************************
 * SMI (Services Maintenance Interventions) est une gestion libre de maintenance et de SAV
 *
 * Version 1.0.0
 *
 * Copyright (C) 2006-2014  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/fic_age.inc.php");
include_once("../inc/fic_do.inc.php");
include_once("../inc/fic_st.inc.php");
include_once("../inc/fic_hum.inc.php");
include_once("../inc/fic_cli.inc.php");
include_once("../inc/fic_droits.inc.php");
include_once("../inc/fic_int.inc.php");
include_once("../inc/fic_ot.inc.php");
include_once("../inc/fic_tec.inc.php");
include_once("../inc/fic_txt.inc.php");
include_once("../inc/func.inc.php");
include_once("../inc/func_time.inc.php");
include_once("../inc/func_date.inc.php");
include_once("../inc/func_geo.inc.php");
include_once("../inc/func_txt.inc.php");
include_once("../inc/func_txtcm.inc.php");
include_once("../inc/func_geo.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"]);
// Variables Formulaire
fix_magic_quotes();
$_GET = clean_str($_GET);

$co = $_GET['co']; // Récupération code Intervention
$cg = $_GET['cgv']; // Récupération si avec ou sans CGV
$niv_util = @$_SESSION["niv_log"];

if ($cg == "ok")
    $cgv = TRUE;
else
    $cgv = FALSE;

$pbm_otpdf = FALSE;

if ($co <> "") {
    $row = lit_enr_ot($co);
    if (is_array($row)) {
        $row = encode_str($row);
        extract($row);

        // Contrôle de hack pour un sous-traitant
        if ((($niv_util == 11) OR ($niv_util == 10)) AND ($ot_codest <> @$_SESSION["code_st"]))
            $pbm_otpdf = TRUE;

        if ($pbm_otpdf == FALSE) {
            // Coordonnées technicien
            $row = lit_enr_tec($ot_codetec, TRUE);
            if (is_array($row)) {
                $row = encode_str($row);
                extract($row);
            }

            // Récupération du total travaillé & Techniciens traitants
            $nbtotalsec = 0;
            $str_tec_traitants = "";
            $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);

            // Récupération total travaillé
            $rech = "SELECT * FROM `" . TBOTH . "` WHERE `oth_codeot`= '" . $co . "'";
            $rows = $db->get_results($rech, ARRAY_A);
            if ($rows) {
                foreach ($rows as $row) {
                    $row = encode_str($row);
                    if ($row["oth_offert"] == 0)
                        $nbtotalsec = $nbtotalsec + diff_time_sec($row["oth_heurea"], $row["oth_heured"]);
                }
            }

            // Chaîne des techniciens traitants
            $rech = "SELECT DISTINCT oth_codetec FROM `" . TBOTH . "` WHERE `oth_codeot`= '" . $co . "'";
            $rows = $db->get_results($rech, ARRAY_A);
            if ($rows) {
                foreach ($rows as $row) {
                    $row = encode_str($row);
                    $rech2 = "SELECT tec_nom, tec_prenom FROM `" . TBTEC . "` WHERE `tec_code`= '" . $row["oth_codetec"] . "' ORDER BY tec_nom";
                    $row2 = $db->get_row($rech2, ARRAY_A);
                    if ($row2) {
                        $row2 = encode_str($row2);
                        $str_tec_traitants .= $row2["tec_nom"] . " " . $row2["tec_prenom"] . ", ";
                    }
                }
            }
            $str_tec_traitants = substr($str_tec_traitants, 0, strlen($str_tec_traitants) - 2);
            $db->disconnect();

            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(_("Ordre N°") . $ot_code);
            $pdf->SetSubject(_("Ordre N°") . $ot_code);
            $pdf->settheader("ot");

            // 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();

            // Impression du détail client
            $pdf->SetFont('', 'BU', 12); // Titre
            $pdf->Cell(95, 5, _("SITE INTERVENTION"), 0, 1, 'C');

            if (intval($ot_idsite) == 0) // S'il s'agit du site principal
            {
                $row = lit_enr_cli($ot_codecli, TRUE);
                if (is_array($row)) {
                    $row = encode_str($row);
                    extract($row);

                    $ent_cli = ""; // Détail
                    if ($cli_ste <> "") {
                        $ent_cli .= $cli_ste . "\n";
                        $ent_cli .= $cli_civilite . " " . $cli_prenom . " " . $cli_nom . "\n";
                    } else
                        $ent_cli .= $cli_civilite . " " . $cli_prenom . " " . $cli_nom . "\n";
                    $pdf->SetFont('', 'B', 10);
                    $pdf->MultiCell(95, 4, $ent_cli, 0, 'L');

                    $ent_cli = $cli_adr1 . "\n"; // Suite...
                    if (trim($cli_adr2) <> "")
                        $ent_cli .= $cli_adr2 . "\n";
                    $ent_cli .= Retournecp_Id($cli_ville, TRUE) . " " . Retourneville_Id($cli_ville, TRUE) . "\n";
                    $ent_cli .= "Tel : " . $cli_telf . "\n";
                    $ent_cli .= "Fax : " . $cli_fax;
                    if (trim($cli_tvai) <> "")
                        $ent_cli .= "\nTVA : " . $cli_tvai;

                    $pdf->SetFont('', '', 10);
                    $pdf->MultiCell(95, 4, $ent_cli, 0, 'L');
                }
            } else // S'il s'agit d'un site secondaire
            {
                $row = lit_enr_scli_id($ot_idsite, TRUE);
                if (is_array($row)) {
                    $row = encode_str($row);
                    extract($row);

                    $ent_scli = ""; // Détail
                    $ent_scli .= $scli_ste . "\n";
                    $ent_scli .= $scli_rcivil . " " . $scli_rprenom . " " . $scli_rnom . "\n";
                    $pdf->SetFont('', 'B', 10);
                    $pdf->MultiCell(95, 4, $ent_scli, 0, 'L');

                    $ent_scli = $scli_adr1 . "\n"; // Suite...
                    if (trim($scli_adr2) <> "")
                        $ent_scli .= $scli_adr2 . "\n";
                    $ent_scli .= Retournecp_Id($scli_ville, TRUE) . " " . Retourneville_Id($scli_ville, TRUE) . "\n";
                    $ent_scli .= "Tel : " . $scli_telf . "\n";
                    $ent_scli .= "Fax : " . $scli_fax;
                    if (trim($scli_tvai) <> "")
                        $ent_scli .= "\nTVA : " . $scli_tvai;

                    $pdf->SetFont('', '', 10);
                    $pdf->MultiCell(95, 4, $ent_scli, 0, 'L');
                }
            }

            // Récupération Coordonnées
            $Pos_EntCli = $pdf->GetY();

            // Impression du détail ordre
            $pdf->SetY($Pos_Entete); // Renvoie le pointeur SOUS l'entête agence


            $pdf->Cell(95);

            $pdf->SetFont('', '', 8); // Niveau d'urgence
            $pdf->Cell(95, 5, $ot_urg, 0, 1, 'R');

            $pdf->SetY($Pos_Entete + 1); // Renvoie le pointeur SOUS l'entête agence

            $pdf->Cell(95);

            $ent_ot = _("Agence") . " :\n";
            $ent_ot .= _("Suivi par") . " :\n";
            $ent_ot .= _("Exécutant") . " :\n";
            $ent_ot .= _("Statut") . " :\n";
            $ent_ot .= _("Lieu") . " :\n";
            $ent_ot .= _("Rendez-vous") . " :\n";
            $ent_ot .= _("Intervention") . " :\n";
            $ent_ot .= "\n";

            $pdf->MultiCell(22, 4, $ent_ot, 0, 'R');

            $pdf->SetY($Pos_Entete + 1); // Renvoie le pointeur SOUS l'entête agence
            $pdf->Cell(117);

            $codetecr = "-";
            if ($ot_codeint <> "--AR--") {
                $row = lit_enr_int($ot_codeint);
                if (is_array($row)) {
                    $row = encode_str($row);
                    extract($row);

                    // Coordonnées agence concernée
                    $row = lit_enr_age($int_codeage, TRUE);
                    $row = encode_str($row);
                    extract($row);

                    // Technicien responsable
                    if ((trim($int_codetec) <> "") AND (trim($int_codetec) <> "-1")) {
                        $row2 = lit_enr_tec($int_codetec, TRUE);
                        if (is_array($row2)) {
                            $row2 = encode_str($row2);
                            extract($row2);
                            $codetecr = $tec_nom . " " . $tec_prenom;
                        }
                    }


                }
            } else {
                $row = lit_enr_cli($ot_codecli, TRUE);
                if (is_array($row)) {
                    $row = encode_str($row);
                    extract($row);
                    if (trim($cli_prop) <> "") {
                        // Coordonnées agence concernée
                        $row = lit_enr_age($cli_prop, TRUE);
                        if (is_array($row)) {
                            $row = encode_str($row);
                            extract($row);
                        }
                    }
                }
            }

            $ent_ot = $age_nom . " (" . $age_telf . ")\n";
            $ent_ot .= $codetecr . "\n";
            $ent_ot .= $ot_codest . "\n";

            // Récupération libellé statut
            $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
            $rech = "SELECT * FROM `" . TBSTA . "` WHERE statut_code='" . $ot_codestatut . "'";
            $row = $db->get_row($rech, ARRAY_A);
            if ($row) {
                $row = encode_str($row);
                extract($row);
            }
            $db->disconnect();

            $ent_ot .= $statut_desc . "\n";

            // Récupération libellé lieu
            $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
            $rech = "SELECT * FROM `" . TBLIEU . "` WHERE lieu_code='" . $ot_codelieu . "'";
            $row = $db->get_row($rech, ARRAY_A);
            if ($row) {
                $row = encode_str($row);
                extract($row);
            }
            $db->disconnect();

            $ent_ot .= $lieu_desc . "\n";
            if (datetolocal($ot_daterdv) <> "")
                $ent_ot .= datetolocal($ot_daterdv) . " (" . _("à partir de") . " " . substr($ot_hrdv, 0, 5) . ")\n";
            else
                $ent_ot .= "-\n";
            if (($ot_codeint <> "") AND ($ot_codeint <> "--AR--"))
                $ent_ot .= $ot_codeint . "\n";
            else
                $ent_ot .= "-\n";
            $ent_ot .= "\n";

            $pdf->MultiCell(73, 4, $ent_ot, 0, 'L');

            // Récupération Coordonnées
            $Pos_EntDetail = $pdf->GetY();

            $PosY = max($Pos_EntCli, $Pos_EntDetail);
            $pdf->SetY($PosY);
            $pdf->ln(1);
            $pdf->SetDrawColor(125);
            $pdf->SetLineWidth(0.4);
            $pdf->SetLineStyle(['dash' => 2]);
            $pdf->Line(10, $PosY, 200, $PosY);
            $pdf->SetDrawColor(0);
            $pdf->SetLineWidth(0.2);
            $pdf->SetDrawColor(220);
            $pdf->SetLineStyle(['dash' => 0]);
            $pdf->ln(1);


            // Détail de la prise en charge
            $pdf->SetFont('', 'B', 10);
            $pdf->Cell(40, 5, _("Contact client") . ' : ', 0, 0, 'R');
            $pdf->SetFont('', '', 8);
            $txt_ccli = _("Pas de contact");
            switch (intval($ot_ccli)) {
                case -1 :
                    $txt_ccli = $cli_nom . " " . $cli_prenom . " (" . _("Contact principal");
                    $txt_ccli .= " - " . $cli_telf . ")";
                    break;
                case 0 :
                    $row = lit_enr_scli_id($ot_idsite, TRUE);
                    if (is_array($row)) {
                        $row = encode_str($row);
                        extract($row);
                        $txt_ccli = $scli_rnom . " " . $scli_rprenom . " (" . _("Contact site");
                        $txt_ccli .= " - " . $scli_telf . ")";
                    }
                    break;
                default :
                    $row = lit_enr_ccli_id_in_cli($ot_ccli, $cli_code);
                    if (is_array($row)) {
                        $row = encode_str($row);
                        extract($row);
                        $row2 = lit_enr_fonc($ccli_codefonc, TRUE);
                        if (is_array($row2)) {
                            $row2 = encode_str($row2);
                            extract($row2);
                            $txt_fonc = $fonc_desc;
                        } else
                            $txt_fonc = $ccli_codefonc;
                        $txt_ccli = $ccli_nom . " " . $ccli_prenom . " (" . $txt_fonc . " - " . $ccli_telf . ")";
                    }
                    break;
            }
            $pdf->MultiCell(150, 4, $txt_ccli, 1, 'L');

            $pdf->SetFont('', 'B', 10);
            $pdf->Cell(40, 5, _("Matériel") . ' : ', 0, 0, 'R');
            $pdf->SetFont('', '', 8);
            $pdf->MultiCell(150, 4, $ot_mat, 1, 'L');

            $pdf->ln(1);

            $pdf->SetFont('', 'B', 10);
            $pdf->Cell(40, 5, _("Descriptif Problème") . ' : ', 0, 0, 'R');
            $pdf->SetFont('', '', 8);
            $pdf->MultiCell(150, 4, $ot_pbm, 1, 'L');

            $pdf->ln(1);

            $pdf->SetFont('', 'B', 10);
            $pdf->Cell(40, 5, _("Garantie") . ' : ', 0, 0, 'R');
            $pdf->SetFont('', '', 8);
            if ($ot_gar == 0)
                $pdf->Cell(8, 5, 'Non', 0, 0, 'L');
            else
                $pdf->Cell(8, 5, 'Oui', 0, 0, 'L');
            $pdf->SetFont('', 'B', 10);
            $pdf->Cell(40, 5, _("Référence Facture") . ' : ', 0, 0, 'R');
            $pdf->SetFont('', '', 8);
            $pdf->Cell(102, 5, $ot_fgar, 0, 1, 'L');

            $pdf->ln(2);

            // Détail du traitement du dossier
            $pdf->SetFont('', 'B', 10);
            $pdf->Cell(40, 5, _("Technicien Responsable") . ' : ', 0, 0, 'R');
            $pdf->SetFont('', '', 8);
            $pdf->MultiCell(150, 4, $tec_civilite . " " . $tec_prenom . " " . $tec_nom, 1, 'L');

            $pdf->ln(1);

            $pdf->SetFont('', 'B', 10);
            $pdf->Cell(40, 5, _("Technicien(s) traitant(s)") . ' : ', 0, 0, 'R');
            $pdf->SetFont('', '', 8);
            $pdf->MultiCell(150, 4, $str_tec_traitants, 1, 'L');

            $pdf->ln(1);


            $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);

            $rech = "SELECT * FROM `" . TBOTH . "` WHERE `oth_codeot`= '" . $co . "' ORDER BY oth_date";
            $rows = $db->get_results($rech, ARRAY_A);
            if ($rows) {
                $pdf->SetFont('', 'B', 8);
                $pdf->Cell(40, 5, _("Détail horaires & techniciens") . ' : ', 0, 1, 'R');
                $pdf->SetFont('', '', 8);
                $pdf->SetFont('', 'IU', 7); // Titres
                $pdf->Cell(7);
                $pdf->Cell(14, 4, _("Date"), 1, 0, 'C');
                $pdf->Cell(50, 4, _("Technicien"), 1, 0, 'C');
                $pdf->Cell(50, 4, _("Lieu"), 1, 0, 'C');
                $pdf->Cell(16, 4, _("Heure début"), 1, 0, 'C');
                $pdf->Cell(16, 4, _("Heure fin"), 1, 0, 'C');
                $pdf->Cell(16, 4, _("Temps passé"), 1, 0, 'C');
                $pdf->Cell(10, 4, _("Offert"), 1, 1, 'C');
                $pdf->SetFont('', 'I', 8);

                foreach ($rows as $row) {
                    $row = encode_str($row);
                    extract($row);

                    // Ligne 1
                    $pdf->Cell(7);
                    $pdf->SetFont('', 'I', 7);
                    $pdf->Cell(14, 4, datetolocal($oth_date), 'LR', 0, 'C');
                    $pdf->Cell(50, 4, $oth_codetec, 'LR', 0, 'L');
                    $rech2 = "SELECT * FROM `" . TBLIEU . "` WHERE `lieu_code` = '" . $oth_codelieu . "'";
                    $row2 = $db->get_row($rech2, ARRAY_A);
                    if ($row2) {
                        $row2 = encode_str($row2);
                        extract($row2);
                    }
                    $pdf->Cell(50, 4, $lieu_desc, 'LR', 0, 'L');
                    $pdf->Cell(16, 4, $oth_heurea, 'LR', 0, 'C');
                    $pdf->Cell(16, 4, $oth_heured, 'LR', 0, 'C');
                    $pdf->Cell(16, 4, heure_to_hhmm(sec_heure(diff_time_sec($oth_heurea, $oth_heured))), 'LR', 0, 'C');
                    if ($oth_offert == 1)
                        $pdf->Cell(10, 4, _("oui"), 'LR', 1, 'C');
                    else
                        $pdf->Cell(10, 4, '-', 'LR', 1, 'C');

                    // Ligne 2
                    $pdf->Cell(7);
                    $pdf->SetFont('', 'I', 7);
                    $pdf->Cell(14, 4, '', 'LR', 0, 'C');
                    $rech2 = "SELECT * FROM `" . TBTEC . "` WHERE `tec_code` = '" . $oth_codetec . "'";
                    $row2 = $db->get_row($rech2, ARRAY_A);
                    if ($row2) {
                        $row2 = encode_str($row2);
                        extract($row2);
                    }
                    $pdf->Cell(50, 4, $tec_nom . " " . $tec_prenom, 'LR', 0, 'L');
                    $pdf->Cell(50, 4, '', 'LR', 0, 'L');
                    $pdf->Cell(16, 4, '', 'LR', 0, 'C');
                    $pdf->Cell(16, 4, '', 'LR', 0, 'C');
                    $pdf->Cell(16, 4, '', 'LR', 0, 'C');
                    $pdf->Cell(10, 4, '', 'LR', 1, 'C');
                }
                $PosY = $pdf->GetY();
                $pdf->Line(17, $PosY, 189, $PosY); // On "ferme" le tableau

                // Totaux
                $pdf->SetFont('', 'IB', 7);
                $pdf->Cell(137);
                $pdf->Cell(16, 4, _("Temps retenu") . ' : ', 0, 0, 'R');
                $pdf->Cell(16, 4, heure_to_hhmm(sec_heure($nbtotalsec)), 0, 1, 'C');
            } else {
                $pdf->SetFont('', 'B', 8);
                $pdf->Cell(40, 5, _("Détail horaires & techniciens") . ' : ', 0, 1, 'R');
                $pdf->SetFont('', 'IU', 7); // Titres
                $pdf->Cell(7);
                $pdf->Cell(14, 4, _("Date"), 1, 0, 'C');
                $pdf->Cell(50, 4, _("Technicien"), 1, 0, 'C');
                $pdf->Cell(50, 4, _("Lieu"), 1, 0, 'C');
                $pdf->Cell(16, 4, _("Heure début"), 1, 0, 'C');
                $pdf->Cell(16, 4, _("Heure fin"), 1, 0, 'C');
                $pdf->Cell(16, 4, _("Temps passé"), 1, 0, 'C');
                $pdf->Cell(10, 4, _("Offert"), 1, 1, 'C');
                $pdf->SetFont('', 'I', 8);

                for ($i = 0; $i < 5; $i++) {
                    $pdf->Cell(7);
                    $pdf->SetFont('', 'I', 7);
                    $pdf->Cell(14, 4, '', 'LR', 0, 'C');
                    $pdf->Cell(50, 4, '', 'LR', 0, 'L');
                    $pdf->Cell(50, 4, '', 'LR', 0, 'L');
                    $pdf->Cell(16, 4, '', 'LR', 0, 'C');
                    $pdf->Cell(16, 4, '', 'LR', 0, 'C');
                    $pdf->Cell(16, 4, '', 'LR', 0, 'C');
                    $pdf->Cell(10, 4, '', 'LR', 1, 'C');
                }
                $PosY = $pdf->GetY();
                $pdf->Line(17, $PosY, 189, $PosY); // On "ferme" le tableau

                // Totaux
                $pdf->SetFont('', 'IB', 7);
                $pdf->Cell(137);
                $pdf->Cell(16, 4, _("Temps retenu") . ' : ', 0, 0, 'R');
                $pdf->Cell(16, 4, '', 0, 1, 'C');
            }

            $pdf->ln(1);

            $pdf->SetFont('', 'B', 10);
            $pdf->Cell(40, 5, _("Travail Effectué") . ' : ', 0, 0, 'R');
            if ($ot_fait == "") {
                for ($i = 0; $i < 10; $i++) {
                    $ot_fait .= "\n";
                }
            }
            $pdf->SetFont('', '', 8);
            $pdf->MultiCell(150, 4, $ot_fait, 1, 'L');
            // On affiche la date où l'agence a été prévenue uniquement si elle a été complétée
            if (datetolocal($ot_dateprev) <> "") {
                $pdf->ln(2);

                $pdf->SetFont('', 'B', 10);
                $pdf->Cell(40, 5, _("Agence prévenue le") . ' : ', 0, 0, 'R');
                $pdf->SetFont('', '', 8);
                $pdf->MultiCell(150, 4, datetolocal($ot_dateprev), 1, 'L');
            }

            // Affichage de la date de fin uniquement si terminé
            if (datetolocal($ot_datefin) <> "") {
                $pdf->ln(2);

                $pdf->SetFont('', 'B', 10);
                $pdf->Cell(40, 5, _("Bon clôt le") . ' : ', 0, 0, 'R');
                $pdf->SetFont('', '', 8);
                $pdf->MultiCell(150, 4, datetolocal($ot_datefin), 1, 'L');
            }
            $pdf->ln(2);

            $pdf->SetLineWidth(0.2);
            $pdf->SetDrawColor(0);

            if ($ot_codestatut <> "CLOT") // On affiche un pied de fiche intervention uniquement si c'est non clot
            {
                if (trim($str_tec_traitants) == "") // Si pas déjà traité, texte préalable que le client doit accepter en le signant
                {
                    $row = lit_enr_txt("CGV_SAV");
                    if ($row) {
                        $row = encode_str($row);
                        extract($row);
                        $txt_sav = parse_txtcorps("age", $age_code, $txt_texte, ""); // BR important pour retour à la ligne finalecho "y5 : ".$pdf->getY()."<br />";
                        $pdf->SetFont('', '', 6);
                        $pdf->WriteHTML($txt_sav, true, false, true);
                    }
                }

                // Si sur site (donc à effectuer), préparation d'une grille de saisie de paramètres
                if ($ot_codelieu == "SITE") {
                    if ($str_tec_traitants == "") // Si pas déjà traité (Sinon, pas de pied)
                    {
                        // Si on est trop bas pour afficher la zone de signature, on effectue un saut de page
                        $y_courant = $pdf->GetY();
                        if ($y_courant > 245)
                            $pdf->AddPage();

                        $pdf->SetFont('', 'BU', 10);
                        $pdf->SetFillColor(200);
                        $pdf->Cell(95, 5, _("Horaires arrivée/ départ"), 'LTR', 0, 'C');
                        $pdf->Cell(95, 5, _("Date & Signature Client") . " : ", 'LTR', 1, 'C');
                        $pdf->Cell(95, 5, "", 'LR', 0, 'L', 1);
                        $pdf->SetFont('', 'I', 8);
                        $pdf->Cell(95, 5, _("Lu et approuvé"), 'LR', 1, 'C');
                        $pdf->SetFont('', 'BU', 10);
                        $pdf->Cell(95, 5, _("Intervention terminée / non terminée"), 'LTR', 0, 'C');
                        $pdf->Cell(95, 5, "", 'LR', 1, 'L');
                        $pdf->Cell(95, 5, "", 'LR', 0, 'L', 1);
                        $pdf->Cell(95, 5, "", 'LR', 1, 'L');
                        $pdf->Cell(95, 5, _("Règlement"), 'LTR', 0, 'C');
                        $pdf->Cell(95, 5, "", 'LR', 1, 'L');
                        $pdf->Cell(95, 5, "", 'LRB', 0, 'L', 1);
                        $pdf->Cell(95, 5, "", 'LRB', 1, 'L');
                    }
                } else {
                    // Si on a pas encore traité l'intervention, on demande signature de demande de travaux
                    if ($str_tec_traitants == "") {
                        // Si on est trop bas pour afficher la zone de signature, on effectue un saut de page
                        $y_courant = $pdf->GetY();
                        if ($y_courant > 230)
                            $pdf->AddPage();

                        $pdf->Ln(5);

                        $pdf->SetFont('', 'BU', 10);
                        $pdf->Cell(47);
                        $pdf->Cell(95, 5, _("Date & Signature client (Demande de travaux)"), 'LTR', 1, 'C');
                        $pdf->SetFont('', 'I', 8);
                        $pdf->Cell(47);
                        $pdf->Cell(95, 5, _("Lu et approuvé"), 'LR', 1, 'C');
                        for ($i = 0; $i < 5; $i++) {
                            $pdf->Cell(47);
                            $pdf->Cell(95, 5, "", 'LR', 1, 'L');
                        }
                        $pdf->Cell(47);
                        $pdf->Cell(95, 5, "", 'LRB', 1, 'L');
                    }

                    // Si on a traité le dossier et que le client est prévenu, on affiche une zone de signature de travaux effectués
                    if (($ot_durees <> 0) AND ($ot_dateprevf <> "")) {
                        // Si on est trop bas pour afficher la zone de signature, on effectue un saut de page
                        $y_courant = $pdf->GetY();
                        if ($y_courant > 230)
                            $pdf->AddPage();

                        $pdf->Ln(5);

                        $pdf->SetFont('', 'BU', 10);
                        $pdf->Cell(47);
                        $pdf->Cell(95, 5, _("Date & Signature client (Travaux effectués)"), 'LTR', 1, 'C');
                        $pdf->Cell(47);
                        $pdf->SetFont('', 'I', 8);
                        $pdf->Cell(95, 5, _("Lu et approuvé"), 'LR', 1, 'C');
                        for ($i = 0; $i < 5; $i++) {
                            $pdf->Cell(47);
                            $pdf->Cell(95, 5, "", 'LR', 1, 'L');
                        }
                        $pdf->Cell(47);
                        $pdf->Cell(95, 5, "", 'LRB', 1, 'L');
                    }
                }
            }
            if ($cgv == TRUE) {
                $pdf->AddPage();

                $row = lit_enr_txt("CGV_MASTER");
                $row = encode_str($row);
                extract($row);

                $pdf->SetFont('', 'BU', 10);
                $txt_ent = parse_txtcorps("cdg", "", $txt_entete, "");
                $pdf->MultiCell(190, 5, $txt_ent . "\n\n", 0, 'C');

                $txt_texte = formatetxt($txt_texte);
                $txt_cgv = parse_txtcorps("cdg", "", $txt_texte, "") . "<br />"; // BR important pour retour à la ligne final

                $pdf->SetFont('', '', 6);
                $pdf->WriteHTML($txt_cgv, true, false, true);
            }
            /*
                    //Détermination d'un nom de fichier temporaire dans le répertoire courant
                    $file=basename(tempnam(getcwd(),'tmp'));
                    rename($file,$file.'.pdf');
                    $file.='.pdf';
            */
            // $pdf->Output($file,'D');
            $pdf->Output('ot_' . $ot_code, 'I');
        }
    } else {
        $pbm_otpdf = TRUE;
    }
} else
    $pbm_otpdf = TRUE;
close_fen_auto('', '');
?>
