Commit | Line | Data |
---|---|---|
89460d9c | 1 | <?php |
2 | /*************************************************************************** | |
179afa7f | 3 | * Copyright (C) 2003-2008 Polytechnique.org * |
89460d9c | 4 | * http://opensource.polytechnique.org/ * |
5 | * * | |
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. * | |
10 | * * | |
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. * | |
15 | * * | |
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 * | |
18 | * Foundation, Inc., * | |
19 | * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * | |
20 | ***************************************************************************/ | |
21 | ||
89460d9c | 22 | require_once('user.func.inc.php'); |
23 | ||
5d42c993 | 24 | class VCard extends PlVCard |
89460d9c | 25 | { |
29b12e6e | 26 | private $user_list = array(); |
27 | private $count = 0; | |
28 | private $freetext = null; | |
29 | private $photos = true; | |
89460d9c | 30 | |
5d42c993 | 31 | public function __construct($photos = true, $freetext = null) |
89460d9c | 32 | { |
5d42c993 | 33 | PlVCard::$folding = false; |
29b12e6e | 34 | $this->freetext = $freetext; |
35 | $this->photos = $photos; | |
89460d9c | 36 | } |
37 | ||
5d42c993 | 38 | public function addUser($user) |
89460d9c | 39 | { |
3ce06e37 FB |
40 | $forlife = get_user_forlife($user, '_silent_user_callback'); |
41 | if ($forlife) { | |
42 | $this->user_list[] = get_user_forlife($user); | |
43 | $this->count++; | |
44 | } | |
89460d9c | 45 | } |
46 | ||
5d42c993 FB |
47 | public function addUsers(array $users) { |
48 | foreach ($users as $user) { | |
49 | $this->addUser($user); | |
50 | } | |
89460d9c | 51 | } |
52 | ||
5d42c993 | 53 | protected function fetch() |
89460d9c | 54 | { |
20661fd0 | 55 | return PlIteratorUtils::fromArray($this->user_list); |
29b12e6e | 56 | } |
89460d9c | 57 | |
5d42c993 | 58 | protected function buildEntry($entry) |
29b12e6e | 59 | { |
29b12e6e | 60 | global $globals; |
5d42c993 | 61 | $login = $entry['value']; |
89460d9c | 62 | $user = get_user_details($login); |
63 | ||
5d42c993 FB |
64 | if (empty($user['nom_usage'])) { |
65 | $entry = new PlVCardEntry($user['prenom'], $user['nom'], null, null, @$user['nickname']); | |
66 | } else { | |
67 | $entry = new PlVCardEntry($user['prenom'], array($user['nom'], $user['nom_usage']), null, null, @$user['nickname']); | |
89460d9c | 68 | } |
5d42c993 FB |
69 | |
70 | // Free text | |
71 | $freetext = '(' . $user['promo'] . ')'; | |
29b12e6e | 72 | if ($this->freetext) { |
5d42c993 FB |
73 | $freetext .= "\n" . $this->freetext; |
74 | } | |
75 | if (strlen(trim($user['freetext']))) { | |
76 | $freetext .= "\n" . MiniWiki::WikiToText($user['freetext']); | |
77 | } | |
78 | $entry->set('NOTE', $freetext); | |
79 | ||
80 | // Mobile | |
81 | if (!empty($user['mobile'])) { | |
82 | $entry->addTel(null, $user['mobile'], false, true, true, false, true, true); | |
83 | } | |
84 | ||
85 | // Emails | |
86 | $entry->addMail(null, $user['bestalias'] . '@' . $globals->mail->domain, true); | |
87 | $entry->addMail(null, $user['bestalias'] . '@' . $globals->mail->domain2); | |
88 | if ($user['bestalias'] != $user['forlife']) { | |
89 | $entry->addMail(null, $user['forlife'] . '@' . $globals->mail->domain); | |
90 | $entry->addMail(null, $user['forlife'] . '@' . $globals->mail->domain2); | |
91 | } | |
92 | ||
93 | // Homes | |
94 | foreach ($user['adr'] as $adr) { | |
95 | $street = array($adr['adr1']); | |
96 | if (!empty($adr['adr2'])) { | |
97 | $street[] = $adr['adr2']; | |
98 | } | |
99 | if (!empty($adr['adr3'])) { | |
100 | $street[] = $adr['adr3']; | |
101 | } | |
102 | $group = $entry->addHome($street, null, null, $adr['postcode'], $adr['city'], $adr['region'], @$adr['country'], | |
103 | $adr['active'], $adr['courier'], $adr['courier']); | |
104 | if (!empty($adr['tels'])) { | |
105 | foreach ($adr['tels'] as $tel) { | |
106 | $fax = $tel['tel_type'] == 'Fax'; | |
107 | $entry->addTel($group, $tel['tel'], $fax, !$fax, !$fax, false, false, !$fax && $adr['active'] && empty($user['mobile'])); | |
108 | } | |
109 | } | |
110 | } | |
111 | ||
112 | // Pro | |
113 | foreach ($user['adr_pro'] as $pro) { | |
114 | $street = array($adr['adr1']); | |
115 | if (!empty($pro['adr2'])) { | |
116 | $street[] = $pro['adr2']; | |
117 | } | |
118 | if (!empty($pro['adr3'])) { | |
119 | $street[] = $pro['adr3']; | |
120 | } | |
121 | $group = $entry->addWork($pro['entreprise'], null, $pro['poste'], $pro['fonction'], | |
122 | $street, null, null, $pro['postcode'], $pro['city'], $pro['region'], @$pro['country']); | |
123 | if (!empty($pro['tel'])) { | |
124 | $entry->addTel($group, $pro['tel']); | |
125 | } | |
126 | if (!empty($pro['fax'])) { | |
127 | $entry->addTel($group, $pro['fax'], true); | |
128 | } | |
129 | if (!empty($pro['email'])) { | |
130 | $entry->addMail($group, $pro['email']); | |
89460d9c | 131 | } |
132 | } | |
133 | ||
5d42c993 | 134 | // Melix |
89460d9c | 135 | $res = XDB::query( |
136 | "SELECT alias | |
137 | FROM virtual | |
138 | INNER JOIN virtual_redirect USING(vid) | |
139 | INNER JOIN auth_user_quick ON ( user_id = {?} AND emails_alias_pub = 'public' ) | |
140 | WHERE ( redirect={?} OR redirect={?} ) | |
141 | AND alias LIKE '%@{$globals->mail->alias_dom}'", | |
50bf984b | 142 | $user['user_id'], |
89460d9c | 143 | $user['forlife'].'@'.$globals->mail->domain, |
144 | $user['forlife'].'@'.$globals->mail->domain2); | |
5d42c993 FB |
145 | if ($res->numRows()) { |
146 | $entry->addMail(null, $res->fetchOneCell()); | |
147 | } | |
148 | ||
149 | // Custom fields | |
150 | if (count($user['gpxs_name'])) { | |
151 | $entry->set('X-GROUPS', join(', ', $user['gpxs_name'])); | |
152 | } | |
153 | if (count($user['binets'])) { | |
154 | $entry->set('X-BINETS', join(', ', $user['binets'])); | |
155 | } | |
156 | if (!empty($user['section'])) { | |
157 | $entry->set('X-SECTION', $user['section']); | |
158 | } | |
eaf30d86 | 159 | |
5d42c993 | 160 | // Photo |
917c4d11 | 161 | if ($this->photos) { |
162 | $res = XDB::query( | |
163 | "SELECT attach, attachmime | |
164 | FROM photo AS p | |
165 | INNER JOIN aliases AS a ON (a.id = p.uid AND a.type = 'a_vie') | |
166 | WHERE a.alias = {?}", $login); | |
167 | if ($res->numRows()) { | |
5d42c993 FB |
168 | list($data, $type) = $res->fetchOneRow(); |
169 | $entry->setPhoto($data, strtoupper($type)); | |
29b12e6e | 170 | } |
29b12e6e | 171 | } |
5d42c993 | 172 | return $entry; |
89460d9c | 173 | } |
89460d9c | 174 | } |
175 | ||
a7de4ef7 | 176 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: |
89460d9c | 177 | ?> |