From 7bff4cb031e50e345d346d2a333b5ac7a9d434fd Mon Sep 17 00:00:00 2001 From: Florent Bruneau Date: Sun, 23 Sep 2007 15:01:00 +0200 Subject: [PATCH] Restore the old birthday check on the profile/edit page Signed-off-by: Florent Bruneau --- modules/profile.php | 15 +++++++++++---- modules/profile/general.inc.php | 12 ++++++++---- modules/profile/page.inc.php | 27 +++++++++++++++++++++++++++ templates/profile/general.tpl | 4 ++++ 4 files changed, 50 insertions(+), 8 deletions(-) diff --git a/modules/profile.php b/modules/profile.php index 0559e6c..f33824c 100644 --- a/modules/profile.php +++ b/modules/profile.php @@ -326,9 +326,7 @@ class ProfileModule extends PLModule $page->trig('Ton profil a été synchronisé avec celui du site polytechniciens.com'); } - // Misc checks - // TODO: Block if birth date is missing ? - + // Build the page $page->addJsLink('ajax.js'); $page->addJsLink('profile.js'); $page->addJsLink('applis.js'); @@ -344,7 +342,16 @@ class ProfileModule extends PLModule $wiz->addPage('ProfileMentor', 'Mentoring', 'mentor'); $wiz->apply($page, 'profile/edit', $opened_tab, $mode); - $page->assign('xorg_title', 'Polytechnique.org - Mon Profil'); + // Misc checks + $res = XDB::query("SELECT user_id + FROM auth_user_md5 + WHERE user_id = {?} AND naissance = '0000-00-00'", S::i('uid')); + if ($res->numRows()) { + $page->trig("Ta date de naissance n'est pas renseignée, ce qui t'empêcheras de réaliser" + . " la procédure de récupération de mot de passe si un jour tu le perdais"); + } + + $page->assign('xorg_title', 'Polytechnique.org - Mon Profil'); } function handler_applis_js(&$page) diff --git a/modules/profile/general.inc.php b/modules/profile/general.inc.php index 9c2590a..7af0a53 100644 --- a/modules/profile/general.inc.php +++ b/modules/profile/general.inc.php @@ -99,6 +99,7 @@ class ProfileGeneral extends ProfilePage parent::__construct($wiz); $this->settings['nom'] = $this->settings['prenom'] = new ProfileNom(); + $this->settings['naissance'] = new ProfileDate(); $this->settings['mobile_pub'] = $this->settings['web_pub'] = $this->settings['freetext_pub'] @@ -120,7 +121,7 @@ class ProfileGeneral extends ProfilePage protected function _fetchData() { // Checkout all data... - $res = XDB::query("SELECT u.promo, u.promo_sortie, u.nom_usage, u.nationalite, + $res = XDB::query("SELECT u.promo, u.promo_sortie, u.nom_usage, u.nationalite, u.naissance, 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, @@ -159,11 +160,14 @@ class ProfileGeneral extends ProfilePage protected function _saveData() { - if ($this->changed['nationalite'] || $this->changed['nom'] || $this->changed['prenom']) { + if ($this->changed['nationalite'] || $this->changed['nom'] || $this->changed['prenom'] + || $this->changed['naissance']) { XDB::execute("UPDATE auth_user_md5 - SET nationalite = {?}, nom={?}, prenom={?} + SET nationalite = {?}, nom={?}, prenom={?}, naissance={?} WHERE user_id = {?}", - $this->values['nationalite'], $this->values['nom'], $this->values['prenom'], S::v('uid')); + $this->values['nationalite'], $this->values['nom'], $this->values['prenom'], + preg_replace('@(\d{2})/(\d{2})/(\d{4})@', '\3-\2-\1', $this->values['naissance']), + S::v('uid')); } if ($this->changed['nick'] || $this->changed['mobile'] || $this->changed['mobile_pub'] || $this->changed['web'] || $this->changed['web_pub'] || $this->changed['freetext'] diff --git a/modules/profile/page.inc.php b/modules/profile/page.inc.php index 4f44024..ec0ed62 100644 --- a/modules/profile/page.inc.php +++ b/modules/profile/page.inc.php @@ -125,6 +125,33 @@ class ProfileBool extends ProfileNoSave } } +class ProfileDate extends ProfileNoSave +{ + public function value(ProfilePage &$page, $field, $value, &$success) + { + $success = true; + if (is_null($value)) { + $value = preg_replace('/(\d{4})-(\d{2})-(\d{2})/', '\3/\2/\1', @$page->values[$field]); + } else { + $success = preg_match('@(\d{2})/(\d{2})/(\d{4})@', $value, $matches); + if (!$success) { + global $page; + $page->trig("Les dates doivent être au format jj/mm/aaaa"); + } else { + $day = (int)$matches[1]; + $month = (int)$matches[2]; + $year = (int)$matches[3]; + $success = ($day > 0 && $day <= 31) && ($month > 0 && $month <= 12) && ($year > 1900 && $year <= 2020); + if (!$success) { + global $page; + $page->trig("La date n'a pas une valeur valide"); + } + } + } + return $value; + } +} + abstract class ProfileGeoloc implements ProfileSetting { protected function geolocAddress(array &$address, &$success) diff --git a/templates/profile/general.tpl b/templates/profile/general.tpl index e5b5a5d..a6abc26 100644 --- a/templates/profile/general.tpl +++ b/templates/profile/general.tpl @@ -79,6 +79,10 @@ + Date de naissance + + + Nationalité -- 2.1.4