Subversion Repositories eFlore/Applications.cel

Rev

Rev 1655 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1652 raphael 1
<?php
2
 
3
// Include the main TCPDF library (search for installation path).
4
date_default_timezone_set("Europe/Paris");
5
require_once('tcpdf_config.php');
6
require_once('tcpdf/tcpdf.php');
7
 
8
Class GenerateurPDF {
9
 
10
	public $pdf;
11
 
12
	function GenerateurPDF($utilisateur = NULL) {
13
		// create new PDF document
14
		$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
15
 
16
		// set document information
17
		$pdf->SetCreator(PDF_CREATOR);
18
		$pdf->SetAuthor($utilisateur ? $utilisateur['prenom'] . ' ' . $utilisateur['nom'] : 'CEL - Tela Botanica');
19
		$pdf->SetTitle('Observations en étiquettes');
20
		$pdf->SetSubject('Étiquettes des observations');
21
		$pdf->SetKeywords('botaniques, observations, étiquettes, cel, tela-botanica');
22
 
23
		// set default header data
24
		// $pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' 005', PDF_HEADER_STRING);
25
 
26
		// set header and footer fonts
27
		// $pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
28
		// $pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
29
 
30
		// set default monospaced font
31
		$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
32
 
33
		// set margins
34
		$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
35
		$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
36
		$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
37
 
38
		// set auto page breaks
39
		// $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
40
		$pdf->SetAutoPageBreak(FALSE, PDF_MARGIN_BOTTOM);
41
 
42
		$pdf->SetFont('times', '', 12);
43
		$pdf->setCellPaddings(1, 1, 1, 1);
44
		$pdf->setCellMargins(1, 1, 1, 1);
45
 
46
		$this->pdf = $pdf;
47
	}
48
 
49
 
50
 
51
	function export($obs) {
52
		$pdf = &$this->pdf;
53
		$pdf->AddPage();
54
		$pdf->setEqualColumns(2);
55
 
56
		$i = 0;
57
		while($i < count($obs)) {
58
			$pdf->selectColumn(0);
59
			// Multicell test
60
			$this->docell($obs[$i++]); if(!isset($obs[$i])) break;
61
			$pdf->Ln();
62
			$this->docell($obs[$i++]);  if(!isset($obs[$i])) break;
63
			$pdf->Ln();
64
			$this->docell($obs[$i++]); if(!isset($obs[$i])) break;
65
			/*$pdf->MultiCell(0, 25, self::doTemplate($obs), 1, 'L', 1, 1, '', '', true);
66
			  $pdf->MultiCell(0, 25, self::doTemplate($obs), 1, 'L', 1, 1, '', '', true);*/
67
 
68
			$pdf->selectColumn(1);
69
			$this->docell($obs[$i++]); if(!isset($obs[$i])) break;
70
			$pdf->Ln();
71
			$this->docell($obs[$i++]); if(!isset($obs[$i])) break;
72
			$pdf->Ln();
73
			$this->docell($obs[$i++]); if(!isset($obs[$i])) break;
74
			/*$pdf->MultiCell(0, 25, self::doTemplate($obs), 1, 'L', 0, 1, '', '', true);
75
			$pdf->MultiCell(0, 25, self::doTemplate($obs), 1, 'L', 0, 1, '', '', true);
76
			$pdf->MultiCell(0, 25, self::doTemplate($obs), 1, 'L', 0, 1, '', '', true);*/
77
 
78
			if(isset($obs[$i])) $pdf->AddPage();
79
		}
80
	}
81
 
82
	// TODO: test plus grand nom d'espèce
83
	// ORDER BY id_observation
84
	// intitulé en gras
85
	// italique pour nom d'espèce, mais pas auteur
86
	// supprimer les lignes
87
	function docell($obs) {
88
		$this->pdf->setCellMargins(0,0,0,0);
89
 
90
		$this->pdf->Cell($w = 60, '',
91
						 $txt = 'Famille : ' . $obs['famille'],
92
						 $border = 1,
93
						 $ln = 0,
94
						 $align = 'L',
95
						 $fill = false,
96
						 $link = false,
97
						 $stretch = 1,
98
						 $ignore_min_height = false,
99
						 $calign = 'T',
100
						 $valign = 'M');
101
 
102
		$this->pdf->Cell($w = 20, '',
103
						 $txt = 'N° : ' . $obs['id_observation'] /*. sprintf("%04d", $obs['ordre']) */,
104
						 $border = 1,
105
						 $ln = 1,
106
						 $align = 'L',
107
						 $fill = false,
108
						 $link = false,
109
						 $stretch = 1,
110
						 $ignore_min_height = false,
111
						 $calign = 'T',
112
						 $valign = 'M');
113
 
114
		$this->pdf->Cell($w = 80, '',
115
						 $txt = 'Espèce : ' . $obs['nom_ret'],
116
						 $border = 1,
117
						 $ln = 1,
118
						 $align = 'L',
119
						 $fill = false,
120
						 $link = false,
121
						 $stretch = 1,
122
						 $ignore_min_height = false,
123
						 $calign = 'T',
124
						 $valign = 'M');
125
 
126
		$this->pdf->Cell($w = 80, '',
127
						 $txt = 'Collecteur : ' . $obs['prenom_utilisateur'] . ' ' . $obs['nom_utilisateur'],
128
						 $border = 1,
129
						 $ln = 1,
130
						 $align = 'L',
131
						 $fill = false,
132
						 $link = false,
133
						 $stretch = 1,
134
						 $ignore_min_height = false,
135
						 $calign = 'T',
136
						 $valign = 'M');
137
 
138
		$this->pdf->MultiCell(80, 20,
139
							  $txt = sprintf("Localité : %s (%s)\n%s, %s",
140
											 $obs['zone_geo'],
141
											 $obs['ce_zone_geo'],
142
											 $obs['lieudit'],
143
											 $obs['station']),
144
							  1,
145
							  'L',
146
							  0,
147
							  1,
148
							  '',
149
							  '',
150
							  true);
151
 
152
		$this->pdf->Cell($w = 80, '',
153
						 $txt = sprintf("Latitude, Longitude : %s  /  %s", $obs['latitude'], $obs['longitude']),
154
						 $border = 1,
155
						 $ln = 1,
156
						 $align = 'L',
157
						 $fill = false,
158
						 $link = false,
159
						 $stretch = 1,
160
						 $ignore_min_height = false,
161
						 $calign = 'T',
162
						 $valign = 'M');
163
 
164
		$this->pdf->MultiCell(80, 20,
165
							  $txt = self::coupeCommentaire("Observation : ", $obs['commentaire']),
166
							  1,
167
							  'L',
168
							  0,
169
							  1,
170
							  '',
171
							  '',
172
							  true);
173
 
174
		$this->pdf->Cell($w = 80, '',
175
						 $txt = 'Date : ' . strftime("%d/%m/%Y", strtotime($obs['date_observation'])),
176
						 $border = 1,
177
						 $ln = 1,
178
						 $align = 'R',
179
						 $fill = false,
180
						 $link = false,
181
						 $stretch = 1,
182
						 $ignore_min_height = false,
183
						 $calign = 'T',
184
						 $valign = 'M');
185
	}
186
 
187
 
188
 
189
 
190
 
191
 
192
 
193
	function coupeCommentaire($intitule, $commentaire) {
194
		// TODO: GetLineWidth, GetCharWidth()
195
		$limite = 3 /* lignes */ * 43 /* caractères */ - strlen($intitule);
196
		if(mb_strlen($commentaire) < $limite) return 'Observation : ' . $commentaire;
197
		return 'Observation : ' . mb_substr($commentaire, 0, $limite - 3) . '...';
198
	}
199
 
200
 
201
	function export1($observations) {
202
		$pdf = &$this->pdf;
203
		// MultiCell($w, $h, $txt, $border=0, $align='J', $fill=0, $ln=1, $x='', $y='', $reseth=true, $stretch=0, $ishtml=false, $autopadding=true, $maxh=0)
204
 
205
		$pdf->setEqualColumns(2);
206
 
207
		$i = 0;
208
		while($i < count($observations)) {
209
			$obs = $observations[$i];
210
 
211
			$pdf->selectColumn(0);
212
			// Multicell test
213
			$pdf->MultiCell(0, 25, self::doTemplate($obs), 1, 'L', 1, 1, '', '', true);
214
			$pdf->MultiCell(0, 25, self::doTemplate($obs), 1, 'L', 1, 1, '', '', true);
215
			$pdf->MultiCell(0, 25, self::doTemplate($obs), 1, 'L', 1, 1, '', '', true);
216
			$pdf->Ln();
217
 
218
			$pdf->selectColumn(1);
219
			$pdf->MultiCell(0, 25, self::doTemplate($obs), 1, 'L', 0, 1, '', '', true);
220
			$pdf->MultiCell(0, 25, self::doTemplate($obs), 1, 'L', 0, 1, '', '', true);
221
			$pdf->MultiCell(0, 25, self::doTemplate($obs), 1, 'L', 0, 1, '', '', true);
222
 
223
			$i += 6;
224
			if(isset($observations[$i])) $pdf->AddPage();
225
		}
226
	}
227
 
228
	static function doTemplate($obs) {
229
		$pattern =
230
<<<EOF
231
Famille: %s (%d)
232
Espèce: %s
233
Collecteur: %s
234
Localité: %s
235
Observation: %s	 Date: %s
236
EOF;
237
		return sprintf($pattern,
238
 
239
					   $obs['famille'],
240
					   $obs['ordre'],
241
					   $obs['nom_ret'],
242
					   $obs['prenom_utilisateur'] . ' ' . $obs['nom_utilisateur'],
243
					   $obs['zone_geo'],
244
					   $obs['commentaire'],
245
					   strftime("%Y-%m-%d", strtotime($obs['date_observation']))
246
		);
247
 
248
	}
249
 
250
 
251
 
252
	function export2($observations) {
253
		$pdf = &$this->pdf;
254
 
255
		$pdf->setEqualColumns(2);
256
 
257
		$i = 0;
258
		$y = $pdf->getY();
259
		$x = $pdf->getX();
260
		while($i < count($observations)) {
261
			$obs = $observations[$i++];
262
 
263
			$pdf->selectColumn(0);
264
			// Multicell test
265
			$pdf->writeHTMLCell(0, 25, $x, $y + 25 * 0, self::doHTMLTemplate($obs), 1, 0, 0, true);
266
			$pdf->writeHTMLCell(0, 25, $x, $y + 25 * 1, self::doHTMLTemplate($obs), 1, 0, 0, true);
267
			$pdf->writeHTMLCell(0, 25, $x, $y + 25 * 2, self::doHTMLTemplate($obs), 1, 0, 0, true);
268
			//$pdf->Ln();
269
 
270
			$pdf->selectColumn(1);
271
			$pdf->writeHTMLCell(0, 25, $x, $y + 25 * 0, self::doHTMLTemplate($obs), 1, 1, 1, true);
272
			$pdf->writeHTMLCell(0, 25, $x, $y + 25 * 1, self::doHTMLTemplate($obs), 1, 1, 1, true);
273
			$pdf->writeHTMLCell(0, 25, $x, $y + 25 * 2, self::doHTMLTemplate($obs), 1, 1, 1, true);
274
 
275
			$i += 6;
276
			if(isset($observations[$i])) $pdf->AddPage();
277
		}
278
	}
279
 
280
	static function doHTMLTemplate($obs) {
281
		$pattern =
282
<<<EOF
283
<p>Famille: %s <span style="text-align: right">(%d)</span><br/>
284
Espèce: %s<br/>
285
Collecteur: %s<br/>
286
Localité: %s<br/>
287
Observation: %s	 Date: %s</p>
288
EOF;
289
		return sprintf($pattern,
290
 
291
					   $obs['famille'],
292
					   $obs['ordre'],
293
					   $obs['nom_ret'],
294
					   $obs['prenom_utilisateur'] . ' ' . $obs['nom_utilisateur'],
295
					   $obs['zone_geo'],
296
					   $obs['commentaire'],
297
					   strftime("%Y-%m-%d", strtotime($obs['date_observation']))
298
		);
299
 
300
	}
301
 
302
}