From c750592ac475195dcfdd4459662f6013951f00c5 Mon Sep 17 00:00:00 2001 From: moodler Date: Fri, 21 Mar 2003 09:42:42 +0000 Subject: [PATCH] Added a search form to the "edit users" admin page yay! --- admin/user.php | 168 +++++++++++++++++++++++++-------------------- lang/en/moodle.php | 2 + lib/datalib.php | 10 ++- 3 files changed, 105 insertions(+), 75 deletions(-) diff --git a/admin/user.php b/admin/user.php index 4edd03ef50..ece6fd7439 100644 --- a/admin/user.php +++ b/admin/user.php @@ -12,6 +12,7 @@ optional_variable($sort, "name"); optional_variable($dir, "ASC"); optional_variable($page, 0); + optional_variable($search, ""); if (! record_exists("user_admins")) { // No admin user yet $user->firstname = "Admin"; @@ -94,6 +95,8 @@ $stredit = get_string("edit"); $strdelete = get_string("delete"); $strdeletecheck = get_string("deletecheck"); + $strsearch = get_string("search"); + $strshowallusers = get_string("showallusers"); print_header("$site->shortname: $stredituser", $site->fullname, "$stradministration -> $stredituser"); @@ -125,7 +128,7 @@ // Carry on with the user listing - $usercount = get_users_count(); + $usertotalcount = get_users_count(); $columns = array("name", "email", "city", "country", "lastaccess"); @@ -140,7 +143,7 @@ if ($columnsort == $sort) { $$column = $string[$column]; } else { - $$column = "".$string[$column].""; + $$column = "".$string[$column].""; } } @@ -148,89 +151,108 @@ $sort = "firstname"; } - if ($users = get_users_listing($sort, $dir, $page, $recordsperpage)) { - print_heading("$usercount ".get_string("users")); - - $a->start = $page; - $a->end = $page + $recordsperpage; - if ($a->end > $usercount) { - $a->end = $usercount; + if (!$users = get_users_listing($sort, $dir, $page, $recordsperpage, $search)) { + if (!$users = get_users_listing($sort, $dir, $page, $recordsperpage)) { + error("No users found!"); + } else { + notify(get_string("nousersmatching", "", $search)); + $search = ""; } - echo ""; - echo "
"; - if ($page) { - $prevpage = $page - $recordsperpage; - if ($prevpage < 0) { - $prevpage = 0; - } - $options["dir"] = $dir; - $options["page"] = 0; - $options["sort"] = $sort; - print_single_button("user.php", $options, " << "); - echo ""; - $options["page"] = $prevpage; - print_single_button("user.php", $options, " < "); + } + + $usercount = count($users); + print_heading("$usercount/$usertotalcount ".get_string("users")); + + $a->start = $page; + $a->end = $page + $recordsperpage; + if ($a->end > $usercount) { + $a->end = $usercount; + } + echo ""; + echo "
"; + if ($page) { + $prevpage = $page - $recordsperpage; + if ($prevpage < 0) { + $prevpage = 0; } + $options["dir"] = $dir; + $options["page"] = 0; + $options["sort"] = $sort; + $options["search"] = $search; + print_single_button("user.php", $options, " << "); echo ""; - print_heading(get_string("displayingusers", "", $a)); + $options["page"] = $prevpage; + print_single_button("user.php", $options, " < "); + } + echo ""; + print_heading(get_string("displayingusers", "", $a)); + echo ""; + $nextpage = $page + $recordsperpage; + if ($nextpage < $usercount) { + $options["dir"] = $dir; + $options["page"] = $nextpage; + $options["sort"] = $sort; + $options["search"] = $search; + print_single_button("user.php", $options, " > "); echo ""; - $nextpage = $page + $recordsperpage; - if ($nextpage < $usercount) { - $options["dir"] = $dir; - $options["page"] = $nextpage; - $options["sort"] = $sort; - print_single_button("user.php", $options, " > "); - echo ""; - $options["page"] = $usercount-$recordsperpage; - print_single_button("user.php", $options, " >> "); - } - echo "
"; + $options["page"] = $usercount-$recordsperpage; + print_single_button("user.php", $options, " >> "); + } + echo "
"; - flush(); + flush(); - foreach ($users as $key => $user) { - $users[$key]->country = $COUNTRIES[$user->country]; + foreach ($users as $key => $user) { + $users[$key]->country = $COUNTRIES[$user->country]; + } + if ($sort == "country") { // Need to resort by full country name, not code + foreach ($users as $user) { + $susers[$user->id] = $user->country; } - if ($sort == "country") { // Need to resort by full country name, not code - foreach ($users as $user) { - $susers[$user->id] = $user->country; - } - asort($susers); - foreach ($susers as $key => $value) { - $nusers[] = $users[$key]; - } - $users = $nusers; + asort($susers); + foreach ($susers as $key => $value) { + $nusers[] = $users[$key]; } + $users = $nusers; + } - $table->head = array ($name, $email, $city, $country, $lastaccess, "", ""); - $table->align = array ("LEFT", "LEFT", "LEFT", "LEFT", "LEFT", "CENTER", "CENTER"); - $table->width = "95%"; - foreach ($users as $user) { - if ($user->id == $USER->id or $user->username == "changeme") { - $deletebutton = ""; - } else { - $deletebutton = "id\" TARGET=\"$strdeletecheck\">$strdelete"; - } - if ($user->lastaccess) { - $strlastaccess = format_time(time() - $user->lastaccess); - } else { - $strlastaccess = get_string("never"); - } - $table->data[] = array ("id&course=$site->id\">$user->firstname $user->lastname", - "$user->email", - "$user->city", - "$user->country", - $strlastaccess, - "id&course=$site->id\">$stredit", - $deletebutton); + $table->head = array ($name, $email, $city, $country, $lastaccess, "", ""); + $table->align = array ("LEFT", "LEFT", "LEFT", "LEFT", "LEFT", "CENTER", "CENTER"); + $table->width = "95%"; + foreach ($users as $user) { + if ($user->id == $USER->id or $user->username == "changeme") { + $deletebutton = ""; + } else { + $deletebutton = "id\" TARGET=\"$strdeletecheck\">$strdelete"; } - print_table($table); + if ($user->lastaccess) { + $strlastaccess = format_time(time() - $user->lastaccess); + } else { + $strlastaccess = get_string("never"); + } + $table->data[] = array ("id&course=$site->id\">$user->firstname $user->lastname", + "$user->email", + "$user->city", + "$user->country", + $strlastaccess, + "id&course=$site->id\">$stredit", + $deletebutton); + } - print_heading("".get_string("addnewuser").""); - } else { - error("No users found!"); - + echo "
"; + echo "
"; + echo ""; + echo ""; + if ($search) { + echo ""; } + echo "
"; + echo "
"; + + print_table($table); + + print_heading("".get_string("addnewuser").""); + print_footer(); } diff --git a/lang/en/moodle.php b/lang/en/moodle.php index 6d3526d654..730df260dd 100644 --- a/lang/en/moodle.php +++ b/lang/en/moodle.php @@ -390,6 +390,7 @@ $string['nosuchemail'] = "No such email address"; $string['noteachersyet'] = "No teachers in this course yet"; $string['notenrolled'] = "\$a is not enrolled in this course."; $string['nothingnew'] = "Nothing new since your last login"; +$string['nousersmatching'] = "No users matching '\$a' were found"; $string['nousersyet'] = "There are no users yet"; $string['now'] = "now"; $string['numberweeks'] = "Number of weeks/topics"; @@ -454,6 +455,7 @@ $string['shortnametaken'] = "Short name is already used for another course (\$a) $string['shortsitename'] = "Short name for site (eg single word)"; $string['show'] = "Show"; $string['showalltopics'] = "Show all topics"; +$string['showallusers'] = "Show all users"; $string['showallweeks'] = "Show all weeks"; $string['showlistofcourses'] = "Show list of courses"; $string['showonlytopic'] = "Show only topic \$a"; diff --git a/lib/datalib.php b/lib/datalib.php index cde9f61bdc..89a1fc3465 100644 --- a/lib/datalib.php +++ b/lib/datalib.php @@ -877,7 +877,7 @@ function get_users_count() { return count_records_select("user", "username <> 'guest' AND deleted <> 1"); } -function get_users_listing($sort, $dir="ASC", $page=1, $recordsperpage=20) { +function get_users_listing($sort, $dir="ASC", $page=1, $recordsperpage=20, $search="") { global $CFG; switch ($CFG->dbtype) { @@ -891,10 +891,16 @@ function get_users_listing($sort, $dir="ASC", $page=1, $recordsperpage=20) { $limit = "LIMIT $recordsperpage,$page"; } + if ($search) { + $search = " AND (firstname LIKE '%$search%' + OR lastname LIKE '%$search%' + OR email LIKE '%$search%') "; + } + return get_records_sql("SELECT id, username, email, firstname, lastname, city, country, lastaccess FROM {$CFG->prefix}user WHERE username <> 'guest' - AND deleted <> '1' + AND deleted <> '1' $search ORDER BY $sort $dir $limit"); } -- 2.39.5