From: Florent Bruneau Date: Sun, 14 Feb 2010 10:04:57 +0000 (+0100) Subject: Partial port of PDF export of contact list. X-Git-Tag: xorg/1.0.0~332^2~235 X-Git-Url: http://git.polytechnique.org/?a=commitdiff_plain;h=714f5437ddf637fc9514709a4bb07c6c5eb71542;p=platal.git Partial port of PDF export of contact list. Profile class does not provide an API to retrieve the couple (job, job address). Profile::getAddresses seems to be a bit buggy. Yet another auth_user_ removed. Signed-off-by: Florent Bruneau --- diff --git a/modules/carnet.php b/modules/carnet.php index a19a50c..4ca7774 100644 --- a/modules/carnet.php +++ b/modules/carnet.php @@ -317,32 +317,23 @@ class CarnetModule extends PLModule function handler_pdf(&$page, $arg0 = null, $arg1 = null) { $this->load('contacts.pdf.inc.php'); - require_once 'user.func.inc.php'; + $user = S::user(); Platal::session()->close(); - $sql = "SELECT a.alias - FROM aliases AS a - INNER JOIN auth_user_md5 AS u ON ( a.id = u.user_id ) - INNER JOIN contacts AS c ON ( a.id = c.contact ) - WHERE c.uid = {?} AND a.type='a_vie'"; + $order = array(new UFO_Name(UserFilter::LASTNAME), new UFO_Name(UserFilter::FIRSTNAME)); if ($arg0 == 'promo') { - $sql .= ' ORDER BY u.promo, u.nom, u.prenom'; + $order = array_unshift($order, new UFO_Promo()); } else { - $sql .= ' ORDER BY u.nom, u.prenom, u.promo'; + $order[] = new UFO_Promo(); } + $filter = new UserFilter(new UFC_Contact($user), $order); - $citer = XDB::iterRow($sql, S::v('uid')); $pdf = new ContactsPDF(); - while (list($alias) = $citer->next()) { - $user = get_user_details($alias); - foreach ($user as &$value) { - if (is_utf8($value)) { - $value = utf8_decode($value); - } - } - $pdf = ContactsPDF::addContact($pdf, $user, $arg0 == 'photos' || $arg1 == 'photos'); + $profiles = $filter->getProfiles(new PlLimit()); + foreach ($profiles as $p) { + $pdf = ContactsPDF::addContact($pdf, $p, $arg0 == 'photos' || $arg1 == 'photos'); } $pdf->Output(); diff --git a/modules/carnet/contacts.pdf.inc.php b/modules/carnet/contacts.pdf.inc.php index e45fc3a..616030e 100644 --- a/modules/carnet/contacts.pdf.inc.php +++ b/modules/carnet/contacts.pdf.inc.php @@ -36,7 +36,7 @@ class ContactsPDF extends FPDF private $report = 0; - function ContactsPDF() + public function __construct() { $this->report = error_reporting(0); parent::FPDF(); @@ -53,7 +53,7 @@ class ContactsPDF extends FPDF $this->AddPage(); } - function Output($name='mescontacts.pdf', $dest='I') + public function Output($name='mescontacts.pdf', $dest='I') { Header('Pragma: public'); error_reporting(0); @@ -61,7 +61,7 @@ class ContactsPDF extends FPDF 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; @@ -84,7 +84,7 @@ class ContactsPDF extends FPDF } } - function Header() + public function Header() { $this->SetFont('Vera Sans', 'B', 20); @@ -111,7 +111,7 @@ class ContactsPDF extends FPDF $this->ColSetup(false); } - function Footer() + public function Footer() { $this->setLeftMargin(5); $this->setRightMargin(5); @@ -122,7 +122,7 @@ class ContactsPDF extends FPDF $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; @@ -132,7 +132,7 @@ class ContactsPDF extends FPDF $this->SetY($this->y0); } - function NextCol() + private function NextCol() { $this->ColSetup(1 - $this->col); if ($this->col == 0) { @@ -140,12 +140,12 @@ class ContactsPDF extends FPDF } } - 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(); @@ -154,7 +154,7 @@ class ContactsPDF extends FPDF $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(); @@ -173,36 +173,41 @@ class ContactsPDF extends FPDF $this->setX($x); } - function Address($a) + private function Address($a) { + if (!$a['text']) { + return; + } $l = "adresse\n"; - if ($a['active']) { + if ($a['current']) { $l .= 'actuelle'; - } elseif ($a['secondaire']) { + } elseif ($a['secondary']) { $l .= 'secondaire'; } else { $l .= 'principale'; } - $r = ''; - $r = trim("$r\n".$a['adr1']); + $r = utf8_decode($a['text']); +/* $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); - +/* if (!empty($a['tels'])) { foreach ($a['tels'] as $tel) { if (!empty($tel['tel'])) { $this->TableRow(utf8_decode($tel['tel_type']), $tel['tel'], 'Mono'); } } - } + }*/ } - function AddressPro($a) + private function AddressPro($a) { + return; + if ($a['entreprise']) { $this->TableRow('Entreprise', $a['entreprise']); } @@ -224,12 +229,12 @@ class ContactsPDF extends FPDF } } - 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(' '); @@ -259,7 +264,7 @@ class ContactsPDF extends FPDF 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. @@ -274,25 +279,23 @@ class ContactsPDF extends FPDF $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']); + $profile->pid); if ($i = $res->numRows()) { $old2 = clone $self; $photo = $res->fetchOneAssoc(); $width = $photo['x'] * 20/$photo['y']; - $GLOBALS["p{$x['user_id']}"] = $photo['attach']; + $GLOBALS['p' . $profile->pid] = $photo['attach']; $_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("var://p" . $profile->pid, $_x, $_y, $width, 20, $photo['attachmime']); error_reporting($self->report); if ($self->error) { @@ -310,43 +313,33 @@ class ContactsPDF extends FPDF $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) { - $self->Space(); + $it = $profile->getAddresses(Profile::ADDRESS_ALL); + while ($a = $it->next()) { foreach ($a as &$value) { - if (is_utf8($value)) { - $value = utf8_decode($value); - } + $value = utf8_decode($value); } + $self->Space(); $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->getAddresses(Profile::ADDRESS_PRO); + while ($a = $it->next()) { + foreach ($a as &$value) { + $value = utf8_decode($value); } + $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;