2 /***************************************************************************
3 * Copyright (C) 2003-2008 Polytechnique.org *
4 * http://opensource.polytechnique.org/ *
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. *
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. *
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 *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
22 class ProfileNom
implements ProfileSetting
24 private function matchWord($old, $new, $newLen) {
25 return ($i = strpos($old, $new)) !== false
26 && ($i == 0 ||
$old{$i-1} == ' ')
27 && ($i +
$newLen == strlen($old) ||
$old{$i +
$newLen} == ' ');
30 private function prepareField($value)
32 $value = strtoupper(replace_accent($value));
33 return preg_replace('/[^A-Z]/', ' ', $value);
36 public function value(ProfilePage
&$page, $field, $value, &$success)
39 $current = S
::v($field);
40 $init = S
::v($field . '_ini');
41 if (is_null($value)) {
44 if ($value == $current ||
$value == $init) {
47 $ini = $this->prepareField($init);
48 $old = $this->prepareField($current);
49 $new = $this->prepareField($value);
50 $newLen = strlen($new);
51 $success = $this->matchWord($old, $new, $newLen)
52 ||
$this->matchWord($ini, $new, $newLen)
53 ||
($field == 'nom' && $new == 'DE ' . $old);
55 Platal
::page()->trigError("Le $field que tu as choisi ($value) est trop loin de ton $field initial ($init)"
56 . (($init == $current)?
"" : " et de ton prénom précédent ($current)"));
58 return $success ?
$value : $current;
61 public function save(ProfilePage
&$page, $field, $new_value)
63 $_SESSION[$field] = $new_value;
67 class ProfileSearchName
implements ProfileSetting
70 public function __construct()
74 public function value(ProfilePage
&$page, $field, $value, &$success)
78 public function save(ProfilePage
&$page, $field, $new_value)
83 class ProfileAppli
implements ProfileSetting
85 public function value(ProfilePage
&$page, $field, $value, &$success)
88 if (is_null($value)) {
89 return $page->values
[$field];
94 public function save(ProfilePage
&$page, $field, $new_value)
96 $index = ($field == 'appli1' ?
0 : 1);
97 if ($new_value['id'] > 0) {
98 XDB
::execute("REPLACE INTO applis_ins
99 SET uid = {?}, aid = {?}, type = {?}, ordre = {?}",
100 S
::i('uid'), $new_value['id'], $new_value['type'], $index);
102 XDB
::execute("DELETE FROM applis_ins
103 WHERE uid = {?} AND ordre = {?}",
104 S
::i('uid'), $index);
109 class ProfileEmailDirectory
implements ProfileSetting
113 public function __construct()
117 public function value(ProfilePage
&$page, $field, $value, &$success)
122 if (!is_null($value)) {
123 $email_stripped = strtolower(trim($value));
124 if ((!isvalid_email($email_stripped)) && ($email_stripped) && ($page->values
['email_directory'] == "new@example.org")) {
125 $p->assign('email_error', '1');
126 $p->assign('email_directory_error', $email_stripped);
127 $p->trigError('Adresse Email invalide');
130 $p->assign('email_error', '0');
136 public function save(ProfilePage
&$page, $field, $value)
141 class ProfileNetworking
implements ProfileSetting
148 public function __construct()
150 $this->email
= new ProfileEmail();
151 $this->pub
= new ProfilePub();
152 $this->web
= new ProfileWeb();
153 $this->number
= new ProfileNumber();
156 public function value(ProfilePage
&$page, $field, $value, &$success)
158 if (is_null($value)) {
160 $res = XDB
::iterator("SELECT n.address, n.network_type AS type, n.pub, m.name
161 FROM profile_networking AS n
162 INNER JOIN profile_networking_enum AS m ON (n.network_type = m.network_type)
165 while($network = $res->next()) {
169 if (!is_array($value)) {
172 $res = XDB
::iterator("SELECT filter, network_type AS type
173 FROM profile_networking_enum;");
175 while($filter = $res->next()) {
176 $filters[$filter['type']] = $filter['filter'];
179 foreach($value as $i=>&$network) {
180 if (!trim($network['address'])) {
183 if (!isset($network['pub'])) {
184 $network['pub'] = 'private';
186 $network['error'] = false
;
187 $network['pub'] = $this->pub
->value($page, 'pub', $network['pub'], $s);
189 if ($filters[$network['type']] == 'web') {
190 $network['address'] = $this->web
->value($page, 'address', $network['address'], $s);
191 } elseif ($filters[$network['type']] == 'email') {
192 $network['address'] = $this->email
->value($page, 'address', $network['address'], $s);
193 } elseif ($filters[$network['type']] == 'number') {
194 $network['address'] = $this->number
->value($page, 'address', $network['address'], $s);
198 $network['error'] = true
;
205 public function save(ProfilePage
&$page, $field, $value)
207 XDB
::execute("DELETE FROM profile_networking
210 if (!count($value)) {
214 foreach ($value as $id=>$network) {
215 XDB
::execute("INSERT INTO profile_networking (uid, nwid, network_type, address, pub)
216 VALUES ({?}, {?}, {?}, {?}, {?})",
217 S
::i('uid'), $id, $network['type'], $network['address'], $network['pub']);
222 class ProfileGeneral
extends ProfilePage
224 protected $pg_template = 'profile/general.tpl';
226 public function __construct(PlWizard
&$wiz)
228 parent
::__construct($wiz);
229 $this->settings
['nom'] = $this->settings
['prenom']
231 $this->settings
['naissance'] = new ProfileDate();
232 $this->settings
['freetext_pub']
233 = $this->settings
['photo_pub']
235 $this->settings
['freetext']
236 = $this->settings
['nationalite']
237 = $this->settings
['nationalite2']
238 = $this->settings
['nationalite3']
239 = $this->settings
['nick']
240 = $this->settings
['yourself']
241 = $this->settings
['display_name']
242 = $this->settings
['sort_name']
243 = $this->settings
['tooltip_name']
245 $this->settings
['synchro_ax']
247 $this->settings
['email_directory']
248 = new ProfileEmail();
249 $this->settings
['email_directory_new']
250 = new ProfileEmailDirectory();
251 $this->settings
['networking'] = new ProfileNetworking();
252 $this->settings
['tels'] = new ProfilePhones('user', 0);
253 $this->settings
['appli1']
254 = $this->settings
['appli2']
255 = new ProfileAppli();
256 $this->watched
= array('nom' => true
, 'freetext' => true
, 'tels' => true
,
257 'networking' => true
, 'appli1' => true
, 'appli2' => true
,
258 'nationalite' => true
, 'nationalite2' => true
,
259 'nationalite3' => true
, 'nick' => true
);
262 protected function _fetchData()
264 // Checkout all data...
265 $res = XDB
::query("SELECT u.promo, u.promo_sortie, u.nom_usage, u.nationalite,
266 u.nationalite2, u.nationalite3, u.naissance,
267 t.display_tel as mobile, t.pub as mobile_pub,
268 d.email_directory as email_directory,
269 q.profile_freetext as freetext, q.profile_freetext_pub as freetext_pub,
270 q.profile_nick as nick, q.profile_from_ax as synchro_ax, u.matricule_ax,
271 IF(a1.aid IS NULL, -1, a1.aid) as appli_id1, a1.type as appli_type1,
272 IF(a2.aid IS NULL, -1, a2.aid) as appli_id2, a2.type as appli_type2,
273 n.yourself, n.display AS display_name, n.sort AS sort_name,
274 n.tooltip AS tooltip_name
275 FROM auth_user_md5 AS u
276 INNER JOIN auth_user_quick AS q ON(u.user_id = q.user_id)
277 INNER JOIN profile_names_display AS n ON(n.user_id = u.user_id)
278 LEFT JOIN profile_phones AS t ON(u.user_id = t.uid AND link_type = 'user')
279 LEFT JOIN profile_directory AS d ON(d.uid = u.user_id)
280 LEFT JOIN applis_ins AS a1 ON(a1.uid = u.user_id and a1.ordre = 0)
281 LEFT JOIN applis_ins AS a2 ON(a2.uid = u.user_id and a2.ordre = 1)
282 WHERE u.user_id = {?}", S
::v('uid', -1));
283 $this->values
= $res->fetchOneAssoc();
285 // Reformat formation data
286 $this->values
['appli1'] = array('id' => $this->values
['appli_id1'],
287 'type' => $this->values
['appli_type1']);
288 unset($this->values
['appli_id1']);
289 unset($this->values
['appli_type1']);
290 $this->values
['appli2'] = array('id' => $this->values
['appli_id2'],
291 'type' => $this->values
['appli_type2']);
292 unset($this->values
['appli_id2']);
293 unset($this->values
['appli_type2']);
295 // Retreive photo informations
296 $res = XDB
::query("SELECT pub
298 WHERE uid = {?}", S
::v('uid'));
299 $this->values
['photo_pub'] = $res->fetchOneCell();
301 $res = XDB
::query("SELECT COUNT(*)
303 WHERE type='photo' AND user_id = {?}",
305 $this->values
['nouvellephoto'] = $res->fetchOneCell();
307 // Retreive search names info
308 $this->values
['search_names'] = XDB
::iterator("
309 SELECT sn.search_name, sn.name_type, sn.pub, sn.sn_id
310 FROM profile_names_search AS sn
311 WHERE sn.user_id = {?}
312 ORDER BY sn.name_type, search_score, search_name",
316 $res = XDB
::iterator("SELECT t.display_tel AS tel, t.tel_type AS type, t.pub, t.comment
317 FROM profile_phones AS t
318 WHERE t.uid = {?} AND t.link_type = 'user'
321 $this->values
['tels'] = $res->fetchAllAssoc();
324 protected function _saveData()
326 if ($this->changed
['nationalite'] ||
$this->changed
['nationalite2'] ||
$this->changed
['nationalite3']
327 ||
$this->changed
['nom'] ||
$this->changed
['prenom'] ||
$this->changed
['naissance']) {
328 if ($this->values
['nationalite3'] == "") {
329 $this->values
['nationalite3'] = NULL
;
331 if ($this->values
['nationalite2'] == "") {
332 $this->values
['nationalite2'] = $this->values
['nationalite3'];
333 $this->values
['nationalite3'] = NULL
;
335 if ($this->values
['nationalite'] == "") {
336 $this->values
['nationalite'] = $this->values
['nationalite2'];
337 $this->values
['nationalite2'] = $this->values
['nationalite3'];
338 $this->values
['nationalite3'] = NULL
;
341 XDB
::execute("UPDATE auth_user_md5
342 SET nationalite = {?}, nationalite2 = {?}, nationalite3 = {?}, nom={?}, prenom={?}, naissance={?}
343 WHERE user_id = {?}",
344 $this->values
['nationalite'], $this->values
['nationalite2'], $this->values
['nationalite3'],
345 $this->values
['nom'], $this->values
['prenom'],
346 preg_replace('@(\d{2})/(\d{2})/(\d{4})@', '\3-\2-\1', $this->values
['naissance']),
349 if ($this->changed
['nick'] ||
$this->changed
['freetext'] ||
$this->changed
['freetext_pub'] ||
$this->changed
['synchro_ax']) {
350 XDB
::execute("UPDATE auth_user_quick
351 SET profile_nick= {?},
352 profile_freetext={?},
353 profile_freetext_pub={?}, profile_from_ax = {?}
354 WHERE user_id = {?}",
355 $this->values
['nick'],
356 $this->values
['freetext'], $this->values
['freetext_pub'],
357 $this->values
['synchro_ax'], S
::v('uid'));
359 if ($this->changed
['email_directory']) {
360 $new_email = ($this->values
['email_directory'] == "new@example.org") ?
361 $this->values
['email_directory_new'] : $this->values
['email_directory'];
362 if ($new_email == "") {
365 XDB
::execute("REPLACE INTO profile_directory (uid, email_directory)
367 S
::v('uid'), $new_email);
369 if ($this->changed
['nick']) {
370 require_once('user.func.inc.php');
371 user_reindex(S
::v('uid'));
373 if ($this->changed
['photo_pub']) {
374 XDB
::execute("UPDATE photo
377 $this->values
['photo_pub'], S
::v('uid'));
379 if ($this->changed
['yourself'] ||
$this->changed
['sort_name'] ||
380 $this-> changed
['display_name'] ||
$this->changed
['tooltip_name']) {
381 XDB
::execute("UPDATE profile_names_display AS n
382 SET n.yourself = {?},
383 n.sort = {?}, ". // SET
384 "n.display = {?}, ". // SET
385 "n.tooltip = {?} ". // SET
386 "WHERE n.user_id = {?}",
387 $this->values
['yourself'],
388 $this->values
['sort_name'],
389 $this->values
['display_name'],
390 $this->values
['tooltip_name'],
395 public function _prepare(PlPage
&$page, $id)
397 require_once "applis.func.inc.php";
399 require_once "emails.combobox.inc.php";
400 fill_email_combobox($page);
402 $res = XDB
::iterator("SELECT nw.network_type AS type, nw.name
403 FROM profile_networking_enum AS nw
405 $page->assign('network_list', $res->fetchAllAssoc());
409 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: