wwwroot/$CFG->admin/index.php"); } if (! $course = get_record("course", "id", $id)) { error("Course ID was incorrect (can't find it)"); } require_login($course->id); if (!isteacher($course->id)) { error("You must be a teacher in this course, or an admin"); } $strassignstudents = get_string("assignstudents"); $strexistingstudents = get_string("existingstudents"); $strnoexistingstudents = get_string("noexistingstudents"); $strpotentialstudents = get_string("potentialstudents"); $strnopotentialstudents = get_string("nopotentialstudents"); $straddstudent = get_string("addstudent"); $strremovestudent = get_string("removestudent"); $strsearch = get_string("search"); $strsearchresults = get_string("searchresults"); $strsearchagain = get_string("searchagain"); $strtoomanytoshow = get_string("toomanytoshow"); $strstudents = get_string("students"); if ($search) { $searchstring = $strsearchagain; } else { $searchstring = $strsearch; } if ($course->students != $strstudents) { $parastudents = " ($course->students)"; } else { $parastudents = ""; } print_header("$course->shortname: $strassignstudents", "$site->fullname", "id\">$course->shortname -> $strassignstudents", ""); /// Add a student if one is specified if (!empty($add)) { if (! enrol_student($add, $course->id)) { 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 add that student to 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 ($course->password) { $note .= "
".get_string("assignstudentspass", "", "id\">$course->password"); } 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 "
$strexistingstudents$parastudents | $strpotentialstudents | |
---|---|---|
";
/// First, show existing students for this course
if (empty($students)) {
echo " $strnoexistingstudents"; $studentlist = ""; } else { $studentarray = array(); foreach ($students as $student) { $studentarray[] = $student->id; $fullname = fullname($student, true); echo " $fullname, $student->email id&remove=$student->id\" title=\"$strremovestudent\"> "; } $studentlist = implode(",",$studentarray); unset($studentarray); } echo " | "; echo " | ";
/// Print list of potential students
$usercount = get_users(false, $search, true, $studentlist, "lastname ASC, firstname ASC");
if ($usercount == 0) {
echo " $strnopotentialstudents "; } else if ($usercount > MAX_USERS_PER_PAGE) { echo "$strtoomanytoshow ($usercount) "; } else { if ($search) { echo "($strsearchresults : $search) "; } if (!$users = get_users(true, $search, true, $studentlist)) { error("Could not get users!"); } foreach ($users as $user) { $fullname = fullname($user, true); echo "id&add=$user->id\"". "title=\"$straddstudent\"> $fullname, $user->email"; } } if ($search or $usercount > MAX_USERS_PER_PAGE) { echo " "; } echo " |