1 |
<?php |
2 |
/** |
3 |
* Classe de base permettant l'édition d'un document pdf à imprimer sur |
4 |
* les feuillets d'accusé de récéption de la poste |
5 |
* |
6 |
* @package openfoncier |
7 |
* @version SVN : $Id$ |
8 |
*/ |
9 |
|
10 |
require_once "../core/fpdf_etat.php"; |
11 |
|
12 |
/** |
13 |
* |
14 |
*/ |
15 |
class pdf_lettre_rar extends PDF{ |
16 |
|
17 |
private $pdf; |
18 |
private $utils; |
19 |
private $filename; |
20 |
private $adresse_dest; |
21 |
private $adresse_emetteur; |
22 |
private $specifique_content; |
23 |
private $font = 'Helvetica'; |
24 |
private $fontsize = 10; |
25 |
private $path; |
26 |
private $cell_width = 84; |
27 |
private $cell_height = 7; |
28 |
|
29 |
|
30 |
// Initialisation des attributs |
31 |
function init($f, $filename = "lettre_rar", |
32 |
$path = "../tmp/", $font = 'Helvetica', $fontsize = 10 ){ |
33 |
|
34 |
// Definition des attributs |
35 |
$this->filename = $filename.date("dmYHis"); |
36 |
$this->path = $path; |
37 |
$this->font = $font; |
38 |
$this->fontsize = $fontsize; |
39 |
$this->utils = $f; |
40 |
$this->adresse_emetteur = explode("\n",$this->utils->getParameter('adresse_direction_urbanisme_RAR')); |
41 |
if (DBCHARSET=="UTF8"){ |
42 |
$this->adresse_emetteur = $this->encodeToUtf8($this->adresse_emetteur); |
43 |
} |
44 |
|
45 |
//Paramétrage du pdf |
46 |
$this->SetFont($font, '', $fontsize); |
47 |
$this->SetMargins(0,0,0); |
48 |
$this->SetAutoPageBreak(false, 0); |
49 |
$this->setPrintHeader(false); |
50 |
} |
51 |
|
52 |
// Ajout d'une page au document pdf |
53 |
function addLetter($adresse_dest, $specifique_content) { |
54 |
|
55 |
$this->adresse_dest = $adresse_dest; |
56 |
$this->specifique_content = $specifique_content; |
57 |
//Formatage des données si la base de données est en UTF8 |
58 |
if(DBCHARSET=="UTF8"){ |
59 |
$this->adresse_dest = $this->encodeToUtf8($adresse_dest); |
60 |
$this->specifique_content = $this->encodeToUtf8($specifique_content); |
61 |
} |
62 |
$this->addPage(); |
63 |
$this->printAvisPassage(); |
64 |
$this->printPreuveDistri(); |
65 |
$this->printAvisRecept(); |
66 |
} |
67 |
|
68 |
// Insertion des adresses dans la partie "Avis de passage" |
69 |
private function printAvisPassage() { |
70 |
if( DEBUG != 0) { |
71 |
$this->SetXY(0, 0); |
72 |
$this->SetDrawColor(255, 215, 0); |
73 |
$this->Cell(209.5, 98.5,"",1,2,true); |
74 |
} |
75 |
$this->printCellRAR(35, 37, $this->adresse_dest); |
76 |
$this->printCellRAR(120, 37, $this->adresse_dest); |
77 |
} |
78 |
|
79 |
// Insertion des adresses dans la partie "Preuve de distribution" |
80 |
private function printPreuveDistri() { |
81 |
if( DEBUG != 0) { |
82 |
$this->SetXY(0, 98.5); |
83 |
$this->SetDrawColor(131, 131, 131); |
84 |
$this->Cell(209.5, 101.5,"",1,2,true); |
85 |
} |
86 |
$this->printCellRAR(55, 138, $this->adresse_dest); |
87 |
$this->printCellRAR(55, 167, $this->adresse_emetteur, true); |
88 |
} |
89 |
|
90 |
// Insertion des adresses dans la partie "Avis de reception" |
91 |
private function printAvisRecept() { |
92 |
if( DEBUG != 0) { |
93 |
$this->SetXY(0, 200); |
94 |
$this->SetDrawColor(205, 51, 51); |
95 |
$this->Cell(209.5, 97,"",1,2,true); |
96 |
} |
97 |
$this->printCellRAR(55, 226, $this->specifique_content, true); |
98 |
$this->printCellRAR(55, 257, $this->adresse_emetteur, true); |
99 |
} |
100 |
|
101 |
// Insertion d'une adresse |
102 |
private function printCellRAR($left, $top, $content,$fullBold = false) { |
103 |
|
104 |
// 1ere ligne en gras |
105 |
$this->SetFont($this->font, 'B', $this->fontsize); |
106 |
$this->SetXY($left, $top); |
107 |
$border = 0; |
108 |
if( DEBUG != 0) { |
109 |
$this->SetDrawColor(0, 0, 0); |
110 |
$border = 1; |
111 |
} |
112 |
foreach ($content as $line) { |
113 |
|
114 |
//Gestion du code barres |
115 |
if ( preg_match('/^\|{5}[0-9]{12}\|{5}$/', $line)){ |
116 |
$this->Code128($this->GetX()+19, $this->GetY(), str_replace("|||||", "", $line), 50, 8); |
117 |
$this->Cell($this->cell_width, $this->cell_height*2,"",$border,2,false); |
118 |
} |
119 |
else{ |
120 |
$this->Cell($this->cell_width, $this->cell_height,/*utf8_decode(*/trim($line)/*)*/,$border,2,false); |
121 |
} |
122 |
// test si tout le contenu de la cellule doit être en gras |
123 |
if(!$fullBold) { |
124 |
$this->SetFont($this->font, '', $this->fontsize); |
125 |
} |
126 |
} |
127 |
|
128 |
} |
129 |
|
130 |
// Récupération du fichier |
131 |
function getFile() { |
132 |
$this->Output($this->path.$this->filename.".pdf", 'F'); |
133 |
return $this->path.$this->filename.".pdf"; |
134 |
} |
135 |
|
136 |
// setters |
137 |
function setPath($path) { |
138 |
$this->path = $path; |
139 |
} |
140 |
function setFilename($filename) { |
141 |
$this->filename = $filename; |
142 |
} |
143 |
|
144 |
|
145 |
//Surchage afin que le nombre de page ne s'affiche pas |
146 |
function Footer() { |
147 |
} |
148 |
|
149 |
/** |
150 |
* Encode les données passées au tableau en paramètre en UTF8 |
151 |
* @param $data array Le tableau de données à traiter |
152 |
* |
153 |
* @return array Le tableau de données encodées en UTF8 |
154 |
*/ |
155 |
function encodeToUtf8($data) { |
156 |
|
157 |
//Tableau de résultats |
158 |
$res = array(); |
159 |
//Liste des encodages possibles |
160 |
$encodage = array("UTF-8", "ASCII", "Windows-1252", "ISO-8859-15", "ISO-8859-1"); |
161 |
|
162 |
foreach ($data as $key => $value) { |
163 |
// |
164 |
$res[] = iconv(mb_detect_encoding($value,$encodage), "UTF-8", $value); |
165 |
} |
166 |
|
167 |
return $res; |
168 |
} |
169 |
} |
170 |
?> |