+++ /dev/null
-<?php
-/***************************************************************************
- * Copyright (C) 2003-2007 Polytechnique.org *
- * http://opensource.polytechnique.org/ *
- * *
- * This program is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. *
- * *
- * This program is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
- * GNU General Public License for more details. *
- * *
- * You should have received a copy of the GNU General Public License *
- * along with this program; if not, write to the Free Software *
- * Foundation, Inc., *
- * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
- ***************************************************************************/
-
-$page->assign('mobile_pub',$mobile_pub);
-$page->assign('web_pub',$web_pub);
-$page->assign('freetext_pub',$freetext_pub);
-
-$page->assign('nom', $nom);
-$page->assign('prenom', $prenom);
-$page->assign('promo', $promo);
-$page->assign('promo_sortie', $promo_sortie);
-$page->assign('nom_usage', $nom_usage);
-
-$page->assign('nationalite',$nationalite);
-
-$page->assign('mobile',$mobile);
-
-$page->assign('web',$web);
-
-$page->assign('freetext',$freetext);
-
-$page->assign('appli_id1',$appli_id1);
-$page->assign('appli_id2',$appli_id2);
-$page->assign('appli_type1',$appli_type1);
-$page->assign('appli_type2',$appli_type2);
-
-$page->assign('photo_pub',$photo_pub);
-$page->assign('nouvellephoto', $nouvellephoto);
-$page->assign('nickname', $nickname);
-
-$page->assign('synchro_ax', $synchro_ax);
-$page->assign('matricule_ax', $matricule_ax);
-// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
-?>
}
}
+class ProfileAppli implements ProfileSetting
+{
+ public function value(ProfilePage &$page, $field, $value, &$success)
+ {
+ $success = true;
+ if (is_null($value)) {
+ return $page->values[$field];
+ }
+ return $value;
+ }
+
+ public function save(ProfilePage &$page, $field, $new_value)
+ {
+ $index = ($field == 'appli1' ? 0 : 1);
+ if ($new_value['id'] > 0) {
+ XDB::execute("REPLACE INTO applis_ins
+ SET uid = {?}, aid = {?}, type = {?}, ordre = {?}",
+ S::i('uid'), $new_value['id'], $new_value['type'], $index);
+ } else {
+ XDB::execute("DELETE FROM applis_ins
+ WHERE uid = {?} AND ordre = {?}",
+ S::i('uid'), $index);
+ }
+ }
+}
+
class ProfileGeneral extends ProfilePage
{
protected $pg_template = 'profile/general.tpl';
$this->settings['mobile_pub']
= $this->settings['web_pub']
= $this->settings['freetext_pub']
+ = $this->settings['photo_pub']
= new ProfilePub();
$this->settings['freetext']
- = $this->settings['appli_id1']
- = $this->settings['appli_id2']
+ = $this->settings['nationalite']
= $this->settings['nick']
= null;
+ $this->settings['synchro_ax']
+ = new ProfileBool();
$this->settings['mobile'] = new ProfileTel();
$this->settings['web'] = new ProfileWeb();
+ $this->settings['appli1']
+ = $this->settings['appli2']
+ = new ProfileAppli();
}
protected function fetchData()
$this->values = $this->orig;
return;
}
+
+ // Checkout all data...
$res = XDB::query("SELECT u.promo, u.promo_sortie, u.nom_usage, u.nationalite,
q.profile_mobile as mobile, q.profile_mobile_pub as mobile_pub,
q.profile_web as web, q.profile_web_pub as web_pub,
q.profile_freetext as freetext, q.profile_freetext_pub as freetext_pub,
- q.profile_nick as nick, q.profile_from_ax, u.matricule_ax,
+ q.profile_nick as nick, q.profile_from_ax as synchro_ax, u.matricule_ax,
IF(a1.aid IS NULL, -1, a1.aid) as appli_id1, a1.type as appli_type1,
IF(a2.aid IS NULL, -1, a2.aid) as appli_id2, a2.type as appli_type2
FROM auth_user_md5 AS u
LEFT JOIN applis_ins AS a2 ON(a2.uid = u.user_id and a2.ordre = 1)
WHERE u.user_id = {?}", S::v('uid', -1));
$this->values = $res->fetchOneAssoc();
+
+ // Reformat formation data
+ $this->values['appli1'] = array('id' => $this->values['appli_id1'],
+ 'type' => $this->values['appli_type1']);
+ unset($this->values['appli_id1']);
+ unset($this->values['appli_type1']);
+ $this->values['appli2'] = array('id' => $this->values['appli_id2'],
+ 'type' => $this->values['appli_type2']);
+ unset($this->values['appli_id2']);
+ unset($this->values['appli_type2']);
+
+ // Retreive photo informations
+ $res = XDB::query("SELECT pub
+ FROM photo
+ WHERE uid = {?}", S::v('uid'));
+ $this->values['photo_pub'] = $res->fetchOneCell();
+
+ $res = XDB::query("SELECT COUNT(*)
+ FROM requests
+ WHERE type='photo' AND user_id = {?}",
+ S::v('uid'));
+ $this->values['nouvellephoto'] = $res->fetchOneCell();
parent::fetchData();
}
protected function saveData()
{
parent::saveData();
- XDB::execute("UPDATE auth_user_md5 SET nom={?}, prenom={?} WHERE user_id = {?}",
- $this->values['nom'], $this->values['prenom'], S::v('uid'));
+ if ($this->changed['nationalite'] || $this->changed['nom'] || $this->changed['prenom']) {
+ XDB::execute("UPDATE auth_user_md5
+ SET nationalite = {?}, nom={?}, prenom={?} WHERE user_id = {?}",
+ $this->values['nationalite'], $this->values['nom'], $this->values['prenom'], S::v('uid'));
+ }
+ if ($this->changed['nick'] || $this->changed['mobile'] || $this->changed['mobile_pub']
+ || $this->changed['web'] || $this->changed['web_pub'] || $this->changed['freetext']
+ || $this->changed['freetext_pub'] || $this->changed['synchro_ax']) {
+ XDB::execute("UPDATE auth_user_quick
+ SET profile_nick= {?}, profile_mobile={?}, profile_mobile_pub={?},
+ profile_web={?}, profile_web_pub={?}, profile_freetext={?},
+ profile_freetext_pub={?}, profile_from_ax = {?}
+ WHERE user_id = {?}",
+ $this->values['nick'], $this->values['mobile'], $this->values['mobile_pub'],
+ $this->values['web'], $this->values['web_pub'],
+ $this->values['freetext'], $this->values['freetext_pub'],
+ $this->values['synchro_ax'], S::v('uid'));
+ }
+ if ($this->changed['nick']) {
+ require_once('user.func.inc.php');
+ user_reindex(S::v('uid'));
+ }
+ XDB::execute("UPDATE photo SET pub = {?} WHERE uid = {?}", $this->values['photo_pub'], S::v('uid'));
}
public function prepare(PlatalPage &$page)
+++ /dev/null
-<?php
-/***************************************************************************
- * Copyright (C) 2003-2007 Polytechnique.org *
- * http://opensource.polytechnique.org/ *
- * *
- * This program is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. *
- * *
- * This program is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
- * GNU General Public License for more details. *
- * *
- * You should have received a copy of the GNU General Public License *
- * along with this program; if not, write to the Free Software *
- * Foundation, Inc., *
- * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
- ***************************************************************************/
-
-// on ramène les données du profil connecté (uid paramètre de session)
-$sql = "SELECT u.nom, u.prenom, u.nom_ini, u.prenom_ini, u.promo, u.promo_sortie, u.nom_usage, u.nationalite,
- q.profile_mobile, q.profile_mobile_pub, q.profile_web, q.profile_web_pub, q.profile_freetext, q.profile_freetext_pub, q.profile_nick,
- q.profile_from_ax, u.matricule_ax,
- a1.aid, a1.type, a2.aid, a2.type
- FROM auth_user_md5 AS u
- INNER JOIN auth_user_quick AS q USING(user_id)
- LEFT JOIN applis_ins AS a1 ON(a1.uid = u.user_id and a1.ordre = 0)
- LEFT JOIN applis_ins AS a2 ON(a2.uid = u.user_id and a2.ordre = 1)
- WHERE u.user_id = {?}";
-
-$result = XDB::query($sql, S::v('uid', -1));
-list($nom, $prenom, $nom_ini, $prenom_ini, $promo, $promo_sortie, $nom_usage, $nationalite,
- $mobile, $mobile_pub, $web, $web_pub, $freetext, $freetext_pub, $nickname,
- $synchro_ax, $matricule_ax,
- $appli_id1,$appli_type1, $appli_id2,$appli_type2) = $result->fetchOneRow();
-
-$result = XDB::query("SELECT pub FROM photo WHERE uid = {?}", S::v('uid', -1));
-$photo_pub = $result->fetchOneCell();
-
-$nom_anc = $nom;
-$prenom_anc = $prenom;
-$nationalite_anc = $nationalite;
-$nickname_anc = $nickname;
-
-replace_ifset($nom,'nom');
-replace_ifset($prenom,'prenom');
-replace_ifset($nationalite,'nationalite');
-replace_ifset($mobile,'mobile');
-replace_ifset($web,"web");
-replace_ifset($freetext,"freetext");
-replace_ifset($appli_id1,"appli_id1");
-replace_ifset($appli_id2,"appli_id2");
-replace_ifset($appli_type1,"appli_type1");
-replace_ifset($appli_type2,"appli_type2");
-replace_ifset($nickname,"nickname");
-
-if(Env::has('modifier') || Env::has('suivant') && $opened_tab == 'general') {
- $mobile_pub = Env::v('mobile_pub');
- $web_pub = Env::has('web_pub')?'public':'private';
- $freetext_pub = Env::has('freetext_pub')?'public':'private';
- $photo_pub = Env::has('photo_pub')?'public':'private';
- $synchro_ax = Env::has("synchro_ax")?1:0;
-}
-
-require_once("xorg.misc.inc.php");
- $nom = strtoupper($nom);
- $nom_comp = replace_accent($nom);
- $nom_anc_comp = replace_accent($nom_anc);
-
- $prenom = make_firstname_case($prenom);
- $prenom_comp = replace_accent($prenom);
- $prenom_anc_comp = replace_accent($prenom_anc);
-
-// Y a-t-il une photo en attente de confirmation ?
-$sql = XDB::query("SELECT COUNT(*) FROM requests WHERE type='photo' AND user_id = {?}", S::v('uid', -1));
-$nouvellephoto=$sql->fetchOneCell();
-
-// vim:set et sws=4 sw=4 sts=4 enc=utf-8:
-?>
}
}
+class ProfileBool extends ProfileNoSave
+{
+ public function value(ProfilePage &$page, $field, $value, &$success)
+ {
+ $success = true;
+ if (is_null($value)) {
+ $value = $page->values[$field];
+ }
+ return $value ? 1 : 0;
+ }
+}
+
abstract class ProfilePage implements PlWizardPage
{
protected $wizard;
protected $pg_template;
protected $settings = array(); // A set ProfileSetting objects
protected $errors = array(); // A set of boolean with the value check errors
+ protected $changed = array(); // A set of boolean indicating wether the value has been changed
public $orig = array();
public $values = array();
protected function saveData()
{
foreach ($this->settings as $field=>&$setting) {
- if (!is_null($setting)) {
+ if (!is_null($setting) && $this->changed[$field]) {
$setting->save($this, $field, $this->values[$field]);
}
}
+
+ // Update the last modification date
+ XDB::execute('REPLACE INTO user_changes
+ SET user_id = {?}', S::v('uid'));
+ global $platal;
+ $log =& $_SESSION['log'];
+ $log->log('profil', $platal->pl_self(1));
}
protected function checkChanges()
$this->values = array();
$this->fetchData();
$this->values = $newvalues;
+ $changes = false;
foreach ($this->settings as $field=>&$setting) {
if ($this->orig[$field] != $this->values[$field]) {
- return true;
+ $this->changed[$field] = true;
+ $changes = true;
+ } else {
+ $this->changed[$field] = false;
}
}
- return false;
+ return $changes;
}
protected function markChange()
+++ /dev/null
-<?php
-/***************************************************************************
- * Copyright (C) 2003-2007 Polytechnique.org *
- * http://opensource.polytechnique.org/ *
- * *
- * This program is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. *
- * *
- * This program is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
- * GNU General Public License for more details. *
- * *
- * You should have received a copy of the GNU General Public License *
- * along with this program; if not, write to the Free Software *
- * Foundation, Inc., *
- * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
- ***************************************************************************/
-
-if ($appli_id1>0)
- XDB::execute("REPLACE INTO applis_ins SET uid= {?}, aid = {?}, type = {?}, ordre = 0", S::v('uid', -1), $appli_id1, $appli_type1);
-else
- XDB::execute("DELETE FROM applis_ins WHERE uid= {?} AND ordre=0", S::v('uid', -1));
-
-if ($appli_id2>0)
- XDB::execute("REPLACE INTO applis_ins SET uid= {?}, aid = {?}, type = {?}, ordre = 1", S::v('uid', -1), $appli_id2, $appli_type2);
-else
- XDB::execute("DELETE FROM applis_ins WHERE uid= {?} AND ordre=1", S::v('uid', -1));
-
-if ($nationalite != $nationalite_anc || $nom != $nom_anc || $prenom != $prenom_anc) {
- $sql = "UPDATE auth_user_md5
- SET nationalite= {?},
- nom = {?},
- prenom = {?} WHERE user_id= {?}";
- XDB::execute($sql, $nationalite, $nom, $prenom, S::v('uid', -1));
-}
-XDB::execute(
- "UPDATE auth_user_quick SET
- profile_nick={?},
- profile_mobile={?}, profile_mobile_pub={?},
- profile_web={?}, profile_web_pub={?},
- profile_freetext={?}, profile_freetext_pub={?},
- profile_from_ax = {?}
- WHERE user_id = {?}",
- $nickname,
- $mobile, $mobile_pub,
- $web, $web_pub,
- $freetext, $freetext_pub,
- $synchro_ax,
- S::v('uid', -1));
-
-if ($nickname != $nickname_anc) {
- require_once('user.func.inc.php');
- user_reindex(S::v('uid', -1));
-}
-XDB::execute("UPDATE photo SET pub = {?} WHERE uid = {?}", $photo_pub, S::v('uid', -1));
-// vim:set et sws=4 sts=4 sw=4 enc=utf-8:
-?>
+++ /dev/null
-<?php
-/***************************************************************************
- * Copyright (C) 2003-2007 Polytechnique.org *
- * http://opensource.polytechnique.org/ *
- * *
- * This program is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. *
- * *
- * This program is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
- * GNU General Public License for more details. *
- * *
- * You should have received a copy of the GNU General Public License *
- * along with this program; if not, write to the Free Software *
- * Foundation, Inc., *
- * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
- ***************************************************************************/
-
-function strmatch_whole_words($nouveau, $ancien) {
- $nouveau = strtoupper($nouveau);
- $ancien = strtoupper($ancien);
- $len_nouveau = strlen($nouveau);
- return (($i = strpos($ancien, $nouveau)) !== false && ($i == 0 || $ancien{$i-1} == ' ' || $ancien{$i-1} == '-') && ($i + $len_nouveau == strlen($ancien) || $ancien{$i + $len_nouveau} == ' ' || $ancien{$i+$len_nouveau} == '-'));
-}
-
-// validite du nom
-if ($nom != $nom_anc &&
- !strmatch_whole_words($nom_comp, $nom_anc_comp) &&
- ($nom_anc_comp == $nom_ini || !strmatch_whole_words($nom_comp, $nom_ini))) {
- $page->trig("Le nom que tu as choisi ($nom) est trop loin de ton nom initial ($nom_ini)".(($nom_ini==$nom_anc_comp)?"":" et de ton nom précédent ($nom_anc)"));
-}
-
-// validite du prenom
-if ($prenom != $prenom_anc &&
- !strmatch_whole_words($prenom_comp, $prenom_anc_comp) &&
- ($prenom_anc_comp == $prenom_ini || !strmatch_whole_words($prenom_comp, $prenom_ini))) {
- $page->trig("Le prénom que tu as choisi ($prenom) est trop loin de ton prénom initial ($prenom_ini)".(($prenom_ini==$prenom_anc_comp)?"":" et de ton prénom précédent ($prenom_anc)"));
-}
-
-// validité du mobile
-if (strlen(strtok($mobile,"<>{}@&#~\/:;?,!§*_`[]|%$^=")) < strlen($mobile)) {
- $page->trig("Le champ 'Téléphone mobile' contient un caractère interdit.");
-}
-
-// correction du champ web si vide
-if ($web=="http://" or $web == '') {
- $web='';
-} elseif (!preg_match("{^(https?|ftp)://[a-zA-Z0-9._%#+/?=&~-]+$}i", $web)) {
- // validité de l'url donnée dans web
- $page->trig("URL incorrecte dans le champ 'Page web perso', une url doit commencer par
- http:// ou https:// ou ftp:// et ne pas contenir de caractères interdits");
-} else {
- $web = str_replace('&', '&', $web);
-}
-
-//validité du champ libre
-if (strlen(strtok($freetext,"<>")) < strlen($freetext))
-{
- $page->trig("Le champ 'Complément libre' contient un caractère interdit.");
-}
-
-// vim:set et sws=4 sts=4 sw=4 enc=utf-8:
-?>
<span class="comm">(4ème année de l'X)</span>
</td>
<td class="cold">
- <select name="appli_id1" onchange="fillType(this.form.appli_type1, this.selectedIndex-1);">
- {applis_options selected=$appli_id1}
+ <select name="appli1[id]" onchange="fillType(this.form['appli1[type]'], this.selectedIndex-1);">
+ {applis_options selected=$appli1.id}
</select>
<br />
- <select name="appli_type1">
+ <select name="appli1[type]">
<option value=""></option>
</select>
<script type="text/javascript">
<!--
- fillType(document.forms.prof_annu.appli_type1, document.forms.prof_annu.appli_id1.selectedIndex-1);
- selectType(document.forms.prof_annu.appli_type1, '{$appli_type1}');
+ fillType(document.forms.prof_annu['appli1[type]'], document.forms.prof_annu['appli1[id]'].selectedIndex-1);
+ selectType(document.forms.prof_annu['appli1[type]'], '{$appli1.type}');
//-->
</script>
</td>
<span class="titre">Post-application</span>
</td>
<td class="dcold">
- <select name="appli_id2" onchange="fillType(this.form.appli_type2, this.selectedIndex-1);">
- {applis_options selected=$appli_id2}
+ <select name="appli2[id]" onchange="fillType(this.form['appli[type]'], this.selectedIndex-1);">
+ {applis_options selected=$appli2.id}
</select>
<br />
- <select name="appli_type2">
+ <select name="appli2[type]">
<option value=""></option>
</select>
<script type="text/javascript">
<!--
- fillType(document.forms.prof_annu.appli_type2, document.forms.prof_annu.appli_id2.selectedIndex-1);
- selectType(document.forms.prof_annu.appli_type2, '{$appli_type2}');
+ fillType(document.forms.prof_annu['appli2[type]'], document.forms.prof_annu['appli2[id]'].selectedIndex-1);
+ selectType(document.forms.prof_annu['appli2[type]'], '{$appli2.type}');
//-->
</script>
</td>