2 /***************************************************************************
3 * Copyright (C) 2003-2006 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 dirname(__FILE__
).'/../../classes/varstream.php';
26 class ContactsPDF
extends FPDF
31 var $title = "Mes contacts sur Polytechnique.org";
37 function ContactsPDF()
39 $this->report
= error_reporting(0);
41 error_reporting($this->report
);
43 $this->AddFont('Vera Sans', '', 'Vera.php');
44 $this->AddFont('Vera Sans', 'I', 'VeraIt.php');
45 $this->AddFont('Vera Sans', 'B', 'VeraBd.php');
47 $this->AddFont('Vera Mono', '', 'VeraMono.php');
49 $this->SetTitle($this->title
);
50 $this->SetCreator('Site Polytechnique.org');
54 function Output($name='mescontacts.pdf', $dest='I')
56 Header('Pragma: public');
58 parent
::Output($name, $dest);
59 error_reporting($this->report
);
62 function Rotate($angle, $x=-1, $y=-1)
70 if (!empty($this->angle
)) {
73 $this->angle
= $angle;
79 $cy = ($this->h
-$y)*$this->k
;
80 $this->_out(sprintf('q %.5f %.5f %.5f %.5f %.2f %.2f cm 1 0 0 1 %.2f %.2f cm',
81 $c, $s, -$s, $c, $cx, $cy, -$cx, -$cy));
88 $this->SetFont('Vera Sans', 'B', 20);
89 $this->SetTextColor(230);
90 $this->Rotate(45, 55, 190);
91 $this->Text(55, 190, "informations limitées à un usage");
92 $this->Text(40, 210, "strictement personnel et non commercial");
95 $this->setLeftMargin(5);
96 $this->setRightMargin(5);
97 $this->SetFont('Vera Sans', 'B', 16);
99 $this->SetTextColor(51, 102, 153);
100 $this->SetDrawColor(102, 153, 204);
101 $this->SetLineWidth(0.2);
102 $this->SetFillColor(245, 248, 252);
103 $this->Cell(200, 10, $this->title
, 1, 1, 'C', 1);
104 $this->Image(dirname(__FILE__
).'/../../htdocs/images/logo.png',
105 5, 5, 10, 10, 'png', 'https://www.polytechnique.org/');
108 $this->y0
= $this->GetY();
109 $this->ColSetup(false
);
114 $this->setLeftMargin(5);
115 $this->setRightMargin(5);
117 $this->SetFont('Vera Sans', 'I', 8);
118 $this->SetTextColor(128);
119 $this->Cell(0, 10, 'Page '.$this->PageNo(), 0, 0, 'C');
120 $this->Cell(0, 10, '(en date du '.strftime('%d %B %Y').')', 0, 0, 'R');
123 function ColSetup($col)
126 $x = 10 +
$this->col
* 100;
127 $this->SetLeftMargin($x);
128 $this->SetRightMargin(120 - $x);
130 $this->SetY($this->y0
);
135 $this->ColSetup(1 - $this->col
);
136 if ($this->col
== 0) {
141 function AcceptPageBreak()
143 $this->broken
= true
;
146 function Space($w=0.1, $h=0.5)
150 $this->SetLineWidth($w);
151 $this->Line($x, $y, $x+
90, $y);
155 function TableRow($l, $r, $font = 'Sans')
157 $this->SetFont('Vera Sans', 'B', 8);
160 $this->MultiCell(25, 4, $l, '', 1);
163 $this->SetFont('Vera '.$font, '', 8);
168 $this->MultiCell(65, 4, $r, '', 1);
170 $this->setY(max($y1, $this->getY())+
0.5);
179 } elseif ($a['secondaire']) {
186 $r = trim("$r\n".$a['adr1']);
187 $r = trim("$r\n".$a['adr2']);
188 $r = trim("$r\n".$a['adr3']);
189 $r = trim("$r\n".trim($a['postcode'].' '.$a['city']));
191 $this->TableRow($l, $r);
193 if (!empty($a['tels'])) {
194 foreach ($a['tels'] as $tel) {
195 if (!empty($tel['tel'])) {
196 $this->TableRow($tel['tel_type'], $tel['tel'], 'Mono');
202 function AddressPro($a)
204 if ($a['entreprise']) {
205 $this->TableRow('Entreprise', $a['entreprise']);
208 if ($a['adr1'] ||
$a['adr2'] ||
$a['adr3'] ||
$a['postcode'] ||
$a['city']) {
210 $r = trim("$r\n".$a['adr1']);
211 $r = trim("$r\n".$a['adr2']);
212 $r = trim("$r\n".$a['adr3']);
213 $r = trim("$r\n".trim($a['postcode'].' '.$a['city']));
214 $this->TableRow('adresse pro', $r);
218 $this->TableRow('Téléphone', $a['tel'], 'Mono');
221 $this->TableRow('Fax', $a['fax'], 'Mono');
230 function wordwrap($text, $maxwidth = 90) {
232 if ($text==='') { return 0; }
233 $space = $this->GetStringWidth(' ');
234 $lines = explode("\n", $text);
238 foreach ($lines as $line) {
239 $words = preg_split('/ +/', $line);
242 foreach ($words as $word) {
243 $wordwidth = $this->GetStringWidth($word);
244 if ($width +
$wordwidth <= $maxwidth) {
245 $width +
= $wordwidth +
$space;
248 $width = $wordwidth +
$space;
249 $text = rtrim($text)."\n".$word.' ';
253 $text = rtrim($text)."\n";
256 $text = rtrim($text);
260 static function AddContact($self, $x, $wp = true
)
263 1- we store the current state.
264 2- at the end, we find out if we triggered the page break,
266 -> yes ? then we have to create a col, and add the contact again.
270 $self->SetFont('Vera Sans', '', 10);
271 $self->SetDrawColor(0);
272 $self->SetFillColor(245, 248, 252);
273 $self->SetLineWidth(0.4);
275 $nom = $x['prenom'].' '
276 .($x['nom_usage'] ?
"{$x['nom_usage']} ({$x['nom']})" : $x['nom'])
281 $res = XDB
::query("SELECT * FROM photo WHERE attachmime IN ('jpeg', 'png') AND uid={?}",
283 if ($i = $res->numRows()) {
285 $photo = $res->fetchOneAssoc();
286 $width = $photo['x'] * 20/$photo['y'];
287 $GLOBALS["p{$x['user_id']}"] = $photo['attach'];
291 $self->Cell(0, 20, '', '', 0, '', 1);
293 $self->Image("var://p{$x['user_id']}", $_x, $_y, $width, 20, $photo['attachmime']);
294 error_reporting($self->report
);
300 $self->Cell($width, 20, '', "T");
301 $h = 20 / $self->wordwrap($nom, 90-$width);
302 $self->MultiCell(0, $h, $nom, 'T', 'C');
308 $self->MultiCell(0, 6, $nom, "T", 'C', 1);
313 $self->TableRow('mobile', $x['mobile'], 'Mono');
316 foreach ($x['adr'] as $a) {
321 if (!empty($x['adr_pro'])) {
322 foreach ($x['adr_pro'] as $a) {
323 if ( ! ($a['entreprise'] ||
$a['tel'] ||
$a['fax']
324 ||
$a['adr1'] ||
$a['adr2'] ||
$a['adr3'] ||
$a['postcode'] ||
$a['city']) )
329 $self->AddressPro($a);
333 $self->Space(0.4, 5);
337 $self = ContactsPDF
::AddContact($old, $x, $wp);