From d5b27c85d3b043cf6d884a68fd339903ec40b5d6 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Mon, 16 Jun 2014 11:21:50 -0700 Subject: [PATCH] web: fix user search function --- html/user/user_search.php | 33 +++++++++------------------------ 1 file changed, 9 insertions(+), 24 deletions(-) diff --git a/html/user/user_search.php b/html/user/user_search.php index b64e8ab031..a8d1ca4d9c 100644 --- a/html/user/user_search.php +++ b/html/user/user_search.php @@ -76,22 +76,6 @@ function search_form() { page_tail(); } -function compare_create_time($u1, $u2) { - if ($u1->create_time < $u2->create_time) return 1; - if ($u1->create_time > $u2->create_time) return -1; - return 0; -} -function compare_expavg_credit($u1, $u2) { - if ($u1->expavg_credit < $u2->expavg_credit) return 1; - if ($u1->expavg_credit > $u2->expavg_credit) return -1; - return 0; -} -function compare_total_credit($u1, $u2) { - if ($u1->total_credit < $u2->total_credit) return 1; - if ($u1->total_credit > $u2->total_credit) return -1; - return 0; -} - function search_action() { $where = "true"; $search_string = get_str('search_string'); @@ -120,16 +104,17 @@ function search_action() { } else if ($t == 'no') { $where .= " and has_profile=0"; } - $fields = "id, create_time, name, country, total_credit, expavg_credit, teamid, url, has_profile, donated"; - $users = BoincUser::enum_fields($fields, $where, "order by id desc limit 100"); + $search_type = get_str('search_type', true); - if ($search_type == 'date') { - usort($users, 'compare_create_time'); - } else if ($search_type == 'rac') { - usort($users, 'compare_expavg_credit'); - } else { - usort($users, 'compare_total_credit'); + $order_clause = "id desc"; + if ($search_type == 'rac') { + $order_clause ="expavg_credit desc"; + } else if ($search_type == 'total') { + $order_clause ="total_credit desc"; } + + $fields = "id, create_time, name, country, total_credit, expavg_credit, teamid, url, has_profile, donated"; + $users = BoincUser::enum_fields($fields, $where, "order by $order_clause limit 100"); page_head(tra("User search results")); $n=0; foreach ($users as $user) {