Moving to GitHub.
[platal.git] / plugins / insert.getUserName.php
index 7d69ee9..8e81c7e 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /***************************************************************************
- *  Copyright (C) 2003-2010 Polytechnique.org                              *
+ *  Copyright (C) 2003-2014 Polytechnique.org                              *
  *  http://opensource.polytechnique.org/                                   *
  *                                                                         *
  *  This program is free software; you can redistribute it and/or modify   *
@@ -21,8 +21,6 @@
 
 function smarty_insert_getUsername()
 {
-    global $globals;
-
     $id = Cookie::i('uid', -1);
     $id = S::v('uid', $id);
 
@@ -30,31 +28,9 @@ function smarty_insert_getUsername()
         return '';
     }
 
-    if (Cookie::v('domain', 'login') != 'alias') {
-        $res = XDB::query("SELECT  alias
-                             FROM  aliases
-                            WHERE  uid = {?} AND (type IN ('a_vie', 'alias') AND FIND_IN_SET('bestalias', flags))",
-                          $id);
-        return $res->fetchOneCell();
-    } else {
-        $res = XDB::query("
-            SELECT  v.alias
-              FROM  virtual AS v
-        INNER JOIN  virtual_redirect USING (vid)
-        INNER JOIN  aliases AS a ON (uid = {?} AND a.type = 'a_vie')
-             WHERE  redirect = CONCAT(a.alias, {?}) OR redirect = CONCAT(a.alias, {?})",
-            $id, '@' . $globals->mail->domain, '@' . $globals->mail->domain2);
-        $aliases = $res->fetchAllAssoc();
-        foreach ($aliases as $alias) {
-            list($login, $domain) = explode('@', $alias['alias']);
-            if ($domain == $globals->mail->alias_dom || $domain == $globals->mail->alias_dom2) {
-                return $login;
-            }
-        }
-     }
-
-     return '';
+    $user = User::getSilentWithUID($id);
+    return $user->bestEmail();
 }
 
-// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
+// vim:set et sw=4 sts=4 sws=4 foldmethod=marker fenc=utf-8:
 ?>