# This patch file was generated by NetBeans IDE
# This patch can be applied using context Tools: Apply Diff Patch action on respective folder.
# It uses platform neutral UTF-8 encoding.
# Above lines and this line are ignored by the patching process.
Index: moodle/calendar/yui/eventmanager/eventmanager.js
--- moodle/calendar/yui/eventmanager/eventmanager.js Base (1.3)
+++ moodle/calendar/yui/eventmanager/eventmanager.js Locally Modified (Based On 1.3)
@@ -14,7 +14,11 @@
     }
     Y.extend(EVENT, Y.Base, {
         initializer : function(config){
-            var id = this.get(EVENTID), node = this.get(EVENTNODE), td = node.ancestor('td'), constraint = td.ancestor('div'), panel;
\ No newline at end of file
+            var id = this.get(EVENTID), node = this.get(EVENTNODE);
+            if (!node) {
+                return false;
+            }
+            var td = node.ancestor('td'), constraint = td.ancestor('div'), panel;
\ No newline at end of file
             this.publish('showevent');
             this.publish('hideevent');
             panel = new Y.Overlay({
Index: moodle/enrol/ajax.php
--- moodle/enrol/ajax.php Base (1.6)
+++ moodle/enrol/ajax.php Locally Modified (Based On 1.6)
@@ -17,6 +17,9 @@
 /**
  * This file processes AJAX enrolment actions and returns JSON
  *
+ * The general idea behind this file is that any errors should throw exceptions
+ * which will be returned and acted upon by the calling AJAX script.
+ *
  * @package moodlecore
  * @copyright  2010 Sam Hemelryk
  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
@@ -40,91 +43,76 @@
 $context = get_context_instance(CONTEXT_COURSE, $course->id, MUST_EXIST);
 
 if ($course->id == SITEID) {
-    redirect(new moodle_url('/'));
+    throw new moodle_exception('invalidcourse');
 }
 
 require_login($course);
 require_capability('moodle/course:enrolreview', $context);
+require_sesskey();
 
 $manager = new course_enrolment_manager($course);
 
 $outcome = new stdClass;
-$outcome->success = false;
+$outcome->success = true;
 $outcome->response = new stdClass;
 $outcome->error = '';
 
-if (!confirm_sesskey()) {
-    $outcome->error = 'invalidsesskey';
-    echo json_encode($outcome);
-    die();
-}
-
 switch ($action) {
     case 'unenrol':
         $ue = $DB->get_record('user_enrolments', array('id'=>required_param('ue', PARAM_INT)), '*', MUST_EXIST);
         list ($instance, $plugin) = $manager->get_user_enrolment_components($ue);
-        if ($instance && $plugin && $plugin->allow_unenrol($instance) && has_capability("enrol/$instance->enrol:unenrol", $manager->get_context()) && $manager->unenrol_user($ue)) {
-            $outcome->success = true;
-        } else {
-            $outcome->error = 'unabletounenrol';
+        if (!$instance || !$plugin || !$plugin->allow_unenrol($instance) || !has_capability("enrol/$instance->enrol:unenrol", $manager->get_context()) || !$manager->unenrol_user($ue)) {
+            throw new enrol_ajax_exception('unenrolnotpermitted');
         }
         break;
     case 'unassign':
         $role = required_param('role', PARAM_INT);
         $user = required_param('user', PARAM_INT);
-        if (has_capability('moodle/role:assign', $manager->get_context()) && $manager->unassign_role_from_user($user, $role)) {
-            $outcome->success = true;
-        } else {
-            $outcome->error = 'unabletounassign';
+        if (!has_capability('moodle/role:assign', $manager->get_context()) || !$manager->unassign_role_from_user($user, $role)) {
+            throw new enrol_ajax_exception('unassignnotpermitted');
         }
         break;
 
     case 'assign':
         $user = $DB->get_record('user', array('id'=>required_param('user', PARAM_INT)), '*', MUST_EXIST);
         $roleid = required_param('roleid', PARAM_INT);
-
-        if (!is_enrolled($context, $user)) {
-            $outcome->error = 'mustbeenrolled';
-            break; // no roles without enrolments here in this script
-        }
         if (!array_key_exists($roleid, $manager->get_assignable_roles())) {
-            $outcome->error = 'invalidrole';
-            break;
+            throw new enrol_ajax_exception('invalidrole');
         }
-
-        if (has_capability('moodle/role:assign', $manager->get_context()) && $manager->assign_role_to_user($roleid, $user->id)) {
-            $outcome->success = true;
-            $outcome->response->roleid = $roleid;
-        } else {
-            $outcome->error = 'unabletoassign';
+        if (!has_capability('moodle/role:assign', $manager->get_context()) || !$manager->assign_role_to_user($roleid, $user->id)) {
+            throw new enrol_ajax_exception('assignnotpermitted');
         }
+        $outcome->response->roleid = $roleid;
         break;
 
     case 'getassignable':
-        $outcome->success = true;
         $outcome->response = $manager->get_assignable_roles();
         break;
     case 'getcohorts':
         require_capability('moodle/course:enrolconfig', $context);
-        $outcome->success = true;
         $outcome->response = $manager->get_cohorts();
         break;
     case 'enrolcohort':
         require_capability('moodle/course:enrolconfig', $context);
         $roleid = required_param('roleid', PARAM_INT);
         $cohortid = required_param('cohortid', PARAM_INT);
-        $outcome->success = $manager->enrol_cohort($cohortid, $roleid);
+        if (!$manager->enrol_cohort($cohortid, $roleid)) {
+            throw new enrol_ajax_exception('errorenrolcohort');
+        }
         break;
     case 'enrolcohortusers':
         require_capability('moodle/course:enrolconfig', $context);
         $roleid = required_param('roleid', PARAM_INT);
         $cohortid = required_param('cohortid', PARAM_INT);
         $result = $manager->enrol_cohort_users($cohortid, $roleid);
-        if ($result !== false) {
+        if ($result === false) {
+            throw new enrol_ajax_exception('errorenrolcohortusers');
+        }
             $outcome->success = true;
             $outcome->response->users = $result;
+        $outcome->response->title = get_string('success');
             $outcome->response->message = get_string('enrollednewusers', 'enrol', $result);
-        }
+        $outcome->response->yesLabel = get_string('ok');
         break;
     case 'searchusers':
         $enrolid = required_param('enrolid', PARAM_INT);
@@ -138,6 +126,19 @@
         $outcome->success = true;
         break;
 
+    case 'searchotherusers':
+        $search  = optional_param('search', '', PARAM_CLEAN);
+        $page = optional_param('page', 0, PARAM_INT);
+        $outcome->response = $manager->search_other_users($search, false, $page);
+        foreach ($outcome->response['users'] as &$user) {
+            $user->userId = $user->id;
+            $user->picture = $OUTPUT->user_picture($user);
+            $user->fullname = fullname($user);
+            unset($user->id);
+        }
+        $outcome->success = true;
+        break;
+
     case 'enrol':
         $enrolid = required_param('enrolid', PARAM_INT);
         $userid = required_param('userid', PARAM_INT);
@@ -170,29 +171,22 @@
         $instances = $manager->get_enrolment_instances();
         $plugins = $manager->get_enrolment_plugins();
         if (!array_key_exists($enrolid, $instances)) {
-            $outcome->error = 'invalidinstance';
-            break;
+            throw new enrol_ajax_exception('invalidenrolinstance');
         }
         $instance = $instances[$enrolid];
         $plugin = $plugins[$instance->enrol];
         if ($plugin->allow_enrol($instance) && has_capability('enrol/'.$plugin->get_name().':enrol', $context)) {
-            try {
                 $plugin->enrol_user($instance, $user->id, $roleid, $timestart, $timeend);
-            } catch (Exception $e) {
-                $outcome->error = 'unabletoenrol';
-                break;
-            }
         } else {
-            $outcome->error = 'unablenotallowed';
-            break;
+            throw new enrol_ajax_exception('enrolnotpermitted');
         }
         $outcome->success = true;
         break;
 
     default:
-        $outcome->error = 'unknownaction';
-        break;
+        throw new enrol_ajax_exception('unknowajaxaction');
 }
 
+header('Content-type: application/json');
 echo json_encode($outcome);
 die();
Index: moodle/enrol/locallib.php
--- moodle/enrol/locallib.php Base (1.6)
+++ moodle/enrol/locallib.php Locally Modified (Based On 1.6)
@@ -64,6 +64,20 @@
      */
     protected $users = array();
 
+    /**
+     * An array of users who have roles within this course but who have not
+     * been enrolled in the course
+     * @var array
+     */
+    protected $otherusers = array();
+
+    /**
+     * The total number of users who hold a role within the course but who
+     * arn't enrolled.
+     * @var int
+     */
+    protected $totalotherusers = null;
+
     /**#@+
      * These variables are used to cache the information this class uses
      * please never use these directly instead use thier get_ counterparts.
@@ -114,6 +128,38 @@
     }
 
     /**
+     * Returns the total number of enrolled users in the course.
+     *
+     * If a filter was specificed this will be the total number of users enrolled
+     * in this course by means of that instance.
+     *
+     * @global moodle_database $DB
+     * @return int
+     */
+    public function get_total_other_users() {
+        global $DB;
+        if ($this->totalotherusers === null) {
+            list($ctxcondition, $params) = $DB->get_in_or_equal(get_parent_contexts($this->context, true), SQL_PARAMS_NAMED, 'ctx00');
+            $params['courseid'] = $this->course->id;
+            $sql = "SELECT COUNT(DISTINCT u.id)
+                    FROM {role_assignments} ra
+                    JOIN {user} u ON u.id = ra.userid
+                    JOIN {context} ctx ON ra.contextid = ctx.id
+                    LEFT JOIN (
+                        SELECT ue.id, ue.userid
+                        FROM {user_enrolments} ue
+                        LEFT JOIN {enrol} e ON e.id=ue.enrolid
+                        WHERE e.courseid = :courseid
+                    ) ue ON ue.userid=u.id
+                    WHERE
+                        ctx.id $ctxcondition AND
+                        ue.id IS NULL";
+            $this->totalotherusers = (int)$DB->count_records_sql($sql, $params);
+        }
+        return $this->totalotherusers;
+    }
+
+    /**
      * Gets all of the users enrolled in this course.
      *
      * If a filter was specificed this will be the users who were enrolled
@@ -154,6 +200,49 @@
     }
 
     /**
+     * Gets and array of other users.
+     *
+     * Other users are users who have been assigned roles or inherited roles
+     * within this course but who have not been enrolled in the course
+     *
+     * @global moodle_database $DB
+     * @param string $sort
+     * @param string $direction
+     * @param int $page
+     * @param int $perpage
+     * @return array
+     */
+    public function get_other_users($sort, $direction='ASC', $page=0, $perpage=25) {
+        global $DB;
+        if ($direction !== 'ASC') {
+            $direction = 'DESC';
+        }
+        $key = md5("$sort-$direction-$page-$perpage");
+        if (!array_key_exists($key, $this->otherusers)) {
+            list($ctxcondition, $params) = $DB->get_in_or_equal(get_parent_contexts($this->context, true), SQL_PARAMS_NAMED, 'ctx00');
+            $params['courseid'] = $this->course->id;
+            $params['cid'] = $this->course->id;
+            $sql = "SELECT ra.id as raid, ra.contextid, ra.component, ctx.contextlevel, ra.roleid, u.*, ue.lastseen
+                    FROM {role_assignments} ra
+                    JOIN {user} u ON u.id = ra.userid
+                    JOIN {context} ctx ON ra.contextid = ctx.id
+                    LEFT JOIN (
+                        SELECT ue.id, ue.userid, ul.timeaccess AS lastseen
+                        FROM {user_enrolments} ue
+                        LEFT JOIN {enrol} e ON e.id=ue.enrolid
+                        LEFT JOIN {user_lastaccess} ul ON (ul.courseid = e.courseid AND ul.userid = ue.userid)
+                        WHERE e.courseid = :courseid
+                    ) ue ON ue.userid=u.id
+                    WHERE
+                        ctx.id $ctxcondition AND
+                        ue.id IS NULL
+                    ORDER BY u.$sort $direction, ctx.depth DESC";
+            $this->otherusers[$key] = $DB->get_records_sql($sql, $params, $page*$perpage, $perpage);
+        }
+        return $this->otherusers[$key];
+    }
+
+    /**
      * Gets an array of the users that can be enrolled in this course.
      *
      * @global moodle_database $DB
@@ -205,6 +294,58 @@
     }
 
     /**
+     * Searches other users and returns paginated results
+     *
+     * @global moodle_database $DB
+     * @param string $search
+     * @param bool $searchanywhere
+     * @param int $page Starting at 0
+     * @param int $perpage
+     * @return array
+     */
+    public function search_other_users($search='', $searchanywhere=false, $page=0, $perpage=25) {
+        global $DB;
+
+        // Add some additional sensible conditions
+        $tests = array("u.username <> 'guest'", 'u.deleted = 0', 'u.confirmed = 1');
+        $params = array();
+        if (!empty($search)) {
+            $conditions = array('u.firstname','u.lastname');
+            $ilike = ' ' . $DB->sql_ilike();
+            if ($searchanywhere) {
+                $searchparam = '%' . $search . '%';
+            } else {
+                $searchparam = $search . '%';
+            }
+            $i = 0;
+            foreach ($conditions as &$condition) {
+                $condition .= "$ilike :con{$i}00";
+                $params["con{$i}00"] = $searchparam;
+                $i++;
+            }
+            $tests[] = '(' . implode(' OR ', $conditions) . ')';
+        }
+        $wherecondition = implode(' AND ', $tests);
+        
+
+        $fields      = 'SELECT u.id, u.firstname, u.lastname, u.username, u.email, u.lastaccess, u.picture, u.imagealt, '.user_picture::fields('u');;
+        $countfields = 'SELECT COUNT(u.id)';
+        $sql   = " FROM {user} u
+                  WHERE $wherecondition
+                        AND u.id NOT IN (
+                           SELECT u.id
+                             FROM {role_assignments} r, {user} u
+                            WHERE r.contextid = :contextid
+                                  AND u.id = r.userid)";
+        $order = ' ORDER BY lastname ASC, firstname ASC';
+
+        $params['contextid'] = $this->context->id;
+        $totalusers = $DB->count_records_sql($countfields . $sql, $params);
+        $availableusers = $DB->get_records_sql($fields . $sql . $order, $params, $page*$perpage, $perpage);
+        return array('totalusers'=>$totalusers, 'users'=>$availableusers);
+    }
+
+    /**
      * Gets an array containing some SQL to user for when selecting, params for
      * that SQL, and the filter that was used in constructing the sql.
      *
@@ -373,6 +514,9 @@
         try {
             role_unassign($roleid, $user->id, $this->context->id, '', NULL);
         } catch (Exception $e) {
+            if (is_defined('AJAX_SCRIPT')) {
+                throw $e;
+            }
             return false;
         }
         return true;
@@ -388,6 +532,9 @@
     public function assign_role_to_user($roleid, $userid) {
         require_capability('moodle/role:assign', $this->context);
         if (!array_key_exists($roleid, $this->get_assignable_roles())) {
+            if (is_defined('AJAX_SCRIPT')) {
+                throw new moodle_;
+            }
             return false;
         }
         return role_assign($roleid, $userid, $this->context->id, '', NULL);
@@ -561,6 +708,69 @@
     }
 
     /**
+     * Gets an array of other users in this course ready for display.
+     *
+     * Other users are users who have been assigned or inherited roles within this
+     * course but have not been enrolled.
+     *
+     * @param core_enrol_renderer $renderer
+     * @param moodle_url $pageurl
+     * @param string $sort
+     * @param string $direction ASC | DESC
+     * @param int $page Starting from 0
+     * @param int $perpage
+     * @return array
+     */
+    public function get_other_users_for_display(core_enrol_renderer $renderer, moodle_url $pageurl, $sort, $direction, $page, $perpage) {
+        
+        $userroles = $this->get_other_users($sort, $direction, $page, $perpage);
+        $roles = $this->get_all_roles();
+
+        $courseid   = $this->get_course()->id;
+        $context    = $this->get_context();
+
+        $users = array();
+        foreach ($userroles as $userrole) {
+            if (!array_key_exists($userrole->id, $users)) {
+                $users[$userrole->id] = array(
+                    'userid'     => $userrole->id,
+                    'courseid'   => $courseid,
+                    'picture'    => new user_picture($userrole),
+                    'firstname'  => fullname($userrole, true),
+                    'email'      => $userrole->email,
+                    'roles'      => array()
+                );
+            }
+            $a = new stdClass;
+            $a->role = $roles[$userrole->roleid]->localname;
+            $changeable = ($userrole->component == '');
+            if ($userrole->contextid == $this->context->id) {
+                $roletext = get_string('rolefromthiscourse', 'enrol', $a);
+            } else {
+                $changeable = false;
+                switch ($userrole->contextlevel) {
+                    case CONTEXT_COURSE :
+                        // Meta course
+                        $roletext = get_string('rolefrommetacourse', 'enrol', $a);
+                        break;
+                    case CONTEXT_COURSECAT :
+                        $roletext = get_string('rolefromcategory', 'enrol', $a);
+                        break;
+                    case CONTEXT_SYSTEM:
+                    default:
+                        $roletext = get_string('rolefromsystem', 'enrol', $a);
+                        break;
+                }
+            }
+            $users[$userrole->id]['roles'][$userrole->roleid] = array(
+                'text' => $roletext,
+                'unchangeable' => !$changeable
+            );
+        }
+        return $users;
+    }
+
+    /**
      * Gets all the cohorts the user is able to view.
      *
      * @global moodle_database $DB
@@ -758,3 +968,17 @@
         return $userdetails;
     }
 }
+
+class enrol_ajax_exception extends moodle_exception {
+    /**
+     * Constructor
+     * @param string $errorcode The name of the string from error.php to print
+     * @param string $module name of module
+     * @param string $link The url where the user will be prompted to continue. If no url is provided the user will be directed to the site index page.
+     * @param object $a Extra words and phrases that might be required in the error string
+     * @param string $debuginfo optional debugging information
+     */
+    public function __construct($errorcode, $link = '', $a = NULL, $debuginfo = null) {
+        parent::__construct($errorcode, 'enrol', $link, $a, $debuginfo);
+    }
+}
\ No newline at end of file
Index: moodle/enrol/otherusers.php
--- moodle/enrol/otherusers.php Base (1.1)
+++ moodle/enrol/otherusers.php Locally Modified (Based On 1.1)
@@ -24,17 +24,14 @@
  */
 
 require('../config.php');
+require_once("$CFG->dirroot/enrol/locallib.php");
+require_once("$CFG->dirroot/enrol/renderer.php");
+require_once("$CFG->dirroot/group/lib.php");
 
 $id      = required_param('id', PARAM_INT); // course id
 $action  = optional_param('action', '', PARAM_ACTION);
-$confirm = optional_param('confirm', 0, PARAM_BOOL);
+$filter  = optional_param('ifilter', 0, PARAM_INT);
 
-$ifilter = optional_param('ifilter', 0, PARAM_INT); // only one instance
-$page    = optional_param('page', 0, PARAM_INT);
-$perpage = optional_param('perpage', 20, PARAM_INT);
-$sort    = optional_param('sort', 'lastname', PARAM_ALPHA);
-$dir     = optional_param('dir', 'ASC', PARAM_ALPHA);
-
 $course = $DB->get_record('course', array('id'=>$id), '*', MUST_EXIST);
 $context = get_context_instance(CONTEXT_COURSE, $course->id, MUST_EXIST);
 
@@ -45,47 +42,59 @@
     redirect("$CFG->wwwroot/");
 }
 
-$instances = enrol_get_instances($course->id, true);
-$plugins   = enrol_get_plugins(true);
-$inames    = array();
-foreach ($instances as $k=>$i) {
-    if (!isset($plugins[$i->enrol])) {
-        // weird, some broken stuff in plugin
-        unset($instances[$k]);
-        continue;
-    }
-    $inames[$k] = $plugins[$i->enrol]->get_instance_name($i);
-}
+$PAGE->set_url('/enrol/otherusers.php', array('id'=>$course->id));
+$PAGE->set_pagelayout('admin');
 
-// validate paging params
-if ($ifilter != 0 and !isset($instances[$ifilter])) {
-    $ifilter = 0;
-}
-if ($perpage < 3) {
-    $perpage = 3;
-}
-if ($page < 0) {
-    $page = 0;
-}
-if (!in_array($dir, array('ASC', 'DESC'))) {
-    $dir = 'ASC';
-}
-if (!in_array($sort, array('firstname', 'lastname', 'email', 'lastseen'))) {
-    $dir = 'lastname';
-}
+$manager = new course_enrolment_manager($course, $filter);
+$table = new course_enrolment_other_users_table($manager, $PAGE->url);
+$pageurl = new moodle_url($PAGE->url, $manager->get_url_params()+$table->get_url_params());
 
-$PAGE->set_url('/enrol/notenrolled.php', array('id'=>$course->id, 'page'=>$page, 'sort'=>$sort, 'dir'=>$dir, 'perpage'=>$perpage, 'ifilter'=>$ifilter));
-$PAGE->set_pagelayout('admin');
+/***
+ * Actions will go here
+ */
 
-//lalala- nav hack
-navigation_node::override_active_url(new moodle_url('/enrol/otherusers.php', array('id'=>$course->id)));
+/*$fields = array(
+    'userdetails' => array (
+        'picture' => false,
+        'firstname' => get_string('firstname'),
+        'lastname' => get_string('lastname'),
+        'email' => get_string('email')
+    ),
+    'lastseen' => get_string('lastaccess'),
+    'role' => array(
+        'roles' => get_string('roles', 'role'),
+        'context' => get_string('context')
+    )
+);*/
+$fields = array(
+    'userdetails' => array (
+        'picture' => false,
+        'firstname' => get_string('firstname'),
+        'lastname' => get_string('lastname'),
+        'email' => get_string('email')
+    ),
+    'lastseen' => get_string('lastaccess'),
+    'role' => get_string('roles', 'role')
+);
+$table->set_fields($fields);
 
-echo $OUTPUT->header();
+//$users = $manager->get_other_users($table->sort, $table->sortdirection, $table->page, $table->perpage);
 
-//TODO: MDL-22854 add some new role related UI for users that are not enrolled but still got a role somehow in this course context
+$renderer = $PAGE->get_renderer('core_enrol');
+$canassign = has_capability('moodle/role:assign', $manager->get_context());
+$users = $manager->get_other_users_for_display($renderer, $pageurl, $table->sort, $table->sortdirection, $table->page, $table->perpage);
+$assignableroles = $manager->get_assignable_roles();
+foreach ($users as $userid=>&$user) {
+    $user['picture'] = $OUTPUT->render($user['picture']);
+    $user['role'] = $renderer->user_roles_and_actions($userid, $user['roles'], $assignableroles, $canassign, $pageurl);
+}
 
-notify('This page is not implemented yet, sorry. See MDL-21782 in our tracker for more information.');
+$table->set_total_users($manager->get_total_other_users());
+$table->set_users($users);
 
-echo $OUTPUT->single_button(new moodle_url('/admin/roles/assign.php', array('contextid'=>$context->id)), 'Continue to old Assign roles UI');
+$PAGE->set_title($course->fullname.': '.get_string('totalotherusers', 'enrol', $manager->get_total_other_users()));
+$PAGE->set_heading($PAGE->title);
 
+echo $OUTPUT->header();
+echo $renderer->render($table);
 echo $OUTPUT->footer();
Index: moodle/enrol/renderer.php
--- moodle/enrol/renderer.php Base (1.3)
+++ moodle/enrol/renderer.php Locally Modified (Based On 1.3)
@@ -37,7 +37,7 @@
      * @param course_enrolment_table $table
      * @return string
      */
-    protected function render_course_enrolment_table(course_enrolment_table $table) {
+    protected function render_course_enrolment_users_table(course_enrolment_users_table $table) {
         $content = '';
         $enrolmentselector = $table->get_enrolment_selector($this->page);
         if ($enrolmentselector) {
@@ -63,6 +63,29 @@
     }
 
     /**
+     * Renders a course enrolment table
+     *
+     * @param course_enrolment_table $table
+     * @return string
+     */
+    protected function render_course_enrolment_other_users_table(course_enrolment_other_users_table $table) {
+        $content = '';
+        $searchbutton = $table->get_user_search_button($this->page);
+        if ($searchbutton) {
+            $content .= $this->output->render($searchbutton);
+        }
+        $content .= html_writer::tag('div', get_string('otheruserdesc', 'enrol'), array('class'=>'otherusersdesc'));
+        $content .= $this->output->render($table->get_paging_bar());
+        $content .= html_writer::table($table);
+        $content .= $this->output->render($table->get_paging_bar());
+        $searchbutton = $table->get_user_search_button($this->page);
+        if ($searchbutton) {
+            $content .= $this->output->render($searchbutton);
+        }
+        return $content;
+    }
+
+    /**
      * Generates HTML to display the users roles and any available actions
      *
      * @param int $userid
@@ -303,7 +326,12 @@
      */
     protected $fields = array();
 
-    protected static $sortablefields = array('firstname', 'lastname', 'email', 'lastaccess');
+    /**
+     * An array of sortable fields
+     * @static
+     * @var array
+     */
+    protected static $sortablefields = array('firstname', 'lastname', 'email');
 
     /**
      * Constructs the table
@@ -332,7 +360,6 @@
         }
 
         $this->id = html_writer::random_id();
-        $this->set_total_users($manager->get_total_users());
     }
 
     /**
@@ -455,8 +482,20 @@
             $this->data[] = $row;
         }
         if (has_capability('moodle/role:assign', $this->manager->get_context())) {
-            $arguments = array(array('containerId'=>$this->id, 'userIds'=>array_keys($users), 'courseId'=>$this->manager->get_course()->id));
-            $page->requires->yui_module(array('moodle-enrol-rolemanager', 'moodle-enrol-rolemanager-skin'), 'M.enrol.rolemanager.init', $arguments);
+            $page->requires->strings_for_js(array(
+                'assignroles',
+                'confirmunassign',
+                'confirmunassigntitle',
+                'confirmunassignyes',
+                'confirmunassignno'
+            ), 'role');
+            $modules = array('moodle-enrol-rolemanager', 'moodle-enrol-rolemanager-skin');
+            $function = 'M.enrol.rolemanager.init';
+            $arguments = array(
+                'containerId'=>$this->id,
+                'userIds'=>array_keys($users),
+                'courseId'=>$this->manager->get_course()->id);
+            $page->requires->yui_module($modules, $function, array($arguments));
         }
     }
     
@@ -504,20 +543,24 @@
             self::SORTDIRECTIONVAR => $this->sortdirection
         );
     }
+}
 
     /**
-     * Gets the enrolment type filter control for this table
+ * Table control used for enrolled users
      *
-     * @return single_select
+ * @copyright 2010 Sam Hemelryk
+ * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
      */
-    public function get_enrolment_type_filter() {
-        $url = new moodle_url($this->pageurl, $this->manager->get_url_params()+$this->get_url_params());
-        $selector = new single_select($url, 'ifilter', array(0=>get_string('all')) + (array)$this->manager->get_enrolment_instance_names(), $this->manager->get_enrolment_filter(), array());
-        $selector->set_label( get_string('enrolmentinstances', 'enrol'));
-        return $selector;
-    }
+class course_enrolment_users_table extends course_enrolment_table {
 
     /**
+     * An array of sortable fields
+     * @static
+     * @var array
+     */
+    protected static $sortablefields = array('firstname', 'lastname', 'email', 'lastaccess');
+
+    /**
      * Returns a button to enrol cohorts or thier users
      *
      * @staticvar int $count
@@ -558,12 +601,14 @@
                 }
             }
             
-            $arguments = array(array(
+            $modules = array('moodle-enrol-quickcohortenrolment', 'moodle-enrol-quickcohortenrolment-skin');
+            $function = 'M.enrol.quickcohortenrolment.init';
+            $arguments = array(
                 'courseid'=>$course->id,
                 'ajaxurl'=>'/enrol/ajax.php',
                 'url'=>$url->out(false),
-                'manualEnrolment'=>$hasmanualinstance));
-            $page->requires->yui_module(array('moodle-enrol-quickcohortenrolment', 'moodle-enrol-quickcohortenrolment-skin'), 'M.enrol.quickcohortenrolment.init', $arguments);
+                'manualEnrolment'=>$hasmanualinstance);
+            $page->requires->yui_module($modules, $function, array($arguments));
         }
         return $control;
     }
@@ -636,18 +681,99 @@
                 $page->requires->string_for_js('assignroles', 'role');
                 $page->requires->string_for_js('startingfrom', 'moodle');
 
-
-                $arguments = array(array(
+                $modules = array('moodle-enrol-enrolmentmanager', 'moodle-enrol-enrolmentmanager-skin');
+                $function = 'M.enrol.enrolmentmanager.init';
+                $arguments = array(
                     'instances'=>$arguments,
                     'courseid'=>$course->id,
                     'ajaxurl'=>'/enrol/ajax.php',
                     'url'=>$url->out(false),
                     'optionsStartDate'=>$startdateoptions,
-                    'defaultRole'=>get_config('enrol_manual', 'roleid')));
-                $page->requires->yui_module(array('moodle-enrol-enrolmentmanager', 'moodle-enrol-enrolmentmanager-skin'), 'M.enrol.enrolmentmanager.init', $arguments);
+                    'defaultRole'=>get_config('enrol_manual', 'roleid'));
+                $page->requires->yui_module($modules, $function, array($arguments));
             }
             return $control;
         }
         return null;
     }
+    /**
+     * Gets the enrolment type filter control for this table
+     *
+     * @return single_select
+     */
+    public function get_enrolment_type_filter() {
+        $url = new moodle_url($this->pageurl, $this->manager->get_url_params()+$this->get_url_params());
+        $selector = new single_select($url, 'ifilter', array(0=>get_string('all')) + (array)$this->manager->get_enrolment_instance_names(), $this->manager->get_enrolment_filter(), array());
+        $selector->set_label( get_string('enrolmentinstances', 'enrol'));
+        return $selector;
 }
+}
+
+/**
+ * Table used for other users
+ *
+ * Other users are users who have roles but are not enrolled.
+ *
+ * @copyright 2010 Sam Hemelryk
+ * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class course_enrolment_other_users_table extends course_enrolment_table {
+
+    /**
+     * Constructs the table
+     *
+     * @param course_enrolment_manager $manager
+     * @param moodle_url $pageurl
+     */
+    public function __construct(course_enrolment_manager $manager, moodle_url $pageurl) {
+        parent::__construct($manager, $pageurl);
+        $this->attributes = array('class'=>'userenrolment otheruserenrolment');
+    }
+
+    /**
+     * Gets a button to search users and assign them roles in the course.
+     *
+     * @staticvar int $count
+     * @param int $page
+     * @return single_button
+     */
+    public function get_user_search_button($page) {
+        global $CFG;
+        static $count = 0;
+        if (!has_capability('moodle/role:assign', $this->manager->get_context())) {
+            return false;
+        }
+        $count++;
+        $url = new moodle_url('/'.$CFG->admin.'/roles/assign.php', array('contextid'=>$this->manager->get_context()->id, 'sesskey'=>sesskey()));
+        $control = new single_button($url, get_string('assignroles', 'role'), 'get');
+        $control->class = 'singlebutton assignuserrole instance'.$count;
+        if ($count == 1) {
+            $page->requires->strings_for_js(array(
+                    'ajaxoneuserfound',
+                    'ajaxxusersfound',
+                    'ajaxnext25',
+                    'enrol',
+                    'enrolmentoptions',
+                    'enrolusers',
+                    'errajaxfailedenrol',
+                    'errajaxsearch',
+                    'none',
+                    'usersearch',
+                    'unlimitedduration',
+                    'startdatetoday',
+                    'durationdays',
+                    'enrolperiod'), 'enrol');
+            $page->requires->string_for_js('assignrole', 'role');
+
+            $modules = array('moodle-enrol-otherusersmanager', 'moodle-enrol-otherusersmanager-skin');
+            $function = 'M.enrol.otherusersmanager.init';
+            $url = new moodle_url($this->pageurl, $this->manager->get_url_params()+$this->get_url_params());
+            $arguments = array(
+                'courseId'=> $this->manager->get_course()->id,
+                'ajaxUrl' => '/enrol/ajax.php',
+                'url' => $url->out(false));
+            $page->requires->yui_module($modules, $function, array($arguments));
+        }
+        return $control;
+    }
+}
Index: moodle/enrol/users.php
--- moodle/enrol/users.php Base (1.9)
+++ moodle/enrol/users.php Locally Modified (Based On 1.9)
@@ -46,7 +46,7 @@
 $PAGE->set_pagelayout('admin');
 
 $manager = new course_enrolment_manager($course, $filter);
-$table = new course_enrolment_table($manager, $PAGE->url);
+$table = new course_enrolment_users_table($manager, $PAGE->url);
 $pageurl = new moodle_url($PAGE->url, $manager->get_url_params()+$table->get_url_params());
 
 // Check if there is an action to take
@@ -226,6 +226,7 @@
     $user['group'] = $renderer->user_groups_and_actions($userid, $user['groups'], $manager->get_all_groups(), has_capability('moodle/course:managegroups', $manager->get_context()), $pageurl);
     $user['enrol'] = $renderer->user_enrolments_and_actions($userid, $user['enrolments'], $pageurl);
 }
+$table->set_total_users($manager->get_total_users());
\ No newline at end of file
 $table->set_users($users);
 
 $PAGE->set_title($PAGE->course->fullname.': '.get_string('totalenrolledusers', 'enrol', $manager->get_total_users()));
Index: moodle/enrol/yui/enrolmentmanager/enrolmentmanager.js
--- moodle/enrol/yui/enrolmentmanager/enrolmentmanager.js Base (1.2)
+++ moodle/enrol/yui/enrolmentmanager/enrolmentmanager.js Locally Modified (Based On 1.2)
@@ -193,7 +193,7 @@
                             var roles = Y.JSON.parse(outcome.responseText);
                             this.set(UEP.ASSIGNABLEROLES, roles.response);
                         } catch (e) {
-                            Y.fail(UEP.NAME+': Failed to load assignable roles');
+                            new M.core.exception(e);
                         }
                         this.getAssignableRoles = function() {
                             this.fire('assignablerolesloaded');
@@ -298,8 +298,11 @@
         processSearchResults : function(tid, outcome, args) {
             try {
                 var result = Y.JSON.parse(outcome.responseText);
+                if (result.error) {
+                    return new M.core.ajaxException(result);
+                }
             } catch (e) {
-                Y.fail(UEP.NAME+': Failed to parse user search response  ['+e.linenum+':'+e.message+']');
+                new M.core.exception(e);
             }
             if (!result.success) {
                 this.setContent = M.str.enrol.errajaxsearch;
@@ -364,16 +367,16 @@
                     complete : function(tid, outcome, args) {
                         try {
                             var result = Y.JSON.parse(outcome.responseText);
-                        } catch (e) {
-                            Y.fail(UEP.NAME+': Failed to parse user search response  ['+e.linenum+':'+e.message+']');
-                        }
-                        if (result.success) {
+                            if (result.error) {
+                                return new M.core.ajaxException(result);
+                            } else {
                             args.userNode.addClass(CSS.ENROLLED);
                             args.userNode.one('.'+CSS.ENROL).remove();
                             this.set(UEP.REQUIREREFRESH, true);
-                        } else {
-                            alert(M.str.enrol.errajaxfailedenrol);
                         }
+                        } catch (e) {
+                            new M.core.exception(e);
+                        }
                     },
                     end : this.removeLoading
                 },
@@ -489,4 +492,4 @@
         }
     }
 
-}, '@VERSION@', {requires:['base','node', 'overlay', 'io', 'test', 'json-parse', 'event-delegate', 'dd-plugin', 'event-key']});
\ No newline at end of file
+}, '@VERSION@', {requires:['base','node', 'overlay', 'io', 'test', 'json-parse', 'event-delegate', 'dd-plugin', 'event-key', 'moodle-enrol-notification']});
\ No newline at end of file
Index: moodle/enrol/yui/notification/assets/skins/sam/notification.css
--- moodle/enrol/yui/notification/assets/skins/sam/notification.css No Base Revision
+++ moodle/enrol/yui/notification/assets/skins/sam/notification.css Locally New
@@ -0,0 +1,22 @@
+.moodle-dialogue-base .hidden,
+.moodle-dialogue-base .moodle-dialogue-hidden {display:none;}
+.moodle-dialogue-base .moodle-dialogue-lightbox {background-color:#AAA;position:absolute;top:0;left:0;width:100%;height:100%;}
+.moodle-dialogue-base .moodle-dialogue {background-color:#666;border:0 solid #666;border-right-width:3px;border-bottom-width:3px;}
+.moodle-dialogue-base .moodle-dialogue-wrap {background-color:#FFF;margin-top:-3px;margin-left:-3px;border:1px solid #555;}
+.moodle-dialogue-base .moodle-dialogue-hd {font-size:110%;color:inherit;font-weight:bold;text-align:left;padding:5px 6px;margin:0;border-bottom:1px solid #ccc;background-color:#f6f6f6;}
+.moodle-dialogue-base .closebutton {background-image:url(sprite.png);width:25px;height:15px;background-repeat:no-repeat;float:right;vertical-align:middle;display:inline-block;cursor:pointer;}
+.moodle-dialogue-base .moodle-dialogue-bd {padding:5px;}
+.moodle-dialogue-base .moodle-dialogue-fd {}
+
+.moodle-dialogue-confirm .confirmation-dialogue {text-align:center;}
+.moodle-dialogue-confirm .confirmation-message {margin:0.5em 1em;}
+.moodle-dialogue-confirm .confirmation-dialogue input {min-width:80px;text-align:center;}
+
+.moodle-dialogue-exception .moodle-exception-message {text-align:center;margin:1em;}
+.moodle-dialogue-exception .moodle-exception-param {margin-bottom:0.5em;}
+.moodle-dialogue-exception .moodle-exception-param label {width:150px;font-weight:bold;}
+.moodle-dialogue-exception .param-stacktrace label {display:block;background-color:#EEE;margin:0;padding:4px 1em;border:1px solid #ccc;border-bottom-width:0;}
+.moodle-dialogue-exception .param-stacktrace pre {display:block;border:1px solid #ccc;background-color:#fff;height:200px;overflow:auto;}
+.moodle-dialogue-exception .param-stacktrace .stacktrace-file {color:navy;display:inline-block;font-size:80%;margin:4px 0;}
+.moodle-dialogue-exception .param-stacktrace .stacktrace-line {color:#AA0000;display:inline-block;font-size:80%;width:50px;margin:4px 1em;}
+.moodle-dialogue-exception .param-stacktrace .stacktrace-call {color:#333;font-size:90%;padding-left:25px;margin-bottom:4px;padding-bottom:4px;border-bottom:1px solid #eee;}
\ No newline at end of file
Index: moodle/enrol/yui/notification/assets/skins/sam/sprite.png
MIME: application/octet-stream; encoding: Base64; length: 1002
iVBORw0KGgoAAAANSUhEUgAAABkAAAAPCAMAAAAmuJTXAAAAAXNSR0IArs4c
6QAAAwBQTFRF19jawcHB/v7+bW1t/Pz8+/v79fX1+vr69/f34+Pl5+jo7/Dw
Qm/Z5vH/3+Dg7Ozs4eHi8vLy9vb24OHi9fX2AAAA6+vs4eLj5/H/8fHy5fD/
9/f5QW7X8vT06+zsy+L/3+3/6Orq4O3/3Oz/4u7/0eb/+fn6M1u8x9//1ef/
xN3/P2rRhYWFz+P/1+j/3+Dh4/D/7e/v+vr75/L/2un/3t/g5ebm+fn5f39/
4ODh4uPjIiIi5ufoLz6s6urr2trb3Nzd0NHS5+jq19fYutj/7OztvsHC8fLy
9PT0xMXG3d3fs7W36Ojq+fr6MFa1LlKw9PX1QGzV1NXWQG3WOWHEuLu9ycrL
9fb2N1/CrK+wPWfOO2XLOWPI7O3t7+/vQGvU8PDx8PDw8PHx8fHx8vL0KEym
K06r7e3v5eXm9vb3zM7Q9jQ04XcbnZ2d7Ykb8dJYKDGTpcv/4XoSsbGx+by8
6Ks7lqrDys7p56Q96sAp6r036bol17Mo+AsLc3Nz68I1+ei26LI6boqs9UdH
lpaW6bc4+BUV88486Kcb+CQk81JHEw5L5pw/1AgBSUlJ5WgEoXMOLjec9ctM
5rIe4efv+GFe6JJC5poV534X5ubm1TEB5trB2qMNJCqRampq8dRGzHwK8Jo0
O0Ob9Y+PM0Os8bOHxJYWubrX8dVn9HV1+tCaRFmzGRtq+9XVLStr9uBT3E0E
+ufK5IoO14YG+Ne+gZm3ICSB+39/XH7K6XkU6HQOJSuH6Ojo91VV9mpqtJNI
9Mii4FkCzrFMhIfB98SA4mEN9bJVfn+srbHEUmO67o8prYYiHyR39eCMPFG2
/HF3nqPR5cpNpKvb++rf5nYu4e7/38l1/e/i61ZX7Ysh86M78JYs1jwg2caL
9np64XQRd3ST5M526goLTWjDzrZu+euo+cXF8vn/c4bO+9dQz7eH8ahh++1s
/v3028BN6pFh9tp9pKSlOk2y7S4vUW/GZmZmJkeg5ubn29zdv9r/pair2Nja
3N3f6PL/////////FVh3eAAAAAF0Uk5TAEDm2GYAAAABYktHRACIBR1IAAAA
CXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH2gcBBgsElflP/AAAAFZJREFU
GNNjYGDEDhgYGP9hB4zEyBSzAQm2YkyZYmYdtn9sOszFGDJAQR1+HZA0hmlA
qTqEBIoL+OuY6/ixuQCnHtz25ELdloupJ5cNThIdBhgyOMMaAFIZ83j7F2ns
AAAAAElFTkSuQmCC
Index: moodle/enrol/yui/notification/notification.js
--- moodle/enrol/yui/notification/notification.js No Base Revision
+++ moodle/enrol/yui/notification/notification.js Locally New
@@ -0,0 +1,374 @@
+YUI.add('moodle-enrol-notification', function(Y) {
+
+var DIALOGUE_NAME = 'Moodle dialogue',
+    DIALOGUE_PREFIX = 'moodle-dialogue',
+    CONFIRM_NAME = 'Moodle confirmation dialogue',
+    EXCEPTION_NAME = 'Moodle exception',
+    AJAXEXCEPTION_NAME = 'Moodle AJAX exception',
+    ALERT_NAME = 'Moodle alert',
+    C = Y.Node.create,
+    BASE = 'notificationBase',
+    LIGHTBOX = 'lightbox',
+    NODELIGHTBOX = 'nodeLightbox',
+    COUNT = 0,
+    CONFIRMYES = 'yesLabel',
+    CONFIRMNO = 'noLabel',
+    TITLE = 'title',
+    QUESTION = 'question',
+    CSS = {
+        BASE : 'moodle-dialogue-base',
+        WRAP : 'moodle-dialogue-wrap',
+        HEADER : 'moodle-dialogue-hd',
+        BODY : 'moodle-dialogue-bd',
+        CONTENT : 'moodle-dialogue-content',
+        FOOTER : 'moodle-dialogue-fd',
+        HIDDEN : 'hidden',
+        LIGHTBOX : 'moodle-dialogue-lightbox'
+    };
+
+var DIALOGUE = function(config) {
+    COUNT++;
+    var id = 'moodle-dialogue-'+COUNT;
+    config.notificationBase =
+        C('<div class="'+CSS.BASE+'">')
+            .append(C('<div class="'+CSS.LIGHTBOX+' '+CSS.HIDDEN+'"></div>'))
+            .append(C('<div id="'+id+'" class="'+CSS.WRAP+'"></div>')
+                .append(C('<div class="'+CSS.HEADER+' yui3-widget-hd"></div>'))
+                .append(C('<div class="'+CSS.BODY+' yui3-widget-bd"></div>'))
+                .append(C('<div class="'+CSS.CONTENT+' yui3-widget-ft"></div>')));
+    Y.one(document.body).append(config.notificationBase);
+    config.srcNode =    '#'+id;
+    config.width =      config.width || '400px';
+    config.visible =    config.visible || false;
+    config.center =     config.centered || true;
+    config.centered =   false;
+    DIALOGUE.superclass.constructor.apply(this, [config]);
+}
+Y.extend(DIALOGUE, Y.Overlay, {
+    initializer : function(config) {
+        this.set(NODELIGHTBOX, this.get(BASE).one('.'+CSS.LIGHTBOX).setStyle('opacity', 0.5));
+        this.after('visibleChange', this.visibilityChanged, this);
+        this.after('headerContentChange', function(e){
+            var h = (this.get('closeButton'))?this.get(BASE).one('.'+CSS.HEADER):false;
+            if (h && !h.one('.closebutton')) {
+                var c = C('<div class="closebutton"></div>');
+                c.on('click', this.hide, this);
+                h.append(c);
+            }
+        }, this);
+        this.render();
+        this.show();
+    },
+    visibilityChanged : function(e) {
+        switch (e.attrName) {
+            case 'visible':
+                if (this.get(LIGHTBOX)) {
+                    var l = this.get(NODELIGHTBOX);
+                    if (!e.prevVal && e.newVal) {
+                        l.setStyle('height',l.get('docHeight')+'px').removeClass(CSS.HIDDEN);
+                    } else if (e.prevVal && !e.newVal) {
+                        l.addClass(CSS.HIDDEN);
+                    }
+                }
+                if (this.get('center') && !e.prevVal && e.newVal) {
+                    this.centerDialogue();
+                }
+                break;
+        }
+    },
+    centerDialogue : function() {
+        var bb = this.get('boundingBox'), hidden = bb.hasClass(DIALOGUE_PREFIX+'-hidden');
+        if (hidden) {
+            bb.setStyle('top', '-1000px').removeClass(DIALOGUE_PREFIX+'-hidden');
+        }
+        var x = Math.round((bb.get('winWidth') - bb.get('offsetWidth'))/2);
+        var y = Math.round((bb.get('winHeight') - bb.get('offsetHeight'))/2)+Y.one(window).get('scrollTop');
+        if (hidden) {
+            bb.addClass(DIALOGUE_PREFIX+'-hidden');
+        }
+        bb.setStyle('left', x).setStyle('top', y);
+    }
+}, {
+    NAME : DIALOGUE_NAME,
+    CSS_PREFIX : DIALOGUE_PREFIX,
+    ATTRS : {
+        notificationBase : {
+
+        },
+        nodeLightbox : {
+            value : null
+        },
+        lightbox : {
+            validator : Y.Lang.isBoolean,
+            value : true
+        },
+        closeButton : {
+            validator : Y.Lang.isBoolean,
+            value : true
+        },
+        center : {
+            validator : Y.Lang.isBoolean,
+            value : true
+        }
+    }
+});
+
+var ALERT = function(config) {
+    config.closeButton = false;
+    ALERT.superclass.constructor.apply(this, [config]);
+}
+Y.extend(ALERT, DIALOGUE, {
+    _enterKeypress : null,
+    initializer : function(config) {
+        this.publish('complete');
+        var yes = C('<input type="button" value="'+this.get(CONFIRMYES)+'" />'),
+            content = C('<div class="confirmation-dialogue"></div>')
+                    .append(C('<div class="confirmation-message">'+this.get('message')+'</div>'))
+                    .append(C('<div class="confirmation-buttons"></div>')
+                            .append(yes));
+        this.get(BASE).addClass('moodle-dialogue-confirm');
+        this.setStdModContent(Y.WidgetStdMod.BODY, content, Y.WidgetStdMod.REPLACE);
+        this.setStdModContent(Y.WidgetStdMod.HEADER, this.get(TITLE), Y.WidgetStdMod.REPLACE);
+        this.after('destroyedChange', function(){this.get(BASE).remove();}, this);
+        this._enterKeypress = Y.on('key', this.submit, window, 'down:13', this);
+        yes.on('click', this.submit, this);
+    }, 
+    submit : function(e, outcome) {
+        this._enterKeypress.detach();
+        this.fire('complete');
+        this.hide();
+        this.destroy();
+    }
+}, {
+    NAME : ALERT_NAME,
+    CSS_PREFIX : DIALOGUE_PREFIX,
+    ATTRS : {
+        title : {
+            validator : Y.Lang.isString,
+            value : 'Alert'
+        },
+        message : {
+            validator : Y.Lang.isString,
+            value : 'Confirm'
+        },
+        yesLabel : {
+            validator : Y.Lang.isString,
+            setter : function(txt) {
+                if (!txt) {
+                    txt = 'Ok';
+                }
+                return txt;
+            },
+            value : 'Ok'
+        }
+    }
+});
+
+var CONFIRM = function(config) {
+    CONFIRM.superclass.constructor.apply(this, [config]);
+}
+Y.extend(CONFIRM, DIALOGUE, {
+    _enterKeypress : null,
+    _escKeypress : null,
+    initializer : function(config) {
+        this.publish('complete');
+        this.publish('complete-yes');
+        this.publish('complete-no');
+        var yes = C('<input type="button" value="'+this.get(CONFIRMYES)+'" />'),
+            no = C('<input type="button" value="'+this.get(CONFIRMNO)+'" />'),
+            content = C('<div class="confirmation-dialogue"></div>')
+                        .append(C('<div class="confirmation-message">'+this.get(QUESTION)+'</div>'))
+                        .append(C('<div class="confirmation-buttons"></div>')
+                            .append(yes)
+                            .append(no));
+        this.get(BASE).addClass('moodle-dialogue-confirm');
+        this.setStdModContent(Y.WidgetStdMod.BODY, content, Y.WidgetStdMod.REPLACE);
+        this.setStdModContent(Y.WidgetStdMod.HEADER, this.get(TITLE), Y.WidgetStdMod.REPLACE);
+        this.after('destroyedChange', function(){this.get(BASE).remove();}, this);
+        this._enterKeypress = Y.on('key', this.submit, window, 'down:13', this, true);
+        this._escKeypress = Y.on('key', this.submit, window, 'down:27', this, false);
+        yes.on('click', this.submit, this, true);
+        no.on('click', this.submit, this, false);
+    },
+    submit : function(e, outcome) {
+        this._enterKeypress.detach();
+        this._escKeypress.detach();
+        this.fire('complete', outcome);
+        if (outcome) {
+            this.fire('complete-yes');
+        } else {
+            this.fire('complete-no');
+        }
+        this.hide();
+        this.destroy();
+    }
+}, {
+    NAME : CONFIRM_NAME,
+    CSS_PREFIX : DIALOGUE_PREFIX,
+    ATTRS : {
+        yesLabel : {
+            validator : Y.Lang.isString,
+            value : 'Yes'
+        },
+        noLabel : {
+            validator : Y.Lang.isString,
+            value : 'No'
+        },
+        title : {
+            validator : Y.Lang.isString,
+            value : 'Confirm'
+        },
+        question : {
+            validator : Y.Lang.isString,
+            value : 'Are you sure?'
+        }
+    }
+});
+Y.augment(CONFIRM, Y.EventTarget);
+
+var EXCEPTION = function(config) {
+    config.width = config.width || (M.cfg.developerdebug)?Math.floor(Y.one(document.body).get('winWidth')/3)+'px':null;
+    config.closeButton = true;
+    EXCEPTION.superclass.constructor.apply(this, [config]);
+}
+Y.extend(EXCEPTION, DIALOGUE, {
+    _hideTimeout : null,
+    _keypress : null,
+    initializer : function(config) {
+        this.get(BASE).addClass('moodle-dialogue-exception');
+        this.setStdModContent(Y.WidgetStdMod.HEADER, config.name, Y.WidgetStdMod.REPLACE);
+        var content = C('<div class="moodle-exception"></div>')
+                    .append(C('<div class="moodle-exception-message">'+this.get('message')+'</div>'))
+                    .append(C('<div class="moodle-exception-param hidden param-filename"><label>File:</label> '+this.get('fileName')+'</div>'))
+                    .append(C('<div class="moodle-exception-param hidden param-linenumber"><label>Line:</label> '+this.get('lineNumber')+'</div>'))
+                    .append(C('<div class="moodle-exception-param hidden param-stacktrace"><label>Stack trace:</label> <pre>'+this.get('stack')+'</pre></div>'));
+        if (M.cfg.developerdebug) {
+            content.all('.moodle-exception-param').removeClass('hidden');
+        }
+        this.setStdModContent(Y.WidgetStdMod.BODY, content, Y.WidgetStdMod.REPLACE);
+
+        var self = this;
+        var delay = this.get('hideTimeoutDelay');
+        if (delay) {
+            this._hideTimeout = setTimeout(function(){self.hide();}, delay);
+        }
+        this.after('visibleChange', this.visibilityChanged, this);
+        this.after('destroyedChange', function(){this.get(BASE).remove();}, this);
+        this._keypress = Y.on('key', this.hide, window, 'down:13,27', this);
+        this.centerDialogue();
+    },
+    visibilityChanged : function(e) {
+        if (e.attrName == 'visible' && e.prevVal && !e.newVal) {
+            if (this._keypress) this._keypress.detach();
+            var self = this;
+            setTimeout(function(){self.destroy();}, 1000);
+        }
+    }
+}, {
+    NAME : EXCEPTION_NAME,
+    CSS_PREFIX : DIALOGUE_PREFIX,
+    ATTRS : {
+        message : {
+            value : ''
+        },
+        name : {
+            value : ''
+        },
+        fileName : {
+            value : ''
+        },
+        lineNumber : {
+            value : ''
+        },
+        stack : {
+            setter : function(str) {
+                var lines = str.split("\n");
+                var pattern = new RegExp('^(.+)@('+M.cfg.wwwroot+')?(.{0,75}).*:(\\d+)$');
+                for (var i in lines) {
+                    lines[i] = lines[i].replace(pattern, "<div class='stacktrace-line'>ln: $4</div><div class='stacktrace-file'>$3</div><div class='stacktrace-call'>$1</div>");
+                }
+                return lines.join('');
+            },
+            value : ''
+        },
+        hideTimeoutDelay : {
+            validator : Y.Lang.isNumber,
+            value : null
+        }
+    }
+});
+
+var AJAXEXCEPTION = function(config) {
+    config.name = config.name || 'Error';
+    config.closeButton = true;
+    AJAXEXCEPTION.superclass.constructor.apply(this, [config]);
+}
+Y.extend(AJAXEXCEPTION, DIALOGUE, {
+    _keypress : null,
+    initializer : function(config) {
+        this.get(BASE).addClass('moodle-dialogue-exception');
+        this.setStdModContent(Y.WidgetStdMod.HEADER, config.name, Y.WidgetStdMod.REPLACE);
+        var content = C('<div class="moodle-ajaxexception"></div>')
+                    .append(C('<div class="moodle-exception-message">'+this.get('error')+'</div>'))
+                    .append(C('<div class="moodle-exception-param hidden param-debuginfo"><label>URL:</label> '+this.get('reproductionlink')+'</div>'))
+                    .append(C('<div class="moodle-exception-param hidden param-debuginfo"><label>Debug info:</label> '+this.get('debuginfo')+'</div>'))
+                    .append(C('<div class="moodle-exception-param hidden param-stacktrace"><label>Stack trace:</label> <pre>'+this.get('stacktrace')+'</pre></div>'));
+        if (M.cfg.developerdebug) {
+            content.all('.moodle-exception-param').removeClass('hidden');
+        }
+        this.setStdModContent(Y.WidgetStdMod.BODY, content, Y.WidgetStdMod.REPLACE);
+
+        var self = this;
+        var delay = this.get('hideTimeoutDelay');
+        if (delay) {
+            this._hideTimeout = setTimeout(function(){self.hide();}, delay);
+        }
+        this.after('visibleChange', this.visibilityChanged, this);
+        this._keypress = Y.on('key', this.hide, window, 'down:13, 27', this);
+        this.centerDialogue();
+    },
+    visibilityChanged : function(e) {
+        if (e.attrName == 'visible' && e.prevVal && !e.newVal) {
+            var self = this;
+            this._keypress.detach();
+            setTimeout(function(){self.destroy();}, 1000);
+        }
+    }
+}, {
+    NAME : AJAXEXCEPTION_NAME,
+    CSS_PREFIX : DIALOGUE_PREFIX,
+    ATTRS : {
+        error : {
+            validator : Y.Lang.isString,
+            value : 'Unknown error'
+        },
+        debuginfo : {
+            value : null
+        },
+        stacktrace : {
+            value : null
+        },
+        reproductionlink : {
+            setter : function(link) {
+                if (link !== null) {
+                    link = '<a href="'+link+'">'+link.replace(M.cfg.wwwroot, '')+'</a>';
+                }
+                return link;
+            },
+            value : null
+        },
+        hideTimeoutDelay : {
+            validator : Y.Lang.isNumber,
+            value : null
+        }
+    }
+});
+
+M.core = M.core || {};
+M.core.dialogue = DIALOGUE;
+M.core.alert = ALERT;
+M.core.confirm = CONFIRM;
+M.core.exception = EXCEPTION;
+M.core.ajaxException = AJAXEXCEPTION;
+
+}, '@VERSION@', {requires:['base','node','overlay','event-key', 'moodle-enrol-notification-skin']});
\ No newline at end of file
Index: moodle/enrol/yui/otherusersmanager/assets/skins/sam/otherusersmanager.css
--- moodle/enrol/yui/otherusersmanager/assets/skins/sam/otherusersmanager.css No Base Revision
+++ moodle/enrol/yui/otherusersmanager/assets/skins/sam/otherusersmanager.css Locally New
@@ -0,0 +1,64 @@
+/**************************************
+
+Structure of the other user role assignment panel
+
+.other-user-manager-panel(.visible)
+    .oump-wrap
+        .oump-header
+        .oump-content
+            .oump-ajax-content
+                .oump-search-results
+                    .oump-total-users
+                    .oump-users
+                        .oump-user.clearfix(.odd|.even)(.enrolled)
+                            .count
+                            .oump-user-details
+                                .oump-user-picture
+                                .oump-user-specifics
+                                    .oump-user-fullname
+                                    .oump-user-email
+                                .oump-role-options
+                                    .label
+                                    .oump-assignable-role
+                    .oump-more-results
+            .oump-loading-lightbox(.hidden)
+                .loading-icon
+        .oump-footer
+            .oump-search
+                input
+
+**************************************/
+
+.other-user-manager-panel {width:400px;background-color:#666;position:absolute;top:10%;left:10%;border:1px solid #666;border-width:0 5px 5px 0;}
+.other-user-manager-panel.hidden {display:none;}
+.other-user-manager-panel .oump-wrap {margin-top:-5px;margin-left:-5px;background-color:#FFF;border:1px solid #999;height:inherit;}
+
+.other-user-manager-panel .oump-header {background-color:#eee;padding:1px;}
+.other-user-manager-panel .oump-header h2 {margin:3px 1em 0.5em 1em;font-size:1em;}
+.other-user-manager-panel .oump-header .oump-panel-close {width:25px;height:15px;position:absolute;top:2px;right:1em;cursor:pointer;background:url("sprite.png") no-repeat scroll 0 0 transparent;}
+
+.other-user-manager-panel .oump-content {text-align:center;position:relative;width:100%;border-top:1px solid #999;border-bottom:1px solid #999;}
+.other-user-manager-panel .oump-ajax-content {height:375px;overflow:auto;}
+.other-user-manager-panel .oump-search-results .oump-total-users {background-color:#eee;padding:5px;border-bottom:1px solid #BBB;font-size:7pt;font-weight: bold;}
+
+.other-user-manager-panel .oump-search-results .oump-user {width:100%;text-align:left;font-size:9pt;background-color:#ddd;border-bottom:1px solid #aaa;}
+.other-user-manager-panel .oump-search-results .oump-user .oump-user-details {background-color:#fff;margin-left:25px;border-left:1px solid #bbb;}
+.other-user-manager-panel .oump-search-results .oump-user.odd .oump-user-details {background-color:#f9f9f9;}
+.other-user-manager-panel .oump-search-results .oump-user .count {width:20px;font-size:7pt;line-height:100%;text-align:right;float:left;padding:5px 5px 2px 2px}
+.other-user-manager-panel .oump-search-results .oump-user .oump-user-details .oump-user-picture {display:inline-block;margin:3px;}
+.other-user-manager-panel .oump-search-results .oump-user .oump-user-details .oump-user-specifics {width:250px;display:inline-block;margin:3px;vertical-align:top;}
+.other-user-manager-panel .oump-search-results .oump-user .oump-user-details .oump-role-options {font-size:8pt;margin-top:2px;text-align:right;margin-right:2px;}
+.other-user-manager-panel .oump-search-results .oump-user .oump-user-details .oump-role-options .oump-assignable-role {display:inline-block;margin:0;padding:3px 4px;cursor:pointer;}
+.other-user-manager-panel .oump-search-results .oump-user.assignment-in-progress .oump-assignable-role {color:#666;cursor:default;}
+.other-user-manager-panel .oump-search-results .oump-more-results {background-color:#eee;padding:5px;cursor:pointer;}
+.other-user-manager-panel .oump-search-results .oump-user.oump-has-all-roles {background-color:#CCC;}
+.other-user-manager-panel .oump-search-results .oump-user.oump-has-all-roles .count {width:40px;}
+
+.other-user-manager-panel .oump-loading-lightbox {position:absolute;width:100%;height:100%;top:0;left:0;background-color:#FFF;min-width:50px;min-height:50px;}
+.other-user-manager-panel .oump-loading-lightbox.hidden {display:none;}
+.other-user-manager-panel .oump-loading-lightbox .loading-icon {margin:auto;vertical-align:middle;margin-top:125px;}
+
+.other-user-manager-panel .oump-footer {padding:3px;background-color:#ddd;}
+.other-user-manager-panel .oump-search {margin:3px;}
+.other-user-manager-panel .oump-search label {padding-right:8px;}
+.other-user-manager-panel .oump-search input {width:70%;}
Index: moodle/enrol/yui/otherusersmanager/assets/skins/sam/sprite.png
MIME: application/octet-stream; encoding: Base64; length: 1002
iVBORw0KGgoAAAANSUhEUgAAABkAAAAPCAMAAAAmuJTXAAAAAXNSR0IArs4c
6QAAAwBQTFRF19jawcHB/v7+bW1t/Pz8+/v79fX1+vr69/f34+Pl5+jo7/Dw
Qm/Z5vH/3+Dg7Ozs4eHi8vLy9vb24OHi9fX2AAAA6+vs4eLj5/H/8fHy5fD/
9/f5QW7X8vT06+zsy+L/3+3/6Orq4O3/3Oz/4u7/0eb/+fn6M1u8x9//1ef/
xN3/P2rRhYWFz+P/1+j/3+Dh4/D/7e/v+vr75/L/2un/3t/g5ebm+fn5f39/
4ODh4uPjIiIi5ufoLz6s6urr2trb3Nzd0NHS5+jq19fYutj/7OztvsHC8fLy
9PT0xMXG3d3fs7W36Ojq+fr6MFa1LlKw9PX1QGzV1NXWQG3WOWHEuLu9ycrL
9fb2N1/CrK+wPWfOO2XLOWPI7O3t7+/vQGvU8PDx8PDw8PHx8fHx8vL0KEym
K06r7e3v5eXm9vb3zM7Q9jQ04XcbnZ2d7Ykb8dJYKDGTpcv/4XoSsbGx+by8
6Ks7lqrDys7p56Q96sAp6r036bol17Mo+AsLc3Nz68I1+ei26LI6boqs9UdH
lpaW6bc4+BUV88486Kcb+CQk81JHEw5L5pw/1AgBSUlJ5WgEoXMOLjec9ctM
5rIe4efv+GFe6JJC5poV534X5ubm1TEB5trB2qMNJCqRampq8dRGzHwK8Jo0
O0Ob9Y+PM0Os8bOHxJYWubrX8dVn9HV1+tCaRFmzGRtq+9XVLStr9uBT3E0E
+ufK5IoO14YG+Ne+gZm3ICSB+39/XH7K6XkU6HQOJSuH6Ojo91VV9mpqtJNI
9Mii4FkCzrFMhIfB98SA4mEN9bJVfn+srbHEUmO67o8prYYiHyR39eCMPFG2
/HF3nqPR5cpNpKvb++rf5nYu4e7/38l1/e/i61ZX7Ysh86M78JYs1jwg2caL
9np64XQRd3ST5M526goLTWjDzrZu+euo+cXF8vn/c4bO+9dQz7eH8ahh++1s
/v3028BN6pFh9tp9pKSlOk2y7S4vUW/GZmZmJkeg5ubn29zdv9r/pair2Nja
3N3f6PL/////////FVh3eAAAAAF0Uk5TAEDm2GYAAAABYktHRACIBR1IAAAA
CXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH2gcBBgsElflP/AAAAFZJREFU
GNNjYGDEDhgYGP9hB4zEyBSzAQm2YkyZYmYdtn9sOszFGDJAQR1+HZA0hmlA
qTqEBIoL+OuY6/ixuQCnHtz25ELdloupJ5cNThIdBhgyOMMaAFIZ83j7F2ns
AAAAAElFTkSuQmCC
Index: moodle/enrol/yui/otherusersmanager/otherusersmanager.js
--- moodle/enrol/yui/otherusersmanager/otherusersmanager.js No Base Revision
+++ moodle/enrol/yui/otherusersmanager/otherusersmanager.js Locally New
@@ -0,0 +1,392 @@
+YUI.add('moodle-enrol-otherusersmanager', function(Y) {
+    
+    var OUMANAGERNAME = 'Other users manager',
+        OTHERUSERNAME = 'Other user (not enroled in course)',
+        COURSEID = 'courseId',
+        USERID = 'userId',
+        BASE = 'base',
+        SEARCH = 'search',
+        REQUIREREFRESH = 'requiresRefresh',
+        PAGE = 'page',
+        USERCOUNT = 'userCount',
+        PICTURE = 'picture',
+        FULLNAME = 'fullname',
+        EMAIL = 'email',
+        ASSIGNABLEROLES = 'assignableRoles',
+        USERS = 'users',
+        URL = 'url',
+        AJAXURL = 'ajaxUrl';
+
+    CSS = {
+        PANEL : 'other-user-manager-panel',
+        WRAP : 'oump-wrap',
+        HEADER : 'oump-header',
+        CONTENT : 'oump-content',
+        AJAXCONTENT : 'oump-ajax-content',
+        SEARCHRESULTS : 'oump-search-results',
+        TOTALUSERS : 'oump-total-users',
+        USERS : 'oump-users',
+        USER : 'oump-user',
+        USERDETAILS : 'oump-user-details',
+        MORERESULTS : 'oump-more-results',
+        LIGHTBOX : 'oump-loading-lightbox',
+        LOADINGICON : 'loading-icon',
+        FOOTER : 'oump-footer',
+        COUNT : 'count',
+        PICTURE : 'oump-user-picture',
+        DETAILS : 'oump-user-specifics',
+        FULLNAME : 'oump-user-fullname',
+        EMAIL : 'oump-user-email',
+        OPTIONS : 'oump-role-options',
+        ROLEOPTION : 'oump-assignable-role',
+        ODD  : 'odd',
+        EVEN : 'even',
+        HIDDEN : 'hidden',
+        SEARCH : 'oump-search',
+        CLOSE : 'oump-panel-close',
+        ALLROLESASSIGNED : 'oump-has-all-roles'
+    };
+
+    var OUMANAGER = function(config) {
+        OUMANAGER.superclass.constructor.apply(this, arguments);
+    }
+    Y.extend(OUMANAGER, Y.Base, {
+        _loadingNode : null,
+        _escCloseEvent : null,
+        initializer : function(config) {
+            this.set(BASE, Y.Node.create('<div class="'+CSS.PANEL+' '+CSS.HIDDEN+'"></div>')
+                .append(Y.Node.create('<div class="'+CSS.WRAP+'"></div>')
+                    .append(Y.Node.create('<div class="'+CSS.HEADER+' header"></div>')
+                        .append(Y.Node.create('<div class="'+CSS.CLOSE+'"></div>'))
+                        .append(Y.Node.create('<h2>'+M.str.enrol.usersearch+'</h2>')))
+                    .append(Y.Node.create('<div class="'+CSS.CONTENT+'"></div>')
+                        .append(Y.Node.create('<div class="'+CSS.AJAXCONTENT+'"></div>'))
+                        .append(Y.Node.create('<div class="'+CSS.LIGHTBOX+' '+CSS.HIDDEN+'"></div>')
+                            .append(Y.Node.create('<img alt="loading" class="'+CSS.LOADINGICON+'" />')
+                                .setAttribute('src', M.util.image_url('i/loading', 'moodle')))
+                            .setStyle('opacity', 0.5)))
+                    .append(Y.Node.create('<div class="'+CSS.FOOTER+'"></div>')
+                        .append(Y.Node.create('<div class="'+CSS.SEARCH+'"><label>'+M.str.enrol.usersearch+'</label></div>')
+                            .append(Y.Node.create('<input type="text" id="oump-usersearch" value="" />'))
+                        )
+                    )
+                )
+            );
+            this.set(SEARCH, this.get(BASE).one('#oump-usersearch'));
+            Y.all('.assignuserrole input').each(function(node){
+                if (node.getAttribute('type', 'submit')) {
+                    node.on('click', this.show, this);
+                }
+            }, this);
+            this.get(BASE).one('.'+CSS.HEADER+' .'+CSS.CLOSE).on('click', this.hide, this);
+            this._loadingNode = this.get(BASE).one('.'+CSS.CONTENT+' .'+CSS.LIGHTBOX);
+            Y.on('key', this.getUsers, this.get(SEARCH), 'down:13', this);
+            Y.one(document.body).append(this.get(BASE));
+            
+            var base = this.get(BASE);
+            base.plug(Y.Plugin.Drag);
+            base.dd.addHandle('.'+CSS.HEADER+' h2');
+            base.one('.'+CSS.HEADER+' h2').setStyle('cursor', 'move');
+
+            this.getAssignableRoles();
+        },
+        show : function(e) {
+            e.preventDefault();
+            e.halt();
+
+            var base = this.get(BASE);
+            base.removeClass(CSS.HIDDEN);
+            var x = (base.get('winWidth') - 400)/2;
+            var y = (parseInt(base.get('winHeight'))-base.get('offsetHeight'))/2 + parseInt(base.get('docScrollY'));
+            if (y < parseInt(base.get('winHeight'))*0.1) {
+                y = parseInt(base.get('winHeight'))*0.1;
+            }
+            base.setXY([x,y]);
+
+            if (this.get(USERS)===null) {
+                this.getUsers(e, false);
+            }
+
+            this._escCloseEvent = Y.on('key', this.hide, document.body, 'down:27', this);
+        },
+        hide : function() {
+            if (this._escCloseEvent) {
+                this._escCloseEvent.detach();
+                this._escCloseEvent = null;
+            }
+            this.get(BASE).addClass(CSS.HIDDEN);
+            if (this.get(REQUIREREFRESH)) {
+                window.location = this.get(URL);
+            }
+        },
+        getUsers : function(e, append) {
+            if (e) {
+                e.halt();
+                e.preventDefault();
+            }
+            var on, params;
+            if (append) {
+                this.set(PAGE, this.get(PAGE)+1);
+            } else {
+                this.set(USERCOUNT, 0);
+            }
+
+            params = [];
+            params['id'] = this.get(COURSEID);
+            params['sesskey'] = M.cfg.sesskey;
+            params['action'] = 'searchotherusers';
+            params['search'] = this.get(SEARCH).get('value');
+            params['page'] = this.get(PAGE);
+            
+            Y.io(M.cfg.wwwroot+this.get(AJAXURL), {
+                method:'POST',
+                data:build_querystring(params),
+                on : {
+                    start : this.displayLoading,
+                    complete: this.processSearchResults,
+                    end : this.removeLoading
+                },
+                context:this,
+                arguments:{
+                    append:append,
+                    params:params
+                }
+            });
+        },
+        displayLoading : function() {
+            this._loadingNode.removeClass(CSS.HIDDEN);
+        },
+        removeLoading : function() {
+            this._loadingNode.addClass(CSS.HIDDEN);
+        },
+        processSearchResults : function(tid, outcome, args) {
+            try {
+                var result = Y.JSON.parse(outcome.responseText);
+                if (result.error) {
+                    return new M.core.ajaxException(result);
+                }
+            } catch (e) {
+                new M.core.exception(e);
+            }
+            if (!result.success) {
+                this.setContent = M.str.enrol.errajaxsearch;
+            }
+            var usersnode, users = [], i=0, count=0, user;
+            if (!args.append) {
+                usersnode = Y.Node.create('<div class="'+CSS.USERS+'"></div>');
+            } else {
+                usersnode = this.get(BASE).one('.'+CSS.SEARCHRESULTS+' .'+CSS.USERS);
+            }
+            count = this.get(USERCOUNT);
+            for (i in result.response.users) {
+                count++;
+                user = new OTHERUSER(result.response.users[i], count, this);
+                usersnode.append(user.toHTML());
+                users[user.get(USERID)] = user;
+            }
+            this.set(USERCOUNT, count);
+            if (!args.append) {
+                var usersstr = (result.response.totalusers == '1')?M.str.enrol.ajaxoneuserfound:M.str.enrol.ajaxxusersfound.replace(/\[users\]/, result.response.totalusers);
+                var content = Y.Node.create('<div class="'+CSS.SEARCHRESULTS+'"></div>')
+                    .append(Y.Node.create('<div class="'+CSS.TOTALUSERS+'">'+usersstr+'</div>'))
+                    .append(usersnode);
+                if (result.response.totalusers > (this.get(PAGE)+1)*25) {
+                    var fetchmore = Y.Node.create('<div class="'+CSS.MORERESULTS+'"><a href="#">'+M.str.enrol.ajaxnext25+'</a></div>');
+                    fetchmore.on('click', this.getUsers, this, true);
+                    content.append(fetchmore)
+                }
+                this.setContent(content);
+            } else {
+                if (result.response.totalusers <= (this.get(PAGE)+1)*25) {
+                    this.get(BASE).one('.'+CSS.MORERESULTS).remove();
+                }
+            }
+        },
+        setContent : function(content) {
+            this.get(BASE).one('.'+CSS.CONTENT+' .'+CSS.AJAXCONTENT).setContent(content);
+        },
+        getAssignableRoles : function() {
+            Y.io(M.cfg.wwwroot+'/enrol/ajax.php', {
+                method:'POST',
+                data:'id='+this.get(COURSEID)+'&action=getassignable&sesskey='+M.cfg.sesskey,
+                on: {
+                    complete: function(tid, outcome, args) {
+                        try {
+                            var roles = Y.JSON.parse(outcome.responseText);
+                            if (roles.error) {
+                                new M.core.ajaxException(roles);
+                            } else {
+                                this.set(ASSIGNABLEROLES, roles.response);
+                            }
+                        } catch (e) {
+                            new M.core.exception(e);
+                        }
+                        this.getAssignableRoles = function() {
+                            this.fire('assignablerolesloaded');
+                        }
+                        this.getAssignableRoles();
+                    }
+                },
+                context:this
+            });
+        }
+    }, {
+        NAME : OUMANAGERNAME,
+        ATTRS : {
+            courseId : {
+                
+            },
+            ajaxUrl : {
+                validator : Y.Lang.isString
+            },
+            url : {
+                validator : Y.Lang.isString
+            },
+            roles : {
+                validator :Y.Lang.isArray,
+                value : []
+            },
+            base : {
+                setter : function(node) {
+                    var n = Y.one(node);
+                    if (!n) {
+                        Y.fail(OUMANAGERNAME+': invalid base node set');
+                    }
+                    return n;
+                }
+            },
+            search : {
+                setter : function(node) {
+                    var n = Y.one(node);
+                    if (!n) {
+                        Y.fail(OUMANAGERNAME+': invalid base node set');
+                    }
+                    return n;
+                }
+            },
+            requiresRefresh : {
+                validator : Y.Lang.isBoolean,
+                value : false
+            },
+            users : {
+                validator : Y.Lang.isArray,
+                value : null
+            },
+            page : {
+                validator : Y.Lang.isNumber,
+                value : 0
+            },
+            userCount : {
+                validator : Y.Lang.isNumber,
+                value : 0
+            },
+            assignableRoles : {
+                value : []
+            }
+        }
+    });
+
+    var OTHERUSER = function(config, count, manager) {
+        this._count = count;
+        this._manager = manager;
+        OTHERUSER.superclass.constructor.apply(this, arguments);
+    }
+    Y.extend(OTHERUSER, Y.Base, {
+        _count : 0,
+        _manager : null,
+        _node : null,
+        _assignmentInProgress : false,
+        initializer : function(config) {
+            this.publish('assignrole:success');
+            this.publish('assignrole:failure');
+        },
+        toHTML : function() {
+            this._node = Y.Node.create('<div class="'+CSS.USER+' clearfix" rel="'+this.get(USERID)+'"></div>')
+                .addClass((this._count%2)?CSS.ODD:CSS.EVEN)
+                .append(Y.Node.create('<div class="'+CSS.COUNT+'">'+this._count+'</div>'))
+                .append(Y.Node.create('<div class="'+CSS.USERDETAILS+'"></div>')
+                    .append(Y.Node.create('<div class="'+CSS.PICTURE+'"></div>')
+                        .append(Y.Node.create(this.get(PICTURE)))
+                    )
+                    .append(Y.Node.create('<div class="'+CSS.DETAILS+'"></div>')
+                        .append(Y.Node.create('<div class="'+CSS.FULLNAME+'">'+this.get(FULLNAME)+'</div>'))
+                        .append(Y.Node.create('<div class="'+CSS.EMAIL+'">'+this.get(EMAIL)+'</div>'))
+                    )
+                    .append(Y.Node.create('<div class="'+CSS.OPTIONS+'"><span class="label">'+M.str.role.assignrole+': </span></div>'))
+                );
+            var id = 0, roles = this._manager.get(ASSIGNABLEROLES);
+            for (id in roles) {
+                var role = Y.Node.create('<a href="#" class="'+CSS.ROLEOPTION+'">'+roles[id]+'</a>');
+                role.on('click', this.assignRoleToUser, this, id, role);
+                this._node.one('.'+CSS.OPTIONS).append(role);
+            }
+            return this._node;
+        },
+        assignRoleToUser : function(e, roleid, node) {
+            e.halt();
+            if (this._assignmentInProgress) {
+                return true;
+            }
+            this._node.addClass('assignment-in-progress');
+            this._assignmentInProgress = true;
+            Y.io(M.cfg.wwwroot+'/enrol/ajax.php', {
+                method:'POST',
+                data:'id='+this._manager.get(COURSEID)+'&action=assign&sesskey='+M.cfg.sesskey+'&roleid='+roleid+'&user='+this.get(USERID),
+                on: {
+                    complete: function(tid, outcome, args) {
+                        try {
+                            var o = Y.JSON.parse(outcome.responseText);
+                            if (o.success) {
+                                var options = args.node.ancestor('.'+CSS.OPTIONS);
+                                if (options.all('.'+CSS.ROLEOPTION).size() == 1) {
+                                    // This is the last node so remove the options div
+                                    options.remove();
+                                    options.ancestor(CSS.USER).addClass(CSS.ALLROLESASSIGNED);
+                                } else {
+                                    // There are still more assignable roles
+                                    args.node.remove();
+                                }
+                                this._manager.set(REQUIREREFRESH, true);
+                            }
+                        } catch (e) {
+                            new M.core.exception(e);
+                        }
+                        this._assignmentInProgress = false;
+                        this._node.removeClass('assignment-in-progress');
+                    }
+                },
+                context:this,
+                arguments:{
+                    roleid : roleid,
+                    node : node
+                }
+            });
+            return true;
+        }
+    }, {
+        NAME : OTHERUSERNAME,
+        ATTRS : {
+            userId : {
+                
+            },
+            fullname : {
+                validator : Y.Lang.isString
+            },
+            email : {
+                validator : Y.Lang.isString
+            },
+            picture : {
+                validator : Y.Lang.isString
+            }
+        }
+    });
+    Y.augment(OTHERUSER, Y.EventTarget);
+
+    M.enrol = M.enrol || {};
+    M.enrol.otherusersmanager = {
+        init : function(cfg) {
+            new OUMANAGER(cfg);
+        }
+    }
+
+}, '@VERSION@', {requires:['base','node', 'overlay', 'io', 'test', 'json-parse', 'event-delegate', 'dd-plugin', 'event-key', 'moodle-enrol-notification']});
\ No newline at end of file
Index: moodle/enrol/yui/quickcohortenrolment/assets/skins/sam/quickcohortenrolment.css
--- moodle/enrol/yui/quickcohortenrolment/assets/skins/sam/quickcohortenrolment.css Base (1.1)
+++ moodle/enrol/yui/quickcohortenrolment/assets/skins/sam/quickcohortenrolment.css Locally Modified (Based On 1.1)
@@ -20,3 +20,5 @@
 .qce-panel .qce-assignable-roles {margin:3px 5px 2px;}
 .qce-panel .qce-cohort.headings {font-weight:bold;border-width:0;}
 .qce-panel .qce-cohort.headings .qce-cohort-button {display:none;}
+.qce-panel .performing-action {position:absolute;top:0;left:0;width:100%;height:100%;background-color:#fff;text-align:center;}
+.qce-panel .performing-action img {margin-top:150px;}
\ No newline at end of file
Index: moodle/enrol/yui/quickcohortenrolment/quickcohortenrolment.js
--- moodle/enrol/yui/quickcohortenrolment/quickcohortenrolment.js Base (1.2)
+++ moodle/enrol/yui/quickcohortenrolment/quickcohortenrolment.js Locally Modified (Based On 1.2)
@@ -34,10 +34,13 @@
         CONTROLLER.superclass.constructor.apply(this, arguments);
     }
     Y.extend(CONTROLLER, Y.Base, {
+        _preformingAction : false,
         initializer : function(config) {
             COUNT ++;
             this.publish('assignablerolesloaded');
             this.publish('cohortsloaded');
+            this.publish('performingaction');
+            this.publish('actioncomplete');
             
             var close = Y.Node.create('<div class="close"></div>');
             var panel = new Y.Overlay({
@@ -57,6 +60,12 @@
             this.on('hide', function() {
                 this.hide();
             }, panel);
+            this.on('performingaction', function(){
+                this.get('boundingBox').append(Y.Node.create('<div class="performing-action"></div>').append(Y.Node.create('<img alt="loading" />').setAttribute('src', M.cfg.loadingicon)).setStyle('opacity', 0.5));
+            }, panel);
+            this.on('actioncomplete', function(){
+                this.get('boundingBox').one('.performing-action').remove();
+            }, panel);
             this.on('assignablerolesloaded', this.updateContent, this, panel);
             this.on('cohortsloaded', this.updateContent, this, panel);
             close.on('click', this.hide, this);
@@ -121,9 +130,13 @@
                     complete: function(tid, outcome, args) {
                         try {
                             var cohorts = Y.JSON.parse(outcome.responseText);
+                            if (cohorts.error) {
+                                new M.core.ajaxException(cohorts);
+                            } else {
                             this.setCohorts(cohorts.response);
+                            }
                         } catch (e) {
-                            Y.fail(CONTROLLERNAME+': Failed to load cohorts');
+                            return new M.core.exception(e);
                         }
                         this.getCohorts = function() {
                             this.fire('cohortsloaded');
@@ -151,7 +164,7 @@
                             var roles = Y.JSON.parse(outcome.responseText);
                             this.set(ASSIGNABLEROLES, roles.response);
                         } catch (e) {
-                            Y.fail(CONTROLLERNAME+': Failed to load assignable roles');
+                            return new M.core.exception(e);
                         }
                         this.getAssignableRoles = function() {
                             this.fire('assignablerolesloaded');
@@ -163,6 +176,11 @@
             });
         },
         enrolCohort : function(e, cohort, node, usersonly) {
+            if (this._preformingAction) {
+                return true;
+            }
+            this._preformingAction = true;
+            this.fire('performingaction');
             var params = {
                 id : this.get(COURSEID),
                 roleid : node.one('.'+CSS.PANELROLES+' select').get('value'),
@@ -177,23 +195,30 @@
                     complete: function(tid, outcome, args) {
                         try {
                             var result = Y.JSON.parse(outcome.responseText);
-                            if (result.success) {
-                                if (result.response && result.response.message) {
-                                    alert(result.response.message);
-                                }
+                            if (result.error) {
+                                new M.core.ajaxException(result);
+                            } else {
+                                var redirect = function() {
                                 if (result.response.users) {
                                     window.location.href = this.get(URL);
                                 }
+                                }
+                                if (result.response && result.response.message) {
+                                    new M.core.alert(result.response).on('complete', redirect, this);
                             } else {
-                                alert('Failed to enrol cohort');
+                                    redirect();
                             }
+                            }
+                            this._preformingAction = false;
+                            this.fire('actioncomplete');
                         } catch (e) {
-                            Y.fail(CONTROLLERNAME+': Failed to enrol cohort');
+                            new M.core.exception(e);
                         }
                     }
                 },
                 context:this
             });
+            return true;
         }
     }, {
         NAME : CONTROLLERNAME,
@@ -276,4 +301,4 @@
         }
     }
 
-}, '@VERSION@', {requires:['base','node', 'overlay', 'io', 'test', 'json-parse', 'event-delegate', 'dd-plugin', 'event-key']});
\ No newline at end of file
+}, '@VERSION@', {requires:['base','node', 'overlay', 'io', 'test', 'json-parse', 'event-delegate', 'dd-plugin', 'event-key', 'moodle-enrol-notification']});
\ No newline at end of file
Index: moodle/enrol/yui/rolemanager/rolemanager.js
--- moodle/enrol/yui/rolemanager/rolemanager.js Base (1.1)
+++ moodle/enrol/yui/rolemanager/rolemanager.js Locally Modified (Based On 1.1)
@@ -86,11 +86,13 @@
                     complete: function(tid, outcome, args) {
                         try {
                             var o = Y.JSON.parse(outcome.responseText);
-                            if (o.success) {
+                            if (o.error) {
+                                new M.core.ajaxException(o);
+                            } else {
                                 panel.user.addRoleToDisplay(args.roleid, this.get(ASSIGNABLEROLES)[args.roleid]);
                             }
                         } catch (e) {
-                            Y.fail(MOD_PANEL+': Failed to parse role assignment response  ['+e.linenum+':'+e.message+']');
+                            new M.core.exception(e);
                         }
                         panel.hide();
                     }
@@ -103,9 +105,18 @@
         },
         removeRole : function(e, user, roleid) {
             e.halt();
-            if (confirm('Are you sure you wish to remove this role from this user?')) {
-                this.removeRoleCallback(e, user.get(USERID), roleid);
+            var event = this.on('assignablerolesloaded', function(){
+                event.detach();
+                var s = M.str.role, confirmation = {
+                    lightbox :  true,
+                    title    :  s.confirmunassigntitle,
+                    question :  s.confirmunassign,
+                    yesLabel :  s.confirmunassignyes,
+                    noLabel  :  s.confirmunassignno
             }
+                new M.core.confirm(confirmation).on('complete-yes', this.removeRoleCallback, this, user.get(USERID), roleid);
+            }, this);
+            this._loadAssignableRoles();
         },
         removeRoleCallback : function(e, userid, roleid) {
             Y.io(M.cfg.wwwroot+'/enrol/ajax.php', {
@@ -113,13 +124,16 @@
                 data:'id='+this.get(COURSEID)+'&action=unassign&sesskey='+M.cfg.sesskey+'&role='+roleid+'&user='+userid,
                 on: {
                     complete: function(tid, outcome, args) {
+                        var o;
                         try {
-                            var o = Y.JSON.parse(outcome.responseText);
-                            if (o.success) {
+                            o = Y.JSON.parse(outcome.responseText);
+                            if (o.error) {
+                                new M.core.ajaxException(o);
+                            } else {
                                 this.users[userid].removeRoleFromDisplay(args.roleid);
                             }
                         } catch (e) {
-                            Y.fail(MOD_PANEL+': Failed to parse role assignment response ['+e.linenum+':'+e.message+']');
+                            new M.core.exception(e);
                         }
                     }
                 },
@@ -140,7 +154,7 @@
                             var roles = Y.JSON.parse(outcome.responseText);
                             this.set(ASSIGNABLEROLES, roles.response);
                         } catch (e) {
-                            Y.fail(MOD_NAME+': Failed to load assignable roles');
+                            new M.core.exception(e);
                         }
                         this._loadAssignableRoles = function() {
                             this.fire('assignablerolesloaded');
@@ -260,7 +274,9 @@
             } else {
                 if (!link) {
                     var m = this.get(MANIPULATOR);
-                    link = Y.Node.create('<div class="addrole">&nbsp;</div>');
+                    link = Y.Node.create('<div class="addrole"></div>').append(
+                        Y.Node.create('<img alt="" />').setAttribute('src', M.util.image_url('t/enroladd', 'moodle'))
+                    );
                     link.on('click', m.addRole, m, this);
                     this.get(CONTAINER).one('.col_role').insert(link, 0);
                     this.set(ASSIGNROLELINK, link);
@@ -351,8 +367,8 @@
             this.user = user;
             var roles = this.user.get(CONTAINER).one('.col_role .roles');
             var x = roles.getX() + 10;
-            var y = roles.getY() + this.user.get(CONTAINER).get('offsetHeight') - 10 + Y.one(window).get('scrollTop');
-            this.get('elementNode').setXY([x, y]);
+            var y = roles.getY() + this.user.get(CONTAINER).get('offsetHeight') - 10;
+            this.get('elementNode').setStyle('left', x).setStyle('top', y);
             this.get('elementNode').addClass('visible');
             this.escCloseEvent = Y.on('key', this.hide, document.body, 'down:27', this);
             this.displayed = true;
@@ -386,4 +402,4 @@
         }
     }
     
-}, '@VERSION@', {requires:['base','node','io','json-parse','test']});
\ No newline at end of file
+}, '@VERSION@', {requires:['base','node','io','json-parse','test','moodle-enrol-notification']});
\ No newline at end of file
Index: moodle/lang/en/enrol.php
--- moodle/lang/en/enrol.php Base (1.6)
+++ moodle/lang/en/enrol.php Locally Modified (Based On 1.6)
@@ -29,6 +29,7 @@
 $string['ajaxoneuserfound'] = '1 user found';
 $string['ajaxxusersfound'] = '[users] users found';
 $string['ajaxnext25'] = 'Next 25...';
+$string['assignnotpermitted'] = 'You do not have permission or can not assign roles in this course.';
 $string['configenrolplugins'] = 'Please select all required plugins and arrange then in appropriate order.';
 $string['defaultenrol'] = 'Add instance to new courses';
 $string['defaultenrol_desc'] = 'It is possible to add this plugin to all new courses by default.';
@@ -48,6 +49,7 @@
 $string['enrolmentnewuser'] = '{$a->user} has enrolled in course "{$a->course}"';
 $string['enrolments'] = 'Enrolments';
 $string['enrolmentoptions'] = 'Enrolment options';
+$string['enrolnotpermitted'] = 'You do not have permission or are not allowed to enrol someone in this course';
 $string['enrolperiod'] = 'Enrolment duration';
 $string['enrolusage'] = 'Instances / enrolments';
 $string['enrolusers'] = 'Enrol users';
@@ -55,6 +57,10 @@
 $string['enroltimestart'] = 'Enrolment starts';
 $string['errajaxfailedenrol'] = 'Failed to enrol user';
 $string['errajaxsearch'] = 'Error when searching users';
+$string['errorenrolcohort'] = 'Error creating cohort sync enrolment instance in this course.';
+$string['errorenrolcohortusers'] = 'Error enrolling cohort members in this course.';
+$string['invalidenrolinstance'] = 'Invalid enrolment instance';
+$string['invalidrole'] = 'Invalid role';
 $string['manageenrols'] = 'Manage enrol plugins';
 $string['manageinstance'] = 'Manage';
 $string['noexistingparticipants'] = 'No existing participants';
@@ -62,21 +68,30 @@
 $string['none'] = 'None';
 $string['notenrollable'] = 'This course is not enrollable at the moment.';
 $string['notenrolledusers'] = 'Other users';
+$string['otheruserdesc'] = 'The following users are not enrolled in this course but do have roles, inherited or assigned within it.';
 $string['participationactive'] = 'Active';
 $string['participationstatus'] = 'Status';
 $string['participationsuspended'] = 'Suspended';
 $string['periodend'] = 'until {$a}';
 $string['periodstart'] = 'from {$a}';
 $string['periodstartend'] = 'from {$a->start} until {$a->end}';
+$string['rolefromthiscourse'] = '{$a->role} (Assigned in this course)';
+$string['rolefrommetacourse'] = '{$a->role} (Inherited from parent course)';
+$string['rolefromcategory'] = '{$a->role} (Inherited from course category)';
+$string['rolefromsystem'] = '{$a->role} (Assigned at site level)';
 $string['startdatetoday'] = 'Today';
 $string['synced'] = 'Synced';
 $string['totalenrolledusers'] = '{$a} enrolled users';
+$string['totalotherusers'] = '{$a} other users';
+$string['unassignnotpermitted'] = 'You do not have permission to unassign roles in this course';
 $string['unenrol'] = 'Unenrol';
 $string['unenrolconfirm'] = 'Do you really want to unenrol user "{$a->user}" from course "{$a->course}"?';
 $string['unenrolme'] = 'Unenrol me from {$a}';
+$string['unenrolnotpermitted'] = 'You do not have permission or can not unenrol this user from this course.';
 $string['unenrolroleusers'] = 'Unenrol users';
 $string['uninstallconfirm'] = 'You are about to completely delete the enrol plugin \'{$a}\'.  This will completely delete everything in the database associated with this enrolment type.  Are you SURE you want to continue?';
 $string['uninstalldeletefiles'] = 'All data associated with the enrol plugin \'{$a->plugin}\' has been deleted from the database.  To complete the deletion (and prevent the plugin re-installing itself), you should now delete this directory from your server: {$a->directory}';
+$string['unknowajaxaction'] = 'Unknown action requested';
\ No newline at end of file
 $string['unlimitedduration'] = 'Unlimited';
 $string['usersearch'] = 'Search ';
 $string['extremovedaction'] = 'External unenrol action';
Index: moodle/lang/en/role.php
--- moodle/lang/en/role.php Base (1.15)
+++ moodle/lang/en/role.php Locally Modified (Based On 1.15)
@@ -52,6 +52,7 @@
 $string['assignmentcontext'] = 'Assignment context';
 $string['assignmentoptions'] = 'Assignment options';
 $string['assignrolenameincontext'] = 'Assign role \'{$a->role}\' in {$a->context}';
+$string['assignrole'] = 'Assign role';
 $string['assignroles'] = 'Assign roles';
 $string['assignroles_help'] = 'By assigning a role to a user in a context, you are granting them the permissions contained in that role, for the current context and all lower contexts. For example, if a user is assigned the role of student in a course, they will also have the role of student for all activities and blocks within the course.';
 $string['assignroles_link'] = 'admin/roles/assign';
@@ -102,6 +103,10 @@
 $string['confirmdeladmin'] = 'Do you really want to remove user <strong>{$a}</strong> from the list of site administrators?';
 $string['confirmroleprevent'] = 'Do you really want to remove <strong>{$a->role}</strong> from the list of allowed roles for capability {$a->cap} in context {$a->context}?';
 $string['confirmroleunprohibit'] = 'Do you really want to remove <strong>{$a->role}</strong> from the list of prohibited roles for capability {$a->cap} in context {$a->context}?';
+$string['confirmunassign'] = 'Are you sure you wish to remove this role from this user?';
+$string['confirmunassigntitle'] = 'Confirm role change';
+$string['confirmunassignyes'] = 'Remove';
+$string['confirmunassignno'] = 'Cancel';
 $string['context'] = 'Context';
 $string['course:activityvisibility'] = 'Hide/show activities';
 $string['course:bulkmessaging'] = 'Send a message to many people';
Index: moodle/lib/outputrenderers.php
--- moodle/lib/outputrenderers.php Base (1.225)
+++ moodle/lib/outputrenderers.php Locally Modified (Based On 1.225)
@@ -2573,11 +2573,14 @@
      * @return string A template fragment for a fatal error
      */
     public function fatal_error($message, $moreinfourl, $link, $backtrace, $debuginfo = null) {
+        global $FULLME, $USER;
         $e = new stdClass();
         $e->error      = $message;
         $e->stacktrace = NULL;
         $e->debuginfo  = NULL;
+        $e->reproductionlink = NULL;
         if (!empty($CFG->debug) and $CFG->debug >= DEBUG_DEVELOPER) {
+            $e->reproductionlink = $link;
             if (!empty($debuginfo)) {
                 $e->debuginfo = $debuginfo;
             }
@@ -2585,6 +2588,7 @@
                 $e->stacktrace = format_backtrace($backtrace, true);
             }
         }
+        @header('Content-type: application/json');
         return json_encode($e);
     }
 
Index: moodle/lib/setuplib.php
--- moodle/lib/setuplib.php Base (1.108)
+++ moodle/lib/setuplib.php Locally Modified (Based On 1.108)
@@ -1035,6 +1035,7 @@
                     $e->stacktrace = format_backtrace($backtrace, true);
                 }
             }
+            @header('Content-Type: application/json');
             echo json_encode($e);
             return;
         }
Index: moodle/theme/standard/style/core.css
--- moodle/theme/standard/style/core.css Base (1.13)
+++ moodle/theme/standard/style/core.css Locally Modified (Based On 1.13)
@@ -439,7 +439,9 @@
 .userenrolment .col_group .addgroup {background-color:#DDD;border:1px outset #EEE;-moz-border-radius:5px;}
 .userenrolment .col_enrol {max-width:300px;}
 .userenrolment .col_enrol .enrolment {border:1px outset #E6E6E6;background-color:#EEE;line-height:10px;font-size:10px;-moz-border-radius:5px;}
+.userenrolment.otheruserenrolment .col_role .role {float:none;}
 .path-enrol .enrolusersbutton,
 .path-enrol .enrolcohortbutton {float:left;}
 .path-enrol .enrolusersbutton.instance1,
-.path-enrol .enrolcohortbutton.instance1 {float:right;}
+.path-enrol .enrolcohortbutton.instance1,
+.path-enrol .assignuserrole.instance1 {float:right;}
