Should fix comment in cyberplus payment notification.
[platal.git] / modules / carnet / contacts.pdf.inc.php
index 2ceea8d..a981b1c 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /***************************************************************************
- *  Copyright (C) 2003-2010 Polytechnique.org                              *
+ *  Copyright (C) 2003-2011 Polytechnique.org                              *
  *  http://opensource.polytechnique.org/                                   *
  *                                                                         *
  *  This program is free software; you can redistribute it and/or modify   *
@@ -187,40 +187,25 @@ class ContactsPDF extends FPDF
             $l .= 'principale';
         }
 
-        $r = $a->text;
-        $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');
-                }
-            }
-        }*/
+        $this->TableRow($l, utf8_decode($a->text));
+
+        foreach ($a->phones() as $phone) {
+            $this->TableRow(utf8_decode($phone->displayType()),
+                            utf8_decode($phone->display), 'Mono');
+        }
     }
 
     private function AddressPro($a)
     {
-        return;
-
-        if ($a['entreprise']) {
-            $this->TableRow('Entreprise', $a['entreprise']);
-        }
-
-        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->company) {
+            $this->TableRow('Entreprise', utf8_decode($a->company->name));
         }
-
-        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');
         }
     }
 
@@ -259,7 +244,7 @@ class ContactsPDF extends FPDF
         return $count;
     }
 
-    public static function AddContact(ContactsPDF $self, Profile &$profile, $wp = true)
+    public static function AddContact(ContactsPDF $self, Profile $profile, $wp = true)
     {
         /* infamous hack :
            1- we store the current state.
@@ -280,23 +265,27 @@ class ContactsPDF extends FPDF
         if ($wp) {
             $photo = $profile->getPhoto(false, true);
             if ($photo) {
-                $old2  = clone $self;
-                $width = $photo->width() * 20 / $photo->height();
-                $_x = $self->getX();
-                $_y = $self->getY();
-                $self->Cell(0, 20, '', '', 0, '', 1);
-                error_reporting(0);
-                $self->Image($photo->path(), $_x, $_y, $width, 20, $photo->mimeType());
-                error_reporting($self->report);
-
-                if ($self->error) {
-                    $self = clone $old2;
-                } else {
-                    $self->setX($_x);
-                    $self->Cell($width, 20, '', "T");
-                    $h = 20 / $self->wordwrap($nom, 90 - $width);
-                    $self->MultiCell(0, $h, $nom, 'T', 'C');
-                    $ok = true;
+                list(, $type) = explode('/', $photo->mimeType());
+                $type = ($type == 'jpeg') ? 'jpg' : $type;
+                if (method_exists($self, '_parse' . $type)) {
+                    $old2  = clone $self;
+                    $width = $photo->width() * 20 / $photo->height();
+                    $_x = $self->getX();
+                    $_y = $self->getY();
+                    $self->Cell(0, 20, '', '', 0, '', 1);
+                    error_reporting(0);
+                    $self->Image($photo->path(), $_x, $_y, $width, 20, $type);
+                    error_reporting($self->report);
+
+                    if ($self->error) {
+                        $self = clone $old2;
+                    } else {
+                        $self->setX($_x);
+                        $self->Cell($width, 20, '', "T");
+                        $h = 20 / $self->wordwrap($nom, 90 - $width);
+                        $self->MultiCell(0, $h, $nom, 'T', 'C');
+                        $ok = true;
+                    }
                 }
             }
         }
@@ -311,17 +300,11 @@ class ContactsPDF extends FPDF
 
         $it = $profile->iterAddresses(Profile::ADDRESS_ALL);
         while ($a = $it->next()) {
-            foreach ($a as &$value) {
-                $value = utf8_decode($value);
-            }
             $self->Space();
             $self->Address($a);
         }
-        $it = $profile->iterAddresses(Profile::ADDRESS_PRO);
-        while ($a = $it->next()) {
-            foreach ($a as &$value) {
-                $value = utf8_decode($value);
-            }
+        $it = $profile->getJobs(Profile::JOBS_CURRENT);
+        foreach ($it as $a) {
             $self->Space();
             $self->AddressPro($a);
         }