e47628e906d1933e00cc8328fa546764b1e82a37
2 /***************************************************************************
3 * Copyright (C) 2003-2004 Polytechnique.org *
4 * http://opensource.polytechnique.org/ *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the Free Software *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
22 define ('FPDF_FONTPATH', dirname(__FILE__
).'/fonts/');
23 require_once('/usr/share/fpdf/fpdf.php');
24 require_once('xorg.varstream.inc.php');
26 class ContactsPDF
extends FPDF
31 var $title = "Mes contacts sur Polytechnique.org";
35 function ContactsPDF()
38 $this->AddFont('Vera Sans', '', 'Vera.php');
39 $this->AddFont('Vera Sans', 'I', 'VeraIt.php');
40 $this->AddFont('Vera Sans', 'B', 'VeraBd.php');
42 $this->AddFont('Vera Mono', '', 'VeraMono.php');
44 $this->SetTitle($this->title
);
45 $this->SetCreator('Site Polytechnique.org');
51 Header('Pragma: public');
55 function Rotate($angle,$x=-1,$y=-1)
63 if($this->angle
!= 0) {
66 $this->angle
= $angle;
73 $cy = ($this->h
-$y)*$this->k
;
74 $this->_out(sprintf('q %.5f %.5f %.5f %.5f %.2f %.2f cm 1 0 0 1 %.2f %.2f cm',$c,$s,-$s,$c,$cx,$cy,-$cx,-$cy));
81 $this->SetFont('Vera Sans', 'B', 20);
82 $this->SetTextColor(230);
83 $this->Rotate(45,55,190);
84 $this->Text(55,190,"informations limitées à un usage");
85 $this->Text(40,210,"strictement personnel et non commercial");
88 $this->setLeftMargin(5);
89 $this->setRightMargin(5);
90 $this->SetFont('Vera Sans', 'B', 16);
92 $this->SetTextColor(51,102,153);
93 $this->SetDrawColor(102,153,204);
94 $this->SetLineWidth(0.2);
95 $this->SetFillColor(245, 248, 252);
96 $this->Cell(200, 10, $this->title
, 1, 1, 'C', 1);
97 $this->Image(dirname(__FILE__
).'/../htdocs/images/logo.png', 5, 5, 10, 10, 'png', 'https://www.polytechnique.org/');
100 $this->y0
= $this->GetY();
101 $this->ColSetup(false
);
106 $this->setLeftMargin(5);
107 $this->setRightMargin(5);
109 $this->SetFont('Vera Sans','I',8);
110 $this->SetTextColor(128);
111 $this->Cell(0, 10, 'Page '.$this->PageNo(), 0, 0, 'C');
114 function ColSetup($col)
117 $x = 10 +
$this->col
* 100;
118 $this->SetLeftMargin($x);
119 $this->SetRightMargin(120 - $x);
121 $this->SetY($this->y0
);
126 $this->ColSetup(1 - $this->col
);
127 if ($this->col
== 0) { $this->AddPage(); }
130 function AcceptPageBreak()
132 $this->broken
= true
;
135 function Space($w=0.1, $h=0.5)
139 $this->SetLineWidth($w);
140 $this->Line($x, $y, $x+
90, $y);
144 function TableRow($l, $r, $font = 'Sans')
146 $this->SetFont('Vera Sans', 'B', 8);
149 $this->MultiCell(25, 4, $l, '', 1);
152 $this->SetFont('Vera '.$font, '', 8);
157 $this->MultiCell(65, 4, $r, '', 1);
159 $this->setY(max($y1, $this->getY())+
0.5);
168 } elseif ($a['secondaire']) {
175 $r = trim("$r\n".$a['adr1']);
176 $r = trim("$r\n".$a['adr2']);
177 $r = trim("$r\n".$a['adr3']);
178 $r = trim("$r\n".trim($a['postcode'].' '.$a['city']));
180 $this->TableRow($l, $r);
183 $this->TableRow('Téléphone', $a['tel'], 'Mono');
186 $this->TableRow('Fax', $a['fax'], 'Mono');
190 function AddressPro($a)
192 if ($a['entreprise']) {
193 $this->TableRow('Entreprise', $a['entreprise']);
196 if ($a['adr1'] ||
$a['adr2'] ||
$a['adr3'] ||
$a['postcode'] ||
$a['city']) {
198 $r = trim("$r\n".$a['adr1']);
199 $r = trim("$r\n".$a['adr2']);
200 $r = trim("$r\n".$a['adr3']);
201 $r = trim("$r\n".trim($a['postcode'].' '.$a['city']));
202 $this->TableRow('adresse pro', $r);
206 $this->TableRow('Téléphone', $a['tel'], 'Mono');
209 $this->TableRow('Fax', $a['fax'], 'Mono');
218 function wordwrap($text, $maxwidth = 90) {
220 if ($text==='') { return 0; }
221 $space = $this->GetStringWidth(' ');
222 $lines = explode("\n", $text);
226 foreach ($lines as $line)
228 $words = preg_split('/ +/', $line);
231 foreach ($words as $word)
233 $wordwidth = $this->GetStringWidth($word);
234 if ($width +
$wordwidth <= $maxwidth)
236 $width +
= $wordwidth +
$space;
241 $width = $wordwidth +
$space;
242 $text = rtrim($text)."\n".$word.'
247 $text = rtrim($text)."\n";
250 $text = rtrim($text);
254 function AddContact($x, $wp = true
)
258 1- we store the current state.
259 2- at the end, we find out if we triggered the page break,
261 -> yes ? then we have to create a col, and add the contact again.
265 $this->SetFont('Vera Sans', '', 10);
266 $this->SetDrawColor(0);
267 $this->SetFillColor(245, 248, 252);
268 $this->SetLineWidth(0.4);
270 $nom = $x['prenom'].' '.($x['nom_usage'] ?
"{$x['nom_usage']} ({$x['nom']})" : $x['nom'])." ({$x['promo']})";
274 $res = $globals->xdb
->query("SELECT * FROM photo WHERE attachmime IN ('jpeg','png') AND uid={?}", $x['user_id']);
275 if ($i = $res->numRows()) {
277 $photo = $res->fetchOneAssoc();
278 $width = $photo['x'] * 20/$photo['y'];
279 $GLOBALS["p{$x['user_id']}"] = $photo['attach'];
283 $this->Cell(0, 20, '', '', 0, '', 1);
284 $this->Image("var://p{$x['user_id']}", $_x, $_y, $width, 20, $photo['attachmime']);
290 $this->Cell($width, 20, '', "T");
291 $h = 20 / $this->wordwrap($nom, 90-$width);
292 $this->MultiCell(0, $h, $nom, 'T', 'C');
298 $this->MultiCell(0, 6, $nom, "T", 'C', 1);
303 $this->TableRow('mobile', $x['mobile'], 'Mono');
306 foreach ($x['adr'] as $a) {
311 foreach ($x['adr_pro'] as $a) {
312 if ( ! ($a['entreprise'] ||
$a['tel'] ||
$a['fax']
313 ||
$a['adr1'] ||
$a['adr2'] ||
$a['adr3'] ||
$a['postcode'] ||
$a['city']) )
318 $this->AddressPro($a);
321 $this->Space(0.4, 5);
325 $old->AddContact($x, $wp);