<?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/fic_age.inc.php');
include_once('../inc/fic_cli.inc.php');
include_once('../inc/fic_hum.inc.php');
include_once('../inc/fic_dos.inc.php');
include_once('../inc/fic_droits.inc.php');
include_once('../inc/fic_prm.inc.php');
include_once('../inc/fic_st.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(valsession('code_log'));
// Variables Formulaire
fix_magic_quotes();
$_GET = clean_str($_GET);

$cd = $_GET['cd']; // Récupération code Dossier
$niv_util = valsession('niv_log');

$pbm_dospdf = FALSE;

if ($cd <> '') {
    $nbdosd = nb_dosd_in_dos($cd);

    $row = lit_enr_dos($cd);
    if (is_array($row)) {
        $row = encode_str($row);
        extract($row);

        // Contrôle de hack pour une agence
        if ((($niv_util == 4) OR ($niv_util == 3)) AND ($dos_codeage <> valsession('code_age'))) {
            $pbm_dospdf = TRUE;
        }

        if ($pbm_dospdf == FALSE) {
            $dos_datecreaf = datetolocal($dos_datecrea);
            $dos_datemodf = datetolocal($dos_datemod);
            $dos_dateddef = datetolocal($dos_datedde);
            $dos_datefinpf = datetolocal($dos_datefinp);
            $dos_datefinf = datetolocal($dos_datefin);

            $row = lit_enr_age($dos_codeage, TRUE);
            if ($row) {
                $row = encode_str($row);
                extract($row);
            }

            $cp_age = Retournecp_Id($age_ville, TRUE);
            $ville_age = Retourneville_Id($age_ville, TRUE);

            // Coordonnées compte client
            $row = lit_enr_cli($dos_codecli, TRUE);
            if ($row) {
                $row = encode_str($row);
                extract($row);
            }

            // Coordonnées technicien
            $row = lit_enr_tec($dos_codesuiv, TRUE);
            if ($row) {
                $row = encode_str($row);
                extract($row);
            }

            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(_('Dossier N°') . $dos_code);
            $pdf->SetSubject(_('Dossier N°') . $dos_code);
            $pdf->settheader('dos');

            // 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, 'CLIENT', 0, 1, 'C');

            $ent_cli = ''; // Détail
            if ($cli_ste <> '') {
                $ent_cli .= $cli_ste . "\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 .= "\n" . _('TVA') . ' : ' . $cli_tvai;
            }

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

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

            // Impression du détail dossier
            $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, $dos_urg, 0, 1, 'R');

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

            $pdf->Cell(95);

            $txt_entete = '';
            $txt_entete = _('Création') . " :\n";
            $txt_entete .= _('Fin prévue') . " :\n";
            $txt_entete .= _('Agence') . " :\n";
            $txt_entete .= _('Responsable') . " :\n";
            $txt_entete .= _('Catégorie') . " :\n";
            $txt_entete .= _('Statut') . " :\n";
            $txt_entete .= _('Probabilité') . " :\n";
            $txt_entete .= _('Avancement') . ' :';

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

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

            $txt_entete = '';
            $txt_entete = $dos_codecrea . "\n";
            $txt_entete .= $dos_datefinpf . "\n";
            $txt_entete .= $dos_codeage . "\n";
            $txt_entete .= $dos_codesuiv . "\n";

            // Récupération libellé catégorie
            $row = lit_enr_dosc($dos_codedosc);
            if ($row) {
                $row = encode_str($row);
                extract($row);
            }

            $txt_entete .= $dosc_desc . "\n";

            // Récupération libellé statut
            $row = lit_enr_doss($dos_codedoss);
            if ($row) {
                $row = encode_str($row);
                extract($row);
            }
            $txt_entete .= $doss_desc . "\n";
            $txt_entete .= $dos_proba . "%\n";
            $txt_entete .= $dos_avance . "%\n";

            $pdf->MultiCell(73, 4, $txt_entete, 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 du dossier

            $pdf->SetFont('', 'B', 10);
            $pdf->Cell(40, 5, _('Titre') . ' : ', 0, 0, 'R');
            $pdf->SetFont('', '', 8);
            $pdf->MultiCell(150, 4, $dos_titre, 1, 'L');

            $pdf->Ln(1);

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

            $pdf->Ln(1);

            $pdf->SetFont('', 'B', 10);
            $pdf->Cell(40, 5, _('Prix de revient') . ' : ', 0, 0, 'R');
            $pdf->SetFont('', '', 8);

            $pdf->MultiCell(150, 4, full_num_format(px_revient_dos($dos_code, TRUE), '', '', TRUE, '', TRUE, TRUE), 1, 'L');

            $pdf->Ln(1);

            if ($nbdosd <> 0) // S'il y a des détails, on les affiche
            {
                $pdf->SetFillColor(255);
                $pdf->SetTextColor(0);

                $pdf->Ln(2);
                $pdf->SetFont('', 'BU', 12);
                $pdf->Cell(190, 5, _('HISTORIQUE'), 0, 1, 'C');
                $pdf->Ln(2);

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

                $rech = 'SELECT * FROM `' . TBDOSD . "` WHERE dosd_codedos='" . $dos_code . "' ORDER BY dosd_dateact";

                $rows = $db->get_results($rech, ARRAY_A);

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

                    $pdf->Ln(3);
                    $pdf->SetFont('', '', 10);
                    $pdf->SetFillColor(0);
                    $pdf->SetTextColor(255);
                    $pdf->Cell(80, 5, _('Action du') . ' ' . datetolocal($dosd_dateact) . ' ' . _('de') . ' ' . substr($dosd_heured, 0, 5) . ' ' . _('à') . ' ' . substr($dosd_heuref, 0, 5), 1, 1, 'C', 1);
                    $pdf->SetFillColor(255);
                    $pdf->SetTextColor(0);
                    $pdf->Ln(1);

                    $PosY = $pdf->GetY();
                    $pdf->SetDrawColor(125);
                    $pdf->SetLineWidth(0.4);
                    $pdf->Line(10, $PosY, 200, $PosY);
                    $pdf->SetDrawColor(0);
                    $pdf->SetLineWidth(0.2);
                    $pdf->SetDrawColor(220);

                    $pdf->Ln(1);

                    $pdf->SetFont('', '', 8);

                    // Type action
                    $pdf->SetFont('', 'B', 10);
                    $pdf->Cell(40, 5, _('Type action') . ' : ', 0, 0, 'R');
                    // Récupération libellé type action
                    $rech2 = 'SELECT * FROM `' . TBTA . "` WHERE `ta_code` = '$dosd_codeta'";
                    $row2 = $db->get_row($rech2, ARRAY_A);
                    if (is_array($row2)) {
                        $row2 = encode_str($row2);
                        extract($row2);
                    }
                    $pdf->SetFont('', '', 8);
                    $pdf->MultiCell(150, 4, $ta_desc, 1, 'L');
                    $pdf->Ln(1);

                    // Objet
                    $pdf->SetFont('', 'B', 10);
                    $pdf->Cell(40, 5, 'Objet' . ' : ', 0, 0, 'R');
                    $pdf->SetFont('', '', 8);
                    $pdf->MultiCell(150, 4, $dosd_obj, 1, 'L');
                    $pdf->Ln(1);

                    // Résumé
                    $pdf->SetFont('', 'B', 10);
                    $pdf->Cell(40, 5, _('Résumé') . ' : ', 0, 0, 'R');
                    $pdf->SetFont('', '', 8);
                    $pdf->MultiCell(150, 4, $dosd_res, 1, 'L');
                    $pdf->Ln(1);

                    // Conclusion
                    $pdf->SetFont('', 'B', 10);
                    $pdf->Cell(40, 5, _('Conclusion') . ' : ', 0, 0, 'R');
                    $pdf->SetFont('', '', 8);
                    $pdf->MultiCell(150, 4, $dosd_concl, 1, 'L');
                    $pdf->Ln(1);

                    // Intervenants
                    $pdf->SetFont('', 'BU', 10);
                    $pdf->Cell(190, 5, _('Intervenants'), 0, 1, 'C');

                    //...Agences
                    $rech2 = 'SELECT COUNT(*) FROM `' . TBDOSDI . '` WHERE `dosdi_iddosd`=' . $dosd_id . ' AND `dosdi_typinter`=0';
                    $nbres = $db->get_var($rech2);
                    if ($nbres > 0) {
                        $pdf->Ln(1);
                        $pdf->SetFont('', 'IU', 8);
                        $pdf->MultiCell(190, 4, _('Agence'), 0, 1, 'C');
                        $pdf->Ln(1);

                        $row2 = lit_enr_age($dos_codeage, FALSE);
                        if (is_array($row2)) {
                            $row2 = encode_str($row2);
                            extract($row2);
                        }

                        $txt_ctact = '';
                        // Contact principal
                        $txt_cage = $age_resp_nom . ' ' . $age_resp_prenom . ' (' . _('Contact principal') . ')';
                        if (exist_inter_id_in_dosdi($dosd_id, 0, '-1', $dos_codeage, FALSE)) {
                            $txt_ctact .= $txt_cage . "\n";
                        }

                        // Contacts secondaires
                        $rech3 = 'SELECT * FROM `' . TBCAGE . "` WHERE `cage_codeage` = '" . $dos_codeage . "' ORDER BY cage_nom";
                        $rows3 = $db->get_results($rech3, ARRAY_A);
                        if ($rows3) {
                            foreach ($rows3 as $row3) {
                                $row3 = encode_str($row3);
                                extract($row3);

                                $txt_cage = $cage_nom . ' ' . $cage_prenom;
                                $row4 = lit_enr_fonc($cage_codefonc, FALSE);
                                if (is_array($row4)) {
                                    $row4 = encode_str($row4);
                                    extract($row4);
                                    $txt_fonc = $fonc_desc;
                                } else {
                                    $txt_fonc = $cage_codefonc;
                                }
                                $txt_cage .= ' (' . $txt_fonc . ')';
                                if (exist_inter_id_in_dosdi($dosd_id, 0, $cage_id, $dos_codeage, FALSE)) {
                                    $txt_ctact .= $txt_cage . "\n";
                                }
                            }
                        }
                        $pdf->SetFont('', '', 8);
                        $pdf->MultiCell(190, 4, $txt_ctact, 1, 'L');
                        $pdf->Ln(1);
                    }

                    //...Techniciens
                    $rech2 = 'SELECT COUNT(*) FROM `' . TBDOSDI . '` WHERE `dosdi_iddosd`=' . $dosd_id . ' AND `dosdi_typinter`=1';
                    $nbres = $db->get_var($rech2);
                    if ($nbres > 0) {
                        $pdf->Ln(1);
                        $pdf->SetFont('', 'IU', 8);
                        $pdf->MultiCell(190, 4, _('Techniciens'), 0, 1, 'C');
                        $pdf->Ln(1);

                        $txt_ctact = '';

                        $rech3 = 'SELECT * FROM `' . TBTEC . "` WHERE `tec_codeage` = '$dos_codeage' AND `tec_out` = '0' ORDER BY tec_nom";
                        $rows3 = $db->get_results($rech3, ARRAY_A);
                        if ($rows3) {
                            foreach ($rows3 as $row3) {
                                $row3 = encode_str($row3);
                                extract($row3);

                                $txt_tec = $tec_nom . ' ' . $tec_prenom;
                                if (exist_inter_id_in_dosdi($dosd_id, '1', $tec_id, $tec_code, FALSE)) {
                                    $txt_ctact .= $txt_tec . "\n";
                                }
                            }
                        }
                        $pdf->SetFont('', '', 8);
                        $pdf->MultiCell(190, 4, $txt_ctact, 1, 'L');
                        $pdf->Ln(1);
                    }

                    //...Clients
                    $rech2 = 'SELECT COUNT(*) FROM `' . TBDOSDI . '` WHERE `dosdi_iddosd`=' . $dosd_id . ' AND (`dosdi_typinter`=2 OR `dosdi_typinter`=6)';
                    $nbres = $db->get_var($rech2);
                    if ($nbres > 0) {
                        $pdf->Ln(1);
                        $pdf->SetFont('', 'IU', 8);
                        $pdf->MultiCell(190, 4, _('Client'), 0, 1, 'C');
                        $pdf->Ln(1);

                        $row2 = lit_enr_cli($dos_codecli, FALSE);
                        if (is_array($row2)) {
                            $row2 = encode_str($row2);
                            extract($row2);
                        }


                        $txt_ctact = '';
                        // Contact principal
                        $txt_ccli = $cli_nom . ' ' . $cli_prenom . ' (' . _('Contact principal') . ')';
                        if (exist_inter_id_in_dosdi($dosd_id, 2, '-1', $cli_code, FALSE)) {
                            $txt_ctact .= $txt_ccli . "\n";
                        }

                        // Contacts secondaires
                        $rech3 = 'SELECT * FROM `' . TBCCLI . "` WHERE `ccli_codecli` = '" . $cli_code . "' ORDER BY ccli_nom";
                        $rows3 = $db->get_results($rech3, ARRAY_A);
                        if ($rows3) {
                            foreach ($rows3 as $row3) {
                                encode_str($row3);
                                extract($row3);

                                $txt_ccli = $ccli_nom . ' ' . $ccli_prenom;
                                $row4 = lit_enr_fonc($ccli_codefonc, FALSE);
                                if (is_array($row4)) {
                                    $row4 = encode_str($row4);
                                    extract($row4);
                                    $txt_fonc = $fonc_desc;
                                } else {
                                    $txt_fonc = $ccli_codefonc;
                                }
                                $txt_ccli .= ' (' . $txt_fonc . ')';
                                if (exist_inter_id_in_dosdi($dosd_id, 2, $ccli_id, $cli_code, FALSE)) {
                                    $txt_ctact .= $txt_ccli . "\n";
                                }
                            }
                        }

                        // Contacts sites
                        $rech3 = 'SELECT * FROM `' . TBSCLI . "` WHERE `scli_codecli` = '" . $cli_code . "' ORDER BY scli_ste,scli_rnom";
                        $rows3 = $db->get_results($rech3, ARRAY_A);
                        if ($rows3) {
                            foreach ($rows3 as $row3) {
                                $row3 = encode_str($row3);
                                extract($row3);

                                $txt_ccli = $scli_rnom . ' ' . $scli_rprenom;
                                $row4 = lit_enr_fonc($scli_rcodefonc, FALSE);
                                if (is_array($row4)) {
                                    $row4 = encode_str($row4);
                                    extract($row4);
                                    $txt_fonc = $fonc_desc;
                                } else {
                                    $txt_fonc = $scli_rcodefonc;
                                }
                                $txt_ccli .= ' (' . _('Site') . ' ' . $scli_ste . ', ' . $txt_fonc . ')';
                                if (exist_inter_id_in_dosdi($dosd_id, 6, $scli_id, $cli_code, FALSE)) {
                                    $txt_ctact .= $txt_ccli . "\n";
                                }
                            }
                        }

                        $pdf->SetFont('', '', 8);
                        $pdf->MultiCell(190, 4, $txt_ctact, 1, 'L');
                        $pdf->Ln(1);
                    }

                    //...Marques
                    $rech2 = 'SELECT COUNT(*) FROM `' . TBDOSDI . '` WHERE `dosdi_iddosd`=' . $dosd_id . ' AND `dosdi_typinter`=3';
                    $nbres = $db->get_var($rech2);
                    if ($nbres > 0) {
                        $pdf->Ln(1);
                        $pdf->SetFont('', 'IU', 8);
                        $pdf->MultiCell(190, 4, _('Fabricant / Editeur'), 0, 1, 'C');
                        $pdf->Ln(1);

                        $txt_ctact = '';

                        $codemque = '';
                        $codemque = donne_code_mds($dosd_id, 3, FALSE);
                        $rech3 = 'SELECT mque_ste FROM `' . TBMQUE . "` WHERE `mque_code` = '" . $codemque . "'";
                        $row3 = $db->get_row($rech4, ARRAY_A);
                        if (is_array($row3)) {
                            $row3 = encode_str($row3);
                            extract($row3);
                        }

                        $rech3 = 'SELECT * FROM `' . TBCMQUE . "` WHERE `cmque_codemque` = '" . $codemque . "' ORDER BY cmque_nom";
                        $rows3 = $db->get_row($rech3, ARRAY_A);
                        if ($rows3) {
                            foreach ($rows3 as $row3) {
                                $row3 = encode_str($row3);
                                extract($row3);

                                $txt = $cmque_nom . ' ' . $cmque_prenom;
                                $row4 = lit_enr_fonc($cmque_codefonc, FALSE);
                                if (is_array($row4)) {
                                    $row4 = encode_str($row4);
                                    extract($row4);
                                    $txt_fonc = $fonc_desc;
                                } else {
                                    $txt_fonc = $cmque_codefonc;
                                }
                                $txt .= ' (' . $mque_ste . ', ' . $txt_fonc . ')';
                                if (exist_inter_id_in_dosdi($dosd_id, 3, $cmque_id, $codemque, FALSE)) {
                                    $txt_ctact .= $txt . "\n";
                                }
                            }
                        }

                        $pdf->SetFont('', '', 8);
                        $pdf->MultiCell(190, 4, $txt_ctact, 1, 'L');
                        $pdf->Ln(1);
                    }

                    //...Donneurs d'ordres
                    $rech2 = 'SELECT COUNT(*) FROM `' . TBDOSDI . '` WHERE `dosdi_iddosd`=' . $dosd_id . ' AND `dosdi_typinter`=4';
                    $nbres = $db->get_var($rech2);
                    if ($nbres > 0) {
                        $pdf->Ln(1);
                        $pdf->SetFont('', 'IU', 8);
                        $pdf->MultiCell(190, 4, _("Donneur d'ordres"), 0, 1, 'C');
                        $pdf->Ln(1);

                        $txt_ctact = '';

                        $codedo = '';
                        $codedo = donne_code_mds($dosd_id, 4, FALSE);
                        $rech3 = 'SELECT do_nom FROM `' . TBDO . "` WHERE `do_code` = '" . $codedo . "'";
                        $row3 = $db->get_row($rech3, ARRAY_A);
                        if (is_array($row3)) {
                            $row3 = encode_str($row3);
                            extract($row3);
                        }

                        $rech3 = 'SELECT * FROM `' . TBCDO . "` WHERE `cdo_codedo` = '" . $codedo . "' ORDER BY cdo_nom";
                        $rows3 = $db->get_results($rech3, ARRAY_A);
                        if ($rows3) {
                            foreach ($rows3 as $row3) {
                                $row3 = encode_str($row3);
                                extract($row3);

                                $txt = $cdo_nom . ' ' . $cdo_prenom;
                                $row4 = lit_enr_fonc($cdo_codefonc, FALSE);
                                if (is_array($row4)) {
                                    $row4 = encode_str($row4);
                                    extract($row4);
                                    $txt_fonc = $fonc_desc;
                                } else {
                                    $txt_fonc = $cdo_codefonc;
                                }
                                $txt .= ' (' . $do_nom . ', ' . $txt_fonc . ')';
                                if (exist_inter_id_in_dosdi($dosd_id, 4, $cdo_id, $codedo, FALSE)) {
                                    $txt_ctact .= $txt . "\n";
                                }
                            }
                        }

                        $pdf->SetFont('', '', 8);
                        $pdf->MultiCell(190, 4, $txt_ctact, 1, 'L');
                        $pdf->Ln(1);
                    }

                    //...Sous-traitants
                    $rech2 = 'SELECT COUNT(*) FROM `' . TBDOSDI . '` WHERE `dosdi_iddosd`=' . $dosd_id . ' AND `dosdi_typinter`=5';
                    $nbres = $db->get_var($rech2);
                    if ($nbres > 0) {
                        $pdf->Ln(1);
                        $pdf->SetFont('', 'IU', 8);
                        $pdf->MultiCell(190, 4, _('Sous-traitant'), 0, 1, 'C');
                        $pdf->Ln(1);

                        $txt_ctact = '';

                        $codest = '';
                        $codest = donne_code_mds($dosd_id, 5, FALSE);
                        $rech3 = 'SELECT st_nom FROM `' . TBST . "` WHERE `st_code` = '" . $codest . "'";
                        $row3 = $db->get_row($rech3, ARRAY_A);
                        if ($row3) {
                            $row3 = encode_str($row3);
                            extract($row3);
                        }

                        $rech3 = 'SELECT * FROM `' . TBCST . "` WHERE `cst_codest` = '" . $codest . "' ORDER BY cst_nom";
                        $rows3 = $db->get_results($rech3, ARRAY_A);
                        if ($rows3) {
                            foreach ($rows3 as $row3) {
                                $row3 = encode_str($row3);
                                extract($row3);

                                $txt = $cst_nom . ' ' . $st_prenom;
                                $row4 = lit_enr_fonc($cst_codefonc, FALSE);
                                if (is_array($row4)) {
                                    $row4 = encode_str($row4);
                                    extract($row4);
                                    $txt_fonc = $fonc_desc;
                                } else {
                                    $txt_fonc = $cst_codefonc;
                                }
                                $txt .= ' (' . $st_nom . ', ' . $txt_fonc . ')';
                                if (exist_inter_id_in_dosdi($dosd_id, 5, $cst_id, $codest, FALSE)) {
                                    $txt_ctact .= $txt . "\n";
                                }
                            }
                        }

                        $pdf->SetFont('', '', 8);
                        $pdf->MultiCell(190, 4, $txt_ctact, 1, 'L');
                        $pdf->Ln(1);
                    }
                }
            }

            close_database();

            $PosY = $pdf->GetY();
            $pdf->SetDrawColor(125);
            $pdf->SetLineWidth(0.4);
            $pdf->Line(10, $PosY, 200, $PosY);
            $pdf->SetDrawColor(0);
            $pdf->SetLineWidth(0.2);
            $pdf->SetDrawColor(220);

            $url_pdf = $url_gfc . '/pj/' . _('Dossier') . '_' . $dos_code . '.pdf';
            $pdf->Output($url_pdf, 'FI');
            killfile($url_pdf);
            close_fen_auto('', '');
        }
    } else {
        $pbm_dospdf = TRUE;
    }
} else {
    $pbm_dospdf = TRUE;
}

if ($pbm_dospdf == TRUE) {
    close_fen_auto('', '');
}
