Merge commit 'origin/master' into fusionax
[platal.git] / include / user.func.inc.php
index bdf4602..3e57923 100644 (file)
@@ -26,7 +26,7 @@
  */
 function user_clear_all_subs($user_id, $really_del=true)
 {
-    // keep datas in : aliases, adresses, tels, applis_ins, binets_ins, contacts, groupesx_ins, homonymes, identification_ax, photo
+    // keep datas in : aliases, adresses, tels, profile_education, binets_ins, contacts, groupesx_ins, homonymes, identification_ax, photo
     // delete in     : auth_user_md5, auth_user_quick, competences_ins, emails, entreprises, langues_ins, mentor,
     //                 mentor_pays, mentor_secteurs, newsletter_ins, perte_pass, requests, user_changes, virtual_redirect, watch_sub
     // + delete maillists
@@ -48,7 +48,8 @@ function user_clear_all_subs($user_id, $really_del=true)
         $tables_to_clear['contact'] = array('contacts');
         XDB::execute("UPDATE auth_user_md5
                          SET date_ins = 0, promo_sortie = 0, nom_usage = '',  password = '', perms = 'pending',
-                             nationalite = '', cv = '', section = 0, date = 0, smtppass = '', mail_storage = ''
+                             nationalite = '', nationalite2 = '', nationalite3 = '', cv = '', section = 0,
+                             date = 0, smtppass = '', mail_storage = ''
                        WHERE user_id = {?}", $uid);
         XDB::execute("DELETE virtual.* FROM virtual INNER JOIN virtual_redirect AS r USING(vid) WHERE redirect = {?}",
                      $alias.'@'.$globals->mail->domain);
@@ -87,8 +88,7 @@ function user_clear_all_subs($user_id, $really_del=true)
 // Defaut callback to call when a login is not found
 function _default_user_callback($login)
 {
-    global $page;
-    $page->trigError("Il n'y a pas d'utilisateur avec l'identifiant : $login");
+    Platal::page()->trigError("Il n'y a pas d'utilisateur avec l'identifiant : $login");
     return;
 }
 
@@ -99,7 +99,7 @@ function _silent_user_callback($login)
 
 function get_user_login($data, $get_forlife = false, $callback = '_default_user_callback')
 {
-    global $globals, $page;
+    global $globals;
 
     if (is_numeric($data)) {
         $res = XDB::query("SELECT alias FROM aliases WHERE type='a_vie' AND id={?}", $data);
@@ -171,7 +171,7 @@ function get_user_login($data, $get_forlife = false, $callback = '_default_user_
             default:
                 if (S::has_perms()) {
                     $aliases = $res->fetchColumn();
-                    $page->trigError("Il y a $i utilisateurs avec cette adresse mail : ".join(', ', $aliases));
+                    Platal::page()->trigError("Il y a $i utilisateurs avec cette adresse mail : ".join(', ', $aliases));
                 } else {
                     $res->free();
                 }
@@ -198,15 +198,27 @@ function get_users_forlife_list($members, $strict = false, $callback = '_default
         if (strlen(trim($members)) == 0) {
             return null;
         }
-        $members = explode(' ', $members);
+        $members = split("[; ,\r\n\|]+", $members);
     }
     if ($members) {
         $list = array();
         foreach ($members as $i => $alias) {
+            $alias = trim($alias);
+            if (empty($alias)) {
+                continue;
+            }
             if (($login = get_user_forlife($alias, $callback)) !== false) {
                 $list[$i] = $login;
-            } else if(!$strict) {
+            } else if (!$strict) {
                 $list[$i] = $alias;
+            } else {
+                global $globals;
+                if (strpos($alias, '@') !== false) {
+                    list($user, $dom) = explode('@', $alias);
+                    if ($dom != $globals->mail->domain && $dom != $globals->mail->domain2) {
+                        $list[$i] = $alias;
+                    }
+                }
             }
         }
         return $list;
@@ -247,7 +259,7 @@ function get_not_registered_user($login, $iterator = false)
     }
     $sql = "SELECT  user_id, nom, prenom, promo
               FROM  auth_user_md5
-             WHERE  $where
+             WHERE  $where AND perms = 'pending'
           ORDER BY  promo, nom, prenom";
     if ($iterator) {
         return XDB::iterator($sql, $nom, $prenom, $promo);
@@ -347,6 +359,7 @@ function get_user_details_adr($uid, $view = 'private') {
                      gp.pays AS countrytxt,a.region, a.regiontxt,
                      FIND_IN_SET('active', a.statut) AS active, a.adrid,
                      FIND_IN_SET('res-secondaire', a.statut) AS secondaire,
+                     FIND_IN_SET('courrier', a.statut) AS courier,
                      a.pub, gp.display, a.comment
                FROM  adresses AS a
           LEFT JOIN  geoloc_pays AS gp ON (gp.a2=a.country)
@@ -391,8 +404,10 @@ function &get_user_details($login, $from_uid = '', $view = 'private')
                        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,
-                       q.profile_medals_pub AS medals_pub,
-                       IF(gp.nat='',gp.pays,gp.nat) AS nationalite, gp.a2 AS iso3166,
+                       q.profile_medals_pub AS medals_pub, co.corps_pub AS corps_pub,
+                       IF(gp1.nat='',gp1.pays,gp1.nat) AS nationalite, gp1.a2 AS iso3166_1,
+                       IF(gp2.nat='',gp2.pays,gp2.nat) AS nationalite2, gp2.a2 AS iso3166_2,
+                       IF(gp3.nat='',gp3.pays,gp3.nat) AS nationalite3, gp3.a2 AS iso3166_3,
                        a.alias AS forlife, a2.alias AS bestalias,
                        c.uid IS NOT NULL AS is_contact,
                        s.text AS section, p.x, p.y, p.pub AS photo_pub,
@@ -401,15 +416,18 @@ function &get_user_details($login, $from_uid = '', $view = 'private')
                        (COUNT(e.email) > 0 OR FIND_IN_SET('googleapps', u.mail_storage) > 0) AS actif,
                        nd.display AS name_display, nd.tooltip AS name_tooltip
                  FROM  auth_user_md5   AS u
-           INNER JOIN  auth_user_quick AS q  USING(user_id)
-           INNER JOIN  aliases         AS a  ON (u.user_id=a.id AND a.type='a_vie')
-           INNER JOIN  aliases         AS a2 ON (u.user_id=a2.id AND FIND_IN_SET('bestalias',a2.flags))
-            LEFT JOIN  contacts        AS c  ON (c.uid = {?} and c.contact = u.user_id)
-            LEFT JOIN  geoloc_pays     AS gp ON (gp.a2 = u.nationalite)
-           INNER JOIN  sections        AS s  ON (s.id  = u.section)
-            LEFT JOIN  photo           AS p  ON (p.uid = u.user_id)
-            LEFT JOIN  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  auth_user_quick AS q   USING(user_id)
+           INNER JOIN  aliases         AS a   ON (u.user_id = a.id AND a.type = 'a_vie')
+           INNER JOIN  aliases         AS a2  ON (u.user_id = a2.id AND FIND_IN_SET('bestalias', a2.flags))
+            LEFT JOIN  contacts        AS c   ON (c.uid = {?} and c.contact = u.user_id)
+            LEFT JOIN  profile_corps   AS co  ON (co.uid = u.user_id)
+            LEFT JOIN  geoloc_pays     AS gp1 ON (gp1.a2 = u.nationalite)
+            LEFT JOIN  geoloc_pays     AS gp2 ON (gp2.a2 = u.nationalite2)
+            LEFT JOIN  geoloc_pays     AS gp3 ON (gp3.a2 = u.nationalite3)
+           INNER JOIN  sections        AS s   ON (s.id  = u.section)
+            LEFT JOIN  photo           AS p   ON (p.uid = u.user_id)
+            LEFT JOIN  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)
                 WHERE  a.alias = {?}
              GROUP BY  u.user_id";
@@ -476,20 +494,36 @@ function &get_user_details($login, $from_uid = '', $view = 'private')
         $user['gpxs_join'] = join(', ', $user['gpxs']);
     }
 
-    $res = XDB::iterRow("SELECT  applis_def.text, applis_def.url, applis_ins.type
-                           FROM  applis_ins
-                     INNER JOIN  applis_def ON applis_def.id = applis_ins.aid
+    $res = XDB::iterRow("SELECT  en.name AS name, en.url AS url, d.degree AS degree,
+                                 ed.grad_year AS grad_year, f.field AS field, ed.program AS program
+                           FROM  profile_education AS ed
+                     INNER JOIN  profile_education_enum        AS en ON (en.id = ed.eduid)
+                     INNER JOIN  profile_education_degree_enum AS d  ON (d.id  = ed.degreeid)
+                     INNER JOIN  profile_education_field_enum  AS f  ON (f.id  = ed.fieldid)
                           WHERE  uid={?}
-                       ORDER BY  ordre", $uid);
-
-    $user['applis_fmt'] = Array();
-    $user['formation'] = Array();
-    while (list($txt, $url, $type) = $res->next()) {
-        $user['formation'][] = $txt." ".$type;
-        require_once('applis.func.inc.php');
-        $user['applis_fmt'][] = applis_fmt($type, $txt, $url);
+                       ORDER BY  ed.grad_year", $uid);
+
+    $user['education'] = "";
+    require_once('education.func.inc.php');
+    if (list($name, $url, $degree, $grad_year, $field, $program) = $res->next()) {
+        $user['education'] .= education_fmt($name, $url, $degree, $grad_year, $field, $program, $user['sexe'], true);
+    }
+    while (list($name, $url, $degree, $grad_year, $field, $program) = $res->next()) {
+        $user['education'] .= ", " . education_fmt($name, $url, $degree, $grad_year, $field, $program, $user['sexe'], true);
+    }
+
+    if (has_user_right($user['corps_pub'], $view)) {
+        $res = XDB::query("SELECT  e1.name AS original, e2.name AS current, r.name AS rank
+                             FROM  profile_corps           AS c
+                        LEFT JOIN  profile_corps_enum      AS e1 ON (c.original_corpsid = e1.id)
+                        LEFT JOIN  profile_corps_enum      AS e2 ON (c.current_corpsid = e2.id)
+                        LEFT JOIN  profile_corps_rank_enum AS r  ON (c.rankid = r.id)
+                            WHERE  c.uid = {?} AND c.original_corpsid != 1", $uid);
+        if ($res = $res->fetchOneRow()) {
+            list($original, $current, $rank) = $res;
+            $user['corps'] = "Corps d'origine : " . $original . ", corps actuel : " . $current . ", grade : " . $rank;
+        }
     }
-    $user['applis_join'] = join(', ', $user['applis_fmt']);
 
     if (has_user_right($user['medals_pub'], $view)) {
         $res = XDB::iterator("SELECT  m.id, m.text AS medal, m.type, s.gid, g.text AS grade
@@ -790,7 +824,7 @@ function set_user_details($uid, $details) {
         }
     }
 
-    // applis
+    // education
     // medals
 }
 // }}}