diff --git a/core/user_api.php b/core/user_api.php index 883f2f2..2e1ef90 100644 --- a/core/user_api.php +++ b/core/user_api.php @@ -131,6 +131,19 @@ function user_cache_array_rows( $p_user_id_array ) { return; } +function user_cache_all() { + global $g_cache_user; + + $t_user_table = db_get_table( 'user' ); + $t_query = "SELECT * FROM $t_user_table"; + $t_result = db_query_bound( $t_query ); + + while( $t_row = db_fetch_array( $t_result ) ) { + $g_cache_user[(int) $t_row['id']] = $t_row; + } + return $g_cache_user; +} + # -------------------- # Cache an object as a bug. function user_cache_database_result( $p_user_database_result ) { @@ -730,6 +743,12 @@ function user_get_row( $p_user_id ) { } # -------------------- +# return all users +function user_get_all() { + return user_cache_all(); +} + +# -------------------- # return the specified user field for the user id function user_get_field( $p_user_id, $p_field_name ) { if( NO_USER == $p_user_id ) { diff --git a/core/xmlhttprequest_api.php b/core/xmlhttprequest_api.php index 7c9e243..307a31a 100644 --- a/core/xmlhttprequest_api.php +++ b/core/xmlhttprequest_api.php @@ -57,6 +57,22 @@ function xmlhttprequest_filter_by_prefix( $p_set, $p_prefix ) { } /** + * Filter a set of strings by finding strings that match a case-insensitive substring. + * @param array $p_set An array of strings to search through. + * @param string $p_substr The substring to filter by. + * @return array An array of strings which match the supplied substring. + */ +function xmlhttprequest_filter_match( $p_set, $p_substr ) { + $t_matches = array(); + foreach ( $p_set as $p_item ) { + if( utf8_strpos( utf8_strtolower( $p_item ), utf8_strtolower( $p_substr ) ) !== false ) { + $t_matches[] = $p_item; + } + } + return $t_matches; +} + +/** * Echos a serialized list of platforms starting with the prefix specified in the $_POST * @return null * @access public @@ -97,3 +113,21 @@ function xmlhttprequest_os_build_get_with_prefix() { echo json_encode( $t_matching_entries ); } + +/** + * Echos a serialized list of Users starting with the prefix specified in the $_POST + * @return null + * @access public + */ +function xmlhttprequest_username_get_with_prefix() { + $f_username = gpc_get_string( 'username' ); + + $t_users = user_cache_all(); + foreach( $t_users AS $t_user ) { + $t_unique_entries[] = $t_user['username']; + } + + $t_matching_entries = xmlhttprequest_filter_match( $t_unique_entries, $f_username ); + + echo json_encode( $t_matching_entries ); +} diff --git a/manage_user_page.php b/manage_user_page.php index 3231f7b..484031b 100644 --- a/manage_user_page.php +++ b/manage_user_page.php @@ -380,7 +380,7 @@ for ($i=0;$i<$user_count;$i++) {