Merge commit 'origin/master' into fusionax
[platal.git] / modules / profile / general.inc.php
index 794f746..ecb18b3 100644 (file)
@@ -82,15 +82,15 @@ class ProfileSearchName implements ProfileSetting
 
 class ProfileEdu implements ProfileSetting
 {
-    public function __construct()
-    {
-    }
+    public function __construct(){}
 
     static function sortByGradYear($line1, $line2) {
-        if ($line1['grad_year'] == $line2['grad_year']) {
+        $a = (int) $line1['grad_year'];
+        $b = (int) $line2['grad_year'];
+        if ($a == $b) {
             return 0;
         }
-        return ($line1['grad_year'] < $line2['grad_year']) ? -1 : 1;
+        return ($a < $b) ? -1 : 1;
     }
 
     public function value(ProfilePage &$page, $field, $value, &$success)
@@ -100,7 +100,7 @@ class ProfileEdu implements ProfileSetting
             $value = array();
             $res = XDB::iterator("SELECT  eduid, degreeid, fieldid, grad_year, program
                                     FROM  profile_education
-                                   WHERE  uid = {?}
+                                   WHERE  uid = {?} AND !FIND_IN_SET('primary', flags)
                                 ORDER BY  id",
                                  S::v('uid'));
             while($edu = $res->next()) {
@@ -128,7 +128,7 @@ class ProfileEdu implements ProfileSetting
     public function save(ProfilePage &$page, $field, $value)
     {
         XDB::execute("DELETE FROM  profile_education
-                            WHERE  uid = {?}",
+                            WHERE  uid = {?} AND !FIND_IN_SET('primary', flags)",
                      S::i('uid'));
         foreach ($value as $eduid=>&$edu) {
             if ($edu['eduid'] != '') {
@@ -140,14 +140,12 @@ class ProfileEdu implements ProfileSetting
             }
         }
     }
-
 }
 
 class ProfileEmailDirectory implements ProfileSetting
 {
-    public function __construct()
-    {
-    }
+    public function __construct(){}
+    public function save(ProfilePage &$page, $field, $value){}
 
     public function value(ProfilePage &$page, $field, $value, &$success)
     {
@@ -167,10 +165,6 @@ class ProfileEmailDirectory implements ProfileSetting
         }
         return $value;
     }
-
-    public function save(ProfilePage &$page, $field, $value)
-    {
-    }
 }
 
 class ProfileNetworking implements ProfileSetting
@@ -276,6 +270,7 @@ class ProfileGeneral extends ProfilePage
                                   = $this->settings['display_name']
                                   = $this->settings['sort_name']
                                   = $this->settings['tooltip_name']
+                                  = $this->settings['promo_display']
                                   = null;
         $this->settings['synchro_ax']
                                   = new ProfileBool();
@@ -295,8 +290,8 @@ class ProfileGeneral extends ProfilePage
     protected function _fetchData()
     {
         // Checkout all data...
-        $res = XDB::query("SELECT  u.promo, u.promo_sortie, u.nom_usage, u.nationalite,
-                                   u.nationalite2, u.nationalite3, u.naissance,
+        $res = XDB::query("SELECT  p.promo_display, e.entry_year AS entry_year, e.grad_year AS grad_year,
+                                   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,
@@ -304,10 +299,12 @@ class ProfileGeneral extends ProfilePage
                                    n.yourself, n.display AS display_name, n.sort AS sort_name,
                                    n.tooltip AS tooltip_name
                              FROM  auth_user_md5         AS u
-                       INNER JOIN  auth_user_quick       AS q  ON(u.user_id = q.user_id)
-                       INNER JOIN  profile_names_display AS n  ON(n.user_id = u.user_id)
-                        LEFT JOIN  profile_phones        AS t  ON(u.user_id = t.uid AND link_type = 'user')
-                        LEFT JOIN  profile_directory     AS d  ON(d.uid = u.user_id)
+                       INNER JOIN  auth_user_quick       AS q ON (u.user_id = q.user_id)
+                       INNER JOIN  profile_names_display AS n ON (n.user_id = u.user_id)
+                       INNER JOIN  profile_display       AS p ON (p.uid = u.user_id)
+                       INNER JOIN  profile_education     AS e ON (e.uid = u.user_id AND FIND_IN_SET('primary', e.flags))
+                        LEFT JOIN  profile_phones        AS t ON (u.user_id = t.uid AND link_type = 'user')
+                        LEFT JOIN  profile_directory     AS d ON (d.uid = u.user_id)
                             WHERE  u.user_id = {?}", S::v('uid', -1));
         $this->values = $res->fetchOneAssoc();
 
@@ -331,13 +328,12 @@ class ProfileGeneral extends ProfilePage
                             ORDER BY  sn.name_type, search_score, search_name",
                           S::v('uid'));
 
-        // Retreive phones
-        $res = XDB::iterator("SELECT t.display_tel AS tel, t.tel_type AS type, t.pub, t.comment
-                                FROM profile_phones AS t
-                               WHERE t.uid = {?} AND t.link_type = 'user'
-                            ORDER BY t.tel_id",
-                             S::v('uid'));
-        $this->values['tels'] = $res->fetchAllAssoc();
+        // Proposes choice for promo_display
+        if ($this->values['entry_year'] != $this->values['grad_year'] - 3) {
+            for ($i = $this->values['entry_year']; $i < $this->values['grad_year'] - 2; $i++) {
+                $this->values['promo_choice'][] = "X" . $i;
+            }
+        }
     }
 
     protected function _saveData()
@@ -357,13 +353,13 @@ class ProfileGeneral extends ProfilePage
                 $this->values['nationalite3'] = NULL;
             }
 
-           XDB::execute("UPDATE  auth_user_md5
-                            SET  nationalite = {?}, nationalite2 = {?}, nationalite3 = {?}, nom={?}, prenom={?}, naissance={?}
-                          WHERE  user_id = {?}",
-                         $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'));
+            XDB::execute("UPDATE  auth_user_md5
+                             SET  nationalite = {?}, nationalite2 = {?}, nationalite3 = {?}, nom={?}, prenom={?}, naissance={?}
+                           WHERE  user_id = {?}",
+                          $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'));
         }
         if ($this->changed['nick'] || $this->changed['freetext'] || $this->changed['freetext_pub'] || $this->changed['synchro_ax']) {
             XDB::execute("UPDATE  auth_user_quick
@@ -397,17 +393,23 @@ class ProfileGeneral extends ProfilePage
         }
         if ($this->changed['yourself'] || $this->changed['sort_name'] ||
             $this-> changed['display_name'] || $this->changed['tooltip_name']) {
-          XDB::execute("UPDATE  profile_names_display AS n
-                           SET  n.yourself = {?},
-                                n.sort = {?}, ". // SET
-                               "n.display = {?}, ". // SET
-                               "n.tooltip = {?} ". // SET
-                        "WHERE  n.user_id = {?}",
-                       $this->values['yourself'],
-                       $this->values['sort_name'],
-                       $this->values['display_name'],
-                       $this->values['tooltip_name'],
-                        S::v('uid'));
+            XDB::execute("UPDATE  profile_names_display AS n
+                             SET  n.yourself = {?},
+                                  n.sort = {?}, ". // SET
+                                 "n.display = {?}, ". // SET
+                                 "n.tooltip = {?} ". // SET
+                          "WHERE  n.user_id = {?}",
+                         $this->values['yourself'],
+                         $this->values['sort_name'],
+                         $this->values['display_name'],
+                         $this->values['tooltip_name'],
+                         S::v('uid'));
+        }
+        if ($this->changed['promo_display']) {
+            XDB::execute("UPDATE  profile_display
+                             SET  promo_display = {?}
+                           WHERE  uid = {?}",
+                         $this->values['promo_display'], S::v('uid'));
         }
     }