wwwroot/admin/");
}
require_login();
if (!isadmin()) {
error("You must be an administrator to use this page.");
}
$strassignteachers = get_string("assignteachers");
$stradministration = get_string("administration");
$strexistingteachers = get_string("existingteachers");
$strnoexistingteachers = get_string("noexistingteachers");
$strpotentialteachers = get_string("potentialteachers");
$strnopotentialteachers = get_string("nopotentialteachers");
$straddteacher = get_string("addteacher");
$strremoveteacher = get_string("removeteacher");
$strsearch = get_string("search");
$strsearchagain = get_string("searchagain");
$strtoomanytoshow = get_string("toomanytoshow");
if (!$id) {
print_header("$site->shortname: $strassignteachers", "$site->fullname",
"wwwroot/admin\">$stradministration -> $strassignteachers");
if ($courses = get_courses()) {
print_heading(get_string("choosecourse"));
print_simple_box_start("CENTER");
foreach ($courses as $course) {
echo "id\">$course->fullname
";
}
print_simple_box_end();
} else {
print_heading(get_string("nocoursesyet"));
print_continue("$CFG->wwwroot/admin/");
}
print_footer();
exit;
}
if (! $course = get_record("course", "id", $id)) {
error("Course ID was incorrect (can't find it)");
}
print_header("$site->shortname: $course->shortname: $strassignteachers",
"$site->fullname",
"wwwroot/admin\">$stradministration ->
$strassignteachers ->
$course->shortname", "");
print_heading("wwwroot/course/view.php?id=$course->id\">$course->fullname");
/// Get all existing teachers for this course.
$teachers = get_course_teachers($course->id);
/// Add a teacher if one is specified
if (!empty($add)) {
if (! $user = get_record("user", "id", $add)) {
error("That teacher (id = $add) doesn't exist", "teacher.php?id=$course->id");
}
if (!empty($teachers)) {
foreach ($teachers as $tt) {
if ($tt->id == $user->id) {
error("That user is already a teacher for this course.", "teacher.php?id=$course->id");
}
}
}
$teacher->userid = $user->id;
$teacher->course = $course->id;
if (!empty($teachers)) {
$teacher->authority = 2;
} else {
$teacher->authority = 1; // First teacher is the main teacher
}
$teacher->id = insert_record("user_teachers", $teacher);
if (empty($teacher->id)) {
error("Could not add that teacher to this course!");
}
$teachers[] = $user;
}
/// Remove a teacher if one is specified.
if (!empty($remove)) {
if (! $user = get_record("user", "id", $remove)) {
error("That teacher (id = $remove) doesn't exist", "teacher.php?id=$course->id");
}
if (!empty($teachers)) {
foreach ($teachers as $key => $tt) {
if ($tt->id == $user->id) {
remove_teacher($user->id, $course->id);
unset($teachers[$key]);
}
}
}
}
/// Print the lists of existing and potential teachers
echo "
$strexistingteachers | $strpotentialteachers |
---|---|
";
/// First, show existing teachers for this course
if (empty($teachers)) {
echo " $strnoexistingteachers"; } else { foreach ($teachers as $teacher) { echo " $teacher->firstname $teacher->lastname, $teacher->email id&remove=$teacher->id\" TITLE=\"$strremoveteacher\"> "; } } echo " | ";
/// Print list of potential teachers
if (!empty($search)) {
$users = get_users_search($search);
} else {
$users = get_users_confirmed();
}
if (!empty($users)) {
foreach ($users as $user) { // Remove users who are already teachers
if (!empty($teachers)) {
foreach ($teachers as $teacher) {
if ($teacher->id == $user->id) {
continue 2;
}
}
}
$potential[] = $user;
}
}
if (empty($potential)) {
echo " $strnopotentialteachers"; if ($search) { echo " "; } } else { if (!empty($search)) { echo "($strsearchresults) "; } if (count($potential) <= 20) { foreach ($potential as $user) { echo "id&add=$user->id\" TITLE=\"$straddteacher\"> $user->firstname $user->lastname, $user->email"; } } else { echo " There are too many users to show. |