<?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");

$pdf->Ln(1);
$pdf->SetFont('', '', 10);
$pdf->SetFillColor(0);
$pdf->SetTextColor(255);
$pdf->Cell(80, 5, _("Relevé") . ' : ' . $rpdt_code, 1, 0, 'C', 1);
$pdf->SetFillColor(255);
$pdf->SetTextColor(0);
$PosX = $pdf->GetX();
$PosY = $pdf->GetY();
$pdf->Ln();
// Code-barre
$pdf->write1DBarcode($rpdt_code, 'C39', $PosX + 10, $PosY, 55, 5, 0.4, $style, 'N');

// Relevé effectué "par"
$pdf->SetFont('', 'I', 8);

$row2 = lit_enr_tec($rpdt_codetec);
if ($row2) {
    $row2 = encode_str($row2);
    extract($row2);
}

$pdf->Cell(140, 4, _("Fiche créée le") . ' ' . datetolocal($rpdt_datecrea) . '. ' . _("Relevé effectué par") . ' ' . $tec_nom . ' ' . $tec_prenom . '.', 0, 0, 'L');
$pdf->SetFont('', '', 8);

if (datetolocal($rpdt_dateout) == "") {
    $pdf->Ln(5);
} else {
    $pdf->SetFont('', 'BI', 8);
    $pdf->Cell(137, 5, _("Sorti du parc le") . ' ' . datetolocal($rpdt_dateout), 0, 1, 'R');
    $pdf->SetFont('', '', 8);
}

// Site d'utilisation
$nom_site = nom_scli($rpdt_idsite, FALSE, FALSE, FALSE);

$pdf->SetFont('', 'B', 8);
$pdf->Cell(30, 4, _("Site") . ' : ', 0, 0, 'R');
$pdf->SetFont('', '', 8);
$pdf->Cell(247, 4, $nom_site, 0, 1, 'L');

// Catégorie
$row2 = lit_enr_rpcat($rpdt_codecat);;
if ($row2) {
    $row2 = encode_str($row2);
    extract($row2);
}
$pdf->SetFont('', 'B', 8);
$pdf->Cell(30, 4, _("Catégorie") . ' : ', 0, 0, 'R');
$pdf->SetFont('', '', 8);
$pdf->Cell(247, 4, $rpcat_desc, 0, 1, 'L');

// Marque
$row2 = lit_enr_mque($rpdt_codema);
if ($row2) {
    $row2 = encode_str($row2);
    extract($row2);
}
$pdf->SetFont('', 'B', 8);
$pdf->Cell(30, 4, _("Marque") . ' : ', 0, 0, 'R');
$pdf->SetFont('', '', 8);
$pdf->Cell(247, 4, $mque_ste, 0, 1, 'L');

// Modèle & NS
$pdf->SetFont('', 'B', 8);
$pdf->Cell(30, 4, _("Modèle / NS") . ' : ', 0, 0, 'R');
$pdf->SetFont('', '', 8);
$pdf->Cell(247, 4, $rpdt_modele . ' / ' . $rpdt_ns, 0, 1, 'L');

// Emplacement
$pdf->SetFont('', 'B', 8);
$pdf->Cell(30, 4, _("Emplacement") . ' : ', 0, 0, 'R');
$pdf->SetFont('', '', 8);
$pdf->Cell(247, 4, $rpdt_empl, 0, 1, 'L');

// Codage
$pdf->SetFont('', 'B', 8);
$pdf->Cell(30, 4, _("Codage Inventaire") . ' : ', 0, 0, 'R');
$pdf->SetFont('', '', 8);
$pdf->Cell(247, 4, $rpdt_codep, 0, 0, 'L');
$posx_cb = 30 + ((strlen($rpdt_codep) * 8) * 25.4 / 72) + 10;
$PosY = $pdf->GetY();
$pdf->Ln();
// Code-barre
$pdf->write1DBarcode($rpdt_code, 'C39', $posx_cb, $PosY, 55, 4, 0.4, $style, 'N');

// Utilisateur
$pdf->SetFont('', 'B', 8);
$pdf->Cell(30, 4, _("Utilisateur") . ' : ', 0, 0, 'R');
$pdf->SetFont('', '', 8);
$pdf->Cell(247, 4, $rpdt_util, 0, 1, 'L');

// Date Achat
$pdf->SetFont('', 'B', 8);
$pdf->Cell(30, 4, _("Date d'achat") . ' : ', 0, 0, 'R');
$pdf->SetFont('', '', 8);
$pdf->Cell(247, 4, datetolocal($rpdt_dateach), 0, 1, 'L');

// Fin de Garantie
$pdf->SetFont('', 'B', 8);
$pdf->Cell(30, 4, _("Fin de garantie") . ' : ', 0, 0, 'R');
$pdf->SetFont('', '', 8);
if (datetolocal($rpdt_fingar) <> "") {
    if (echeance_depassee_date($datea, $rpdt_fingar) == TRUE)
        $pdf->SetFont('', 'BI', 8);
}
$pdf->Cell(247, 4, datetolocal($rpdt_fingar), 0, 1, 'L');

// Gtie Sur site / propriétaire
$pdf->SetFont('', 'B', 8);
$pdf->Cell(30, 4, _("G. site / Propriétaire") . ' : ', 0, 0, 'R');
$pdf->SetFont('', '', 8);
$pdf->Cell(247, 4, $non_oui[$rpdt_gars] . ' / ' . $non_oui[$rpdt_prop], 0, 1, 'L');

// Validation
$pdf->SetFont('', 'B', 8);
$pdf->Cell(30, 4, _("Validé par") . ' : ', 0, 0, 'R');
$pdf->SetFont('', '', 8);
$pdf->Cell(247, 4, $rpdt_signataire, 0, 1, 'L');

/********************************/
/* Informations complémentaires */
/********************************/
$pdf->Ln(2);
$pdf->SetFont('', 'BU', 10);
$pdf->Cell(277, 5, _("INFORMATIONS COMPLEMENTAIRES"), '', 1, 'L');
$pdf->Ln(2);

/*********/
/* Notes */
/*********/
$pdf->SetFont('', 'B', 8);
$pdf->Cell(30, 4, _("Notes") . ' : ', 0, 0, 'R');
$pdf->SetFont('', '', 8);
$pdf->MultiCell(247, 4, $rpdt_nota, 0, 'L');
$pdf->Ln(2);

/************/
/* Licences */
/************/
$db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
$rech2 = "SELECT * FROM `" . TBRLIC . "` WHERE rlic_dateout = '0000-00-00' AND rlic_codecli = '" . $rel_codecli . "'";
$tab_coderlic = explode("-", $rpdt_coderlic);
if (count($tab_coderlic) <> 0) {
    if (count($tab_coderlic) > 1)
        $rech2 .= " AND (";
    else
        $rech2 .= " AND";
    for ($i = 0; $i < count($tab_coderlic); $i++) {
        $rech2 .= " rlic_code = '" . $tab_coderlic[$i] . "' OR";
    }
    $rech2 = substr($rech2, 0, strlen($rech2) - 3);
    if (count($tab_coderlic) > 1)
        $rech2 .= " )";
}
$rech2 .= " ORDER BY rlic_code";
$rows2 = $db->get_results($rech2, ARRAY_A);
$db->disconnect();
if ($rows2) {
    $warn = FALSE;

    $pdf->SetFont('', 'IB', 8);
    $pdf->Cell(7);
    $pdf->Cell(30, 4, _("Licences utilisées") . ' : ', 'LT', 0, 'R');

    $pdf->SetFont('', 'IU', 7); // Titres
    $pdf->Cell(30, 4, _("Code Fiche Lic."), 1, 0, 'C');
    $pdf->Cell(14, 4, _("Dte Relevé"), 1, 0, 'C');
    $pdf->Cell(58, 4, _("Marque"), 1, 0, 'C');
    $pdf->Cell(58, 4, _("Modèle / Version"), 1, 0, 'C');
    $pdf->Cell(14, 4, _("Validité"), 1, 1, 'C');
    $pdf->SetFont('', 'I', 8);

    foreach ($rows2 as $row2) {
        $row2 = encode_str($row2);
        extract($row2);

        $pdf->Cell(7);
        $pdf->Cell(30, 4, '', 'LR', 0, 'R');
        $pdf->SetFont('', 'I', 7);
        $pdf->Cell(30, 4, $rlic_code, 'LR', 0, 'L');
        $pdf->Cell(14, 4, datetolocal($rlic_daterel), 'LR', 0, 'C');

        $row3 = lit_enr_mque($rlic_codema);
        if ($row3) {
            $row3 = encode_str($row3);
            extract($row3);
        }
        $pdf->Cell(58, 4, $mque_ste, 'LR', 0, 'L');
        $pdf->Cell(58, 4, $rlic_modele, 'LR', 0, 'L');

        // Alertes complémentaires
        $txt_warn = "";
        if ($rlic_legal == FALSE) {
            $warn = TRUE;
            $txt_warn .= "I";
        }
        $nb_rlic_utilisees = 0;

        $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
        $rech3 = "SELECT * FROM `" . TBRPDT . "` WHERE `rpdt_codecli` = '" . $rpdt_codecli . "'";
        $rows3 = $db->get_results($rech3, ARRAY_A);
        $db->disconnect();
        if ($rows3) {
            foreach ($rows3 as $row3) {
                $row3 = encode_str($row3);
                if (strpos($row3["rpdt_coderlic"], $rlic_code) !== false)
                    $nb_rlic_utilisees++;
            }
        }
        if ($nb_rlic_utilisees >= $rlic_maxcli) {
            $warn = TRUE;
            $txt_warn .= "M";
        }
        if (datetolocal($rlic_dateval) <> "") {
            if ((echeance_depassee_date($datea, $rlic_dateval) == TRUE)  AND (datetolocal($rlic_dateout) == ""))
                $warn = TRUE;
            $txt_warn .= "V";
        }

        if ($txt_warn <> "") {
            $pdf->Cell(14, 4, datetolocal($rlic_dateval), 'LR', 0, 'C');
            $pdf->Cell(5, 4, $txt_warn, 0, 1, 'L');
        } else {
            $pdf->Cell(14, 4, datetolocal($rlic_dateval), 'LR', 1, 'C');
        }

        if ($rlic_version <> "") {
            $pdf->Cell(7);
            $pdf->Cell(30, 4, '', 'LR', 0, 'L');
            $pdf->Cell(30, 4, '', 'LR', 0, 'L');
            $pdf->Cell(14, 4, '', 'LR', 0, 'L');
            $pdf->Cell(58, 4, '', 'LR', 0, 'L');
            $pdf->Cell(58, 4, _("Version") . ' : ' . $rlic_version, 'LR', 0, 'L');
            $pdf->Cell(14, 4, '', 'LR', 1, 'L');
        }
    }

    $PosY = $pdf->GetY();
    $pdf->Line(17, $PosY, 221, $PosY); // On "ferme" le tableau

    // Légende si alertes affichées
    if ($warn == TRUE) {
        $pdf->SetFont('', 'I', 8);
        $pdf->Cell(7);
        $pdf->Cell(204, 4, _("Légende") . ' : \'I\'=' . _("Licence illégale") . ' / \'M\'=' . _("Maximum dépassé") . ' / \'V\'=' . _("Validité dépassée"), 0, 1, 'R');
    }
} else {
    $pdf->SetFont('', 'B', 8);
    $pdf->Cell(30, 4, _("Licences utilisées") . ' : ', 0, 0, 'R');
    $pdf->SetFont('', '', 8);
    $pdf->Cell(247, 4, _("Aucune"), 0, 1, 'L');
}
$pdf->SetFont('', '', 8);

$pdf->Ln(2);

/**********/
/* Réseau */
/**********/
$pdf->SetFont('', 'IB', 8);
$pdf->Cell(7);
$pdf->Cell(30, 4, _("Réseau") . ' : ', 'LTR', 0, 'R');

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

// Nom du poste
$pdf->Cell(30, 4, _("Nom du poste") . ' : ', 'LTR', 0, 'R');
$pdf->Cell(144, 4, $rpdt_nomp, 'LTR', 1, 'L');

// Groupe Travail
$pdf->Cell(7);
$pdf->Cell(30, 4, '', 'LR', 0, 'R');
$pdf->Cell(30, 4, _("Groupe de Travail") . ' : ', 'R', 0, 'R');
$pdf->Cell(144, 4, $rpdt_gt, 'R', 1, 'L');

// Domaine
$pdf->Cell(7);
$pdf->Cell(30, 4, '', 'LR', 0, 'R');
$pdf->Cell(30, 4, _("Domaine") . ' : ', 'R', 0, 'R');
$pdf->Cell(144, 4, $rpdt_dom, 'R', 1, 'L');

// Login / MDP
$pdf->Cell(7);
$pdf->Cell(30, 4, '', 'LR', 0, 'R');
$pdf->Cell(30, 4, _("Login / MDP") . ' : ', 'R', 0, 'R');
$pdf->Cell(144, 4, $rpdt_login . " / " . $rpdt_mdp, 'R', 1, 'L');

// MAC
$pdf->Cell(7);
$pdf->Cell(30, 4, '', 'LR', 0, 'R');
$pdf->Cell(30, 4, _("Adresse MAC") . ' : ', 'R', 0, 'R');
$pdf->Cell(144, 4, $rpdt_mac, 'R', 1, 'L');

// Mode IP
$pdf->Cell(7);
$pdf->Cell(30, 4, '', 'LR', 0, 'R');
$pdf->Cell(30, 4, _("Mode IP") . ' : ', 'R', 0, 'R');
$pdf->Cell(144, 4, $maj_modeip[$rpdt_modeip], 'R', 1, 'L');

// serveur DHCP
$pdf->Cell(7);
$pdf->Cell(30, 4, '', 'LR', 0, 'R');
$pdf->Cell(30, 4, _("Serveur DHCP") . ' : ', 'R', 0, 'R');
$pdf->Cell(144, 4, $non_oui[$rpdt_sdhcp], 'R', 1, 'L');

// Plage IP / Masque
$pdf->Cell(7);
$pdf->Cell(30, 4, '', 'LR', 0, 'R');
$pdf->Cell(30, 4, _("Plage IP / Masque") . ' : ', 'R', 0, 'R');
$pdf->Cell(144, 4, $rpdt_ip1 . " / " . $rpdt_ip2 . " / " . $rpdt_msdhcp, 'R', 1, 'L');

// IP / Masque / Passerelle
$pdf->Cell(7);
$pdf->Cell(30, 4, '', 'LR', 0, 'R');
$pdf->Cell(30, 4, _("IP / Masque / Pass.") . ' : ', 'R', 0, 'R');
$pdf->Cell(144, 4, $rpdt_ip . " / " . $rpdt_masq . " / " . $rpdt_pass, 'R', 1, 'L');

// Numéros de prises
$pdf->Cell(7);
$pdf->Cell(30, 4, '', 'LR', 0, 'R');
$pdf->Cell(30, 4, _("Numéro de prise") . ' : ', 'R', 0, 'R');
$pdf->Cell(144, 4, "Murale : " . $rpdt_npm . " Baie : " . $rpdt_mpb . " Commutateur : " . $rpdt_npc, 'R', 1, 'L');

// SNMP / WOL
$pdf->Cell(7);
$pdf->Cell(30, 4, '', 'LR', 0, 'R');
$pdf->Cell(30, 4, _("SNMP / WEP") . ' : ', 'R', 0, 'R');
$pdf->Cell(144, 4, $non_oui[$rpdt_snmp] . " / " . $non_oui[$rpdt_wol], 'R', 1, 'L');

// SID
$pdf->Cell(7);
$pdf->Cell(30, 4, '', 'LR', 0, 'R');
$pdf->Cell(30, 4, _("WiFi (SID)") . ' : ', 'R', 0, 'R');
$pdf->Cell(144, 4, $rpdt_sid, 'R', 1, 'L');

// WEP
$pdf->Cell(7);
$pdf->Cell(30, 4, '', 'LR', 0, 'R');
$pdf->Cell(30, 4, _("WEP (WiFi)") . ' : ', 'R', 0, 'R');
$pdf->Cell(144, 4, $rpdt_wep, 'R', 1, 'L');

$PosY = $pdf->GetY();
$pdf->Line(17, $PosY, 221, $PosY); // On "ferme" le tableau

$pdf->Ln(2);

/*******************/
/* Télémaintenance */
/*******************/
$pdf->SetFont('', 'IB', 8);
$pdf->Cell(7);
$pdf->Cell(30, 4, _("Télémaintenance") . ' : ', 'LTR', 0, 'R');

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

// Type d'accès
$pdf->Cell(30, 4, _("Type d'accès") . ' : ', 'LTR', 0, 'R');
$row2 = lit_enr_tmta($rpdt_codeta);
if ($row2) {
    $row2 = encode_str($row2);
    extract($row2);
}
$pdf->Cell(144, 4, $rlptmta_desc, 'LTR', 1, 'L');

// Mode d'accès
$pdf->Cell(7);
$pdf->Cell(30, 4, '', 'LR', 0, 'R');
$pdf->Cell(30, 4, _("Mode d'accès") . ' : ', 'R', 0, 'R');
$pdf->Cell(144, 4, $maj_typesma[$rpdt_tma], 'R', 1, 'L');

// Logiciel télémaintenance
$pdf->Cell(7);
$pdf->Cell(30, 4, '', 'LR', 0, 'R');
$pdf->Cell(30, 4, _("Logiciel télém.") . ' : ', 'R', 0, 'R');
$row2 = lit_enr_rlptml($rpdt_codel);
if ($row2) {
    $row2 = encode_str($row2);
    extract($row2);
}
$pdf->Cell(144, 4, $rlptml_desc, 'R', 1, 'L');

// Mode Service
$pdf->Cell(7);
$pdf->Cell(30, 4, '', 'LR', 0, 'R');
$pdf->Cell(30, 4, _("Mode service ?") . ' : ', 'R', 0, 'R');
$pdf->Cell(144, 4, $non_oui[$rpdt_tser], 'R', 1, 'L');

// Lien d'accès
$pdf->Cell(7);
$pdf->Cell(30, 4, '', 'LR', 0, 'R');
$pdf->Cell(30, 4, _("Lien d'accès") . ' : ', 'R', 0, 'R');
$pdf->Cell(144, 4, $rpdt_tlien, 'R', 1, 'L');

// Login/MDP
$pdf->Cell(7);
$pdf->Cell(30, 4, '', 'LR', 0, 'R');
$pdf->Cell(30, 4, _("Login / MDP") . ' : ', 'R', 0, 'R');
$pdf->Cell(144, 4, $rpdt_tlogin . " / " . $rpdt_tmdp, 'R', 1, 'L');

// Arrêt exploitation
$pdf->Cell(7);
$pdf->Cell(30, 4, '', 'LR', 0, 'R');
$pdf->Cell(30, 4, _("Arrêt exploitation ?") . ' : ', 'R', 0, 'R');
$pdf->Cell(144, 4, $non_oui[$rpdt_tae], 'R', 1, 'L');

// Redémarrage
$pdf->Cell(7);
$pdf->Cell(30, 4, '', 'LR', 0, 'R');
$pdf->Cell(30, 4, _("Redémarrage ?") . ' : ', 'R', 0, 'R');
$pdf->Cell(144, 4, $non_oui[$rpdt_tred], 'R', 1, 'L');

$PosY = $pdf->GetY();
$pdf->Line(17, $PosY, 221, $PosY); // On "ferme" le tableau

$pdf->Ln(2);

/****************/
/* Mises à jour */
/****************/
$pdf->SetFont('', 'IB', 8);
$pdf->Cell(7);
$pdf->Cell(30, 4, _("Mises à jour") . ' : ', 'LTR', 0, 'R');

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

// Mode
$pdf->Cell(30, 4, 'Mode : ', 'LTR', 0, 'R');
$row2 = lit_enr_rlpmm($rpdt_codem);
if ($row2) {
    $row2 = encode_str($row2);
    extract($row2);
}
$pdf->Cell(144, 4, $rlpmm_desc, 'LTR', 1, 'L');

// Fréquence/type
$pdf->Cell(7);
$pdf->Cell(30, 4, '', 'LR', 0, 'R');
$pdf->Cell(30, 4, _("Fréquence") . ' : ', 'R', 0, 'R');
$txt_pre = "";
$row2 = lit_enr_per($rpdt_mper);
if ($row2) {
    $row2 = encode_str($row2);
    extract($row2);
    if ($per_nbj <> 0)
        $txt_per = $per_desc . " (" . _("tous les") . " " . $per_nbj . " " . _("jours") . ")";
    else
        $txt_per = $per_desc . " (" . _("à la demande") . ")";
}
$pdf->Cell(144, 4, $txt_per . " -> " . _("type") . " " . $maj_types[$rpdt_mmode], 'R', 1, 'L');

// Date échéance
$pdf->Cell(7);
$pdf->Cell(30, 4, '', 'LR', 0, 'R');
$pdf->Cell(30, 4, _("Echéance") . ' : ', 'R', 0, 'R');
$txt_edep = "";
if (datetolocal($rpdt_mdval) <> "") {
    if (echeance_depassee_date($datea, $rpdt_mdval) == TRUE)
        $txt_edep = " (" . _("Echéance dépassée") . ")";
}
$pdf->Cell(144, 4, datetolocal($rpdt_mdval) . $txt_edep, 'R', 1, 'L');

// Date mise à jour
$pdf->Cell(7);
$pdf->Cell(30, 4, '', 'LR', 0, 'R');
$pdf->Cell(30, 4, _("Dernière MAJ") . ' : ', 'R', 0, 'R');
$pdf->Cell(144, 4, datetolocal($rpdt_mdlmaj), 'R', 1, 'L');

// Arrêt exploitation
$pdf->Cell(7);
$pdf->Cell(30, 4, '', 'LR', 0, 'R');
$pdf->Cell(30, 4, _("Arrêt exploitation ?") . ' : ', 'R', 0, 'R');
$pdf->Cell(144, 4, $non_oui[$rpdt_mae], 'R', 1, 'L');

// Redémarrage
$pdf->Cell(7);
$pdf->Cell(30, 4, '', 'LR', 0, 'R');
$pdf->Cell(30, 4, _("Redémarrage ?") . ' : ', 'R', 0, 'R');
$pdf->Cell(144, 4, $non_oui[$rpdt_mred], 'R', 1, 'L');

$PosY = $pdf->GetY();
$pdf->Line(17, $PosY, 221, $PosY); // On "ferme" le tableau

$pdf->Ln(2);

/**************/
/* Connexions */
/**************/
$db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
$rech2 = "SELECT * FROM `" . TBRPDT . "`, `" . TBMQUE . "`, `" . TBRPCAT . "` WHERE ";
$rech2 .= TBRPDT . ".rpdt_codema = " . TBMQUE . ".mque_code AND " . TBRPDT . ".rpdt_codecat = " . TBRPCAT . ".rpcat_code";
$rech2 .= " AND " . TBRPDT . ".rpdt_codecli='" . $rpdt_codecli . "' AND " . TBRPDT . ".rpdt_dateout='0000-00-00' AND " . TBRPDT . ".rpdt_code<>'" . $rpdt_code . "'";
$rech2 .= " ORDER BY " . TBRPDT . ".rpdt_code";
$rows2 = $db->get_results($rech2, ARRAY_A);
$db->disconnect();

if ($rows2) {
    $i = 0;
    foreach ($rows2 as $row2) {
        $row2 = encode_str($row2);
        $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
        $rech3 = "SELECT * FROM `" . TBCNX . "`  WHERE (cnx_p1 = '" . $rpdt_code . "' AND cnx_p2 = '" . $row2["rpdt_code"] . "'";
        $rech3 .= " AND (cnx_type = '1' OR cnx_type = '2' OR cnx_type = '3' OR cnx_type = '4'))";
        $rech3 .= " OR ((cnx_p1 = '" . $rpdt_code . "' OR cnx_p2 = '" . $row2["rpdt_code"] . "')";
        $rech3 .= " OR  (cnx_p1 = '" . $row2["rpdt_code"] . "' OR cnx_p2 = '" . $rpdt_code . "')";
        $rech3 .= " AND cnx_type = '5')";
        $row3 = $db->get_row($rech3, ARRAY_A);
        $db->disconnect();
        if ($row3) {
            $row3 = encode_str($row3);
            extract($row3);

            if ($i == 0) {
                $pdf->SetFont('', 'IB', 8);
                $pdf->Cell(7);
                $pdf->Cell(30, 4, _("Connexions") . ' : ', 'LTR', 0, 'R');

                $pdf->SetFont('', 'IU', 7); // Titres
                $pdf->Cell(21, 4, _("Liaison"), 1, 0, 'C');
                $pdf->Cell(40, 4, _("Code Fiche/Inventaire"), 1, 0, 'C');
                $pdf->Cell(65, 4, _("Catégorie"), 1, 0, 'C');
                $pdf->Cell(65, 4, _("Marque / Modèle / NS / Emplacement"), 1, 1, 'C');
                $pdf->SetFont('', 'I', 8);
            }

            // Ligne 1
            $pdf->Cell(7);
            $pdf->Cell(30, 4, '', 'LR', 0, 'C');
            $pdf->Cell(21, 4, $cnxm_types[$cnx_type], 'LR', 0, 'L');
            $pdf->Cell(40, 4, $row2["rpdt_code"], 'LR', 0, 'L');
            $pdf->Cell(65, 4, $row2["rpcat_desc"], 'LR', 0, 'L');
            $pdf->Cell(65, 4, $row2["mque_ste"], 'LR', 1, 'L');
            // Ligne 2
            $pdf->Cell(7);
            $pdf->Cell(30, 4, '', 'LR', 0, 'L');
            $pdf->Cell(21, 4, '', 'LR', 0, 'L');
            $pdf->Cell(40, 4, "(" . $row2["rpdt_codep"] . ")", 'LR', 0, 'L');
            $pdf->Cell(65, 4, '', 'LR', 0, 'L');
            $pdf->Cell(65, 4, $row2["rpdt_modele"], 'LR', 1, 'L');
            // Ligne 3
            $pdf->Cell(7);
            $pdf->Cell(30, 4, '', 'LR', 0, 'L');
            $pdf->Cell(21, 4, '', 'LR', 0, 'L');
            $pdf->Cell(40, 4, '', 'LR', 0, 'L');
            $pdf->Cell(65, 4, '', 'LR', 0, 'L');
            $pdf->Cell(65, 4, "Empl. : " . $row2["rpdt_empl"], 'LR', 1, 'L');
            // Ligne 4
            $pdf->Cell(7);
            $pdf->Cell(30, 4, '', 'LR', 0, 'L');
            $pdf->Cell(21, 4, '', 'LR', 0, 'L');
            $pdf->Cell(40, 4, '', 'LR', 0, 'L');
            $pdf->Cell(65, 4, '', 'LR', 0, 'L');
            $pdf->Cell(65, 4, "NS : " . $row2["rpdt_ns"], 'LR', 1, 'L');

            $i++;
        }
    }

    if ($i <> 0) {
        $PosY = $pdf->GetY();
        $pdf->Line(17, $PosY, 238, $PosY); // On "ferme" le tableau
    }
} else {
    $pdf->SetFont('', 'IB', 8);
    $pdf->Cell(7);
    $pdf->Cell(30, 4, _("Connexions") . ' : ', 0, 0, 'R');
    $pdf->SetFont('', 'I', 8);
    $pdf->Cell(277, 4, _("Aucune connexion déclarée"), 0, 1, 'L');
}

$pdf->Ln(2);

/************/
/* Contrats */
/************/
$db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
$rech2 = "SELECT * FROM `" . TBCOCL . "` WHERE `cocl_coderlp` LIKE '%" . $rpdt_code . "%'";
$rech2 .= " ORDER BY `cocl_code`";
$rows2 = $db->get_results($rech2, ARRAY_A);
$db->disconnect();

if ($rows2) {
    $warn = FALSE;

    $pdf->SetFont('', 'IB', 8);
    $pdf->Cell(7);
    $pdf->Cell(30, 4, _("Contrats") . ' : ', 'LTR', 0, 'R');

    $pdf->SetFont('', 'IU', 7); // Titres
    $pdf->Cell(45, 4, _("Code"), 1, 0, 'C');
    $pdf->Cell(43, 4, _("Créé le"), 1, 0, 'C');
    $pdf->Cell(43, 4, _("Début le"), 1, 0, 'C');
    $pdf->Cell(43, 4, _("Fin le"), 1, 1, 'C');
    $pdf->SetFont('', 'I', 8);

    foreach ($rows2 as $row2) {
        $row2 = encode_str($row2);
        $echeance_ok = TRUE;
        if (datetolocal($row2["cocl_datef"]) <> "") {
            if (echeance_depassee_date($datea, $row2["cocl_datef"]) == TRUE)
                $echeance_ok = FALSE;
        }

        $pdf->Cell(7);
        $pdf->Cell(30, 4, '', 'LR', 0, 'C');
        $pdf->Cell(45, 4, $row2["cocl_code"], 'LR', 0, 'L');
        $pdf->Cell(43, 4, datetolocal($row2["cocl_datecrea"]), 'LR', 0, 'C');
        $pdf->Cell(43, 4, datetolocal($row2["cocl_dated"]), 'LR', 0, 'C');

        // Alertes complémentaires
        $txt_warn = "";
        if (datetolocal($row2["cocl_datesig"]) == "") {
            $warn = TRUE;
            $txt_warn .= "S";
        }
        if ((datetolocal($row2["cocl_datefin"]) <> "") OR ($echeance_ok == FALSE)) {
            $warn = TRUE;
            $txt_warn .= "T";
        }

        if ($txt_warn <> "") {
            $pdf->Cell(43, 4, datetolocal($row2["cocl_datef"]), 'LR', 0, 'C');
            $pdf->Cell(5, 4, $txt_warn, 0, 1, 'L');
        } else {
            $pdf->Cell(43, 4, datetolocal($row2["cocl_datef"]), 'LR', 1, 'C');
        }
    }

    $PosY = $pdf->GetY();
    $pdf->Line(17, $PosY, 221, $PosY); // On "ferme" le tableau

    // Légende si alertes affichées
    if ($warn == TRUE) {
        $pdf->SetFont('', 'I', 8);
        $pdf->Cell(7);
        $pdf->Cell(204, 4, _("Légende") . ' : \'S\': ' . _("Non signé") . ' / \'T\': ' . _("Terminé"), 0, 1, 'R');
    }
} else {
    $pdf->SetFont('', 'IB', 8);
    $pdf->Cell(7);
    $pdf->Cell(30, 4, _("Contrats") . ' : ', 0, 0, 'R');
    $pdf->SetFont('', 'I', 8);
    $pdf->Cell(277, 4, _("Aucun contrat couvrant ce matériel"), 0, 1, 'L');
}

/*************/
/* Problèmes */
/*************/
if ($pbm == 1) {
    $pdf->Ln(2);
    $pdf->SetFont('', 'BU', 10);
    $pdf->Cell(277, 5, _("PROBLEMES"), 0, 1, 'C');
    $pdf->Ln(2);

    $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
    $rech2 = "SELECT * FROM `" . TBRPBM . "` WHERE `rpbm_coderlp` = '" . $rpdt_code . "' ORDER BY `rpbm_datecrea`";
    $rows2 = $db->get_results($rech2, ARRAY_A);
    $db->disconnect();
    if ($rows2) {
        $pdf->SetFont('', 'IU', 7); // Titres
        $pdf->Cell(30, 4, _("Déclaré le"), 1, 0, 'C');
        $pdf->Cell(73, 4, _("Déclaré par"), 1, 0, 'C');
        $pdf->Cell(144, 4, _("Site / Problème"), 1, 0, 'C');
        $pdf->Cell(30, 4, _("Traité le"), 1, 1, 'C');
        $pdf->SetFont('', 'I', 8);

        foreach ($rows2 as $row2) {
            $row2 = encode_str($row2);
            extract($row2);

            $pdf->SetFont('', 'IB', 7);
            $pdf->Cell(30, 4, datetolocal($rpbm_datecrea), 'LR', 0, 'L');
            $pdf->Cell(73, 4, $rpbm_signale, 'LR', 0, 'L');

            $nom_site = "";
            switch ($rpbm_idsite) {
                case 0 :
                    $nom_site = _("Site principal");
                    break;
                default :
                    $row3 = lit_enr_scli_id($rpbm_idsite);
                    if ($row3) {
                        $row3 = encode_str($row3);
                        extract($row3);
                        $nom_site .= $scli_ste;
                        $nom_site .= " (" . Retournecp_Id($scli_ville, TRUE) . " " . Retourneville_Id($scli_ville, TRUE) . ")";
                    }
            }
            $pdf->Cell(144, 4, $nom_site, 'LR', 0, 'L');
            if (($rpbm_datett <> "0000-00-00") AND ($rpbm_datett <> NULL))
                $pdf->Cell(30, 4, datetolocal($rpbm_datett) . ' (' . $rpbm_codeint . ')', 'LR', 1, 'L');
            else {
                if ($rpbm_codeint <> NULL)
                    $pdf->Cell(30, 4, _("En cours") . ' (' . $rpbm_codeint . ')', 'LR', 1, 'L');
                else
                    $pdf->Cell(30, 4, _("Non traité"), 'LR', 1, 'L');
            }
            $pdf->SetFont('', 'I', 7);

            // Lignes supplémentaires si long descriptif problème
            $ligne_cesure = cesuretxt_tab($rpbm_pbm, 100);

            foreach ($ligne_cesure as $key => $value) {
                $pdf->SetFillColor(255);
                $pdf->Cell(30, 4, "", 'LR', 0, 'L', 1);
                $pdf->Cell(73, 4, "", 'LR', 0, 'L', 1);
                $pdf->Cell(144, 4, $value, 'LR', 0, 'L', 1);
                $pdf->Cell(30, 4, "", 'LR', 1, 'L', 1);
            }
        }
        $PosY = $pdf->GetY();
        $pdf->Line(10, $PosY, 287, $PosY); // On "ferme" le tableau
    } else {
        $pdf->SetFont('', 'I', 8);
        $pdf->Cell(277, 4, _("Aucun problème déclaré"), 0, 1, 'C');
    }
}

$pdf->Ln(1);
$pdf->SetDrawColor(120);
$pdf->SetLineWidth(0.4);
$PosY = $pdf->GetY();
$pdf->Line(10, $PosY, 287, $PosY);
$pdf->SetDrawColor(0);
$pdf->SetLineWidth(0.2);
?>