From 576777d76fe12b6e91131ae9e43716d3d3938746 Mon Sep 17 00:00:00 2001 From: Florent Bruneau Date: Sun, 26 Aug 2007 19:17:55 +0200 Subject: [PATCH] The general page works! Repair the "last modification date" update and the action logging Signed-off-by: Florent Bruneau --- modules/profile/assign_general.inc.php | 52 -------------------- modules/profile/general.inc.php | 86 ++++++++++++++++++++++++++++++++-- modules/profile/get_general.inc.php | 81 -------------------------------- modules/profile/page.inc.php | 30 ++++++++++-- modules/profile/update_general.inc.php | 60 ------------------------ modules/profile/verif_general.inc.php | 66 -------------------------- templates/profile/general.tpl | 20 ++++---- 7 files changed, 118 insertions(+), 277 deletions(-) delete mode 100644 modules/profile/assign_general.inc.php delete mode 100644 modules/profile/get_general.inc.php delete mode 100644 modules/profile/update_general.inc.php delete mode 100644 modules/profile/verif_general.inc.php diff --git a/modules/profile/assign_general.inc.php b/modules/profile/assign_general.inc.php deleted file mode 100644 index 033bc1c..0000000 --- a/modules/profile/assign_general.inc.php +++ /dev/null @@ -1,52 +0,0 @@ -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: -?> diff --git a/modules/profile/general.inc.php b/modules/profile/general.inc.php index 115636c..9781828 100644 --- a/modules/profile/general.inc.php +++ b/modules/profile/general.inc.php @@ -64,6 +64,32 @@ class ProfileNom implements ProfileSetting } } +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'; @@ -76,14 +102,19 @@ class ProfileGeneral extends ProfilePage $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() @@ -92,11 +123,13 @@ class ProfileGeneral extends ProfilePage $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 @@ -105,14 +138,57 @@ class ProfileGeneral extends ProfilePage 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) diff --git a/modules/profile/get_general.inc.php b/modules/profile/get_general.inc.php deleted file mode 100644 index d0fa5d6..0000000 --- a/modules/profile/get_general.inc.php +++ /dev/null @@ -1,81 +0,0 @@ -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: -?> diff --git a/modules/profile/page.inc.php b/modules/profile/page.inc.php index aef1c62..d014989 100644 --- a/modules/profile/page.inc.php +++ b/modules/profile/page.inc.php @@ -93,12 +93,25 @@ class ProfilePub extends ProfileNoSave } } +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(); @@ -129,10 +142,17 @@ abstract class ProfilePage implements PlWizardPage 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() @@ -141,12 +161,16 @@ abstract class ProfilePage implements PlWizardPage $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() diff --git a/modules/profile/update_general.inc.php b/modules/profile/update_general.inc.php deleted file mode 100644 index ccdaeb5..0000000 --- a/modules/profile/update_general.inc.php +++ /dev/null @@ -1,60 +0,0 @@ -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: -?> diff --git a/modules/profile/verif_general.inc.php b/modules/profile/verif_general.inc.php deleted file mode 100644 index 564f275..0000000 --- a/modules/profile/verif_general.inc.php +++ /dev/null @@ -1,66 +0,0 @@ -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: -?> diff --git a/templates/profile/general.tpl b/templates/profile/general.tpl index 38f7e43..50d3653 100644 --- a/templates/profile/general.tpl +++ b/templates/profile/general.tpl @@ -101,17 +101,17 @@ (4ème année de l'X) - + {applis_options selected=$appli1.id}
- @@ -121,17 +121,17 @@ Post-application - + {applis_options selected=$appli2.id}
- -- 2.1.4