<?php
/***************************************************************************
- * Copyright (C) 2003-2008 Polytechnique.org *
+ * Copyright (C) 2003-2010 Polytechnique.org *
* http://opensource.polytechnique.org/ *
* *
* This program is free software; you can redistribute it and/or modify *
private $report = 0;
- function ContactsPDF()
+ public function __construct()
{
$this->report = error_reporting(0);
parent::FPDF();
$this->AddPage();
}
- function Output($name='mescontacts.pdf', $dest='I')
+ public function Output($name='mescontacts.pdf', $dest='I')
{
Header('Pragma: public');
error_reporting(0);
error_reporting($this->report);
}
- function Rotate($angle, $x=-1, $y=-1)
+ private function Rotate($angle, $x=-1, $y=-1)
{
if ($x==-1) {
$x = $this->x;
}
}
- function Header()
+ public function Header()
{
$this->SetFont('Vera Sans', 'B', 20);
$this->ColSetup(false);
}
- function Footer()
+ public function Footer()
{
$this->setLeftMargin(5);
$this->setRightMargin(5);
$this->Cell(0, 10, '(en date du '.strftime('%d %B %Y').')', 0, 0, 'R');
}
- function ColSetup($col)
+ private function ColSetup($col)
{
$this->col = $col;
$x = 10 + $this->col * 100;
$this->SetY($this->y0);
}
- function NextCol()
+ private function NextCol()
{
$this->ColSetup(1 - $this->col);
if ($this->col == 0) {
}
}
- function AcceptPageBreak()
+ public function AcceptPageBreak()
{
$this->broken = true;
}
- function Space($w=0.1, $h=0.5)
+ private function Space($w=0.1, $h=0.5)
{
$x = $this->getX();
$y = $this->getY();
$this->Ln($h);
}
- function TableRow($l, $r, $font = 'Sans')
+ private function TableRow($l, $r, $font = 'Sans')
{
$this->SetFont('Vera Sans', 'B', 8);
$y = $this->getY();
$this->setX($x);
}
- function Address($a)
+ private function Address($a)
{
+ if (!$a->text) {
+ return;
+ }
$l = "adresse\n";
- if ($a['active']) {
+ if ($a->hasFlag('current')) {
$l .= 'actuelle';
- } elseif ($a['secondaire']) {
+ } elseif ($a->hasFlag('secondary')) {
$l .= 'secondaire';
} else {
$l .= 'principale';
}
- $r = '';
- $r = trim("$r\n".$a['adr1']);
- $r = trim("$r\n".$a['adr2']);
- $r = trim("$r\n".$a['adr3']);
- $r = trim("$r\n".trim($a['postcode'].' '.$a['city']));
-
- $this->TableRow($l, $r);
+ $this->TableRow($l, utf8_decode($a->text));
- if (!empty($a['tels'])) {
- foreach ($a['tels'] as $tel) {
- if (!empty($tel['tel'])) {
- $this->TableRow(utf8_decode($tel['tel_type']), $tel['tel'], 'Mono');
- }
- }
+ foreach ($a->phones() as $phone) {
+ $this->TableRow(utf8_decode($phone->displayType()),
+ utf8_decode($phone->display), 'Mono');
}
}
- function AddressPro($a)
+ private function AddressPro($a)
{
- if ($a['entreprise']) {
- $this->TableRow('Entreprise', $a['entreprise']);
+ if ($a->company) {
+ $this->TableRow('Entreprise', utf8_decode($a->company->name));
}
-
- if ($a['adr1'] || $a['adr2'] || $a['adr3'] || $a['postcode'] || $a['city']) {
- $r = '';
- $r = trim("$r\n".$a['adr1']);
- $r = trim("$r\n".$a['adr2']);
- $r = trim("$r\n".$a['adr3']);
- $r = trim("$r\n".trim($a['postcode'].' '.$a['city']));
- $this->TableRow('adresse pro', $r);
- }
-
- if ($a['tel']) {
- $this->TableRow(utf8_decode('Téléphone'), $a['tel'], 'Mono');
+ if ($a->address()) {
+ $this->TableRow('adresse pro', utf8_decode($a->address()->text));
}
- if ($a['fax']) {
- $this->TableRow('Fax', $a['fax'], 'Mono');
+ foreach ($a->phones() as $phone) {
+ $this->TableRow(utf8_decode($phone->displayType()),
+ utf8_decode($phone->display), 'Mono');
}
}
- function Error($msg)
+ public function Error($msg)
{
$this->error = true;
}
- function wordwrap($text, $maxwidth = 90) {
+ private function wordwrap($text, $maxwidth = 90) {
$text = trim($text);
if ($text==='') { return 0; }
$space = $this->GetStringWidth(' ');
return $count;
}
- static function AddContact($self, $x, $wp = true)
+ public static function AddContact(ContactsPDF $self, Profile &$profile, $wp = true)
{
/* infamous hack :
1- we store the current state.
$self->SetFillColor(245, 248, 252);
$self->SetLineWidth(0.4);
- $nom = $x['prenom'].' '
- .($x['nom_usage'] ? "{$x['nom_usage']} ({$x['nom']})" : $x['nom'])
- ." ({$x['promo']})";
+ $nom = utf8_decode($profile->full_name);
$ok = false;
if ($wp) {
- $res = XDB::query("SELECT * FROM photo WHERE attachmime IN ('jpeg', 'png') AND uid={?}",
- $x['user_id']);
- if ($i = $res->numRows()) {
+ $photo = $profile->getPhoto(false, true);
+ if ($photo) {
$old2 = clone $self;
- $photo = $res->fetchOneAssoc();
- $width = $photo['x'] * 20/$photo['y'];
- $GLOBALS["p{$x['user_id']}"] = $photo['attach'];
-
+ $width = $photo->width() * 20 / $photo->height();
$_x = $self->getX();
$_y = $self->getY();
$self->Cell(0, 20, '', '', 0, '', 1);
error_reporting(0);
- $self->Image("var://p{$x['user_id']}", $_x, $_y, $width, 20, $photo['attachmime']);
+ $self->Image($photo->path(), $_x, $_y, $width, 20, $photo->mimeType());
error_reporting($self->report);
if ($self->error) {
} else {
$self->setX($_x);
$self->Cell($width, 20, '', "T");
- $h = 20 / $self->wordwrap($nom, 90-$width);
+ $h = 20 / $self->wordwrap($nom, 90 - $width);
$self->MultiCell(0, $h, $nom, 'T', 'C');
$ok = true;
}
$self->MultiCell(0, 6, $nom, "T", 'C', 1);
}
- if ($x['mobile']) {
+ if ($profile->mobile) {
$self->Space();
- $self->TableRow('mobile', $x['mobile'], 'Mono');
+ $self->TableRow('mobile', utf8_decode($profile->mobile), 'Mono');
}
- foreach ($x['adr'] as $a) {
+ $it = $profile->iterAddresses(Profile::ADDRESS_ALL);
+ while ($a = $it->next()) {
$self->Space();
- foreach ($a as &$value) {
- if (is_utf8($value)) {
- $value = utf8_decode($value);
- }
- }
$self->Address($a);
}
-
- if (!empty($x['adr_pro'])) {
- foreach ($x['adr_pro'] as $a) {
- if ( ! ($a['entreprise'] || $a['tel'] || $a['fax']
- || $a['adr1'] || $a['adr2'] || $a['adr3'] || $a['postcode'] || $a['city']) )
- {
- continue;
- }
- foreach ($a as &$value) {
- if (is_utf8($value)) {
- $value = utf8_decode($value);
- }
- }
- $self->Space();
- $self->AddressPro($a);
- }
+ $it = $profile->getJobs(Profile::JOBS_CURRENT);
+ foreach ($it as $a) {
+ $self->Space();
+ $self->AddressPro($a);
}
$self->Space(0.4, 5);
if ($self->broken) {
$old->NextCol();
- $self = ContactsPDF::AddContact($old, $x, $wp);
+ $self = ContactsPDF::AddContact($old, $profile, $wp);
}
return $self;