Restore the old birthday check on the profile/edit page
authorFlorent Bruneau <florent.bruneau@polytechnique.org>
Sun, 23 Sep 2007 13:01:00 +0000 (15:01 +0200)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Sun, 23 Sep 2007 13:01:00 +0000 (15:01 +0200)
Signed-off-by: Florent Bruneau <florent.bruneau@polytechnique.org>
modules/profile.php
modules/profile/general.inc.php
modules/profile/page.inc.php
templates/profile/general.tpl

index 0559e6c..f33824c 100644 (file)
@@ -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)
index 9c2590a..7af0a53 100644 (file)
@@ -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']
index 4f44024..ec0ed62 100644 (file)
@@ -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)
index e5b5a5d..a6abc26 100644 (file)
     </td>
   </tr>
   <tr>
+    <td class="titre">Date de naissance</td>
+    <td><input type="text" {if $errors.naissance}class="error"{/if} name="naissance" value="{$naissance}" /></td>
+  </tr>
+  <tr>
     <td class="colg">
       <span class="titre">Nationalité</span>
     </td>