2b49451865ec50b8f0c662637ada69a4c9dab3cd
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)
26 return ($i = strpos($old, $new)) !== false
27 && ($i == 0 ||
$old{$i-1} == ' ')
28 && ($i +
$newLen == strlen($old) ||
$old{$i +
$newLen} == ' ');
31 private function prepareField($value)
33 $value = strtoupper(replace_accent($value));
34 return preg_replace('/[^A-Z]/', ' ', $value);
37 public function value(ProfilePage
&$page, $field, $value, &$success)
40 $current = S
::v($field);
41 $init = S
::v($field . '_ini');
42 if (is_null($value)) {
45 if ($value == $current ||
$value == $init) {
48 $ini = $this->prepareField($init);
49 $old = $this->prepareField($current);
50 $new = $this->prepareField($value);
51 $newLen = strlen($new);
52 $success = $this->matchWord($old, $new, $newLen)
53 ||
$this->matchWord($ini, $new, $newLen)
54 ||
($field == 'nom' && $new == 'DE ' . $old);
56 Platal
::page()->trigError("Le $field que tu as choisi ($value) est trop loin de ton $field initial ($init)"
57 . (($init == $current)?
"" : " et de ton prénom précédent ($current)"));
59 return $success ?
$value : $current;
62 public function save(ProfilePage
&$page, $field, $new_value)
64 $_SESSION[$field] = $new_value;
68 class ProfileSearchName
implements ProfileSetting
71 public function __construct()
75 public function value(ProfilePage
&$page, $field, $value, &$success)
79 public function save(ProfilePage
&$page, $field, $new_value)
84 class ProfileEdu
implements ProfileSetting
86 public function __construct() {
89 static function sortByGradYear($line1, $line2) {
90 $a = (int) $line1['grad_year'];
91 $b = (int) $line2['grad_year'];
95 return ($a < $b) ?
-1 : 1;
98 public function value(ProfilePage
&$page, $field, $value, &$success)
101 if (is_null($value) ||
!is_array($value)) {
103 $res = XDB
::iterator("SELECT eduid, degreeid, fieldid, grad_year, program
104 FROM profile_education
105 WHERE uid = {?} AND !FIND_IN_SET('primary', flags)
108 while($edu = $res->next()) {
113 foreach ($value as $key=>&$edu) {
114 if (($edu['grad_year'] < 1921) ||
($edu['grad_year'] > (date('Y') +
4))) {
115 Platal
::page()->trigError('L\'année d\'obtention du diplôme est mal renseignée, elle doit être du type : 2004.');
116 $edu['error'] = true
;
125 usort($value, array("ProfileEdu", "sortByGradYear"));
130 public function save(ProfilePage
&$page, $field, $value)
132 XDB
::execute("DELETE FROM profile_education
133 WHERE uid = {?} AND !FIND_IN_SET('primary', flags)",
135 foreach ($value as $eduid=>&$edu) {
136 if ($edu['eduid'] != '') {
137 XDB
::execute("INSERT INTO profile_education
138 SET id = {?}, uid = {?}, eduid = {?}, degreeid = {?},
139 fieldid = {?}, grad_year = {?}, program = {?}",
140 $eduid, $page->pid(), $edu['eduid'], $edu['degreeid'],
141 $edu['fieldid'], $edu['grad_year'], $edu['program']);
147 class ProfileEmailDirectory
implements ProfileSetting
149 public function __construct(){}
150 public function save(ProfilePage
&$page, $field, $value){}
152 public function value(ProfilePage
&$page, $field, $value, &$success)
157 if (!is_null($value)) {
158 $email_stripped = strtolower(trim($value));
159 if ((!isvalid_email($email_stripped)) && ($email_stripped) && ($page->values
['email_directory'] == "new@example.org")) {
160 $p->assign('email_error', '1');
161 $p->assign('email_directory_error', $email_stripped);
162 $p->trigError('Adresse Email invalide');
165 $p->assign('email_error', '0');
172 class ProfileNetworking
implements ProfileSetting
179 public function __construct()
181 $this->email
= new ProfileEmail();
182 $this->pub
= new ProfilePub();
183 $this->web
= new ProfileWeb();
184 $this->number
= new ProfileNumber();
187 public function value(ProfilePage
&$page, $field, $value, &$success)
189 if (is_null($value)) {
191 $res = XDB
::iterator("SELECT n.address, n.network_type AS type, n.pub, m.name
192 FROM profile_networking AS n
193 INNER JOIN profile_networking_enum AS m ON (n.network_type = m.network_type)
196 while($network = $res->next()) {
200 if (!is_array($value)) {
203 $res = XDB
::iterator("SELECT filter, network_type AS type
204 FROM profile_networking_enum;");
206 while($filter = $res->next()) {
207 $filters[$filter['type']] = $filter['filter'];
210 foreach($value as $i=>&$network) {
211 if (!trim($network['address'])) {
214 if (!isset($network['pub'])) {
215 $network['pub'] = 'private';
217 $network['error'] = false
;
218 $network['pub'] = $this->pub
->value($page, 'pub', $network['pub'], $s);
220 if ($filters[$network['type']] == 'web') {
221 $network['address'] = $this->web
->value($page, 'address', $network['address'], $s);
222 } elseif ($filters[$network['type']] == 'email') {
223 $network['address'] = $this->email
->value($page, 'address', $network['address'], $s);
224 } elseif ($filters[$network['type']] == 'number') {
225 $network['address'] = $this->number
->value($page, 'address', $network['address'], $s);
229 $network['error'] = true
;
236 public function save(ProfilePage
&$page, $field, $value)
238 XDB
::execute("DELETE FROM profile_networking
241 if (!count($value)) {
245 foreach ($value as $id=>$network) {
246 XDB
::execute("INSERT INTO profile_networking (uid, nwid, network_type, address, pub)
247 VALUES ({?}, {?}, {?}, {?}, {?})",
248 $page->pid(), $id, $network['type'], $network['address'], $network['pub']);
253 class ProfileGeneral
extends ProfilePage
255 protected $pg_template = 'profile/general.tpl';
257 public function __construct(PlWizard
&$wiz)
259 parent
::__construct($wiz);
260 $this->settings
['nom'] = $this->settings
['prenom']
262 $this->settings
['birthdate'] = new ProfileDate();
263 $this->settings
['freetext_pub']
264 = $this->settings
['photo_pub']
266 $this->settings
['freetext']
267 = $this->settings
['nationality1']
268 = $this->settings
['nationality2']
269 = $this->settings
['nationality3']
270 = $this->settings
['nick']
271 = $this->settings
['yourself']
272 = $this->settings
['display_name']
273 = $this->settings
['sort_name']
274 = $this->settings
['tooltip_name']
275 = $this->settings
['promo_display']
277 $this->settings
['synchro_ax']
279 $this->settings
['email_directory']
280 = new ProfileEmail();
281 $this->settings
['email_directory_new']
282 = new ProfileEmailDirectory();
283 $this->settings
['networking'] = new ProfileNetworking();
284 $this->settings
['tels'] = new ProfilePhones('user', 0);
285 $this->settings
['edus'] = new ProfileEdu();
286 $this->watched
= array('nom' => true
, 'freetext' => true
, 'tels' => true
,
287 'networking' => true
, 'edus' => true
,
288 'nationality1' => true
, 'nationality2' => true
,
289 'nationality3' => true
, 'nick' => true
);
292 protected function _fetchData()
294 // Checkout all data...
295 $res = XDB
::query("SELECT p.promo AS promo_display, e.entry_year AS entry_year, e.grad_year AS grad_year,
296 pr.nationality1, pr.nationality2, pr.nationality3, pr.birthdate,
297 t.display_tel as mobile, t.pub as mobile_pub,
298 d.email_directory as email_directory,
299 pr.freetext, pr.freetext_pub as freetext_pub,
300 n.yourself, n.display AS display_name, n.sort AS sort_name,
301 n.tooltip AS tooltip_name
303 INNER JOIN profile_names_display AS n ON (n.user_id = pr.pid)
304 INNER JOIN profile_display AS p ON (p.pid = pr.pid)
305 INNER JOIN profile_education AS e ON (e.uid = pr.pid AND FIND_IN_SET('primary', e.flags))
306 LEFT JOIN profile_phones AS t ON (t.uid = pr.pid AND link_type = 'user')
307 LEFT JOIN profile_directory AS d ON (d.uid = pr.pid)
308 WHERE pr.pid = {?}", $this->pid());
309 $this->values
= $res->fetchOneAssoc();
311 // Retreive photo informations
312 $res = XDB
::query("SELECT pub
314 WHERE uid = {?}", $this->pid());
315 $this->values
['photo_pub'] = $res->fetchOneCell();
318 $res = XDB
::query("SELECT COUNT(*)
320 WHERE type='photo' AND user_id = {?}",
322 $this->values
['nouvellephoto'] = $res->fetchOneCell();
324 $this->values
['nouvellephoto'] = 0;
327 // Retreive search names info
328 $this->values
['search_names'] = XDB
::iterator("
329 SELECT sn.search_name, sn.name_type, sn.pub, sn.sn_id
330 FROM profile_names_search AS sn
331 WHERE sn.user_id = {?}
332 ORDER BY sn.name_type, search_score, search_name",
335 // Proposes choice for promo_display
336 if ($this->values
['entry_year'] != $this->values
['grad_year'] - 3) {
337 for ($i = $this->values
['entry_year']; $i < $this->values
['grad_year'] - 2; $i++
) {
338 $this->values
['promo_choice'][] = "X" . $i;
343 protected function _saveData()
345 if ($this->changed
['nationality1'] ||
$this->changed
['nationality2'] ||
$this->changed
['nationality3']
346 ||
$this->changed
['nom'] ||
$this->changed
['prenom'] ||
$this->changed
['naissance']
347 ||
$this->changed
['freetext'] ||
$this->changed
['freetext_pub']) {
348 if ($this->values
['nationality3'] == "") {
349 $this->values
['nationality3'] = NULL
;
351 if ($this->values
['nationality2'] == "") {
352 $this->values
['nationality2'] = $this->values
['nationality3'];
353 $this->values
['nationality3'] = NULL
;
355 if ($this->values
['nationality1'] == "") {
356 $this->values
['nationality1'] = $this->values
['nationality2'];
357 $this->values
['nationality2'] = $this->values
['nationality3'];
358 $this->values
['nationality3'] = NULL
;
361 XDB
::execute("UPDATE profiles
362 SET nationality1 = {?}, nationality2 = {?}, nationality3 = {?}, birthdate = {?},
363 freetext = {?}, freetext_pub = {?}
364 WHERE user_id = {?}",
365 $this->values
['nationality1'], $this->values
['nationality2'], $this->values
['nationality3'],
366 preg_replace('@(\d{2})/(\d{2})/(\d{4})@', '\3-\2-\1', $this->values
['birthdate']),
367 $this->values
['freetext'], $this->values
['freetext_pub'],
370 if ($this->changed
['email_directory']) {
371 $new_email = ($this->values
['email_directory'] == "new@example.org") ?
372 $this->values
['email_directory_new'] : $this->values
['email_directory'];
373 if ($new_email == "") {
376 XDB
::execute("REPLACE INTO profile_directory (uid, email_directory)
378 $this->pid(), $new_email);
380 if ($this->changed
['nick']) {
381 require_once('user.func.inc.php');
382 user_reindex(S
::v('uid'));
384 if ($this->changed
['photo_pub']) {
385 XDB
::execute("UPDATE photo
388 $this->values
['photo_pub'], $this->pid());
390 if ($this->changed
['yourself'] ||
$this->changed
['sort_name'] ||
391 $this-> changed
['display_name'] ||
$this->changed
['tooltip_name']) {
392 XDB
::execute("UPDATE profile_names_display AS n
393 SET n.yourself = {?},
394 n.sort = {?}, ". // SET
395 "n.display = {?}, ". // SET
396 "n.tooltip = {?} ". // SET
397 "WHERE n.user_id = {?}",
398 $this->values
['yourself'],
399 $this->values
['sort_name'],
400 $this->values
['display_name'],
401 $this->values
['tooltip_name'],
404 if ($this->changed
['promo_display']) {
405 XDB
::execute("UPDATE profile_display
408 $this->values
['promo_display'], $this->pid());
412 public function _prepare(PlPage
&$page, $id)
414 require_once "education.func.inc.php";
416 $res = XDB
::iterator("SELECT id, field
417 FROM profile_education_field_enum
419 $page->assign('edu_fields', $res->fetchAllAssoc());
421 require_once "emails.combobox.inc.php";
422 fill_email_combobox($page, $this->owner
, $this->profile
);
424 $res = XDB
::iterator("SELECT nw.network_type AS type, nw.name
425 FROM profile_networking_enum AS nw
427 $page->assign('network_list', $res->fetchAllAssoc());
431 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: