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

Version 0.9.6
Copyright (C) 2006  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
****************************************************************************************/

include ("../inc/config.inc.php");
?>
<?php require ("../inc/fic_fpdf.inc.php") ?>
<?php require ("../inc/func_time.inc.php") ?>
<?php require ("../inc/func_date.inc.php") ?>
<?php require ("../inc/func_log.inc.php") ?>
<?php require ("../inc/func_txt.inc.php") ?>
<?php require ("../inc/txt.inc.php") ?>
<?PHP
	Archivelog(@$HTTP_SESSION_VARS["code_log"]);

	$ci = strip_tags(trim($_GET['ci']));	// Récupération code Intervention
	$cg = strip_tags(trim($_GET['cgv']));	// Récupération si avec ou sans CGV
	$niv_util = @$HTTP_SESSION_VARS["niv_log"];
		
	if ($cg == "ok")
		$cgv = TRUE;
	else
		$cgv = FALSE;
		
	function Retourneville($insee)
	{
		$ville_nom = "";
		
		$conn2 = mysql_connect(DBHOST, DBUSER, DBPASS);
		mysql_select_db(DBNAME);
		$rnom = "SELECT villes_insee,villes_nom FROM " .TBVILLES. " WHERE villes_insee='".$insee."'";;
		$rsnom = mysql_query($rnom) or die(mysql_error());
		if (mysql_num_rows($rsnom) == 1) // Uniquement UN SEUL enregistrement !
		{
			if ($rowville = mysql_fetch_array($rsnom)) 
			{
				extract ($rowville);
			}
		}
	
		mysql_free_result($rsnom);
		mysql_close($conn2);  
	
		$ville = str_majuscules($villes_nom);
		
		// Les villes de LYON, MARSEILLE, PARIS doivent être traitées à part (arrondissements)
		
		if (stristr($villes_nom,"LYON"))
			$ville="LYON";
		if (stristr($villes_nom,"MARSEILLE"))
			$ville="MARSEILLE";
		if (stristr($villes_nom,"PARIS"))
			$ville="PARIS";
			
		return $ville;
	}

	function Retournecp($insee)
	{
		$villes_cp = "";
		
		$conn2 = mysql_connect(DBHOST, DBUSER, DBPASS);
		mysql_select_db(DBNAME);
		$rcp = "SELECT villes_insee,villes_cp FROM " .TBVILLES. " WHERE villes_insee='".$insee."'";;
		$rscp = mysql_query($rcp) or die(mysql_error());
		if (mysql_num_rows($rscp) == 1) // Uniquement UN SEUL enregistrement !
		{
			if ($rowcp = mysql_fetch_array($rscp)) 
			{
				extract ($rowcp);
			}
		}
	
		mysql_free_result($rscp);
		mysql_close($conn2);  
	
		return $villes_cp;
	}


	$pbm_intpdf = FALSE;
	
	if ($ci <> "")
	{
		$nbartint = nb_art_in_int($ci);

		$row = lit_enr_int($ci);
		if (is_array($row))
		{
			extract ($row);
			
			// Contrôle de hack pour un client
			if (($niv_util == 1)  AND ($int_codecli <> @$HTTP_SESSION_VARS["code_log"]))
				$pbm_intpdf=TRUE;

			// Contrôle de hack pour une agence
			if ((($niv_util == 4) OR ($niv_util == 3)) AND ($int_codeage <> @$HTTP_SESSION_VARS["code_age"]))
				$pbm_intpdf=TRUE;
			
			if ($pbm_intpdf==FALSE)
			{
				$int_datecreaf = formatedate($int_datecrea);
				$int_datemodf = formatedate($int_datemod);
				$int_dateddef = formatedate($int_datedde);
				$int_daterdvf = formatedate($int_daterdv);
				$int_dateprevf = formatedate($int_dateprev);
				$int_datefinf = formatedate($int_datefin);
		
				$row = lit_enr_age($int_codeage);
				extract ($row);
		
				$cp_age = Retournecp($age_ville);
				$ville_age = Retourneville($age_ville);
		
				// Coordonnées compte client
				$row = lit_enr_cli($int_codecli);
				extract ($row);
		
				// Coordonnées site intervention
				if ($int_idsite>0)
				{
					$row = lit_enr_scli($int_idsite);
					extract ($row);
				}
		
				// Coordonnées technicien
				$row = lit_enr_tec($int_codetec);
				if (is_array($row))
					extract ($row);
		
				// Récupération du total travaillé & Techniciens traitants
				$nbtotalsec = 0;
				$str_tec_traitants = "";
				$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
				mysql_select_db(DBNAME);
		
				// Récupération total travaillé
				$rech = "SELECT * FROM `" .TBINTH. "` WHERE `inth_codeint`= '".$ci."'";
				$rs = mysql_query($rech);
				if (mysql_num_rows($rs) <> 0)
				{
					while ($row = mysql_fetch_assoc($rs)) 
					{         
						if ($row["inth_offert"] == 0)
							$nbtotalsec = $nbtotalsec + diff_time_sec($row["inth_heurea"],$row["inth_heured"]);
					}
				}
		
				// Chaîne des techniciens traitants
				$rech = "SELECT DISTINCT inth_codetec FROM `" .TBINTH. "` WHERE `inth_codeint`= '".$ci."'";
				$rs = mysql_query($rech);
				if (mysql_num_rows($rs) <> 0)
				{
					while ($row = mysql_fetch_assoc($rs)) 
					{
						$rech2 = "SELECT tec_nom, tec_prenom FROM `" .TBTEC. "` WHERE `tec_code`= '".$row["inth_codetec"]."' ORDER BY tec_nom";
						$rs2 = mysql_query($rech2);
						if (mysql_num_rows($rs2) <> 0)
						{
							if ($row2 = mysql_fetch_assoc($rs2))
								$str_tec_traitants .= $row2["tec_nom"]." ".$row2["tec_prenom"].", ";
						}
						mysql_free_result($rs2);
					}
				}
				$str_tec_traitants = substr($str_tec_traitants,0,strlen($str_tec_traitants)-2).".";
				mysql_free_result($rs);
				mysql_close($conn);
		
				require('../classes/fpdf/fpdf.php');
				
				/************************************/
				/* Fonctions globales               */
				/************************************/
				function hex2dec($color = "#000000"){
					$tbl_color = array();
					$tbl_color['R']=hexdec(substr($color, 1, 2));
					$tbl_color['G']=hexdec(substr($color, 3, 2));
					$tbl_color['B']=hexdec(substr($color, 5, 2));
					return $tbl_color;
				}
				
				function px2mm($px){
					return $px*25.4/72;
				}
				
				function txtentities($html)
				{
					$trans = get_html_translation_table(HTML_ENTITIES);
					$trans = array_flip($trans);
					return strtr($html, $trans);
				}
			
				function ConvertSize($size=5,$maxsize=0)
				{
				// Depends of maxsize value to make % work properly. Usually maxsize == pagewidth
				  //Identify size (remember: we are using 'mm' units here)
				  if ( stristr($size,'px') ) $size *= 0.2645; //pixels
				  elseif ( stristr($size,'cm') ) $size *= 10; //centimeters
				  elseif ( stristr($size,'mm') ) $size += 0; //millimeters
				  elseif ( stristr($size,'in') ) $size *= 25.4; //inches 
				  elseif ( stristr($size,'pc') ) $size *= 38.1/9; //PostScript picas 
				  elseif ( stristr($size,'pt') ) $size *= 25.4/72; //72dpi
				  elseif ( stristr($size,'%') )
				  {
					$size += 0; //make "90%" become simply "90" 
					$size *= $maxsize/100;
				  }
				  else $size *= 0.2645; //nothing == px
				  
				  return $size;
				}
		
				class PDF extends FPDF
				{
					//En-tête
					function Header()
					{
						global
							$niv_util,
							$int_code,
							$int_codeage,
							$int_dateddef,
							$int_daterdvf,
							$int_datehrdv,
							$int_dateprevf,
							$int_datefinf,
							$int_codestatut,
							$int_codelieu,
							$chemin_logos,
							$pv_ent_age,
							$pv_ent_int,
							$age_adr1,
							$age_adr2,
							$age_ville,
							$age_telf,
							$age_fax,
							$age_txtfax,
							$age_web,
							$age_email,
							$age_heures,
							$age_txtent,
							$cp_age,
							$ville_age;
							
				
		
						$pv_ent_age = 30; // Valeur de départ (mm) du pointeur pour l'affichage agence par rapport au bord haut de la feuille
										  // Cette valeur comprend la hauteur du logo (20 mm)
				
						$pv_ent_int = 20; // Valeur de départ (mm) du pointeur pour l'affichage de l'entête intervention par rapport au bord haut de la feuille
		
		
						// Logo Agence
						if (agence <> "")
						{
							$urlimg = $chemin_logos."/log".strtolower($int_codeage).".png"; 
						}
						$this->Image($urlimg,10,10,55,15); // Image à 10mm du bord gauche, 10mm du bord haut, largeur maximum 55mm
									
						// Entête Agence
						
							// N° de Siret
							$this->SetY($pv_ent_age);
							$this->SetFont('Arial','I',6);
							$this->Cell(95,3,$age_rcs,0,0,'L');
			
							// Coordonnées
							$ent_age = $age_adr1."\n";
							if ($age_adr2 <> "")
								$ent_age.= $age_adr2."\n";
							$ent_age.= $cp_age." ".$ville_age."\n";
							$ent_age.= "Tel : ";
							$ent_age.=$age_telf;
							if ($age_txttelf <> "")
								$ent_age.= " (".$age_txttelf.")\n";
							else
								$ent_age.= "\n";
							$ent_age.="Fax : ";
							$ent_age.= $age_fax;
							if ($age_txtfax <> "")
								$ent_age.= " (".$age_txtfax.")\n";
							else
								$ent_age.= "\n";
			
							$pv_ent_age = $pv_ent_age + 3;
							$this->SetY($pv_ent_age);
							$this->SetFont('Arial','',8);
							$this->MultiCell(95,3,$ent_age,0,'L');
			
							// Textes complémentaires
							$ent_age = "";
							if ($age_web <> "")
							{
								$ent_age = "Site Web : ";
								$ent_age.= $age_web." / ";
							}
							$ent_age.= "Email : ";
							$ent_age.= $age_email."\n";
							$ent_age.= "Horaires : ";
							$ent_age.= $age_heures."\n";
							$ent_age.= formatetxt($age_txtent);
							$this->SetFont('Arial','I',6); // Pas besoin de SetY car le MultiCell renvoie juste en dessous
							$this->MultiCell(95,3,$ent_age,0,'L');
							$pv_ent_age = $this->GetY(); // Récupération de la position du pointeur
			
						// Entête Intervention
						
						$this->SetY($pv_ent_int);
						$this->Cell(95);
						$this->SetFont('Arial','BU',14);
						if (($int_codestatut == "ACC") AND ($int_codelieu == "SITE")) // On attend une commande client pour intervention sur site
						{
							$this->Cell(95,10,'COMMANDE CLIENT',0,1,'C');
						}
						else
						{
							$this->Cell(95,10,'FICHE INTERVENTION',0,1,'C');
							$ent_int = 	"N°".$int_code."\n";
							$ent_int.= 	"Date création : ";
							$ent_int.= $int_dateddef;
							$pv_ent_int = $pv_ent_int + 10;
							$this->SetY($pv_ent_int);
							$this->Cell(95);
							$this->SetFont('Arial','',10);
							$this->MultiCell(95,5,$ent_int,0,'C');
						}
						
						if ($int_datefinf <> "")  // Affichage si intervention close
						{
							$this->SetY($pv_ent_age - 20);
							$this->Cell(95);
							$this->SetTextColor(200);
							$this->SetFont('Arial','B',14);
							$this->Cell(95,20,'TERMINEE',0,1,'C');
							$this->SetTextColor(0);
						}
			
						$this->SetY($pv_ent_age - 5); // Affichage du type d'état
						$this->Cell(95);
						$this->SetFont('Arial','I',8);
						if (($int_codestatut == "ACC") AND ($int_codelieu == "SITE")) // On attend une commande client pour intervention sur site
						{
							$this->Cell(95,5,'Demande d\'intervention',0,1,'R');
						}
						else  
						// Le client a déjà donné son accord
						{ 
							if ($int_dateprevf == "")
								$this->Cell(95,5,'Fiche de travail',0,1,'R');
							else
								$this->Cell(95,5,'Rapport de travail',0,1,'R');
						}
		
						$this->SetDrawColor(125);
						$this->SetLineWidth(0.4);
						$this->Line(10,$pv_ent_age,200,$pv_ent_age);
						$this->SetDrawColor(0);
						$this->SetLineWidth(0.2);
		
						// Duplicata pour les clients (pas de réimpression d'original pour le client !)
						if ($niv_util == 1)
							$this->fond("DUPLICATA");
				
						$pv_ent_age++;
		
					}
					
					//Pied de page
					function Footer()
					{
						//Positionnement à 1,5 cm du bas
						$this->SetY(-15);
						//Police Arial italique 8
						$this->SetFont('Arial','I',8);
						//Numéro de page
						$this->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'R');
					}
		
					var $B;
					var $I;
					var $U;
					var $HREF;
					var $fontList;
					var $issetfont;
					var $issetcolor;
					var $issetbgcolor;
					var $ex_fontsize;
					var $ex_lineheight;
					var $ex_x;
					var $ex_y;
					var $nb_ol;
					var $index_li;
					var $nb_ul;
					var $nb_li;
					var $nb_blockquote;
					var $tag_precedent;
					var $tab_rgb;
					var $pas_afficher;
					
					function PDF($orientation='P',$unit='mm',$format='A4')
					{
						//Appel au constructeur parent
						$this->FPDF($orientation,$unit,$format);
						//Initialisation
						$this->SetMargins(10,10,10,10);
						$this->SetFont('Arial','',10);
						$this->lineheight = 5;
						$this->SetFillColor(255,255,255);
						$this->B=0;
						$this->I=0;
						$this->U=0;
						$this->HREF='';
						$this->fontlist=array("arial","times","courier","helvetica","symbol");
						$this->issetfont=false;
						$this->issetcolor=false;
						$this->issetbgcolor=false;
						$this->ex_fontsize=10;
						$this->ex_lineheight=5;
						$this->ex_x=0;
						$this->ex_y=0;
						$this->nb_ol=0;
						$this->index_li=array();
						$this->nb_ul=0;
						$this->nb_li=0;
						$this->nb_bq=0;
						$this->tag_precedent='';
						$this->tab_rgb=array();
						$this->pas_afficher=FALSE;
						$this->largeur_page= $this->fw - $this->lMargin - $this->rMargin ;
					}
					
					function WriteHTML($html)
					{
						// Nettoyage des tags
						$str=array(
						'<br />' => '<br>',
						'<hr />' => '<hr>',
						'[r]' => '<red>',
						'[/r]' => '</red>',
						'[l]' => '<blue>',
						'[/l]' => '</blue>',
						'&#8220;' => '"',
						'&#8221;' => '"',
						'&#8222;' => '"',
						'&#8230;' => '...',
						'&#8217;' => '\''
						);
						foreach ($str as $_from => $_to) 
							$html = str_replace($_from,$_to,$html);
			
						//Suppression de tous les tags non supportés
						$html=strip_tags($html,"<a><br><font><blockquote><h1><h2><h3><h4><h5><h6><ul><li><b><i><u><strong><em><sub><sup><ol><div><span>");
						//Remplace les retours chariots, nouvelles lignes, et tabulations par des espaces
						$html=str_replace("\n",' ',$html);
						// $repTable = array("\t" => " ", "\n" => " ", "\r" => " ", "\0" => " ", "\x0B" => " "); 
						// $html = strtr($html, $repTable);
			
						//Remplace quelques caractères spéciaux
						$html = str_replace('&trade;','™',$html);
						$html = str_replace('&copy;','©',$html);
						$html = str_replace('&euro;','€',$html);
						
						$pattern = '/(<(?:[^<>]+(?:"[^"]*"|\'[^\']*\')?)+>)/';
			
						$a=preg_split($pattern,trim($html),-1,PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
						
						foreach($a as $key=>$element) 
						{
							if (!preg_match($pattern, $element)) 
							{
								//Texte
								if ($this->pas_afficher == FALSE)
								{
									if ($this->issetbgcolor == true)
									{
										$this->SetFillColor($this->tab_rgb[0],$this->tab_rgb[1],$this->tab_rgb[2]);
									}
									if($this->HREF) // Est-ce un lien ?
									{
										$this->PutLink($this->HREF,$element);
									}
									else 
									{
										// Vérification si blockquote, OL, ou UL
										if (($this->nb_bq > 0) OR ($this->nb_ol > 0) OR ($this->nb_ul > 0))
										{
											if (trim($element) <> "")
											{
												// On sauve la marge de gauche
												$lMargin = $this->lMargin;
												// Blockquote : blancs simples
												if ($this->nb_bq > 0)
												{
													$this->SetLeftMargin($this->nb_bq*10+$lMargin);
													$this->Write($this->lineheight,trim(stripslashes(txtentities($element))));
												}
												// OL ou UL : blancs + numérotation (ou pas)
												if ($this->nb_ol > 0)
												{
													$this->SetLeftMargin($this->nb_ol*10+$lMargin);
													$this->Write($this->lineheight,($this->index_li[$this->nb_ol]).'. '.trim(stripslashes(txtentities($element))));
												}
												if ($this->nb_ul > 0)
												{
													$this->SetLeftMargin($this->nb_ul*10+$lMargin);
													// $this->Write($this->lineheight,'» '.trim(stripslashes(txtentities($element))));
													$this->Write($this->lineheight,chr(149).' '.trim(stripslashes(txtentities($element))));
												}
												// On restaure la marge de gauche
												$this->SetLeftMargin($lMargin);
												$this->tag_precedent='';
											}
										}
										else
										{
											if (trim($element) <> "")
											{
												if ($this->issetbgcolor == true)
												{
													$this->Cell($this->GetStringWidth($element)+2,$this->lineheight,stripslashes(txtentities($element)),0,0,'L',1);
												}
												else
												{
													$this->Write($this->lineheight,stripslashes(txtentities($element)));
													
													// Si il y a un blanc à la fin de la chaîne, Write ne l'imprime pas
													// (ce qui "colle" le texte au suivant) : il faut donc le gérer.
													if ($element{(strlen($element)-1)} == " ")
													{
														$this->Cell($this->GetStringWidth(' '));
													}
													
												}
												$this->tag_precedent='';
											}
										}
									}
									$this->SetFillColor(255);
								}
							}
							else 
							{
								//Tag
								$element = substr($element, 1, -1);
								if($element{0}=='/') 
								{
									$this->CloseTag(strtoupper(substr($element,1)));
								}
								else 
								{
									// Attributs exacts
									// Récupération des tags
									preg_match('/([a-zA-Z0-9]*)/', $element, $tag);
									$tag = strtoupper($tag[0]);
									// Récupération des atributs
									preg_match_all('/([^=\s]*)=["\']?([^"\']*)["\']?/', $element, $attr_array, PREG_PATTERN_ORDER);
									$attr = array(); // reset attribute array
									while(list($id,$name)=each($attr_array[1])) {
										$attr[strtoupper($name)] = $attr_array[2][$id];
									}
									$this->OpenTag($tag,$attr);
								}
							}
						}
					}
					
					function OpenTag($tag,$attr)
					{
						//Balise ouvrante
						switch($tag)
						{
							case 'BR':
								$this->Ln($this->lineheight);
								break;
							case 'STRONG':
							case 'B':
								$this->SetStyle('B',true);
								break;
							case 'I':
							case 'EM':
								$this->SetStyle('I',true);
								break;
							case 'U':
								$this->SetStyle('U',true);
								break;
							case 'SUB': 
								$this->ex_fontsize = $this->FontSizePt;
								$this->ex_lineheight = $this->lineheight;
								$this->ex_x = $this->GetX();
								$this->ex_y = $this->GetY();
								$this->SetFontSize($this->ex_fontsize-3);
								$this->SetXY($this->ex_x, (($this->ex_y+($this->ex_fontsize*0.3))-2));					  
								break;
							case 'SUP': 
								$this->ex_fontsize = $this->FontSizePt;
								$this->ex_lineheight = $this->lineheight;
								$this->ex_x = $this->GetX();
								$this->ex_y = $this->GetY();
								$this->SetFontSize($this->ex_fontsize-3);
								$this->SetXY($this->ex_x, (($this->ex_y-($this->ex_fontsize*0.3))+2));
								break;
							case 'OL': 
								$this->nb_ol++;
								break;
							case 'UL': 
								$this->nb_ul++;
								break;
							case 'LI':
								$this->ln($this->lineheight);
								$this->nb_li++;
								if ($this->nb_ol > 0)
									$this->index_li[$this->nb_ol] = ($this->index_li[$this->nb_ol])+1;
								break;
							case 'BLOCKQUOTE':
								if($this->tag_precedent <> 'BLOCKQUOTE')
									$this->ln($this->lineheight);
								$this->nb_bq++;
								break;
							case 'H1': 
							  $this->SetFontSize(2*$this->FontSizePt); 
							  $this->lineheight *= 2;
							  break;
							case 'H2': 
							  $this->SetFontSize(1.5*$this->FontSizePt); 
							  $this->lineheight *= 1.5;
							  break;
							case 'H3':
							  $this->SetFontSize(1.17*$this->FontSizePt);
							  $this->lineheight *= 1.17;
							  break;
							case 'H4':
							  $this->SetFontSize($this->FontSizePt); 
							  break;
							case 'H5': 
							  $this->SetFontSize(0.83*$this->FontSizePt); 
							  $this->lineheight *= 0.83;
							  break;
							case 'H6': 
							  $this->SetFontSize(0.67*$this->FontSizePt); 
							  $this->lineheight *= 0.67;
							  break;
							case 'FONT':
							case 'SPAN':
							case 'DIV' :
								if ($tag == 'DIV')
								{
									$this->Ln($this->lineheight); // Toujours un saut de ligne sur balise DIV
								}
								if (isset($attr['COLOR']) and $attr['COLOR']!='') 
								{
									$coul=hex2dec($attr['COLOR']);
									$this->mySetTextColor($coul['R'],$coul['G'],$coul['B']);
									$this->issetcolor=true;
								}
								if (isset($attr['FACE']) and in_array(strtolower($attr['FACE']), $this->fontlist))
								{
									$this->SetFont(strtolower($attr['FACE']));
									$this->issetfont=true;
								}
								if (isset($attr['SIZE']) and $attr['SIZE']!='')
								{
									switch ($attr['SIZE'])
									{
										// Rapport de 1.2 entre chiffre, partant du principe que '4' = taille courante
										// Cf http://www.w3.org/TR/REC-CSS2/fonts.html#value-def-absolute-size
										case 1:
											$this->SetFontSize(0.58*$this->FontSizePt); 
											// $this->lineheight *= 0.58;
											break;
										case 2:
											$this->SetFontSize(0.69*$this->FontSizePt); 
											// $this->lineheight *= 0.69;
											break;
										case 3:
											$this->SetFontSize(0.83*$this->FontSizePt); 
											// $this->lineheight *= 0.83;
											break;
										case 4:
											// $this->SetFontSize($this->FontSizePt); 
											break;
										case 5:
											$this->SetFontSize(1.2*$this->FontSizePt); 
											// $this->lineheight *= 1.2;
											break;
										case 6:
											$this->SetFontSize(1.44*$this->FontSizePt); 
											// $this->lineheight *= 1.44;
											break;
										case 7:
											$this->SetFontSize(1.73*$this->FontSizePt); 
											// $this->lineheight *= 1.73;
											break;
									}
									$this->issetfont=true;
								}
								if (isset($attr['STYLE']) and $attr['STYLE']!='')
								{
									$attr_style = explode(";",$attr['STYLE']);
									for ($i=0; $i<count($attr_style);$i++)
									{
										if (trim($attr_style[$i]) <> "")
										{
											$detail_attr_style = explode(":",$attr_style[$i]);
											switch (strtolower(trim($detail_attr_style[0])))
											{
												case 'background-color' :
													// Mode Hexadécimal ?
													$pos = strpos(trim($detail_attr_style[1]), "#");
													if ($pos === FALSE)
													{
														// Mode RGB ?
														$pos2 = strpos(trim($detail_attr_style[1]), "(");
														if ($pos2 === FALSE)
														{
															break; // Aucun des 2, on quitte
														}
														else
														{
															$str_couleur = substr(trim($detail_attr_style[1]),$pos2+1);
															$str_couleur = substr($str_couleur,0,strlen($str_couleur)-1);
															$this->tab_rgb = explode(",",$str_couleur);
															for ($k=0; $k<count($this->tab_rgb); $k++)
															{
																settype($this->$tab_rgb[$k],"int");
															}
															$this->issetbgcolor=true;
														}
													}
													else
													{
														$coul=hex2dec(trim($detail_attr_style[1]));
														$this->SetFillColor($coul['R'],$coul['G'],$coul['B']);
														$this->issetbgcolor=true;
													}
													break;
												case 'page-break-after' :
													if (trim(strtolower($detail_attr_style[1])) == "always")
													{
														$this->AddPage();
													}
													break;
												case 'display' :
													if (trim(strtolower($detail_attr_style[1])) == "none")
													{
														$this->pas_afficher = TRUE;
													}
													break;
											}
										}
									}
								}
								break;
							case 'A':
								$this->HREF=$attr['HREF'];
								break;
							case 'SDP': // Pour conserver compatibilité avec anciens formats < SMI 0.9.5
								$this->AddPage();
								break;
							// Tableaux plus tard
							case 'TABLE':
							case 'TR':
							case 'TH':
							case 'TD':
								break;
						}
						$this->tag_precedent=$tag;
					}
					
					function CloseTag($tag)
					{
						//Balise fermante
						switch ($tag)
						{
							case 'STRONG':
							case 'B':
								$this->SetStyle('B',false);
								break;
							case 'I':
							case 'EM':
								$this->SetStyle('I',false);
								break;
							case 'U':
								$this->SetStyle('U',false);
								break;
							case 'SUB' :
							case 'SUP' :
								$this->SetFontSize($this->ex_fontsize);
								$this->SetXY($this->ex_x, $this->ex_y);					  
								$this->lineheight = $this->ex_lineheight;
								break;
							case 'OL': 
								$this->nb_ol = $this->nb_ol-1;
								if ($this->nb_ol == 0)
								{
									$this->SetLeftMargin(10);
									$this->ln($this->lineheight);
									$this->ln($this->lineheight);
								}
								break;
							case 'UL': 
								$this->nb_ul = $this->nb_ul-1;
								if ($this->nb_ul == 0)
								{
									$this->SetLeftMargin(10);
									$this->ln($this->lineheight);
									$this->ln($this->lineheight);
								}
								break;
							case 'LI' :
								$this->nb_li = $this->nb_li-1;
								break;
							case 'BLOCKQUOTE':
								$this->nb_bq = $this->nb_bq-1;
								break;
							case 'H1' :
							case 'H2' :
							case 'H3' :
							case 'H4' :
							case 'H5' :
							case 'H6' :
								$this->Ln($this->lineheight);
								$this->lineheight = 5;
								$this->SetFont('Arial','',10);
								$this->SetFontSize(11);
								$this->SetStyle('U',false);
								$this->SetStyle('B',false);
								break;
							case 'FONT' :
							case 'SPAN' :
							case 'DIV' :
								if ($tag == 'SPAN')
								{
									$this->pas_afficher = FALSE;
								}
								if ($tag == 'DIV')
								{
									$this->Ln($this->lineheight); // Toujours un saut de ligne sur balise DIV
								}
								if ($this->issetcolor==true) 
								{
									$this->SetTextColor(0,0,0);
								}
								if ($this->issetfont) 
								{
									$this->SetFont('Arial','',10);
									$this->issetfont=false;
								}
								if ($this->issetbgcolor == true) 
								{
									$this->SetFillColor(255,255,255);
									$this->issetbgcolor=false;
								}
								break;
							case 'A' :
								$this->HREF='';
								break;
							// Tableaux plus tard
							case 'TABLE':
							case 'TD':
							case 'TH':
								break;
							case 'TR':
								break;
						}
					}
					
					function SetStyle($tag,$enable)
					{
						//Modifie le style et sélectionne la police correspondante
						$this->$tag+=($enable ? 1 : -1);
						$style='';
						foreach(array('B','I','U') as $s)
							if($this->$s>0)
								$style.=$s;
						$this->SetFont('',$style);
					}
					
					function mySetTextColor($r,$g=0,$b=0)
					{
						static $_r=0, $_g=0, $_b=0;
				
						if ($r==-1) 
							$this->SetTextColor($_r,$_g,$_b);
						else 
						{
							$this->SetTextColor($r,$g,$b);
							$_r=$r;
							$_g=$g;
							$_b=$b;
						}
					}
					
					function PutLink($URL,$txt)
					{
						//Place un hyperlien
						$this->SetTextColor(0,0,255);
						$this->SetStyle('U',true);
						$this->Write($this->lineheight,$txt,$URL);
						$this->SetStyle('U',false);
						$this->SetTextColor(0);
					}

					function Rotate($angle,$x=-1,$y=-1)
					{
						if($x==-1)
							$x=$this->x;
						if($y==-1)
							$y=$this->y;
						if($this->angle!=0)
							$this->_out('Q');
						$this->angle=$angle;
						if($angle!=0)
						{
							$angle*=M_PI/180;
							$c=cos($angle);
							$s=sin($angle);
							$cx=$x*$this->k;
							$cy=($this->h-$y)*$this->k;
							$this->_out(sprintf('q %.5f %.5f %.5f %.5f %.2f %.2f cm 1 0 0 1 %.2f %.2f cm',$c,$s,-$s,$c,$cx,$cy,-$cx,-$cy));
						}
					}
					
					// Permet de rajouter un fonds de page en sous-impression
					function fond($texte)
					{
						$this->SetFont('Arial','B',60);
						$this->SetTextColor(203,203,203);
						$this->Rotate(45,55,100);
						$this->Text(55,100,$texte);
						$this->Rotate(0);
						$this->SetTextColor(0,0,0);
					}
				}
			
				$pdf=new PDF();
				$pdf->FPDF('P','mm','A4');
				$pdf->SetDisplayMode('real');
				$pdf->AliasNbPages();
				$pdf->SetTitle('Intervention N°'.$int_code);
				$pdf->SetSubject('Intervention N°'.$int_code);
				$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_int = $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
				if ($int_idsite==0) // S'il s'agit du site principal
				{
					$pdf->Cell(95,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(95,4,$ent_cli,'LR','L');
			
					$ent_cli = $cli_adr1."\n"; // Suite...
					$ent_cli.= $cli_adr2."\n";
					$ent_cli.= Retournecp($cli_ville)." ".Retourneville($cli_ville)."\n";
					$ent_cli.= "Tel : ".$cli_telf."\n";
					$ent_cli.= "Fax : ".$cli_fax;

					$pdf->SetFont('Arial','',10);
					$pdf->MultiCell(95,4,$ent_cli,'LRB','L');
				}
				else // S'il s'agit d'un site secondaire
				{
					$pdf->Cell(95,5,'SITE INTERVENTION','LTR',1,'C');
				
					$ent_scli = ""; // Détail
					$ent_scli.=$scli_ste."\n";
					$ent_scli.= $scli_rcivil." ".$scli_rprenom." ".$scli_rnom."\n";
					$pdf->SetFont('Arial','B',10);
					$pdf->MultiCell(95,4,$ent_scli,'LR','L');
			
					$ent_scli = $scli_adr1."\n"; // Suite...
					$ent_scli.= $scli_adr2."\n";
					$ent_scli.= Retournecp($scli_ville)." ".Retourneville($scli_ville)."\n";
					$ent_scli.= "Tel : ".$scli_telf."\n";
					$ent_scli.= "Fax : ".$scli_fax;

					$pdf->SetFont('Arial','',10);
					$pdf->MultiCell(95,4,$ent_scli,'LRB','L');
				}
		
				// Impression du détail intervention
		
				$pdf->SetY($pv_det_int); // Renvoie le pointeur SOUS l'entête agence
		
		
				$pdf->Cell(95);
				
				$pdf->SetFont('Arial','',8);  // Niveau d'urgence
				$pdf->Cell(95,5,$int_urg,'LTR',1,'R');
		
				$pdf->Cell(95);
		
				$ent_int = "Création :\n";
				$ent_int.= "Agence :\n";
				$ent_int.= "Contrat :\n";
				$ent_int.= "Origine :\n";
				$ent_int.= "Statut :\n";
				$ent_int.= "Lieu :\n";
				$ent_int.= "Rendez-vous :";
		
				$pdf->MultiCell(22,4,$ent_int,'B','R');
		
				$pdf->SetY($pv_det_int+5); // Renvoie le pointeur SOUS l'entête agence + 5mm (cellule niveau urgence)
				$pdf->Cell(117);
		
				$ent_int = $int_codecrea."\n";
				$ent_int.= $int_codeage."\n";
				if ($int_codecocl <> "")
					$ent_int.= $int_codecocl."\n";
				else
					$ent_int.= "-\n";
		
					// Récupération libellé origine
					$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
					mysql_select_db(DBNAME);
					$rs = mysql_query("SELECT * FROM ".TBORI." WHERE orig_code='".$int_codeorig."'");
					if ($row = mysql_fetch_array($rs))
					{
						extract($row);
					}
					mysql_free_result($rs);
					mysql_close($conn);
		
				$ent_int .= $orig_desc."\n";
		
					// Récupération libellé statut
					$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
					mysql_select_db(DBNAME);
					$rs = mysql_query("SELECT * FROM ".TBSTA." WHERE statut_code='".$int_codestatut."'");
					if ($row = mysql_fetch_array($rs))
					{
						extract($row);
					}
					mysql_free_result($rs);
					mysql_close($conn);
		
				$ent_int.= $statut_desc."\n";
		
					// Récupération libellé lieu
					$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
					mysql_select_db(DBNAME);
					$rs = mysql_query("SELECT * FROM ".TBLIEU." WHERE lieu_code='".$int_codelieu."'");
					if ($row = mysql_fetch_array($rs))
					{
						extract ($row);
					}
					mysql_free_result($rs);
					mysql_close($conn);
		
				$ent_int.= $lieu_desc."\n";
				if ($int_daterdvf <> "")
					$ent_int.= $int_daterdvf." (à partir de ".substr($int_hrdv,0,5).")\n";
				else
					$ent_int.= "-\n";
		
				$pdf->MultiCell(73,4,$ent_int,'BR','L');
				
				$pdf->ln(2);
				
				$pdf->SetLineWidth(0.2);
				$pdf->SetDrawColor(220);
		
				// Détail de la prise en charge
		
				$pdf->SetFont('Arial','B',10);
				$pdf->Cell(40,5,'Matériel : ',0,0,'R');
				$pdf->SetFont('Arial','',8);
				$pdf->MultiCell(150,4,$int_mat,1,'L');
		
				$pdf->ln(1);
		
				$pdf->SetFont('Arial','B',10);
				$pdf->Cell(40,5,'Descriptif Problème : ',0,0,'R');
				$pdf->SetFont('Arial','',8);
				$pdf->MultiCell(150,4,$int_pbm,1,'L');
				
				$pdf->ln(1);
		
				$pdf->SetFont('Arial','B',10);
				$pdf->Cell(40,5,'Garantie : ',0,0,'R');
				$pdf->SetFont('Arial','',8);
				if ($int_gar == 0)
					$pdf->Cell(8,5,'Non',0,0,'L');
				else
					$pdf->Cell(8,5,'Oui',0,0,'L');
				$pdf->SetFont('Arial','B',10);
				$pdf->Cell(40,5,'Référence Facture : ',0,0,'R');
				$pdf->SetFont('Arial','',8);
				$pdf->Cell(102,5,$int_fgar,0,1,'L');
		
				$pdf->ln(2);
		
				if (($int_codestatut == "ACC") AND ($int_codelieu == "SITE")) // On attend une commande client pour intervention sur site
				{
					if ($nbartint <> 0) // S'il y a des articles facturés, on les affiche
					{ 
						$texte="Coûts minimums indicatifs.";
						$pdf->SetFont('Arial','BI',8);
						$pdf->MultiCell(190,5,$texte,0,'L');
		
						$totalint = 0;
				
						$pdf->SetFont('Arial','B',8);
						$pdf->SetFillColor(0);
						$pdf->SetTextColor(255);
			
						$pdf->Cell(30,5,'Code',1,0,'C',1);
						$pdf->Cell(85,5,'Désignation + NS',1,0,'C',1);
						$pdf->Cell(30,5,'PU TTC',1,0,'C',1);
						$pdf->Cell(15,5,'Qté',1,0,'C',1);
						$pdf->Cell(30,5,'Total',1,1,'C',1);
			
						$pdf->SetFillColor(255);
						$pdf->SetTextColor(0);
			
						$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
						mysql_select_db(DBNAME);
						$rech = "SELECT ".TBPDTI.".*, ".TBPDT.".pdt_des FROM ".TBPDTI.", ".TBPDT."  WHERE ".TBPDTI.".pdti_codeint = '".$ci."' AND ".TBPDTI.".pdti_codepdt = ".TBPDT.".pdt_code ORDER BY ".TBPDTI.".pdti_codepdt";
						$rs = mysql_query($rech) or die(mysql_error());
					
						$i = 0;
			
						$pdf->SetFont('Arial','',8);
			
						while ($row = mysql_fetch_assoc($rs)) 
						{         
							$pv_det_art = $pdf->GetY();
			
							// Couleurs alternées
							if($i%2 == 0)  
								$pdf->SetFillColor(200);
							else
								$pdf->SetFillColor(255);
						
							$pdf->Cell(30,5,$row["pdti_codepdt"],'LR',0,'L',1);
							$pdf->Cell(85,5,$row["pdt_des"],'LR',0,'L',1);
							$pdf->Cell(30,5,$row["pdti_puttc"]."€",'LR',0,'R',1);
							$pdf->Cell(15,5,$row["pdti_qte"],'LR',0,'R',1);
							$total = $row["pdti_puttc"]*$row["pdti_qte"];
							$pdf->Cell(30,5,number_format($total,2,'.','')."€",'LR',1,'R',1);
		
							if ($row["pdti_ns"] <> "") // Numéro de série
							{
								$pdf->SetFont('Arial','I',7);
		
								$ligne_cesure = cesuretxt_tab($row["pdti_ns"],100);
								foreach ($ligne_cesure as $index_ligne=>$ligne)
								{
									$pdf->Cell(30,3,"",'LR',0,'L',1);
									$pdf->Cell(85,3,">> N/S : ".$ligne,'LR',0,'L',1);
									$pdf->Cell(30,3,"",'LR',0,'R',1);
									$pdf->Cell(15,3,"",'LR',0,'R',1);
									$pdf->Cell(30,3,"",'LR',1,'R',1);
								}
							}
		
							
							if ($row["pdti_texte"] <> "") // Commentaire
							{
								$ligne_cesure = cesuretxt_tab($row["pdti_texte"],100);
								foreach ($ligne_cesure as $index_ligne=>$ligne)
								{
									$pdf->Cell(30,3,"",'LR',0,'L',1);
									$pdf->Cell(85,3,$ligne,'LR',0,'L',1);
									$pdf->Cell(30,3,"",'LR',0,'R',1);
									$pdf->Cell(15,3,"",'LR',0,'R',1);
									$pdf->Cell(30,3,"",'LR',1,'R',1);
								}
							}
							
							$totalint = $totalint+$total;
			
							$i++;
						}  
				
						$pdf->SetFillColor(255);
						$pdf->SetFont('Arial','B',8);
						$pdf->Cell(160,5,"Total TTC :",1,0,'R');
						$pdf->Cell(30,5,number_format($totalint,2,'.','')."€",1,1,'R');
			
						mysql_free_result($rs);
						mysql_close($conn);
					}
		
					$y_courant = $pdf->GetY();
					
					$pdf->SetDrawColor(0);
					$pdf->SetLineWidth(0.4);
					$pdf->Line(10,$y_courant,200,$y_courant);
					$pdf->SetDrawColor(200);
					$pdf->SetLineWidth(0.2);
		
									
					$pdf->ln(2);
		
					$texte ="Madame, Monsieur,\n";
					$texte.="Vous voudrez bien trouver ci-dessus notre proposition d'intervention à l'adresse sus-indiquée.\n";
					$texte.="Cette proposition s'entend uniquement pour le matériel décrit ci-dessus et implique l'acceptation totale de votre part de nos conditions";
					$texte.=" commerciales et tarifaires, ainsi que nos conditions générales de vente.\n";
					$texte.="En cas d'accord, nous vous demandons de bien vouloir nous la retourner, paraphée, tamponnée et signée, avec la mention";
					$texte.=" \"bon pour intervention\".\n";
					$texte.="Vous remerciant encore de la confiance que vous nous accordez,\n";
					$texte.="Nous vous priond d'agréer, Madame, Monsieur, à l'expression de nos sentiments les plus dévoués.\n";
					$texte.="\n";
					$pdf->SetFont('Arial','',10);
					$pdf->MultiCell(190,5,$texte,0,'L');
					$texte ="La direction technique.\n";
					$pdf->SetFont('Arial','',10);
					$pdf->MultiCell(190,5,$texte,0,'R');
					$texte="P.S. : L'heure indiquée est indicative et peut varier en fonction des conditions de circulation.\n\n";
					$pdf->SetFont('Arial','',8);
					$pdf->MultiCell(190,5,$texte,0,'L');
		
					$pdf->SetFont('Arial','BU',10);
					$pdf->Cell(95);
					$pdf->Cell(95,5,"Tampon, Date & Signature client",'LTR',1,'C');
					$pdf->Cell(95);
					$pdf->SetFont('Arial','I',8);
					$pdf->Cell(95,5,"Bon pour intervention",'LR',1,'C');
					for ($i; $i<7; $i++)
					{
						$pdf->Cell(95);
						$pdf->Cell(95,5,"",'LR',1,'L');
					}
					$pdf->Cell(95);
					$pdf->Cell(95,5,"",'LRB',1,'L');
				}
				else // On attend pas de confirmation client
				{
			
					// Détail du traitement du dossier
			
					$pdf->SetFont('Arial','B',10);
					$pdf->Cell(40,5,'Technicien Responsable : ',0,0,'R');
					$pdf->SetFont('Arial','',8);
					$pdf->MultiCell(150,4,$tec_civilite." ".$tec_prenom." ".$tec_nom,1,'L');
			
					$pdf->ln(1);
			
					$pdf->SetFont('Arial','B',10);
					$pdf->Cell(40,5,'Technicien(s) traitant(s) : ',0,0,'R');
					$pdf->SetFont('Arial','',8);
					$pdf->MultiCell(150,4,$str_tec_traitants,1,'L');
			
					$pdf->ln(1);
			
					
		
					$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
					mysql_select_db(DBNAME);
			
					$rech = "SELECT * FROM `" .TBINTH. "` WHERE `inth_codeint`= '".$ci."' ORDER BY inth_date";
					$rs = mysql_query($rech);
					if (mysql_num_rows($rs) <> 0)
					{
						$pdf->SetFont('Arial','B',8);
						$pdf->Cell(40,5,'Détail horaires & techniciens : ',0,1,'R');
						$pdf->SetFont('Arial','',8);
						$pdf->SetFont('Arial','IU',7); // Titres
						$pdf->Cell(7);
						$pdf->Cell(14,4,'Date',1,0,'C');
						$pdf->Cell(50,4,'Technicien',1,0,'C');
						$pdf->Cell(50,4,'Lieu',1,0,'C');
						$pdf->Cell(16,4,'Heure début',1,0,'C');
						$pdf->Cell(16,4,'Heure fin',1,0,'C');
						$pdf->Cell(16,4,'Temps passé',1,0,'C');
						$pdf->Cell(10,4,'Offert',1,1,'C');
						$pdf->SetFont('Arial','I',8);
		
						while ($row = mysql_fetch_assoc($rs)) 
						{         
							extract($row);
		
							// Ligne 1
							$pdf->Cell(7);
							$pdf->SetFont('Arial','I',7);
							$pdf->Cell(14,4,formatedate($inth_date),'LR',0,'C');
							$pdf->Cell(50,4,$inth_codetec,'LR',0,'L');
							$rech2 = "SELECT * FROM ".TBLIEU." WHERE `lieu_code` = '".$inth_codelieu."'";
							$rs2 = mysql_query($rech2) or die(mysql_error());
							if (mysql_num_rows($rs2) <> 0)
							{
								if ($row2 = mysql_fetch_array($rs2))
									extract($row2);
							}
							$pdf->Cell(50,4,$lieu_desc,'LR',0,'L');
							$pdf->Cell(16,4,$inth_heurea,'LR',0,'C');
							$pdf->Cell(16,4,$inth_heured,'LR',0,'C');
							$pdf->Cell(16,4,sec_heure(diff_time_sec($inth_heurea,$inth_heured)),'LR',0,'C');
							if ($inth_offert == 1)
								$pdf->Cell(10,4,'oui','LR',1,'C');
							else
								$pdf->Cell(10,4,'-','LR',1,'C');
		
							// Ligne 2
							$pdf->Cell(7);
							$pdf->SetFont('Arial','I',7);
							$pdf->Cell(14,4,'','LR',0,'C');
							$rech2 = "SELECT * FROM ".TBTEC." WHERE `tec_code` = '".$inth_codetec."'";
							$rs2 = mysql_query($rech2) or die(mysql_error());
							if (mysql_num_rows($rs2) <> 0)
							{
								if ($row2 = mysql_fetch_array($rs2))
									extract($row2);
							}
							$pdf->Cell(50,4,$tec_nom." ".$tec_prenom,'LR',0,'L');
							$pdf->Cell(50,4,'','LR',0,'L');
							$pdf->Cell(16,4,'','LR',0,'C');
							$pdf->Cell(16,4,'','LR',0,'C');
							$pdf->Cell(16,4,'','LR',0,'C');
							$pdf->Cell(10,4,'','LR',1,'C');
						}
						$PosY = $pdf->GetY();
						$pdf->Line(17,$PosY,189,$PosY); // On "ferme" le tableau
		
						// Totaux
						$pdf->SetFont('Arial','IB',7);
						$pdf->Cell(137);
						$pdf->Cell(16,4,'Temps retenu :',0,0,'R');
						$pdf->Cell(16,4,sec_heure($nbtotalsec),0,1,'C');
					}
					else
					{
						$pdf->SetFont('Arial','B',8);
						$pdf->Cell(40,5,'Détail horaires & techniciens : ',0,0,'R');
						$pdf->SetFont('Arial','',8);
						$pdf->Cell(150,4,'Pas de détail',1,1,'L');
					}
			
					$pdf->ln(1);
			
					$pdf->SetFont('Arial','B',10);
					$pdf->Cell(40,5,'Travail Effectué : ',0,0,'R');
					if ($int_fait == "")
					{
						for ($i=0; $i<10; $i++)
						{
							$int_fait.="\n";
						}
					}
					$pdf->SetFont('Arial','',8);
					$pdf->MultiCell(150,4,$int_fait,1,'L');
			
					// On affiche la date où le client a été prévenu uniquement si elle a été complétée
					if ($int_dateprevf <> "")
					{
						$pdf->ln(2);
				
						$pdf->SetFont('Arial','B',10);
						$pdf->Cell(40,5,'Client prévenu le : ',0,0,'R');
						$pdf->SetFont('Arial','',8);
						$pdf->MultiCell(150,4,$int_dateprevf,1,'L');
					}
			
					if ($int_codestatut == "CLOT") // On affiche uniquement le règlement si l'intervention est close (sinon, c'est inutile)
					{
						$pdf->ln(2);
				
						$pdf->SetFont('Arial','B',10);
						$pdf->Cell(40,5,'Règlement : ',0,0,'R');
			
							// Récupération du libellé règlement
							$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
							mysql_select_db(DBNAME);
							$rs = mysql_query("SELECT * FROM ".TBREG." WHERE reg_code='".$int_codereg."'");
							while ($resultat = mysql_fetch_array($rs)) 
							{
								extract($resultat);
							}
							mysql_free_result($rs);
							mysql_close($conn);
			
						$pdf->SetFont('Arial','',8);
						$pdf->MultiCell(150,4,$reg_desc,1,'L');
					}
			
					// Affichage de la date de fin uniquement si terminé
					if ($int_datefinf <> "")
					{
						$pdf->ln(2);
			
						$pdf->SetFont('Arial','B',10);
						$pdf->Cell(40,5,'Interv. close le : ',0,0,'R');
						$pdf->SetFont('Arial','',8);
						$pdf->MultiCell(150,4,$int_datefinf,1,'L');
					}
			
					$pdf->ln(2);
			
					if ($int_durees <> 0) // On affiche ce titre s'il y a eu un traitement effectué
					{
						$pdf->SetFont('Arial','BU',10);
						$pdf->Cell(190,5,'Forfaits facturés et pièces changées',0,1,'C');
						$pdf->ln(1);
					}
			
					if ($nbartint <> 0) // S'il y a des articles facturés, on les affiche
					{ 
						$totalint = 0;
				
						$pdf->SetFont('Arial','B',8);
						$pdf->SetFillColor(0);
						$pdf->SetTextColor(255);
			
						$pdf->Cell(30,5,'Code',1,0,'C',1);
						$pdf->Cell(85,5,'Désignation + NS',1,0,'C',1);
						$pdf->Cell(30,5,'PU TTC',1,0,'C',1);
						$pdf->Cell(15,5,'Qté',1,0,'C',1);
						$pdf->Cell(30,5,'Total',1,1,'C',1);
			
						$pdf->SetFillColor(255);
						$pdf->SetTextColor(0);
			
						$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
						mysql_select_db(DBNAME);
						$rech = "SELECT ".TBPDTI.".*, ".TBPDT.".pdt_des FROM ".TBPDTI.", ".TBPDT."  WHERE ".TBPDTI.".pdti_codeint = '".$ci."' AND ".TBPDTI.".pdti_codepdt = ".TBPDT.".pdt_code ORDER BY ".TBPDTI.".pdti_id";
						$rs = mysql_query($rech) or die(mysql_error());
					
						$i = 0;
			
						$pdf->SetFont('Arial','',7);
			
						while ($row = mysql_fetch_assoc($rs)) 
						{
							$pv_det_art = $pdf->GetY();
			
							// Couleurs alternées
							if($i%2 == 0)  
								$pdf->SetFillColor(200);
							else
								$pdf->SetFillColor(255);
						
							$pdf->Cell(30,5,$row["pdti_codepdt"],'LR',0,'L',1);
							$pdf->Cell(85,5,$row["pdt_des"],'LR',0,'L',1);
							$pdf->Cell(30,5,$row["pdti_puttc"]."€",'LR',0,'R',1);
							$pdf->Cell(15,5,$row["pdti_qte"],'LR',0,'R',1);
							$total = $row["pdti_puttc"]*$row["pdti_qte"];
							$pdf->Cell(30,5,number_format($total,2,'.','')."€",'LR',1,'R',1);
		
							if ($row["pdti_ns"] <> "")
							{
								$pdf->SetFont('Arial','I',7);
		
								$ligne_cesure = cesuretxt_tab($row["pdti_ns"],100);
								foreach ($ligne_cesure as $index_ligne=>$ligne)
								{
									$pdf->Cell(30,3,"",'LR',0,'L',1);
									$pdf->Cell(85,3,">> N/S : ".$row["pdti_ns"],'LR',0,'L',1);
									$pdf->Cell(30,3,"",'LR',0,'R',1);
									$pdf->Cell(15,3,"",'LR',0,'R',1);
									$pdf->Cell(30,3,"",'LR',1,'R',1);
								}
							}
		
							if ($row["pdti_texte"] <> "") // Commentaire
							{
								$ligne_cesure = cesuretxt_tab($row["pdti_texte"],100);
								foreach ($ligne_cesure as $index_ligne=>$ligne)
								{
									$pdf->Cell(30,3,"",'LR',0,'L',1);
									$pdf->Cell(85,3,$ligne,'LR',0,'L',1);
									$pdf->Cell(30,3,"",'LR',0,'R',1);
									$pdf->Cell(15,3,"",'LR',0,'R',1);
									$pdf->Cell(30,3,"",'LR',1,'R',1);
								}
							}
		
							$totalint = $totalint+$total;
		
							$i++;
						}  
		
						mysql_free_result($rs);
						mysql_close($conn);
		
						 // Si sur site et intervention non close (donc à effectuer), préparation d'une grille complémentaire de saisie articles & prestations
						if (($int_codelieu == "SITE") AND ($int_codestatut <> "CLOT"))
						{
							while ($i <=5) 
							{         
					
								// Couleurs alternées
								if($i%2 == 0)  
									$pdf->SetFillColor(200);
								else
									$pdf->SetFillColor(255);
							
								$pdf->Cell(30,4,'','LR',0,'L',1);
								$pdf->Cell(85,4,'','LR',0,'L',1);
								$pdf->Cell(30,4,"€",'LR',0,'R',1);
								$pdf->Cell(15,4,'','LR',0,'R',1);
								$pdf->Cell(30,4,"€",'LR',1,'R',1);
				
								$i++;
							}
						}
				
						$pdf->SetFillColor(255);
						$pdf->SetFont('Arial','B',8);
						$pdf->Cell(160,5,"Total TTC :",1,0,'R');
						$pdf->Cell(30,5,number_format($totalint,2,'.','')."€",1,1,'R');
						$pdf->Cell(160,5,"Acompte :",1,0,'R');
						$pdf->Cell(30,5,"-".number_format($int_acpte,2,'.','')."€",1,1,'R');
						$pdf->Cell(160,5,"Net à payer :",1,0,'R');
						$pdf->Cell(30,5,number_format(($totalint-$int_acpte),2,'.','')."€",1,1,'R');
			
						$pdf->ln(1);
			
						$pdf->SetFont('Arial','B',10);
						$pdf->Cell(60,5,"Pièces hors service :",0,0,'R');
			
						$pdf->SetFont('Arial','',10);
						if ($int_pces == 0)
							$pdf->Cell(60,5,"Sans objet",0,1,'L');
						if ($int_pces == 1)
							$pdf->Cell(60,5,"Rendues",0,1,'L');
						if ($int_pces == 2)
							$pdf->Cell(60,5,"Conservées",0,1,'L');
					}
					else
					{
						 // Si sur site et intervention non close (donc à effectuer), préparation d'une grille de saisie articles & prestations
						if (($int_codelieu == "SITE") AND ($int_codestatut <> "CLOT"))
						{
							$pdf->SetFont('Arial','B',8);
							$pdf->SetFillColor(0);
							$pdf->SetTextColor(255);
				
							$pdf->Cell(30,5,'Code',1,0,'C',1);
							$pdf->Cell(85,5,'Désignation + NS',1,0,'C',1);
							$pdf->Cell(30,5,'PU TTC',1,0,'C',1);
							$pdf->Cell(15,5,'Qté',1,0,'C',1);
							$pdf->Cell(30,5,'Total',1,1,'C',1);
				
							$pdf->SetFillColor(255);
							$pdf->SetTextColor(0);
				
							$i = 0;
					
							while ($i <=5) 
							{         
					
								// Couleurs alternées
								if($i%2 == 0)  
									$pdf->SetFillColor(200);
								else
									$pdf->SetFillColor(255);
							
								$pdf->Cell(30,4,'','LR',0,'L',1);
								$pdf->Cell(85,4,'','LR',0,'L',1);
								$pdf->Cell(30,4,"€",'LR',0,'R',1);
								$pdf->Cell(15,4,'','LR',0,'R',1);
								$pdf->Cell(30,4,"€",'LR',1,'R',1);
				
								$i++;
							}  
					
							$pdf->SetFillColor(255);
							$pdf->SetFont('Arial','B',8);
							$pdf->Cell(160,5,"Total TTC :",1,0,'R');
							$pdf->Cell(30,5,"€",1,1,'R');
							
							$pdf->ln(1);
			
							$pdf->SetFont('Arial','B',10);
							$pdf->Cell(60,5,"Pièces hors service :",0,0,'R');
			
							$pdf->SetFont('Arial','',10);
							$pdf->Cell(60,5,"Sans objet / Rendues / Conservées (Rayer inutile)",0,1,'L');
						}
						else
						{
							if ($int_durees <> 0) // On affiche ce texte s'il y a eu un traitement effectué
							{
								$pdf->SetFont('Arial','BI',8);
								$pdf->Cell(30,5,'Aucun article ou prestation.',0,1,'L');
							}
						}
					}
			
					$pdf->ln(2);
			
					$pdf->SetLineWidth(0.2);
					$pdf->SetDrawColor(0);
			
					if ($int_codestatut <> "CLOT") // On affiche un pied de fiche intervention uniquement si c'est non clot
					{
						if ($str_tec_traitants == "") // Si pas déjà traité, texte préalable que le client doit accepter en le signant
						{
							$row = lit_enr_txt("CGV_SAV");
							extract ($row);
		
							$row = lit_enr_age($int_codeage);
							extract ($row);
		
							$txt_sav = parse_txt("age",$age_code,$txt_texte)."<BR>"; // BR important pour retour à la ligne final
		
							$pdf->SetFont('Arial','',6);
							$pdf->WriteHTML($txt_sav);
						}
						
						 // Si sur site (donc à effectuer), préparation d'une grille de saisie de paramètres
						if ($int_codelieu == "SITE")
						{
							if ($str_tec_traitants == "") // Si pas déjà traité (Sinon, pas de pied)
							{
								// Si on est trop bas pour afficher la zone de signature, on effectue un saut de page
								$y_courant = $pdf->GetY();
								if ($y_courant > 245)
									$pdf->AddPage();
		
								$pdf->SetFont('Arial','BU',10);
								$pdf->SetFillColor(200);
								$pdf->Cell(95,5,"Horaires arrivée/ départ",'LTR',0,'C');
								$pdf->Cell(95,5,"Date & Signature Client :",'LTR',1,'C');
								$pdf->Cell(95,5,"",'LR',0,'L',1);
								$pdf->SetFont('Arial','I',8);
								$pdf->Cell(95,5,"Lu et approuvé",'LR',1,'C');
								$pdf->SetFont('Arial','BU',10);
								$pdf->Cell(95,5,"Intervention terminée / non terminée",'LTR',0,'C');
								$pdf->Cell(95,5,"",'LR',1,'L');
								$pdf->Cell(95,5,"",'LR',0,'L',1);
								$pdf->Cell(95,5,"",'LR',1,'L');
								$pdf->Cell(95,5,"Règlement",'LTR',0,'C');
								$pdf->Cell(95,5,"",'LR',1,'L');
								$pdf->Cell(95,5,"",'LRB',0,'L',1);
								$pdf->Cell(95,5,"",'LRB',1,'L');
							}
						}
						else
						{
							// Si on a pas encore traité l'intervention, on demande signature de demande de travaux
							if ($str_tec_traitants == "")
							{
								// Si on est trop bas pour afficher la zone de signature, on effectue un saut de page
								$y_courant = $pdf->GetY();
								if ($y_courant > 230)
									$pdf->AddPage();
		
								$pdf->Ln(5);
		
								$pdf->SetFont('Arial','BU',10);
								$pdf->Cell(47);
								$pdf->Cell(95,5,"Date & Signature client (Demande de travaux)",'LTR',1,'C');
								$pdf->SetFont('Arial','I',8);
								$pdf->Cell(47);
								$pdf->Cell(95,5,"Lu et approuvé",'LR',1,'C');
								for ($i=0; $i<5; $i++)
								{
									$pdf->Cell(47);
									$pdf->Cell(95,5,"",'LR',1,'L');
								}
								$pdf->Cell(47);
								$pdf->Cell(95,5,"",'LRB',1,'L');
							}
			
							// Si on a traité le dossier et que le client est prévenu, on affiche une zone de signature de travaux effectués
							if (($int_durees <> 0) AND ($int_dateprevf <> ""))
							{
								// Si on est trop bas pour afficher la zone de signature, on effectue un saut de page
								$y_courant = $pdf->GetY();
								if ($y_courant > 230)
									$pdf->AddPage();
		
								$pdf->Ln(5);
		
								$pdf->SetFont('Arial','BU',10);
								$pdf->Cell(47);
								$pdf->Cell(95,5,"Date & Signature client (Travaux effectués)",'LTR',1,'C');
								$pdf->Cell(47);
								$pdf->SetFont('Arial','I',8);
								$pdf->Cell(95,5,"Lu et approuvé",'LR',1,'C');
								for ($i=0; $i<5; $i++)
								{
									$pdf->Cell(47);
									$pdf->Cell(95,5,"",'LR',1,'L');
								}
								$pdf->Cell(47);
								$pdf->Cell(95,5,"",'LRB',1,'L');
							}
						}
					}
				}
		
				if ($cgv == TRUE)
				{
					$pdf->AddPage();
					
					$row = lit_enr_txt("CGV_MASTER");
					extract ($row);
		
					$pdf->SetFont('Arial','BU',10);
					$txt_ent = parse_txt("cdg","",$txt_entete);
					$pdf->MultiCell(190,5,$txt_ent."\n\n",0,'C');
		
					$txt_texte = formatetxt($txt_texte);
					$txt_cgv = parse_txt("cdg","",$txt_texte)."<BR>"; // BR important pour retour à la ligne final
		
					$pdf->SetFont('Arial','',6);
					$pdf->WriteHTML($txt_cgv);
				}
		/*
				//Détermination d'un nom de fichier temporaire dans le répertoire courant
				$file=basename(tempnam(getcwd(),'tmp'));
				rename($file,$file.'.pdf');
				$file.='.pdf';
		*/
				// $pdf->Output($file,'D');
				$pdf->Output('int_'.$int_code,'I');
			}
		}
		else
		{
			$pbm_intpdf = TRUE;
		}			
	}
	else
	{
		$pbm_intpdf = TRUE;
	}

	if ($pbm_intpdf == TRUE)
	{
	?>
		<script type="text/javascript">
		self.close('');
		</script>
	<?PHP
	}
	?>
