* Contacts :
- Brand new PDF of the contact list (using FPDF). -MC
+ - Even include Photos in the PDF (kludgy !). -MC
* Validation :
- quite a lot of rewrite, simplifications. -MC
while (list($alias) = $citer->next()) {
$user = get_user_details($alias);
- $pdf->addContact($user);
+ $pdf->addContact($user, Env::has('photo'));
}
-
$pdf->Output();
?>
define ('FPDF_FONTPATH', dirname(__FILE__).'/fonts/');
require_once('/usr/share/fpdf/fpdf.php');
+require_once('xorg.varstream.inc.php');
class ContactsPDF extends FPDF
{
var $col = 0;
var $y0;
- var $title = "Mes contacts sur Polytechnique.org";
+ var $title = "Mes contacts sur Polytechnique.org";
var $broken = false;
+ var $error = false;
function ContactsPDF()
{
$this->AddPage();
}
+ function Output()
+ {
+ Header('Pragma: public');
+ parent::Output();
+ }
+
function Rotate($angle,$x=-1,$y=-1)
{
if($x==-1) {
}
}
- function AddContact($x)
+ function Error()
+ {
+ $this->error = true;
+ }
+
+ function AddContact($x, $wp = true)
{
global $globals;
/* infamous hack :
$this->SetLineWidth(0.4);
$nom = $x['prenom'].' '.($x['epouse'] ? "{$x['epouse']} - née {$x['nom']}" : $x['nom'])." ({$x['promo']})";
- $this->Cell(0, 6, $nom, "T", 1, 'C', 1, $globals->baseurl."/fiche.php?user={$x['forlife']}");
+ $ok = false;
+
+ if ($wp) {
+ $res = $globals->xdb->query("SELECT * FROM photo WHERE attachmime IN ('jpeg','png') AND uid={?}", $x['user_id']);
+ if ($i = $res->numRows()) {
+ $old2 = $this;
+ $photo = $res->fetchOneAssoc();
+ $width = $photo['x'] * 20/$photo['y'];
+ $GLOBALS["p{$x['user_id']}"] = $photo['attach'];
+
+ $_x = $this->getX();
+ $_y = $this->getY();
+ $this->Cell(0, 20, '', '', 0, 'C', 1);
+ $this->Image("var://p{$x['user_id']}", $_x, $_y, $width, 20, $photo['attachmime']);
+
+ if ($this->error) {
+ $this = $old2;
+ } else {
+ $this->setX($_x);
+ $this->Cell($width, 20, '', "T");
+ $h = ( $this->GetStringWidth($nom) + $width > 90 ) ? 10 : 20;
+ $this->MultiCell(0, $h, $nom, 'T', 'C');
+ $ok = true;
+ }
+ }
+ }
+ if (!$ok) {
+ $this->MultiCell(0, 6, $nom, "T", 'C', 1);
+ }
+
$this->Space();
if ($x['mobile']) {
$this->Space();
}
- $this->Ln();
- $this->Ln();
+ $this->Ln(10);
if ($this->broken) {
$old->NextCol();
- $old->AddContact($x);
+ $old->AddContact($x, $wp);
$this = $old;
}
}
--- /dev/null
+<?php
+/***************************************************************************
+ * Copyright (C) 2003-2004 Polytechnique.org *
+ * http://opensource.polytechnique.org/ *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the Free Software *
+ * Foundation, Inc., *
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
+ ***************************************************************************/
+
+// {{{ class VarStream
+
+class VarStream
+{
+ // {{{ properties
+
+ // Stream handler to read from global variables
+ var $varname;
+ var $position;
+
+ // }}}
+ // {{{ stream_open
+
+ function stream_open($path, $mode, $options, &$opened_path)
+ {
+ $url = parse_url($path);
+ $this->varname = $url['host'];
+ if(!isset($GLOBALS[$this->varname]))
+ {
+ trigger_error('Global variable '.$this->varname.' does not exist', E_USER_WARNING);
+ return false;
+ }
+ $this->position = 0;
+ return true;
+ }
+
+ // }}}
+ // {{{ stream_read
+
+ function stream_read($count)
+ {
+ $ret = substr($GLOBALS[$this->varname], $this->position, $count);
+ $this->position += strlen($ret);
+ return $ret;
+ }
+
+ // }}}
+ // {{{ stream_eof
+
+ function stream_eof()
+ {
+ return $this->position >= strlen($GLOBALS[$this->varname]);
+ }
+
+ // }}}
+}
+
+// }}}
+
+stream_wrapper_register('var','VarStream');
+
+// vim:set et sw=4 sts=4 sws=4:
+?>
{if $trombi || $citer->total()}
<p>
- Pour récupérer ta liste de contacts dans un PDF imprimable :<br />
- [<a href="mescontacts_pdf.php/mes_contacts.pdf?order=promo" class='popup'><strong>Triée par promo</strong></a>]
- [<a href="mescontacts_pdf.php/mes_contacts.pdf" class='popup'><strong>Triée par noms</strong></a>]
+Pour récupérer ta liste de contacts dans un PDF imprimable :<br />
+(attention, les photos font beaucoup grossir les fichiers !)
</p>
+<ul>
+ <li>avec les photos :
+ [<a href="mescontacts_pdf.php/mes_contacts.pdf?order=promo&photo" class='popup'><strong>tri par promo</strong></a>]
+ [<a href="mescontacts_pdf.php/mes_contacts.pdf?photo" class='popup'><strong>tri par noms</strong></a>]
+ </li>
+ <li>sans les photos :
+ [<a href="mescontacts_pdf.php/mes_contacts.pdf?order=promo" class='popup'><strong>tri par promo</strong></a>]
+ [<a href="mescontacts_pdf.php/mes_contacts.pdf" class='popup'><strong>tri par noms</strong></a>]
+ </li>
+</ul>
{if $trombi}