Rename xorg_ constants to pl_
[platal.git] / include / user.func.inc.php
index b515c0c..1f8a698 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   *
@@ -46,10 +46,9 @@ function user_clear_all_subs($user_id, $really_del=true)
         array_push($tables_to_clear['user_id'], 'newsletter_ins', 'auth_user_quick', 'binets_ins');
         $tables_to_clear['id'] = array('aliases');
         $tables_to_clear['contact'] = array('contacts');
-        $tables_to_clear['guid'] = array('groupesx_ins');
         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 = ''
+                             nationalite = '', 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);
@@ -71,6 +70,15 @@ function user_clear_all_subs($user_id, $really_del=true)
 
     $mmlist = new MMList(S::v('uid'), S::v('password'));
     $mmlist->kill($alias, $really_del);
+
+    // Deactivates, when available, the Google Apps account of the user.
+    if ($globals->mailstorage->googleapps_domain) {
+        require_once 'googleapps.inc.php';
+        if (GoogleAppsAccount::account_status($uid)) {
+            $account = new GoogleAppsAccount($uid, $alias);
+            $account->suspend();
+        }
+    }
 }
 
 // }}}
@@ -79,8 +87,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->trig("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;
 }
 
@@ -91,7 +98,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);
@@ -163,7 +170,7 @@ function get_user_login($data, $get_forlife = false, $callback = '_default_user_
             default:
                 if (S::has_perms()) {
                     $aliases = $res->fetchColumn();
-                    $page->trig("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();
                 }
@@ -391,7 +398,7 @@ function &get_user_details($login, $from_uid = '', $view = 'private')
                        s.text AS section, p.x, p.y, p.pub AS photo_pub,
                        u.matricule_ax,
                        m.expertise != '' AS is_referent,
-                       COUNT(e.email) > 0 AS actif
+                       (COUNT(e.email) > 0 OR FIND_IN_SET('googleapps', u.mail_storage) > 0) AS actif
                  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')
@@ -448,14 +455,18 @@ function &get_user_details($login, $from_uid = '', $view = 'private')
         $user['binets']      = $res->fetchColumn();
         $user['binets_join'] = join(', ', $user['binets']);
 
-        $res  = XDB::iterRow("SELECT  text, url
-                                FROM  groupesx_ins
-                           LEFT JOIN  groupesx_def ON groupesx_ins.gid = groupesx_def.id
-                               WHERE  guid = {?}", $uid);
+        $res  = XDB::iterRow("SELECT  a.diminutif, a.nom, a.site
+                                FROM  groupex.asso    AS a
+                           LEFT JOIN  groupex.membres AS m ON (m.asso_id = a.id)
+                               WHERE  m.uid = {?} AND (a.cat = 'GroupesX' OR a.cat = 'Institutions')
+                                      AND pub = 'public'", $uid);
         $user['gpxs'] = Array();
         $user['gpxs_name'] = Array();
-        while (list($gxt, $gxu) = $res->next()) {
-            $user['gpxs'][] = $gxu ? "<a href=\"$gxu\">$gxt</a>" : $gxt;
+        while (list($gxd, $gxt, $gxu) = $res->next()) {
+            if (!$gxu) {
+                $gxu = 'http://www.polytechnique.net/' . $gxd;
+            }
+            $user['gpxs'][] = '<span title="' . pl_entities($gxt) . "\"><a href=\"$gxu\">$gxd</a></span>";
             $user['gpxs_name'][] = $gxt;
         }
         $user['gpxs_join'] = join(', ', $user['gpxs']);
@@ -477,7 +488,7 @@ function &get_user_details($login, $from_uid = '', $view = 'private')
     $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, m.img, s.gid, g.text AS grade
+        $res = XDB::iterator("SELECT  m.id, m.text AS medal, m.type, s.gid, g.text AS grade
                                 FROM  profile_medals_sub    AS s
                           INNER JOIN  profile_medals        AS m ON ( s.mid = m.id )
                            LEFT JOIN  profile_medals_grades AS g ON ( s.mid = g.mid AND s.gid = g.gid )