Merge branch 'platal-0.9.17'
[platal.git] / modules / profile / general.inc.php
index 3cd19e4..8227f36 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /***************************************************************************
- *  Copyright (C) 2003-2007 Polytechnique.org                              *
+ *  Copyright (C) 2003-2008 Polytechnique.org                              *
  *  http://opensource.polytechnique.org/                                   *
  *                                                                         *
  *  This program is free software; you can redistribute it and/or modify   *
@@ -49,11 +49,11 @@ class ProfileNom implements ProfileSetting
         $new = $this->prepareField($value);
         $newLen = strlen($new);
         $success = $this->matchWord($old, $new, $newLen)
-                || $this->matchWord($ini, $new, $newLen);
+                || $this->matchWord($ini, $new, $newLen)
+                || ($field == 'nom' && $new == 'DE ' . $old);
         if (!$success) {
-            global $page;
-            $page->trig("Le $field que tu as choisi ($value) est trop loin de ton $field initial ($init)"
-                       . (($init == $current)? "" : " et de ton prénom précédent ($current)"));
+            Platal::page()->trigError("Le $field que tu as choisi ($value) est trop loin de ton $field initial ($init)"
+                                    . (($init == $current)? "" : " et de ton prénom précédent ($current)"));
         }
         return $success ? $value : $current;
     }
@@ -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']
@@ -115,17 +116,14 @@ class ProfileGeneral extends ProfilePage
         $this->settings['appli1']
                                   = $this->settings['appli2']
                                   = new ProfileAppli();
+        $this->watched= array('nom' => true, 'freetext' => true, 'mobile' => true, 'web' => true,
+                       'appli1' => true, 'appli2' => true, 'nationalite' => true, 'nick' => true);
     }
 
-    protected function fetchData()
+    protected function _fetchData()
     {
-        if (count($this->orig) > 0) {
-            $this->values = $this->orig;
-            return;
-        }
-
         // 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,
@@ -160,17 +158,18 @@ class ProfileGeneral extends ProfilePage
                             WHERE  type='photo' AND user_id = {?}",
                           S::v('uid'));
         $this->values['nouvellephoto'] = $res->fetchOneCell();
-        parent::fetchData();
     }
 
-    protected function saveData()
+    protected function _saveData()
     {
-        parent::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']
@@ -197,9 +196,8 @@ class ProfileGeneral extends ProfilePage
         }
     }
 
-    public function prepare(PlatalPage &$page, $id)
+    public function _prepare(PlPage &$page, $id)
     {
-        parent::prepare($page, $id);
         require_once "applis.func.inc.php";
     }
 }