require_once($CFG->dirroot . '/user/selector/lib.php');
require_js('group/clientlib.js');
-$groupid = required_param('group', PARAM_INT);
+$groupid = required_param('group', PARAM_INT);
if (!$group = $DB->get_record('groups', array('id'=>$groupid))) {
print_error('invalidgroupid');
<div id="addmembersform">
<h3 class="main"><?php print_string('adduserstogroup', 'group'); echo ": $groupname"; ?></h3>
- <form id="assignform" method="post" action="members.php">
+ <form id="assignform" method="post" action="<?php echo $CFG->wwwroot; ?>/group/members.php?group=<?php echo $groupid; ?>">
<div>
<input type="hidden" name="sesskey" value="<?php p(sesskey()); ?>" />
- <input type="hidden" name="group" value="<?php echo $groupid; ?>" />
<table class="generaltable generalbox groupmanagementtable boxaligncenter" summary="">
<tr>
$multiselect . 'size="' . $this->rows . '">' . "\n";
// Populate the select.
- $output .= $this->output_options($groupedusers);
+ $output .= $this->output_options($groupedusers, $search);
// Output the search controls.
$output .= "</select>\n<div>\n";
* @param array $groupedusers an array, as returned by find_users.
* @return string HTML code.
*/
- protected function output_options($groupedusers) {
+ protected function output_options($groupedusers, $search) {
$output = '';
// Ensure that the list of previously selected users is up to date.
// is only one selected user, set a flag to select them.
$select = false;
if (empty($groupedusers)) {
- $groupedusers = array(get_string('nomatchingusers') => array());
+ $groupedusers = array(get_string('nomatchingusers', '', $search) => array());
} else if (count($groupedusers) == 1 && count(reset($groupedusers)) == 1) {
$select = true;
if (!$this->multiselect) {
// If there were previously selected users who do not match the search, show them too.
if (!empty($this->selected)) {
- $output .= $this->output_optgroup(get_string('previouslyselectedusers'), $this->selected, true);
+ $output .= $this->output_optgroup(get_string('previouslyselectedusers', '', $search), $this->selected, true);
}
// This method trashes $this->selected, so clear the cache so it is
* @param array $roles array in the format returned by groups_calculate_role_people.
* @return array array in the format find_users is supposed to return.
*/
- protected function convert_array_format($roles) {
+ protected function convert_array_format($roles, $search) {
if (empty($roles)) {
$roles = array();
}
$groupedusers = array();
foreach ($roles as $role) {
- $groupedusers[$role->name] = $role->users;
- foreach ($groupedusers[$role->name] as &$user) {
+ if ($search) {
+ $a = new stdClass;
+ $a->role = $role->name;
+ $a->search = $search;
+ $groupname = get_string('matchingsearchandrole', '', $a);
+ } else {
+ $groupname = $role->name;
+ }
+ $groupedusers[$groupname] = $role->users;
+ foreach ($groupedusers[$groupname] as &$user) {
unset($user->roles);
$user->fullname = fullname($user);
}
$roles = groups_get_members_by_role($this->groupid, $this->courseid,
$this->required_fields_sql('u'), 'u.lastname, u.firstname',
$wherecondition, $params);
- return $this->convert_array_format($roles);
+ return $this->convert_array_format($roles, $search);
}
}
$rs = $DB->get_recordset_sql($fields . $sql . $orderby, $params);
$roles = groups_calculate_role_people($rs, $context);
- return $this->convert_array_format($roles);
+ return $this->convert_array_format($roles, $search);
}
}
?>
\ No newline at end of file
}
// Methods for refreshing the list of displayed options ========================
+user_selector.prototype.insert_search_into_str = function(string, search) {
+ return string.replace("''", "'" + search + "'");
+}
/**
* This method should do the same sort of thing as the PHP method
}
if (nogroups) {
- this.output_group(this.strnomatchingusers, {}, false)
+ this.output_group(this.insert_search_into_str(this.strnomatchingusers, this.lastsearch), {}, false)
}
// If there was only one option matching the search results, select it.
break;
}
if (areprevselected) {
- this.output_group(this.strprevselected, this.selected, true);
+ this.output_group(this.insert_search_into_str(this.strprevselected, this.lastsearch), this.selected, true);
}
this.selected = null;
}