From 61a7d2794e5e36491f49ab46d52f8c7eaf2f7a27 Mon Sep 17 00:00:00 2001 From: =?utf8?q?St=C3=A9phane=20Jacob?= Date: Tue, 18 May 2010 16:09:15 +0200 Subject: [PATCH] Replaces removed function get_not_registered_user. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Stéphane Jacob --- classes/user.php | 29 +++++++++++++++++++++++++++++ modules/lists.php | 3 +-- modules/xnetgrp.php | 13 ++++++------- templates/lists/admin.tpl | 2 +- 4 files changed, 37 insertions(+), 10 deletions(-) diff --git a/classes/user.php b/classes/user.php index 1ce06bc..55762d4 100644 --- a/classes/user.php +++ b/classes/user.php @@ -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)); diff --git a/modules/lists.php b/modules/lists.php index d50eeb2..3e85e72 100644 --- a/modules/lists.php +++ b/modules/lists.php @@ -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(); diff --git a/modules/xnetgrp.php b/modules/xnetgrp.php index 3c8861a..5ce2c22 100644 --- a/modules/xnetgrp.php +++ b/modules/xnetgrp.php @@ -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(); diff --git a/templates/lists/admin.tpl b/templates/lists/admin.tpl index df30d58..3a49e91 100644 --- a/templates/lists/admin.tpl +++ b/templates/lists/admin.tpl @@ -69,7 +69,7 @@ emails de marketing. Une fois inscrits à Polytechnique.org, l'inscription à la Camarade :
Action* : -- 2.1.4