2001-11-22 06:23:56 +00:00
|
|
|
<?PHP // $Id$
|
2002-08-11 15:41:54 +00:00
|
|
|
// Admin-only script to assign teachers to courses
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2003-01-05 14:19:20 +00:00
|
|
|
require_once("../config.php");
|
2003-05-14 15:58:48 +00:00
|
|
|
|
|
|
|
define("MAX_USERS_PER_PAGE", 30);
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2003-05-14 16:05:21 +00:00
|
|
|
optional_variable($id); // course id
|
|
|
|
optional_variable($add, "");
|
|
|
|
optional_variable($remove, "");
|
|
|
|
optional_variable($search, ""); // search string
|
2001-11-22 06:23:56 +00:00
|
|
|
|
|
|
|
if (! $site = get_site()) {
|
2003-04-10 13:46:52 +00:00
|
|
|
redirect("$CFG->wwwroot/$CFG->admin/index.php");
|
2001-11-22 06:23:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
require_login();
|
|
|
|
|
2003-02-24 18:48:55 +00:00
|
|
|
if (!iscreator()) {
|
2003-02-26 05:55:31 +00:00
|
|
|
error("You must be an administrator or course creator to use this page.");
|
2001-11-22 06:23:56 +00:00
|
|
|
}
|
|
|
|
|
2002-08-08 15:51:23 +00:00
|
|
|
$strassignteachers = get_string("assignteachers");
|
|
|
|
$stradministration = get_string("administration");
|
2002-09-03 13:11:40 +00:00
|
|
|
$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");
|
2003-04-18 01:57:24 +00:00
|
|
|
$strsearchresults = get_string("searchresults");
|
2002-09-03 13:11:40 +00:00
|
|
|
$strsearchagain = get_string("searchagain");
|
|
|
|
$strtoomanytoshow = get_string("toomanytoshow");
|
2002-08-08 15:51:23 +00:00
|
|
|
|
2003-05-14 16:05:21 +00:00
|
|
|
if ($search) {
|
|
|
|
$searchstring = $strsearchagain;
|
|
|
|
} else {
|
|
|
|
$searchstring = $strsearch;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-11-22 06:23:56 +00:00
|
|
|
if (!$id) {
|
2002-09-27 14:26:02 +00:00
|
|
|
print_header("$site->shortname: $strassignteachers", "$site->fullname",
|
2003-05-14 15:58:48 +00:00
|
|
|
"<a href=\"index.php\">$stradministration</a> -> $strassignteachers");
|
2003-02-24 18:48:55 +00:00
|
|
|
|
|
|
|
$isadmin = isadmin(); /// cache value
|
|
|
|
$courses = get_courses();
|
|
|
|
|
|
|
|
print_heading(get_string("choosecourse"));
|
2003-05-14 15:58:48 +00:00
|
|
|
print_simple_box_start("center");
|
2003-02-24 18:48:55 +00:00
|
|
|
|
2003-06-06 06:20:57 +00:00
|
|
|
if (!empty($courses)) {
|
|
|
|
foreach ($courses as $course) {
|
|
|
|
if ($isadmin or isteacher($course->id, $USER->id)){
|
|
|
|
echo "<a href=\"teacher.php?id=$course->id\">$course->fullname ($course->shortname)</a><br>\n";
|
|
|
|
$coursesfound = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2003-02-24 18:48:55 +00:00
|
|
|
|
|
|
|
print_simple_box_end();
|
|
|
|
|
|
|
|
if ($coursesfound == FALSE) {
|
2002-08-03 04:44:35 +00:00
|
|
|
print_heading(get_string("nocoursesyet"));
|
2003-04-10 13:46:52 +00:00
|
|
|
print_continue("../$CFG->admin/index.php");
|
2001-11-22 06:23:56 +00:00
|
|
|
}
|
2003-02-24 18:48:55 +00:00
|
|
|
|
2001-11-22 06:23:56 +00:00
|
|
|
print_footer();
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! $course = get_record("course", "id", $id)) {
|
|
|
|
error("Course ID was incorrect (can't find it)");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-09-27 14:26:02 +00:00
|
|
|
print_header("$site->shortname: $course->shortname: $strassignteachers",
|
2002-08-08 15:51:23 +00:00
|
|
|
"$site->fullname",
|
2003-05-14 15:58:48 +00:00
|
|
|
"<a href=\"index.php\">$stradministration</a> ->
|
|
|
|
<a href=\"teacher.php\">$strassignteachers</a> -> $course->shortname", "");
|
|
|
|
|
|
|
|
print_heading("<a href=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->fullname ($course->shortname)</a>");
|
2001-11-22 06:23:56 +00:00
|
|
|
|
|
|
|
|
2001-11-29 05:46:15 +00:00
|
|
|
/// Get all existing teachers for this course.
|
2002-09-22 14:06:38 +00:00
|
|
|
$teachers = get_course_teachers($course->id);
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2001-11-29 05:46:15 +00:00
|
|
|
/// Add a teacher if one is specified
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2003-01-01 08:21:19 +00:00
|
|
|
if (!empty($add)) {
|
2003-02-26 05:58:44 +00:00
|
|
|
if (!isteacher($course->id)){
|
2003-02-24 18:48:55 +00:00
|
|
|
error("You must be an administrator or teacher to modify this course.");
|
|
|
|
}
|
|
|
|
|
2001-11-29 05:46:15 +00:00
|
|
|
if (! $user = get_record("user", "id", $add)) {
|
|
|
|
error("That teacher (id = $add) doesn't exist", "teacher.php?id=$course->id");
|
|
|
|
}
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2003-01-01 08:21:19 +00:00
|
|
|
if (!empty($teachers)) {
|
2001-12-04 14:02:36 +00:00
|
|
|
foreach ($teachers as $tt) {
|
|
|
|
if ($tt->id == $user->id) {
|
|
|
|
error("That user is already a teacher for this course.", "teacher.php?id=$course->id");
|
|
|
|
}
|
2001-11-22 06:23:56 +00:00
|
|
|
}
|
2001-11-29 05:46:15 +00:00
|
|
|
}
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2002-12-23 09:39:26 +00:00
|
|
|
$teacher->userid = $user->id;
|
2001-11-29 05:46:15 +00:00
|
|
|
$teacher->course = $course->id;
|
2003-01-01 08:21:19 +00:00
|
|
|
if (!empty($teachers)) {
|
2001-11-29 05:46:15 +00:00
|
|
|
$teacher->authority = 2;
|
|
|
|
} else {
|
|
|
|
$teacher->authority = 1; // First teacher is the main teacher
|
|
|
|
}
|
|
|
|
$teacher->id = insert_record("user_teachers", $teacher);
|
2003-01-01 08:21:19 +00:00
|
|
|
if (empty($teacher->id)) {
|
2001-11-29 05:46:15 +00:00
|
|
|
error("Could not add that teacher to this course!");
|
|
|
|
}
|
|
|
|
$teachers[] = $user;
|
|
|
|
}
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2001-11-29 05:46:15 +00:00
|
|
|
/// Remove a teacher if one is specified.
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2003-01-01 08:21:19 +00:00
|
|
|
if (!empty($remove)) {
|
2003-02-24 18:48:55 +00:00
|
|
|
|
2003-02-26 05:58:44 +00:00
|
|
|
if (!isteacher($course->id)){
|
2003-02-24 18:48:55 +00:00
|
|
|
error("You must be an administrator or teacher to modify this course.");
|
|
|
|
}
|
2001-11-29 05:46:15 +00:00
|
|
|
if (! $user = get_record("user", "id", $remove)) {
|
|
|
|
error("That teacher (id = $remove) doesn't exist", "teacher.php?id=$course->id");
|
|
|
|
}
|
2003-01-01 08:21:19 +00:00
|
|
|
if (!empty($teachers)) {
|
2002-09-22 14:06:38 +00:00
|
|
|
foreach ($teachers as $key => $tt) {
|
2001-12-04 14:02:36 +00:00
|
|
|
if ($tt->id == $user->id) {
|
2002-09-22 14:06:38 +00:00
|
|
|
remove_teacher($user->id, $course->id);
|
|
|
|
unset($teachers[$key]);
|
2001-12-04 14:02:36 +00:00
|
|
|
}
|
2001-11-29 05:46:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2001-11-22 06:23:56 +00:00
|
|
|
|
|
|
|
|
2001-12-04 14:02:36 +00:00
|
|
|
/// Print the lists of existing and potential teachers
|
|
|
|
|
2003-05-14 15:58:48 +00:00
|
|
|
echo "<table cellpadding=2 cellspacing=10 align=center>";
|
|
|
|
echo "<tr><th width=50%>$strexistingteachers</th><th width=50%>$strpotentialteachers</th></tr>";
|
|
|
|
echo "<tr><td width=50% nowrap valign=top>";
|
2001-12-04 14:02:36 +00:00
|
|
|
|
|
|
|
/// First, show existing teachers for this course
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2003-01-01 08:21:19 +00:00
|
|
|
if (empty($teachers)) {
|
2003-05-14 15:58:48 +00:00
|
|
|
echo "<p align=center>$strnoexistingteachers</a>";
|
|
|
|
$teacherlist = "";
|
2001-12-04 14:02:36 +00:00
|
|
|
|
|
|
|
} else {
|
2003-05-14 15:58:48 +00:00
|
|
|
$teacherarray = array();
|
2001-11-29 05:46:15 +00:00
|
|
|
foreach ($teachers as $teacher) {
|
2003-05-14 15:58:48 +00:00
|
|
|
$teacherarray[] = $teacher->id;
|
|
|
|
echo "<p align=right>$teacher->firstname $teacher->lastname, $teacher->email <a href=\"teacher.php?id=$course->id&remove=$teacher->id\" title=\"$strremoveteacher\"><img src=\"../pix/t/right.gif\" border=0></a></p>";
|
2001-11-29 05:46:15 +00:00
|
|
|
}
|
2003-05-14 15:58:48 +00:00
|
|
|
$teacherlist = implode(",",$teacherarray);
|
|
|
|
unset($teacherarray);
|
2001-11-29 05:46:15 +00:00
|
|
|
}
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2003-05-14 15:58:48 +00:00
|
|
|
echo "<td width=50% nowrap valign=top>";
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2001-12-04 14:02:36 +00:00
|
|
|
/// Print list of potential teachers
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2003-05-14 15:58:48 +00:00
|
|
|
$usercount = get_users(false, $search, true, $teacherlist);
|
2003-01-01 08:21:19 +00:00
|
|
|
|
2003-05-14 15:58:48 +00:00
|
|
|
if ($usercount == 0) {
|
|
|
|
echo "<p align=center>$strnopotentialteachers</p>";
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2003-05-14 15:58:48 +00:00
|
|
|
} else if ($usercount > MAX_USERS_PER_PAGE) {
|
|
|
|
echo "<p align=center>$strtoomanytoshow</p>";
|
|
|
|
|
|
|
|
} else {
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2001-12-04 14:02:36 +00:00
|
|
|
if ($search) {
|
2003-05-14 15:58:48 +00:00
|
|
|
echo "<p align=center>($strsearchresults : $search)</p>";
|
2001-12-04 14:02:36 +00:00
|
|
|
}
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2003-05-14 15:58:48 +00:00
|
|
|
if (!$users = get_users(true, $search, true, $teacherlist)) {
|
|
|
|
error("Could not get users!");
|
2001-12-04 14:02:36 +00:00
|
|
|
}
|
2003-05-14 15:58:48 +00:00
|
|
|
|
|
|
|
foreach ($users as $user) {
|
|
|
|
echo "<p align=left><a href=\"{$_SERVER['PHP_SELF']}?id=$course->id&add=$user->id\"".
|
|
|
|
"title=\"$straddteacher\"><img src=\"../pix/t/left.gif\"".
|
|
|
|
"border=0></a> $user->firstname $user->lastname, $user->email";
|
2001-11-29 05:46:15 +00:00
|
|
|
}
|
|
|
|
}
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2003-05-14 15:58:48 +00:00
|
|
|
if ($search or $usercount > MAX_USERS_PER_PAGE) {
|
|
|
|
echo "<form action={$_SERVER['PHP_SELF']} method=post>";
|
2003-05-14 16:05:21 +00:00
|
|
|
echo "<input type=hidden name=id value=\"$course->id\">";
|
2003-05-14 15:58:48 +00:00
|
|
|
echo "<input type=text name=search size=20>";
|
|
|
|
echo "<input type=submit value=\"$searchstring\">";
|
|
|
|
echo "</form>";
|
|
|
|
}
|
|
|
|
|
|
|
|
echo "</tr></table>";
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2001-11-29 05:46:15 +00:00
|
|
|
print_footer();
|
2001-11-22 06:23:56 +00:00
|
|
|
|
|
|
|
?>
|