--- assign.php.194	2009-04-30 20:11:55.000000000 +0300
+++ assign.php.patch	2009-04-30 20:09:33.000000000 +0300
@@ -1,9 +1,10 @@
-<?php // $Id: assign.php,v 1.63.2.16 2009/04/07 23:48:00 arborrow Exp $
+<?php // $Id: assign.php,v 1.63.2.15 2008/12/11 09:21:52 tjhunt Exp $
       // Script to assign users to contexts
 
     require_once('../../config.php');
     require_once($CFG->dirroot.'/mod/forum/lib.php');
     require_once($CFG->libdir.'/adminlib.php');
+    require_once($CFG->dirroot.'/user/filters/lib.php');
 
     define("MAX_USERS_PER_PAGE", 5000);
     define("MAX_USERS_TO_LIST_PER_ROLE", 10);
@@ -265,8 +266,20 @@
         print_box(get_string('globalroleswarning', 'role'));
     }
 
+
     if ($roleid) {        /// prints a form to swap roles
 
+    // pressing the 'add filter' button, reloads the assign role page 
+    // so i have to pass contextid and roleid to the user_filtering class
+    // if i do not want to be kicked out of this page with... contextid missing error :-)
+    $ufiltering = new user_filtering(null,null,array('contextid'=>$contextid,'roleid'=>$roleid));
+    // add filter's buttons
+    $ufiltering->display_add();
+    $ufiltering->display_active();
+    // split filters into SQL WHERE clause and 'should be filled in' params
+    $wheresql = $ufiltering->get_sql_filter();
+
     /// Get all existing participants in this context.
         // Why is this not done with get_users???
 
@@ -275,6 +288,9 @@
         }
 
         $select  = "username <> 'guest' AND deleted = 0 AND confirmed = 1";
+	if ($wheresql) {
+	  $select .= " AND ".$wheresql." ";
+	}
 
         $usercount = count_records_select('user', $select) - count($contextusers);
 
