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