1652 |
raphael |
1 |
<?php
|
|
|
2 |
|
1664 |
raphael |
3 |
/**
|
|
|
4 |
* @category PHP
|
|
|
5 |
* @package jrest
|
|
|
6 |
* @author Raphaël Droz <raphael@tela-botania.org>
|
|
|
7 |
* @copyright 2013 Tela-Botanica
|
|
|
8 |
* @license http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL
|
|
|
9 |
* @license GPL v3 <http://www.gnu.org/licenses/gpl.txt>
|
|
|
10 |
*/
|
|
|
11 |
|
1652 |
raphael |
12 |
// Include the main TCPDF library (search for installation path).
|
|
|
13 |
date_default_timezone_set("Europe/Paris");
|
|
|
14 |
require_once('tcpdf_config.php');
|
|
|
15 |
require_once('tcpdf/tcpdf.php');
|
|
|
16 |
|
|
|
17 |
Class GenerateurPDF {
|
|
|
18 |
|
|
|
19 |
public $pdf;
|
|
|
20 |
|
|
|
21 |
function GenerateurPDF($utilisateur = NULL) {
|
|
|
22 |
// create new PDF document
|
|
|
23 |
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
|
|
|
24 |
|
|
|
25 |
// set document information
|
|
|
26 |
$pdf->SetCreator(PDF_CREATOR);
|
|
|
27 |
$pdf->SetAuthor($utilisateur ? $utilisateur['prenom'] . ' ' . $utilisateur['nom'] : 'CEL - Tela Botanica');
|
|
|
28 |
$pdf->SetTitle('Observations en étiquettes');
|
|
|
29 |
$pdf->SetSubject('Étiquettes des observations');
|
|
|
30 |
$pdf->SetKeywords('botaniques, observations, étiquettes, cel, tela-botanica');
|
|
|
31 |
|
|
|
32 |
// set default header data
|
|
|
33 |
// $pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' 005', PDF_HEADER_STRING);
|
|
|
34 |
|
|
|
35 |
// set header and footer fonts
|
|
|
36 |
// $pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
|
|
|
37 |
// $pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
|
|
|
38 |
|
|
|
39 |
// set default monospaced font
|
|
|
40 |
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
|
|
|
41 |
|
|
|
42 |
// set margins
|
|
|
43 |
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
|
|
|
44 |
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
|
|
|
45 |
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
|
|
|
46 |
|
|
|
47 |
// set auto page breaks
|
|
|
48 |
// $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
|
|
|
49 |
$pdf->SetAutoPageBreak(FALSE, PDF_MARGIN_BOTTOM);
|
|
|
50 |
|
1655 |
raphael |
51 |
$pdf->SetFont('times', '', 11);
|
1652 |
raphael |
52 |
$pdf->setCellPaddings(1, 1, 1, 1);
|
|
|
53 |
$pdf->setCellMargins(1, 1, 1, 1);
|
|
|
54 |
|
1655 |
raphael |
55 |
$pdf->AddPage();
|
|
|
56 |
$pdf->setEqualColumns(2);
|
|
|
57 |
|
1652 |
raphael |
58 |
$this->pdf = $pdf;
|
|
|
59 |
}
|
|
|
60 |
|
|
|
61 |
|
|
|
62 |
|
|
|
63 |
function export($obs) {
|
|
|
64 |
$pdf = &$this->pdf;
|
|
|
65 |
|
|
|
66 |
$i = 0;
|
|
|
67 |
while($i < count($obs)) {
|
|
|
68 |
$pdf->selectColumn(0);
|
|
|
69 |
// Multicell test
|
1655 |
raphael |
70 |
$this->doHTMLcell($obs[$i++]); if(!isset($obs[$i])) break;
|
1652 |
raphael |
71 |
$pdf->Ln();
|
1655 |
raphael |
72 |
$this->doHTMLcell($obs[$i++]); if(!isset($obs[$i])) break;
|
1652 |
raphael |
73 |
$pdf->Ln();
|
1655 |
raphael |
74 |
$this->doHTMLcell($obs[$i++]); if(!isset($obs[$i])) break;
|
1652 |
raphael |
75 |
/*$pdf->MultiCell(0, 25, self::doTemplate($obs), 1, 'L', 1, 1, '', '', true);
|
|
|
76 |
$pdf->MultiCell(0, 25, self::doTemplate($obs), 1, 'L', 1, 1, '', '', true);*/
|
|
|
77 |
|
|
|
78 |
$pdf->selectColumn(1);
|
1655 |
raphael |
79 |
$this->doHTMLcell($obs[$i++]); if(!isset($obs[$i])) break;
|
1652 |
raphael |
80 |
$pdf->Ln();
|
1655 |
raphael |
81 |
$this->doHTMLcell($obs[$i++]); if(!isset($obs[$i])) break;
|
1652 |
raphael |
82 |
$pdf->Ln();
|
1655 |
raphael |
83 |
$this->doHTMLcell($obs[$i++]); if(!isset($obs[$i])) break;
|
1652 |
raphael |
84 |
/*$pdf->MultiCell(0, 25, self::doTemplate($obs), 1, 'L', 0, 1, '', '', true);
|
|
|
85 |
$pdf->MultiCell(0, 25, self::doTemplate($obs), 1, 'L', 0, 1, '', '', true);
|
|
|
86 |
$pdf->MultiCell(0, 25, self::doTemplate($obs), 1, 'L', 0, 1, '', '', true);*/
|
|
|
87 |
|
|
|
88 |
if(isset($obs[$i])) $pdf->AddPage();
|
|
|
89 |
}
|
|
|
90 |
}
|
|
|
91 |
|
1655 |
raphael |
92 |
function getlinenb4($txt) {
|
|
|
93 |
// store current object
|
|
|
94 |
$this->pdf->startTransaction();
|
|
|
95 |
// store starting values
|
|
|
96 |
$start_y = $this->pdf->GetY();
|
|
|
97 |
$start_page = $this->pdf->getPage();
|
|
|
98 |
|
|
|
99 |
$this->pdf->MultiCell($this->column_width, $h=0, $txt, $border=0, $align='L', $fill=false, $ln=1, $x='', $y='', $reseth=true, $stretch=0, $ishtml=false, $autopadding=true, $maxh=0);
|
|
|
100 |
$end_y = $this->pdf->GetY();
|
|
|
101 |
$end_page = $this->pdf->getPage();
|
|
|
102 |
// calculate height
|
|
|
103 |
$height = 0;
|
|
|
104 |
if ($end_page == $start_page) {
|
|
|
105 |
$height = $end_y - $start_y;
|
|
|
106 |
} else {
|
|
|
107 |
for ($page=$start_page; $page <= $end_page; ++$page) {
|
|
|
108 |
$this->setPage($page);
|
|
|
109 |
if ($page == $start_page) {
|
|
|
110 |
// first page
|
|
|
111 |
$height = $this->pdf->h - $start_y - $this->pdf->bMargin;
|
|
|
112 |
} elseif ($page == $end_page) {
|
|
|
113 |
// last page
|
|
|
114 |
$height = $end_y - $this->pdf->tMargin;
|
|
|
115 |
} else {
|
|
|
116 |
$height = $this->pdf->h - $this->pdf->tMargin - $this->bMargin;
|
|
|
117 |
}
|
|
|
118 |
}
|
|
|
119 |
}
|
|
|
120 |
// restore previous object
|
|
|
121 |
$this->pdf = $this->pdf->rollbackTransaction();
|
|
|
122 |
return $height;
|
|
|
123 |
}
|
|
|
124 |
|
|
|
125 |
function getlinenb3($txt) {
|
|
|
126 |
return $this->pdf->getStringHeight($this->column_width, $txt);
|
|
|
127 |
}
|
|
|
128 |
|
|
|
129 |
function getlinenb2($txt) {
|
|
|
130 |
//var_dump($line, $this->pdf->GetStringWidth($line));
|
|
|
131 |
return ceil($this->pdf->GetStringWidth($txt) / $this->column_width);
|
|
|
132 |
}
|
|
|
133 |
|
|
|
134 |
function getlinenb($txt) {
|
|
|
135 |
return $this->pdf->getStringHeight('', $txt) / ($this->pdf->getFontSize() * $this->pdf->getCellHeightRatio());
|
|
|
136 |
}
|
|
|
137 |
|
|
|
138 |
// singe la propriété CSS3 "text-overflow" : "ellipsis"
|
|
|
139 |
function elude($txt, $limite_lignes = 3) {
|
|
|
140 |
// echo strlen($txt) . ' '. $this->getlinenb($txt) . ' ' . $limite_lignes . "\n";
|
|
|
141 |
|
1661 |
aurelien |
142 |
$cell_paddings = $this->pdf->getCellPaddings();
|
|
|
143 |
$marge = $cell_paddings['T'] + $cell_paddings['B'];
|
1655 |
raphael |
144 |
$line_height = $this->pdf->getStringHeight($this->column_width, "a") - $marge;
|
|
|
145 |
if($limite_lignes > 1) {
|
|
|
146 |
$lim = $line_height * $limite_lignes + $marge; // $line_height + ($line_height - $marge) * ($limite_lignes - 1);
|
|
|
147 |
} else {
|
|
|
148 |
$lim = $line_height + $marge;
|
|
|
149 |
}
|
|
|
150 |
|
|
|
151 |
while(strlen($txt) > 4 && ($nb = $this->getlinenb3(strip_tags($txt))) > $lim) {
|
|
|
152 |
//echo "$nb / $line_height: $txt\n";
|
|
|
153 |
// TODO: mb_internal_encoding()
|
|
|
154 |
$txt = mb_substr($txt, 0, -4, 'UTF-8') . '…';
|
|
|
155 |
}
|
|
|
156 |
//echo "$txt: $nb / $limite_lignes \n";
|
|
|
157 |
return $txt;
|
|
|
158 |
}
|
|
|
159 |
|
|
|
160 |
|
|
|
161 |
// TODO: affichage pays dans "localité"
|
1652 |
raphael |
162 |
// ORDER BY id_observation
|
|
|
163 |
// italique pour nom d'espèce, mais pas auteur
|
1661 |
aurelien |
164 |
function doHTMLcell(&$obs) {
|
1655 |
raphael |
165 |
$this->pdf->setCellMargins(0,0,0,0);
|
|
|
166 |
$width = $this->column_width = 98;
|
|
|
167 |
|
|
|
168 |
//echo "cell_padding['T']: " . $this->pdf->getCellPaddings()['T'] . ", cell_padding['B']: " . $this->pdf->getCellPaddings()['B'] . "\n";
|
|
|
169 |
|
|
|
170 |
$lh = $this->pdf->getFontSize() * $this->pdf->getCellHeightRatio();
|
|
|
171 |
//$lh = $this->pdf->GetLineWidth();
|
|
|
172 |
|
|
|
173 |
/*
|
|
|
174 |
var_dump($this->pdf->GetLineWidth(),
|
|
|
175 |
$this->pdf->GetCharWidth("a"),
|
|
|
176 |
$this->pdf->getStringHeight(60, "Ê"),
|
|
|
177 |
$this->pdf->getHTMLFontUnits("plop"),
|
|
|
178 |
$this->pdf->GetStringWidth("aa"),
|
|
|
179 |
$lh,
|
|
|
180 |
|
|
|
181 |
5,
|
|
|
182 |
$this->getlinenb4("Observation : Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Lorem ipsum..."),
|
|
|
183 |
$this->elude("Observation : Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Lorem ipsum...", 5),
|
|
|
184 |
|
|
|
185 |
4,
|
|
|
186 |
$this->getlinenb4("Observation : Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor"),
|
|
|
187 |
$this->elude("Observation : Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Lorem ipsum...", 4),
|
|
|
188 |
|
|
|
189 |
3,
|
|
|
190 |
$this->getlinenb4("Observation : Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Lorem ipsum dolor sit amet"),
|
|
|
191 |
$this->elude("Observation : Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Lorem ipsum...", 3),
|
|
|
192 |
|
|
|
193 |
2,
|
|
|
194 |
$this->getlinenb4("Observation : Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore"),
|
|
|
195 |
$this->elude("Observation : Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Lorem ipsum...", 2),
|
|
|
196 |
|
|
|
197 |
1,
|
|
|
198 |
$this->getlinenb4("Observation : Lorem ipsum dolor sit amet, consectetur"),
|
|
|
199 |
$this->elude("Observation : Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Lorem ipsum...", 1)
|
|
|
200 |
);
|
|
|
201 |
die;
|
|
|
202 |
*/
|
|
|
203 |
|
|
|
204 |
|
|
|
205 |
/* $str = '<strong>Observation</strong> : ' . $obs['commentaire'];
|
|
|
206 |
echo $this->getlinenb(strip_tags($str)) . "\n";
|
|
|
207 |
echo $this->getlinenb2(strip_tags($str)) . "\n";
|
|
|
208 |
echo $this->pdf->getStringHeight($width, strip_tags($str)) . "\n";
|
|
|
209 |
echo $this->pdf->getStringHeight($width, "a") . "\n";
|
|
|
210 |
echo ( $this->pdf->getStringHeight($width, strip_tags($str)) / $this->pdf->getStringHeight($width, "a")) . "\n";
|
|
|
211 |
|
|
|
212 |
die;*/
|
|
|
213 |
|
|
|
214 |
// 3ème paramètre = '' equivalent à $this->pdf->getX()
|
|
|
215 |
// 4ème paramètre = '' equivalent à $this->pdf->getY()
|
1664 |
raphael |
216 |
|
|
|
217 |
// référentiel
|
|
|
218 |
$this->pdf->writeHTMLCell($w = $width, '', '', '',
|
|
|
219 |
$html = '<strong>Référentiel</strong> : ' . $obs['nom_referentiel'],
|
|
|
220 |
$border = 'LTR', $ln = 1, $fill = false, $reset = true, $align = 'L', $autopadding = true);
|
|
|
221 |
|
1655 |
raphael |
222 |
// famille
|
1664 |
raphael |
223 |
$this->pdf->writeHTMLCell($w = $width, '', '', '',
|
1655 |
raphael |
224 |
$html = '<strong>Famille</strong> : ' . $obs['famille'],
|
1664 |
raphael |
225 |
$border = 'LR', $ln = 1, $fill = false, $reset = true, $align = 'L', $autopadding = true);
|
1655 |
raphael |
226 |
|
|
|
227 |
|
1664 |
raphael |
228 |
// taxon
|
1676 |
raphael |
229 |
$nom = '<em>' . $obs['nom_ret'] . '</em>';
|
1664 |
raphael |
230 |
if($obs['certitude'] && stripos($obs['certitude'], 'certain') === false) {
|
|
|
231 |
$nom .= ' ' . $obs['certitude'];
|
|
|
232 |
}
|
|
|
233 |
$this->pdf->writeHTMLCell($w = $width, $lh * 3.5, '', '',
|
|
|
234 |
//$html = '<strong>Espèce</strong> : ' . self::elude('Espèce : ', $obs['nom_ret'], 2),
|
1676 |
raphael |
235 |
//$html = $this->elude('<strong>Taxon</strong> : ' . $nom, 3),
|
|
|
236 |
$html = '<strong>Taxon</strong> : ' . $nom, // on ne strip pas le nom de taxon, pas plus de 3 lignes
|
1664 |
raphael |
237 |
$border = 'LR', $ln = 1, $fill = false, $reset = true, $align = 'L', $autopadding = true);
|
|
|
238 |
|
|
|
239 |
// collecteur
|
|
|
240 |
// TODO: pseudo
|
|
|
241 |
$limite_nom = 26;
|
|
|
242 |
$prenom = $obs['prenom_utilisateur'];
|
|
|
243 |
if(mb_strlen($prenom . ' ' . $obs['nom_utilisateur'], 'UTF-8') > $limite_nom) {
|
|
|
244 |
$prenom = mb_substr($prenom, 0, 26 - mb_strlen($obs['nom_utilisateur'], 'UTF-8') - 1 /* espace */ - 1 /* … */, 'UTF-8') . '…';
|
|
|
245 |
//var_dump($prenom);die;
|
|
|
246 |
}
|
|
|
247 |
$this->pdf->writeHTMLCell($w = $width - 25, '', '', '',
|
|
|
248 |
$html = '<strong>Collecteur</strong> : ' . $prenom . ' ' . $obs['nom_utilisateur'],
|
|
|
249 |
$border = 'L', $ln = 0, $fill = false, $reset = true, $align = 'L', $autopadding = true);
|
|
|
250 |
|
1655 |
raphael |
251 |
// N°: TODO: writeHTMLCell() semble bugger
|
1664 |
raphael |
252 |
$this->pdf->Cell($w = 25, '',
|
1655 |
raphael |
253 |
$txt = 'N° : ' . $obs['id_observation'], //. sprintf("%04d", $obs['ordre'])
|
1664 |
raphael |
254 |
$border = 'R', $ln = 1, $align = 'R', $fill = false, $link = false, $stretch = 1, $ignore_min_height = false, $calign = 'T', $valign = 'M');
|
|
|
255 |
/*$this->pdf->writeHTMLCell($w = 30, '', '', '',
|
1655 |
raphael |
256 |
$html = '<strong>N°</strong> : ' . $obs['id_observation'], //. sprintf("%04d", $obs['ordre']),
|
1664 |
raphael |
257 |
$border = 'R', $ln = 1, $fill = true, $reset = true, $align = 'L', $autopadding = true);*/
|
1655 |
raphael |
258 |
|
1664 |
raphael |
259 |
// localité
|
|
|
260 |
// TODO: département
|
|
|
261 |
// TEST: Corse (2A, 2B)
|
|
|
262 |
$info_dep = "<strong>Localité</strong> : %s";
|
|
|
263 |
$donnees_dep = array($obs['zone_geo']);
|
|
|
264 |
if($obs['ce_zone_geo']) {
|
|
|
265 |
$info_dep .= " (%s)";
|
|
|
266 |
if(strpos($obs['ce_zone_geo'], 'INSEE') !== false) $donnees_dep[] = preg_replace('/^[^\d]*(\d\d).*/', '\1', $obs['ce_zone_geo']);
|
|
|
267 |
else $donnees_dep[] = $obs['ce_zone_geo'];
|
|
|
268 |
}
|
1655 |
raphael |
269 |
|
1664 |
raphael |
270 |
$info_loc = "%s, %s";
|
|
|
271 |
$donnees_loc = array($obs['lieudit'], $obs['station']);
|
|
|
272 |
if($obs['milieu']) {
|
|
|
273 |
$info_loc .= " [%s]";
|
|
|
274 |
$donnees_loc[] = $obs['milieu'];
|
|
|
275 |
}
|
1655 |
raphael |
276 |
$this->pdf->writeHTMLCell($w = $width, $lh * 3.5, '', '',
|
|
|
277 |
//$html = "<strong>Localité</strong> : " .
|
|
|
278 |
//self::elude('Localité : ', sprintf("%s (%s)\n%s, %s [%s]", $obs['zone_geo'], $obs['ce_zone_geo'], $obs['lieudit'], $obs['station'], $obs['milieu'] ), 3),
|
|
|
279 |
// $html = self::elude(sprintf("<strong>Localité</strong> : %s (%s)\n%s, %s [%s]", $obs['zone_geo'], $obs['ce_zone_geo'], $obs['lieudit'], $obs['station'], $obs['milieu']), 3),
|
1664 |
raphael |
280 |
$html = $this->elude(vsprintf($info_dep, $donnees_dep), 2) . "\n" .
|
|
|
281 |
$this->elude(vsprintf($info_loc, $donnees_loc), 2),
|
|
|
282 |
$border = 'LR', $ln = 1, $fill = false, $reset = true, $align = 'L', $autopadding = true);
|
1655 |
raphael |
283 |
|
1664 |
raphael |
284 |
// lon/lat/alt
|
|
|
285 |
$info_geo = '';
|
|
|
286 |
$donnees = array();
|
|
|
287 |
if($obs['latitude'] && $obs['longitude']) {
|
|
|
288 |
$info_geo .= "%.5f N / %.5f E";
|
|
|
289 |
array_push($donnees, $obs['latitude'], $obs['longitude']);
|
|
|
290 |
}
|
|
|
291 |
if($obs['altitude']) {
|
|
|
292 |
$info_geo .= ", %dm";
|
|
|
293 |
array_push($donnees, $obs['altitude']);
|
|
|
294 |
}
|
1655 |
raphael |
295 |
$this->pdf->writeHTMLCell($w = $width, '', '', '',
|
1664 |
raphael |
296 |
$html = vsprintf("<strong>Lat. / Lon. , Alt.</strong> : " . $info_geo, $donnees),
|
|
|
297 |
$border = 'LR', $ln = 1, $fill = false, $reset = true, $align = 'L', $autopadding = true);
|
1655 |
raphael |
298 |
|
|
|
299 |
// commentaire
|
|
|
300 |
$this->pdf->writeHTMLCell($w = $width, $lh * 4.5, '', '',
|
|
|
301 |
//$html = '<strong>Observation</strong> : ' . self::elude('Observation : ', $obs['commentaire']),
|
1676 |
raphael |
302 |
$html = self::elude('<strong>Observations</strong> : ' . $obs['commentaire'], 4),
|
1664 |
raphael |
303 |
$border = 'LR', $ln = 1, $fill = false, $reset = true, $align = 'L', $autopadding = true);
|
1655 |
raphael |
304 |
|
|
|
305 |
// date
|
|
|
306 |
$this->pdf->writeHTMLCell($w = $width, '', '', '',
|
1664 |
raphael |
307 |
$html = '<strong>Date de récolte</strong> : ' . strftime("%d/%m/%Y", strtotime($obs['date_observation'])),
|
1655 |
raphael |
308 |
$border = 'LBR', $ln = 1, $fill = false, $reset = true, $align = 'R', $autopadding = true);
|
|
|
309 |
|
|
|
310 |
}
|
|
|
311 |
|
1652 |
raphael |
312 |
function docell($obs) {
|
|
|
313 |
$this->pdf->setCellMargins(0,0,0,0);
|
|
|
314 |
|
|
|
315 |
$this->pdf->Cell($w = 60, '',
|
|
|
316 |
$txt = 'Famille : ' . $obs['famille'],
|
1655 |
raphael |
317 |
$border = 'LT', $ln = 0, $align = 'L', $fill = false, $link = false, $stretch = 1, $ignore_min_height = false, $calign = 'T', $valign = 'M');
|
1652 |
raphael |
318 |
|
|
|
319 |
$this->pdf->Cell($w = 20, '',
|
|
|
320 |
$txt = 'N° : ' . $obs['id_observation'] /*. sprintf("%04d", $obs['ordre']) */,
|
1655 |
raphael |
321 |
$border = 'TR', $ln = 1, $align = 'L', $fill = false, $link = false, $stretch = 1, $ignore_min_height = false, $calign = 'T', $valign = 'M');
|
1652 |
raphael |
322 |
|
|
|
323 |
$this->pdf->Cell($w = 80, '',
|
|
|
324 |
$txt = 'Espèce : ' . $obs['nom_ret'],
|
1655 |
raphael |
325 |
$border = 'RL', $ln = 1, $align = 'L', $fill = false, $link = false, $stretch = 1, $ignore_min_height = false, $calign = 'T', $valign = 'M');
|
1652 |
raphael |
326 |
|
|
|
327 |
$this->pdf->Cell($w = 80, '',
|
|
|
328 |
$txt = 'Collecteur : ' . $obs['prenom_utilisateur'] . ' ' . $obs['nom_utilisateur'],
|
1655 |
raphael |
329 |
$border = 'RL', $ln = 1, $align = 'L', $fill = false, $link = false, $stretch = 1, $ignore_min_height = false, $calign = 'T', $valign = 'M');
|
1652 |
raphael |
330 |
|
|
|
331 |
$this->pdf->MultiCell(80, 20,
|
1655 |
raphael |
332 |
$txt = sprintf("Localité : %s (%s)\n%s, %s", $obs['zone_geo'], $obs['ce_zone_geo'], $obs['lieudit'], $obs['station']),
|
|
|
333 |
$border = 'RL', 'L', 0, 1, '', '', true);
|
1652 |
raphael |
334 |
|
|
|
335 |
$this->pdf->Cell($w = 80, '',
|
|
|
336 |
$txt = sprintf("Latitude, Longitude : %s / %s", $obs['latitude'], $obs['longitude']),
|
1655 |
raphael |
337 |
$border = 'RL', $ln = 1, $align = 'L', $fill = false, $link = false, $stretch = 1, $ignore_min_height = false, $calign = 'T', $valign = 'M');
|
1652 |
raphael |
338 |
|
|
|
339 |
$this->pdf->MultiCell(80, 20,
|
1655 |
raphael |
340 |
$txt = 'Observation : ' . self::elude('Observation : ', $obs['commentaire']),
|
|
|
341 |
$border = 'RL', 'L', 0, 1, '', '', true);
|
1652 |
raphael |
342 |
|
|
|
343 |
$this->pdf->Cell($w = 80, '',
|
|
|
344 |
$txt = 'Date : ' . strftime("%d/%m/%Y", strtotime($obs['date_observation'])),
|
1655 |
raphael |
345 |
$border = 'LBR', $ln = 1, $align = 'R', $fill = false, $link = false, $stretch = 1, $ignore_min_height = false, $calign = 'T', $valign = 'M');
|
1652 |
raphael |
346 |
}
|
|
|
347 |
|
|
|
348 |
|
1655 |
raphael |
349 |
// singe la propriété CSS3 "text-overflow" : "ellipsis"
|
|
|
350 |
function elude_bis($intitule, $commentaire, $lignes = 3) {
|
1652 |
raphael |
351 |
// TODO: GetLineWidth, GetCharWidth()
|
1655 |
raphael |
352 |
$limite = $lignes /* lignes */ * 43 /* caractères */ - strlen($intitule);
|
1664 |
raphael |
353 |
if(mb_strlen($commentaire, 'UTF-8') < $limite) return $commentaire;
|
1655 |
raphael |
354 |
return mb_substr($commentaire, 0, $limite - 2) . '…';
|
1652 |
raphael |
355 |
}
|
|
|
356 |
|
|
|
357 |
|
|
|
358 |
function export1($observations) {
|
|
|
359 |
$pdf = &$this->pdf;
|
|
|
360 |
// MultiCell($w, $h, $txt, $border=0, $align='J', $fill=0, $ln=1, $x='', $y='', $reseth=true, $stretch=0, $ishtml=false, $autopadding=true, $maxh=0)
|
|
|
361 |
|
|
|
362 |
$pdf->setEqualColumns(2);
|
|
|
363 |
|
|
|
364 |
$i = 0;
|
|
|
365 |
while($i < count($observations)) {
|
|
|
366 |
$obs = $observations[$i];
|
|
|
367 |
|
|
|
368 |
$pdf->selectColumn(0);
|
|
|
369 |
// Multicell test
|
|
|
370 |
$pdf->MultiCell(0, 25, self::doTemplate($obs), 1, 'L', 1, 1, '', '', true);
|
|
|
371 |
$pdf->MultiCell(0, 25, self::doTemplate($obs), 1, 'L', 1, 1, '', '', true);
|
|
|
372 |
$pdf->MultiCell(0, 25, self::doTemplate($obs), 1, 'L', 1, 1, '', '', true);
|
|
|
373 |
$pdf->Ln();
|
|
|
374 |
|
|
|
375 |
$pdf->selectColumn(1);
|
|
|
376 |
$pdf->MultiCell(0, 25, self::doTemplate($obs), 1, 'L', 0, 1, '', '', true);
|
|
|
377 |
$pdf->MultiCell(0, 25, self::doTemplate($obs), 1, 'L', 0, 1, '', '', true);
|
|
|
378 |
$pdf->MultiCell(0, 25, self::doTemplate($obs), 1, 'L', 0, 1, '', '', true);
|
|
|
379 |
|
|
|
380 |
$i += 6;
|
|
|
381 |
if(isset($observations[$i])) $pdf->AddPage();
|
|
|
382 |
}
|
|
|
383 |
}
|
|
|
384 |
|
|
|
385 |
static function doTemplate($obs) {
|
|
|
386 |
$pattern =
|
|
|
387 |
<<<EOF
|
|
|
388 |
Famille: %s (%d)
|
|
|
389 |
Espèce: %s
|
|
|
390 |
Collecteur: %s
|
|
|
391 |
Localité: %s
|
|
|
392 |
Observation: %s Date: %s
|
|
|
393 |
EOF;
|
|
|
394 |
return sprintf($pattern,
|
|
|
395 |
|
|
|
396 |
$obs['famille'],
|
|
|
397 |
$obs['ordre'],
|
|
|
398 |
$obs['nom_ret'],
|
|
|
399 |
$obs['prenom_utilisateur'] . ' ' . $obs['nom_utilisateur'],
|
|
|
400 |
$obs['zone_geo'],
|
|
|
401 |
$obs['commentaire'],
|
|
|
402 |
strftime("%Y-%m-%d", strtotime($obs['date_observation']))
|
|
|
403 |
);
|
|
|
404 |
|
|
|
405 |
}
|
|
|
406 |
|
|
|
407 |
|
|
|
408 |
|
|
|
409 |
function export2($observations) {
|
|
|
410 |
$pdf = &$this->pdf;
|
|
|
411 |
|
|
|
412 |
$pdf->setEqualColumns(2);
|
|
|
413 |
|
|
|
414 |
$i = 0;
|
|
|
415 |
$y = $pdf->getY();
|
|
|
416 |
$x = $pdf->getX();
|
|
|
417 |
while($i < count($observations)) {
|
|
|
418 |
$obs = $observations[$i++];
|
|
|
419 |
|
|
|
420 |
$pdf->selectColumn(0);
|
|
|
421 |
// Multicell test
|
|
|
422 |
$pdf->writeHTMLCell(0, 25, $x, $y + 25 * 0, self::doHTMLTemplate($obs), 1, 0, 0, true);
|
|
|
423 |
$pdf->writeHTMLCell(0, 25, $x, $y + 25 * 1, self::doHTMLTemplate($obs), 1, 0, 0, true);
|
|
|
424 |
$pdf->writeHTMLCell(0, 25, $x, $y + 25 * 2, self::doHTMLTemplate($obs), 1, 0, 0, true);
|
|
|
425 |
//$pdf->Ln();
|
|
|
426 |
|
|
|
427 |
$pdf->selectColumn(1);
|
|
|
428 |
$pdf->writeHTMLCell(0, 25, $x, $y + 25 * 0, self::doHTMLTemplate($obs), 1, 1, 1, true);
|
|
|
429 |
$pdf->writeHTMLCell(0, 25, $x, $y + 25 * 1, self::doHTMLTemplate($obs), 1, 1, 1, true);
|
|
|
430 |
$pdf->writeHTMLCell(0, 25, $x, $y + 25 * 2, self::doHTMLTemplate($obs), 1, 1, 1, true);
|
|
|
431 |
|
|
|
432 |
$i += 6;
|
|
|
433 |
if(isset($observations[$i])) $pdf->AddPage();
|
|
|
434 |
}
|
|
|
435 |
}
|
|
|
436 |
|
|
|
437 |
static function doHTMLTemplate($obs) {
|
|
|
438 |
$pattern =
|
|
|
439 |
<<<EOF
|
|
|
440 |
<p>Famille: %s <span style="text-align: right">(%d)</span><br/>
|
|
|
441 |
Espèce: %s<br/>
|
|
|
442 |
Collecteur: %s<br/>
|
|
|
443 |
Localité: %s<br/>
|
|
|
444 |
Observation: %s Date: %s</p>
|
|
|
445 |
EOF;
|
|
|
446 |
return sprintf($pattern,
|
|
|
447 |
|
|
|
448 |
$obs['famille'],
|
|
|
449 |
$obs['ordre'],
|
|
|
450 |
$obs['nom_ret'],
|
|
|
451 |
$obs['prenom_utilisateur'] . ' ' . $obs['nom_utilisateur'],
|
|
|
452 |
$obs['zone_geo'],
|
|
|
453 |
$obs['commentaire'],
|
|
|
454 |
strftime("%Y-%m-%d", strtotime($obs['date_observation']))
|
|
|
455 |
);
|
|
|
456 |
|
|
|
457 |
}
|
|
|
458 |
|
|
|
459 |
}
|