wwwroot/$CFG->admin/index.php"); } require_login(); if (!iscreator()) { error("You must be an administrator or course creator 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"); $strsearchresults = get_string("searchresults"); $strsearchagain = get_string("searchagain"); $strtoomanytoshow = get_string("toomanytoshow"); if ($search) { $searchstring = $strsearchagain; } else { $searchstring = $strsearch; } if (!$id) { print_header("$site->shortname: $strassignteachers", "$site->fullname", "$stradministration -> $strassignteachers"); $isadmin = isadmin(); /// cache value $courses = get_courses(); print_heading(get_string("choosecourse")); print_simple_box_start("center"); if (!empty($courses)) { foreach ($courses as $course) { if ($isadmin or isteacher($course->id, $USER->id)){ echo "id\">$course->fullname ($course->shortname)
\n"; $coursesfound = TRUE; } } } print_simple_box_end(); if ($coursesfound == FALSE) { print_heading(get_string("nocoursesyet")); print_continue("../$CFG->admin/index.php"); } 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", "$stradministration -> $strassignteachers -> $course->shortname", ""); print_heading("wwwroot/course/view.php?id=$course->id\">$course->fullname ($course->shortname)"); /// Get all existing teachers for this course. $teachers = get_course_teachers($course->id); /// Add a teacher if one is specified if (!empty($add)) { if (!isteacher($course->id)){ error("You must be an administrator or teacher to modify this course."); } 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 (!isteacher($course->id)){ error("You must be an administrator or teacher to modify this course."); } 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 ""; echo ""; echo "
$strexistingteachers$strpotentialteachers
"; /// First, show existing teachers for this course if (empty($teachers)) { echo "

$strnoexistingteachers"; $teacherlist = ""; } else { $teacherarray = array(); foreach ($teachers as $teacher) { $teacherarray[] = $teacher->id; echo "

$teacher->firstname $teacher->lastname, $teacher->email    id&remove=$teacher->id\" title=\"$strremoveteacher\">

"; } $teacherlist = implode(",",$teacherarray); unset($teacherarray); } echo "
"; /// Print list of potential teachers $usercount = get_users(false, $search, true, $teacherlist); if ($usercount == 0) { echo "

$strnopotentialteachers

"; } else if ($usercount > MAX_USERS_PER_PAGE) { echo "

$strtoomanytoshow

"; } else { if ($search) { echo "

($strsearchresults : $search)

"; } if (!$users = get_users(true, $search, true, $teacherlist)) { error("Could not get users!"); } foreach ($users as $user) { echo "

id&add=$user->id\"". "title=\"$straddteacher\">  $user->firstname $user->lastname, $user->email"; } } if ($search or $usercount > MAX_USERS_PER_PAGE) { echo "

"; echo "id\">"; echo ""; echo ""; echo "
"; } echo "
"; print_footer(); ?>