<?php
/****************************************************************************************
SMI (Services Maintenance Interventions) est une gestion libre de maintenance et de SAV

Version 0.9.7

Copyright (C) 2006-2007  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://smitst.homelinux.com
****************************************************************************************/


// 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_age.inc.php");
include_once("../inc/fic_cli.inc.php");
include_once("../inc/fic_rel.inc.php");
include_once("../inc/func_date.inc.php");
include_once("../inc/func_log.inc.php");
include_once("../inc/func_txt.inc.php");
include_once("../inc/func_geo.inc.php");
Archivelog(@$_SESSION["code_log"]);

$cr = strip_tags(trim($_GET['cr']));	// Récupération code Relevé
$pbm = strip_tags(trim($_GET['pbm']));	// Récupération type Relevé (0 : sans détail problèmes, 1 : avec détail problèmes)

if ($cr <> "")
{
	// Récupération des informations dossier relevé
	$row = lit_enr_rel($cr);
	if (is_array($row))
		extract ($row);

	$rel_datecreaf = formatedate($rel_datecrea);
	$rel_datemodf = formatedate($rel_datemod);

	// Récupération des données agence
	$row = lit_enr_age($rel_codeage);
	extract ($row);

	$cp_age = Retournecp_openId($age_ville,TRUE);
	$ville_age = Retourneville_openId($age_ville,TRUE);

	// Récupération des données client
	$row = lit_enr_cli($rel_codecli);
	extract ($row);

	include_once('../classes/fpdf/fpdf.php');
	include_once('../inc/fpdf_ext.inc.php');
	
	$pdf=new PDF();
	$pdf->FPDF('L','mm','A4');
	$pdf->SetDisplayMode('real');
	$pdf->AliasNbPages();
	$pdf->SetTitle('Relevé N°'.$rel_code);
	$pdf->SetSubject('Relevé N°'.$rel_code);
	$pdf->settheader("rel");
	$pdf->AddPage();

	$pv_det_cli = $pv_ent_age; // Récupération de la position sous l'entête agence pour le pointeur détail client
	$pv_det_rel = $pv_ent_age; // Récupération de la position sous l'entête agence pour le pointeur détail intervention

	$pdf->SetLineWidth(0.4);

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

	$pdf->SetFont('Arial','BU',12); // Titre
	$pdf->Cell(138,5,'CLIENT','LTR',1,'C');
	
	$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\n"; // Double saut pour compenser le manque de la société
	}
	$pdf->SetFont('Arial','B',10);
	$pdf->MultiCell(138,4,$ent_cli,'LR','L');

	$ent_cli = $cli_adr1."\n"; // Suite...
	$ent_cli.= $cli_adr2."\n";
	$ent_cli.= Retournecp_openId($cli_ville,TRUE)." ".Retourneville_openId($cli_ville,TRUE)."\n";
	$ent_cli.= "Tel : ".$cli_telf."\n";
	$ent_cli.= "Fax : ".$cli_fax;
	$pdf->SetFont('Arial','',10);
	$pdf->MultiCell(138,4,$ent_cli,'LRB','L');

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

	$pdf->Cell(138);

	$pdf->SetFont('Arial','BU',12);
	$pdf->Cell(139,5,'DETAIL','LTR',1,'C');

	$pdf->Cell(138);

	$pdf->SetFont('Arial','',8);
	$ent_rel = "\n";
	$ent_rel.= "Racine codage :\n";
	$ent_rel.= "Dernier n° machine :\n";
	$ent_rel.= "\n";
	$ent_rel.= "\n";
	$ent_rel.= "\n";
	$ent_rel.= "\n";

	$pdf->MultiCell(30,4,$ent_rel,'B','R');

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

	$pdf->SetFont('Arial','',8);
	$ent_rel = "\n";
	$ent_rel.= $rel_rnum."\n";
	$ent_rel.= $rel_num."\n";
	$ent_rel.= "\n";
	$ent_rel.= "\n";
	$ent_rel.= "\n";
	$ent_rel.= "\n";

	$pdf->MultiCell(109,4,$ent_rel,'BR','L');

	//Notes
	$pdf->SetFont('Arial','UI',8);
	$pdf->MultiCell(277,4,'Notes :','','L');

	$pdf->SetFont('Arial','I',8);
	$ent_rel= $rel_nota."\n";

	$pdf->MultiCell(277,4,$ent_rel,'','L');

	$pdf->SetDrawColor(125);
	$pdf->SetLineWidth(0.4);
	$PosY = $pdf->GetY();
	$pdf->Line(10,$PosY,287,$PosY);


	/**********************************/
	/* Impression des fiches licences */
	/**********************************/

	$pdf->Ln(2);
	$pdf->SetFont('Arial','BU',12);
	$pdf->Cell(277,5,'LICENCES','',1,'C');
	$pdf->Ln(2);

	$PosY = $pdf->GetY();
	$pdf->Line(10,$PosY,287,$PosY);
	$pdf->SetDrawColor(0);
	$pdf->SetLineWidth(0.2);


	$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
	mysql_select_db(DBNAME);

	$rech = "SELECT * FROM ".TBRLIC." WHERE `rlic_codecli` = '".$rel_codecli."' ORDER BY rlic_code";
	
	$rs = mysql_query($rech) or die(mysql_error());
	if (mysql_num_rows($rs) <> 0)
	{
		while ($row = mysql_fetch_assoc($rs)) 
		{         
			extract($row);
			
			$pdf->Ln(1);
			$pdf->SetFont('Arial','',10);
			$pdf->SetFillColor(0);
			$pdf->SetTextColor(255);
			$pdf->Cell(80,5,'Relevé : '.$rlic_code,1,1,'C',1);
			$pdf->SetFillColor(255);
			$pdf->SetTextColor(0);
			

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

			$rech2 = "SELECT * FROM `" .TBTEC. "` WHERE `tec_code` = '$rlic_codetec'";
			$rs2 = mysql_query($rech2)or die(mysql_error());
			if ($row2 = mysql_fetch_array($rs2))
			{
				extract($row2);
			}

			$pdf->Cell(140,4,'Fiche créée le '.formatedate($rlic_datecrea).'. Relevé effectué par '.$tec_nom.' '.$tec_prenom.'.',0,0,'L');
			$pdf->SetFont('Arial','',8);

			if (formatedate($rlic_dateout) == "")
			{
				$pdf->Ln(5);
			}
			else
			{
				$pdf->SetFont('Arial','BI',8);
				$pdf->Cell(137,5,'Sortie du parc le '.formatedate($rlic_dateout),0,1,'R');
				$pdf->SetFont('Arial','',8);
			}

			// Site d'utilisation
			$nom_site=nom_scli($rlic_idsite,FALSE);
			$nom_site=strip_tags($nom_site,"<p><a><br><font><blockquote><h1><h2><h3><h4><h5><h6><ul><li><b><i><u><em><sub><sup><ol><div><img>");

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

			// Marque
			$rech2 = "SELECT * FROM ".TBMQUE." WHERE `mque_code` = '".$rlic_codema."'";
			$rs2 = mysql_query($rech2);
			if ($row2 = mysql_fetch_array($rs2))
			{
				extract ($row2);
			}
			$pdf->SetFont('Arial','B',8);
			$pdf->Cell(30,4,'Marque : ',0,0,'R');
			$pdf->SetFont('Arial','',8);
			$pdf->Cell(247,4,$mque_ste,0,1,'L');

			// Type
			$rech2 = "SELECT * FROM ".TBRLTL." WHERE `rltl_code` = '".$rlic_codetl."'";
			$rs2 = mysql_query($rech2);
			if ($row2 = mysql_fetch_array($rs2))
			{
				extract ($row2);
			}
			$pdf->SetFont('Arial','B',8);
			$pdf->Cell(30,4,'Type : ',0,0,'R');
			$pdf->SetFont('Arial','',8);
			$pdf->Cell(247,4,$rltl_desc,0,1,'L');

			// Modèle
			$pdf->SetFont('Arial','B',8);
			$pdf->Cell(30,4,'Modèle : ',0,0,'R');
			$pdf->SetFont('Arial','',8);
			$pdf->Cell(247,4,$rlic_modele,0,1,'L');

			// Version
			$pdf->SetFont('Arial','B',8);
			$pdf->Cell(30,4,'Version : ',0,0,'R');
			$pdf->SetFont('Arial','',8);
			$pdf->Cell(247,4,$rlic_version,0,1,'L');

			// Maximum de postes
			$rech2 = "SELECT * FROM ".TBRLTL." WHERE `rltl_code` = '".$rlic_codetl."'";
			$rs2 = mysql_query($rech2);
			if ($row2 = mysql_fetch_array($rs2))
			{
				extract ($row2);
			}
			$nbutilise=0;
			$rexist = "SELECT * FROM `" .TBRPDT. "` WHERE `rpdt_codecli` = '".$rlic_codecli."'";
			$rs2 = mysql_query($rexist) or die(mysql_error());
		
			if (mysql_num_rows($rs2) <> 0)
			{
				while ($resultat = mysql_fetch_array($rs2)) 
				{
					if (ereg($rlic_code,$resultat["rpdt_coderlic"]))
						$nbutilise++;
				}
			}
			$pdf->SetFont('Arial','B',8);
			$pdf->Cell(30,4,'Maximum de postes : ',0,0,'R');
			$pdf->SetFont('Arial','',8);
			$pdf->Cell(247,4,$rlic_maxcli.' (Utilisé : '.$nbutilise.')',0,1,'L');

			// Média
			$rech2 = "SELECT * FROM ".TBRLMED." WHERE `rlmed_code` = '".$rlic_codemed."'";
			$rs2 = mysql_query($rech2);
			if ($row2 = mysql_fetch_array($rs2))
			{
				extract ($row2);
			}
			$pdf->SetFont('Arial','B',8);
			$pdf->Cell(30,4,'Média : ',0,0,'R');
			$pdf->SetFont('Arial','',8);
			$pdf->Cell(247,4,$rlmed_desc,0,1,'L');

			// Numéro
			$pdf->SetFont('Arial','B',8);
			$pdf->Cell(30,4,'Numéro : ',0,0,'R');
			$pdf->SetFont('Arial','',8);
			$pdf->Cell(247,4,$rlic_numlic,0,1,'L');

			// Clef
			$pdf->SetFont('Arial','B',8);
			$pdf->Cell(30,4,'Clef d\'activation : ',0,0,'R');
			$pdf->SetFont('Arial','',8);
			$pdf->Cell(247,4,$rlic_cleflic,0,1,'L');

			// A jour / Légale ?
			$pdf->SetFont('Arial','B',8);
			$pdf->Cell(30,4,'A jour / Légale : ',0,0,'R');
			$pdf->SetFont('Arial','',8);
			if ($rlic_ajour == TRUE)
			{
				$pdf->Cell(7,4,'OUI / ',0,0,'L');
			}
			else
			{
				$pdf->SetFont('Arial','BI',8);
				$pdf->Cell(6,4,'NON',0,0,'L');
				$pdf->SetFont('Arial','',8);
				$pdf->Cell(2,4,' / ',0,0,'L');
			}
			// 247
			if ($rlic_legal == TRUE)
			{
				$pdf->Cell(197,4,'OUI',0,1,'L');
			}
			else
			{
				$pdf->SetFont('Arial','BI',8);
				$pdf->Cell(197,4,'NON',0,1,'L');
				$pdf->SetFont('Arial','',8);
			}
	
			// Date Validité
			$pdf->SetFont('Arial','B',8);
			$pdf->Cell(30,4,'Date de validité : ',0,0,'R');
			$pdf->SetFont('Arial','',8);
			if (formatedate($rlic_dateval)<>"")
			{
				if (echeance_depassee_date($datea,$rlic_dateval)==TRUE)
					$pdf->SetFont('Arial','BI',8);
			}				
			$pdf->Cell(247,4,formatedate($rlic_dateval),0,1,'L');

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

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

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

			/*************/
			/* Matériels */
			/*************/
			if ($nbutilise <> 0)
			{
				$warn=FALSE;
				$pdf->SetFont('Arial','IB',8);
				$pdf->Cell(7);
				$pdf->Cell(30,4,'Détail matériels : ','LT',0,'R');
				$rech2 = "SELECT * FROM ".TBRPDT." WHERE rpdt_codecli = '".$rel_codecli."' AND rpdt_dateout = '0000-00-00'";
				$rech2.= " AND rpdt_coderlic LIKE '%".$rlic_code."%'";
				$rech2.= " ORDER BY rpdt_code";
				$rs2 = mysql_query($rech2);
		
				if (mysql_num_rows($rs2) <> 0)
				{
					$pdf->SetFont('Arial','IU',7); // Titres
					$pdf->Cell(30,4,'Code Fiche Mat.',1,0,'C');
					$pdf->Cell(14,4,'Dte Relevé',1,0,'C');
					$pdf->Cell(58,4,'Catégorie',1,0,'C');
					$pdf->Cell(58,4,'Marque / Modèle / NS / Emplacement',1,0,'C');
					$pdf->Cell(14,4,'Fin Gar.',1,1,'C');
					$pdf->SetFont('Arial','I',8);

					while ($row2 = mysql_fetch_assoc($rs2)) 
					{         
						extract($row2);
						$pdf->Cell(7);
						$pdf->Cell(30,4,'','LR',0,'R');
						$pdf->SetFont('Arial','I',7);
						$pdf->Cell(30,4,$rpdt_code,'LR',0,'L');
						$pdf->Cell(14,4,formatedate($rpdt_daterel),'LR',0,'C');
						$rech3 = "SELECT * FROM ".TBRPCAT." WHERE `rpcat_code` = '".$rpdt_codecat."'";
						$rs3 = mysql_query($rech3) or die(mysql_error());
						if (mysql_num_rows($rs3) <> 0)
						{
							if ($row3 = mysql_fetch_array($rs3))
								extract($row3);
						}
						$pdf->Cell(58,4,$rpcat_desc,'LR',0,'L');
						$rech3 = "SELECT * FROM ".TBMQUE." WHERE `mque_code` = '".$rpdt_codema."'";
						$rs3 = mysql_query($rech3) or die(mysql_error());
						if (mysql_num_rows($rs3) <> 0)
						{
							if ($row3 = mysql_fetch_array($rs3))
								extract($row3);
						}
						$pdf->Cell(58,4,$mque_ste,'LR',0,'L');

						// Alertes complémentaires
						$txt_warn="";							
						if  (formatedate($rpdt_fingar) <> "")
						{
							if ((echeance_depassee_date($datea,$rpdt_fingar) == TRUE)  AND (formatedate($rpdt_dateout) == ""))
								$warn=TRUE;
							$txt_warn.="G";
						}
	
						if ($txt_warn <> "")
						{
							$pdf->Cell(14,4,formatedate($rpdt_fingar),'LR',0,'L');
							$pdf->Cell(5,4,$txt_warn,0,1,'L');
						}
						else
						{
							$pdf->Cell(14,4,formatedate($rpdt_fingar),'LR',1,'L');
						}
	
						if ($rpdt_modele <> "")
						{
							$pdf->Cell(7);
							$pdf->Cell(30,4,'','LR',0,'R');
							$pdf->Cell(30,4,'','LR',0,'L');
							$pdf->Cell(14,4,'','LR',0,'C');
							$pdf->Cell(58,4,'','LR',0,'L');
							$pdf->Cell(58,4,$rpdt_modele,'LR',0,'L');
							$pdf->Cell(14,4,'','LR',1,'C');
						}

						if ($rpdt_ns <> "")
						{
							$pdf->Cell(7);
							$pdf->Cell(30,4,'','LR',0,'R');
							$pdf->Cell(30,4,'','LR',0,'L');
							$pdf->Cell(14,4,'','LR',0,'C');
							$pdf->Cell(58,4,'','LR',0,'L');
							$pdf->Cell(58,4,'NS : '.$rpdt_ns,'LR',0,'L');
							$pdf->Cell(14,4,'','LR',1,'C');
						}

						if ($rpdt_empl <> "")
						{
							$pdf->Cell(7);
							$pdf->Cell(30,4,'','LR',0,'R');
							$pdf->Cell(30,4,'','LR',0,'L');
							$pdf->Cell(14,4,'','LR',0,'C');
							$pdf->Cell(58,4,'','LR',0,'L');
							$pdf->Cell(58,4,'Empl. : '.$rpdt_empl,'LR',0,'L');
							$pdf->Cell(14,4,'','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('Arial','I',8);
					$pdf->Cell(7);
					$pdf->Cell(204,4,'Légende : \'G\'= Garantie dépassée',0,1,'R');
				}
			}
			$pdf->SetFont('Arial','',8);
			$pdf->Ln(2);

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

			// Type d'accès
			$pdf->Cell(30,4,'Type d\'accès : ','LTR',0,'R');
			$rech2 = "SELECT * FROM ".TBRLPTMTA." WHERE rlptmta_code = '".$rlic_codeta."'";
			$rs2 = mysql_query($rech2);
			if ($row2 = mysql_fetch_array($rs2))
			{
				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[$rlic_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');
			$rech2 = "SELECT * FROM ".TBRLPTML." WHERE rlptml_code = '".$rlic_codel."'";
			$rs2 = mysql_query($rech2);
			if ($row2 = mysql_fetch_array($rs2))
			{
				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[$lic_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,$rlic_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,$rlic_tlogin." / ".$rlic_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[$rlic_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[$rlic_tred],'R',1,'L');

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

			$pdf->Ln(2);

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

			// Mode
			$pdf->Cell(30,4,'Mode : ','LTR',0,'R');
			$rech2 = "SELECT * FROM ".TBRLPMM." WHERE rlpmm_code = '".$rlic_codem."'";
			$rs2 = mysql_query($rech2);
			if ($row2 = mysql_fetch_array($rs2))
			{
				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="";
			$rech2 = "SELECT * FROM ".TBPER." WHERE per_code = '".$rlic_mper."'";
			$rs2 = mysql_query($rech2);
			if ($row2 = mysql_fetch_array($rs2))
			{
				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[$rlic_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 (formatedate($rlic_mdval) <> "")
			{
				if (echeance_depassee_date($datea,$rlic_mdval) == TRUE)
					$txt_edep=" (Echéance dépassée)";
			}
			$pdf->Cell(144,4,formatedate($rlic_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,formatedate($rlic_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[$rlic_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[$rlic_mred],'R',1,'L');

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

			$pdf->Ln(2);

			/************/
			/* Contrats */
			/************/
			$rech2 = "SELECT * FROM ".TBCOCL." WHERE `cocl_coderlp` LIKE '%".$rlic_code."%'";
			$rech2.=" ORDER BY `cocl_code`";
			$rs2 = mysql_query($rech2);
		
			if (mysql_num_rows($rs2) <> 0)
			{
				$warn=FALSE;

				$pdf->SetFont('Arial','IB',8);
				$pdf->Cell(7);
				$pdf->Cell(30,4,'Contrats : ','LTR',0,'R');
		
				$pdf->SetFont('Arial','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('Arial','I',8);
	
				while ($row2 = mysql_fetch_assoc($rs2)) 
				{
					 $echeance_ok = TRUE;
					 if (formatedate($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,formatedate($row2["cocl_datecrea"]),'LR',0,'C');
					$pdf->Cell(43,4,formatedate($row2["cocl_dated"]),'LR',0,'C');

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

					if ($txt_warn <> "")
					{
						$pdf->Cell(43,4,formatedate($row2["cocl_datef"]),'LR',0,'C');
						$pdf->Cell(5,4,$txt_warn,0,1,'L');
					}
					else
					{
						$pdf->Cell(43,4,formatedate($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('Arial','I',8);
					$pdf->Cell(7);
					$pdf->Cell(204,4,'Légende : \'S\'=Non signé / \'T\'=Terminé',0,1,'R');
				}
			}
			else
			{
				$pdf->SetFont('Arial','IB',8);
				$pdf->Cell(7);
				$pdf->Cell(30,4,'Contrats : ',0,0,'R');
				$pdf->SetFont('Arial','I',8);
				$pdf->Cell(277,4,'Aucun contrat couvrant cette licence',0,1,'L');
			}

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

				$rech2 = "SELECT * FROM ".TBRPBM." WHERE `rpbm_coderlp` = '".$rlic_code."' ORDER BY `rpbm_datecrea`";
				$rs2 = mysql_query($rech2) or die(mysql_error());
				if (mysql_num_rows($rs2) <> 0)
				{
					$pdf->SetFont('Arial','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('Arial','I',8);

					while ($row2 = mysql_fetch_assoc($rs2))
					{
						extract($row2);

						$pdf->SetFont('Arial','IB',7);
						$pdf->Cell(30,4,formatedate($rpbm_datecrea),'LR',0,'L');
						$pdf->Cell(73,4,$rpbm_signale,'LR',0,'L');
						$ligne_cesure = cesuretxt_tab($rpbm_pbm,100);

						$nom_site="";
						switch ($rpbm_idsite)
						{
							case 0 :
								$nom_site="Site principal";
								break;
							default :
								$rech3 = "SELECT * FROM `" .TBSCLI. "` WHERE `scli_id` = '$rpbm_idsite'";
								$rs3 = mysql_query($rech3)or die(mysql_error());
								if ($row3 = mysql_fetch_array($rs3))
								{
									extract($row3);
									$nom_site.= $scli_ste;
									$nom_site.= " (".Retournecp_openId($scli_ville,FALSE)." ".Retourneville_openId($scli_ville,FALSE).")";
								}
								mysql_free_result($rs3);
						}
						$pdf->Cell(144,4,$nom_site,'LR',0,'L');
						if (($rpbm_datett <> "0000-00-00") AND ($rpbm_datett <> NULL))
							$pdf->Cell(30,4,formatedate($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('Arial','I',7);

						// Lignes supplémentaires si long descriptif problème
						if (count($ligne_cesure)>0)
						{
							for ($i=0; $i<count($ligne_cesure);$i++)
							{
								$pdf->Cell(30,4,"",'LR',0,'L',1);
								$pdf->Cell(73,4,"",'LR',0,'L',1);
								$pdf->Cell(144,4,$ligne_cesure[$i],'LR',0,'L',1);
								$pdf->Cell(30,4,"",'LR',1,'L',1);
							}
						}
						$nligne++;
					}
					$PosY = $pdf->GetY();
					$pdf->Line(10,$PosY,287,$PosY); // On "ferme" le tableau
				}
				else
				{
					$pdf->SetFont('Arial','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);
		}
	}
	else
	{
		$pdf->Ln(1);
		$pdf->SetFont('Arial','I',8);
		$pdf->Cell(277,4,'Aucune fiche relevé licence créée.',0,1,'L');
	}
	mysql_free_result($rs);
	mysql_close($conn);  

	$pdf->AddPage();
	$pdf->SetDrawColor(125);
	$pdf->SetLineWidth(0.4);
	$PosY = $pv_ent_age;
	$pdf->Line(10,$PosY+1,287,$PosY+1);
	$pdf->SetY($PosY+1);

	/************************************/
	/* Impression des fiches Matériels  */
	/************************************/

	$pdf->Ln(2);

	$pdf->SetFont('Arial','BU',12);
	$pdf->Cell(277,5,'MATERIELS','',1,'C');

	$pdf->Ln(2);

	$PosY = $pdf->GetY();
	$pdf->Line(10,$PosY,287,$PosY);
	$pdf->SetDrawColor(0);
	$pdf->SetLineWidth(0.2);

	$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
	mysql_select_db(DBNAME);

	$rech = "SELECT * FROM ".TBRPDT." WHERE `rpdt_codecli` = '".$rel_codecli."' ORDER BY rpdt_code";
	
	$rs = mysql_query($rech) or die(mysql_error());
	if (mysql_num_rows($rs) <> 0)
	{
		while ($row = mysql_fetch_assoc($rs)) 
		{         
			extract($row);
			
			$pdf->Ln(1);
			$pdf->SetFont('Arial','',10);
			$pdf->SetFillColor(0);
			$pdf->SetTextColor(255);
			$pdf->Cell(80,5,'Relevé : '.$rpdt_code,1,1,'C',1);
			$pdf->SetFillColor(255);
			$pdf->SetTextColor(0);
			

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

			$rech2 = "SELECT * FROM `" .TBTEC. "` WHERE `tec_code` = '$rpdt_codetec'";
			$rs2 = mysql_query($rech2)or die(mysql_error());
			if ($row2 = mysql_fetch_array($rs2))
			{
				extract($row2);
			}

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

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

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

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

			// Catégorie
			$rech2 = "SELECT * FROM ".TBRPCAT." WHERE `rpcat_code` = '".$rpdt_codecat."'";
			$rs2 = mysql_query($rech2);
			if ($row2 = mysql_fetch_array($rs2))
			{
				extract ($row2);
			}
			$pdf->SetFont('Arial','B',8);
			$pdf->Cell(30,4,'Catégorie : ',0,0,'R');
			$pdf->SetFont('Arial','',8);
			$pdf->Cell(247,4,$rpcat_desc,0,1,'L');

			// Marque
			$rech2 = "SELECT * FROM ".TBMQUE." WHERE `mque_code` = '".$rpdt_codema."'";
			$rs2 = mysql_query($rech2);
			if ($row2 = mysql_fetch_array($rs2))
			{
				extract ($row2);
			}
			$pdf->SetFont('Arial','B',8);
			$pdf->Cell(30,4,'Marque : ',0,0,'R');
			$pdf->SetFont('Arial','',8);
			$pdf->Cell(247,4,$mque_ste,0,1,'L');

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

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

			// Codage
			$pdf->SetFont('Arial','B',8);
			$pdf->Cell(30,4,'Codage Inventaire : ',0,0,'R');
			$pdf->SetFont('Arial','',8);
			$pdf->Cell(247,4,$rpdt_codep,0,1,'L');

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

			// Date Achat
			$pdf->SetFont('Arial','B',8);
			$pdf->Cell(30,4,'Date d\'achat : ',0,0,'R');
			$pdf->SetFont('Arial','',8);
			$pdf->Cell(247,4,formatedate($rpdt_dateach),0,1,'L');

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

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

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

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

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

			/************/
			/* Licences */
			/************/
			$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";
			$rs2 = mysql_query($rech2);
	
			if (mysql_num_rows($rs2) <> 0)
			{
				$warn=FALSE;

				$pdf->SetFont('Arial','IB',8);
				$pdf->Cell(7);
				$pdf->Cell(30,4,'Licences utilisées : ','LT',0,'R');
		
				$pdf->SetFont('Arial','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('Arial','I',8);

				while ($row2 = mysql_fetch_assoc($rs2)) 
				{         
					extract($row2);

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

					$rech3 = "SELECT * FROM ".TBMQUE." WHERE `mque_code` = '".$rlic_codema."'";
					$rs3 = mysql_query($rech3) or die(mysql_error());
					if (mysql_num_rows($rs3) <> 0)
					{
						if ($row3 = mysql_fetch_array($rs3))
							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;
					$rech3 = "SELECT * FROM `" .TBRPDT. "` WHERE `rpdt_codecli` = '".$rpdt_codecli."'";
					$rs3 = mysql_query($rech2) or die(mysql_error());
					if (mysql_num_rows($rs3) <> 0)
					{
						while ($resultat = mysql_fetch_array($rs3)) 
						{
							if (ereg($rlic_code,$resultat["rpdt_coderlic"]))
								$nb_rlic_utilisees++;
						}
					}
					if ($nb_rlic_utilisees >= $rlic_maxcli)
					{
						$warn=TRUE;
						$txt_warn.="M";
					}
					if  (formatedate($rlic_dateval) <> "")
					{
						if ((echeance_depassee_date($datea,$rlic_dateval) == TRUE)  AND (formatedate($rlic_dateout) == ""))
							$warn=TRUE;
						$txt_warn.="V";
					}

					if ($txt_warn <> "")
					{
						$pdf->Cell(14,4,formatedate($rlic_dateval),'LR',0,'C');
						$pdf->Cell(5,4,$txt_warn,0,1,'L');
					}
					else
					{
						$pdf->Cell(14,4,formatedate($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('Arial','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('Arial','B',8);
				$pdf->Cell(30,4,'Licences utilisées : ',0,0,'R');
				$pdf->SetFont('Arial','',8);
				$pdf->Cell(247,4,'Aucune',0,1,'L');
			}
			$pdf->SetFont('Arial','',8);
			
			$pdf->Ln(2);

			/**********/
			/* Réseau */
			/**********/
			$pdf->SetFont('Arial','IB',8);
			$pdf->Cell(7);
			$pdf->Cell(30,4,'Réseau : ','LTR',0,'R');
	
			$pdf->SetFont('Arial','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('Arial','IB',8);
			$pdf->Cell(7);
			$pdf->Cell(30,4,'Télémaintenance : ','LTR',0,'R');
	
			$pdf->SetFont('Arial','I',8);

			// Type d'accès
			$pdf->Cell(30,4,'Type d\'accès : ','LTR',0,'R');
			$rech2 = "SELECT * FROM ".TBRLPTMTA." WHERE rlptmta_code = '".$rpdt_codeta."'";
			$rs2 = mysql_query($rech2);
			if ($row2 = mysql_fetch_array($rs2))
			{
				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');
			$rech2 = "SELECT * FROM ".TBRLPTML." WHERE rlptml_code = '".$rpdt_codel."'";
			$rs2 = mysql_query($rech2);
			if ($row2 = mysql_fetch_array($rs2))
			{
				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('Arial','IB',8);
			$pdf->Cell(7);
			$pdf->Cell(30,4,'Mises à jour : ','LTR',0,'R');
	
			$pdf->SetFont('Arial','I',8);

			// Mode
			$pdf->Cell(30,4,'Mode : ','LTR',0,'R');
			$rech2 = "SELECT * FROM ".TBRLPMM." WHERE rlpmm_code = '".$rpdt_codem."'";
			$rs2 = mysql_query($rech2);
			if ($row2 = mysql_fetch_array($rs2))
			{
				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="";
			$rech2 = "SELECT * FROM ".TBPER." WHERE per_code = '".$rpdt_mper."'";
			$rs2 = mysql_query($rech2);
			if ($row2 = mysql_fetch_array($rs2))
			{
				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 (formatedate($rpdt_mdval) <> "")
			{
				if (echeance_depassee_date($datea,$rpdt_mdval) == TRUE)
					$txt_edep=" (Echéance dépassée)";
			}
			$pdf->Cell(144,4,formatedate($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,formatedate($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 */
			/**************/
			$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";
			$rs2 = mysql_query($rech2) or die(mysql_error());
		
			if (mysql_num_rows($rs2) <> 0)
			{
				$i=0;
				while ($row2 = mysql_fetch_assoc($rs2)) 
				{
					$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')";
					$rs3 = mysql_query($rech3) or die(mysql_error());
					if (mysql_num_rows($rs3) > 0)
					{
						if ($row3 = mysql_fetch_array($rs3))
							extract($row3);

						if ($i==0)
						{
							$pdf->SetFont('Arial','IB',8);
							$pdf->Cell(7);
							$pdf->Cell(30,4,'Connexions : ','LTR',0,'R');
			
							$pdf->SetFont('Arial','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('Arial','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++;
					}
					mysql_free_result($rs3);
				}

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

			$pdf->Ln(2);

			/************/
			/* Contrats */
			/************/
			$rech2 = "SELECT * FROM ".TBCOCL." WHERE `cocl_coderlp` LIKE '%".$rpdt_code."%'";
			$rech2.=" ORDER BY `cocl_code`";
			$rs2 = mysql_query($rech2);
		
			if (mysql_num_rows($rs2) <> 0)
			{
				$warn=FALSE;

				$pdf->SetFont('Arial','IB',8);
				$pdf->Cell(7);
				$pdf->Cell(30,4,'Contrats : ','LTR',0,'R');
		
				$pdf->SetFont('Arial','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('Arial','I',8);
	
				while ($row2 = mysql_fetch_assoc($rs2)) 
				{
					 $echeance_ok = TRUE;
					 if (formatedate($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,formatedate($row2["cocl_datecrea"]),'LR',0,'C');
					$pdf->Cell(43,4,formatedate($row2["cocl_dated"]),'LR',0,'C');

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

					if ($txt_warn <> "")
					{
						$pdf->Cell(43,4,formatedate($row2["cocl_datef"]),'LR',0,'C');
						$pdf->Cell(5,4,$txt_warn,0,1,'L');
					}
					else
					{
						$pdf->Cell(43,4,formatedate($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('Arial','I',8);
					$pdf->Cell(7);
					$pdf->Cell(204,4,'Légende : \'S\': Non signé / \'T\': Terminé',0,1,'R');
				}
			}
			else
			{
				$pdf->SetFont('Arial','IB',8);
				$pdf->Cell(7);
				$pdf->Cell(30,4,'Contrats : ',0,0,'R');
				$pdf->SetFont('Arial','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('Arial','BU',10);
				$pdf->Cell(277,5,'PROBLEMES',0,1,'C');
				$pdf->Ln(2);

				$rech2 = "SELECT * FROM ".TBRPBM." WHERE `rpbm_coderlp` = '".$rpdt_code."' ORDER BY `rpbm_datecrea`";
				$rs2 = mysql_query($rech2) or die(mysql_error());
				if (mysql_num_rows($rs2) <> 0)
				{
					$pdf->SetFont('Arial','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('Arial','I',8);

					while ($row2 = mysql_fetch_assoc($rs2))
					{
						extract($row2);

						$pdf->SetFont('Arial','IB',7);
						$pdf->Cell(30,4,formatedate($rpbm_datecrea),'LR',0,'L');
						$pdf->Cell(73,4,$rpbm_signale,'LR',0,'L');
						$ligne_cesure = cesuretxt_tab($rpbm_pbm,100);

						$nom_site="";
						switch ($rpbm_idsite)
						{
							case 0 :
								$nom_site="Site principal";
								break;
							default :
								$rech3 = "SELECT * FROM `" .TBSCLI. "` WHERE `scli_id` = '$rpbm_idsite'";
								$rs3 = mysql_query($rech3)or die(mysql_error());
								if ($row3 = mysql_fetch_array($rs3))
								{
									extract($row3);
									$nom_site.= $scli_ste;
									$nom_site.= " (".Retournecp_openId($scli_ville,FALSE)." ".Retourneville_openId($scli_ville,FALSE).")";
								}
								mysql_free_result($rs3);
						}
						$pdf->Cell(144,4,$nom_site,'LR',0,'L');
						if (($rpbm_datett <> "0000-00-00") AND ($rpbm_datett <> NULL))
							$pdf->Cell(30,4,formatedate($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('Arial','I',7);

						// Lignes supplémentaires si long descriptif problème
						if (count($ligne_cesure)>0)
						{
							for ($i=0; $i<count($ligne_cesure);$i++)
							{
								$pdf->Cell(30,4,"",'LR',0,'L',1);
								$pdf->Cell(73,4,"",'LR',0,'L',1);
								$pdf->Cell(144,4,$ligne_cesure[$i],'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('Arial','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);
		}
	}
	else
	{
		$pdf->Ln(1);
		$pdf->SetFont('Arial','I',8);
		$pdf->MultiCell(277,4,'Aucune fiche relevé matériel créée.','','L');
	}
	mysql_free_result($rs);
	mysql_close($conn);  
	$pdf->Output('rel_'.$rel_code,'I');
}
?>