user web: fix PHP warning

This commit is contained in:
David Anderson 2016-09-11 19:54:43 -07:00
parent 0c08a4ef92
commit e26094e41e
2 changed files with 7 additions and 10 deletions

View File

@ -193,16 +193,12 @@ class BoincUser {
$email_addr = BoincDb::escape_string($email_addr);
return self::lookup("email_addr='$email_addr'");
}
// name is not necessarily unique
//
static function lookup_name($name) {
$name = BoincDb::escape_string($name);
$users = BoincUser::enum("name='$name'");
switch (sizeof($users)) {
case 1:
return $users[0];
case 0:
return null;
}
return -1;
return $users;
}
static function count($clause) {
$db = BoincDb::get();

View File

@ -210,12 +210,13 @@ function do_send($logged_in_user) {
pm_form($replyto, $userid, tra("Could not find user with id %1", $userid));
}
} else {
$user = BoincUser::lookup_name($username);
if ($user == null) {
$users = BoincUser::lookup_name($username);
if (count($users) == 0) {
pm_form($replyto, $userid, tra("Could not find user with username %1", $username));
} elseif ($user == -1) { // Non-unique username
} elseif (count($users) > 1) { // Non-unique username
pm_form($replyto, $userid, tra("%1 is not a unique username; you will have to use user ID", $username));
}
$user = $users[0];
}
BoincForumPrefs::lookup($user);
if (is_ignoring($user, $logged_in_user)) {