--- /dev/null
+
+<form name="studentform" id="studentform" method="post" action="student.php">
+<input type="hidden" name="id" value="<?php echo $id?>">
+ <table align="center" border="0" cellpadding="5" cellspacing="0">
+ <tr>
+ <td valign="top">
+ <?php p($strexistingstudents) ?>
+ </td>
+ <td></td>
+ <td valign="top">
+ <?php p($strpotentialstudents) ?>
+ </td>
+ </tr>
+ <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;">
+ <?php
+ foreach ($students as $student) {
+ $fullname = fullname($student, true);
+ echo "<option value=\"$student->id\">".$fullname.", ".$student->email."</option>\n";
+ }
+ ?>
+
+ </select></td>
+ <td valign="top">
+ <br />
+ <input name="add" type="submit" id="add" value="←" />
+ <br />
+ <input name="remove" type="submit" id="remove" value="→" />
+ <br />
+ </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;">
+ <?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";
+ }
+ echo "</optgroup>\n";
+ }
+ foreach ($users as $user) {
+ $fullname = fullname($user, true);
+ echo "<option value=\"$user->id\">".$fullname.", ".$user->email."</option>\n";
+ }
+ ?>
+ </select>
+ <br />
+ <input type="text" name="searchtext" size="30" value="<?php echo $searchtext ?>"
+ onFocus ="document.studentform.add.disabled=true;
+ document.studentform.remove.disabled=true;
+ document.studentform.removeselect.selectedIndex=-1;
+ document.studentform.addselect.selectedIndex=-1;">
+ <input name="search" id="search" type="submit" value="<?php p($strsearch) ?>" />
+ <?php
+ if (!empty($searchusers)) {
+ echo '<input name="showall" id="showall" type="submit" value="'.$strshowall.'" />'."\n";
+ }
+ ?>
+ </td>
+ </tr>
+ </table>
+</form>
+
+
$strremovestudent = get_string("removestudent");
$strsearch = get_string("search");
$strsearchresults = get_string("searchresults");
- $strsearchagain = get_string("searchagain");
- $strtoomanytoshow = get_string("toomanytoshow");
$strstudents = get_string("students");
- $strunenrolallstudents = get_string("unenrolallstudents");
- $strunenrolallstudentssure = get_string("unenrolallstudentssure");
+ $strshowall = get_string("showall");
- if ($search) {
- $searchstring = $strsearchagain;
- } else {
- $searchstring = $strsearch;
- }
-
if ($course->students != $strstudents) {
$parastudents = " ($course->students)";
} else {
check_for_restricted_user($USER->username, "$CFG->wwwroot/course/view.php?id=$course->id");
-/// Add a student if one is specified
-
- if (!empty($add)) {
- if ($course->enrolperiod) {
- $timestart = time();
- $timeend = $timestart + $course->enrolperiod;
- } else {
- $timestart = $timeend = 0;
- }
- if (! enrol_student($add, $course->id, $timestart, $timeend)) {
- error("Could not add that student to this course!");
- }
- }
-
-/// Remove a student if one is specified.
-
- if (!empty($remove)) {
- if (! unenrol_student($remove, $course->id)) {
- error("Could not remove that student from this course!");
- }
- }
-
-/// Remove all students from specified course
-
- if (!empty($removeall)) {
- $students = get_course_students($course->id, "u.lastname ASC, u.firstname ASC");
- foreach ($students as $student) {
- if (! unenrol_student($student->id, $course->id)) {
- $fullname = fullname($student, true);
- notify("Could not remove $fullname from this course!");
- }
- }
- }
-
/// Print a help notice about the need to use this page
- if (empty($add) and empty($remove) and empty($search)) {
- $note = get_string("assignstudentsnote");
+ if (!$frm = data_submitted()) {
+ $note = get_string("assignstudentsnote");
+
if ($course->password) {
- $note .= "<p>".get_string("assignstudentspass", "", "<a href=\"edit.php?id=$course->id\">$course->password</a>");
+ $note .= "<p>".get_string("assignstudentspass", "",
+ "<a href=\"edit.php?id=$course->id\">$course->password</a>");
}
print_simple_box($note, "center", "50%");
- }
-
-/// Get all existing students for this course.
- $students = get_course_students($course->id, "u.lastname ASC, u.firstname ASC");
-/// Print the lists of existing and potential students
-
- echo "<table cellpadding=1 cellspacing=5 align=center>";
- echo "<tr><th width=50%>$strexistingstudents$parastudents</th><td> </td><th width=50%>$strpotentialstudents</th></tr>";
- echo "<tr><td width=50% nowrap valign=top>";
-
-/// First, show existing students for this course
-
- if (empty($students)) {
- echo "<p align=center>$strnoexistingstudents</a>";
- $studentlist = "";
+/// A form was submitted so process the input
} else {
- $studentarray = array();
- foreach ($students as $student) {
- $studentarray[] = $student->id;
- $fullname = fullname($student, true);
- echo "<p align=right>$fullname, $student->email <a href=\"student.php?id=$course->id&remove=$student->id\" title=\"$strremovestudent\"><img src=\"../pix/t/right.gif\" border=0></a></p>";
+ if (!empty($frm->add) and !empty($frm->addselect)) {
+ if ($course->enrolperiod) {
+ $timestart = time();
+ $timeend = $timestart + $course->enrolperiod;
+ } else {
+ $timestart = $timeend = 0;
+ }
+ foreach ($frm->addselect as $addstudent) {
+ if (! enrol_student($addstudent, $course->id, $timestart, $timeend)) {
+ error("Could not add student with id $addstudent to this course!");
+ }
+ }
+ } else if (!empty($frm->remove) and !empty($frm->removeselect)) {
+ foreach ($frm->removeselect as $removestudent) {
+ if (! unenrol_student($removestudent, $course->id)) {
+ error("Could not remove student with id $removestudent from this course!");
+ }
+ }
+ } else if (!empty($frm->showall)) {
+ unset($frm->searchtext);
}
- $studentlist = implode(",",$studentarray);
- unset($studentarray);
- // button to unenrol all students from course
-
- echo "<p> </p>\n";
- echo "<p align=\"center\">\n";
- echo "<input type=\"button\" value=\"$strunenrolallstudents\" ".
- " OnClick=\"ctemp = window.confirm('".addslashes($strunenrolallstudentssure)."'); ".
- " if(ctemp) window.location.href='student.php?id=$course->id&removeall=1';\"/>\n";
- echo "</p>\n";
}
- echo "<td> </td>";
- echo "<td width=50% nowrap valign=top>";
-
-/// Print list of potential students
-
- $usercount = get_users(false, $search, true, $studentlist, "lastname ASC, firstname ASC");
-
- if ($usercount == 0) {
- echo "<p align=center>$strnopotentialstudents</p>";
-
- } else if ($usercount > MAX_USERS_PER_PAGE) {
- echo "<p align=center>$strtoomanytoshow ($usercount) </p>";
- } else {
+/// Get all existing students for this course.
+ if (!$students = get_course_students($course->id, "u.firstname ASC, u.lastname ASC", "", 0, 99999,
+ '', '', NULL, '', 'u.id,u.firstname,u.lastname,u.email')) {
+ $students = array();
+ }
+
+ $studentarray = array();
+ foreach ($students as $student) {
+ $studentarray[] = $student->id;
+ }
+ $studentlist = implode(',', $studentarray);
- if ($search) {
- echo "<p align=center>($strsearchresults : $search)</p>";
- }
- if (!$users = get_users(true, $search, true, $studentlist)) {
- error("Could not get users!");
+/// Get search results excluding any users already in this course
+ if (!empty($frm->searchtext)) {
+ if ($searchusers = get_users(true, $frm->searchtext, true, $studentlist, 'firstname ASC, lastname ASC',
+ '', '', 0, 99999, 'id, firstname, lastname, email')) {
+ foreach ($searchusers as $student) {
+ $studentarray[] = $student->id;
+ }
+ $studentlist = implode(',', $studentarray);
}
+ }
- foreach ($users as $user) {
- $fullname = fullname($user, true);
- echo "<p align=left><a href=\"student.php?id=$course->id&add=$user->id\"".
- "title=\"$straddstudent\"><img src=\"../pix/t/left.gif\"".
- "border=0></a> $fullname, $user->email";
+ unset($studentarray);
+
+/// Get potential students for this course excluding users already in course or
+/// users in the search results
+ if (empty($searchusers)) {
+ if (!$users = get_users(true, '', true, $studentlist, 'firstname ASC, lastname ASC', '', '',
+ 0, 99999, 'id, firstname, lastname, email') ) {
+ $users = array();
}
}
- if ($search or $usercount > MAX_USERS_PER_PAGE) {
- echo "<form action=student.php method=post>";
- echo "<input type=hidden name=id value=\"$course->id\">";
- echo "<input type=text name=search size=20>";
- echo "<input type=submit value=\"$searchstring\">";
- echo "</form>";
- }
+ $searchtext = (isset($frm->searchtext)) ? $frm->searchtext : "";
+
+ print_simple_box_start("center", "", "$THEME->cellheading");
+
+ include('student.html');
- echo "</tr></table>";
+ print_simple_box_end();
print_footer();