2003-08-17 05:46:07 +00:00
|
|
|
<?PHP // $Id$
|
|
|
|
// Script to assign students to courses
|
|
|
|
|
|
|
|
require_once("../config.php");
|
|
|
|
|
|
|
|
define("MAX_USERS_PER_PAGE", 30);
|
|
|
|
|
|
|
|
require_variable($id); // course id
|
|
|
|
optional_variable($add, "");
|
|
|
|
optional_variable($remove, "");
|
|
|
|
optional_variable($search, ""); // search string
|
|
|
|
|
|
|
|
if (! $site = get_site()) {
|
|
|
|
redirect("$CFG->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);
|
|
|
|
|
2003-08-17 07:30:31 +00:00
|
|
|
if (!isteacher($course->id)) {
|
|
|
|
error("You must be a teacher in this course, or an admin");
|
2003-08-17 05:46:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$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");
|
2003-08-17 07:14:02 +00:00
|
|
|
$strstudents = get_string("students");
|
2003-08-17 05:46:07 +00:00
|
|
|
|
|
|
|
if ($search) {
|
|
|
|
$searchstring = $strsearchagain;
|
|
|
|
} else {
|
|
|
|
$searchstring = $strsearch;
|
|
|
|
}
|
|
|
|
|
2003-08-17 07:14:02 +00:00
|
|
|
if ($course->students != $strstudents) {
|
|
|
|
$parastudents = " ($course->students)";
|
|
|
|
} else {
|
|
|
|
$parastudents = "";
|
|
|
|
}
|
|
|
|
|
2003-08-17 05:46:07 +00:00
|
|
|
print_header("$course->shortname: $strassignstudents",
|
|
|
|
"$site->fullname",
|
|
|
|
"<a href=\"view.php?id=$course->id\">$course->shortname</a> -> $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
|
|
|
|
|
2003-08-17 07:20:40 +00:00
|
|
|
if (empty($add) and empty($remove) and empty($search)) {
|
2003-08-17 05:46:07 +00:00
|
|
|
$note = get_string("assignstudentsnote");
|
|
|
|
if ($course->password) {
|
2003-08-17 07:14:02 +00:00
|
|
|
$note .= "<p>".get_string("assignstudentspass", "", "<a href=\"edit.php?id=$course->id\">$course->password</a>");
|
2003-08-17 05:46:07 +00:00
|
|
|
}
|
|
|
|
print_simple_box($note, "center", "50%");
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Get all existing students for this course.
|
2003-08-17 07:20:40 +00:00
|
|
|
$students = get_course_students($course->id, "u.lastname ASC, u.firstname ASC");
|
2003-08-17 05:46:07 +00:00
|
|
|
|
|
|
|
/// Print the lists of existing and potential students
|
|
|
|
|
2003-08-17 07:29:36 +00:00
|
|
|
echo "<table cellpadding=1 cellspacing=5 align=center>";
|
|
|
|
echo "<tr><th width=50%>$strexistingstudents$parastudents</th><td> </td><th width=50%>$strpotentialstudents</th></tr>";
|
2003-08-17 05:46:07 +00:00
|
|
|
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 = "";
|
|
|
|
|
|
|
|
} else {
|
|
|
|
$studentarray = array();
|
|
|
|
foreach ($students as $student) {
|
|
|
|
$studentarray[] = $student->id;
|
|
|
|
echo "<p align=right>$student->firstname $student->lastname, $student->email <a href=\"student.php?id=$course->id&remove=$student->id\" title=\"$strremovestudent\"><img src=\"../pix/t/right.gif\" border=0></a></p>";
|
|
|
|
}
|
|
|
|
$studentlist = implode(",",$studentarray);
|
|
|
|
unset($studentarray);
|
|
|
|
}
|
|
|
|
|
2003-08-17 07:29:36 +00:00
|
|
|
echo "<td> </td>";
|
2003-08-17 05:46:07 +00:00
|
|
|
echo "<td width=50% nowrap valign=top>";
|
|
|
|
|
|
|
|
/// Print list of potential students
|
|
|
|
|
2003-08-17 07:20:40 +00:00
|
|
|
$usercount = get_users(false, $search, true, $studentlist, "lastname ASC, firstname ASC");
|
2003-08-17 05:46:07 +00:00
|
|
|
|
|
|
|
if ($usercount == 0) {
|
|
|
|
echo "<p align=center>$strnopotentialstudents</p>";
|
|
|
|
|
|
|
|
} else if ($usercount > MAX_USERS_PER_PAGE) {
|
|
|
|
echo "<p align=center>$strtoomanytoshow</p>";
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
if ($search) {
|
|
|
|
echo "<p align=center>($strsearchresults : $search)</p>";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$users = get_users(true, $search, true, $studentlist)) {
|
|
|
|
error("Could not get users!");
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($users as $user) {
|
|
|
|
echo "<p align=left><a href=\"{$_SERVER['PHP_SELF']}?id=$course->id&add=$user->id\"".
|
|
|
|
"title=\"$straddstudent\"><img src=\"../pix/t/left.gif\"".
|
|
|
|
"border=0></a> $user->firstname $user->lastname, $user->email";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($search or $usercount > MAX_USERS_PER_PAGE) {
|
|
|
|
echo "<form action={$_SERVER['PHP_SELF']} 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>";
|
|
|
|
}
|
|
|
|
|
|
|
|
echo "</tr></table>";
|
|
|
|
|
|
|
|
print_footer();
|
|
|
|
|
|
|
|
?>
|