]> git.mjollnir.org Git - moodle.git/commitdiff
Added a search form to the "edit users" admin page yay!
authormoodler <moodler>
Fri, 21 Mar 2003 09:42:42 +0000 (09:42 +0000)
committermoodler <moodler>
Fri, 21 Mar 2003 09:42:42 +0000 (09:42 +0000)
admin/user.php
lang/en/moodle.php
lib/datalib.php

index 4edd03ef503a54b2d08be6a2d949e6ce940bfddb..ece6fd7439ade60485b8c69bbff0391ec2a71cba 100644 (file)
@@ -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, 
                      "<A HREF=\"index.php\">$stradministration</A> -> $stredituser");
 
         // Carry on with the user listing
 
-        $usercount = get_users_count();
+        $usertotalcount = get_users_count();
 
         $columns = array("name", "email", "city", "country", "lastaccess");
 
             if ($columnsort == $sort) {
                $$column = $string[$column];
             } else {
-               $$column = "<A HREF=\"user.php?sort=$columnsort&dir=$columndir\">".$string[$column]."</A>";
+               $$column = "<A HREF=\"user.php?sort=$columnsort&dir=$columndir&search=$search\">".$string[$column]."</A>";
             }
         }
 
             $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 "<TABLE align=center cellpadding=10><TR>";
-            echo "<TD>";
-            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 "</TD><TD>";
-                $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 "<TABLE align=center cellpadding=10><TR>";
+        echo "<TD>";
+        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 "</TD><TD>";
-            print_heading(get_string("displayingusers", "", $a));
+            $options["page"] = $prevpage;
+            print_single_button("user.php", $options, "  <  ");
+        }
+        echo "</TD><TD>";
+        print_heading(get_string("displayingusers", "", $a));
+        echo "</TD><TD>";
+        $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 "</TD><TD>";
-            $nextpage = $page + $recordsperpage;
-            if ($nextpage < $usercount) {
-                $options["dir"] = $dir;
-                $options["page"] = $nextpage;
-                $options["sort"] = $sort;
-                print_single_button("user.php", $options, "  >  ");
-                echo "</TD><TD>";
-                $options["page"] = $usercount-$recordsperpage;
-                print_single_button("user.php", $options, "  >>  ");
-            }
-            echo "</TD></TR></TABLE>";
+            $options["page"] = $usercount-$recordsperpage;
+            print_single_button("user.php", $options, "  >>  ");
+        }
+        echo "</TD></TR></TABLE>";
 
-            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 = "<A HREF=\"user.php?delete=$user->id\" TARGET=\"$strdeletecheck\">$strdelete</A>";
-                }
-                if ($user->lastaccess) {
-                    $strlastaccess = format_time(time() - $user->lastaccess);
-                } else {
-                    $strlastaccess = get_string("never");
-                }
-                $table->data[] = array ("<A HREF=\"../user/view.php?id=$user->id&course=$site->id\">$user->firstname $user->lastname</A>",
-                                 "$user->email",
-                                 "$user->city",
-                                 "$user->country",
-                                 $strlastaccess,
-                                 "<A HREF=\"../user/edit.php?id=$user->id&course=$site->id\">$stredit</A>",
-                                 $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 = "<A HREF=\"user.php?delete=$user->id\" TARGET=\"$strdeletecheck\">$strdelete</A>";
             }
-            print_table($table);
+            if ($user->lastaccess) {
+                $strlastaccess = format_time(time() - $user->lastaccess);
+            } else {
+                $strlastaccess = get_string("never");
+            }
+            $table->data[] = array ("<A HREF=\"../user/view.php?id=$user->id&course=$site->id\">$user->firstname $user->lastname</A>",
+                             "$user->email",
+                             "$user->city",
+                             "$user->country",
+                             $strlastaccess,
+                             "<A HREF=\"../user/edit.php?id=$user->id&course=$site->id\">$stredit</A>",
+                             $deletebutton);
+        }
 
-            print_heading("<A HREF=\"user.php?newuser=true\">".get_string("addnewuser")."</A>");
-        } else {
-            error("No users found!");
-            
+        echo "<TABLE align=center cellpadding=10><TR><TD>";
+           echo "<FORM ACTION=user.php METHOD=POST>";
+           echo "<INPUT TYPE=text NAME=search VALUE=\"$search\" SIZE=20>";
+           echo "<INPUT TYPE=submit VALUE=\"$strsearch\">";
+        if ($search) {
+            echo "<INPUT type=\"button\" onClick=\"document.location='user.php';\" value=\"$strshowallusers\">";
         }
+           echo "</FORM>";     
+        echo "</TD></TR></TABLE>";
+
+        print_table($table);
+
+        print_heading("<A HREF=\"user.php?newuser=true\">".get_string("addnewuser")."</A>");
+
         print_footer();
     }
 
index 6d3526d6548f069ea2af1131a33d15838acf5b04..730df260ddf65a077808f7507b4fb1ac7b9e51c4 100644 (file)
@@ -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";
index cde9f61bdc564bbc4116e5117f24ecde785bb2d0..89a1fc34650dbe0c602205d0b48b948d473e448f 100644 (file)
@@ -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");
 
 }