Replaces removed function get_not_registered_user.
authorStéphane Jacob <sj@m4x.org>
Tue, 18 May 2010 14:09:15 +0000 (16:09 +0200)
committerStéphane Jacob <sj@m4x.org>
Wed, 26 May 2010 07:42:20 +0000 (09:42 +0200)
Signed-off-by: Stéphane Jacob <sj@m4x.org>
classes/user.php
modules/lists.php
modules/xnetgrp.php
templates/lists/admin.tpl

index 1ce06bc..55762d4 100644 (file)
@@ -653,6 +653,35 @@ class User extends PlUser
             || $dom == $globals->mail->alias_dom2;
     }
 
+    /* Tries to find pending accounts with an hruid close to $login. */
+    public static function getPendingAccounts($login, $iterator = false)
+    {
+        global $globals;
+
+        if (strpos($login, '@') === false) {
+            return null;
+        }
+
+        list($login, $domain) = explode('@', $login);
+
+        if ($domain && $domain != $globals->mail->domain && $domain != $globals->mail->domain2) {
+            return null;
+        }
+
+        $sql = "SELECT  uid, full_name
+                  FROM  accounts
+                 WHERE  state = 'pending' AND REPLACE(hruid, '-', '') LIKE
+                        CONCAT('%', REPLACE(REPLACE(REPLACE({?}, ' ', ''), '-', ''), '\'', ''), '%')
+              ORDER BY  full_name";
+        if ($iterator) {
+            return XDB::iterator($sql, $login);
+        } else {
+            $res = XDB::query($sql, $login);
+            return $res->fetchAllAssoc();
+        }
+    }
+
+
     public static function iterOverUIDs($uids, $respect_order = true)
     {
         return new UserIterator(self::loadMainFieldsFromUIDs($uids, $respect_order));
index d50eeb2..3e85e72 100644 (file)
@@ -582,8 +582,7 @@ class ListsModule extends PLModule
     {
         global $list_unregistered, $globals;
 
-        /* TODO: fixes this call to a removed function. */
-        $users = get_not_registered_user($login, true);
+        $users = User::getPendingAccounts($login, true);
         if ($users && $users->total()) {
             if (!isset($list_unregistered)) {
                 $list_unregistered = array();
index 3c8861a..5ce2c22 100644 (file)
@@ -801,16 +801,15 @@ class XnetGrpModule extends PLModule
                             WHERE  a.alias = {?}",
                           $login);
         if ($res->numRows() == 0) {
-            // TODO: replace this call to a removed function.
-            $x = get_not_registered_user($login);
-            if (!$x) {
-                $page->trigError("Le login $login ne correspond à aucun X.");
+            $accounts = User::getPendingAccounts($login);
+            if (!$accounts) {
+                $page->trigError("L'identifiant $login ne correspond à aucun X.");
                 return false;
-            } else if (count($x) > 1) {
-                $page->trigError("Le login $login correspond a plusieurs camarades.");
+            } else if (count($accounts) > 1) {
+                $page->trigError("L'identifiant $login correspond à plusieurs camarades.");
                 return false;
             }
-            $uid = $x[0]['uid'];
+            $uid = $accounts[0]['uid'];
             $sub = false;
         } else {
             list($uid, $login) = $res->fetchOneRow();
index df30d58..3a49e91 100644 (file)
@@ -69,7 +69,7 @@ emails de marketing. Une fois inscrits à Polytechnique.org, l'inscription à la
         Camarade&nbsp;:
         <select name="mk_uid[{$login}]">
         {iterate from=$it item=user}
-          <option value="{$user.uid}">{$user.prenom} {$user.nom} (X{$user.promo})</option>
+          <option value="{$user.uid}">{$user.full_name}</option>
         {/iterate}
         </select><br />
         Action*&nbsp;: