15c6599c00dd35c46aed9430462e0192f3d30052
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');
112 $this->Cell(0, 10, '(en date du '.strftime('%d %B %Y').')', 0, 0, 'R');
115 function ColSetup($col)
118 $x = 10 +
$this->col
* 100;
119 $this->SetLeftMargin($x);
120 $this->SetRightMargin(120 - $x);
122 $this->SetY($this->y0
);
127 $this->ColSetup(1 - $this->col
);
128 if ($this->col
== 0) { $this->AddPage(); }
131 function AcceptPageBreak()
133 $this->broken
= true
;
136 function Space($w=0.1, $h=0.5)
140 $this->SetLineWidth($w);
141 $this->Line($x, $y, $x+
90, $y);
145 function TableRow($l, $r, $font = 'Sans')
147 $this->SetFont('Vera Sans', 'B', 8);
150 $this->MultiCell(25, 4, $l, '', 1);
153 $this->SetFont('Vera '.$font, '', 8);
158 $this->MultiCell(65, 4, $r, '', 1);
160 $this->setY(max($y1, $this->getY())+
0.5);
169 } elseif ($a['secondaire']) {
176 $r = trim("$r\n".$a['adr1']);
177 $r = trim("$r\n".$a['adr2']);
178 $r = trim("$r\n".$a['adr3']);
179 $r = trim("$r\n".trim($a['postcode'].' '.$a['city']));
181 $this->TableRow($l, $r);
184 $this->TableRow('Téléphone', $a['tel'], 'Mono');
187 $this->TableRow('Fax', $a['fax'], 'Mono');
191 function AddressPro($a)
193 if ($a['entreprise']) {
194 $this->TableRow('Entreprise', $a['entreprise']);
197 if ($a['adr1'] ||
$a['adr2'] ||
$a['adr3'] ||
$a['postcode'] ||
$a['city']) {
199 $r = trim("$r\n".$a['adr1']);
200 $r = trim("$r\n".$a['adr2']);
201 $r = trim("$r\n".$a['adr3']);
202 $r = trim("$r\n".trim($a['postcode'].' '.$a['city']));
203 $this->TableRow('adresse pro', $r);
207 $this->TableRow('Téléphone', $a['tel'], 'Mono');
210 $this->TableRow('Fax', $a['fax'], 'Mono');
219 function wordwrap($text, $maxwidth = 90) {
221 if ($text==='') { return 0; }
222 $space = $this->GetStringWidth(' ');
223 $lines = explode("\n", $text);
227 foreach ($lines as $line)
229 $words = preg_split('/ +/', $line);
232 foreach ($words as $word)
234 $wordwidth = $this->GetStringWidth($word);
235 if ($width +
$wordwidth <= $maxwidth)
237 $width +
= $wordwidth +
$space;
242 $width = $wordwidth +
$space;
243 $text = rtrim($text)."\n".$word.'
248 $text = rtrim($text)."\n";
251 $text = rtrim($text);
255 function AddContact($x, $wp = true
)
259 1- we store the current state.
260 2- at the end, we find out if we triggered the page break,
262 -> yes ? then we have to create a col, and add the contact again.
266 $this->SetFont('Vera Sans', '', 10);
267 $this->SetDrawColor(0);
268 $this->SetFillColor(245, 248, 252);
269 $this->SetLineWidth(0.4);
271 $nom = $x['prenom'].' '.($x['nom_usage'] ?
"{$x['nom_usage']} ({$x['nom']})" : $x['nom'])." ({$x['promo']})";
275 $res = $globals->xdb
->query("SELECT * FROM photo WHERE attachmime IN ('jpeg','png') AND uid={?}", $x['user_id']);
276 if ($i = $res->numRows()) {
278 $photo = $res->fetchOneAssoc();
279 $width = $photo['x'] * 20/$photo['y'];
280 $GLOBALS["p{$x['user_id']}"] = $photo['attach'];
284 $this->Cell(0, 20, '', '', 0, '', 1);
285 $this->Image("var://p{$x['user_id']}", $_x, $_y, $width, 20, $photo['attachmime']);
291 $this->Cell($width, 20, '', "T");
292 $h = 20 / $this->wordwrap($nom, 90-$width);
293 $this->MultiCell(0, $h, $nom, 'T', 'C');
299 $this->MultiCell(0, 6, $nom, "T", 'C', 1);
304 $this->TableRow('mobile', $x['mobile'], 'Mono');
307 foreach ($x['adr'] as $a) {
312 foreach ($x['adr_pro'] as $a) {
313 if ( ! ($a['entreprise'] ||
$a['tel'] ||
$a['fax']
314 ||
$a['adr1'] ||
$a['adr2'] ||
$a['adr3'] ||
$a['postcode'] ||
$a['city']) )
319 $this->AddressPro($a);
322 $this->Space(0.4, 5);
326 $old->AddContact($x, $wp);