diff --git a/htdocs/lib/user.php b/htdocs/lib/user.php index a348fc1f9a9eeada02a9db4bbc18fff7b44865b8..b684914558683372222c39afe663bd95f37f3f16 100644 --- a/htdocs/lib/user.php +++ b/htdocs/lib/user.php @@ -2197,3 +2197,22 @@ function get_onlineusers($limit=10, $offset=0, $orderby='firstname,lastname') { return $result; } + +/** + * Get a list of userids from a list of usernames + * + * @param $usernames array list of usernames + * + * @returns array list of userids + */ +function username_to_id($usernames) { + if (!empty($usernames)) { + $ids = get_records_sql_menu(' + SELECT username, id FROM {usr} + WHERE deleted = 0 + AND LOWER(username) IN (' . join(',', array_fill(0, count($usernames), '?')) . ')', + array_map('strtolower', $usernames) + ); + } + return empty($ids) ? array() : $ids; +}