Subversion Repositories eFlore/Applications.cel

Rev

Rev 2459 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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