<tr>
<td valign="top">
<select name="removeselect[]" size="20" id="removeselect" multiple
- onFocus="document.studentform.add.disabled=true;
- document.studentform.remove.disabled=false;
- document.studentform.addselect.selectedIndex=-1;" />
+ onFocus="document.assignform.add.disabled=true;
+ document.assignform.remove.disabled=false;
+ document.assignform.addselect.selectedIndex=-1;" />
<?php
foreach ($contextusers as $contextuser) {
$fullname = fullname($contextuser, true);
</td>
<td valign="top">
<select name="addselect[]" size="20" id="addselect" multiple
- onFocus="document.studentform.add.disabled=false;
- document.studentform.remove.disabled=true;
- document.studentform.removeselect.selectedIndex=-1;">
+ onFocus="document.assignform.add.disabled=false;
+ document.assignform.remove.disabled=true;
+ document.assignform.removeselect.selectedIndex=-1;">
<?php
- if (!empty($searchusers)) {
- echo "<optgroup label=\"$strsearchresults (" . count($searchusers) . ")\">\n";
- foreach ($searchusers as $user) {
- $fullname = fullname($user, true);
- echo "<option value=\"$user->id\">".$fullname.", ".$user->email."</option>\n";
+ if (!empty($searchtext)) {
+ echo "<optgroup label=\"$strsearchresults (" . $availableusers->_numOfRows . ")\">\n";
+ while (! $availableusers->EOF) {
+ $user = $availableusers->FetchObj();
+ if (!isset($contextusers[$user->id])) {
+ $fullname = fullname($user, true);
+ echo "<option value=\"$user->id\">".$fullname.", ".$user->email."</option>\n";
+ }
+ $availableusers->MoveNext();
}
echo "</optgroup>\n";
- }
- else {
+
+ } else {
if ($usercount > MAX_USERS_PER_PAGE) {
echo '<optgroup label="'.get_string('toomanytoshow').'"><option></option></optgroup>'."\n"
.'<optgroup label="'.get_string('trysearching').'"><option></option></optgroup>'."\n";
- }
- else {
- if ($usercount > 0) { //fix for bug#4455
- foreach ($users as $user) {
+ } else {
+ while (! $availableusers->EOF) {
+ $user = $availableusers->FetchObj();
+ if (!isset($contextusers[$user->id])) {
$fullname = fullname($user, true);
echo "<option value=\"$user->id\">".$fullname.", ".$user->email."</option>\n";
}
+ $availableusers->MoveNext();
}
}
}
</select>
<br />
<input type="text" name="searchtext" size="30" value="<?php p($searchtext, true) ?>"
- onFocus ="document.studentform.add.disabled=true;
- document.studentform.remove.disabled=true;
- document.studentform.removeselect.selectedIndex=-1;
- document.studentform.addselect.selectedIndex=-1;"
+ onFocus ="document.assignform.add.disabled=true;
+ document.assignform.remove.disabled=true;
+ document.assignform.removeselect.selectedIndex=-1;
+ document.assignform.addselect.selectedIndex=-1;"
onkeydown = "var keyCode = event.which ? event.which : event.keyCode;
if (keyCode == 13) {
- document.studentform.previoussearch.value=1;
- document.studentform.submit();
+ document.assignform.previoussearch.value=1;
+ document.assignform.submit();
} " />
<input name="search" id="search" type="submit" value="<?php p($strsearch) ?>" />
<?php
$searchtext = optional_param('searchtext', '', PARAM_RAW); // search string
$previoussearch = optional_param('previoussearch', 0, PARAM_BOOL);
$hidden = optional_param('hidden', 0, PARAM_BOOL); // whether this assignment is hidden
- $previoussearch = ($searchtext != '') or ($previoussearch) ? 1:0;
$timestart = optional_param('timestart', 0, PARAM_INT);
$timeend = optional_param('timened', 0, PARAM_INT);
$userid = optional_param('userid', 0, PARAM_INT); // needed for user tabs
$errors = array();
+ $previoussearch = ($searchtext != '') or ($previoussearch) ? 1:0;
+
$baseurl = 'assign.php?contextid='.$contextid;
if (!empty($userid)) {
$baseurl .= '&userid='.$userid;
$strsearch = get_string('search');
$strshowall = get_string('showall');
$strparticipants = get_string('participants');
+ $strsearchresults = get_string('searchresults');
$timemodified = time();
foreach ($frm->addselect as $adduser) {
- $adduser = clean_param($adduser, PARAM_INT);
+ if (!$adduser = clean_param($adduser, PARAM_INT)) {
+ continue;
+ }
$allow = true;
if ($inmeta) {
if (has_capability('moodle/course:managemetacourse', $context, $adduser)) {
}
}
+ if ($roleid) { /// prints a form to swap roles
-/// Get all existing participants in this course.
-
- $existinguserarray = array();
-
- if (!$contextusers = get_role_users($roleid, $context)) {
- $contextusers = array();
- }
+ /// Get all existing participants in this context.
- foreach ($contextusers as $contextuser) {
- $existinguserarray[] = $contextuser->id;
- }
+ if (!$contextusers = get_role_users($roleid, $context, false, 'u.id, u.firstname, u.lastname, u.email')) {
+ $contextusers = array();
+ }
- $existinguserlist = implode(',', $existinguserarray);
- unset($existinguserarray);
+ $select = "username <> 'guest' AND deleted = 0 AND confirmed = 1";
+
+ $usercount = count_records_select('user', $select) - count($contextusers);
- $usercount = get_users(false, '', true, $existinguserlist);
+ $searchtext = trim($searchtext);
-/// Get search results excluding any users already in this course
- if (($searchtext != '') and $previoussearch) {
- $searchusers = get_users(true, $searchtext, true, $existinguserlist, 'firstname ASC, lastname ASC',
- '', '', 0, MAX_USERS_PER_PAGE, 'id, firstname, lastname, email');
- }
+ if ($searchtext !== '') { // Search for a subset of remaining users
+ $LIKE = sql_ilike();
+ $FULLNAME = sql_fullname();
-/// If no search results then get potential students for this course excluding users already in course
- if (empty($searchusers)) {
- $users = array();
- if ($usercount <= MAX_USERS_PER_PAGE) {
- if (!$users = get_users(true, '', true, $existinguserlist, 'firstname ASC, lastname ASC', '', '',
- 0, MAX_USERS_PER_PAGE, 'id, firstname, lastname, email')) {
- $users = array();
- }
+ $select .= " AND ($FULLNAME $LIKE '%$searchtext%' OR email $LIKE '%$searchtext%') ";
}
- }
+ $availableusers = get_recordset_sql('SELECT id, firstname, lastname, email
+ FROM '.$CFG->prefix.'user
+ WHERE '.$select.'
+ ORDER BY lastname ASC, firstname ASC');
- if ($roleid) {
- /// prints a form to swap roles
+ /// In the .html file below we loop through these results and exclude any in $contextusers
+
echo '<form name="rolesform" action="assign.php" method="post">';
echo '<div align="center">'.$strcurrentcontext.': '.print_context_name($context).'<br/>';
if ($userid) {
$table->align = array('right', 'center');
foreach ($assignableroles as $roleid => $rolename) {
- $countusers = 0;
- if ($contextusers = get_role_users($roleid, $context)) {
- $countusers = count($contextusers);
- }
+ $countusers = count_role_users($roleid, $context);
$table->data[] = array('<a href="'.$baseurl.'&roleid='.$roleid.'">'.$rolename.'</a>', $countusers);
}