Cleans ProfilePhones::value() to avoid a false notification when the profile is valid...
[platal.git] / modules / profile / general.inc.php
index 42dc5cd..5d4135e 100644 (file)
@@ -93,7 +93,7 @@ class ProfileAppli implements ProfileSetting
 
     public function save(ProfilePage &$page, $field, $new_value)
     {
-        $index = ($field == 'appli1' ? 0 : 1);
+        $index = ($field == 'edu_0' ? 0 : 1);
         if ($new_value['id'] > 0) {
             XDB::execute("REPLACE INTO  applis_ins
                                    SET  uid = {?}, aid = {?}, type = {?}, ordre = {?}",
@@ -116,19 +116,18 @@ class ProfileEmailDirectory implements ProfileSetting
 
     public function value(ProfilePage &$page, $field, $value, &$success)
     {
-        $p = $page;
-        global $page;
+        $p = Platal::page();
 
         $success = true;
         if (!is_null($value)) {
             $email_stripped = strtolower(trim($value));
-            if ((!isvalid_email($email_stripped)) && ($email_stripped) && ($p->values['email_directory'] == "new@new.new")) {
-                $page->assign('email_error', '1');
-                $page->assign('email_directory_error', $email_stripped);
-                $page->trigError('Adresse Email invalide');
+            if ((!isvalid_email($email_stripped)) && ($email_stripped) && ($page->values['email_directory'] == "new@example.org")) {
+                $p->assign('email_error', '1');
+                $p->assign('email_directory_error', $email_stripped);
+                $p->trigError('Adresse Email invalide');
                 $success = false;
             } else {
-                $page->assign('email_error', '0');
+                $p->assign('email_error', '0');
             }
         }
         return $value;
@@ -235,6 +234,8 @@ class ProfileGeneral extends ProfilePage
                                   = new ProfilePub();
         $this->settings['freetext']
                                   = $this->settings['nationalite']
+                                  = $this->settings['nationalite2']
+                                  = $this->settings['nationalite3']
                                   = $this->settings['nick']
                                   = $this->settings['yourself']
                                   = $this->settings['display_name']
@@ -249,24 +250,26 @@ class ProfileGeneral extends ProfilePage
                                   = new ProfileEmailDirectory();
         $this->settings['networking'] = new ProfileNetworking();
         $this->settings['tels'] = new ProfilePhones('user', 0);
-        $this->settings['appli1']
-                                  = $this->settings['appli2']
+        $this->settings['edu_0']
+                                  = $this->settings['edu_1']
                                   = new ProfileAppli();
         $this->watched= array('nom' => true, 'freetext' => true, 'tels' => true,
-                              'networking' => true, 'appli1' => true, 'appli2' => true,
-                              'nationalite' => true, 'nick' => true);
+                              'networking' => true, 'edu_0' => true, 'edu_1' => true,
+                              'nationalite' => true, 'nationalite2' => true,
+                              'nationalite3' => true, 'nick' => true);
     }
 
     protected function _fetchData()
     {
         // Checkout all data...
-        $res = XDB::query("SELECT  u.promo, u.promo_sortie, u.nom_usage, u.nationalite, u.naissance,
+        $res = XDB::query("SELECT  u.promo, u.promo_sortie, u.nom_usage, u.nationalite,
+                                   u.nationalite2, u.nationalite3, u.naissance,
                                    t.display_tel as mobile, t.pub as mobile_pub,
                                    d.email_directory as email_directory,
                                    q.profile_freetext as freetext, q.profile_freetext_pub as freetext_pub,
                                    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,
+                                   IF(a1.aid IS NULL, -1, a1.aid) as edu_id1, a1.type as edu_type1,
+                                   IF(a2.aid IS NULL, -1, a2.aid) as edu_id2, a2.type as edu_type2,
                                    n.yourself, n.display AS display_name, n.sort AS sort_name,
                                    n.tooltip AS tooltip_name
                              FROM  auth_user_md5         AS u
@@ -280,14 +283,14 @@ class ProfileGeneral extends ProfilePage
         $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']);
+        $this->values['edu_0'] = array('id'    => $this->values['edu_id1'],
+                                       'type'  => $this->values['edu_type1']);
+        unset($this->values['edu_id1']);
+        unset($this->values['edu_type1']);
+        $this->values['edu_1'] = array('id'    => $this->values['edu_id2'],
+                                       'type'  => $this->values['edu_type2']);
+        unset($this->values['edu_id2']);
+        unset($this->values['edu_type2']);
 
         // Retreive photo informations
         $res = XDB::query("SELECT  pub
@@ -320,12 +323,26 @@ class ProfileGeneral extends ProfilePage
 
     protected function _saveData()
     {
-        if ($this->changed['nationalite'] || $this->changed['nom'] || $this->changed['prenom']
-            || $this->changed['naissance']) {
+        if ($this->changed['nationalite'] || $this->changed['nationalite2'] || $this->changed['nationalite3']
+            || $this->changed['nom'] || $this->changed['prenom'] || $this->changed['naissance']) {
+            if ($this->values['nationalite3'] == "") {
+                $this->values['nationalite3'] = NULL;
+            }
+            if ($this->values['nationalite2'] == "") {
+                $this->values['nationalite2'] = $this->values['nationalite3'];
+                $this->values['nationalite3'] = NULL;
+            }
+            if ($this->values['nationalite'] == "") {
+                $this->values['nationalite']  = $this->values['nationalite2'];
+                $this->values['nationalite2'] = $this->values['nationalite3'];
+                $this->values['nationalite3'] = NULL;
+            }
+
            XDB::execute("UPDATE  auth_user_md5
-                            SET  nationalite = {?}, nom={?}, prenom={?}, naissance={?}
+                            SET  nationalite = {?}, nationalite2 = {?}, nationalite3 = {?}, nom={?}, prenom={?}, naissance={?}
                           WHERE  user_id = {?}",
-                         $this->values['nationalite'], $this->values['nom'], $this->values['prenom'],
+                         $this->values['nationalite'], $this->values['nationalite2'], $this->values['nationalite3'],
+                         $this->values['nom'], $this->values['prenom'],
                          preg_replace('@(\d{2})/(\d{2})/(\d{4})@', '\3-\2-\1', $this->values['naissance']),
                          S::v('uid'));
         }
@@ -340,8 +357,11 @@ class ProfileGeneral extends ProfilePage
                          $this->values['synchro_ax'], S::v('uid'));
         }
         if ($this->changed['email_directory']) {
-            $new_email = ($this->values['email_directory'] == "new@new.new") ?
+            $new_email = ($this->values['email_directory'] == "new@example.org") ?
                 $this->values['email_directory_new'] : $this->values['email_directory'];
+            if ($new_email == "") {
+                $new_email = NULL;
+            }
             XDB::execute("REPLACE INTO  profile_directory (uid, email_directory)
                                 VALUES  ({?}, {?})",
                          S::v('uid'), $new_email);