Merge commit 'origin/master' into fusionax
[platal.git] / include / user.func.inc.php
index 38b17ad..7225d82 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /***************************************************************************
- *  Copyright (C) 2003-2008 Polytechnique.org                              *
+ *  Copyright (C) 2003-2009 Polytechnique.org                              *
  *  http://opensource.polytechnique.org/                                   *
  *                                                                         *
  *  This program is free software; you can redistribute it and/or modify   *
@@ -257,7 +257,7 @@ function get_user_details_adr($uid, $view = 'private') {
 
 function &get_user_details($login, $from_uid = '', $view = 'private')
 {
-    $reqsql = "SELECT  u.user_id, d.promo_display, u.prenom, u.nom, u.nom_usage, u.date, u.cv,
+    $reqsql = "SELECT  u.user_id, d.promo, u.prenom, u.nom, u.nom_usage, u.date, u.cv,
                        u.perms IN ('admin','user','disabled') AS inscrit,  FIND_IN_SET('femme', u.flags) AS sexe, u.deces != 0 AS dcd, u.deces,
                        q.profile_nick AS nickname, q.profile_from_ax, q.profile_freetext AS freetext,
                        q.profile_freetext_pub AS freetext_pub,
@@ -286,7 +286,7 @@ function &get_user_details($login, $from_uid = '', $view = 'private')
             LEFT JOIN  profile_mentor        AS m   ON (m.uid = u.user_id)
             LEFT JOIN  emails                AS e   ON (e.uid = u.user_id AND e.flags='active')
            INNER JOIN  profile_names_display AS nd  ON (nd.user_id = u.user_id)
-           INNER JOIN  profile_display       AS d   ON (d.uid = u.user_id)
+           INNER JOIN  profile_display       AS d   ON (d.pid = u.user_id)
                 WHERE  a.alias = {?}
              GROUP BY  u.user_id";
     $res  = XDB::query($reqsql, $from_uid, $login);
@@ -357,7 +357,7 @@ function &get_user_details($login, $from_uid = '', $view = 'private')
                       LEFT JOIN  profile_education_enum        AS en ON (en.id = ed.eduid)
                       LEFT JOIN  profile_education_degree_enum AS d  ON (d.id  = ed.degreeid)
                       LEFT JOIN  profile_education_field_enum  AS f  ON (f.id  = ed.fieldid)
-                          WHERE  uid={?}
+                          WHERE  uid = {?} AND NOT FIND_IN_SET('primary', flags)
                        ORDER BY  ed.grad_year", $uid);
 
     if (list($name, $url, $degree, $grad_year, $field, $program) = $res->next()) {
@@ -591,18 +591,17 @@ function remove_user_pro($uid, $entrid) {
 // }}}
 // {{{ function set_user_details_addresses()
 function set_user_details_addresses($uid, $adrs) {
-    $res = XDB::query("SELECT adrid FROM adresses WHERE uid = {?} AND adrid >= 1 ORDER BY adrid", $uid);
-    $adrids = $res->fetchColumn();
+    $req = XDB::query('SELECT MAX(adrid) + 1
+                         FROM adresses
+                        WHERE uid = {?}', $uid);
+    $adrid = $req->fetchOneCell();
+    if (is_null($adrid)) {
+        $adrid = 0;
+    }
     foreach ($adrs as $adr) {
-        if (isset($adr['adrid']) && isset($adr['remove']) && $adr['remove']) {
-            remove_user_address($uid, $adr['adrid']);
-            if (isset($adrids[$adr['adrid']])) unset($adrids[$adr['adrid']]);
-        } else if (isset($adr['adrid'])) {
-            update_user_address($uid, $adr['adrid'], $adr);
-        } else {
-            for ($adrid = 1; isset($adrids[$adrid-1]) && ($adrids[$adrid-1] == $adrid); $adrid++);
+        if (!@$adr['remove']) {
             add_user_address($uid, $adrid, $adr);
-            $adrids[$adrid-1] = $adrid;
+            ++$adrid;
         }
     }
     require_once 'geoloc.inc.php';
@@ -613,17 +612,17 @@ function set_user_details_addresses($uid, $adrs) {
 
 function set_user_details_pro($uid, $pros)
 {
-    $res = XDB::query("SELECT entrid FROM entreprises WHERE uid = {?} ORDER BY entrid", $uid);
-    $entrids = $res->fetchColumn();
+    $req = XDB::query('SELECT MAX(entrid) + 1
+                         FROM entreprises
+                        WHERE uid = {?}', $uid);
+    $entrid = $req->fetchOneCell();
+    if (is_null($entrid)) {
+        $entrid = 0;
+    }
     foreach ($pros as $pro) {
-        if (isset($pro['entrid']) && isset($pro['remove']) && $pro['remove']) {
-            remove_user_pro($uid, $pro['entrid']);
-            if (isset($entrids[$pro['entrid']])) unset($entrids[$pro['entrid']]);
-        } else if (isset($pro['entrid'])) {
-            update_user_pro($uid, $pro['entrid'], $pro);
-        } else {
-            for ($entrid = 0; isset($entrids[$entrid]) && ($entrids[$entrid] == $entrid); $entrid++);
+        if (!@$pro['remove']) {
             add_user_pro($uid, $entrid, $pro);
+            ++$entrid;
         }
     }
 }