mirror of
https://github.com/moodle/moodle.git
synced 2025-08-06 01:16:44 +02:00

OK, this is a big check-in with some big changes, and needs work still. It seems relatively stable, but I need help identifying the rough patches. 1) First grading scales support. There is a now a new table called "scale" that contains grading scales. There can be site scales (course=0) and custom course scales. These can be used in modules - I've only done forums for now but that was the hard one. Scales can be edited via the new item in the course admin menu. There is one default scale - the connected/separate knowing one that used to be in forum. To build this I pull data from the language packs to create one during the upgrade, or anytime a scales menu is called and no scales are found. 2) New roles for course creator and teachers. I've fixed up the course menus and some other things but there's a lot left to do on this to make it all smooth. The idea is that teachers no longer can edit courses unless they are also course creators. The interface for this needs to be smoothed out a fair bit and I need help with this. The upgrade will upgrade all teachers to be creators, but will default the new site config "creatornewcourses" to "no", so that effectively these new teachers have the same privileges. 3) Simplified teacher management. There is no longer an "assign teachers" and a "teacher roles" page - it's all on one page in course/teacher.html. Phew ... time for a shower and then back into it.
245 lines
8 KiB
PHP
245 lines
8 KiB
PHP
<?PHP // $Id$
|
|
// Admin-only script to assign teachers 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
|
|
|
|
require_login();
|
|
|
|
if (! $course = get_record("course", "id", $id)) {
|
|
error("Course ID was incorrect (can't find it)");
|
|
}
|
|
|
|
if (!iscreator() and isteacher($course->id)) {
|
|
error("You must be an administrator or course creator to use this page.");
|
|
}
|
|
|
|
$strassignteachers = get_string("assignteachers");
|
|
$strcourses = get_string("courses");
|
|
$strteachers = get_string("teachers");
|
|
$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 ($course->teachers != $strteachers) {
|
|
$parateachers = " ($course->teachers)";
|
|
} else {
|
|
$parateachers = "";
|
|
}
|
|
|
|
|
|
|
|
/// Print headers
|
|
|
|
print_header("$course->shortname: $strassignteachers",
|
|
"$course->fullname",
|
|
"<a href=\"index.php\">$strcourses</a> -> ".
|
|
"<a href=\"view.php?id=$course->id\">$course->shortname</a> -> ".
|
|
"$strassignteachers", "");
|
|
|
|
|
|
/// If data submitted, then process and store.
|
|
|
|
if ($form = data_submitted()) {
|
|
$rank = array();
|
|
|
|
// Peel out all the data from variable names.
|
|
foreach ($form as $key => $val) {
|
|
if ($key <> "id") {
|
|
$type = substr($key,0,1);
|
|
$num = substr($key,1);
|
|
$rank[$num][$type] = $val;
|
|
}
|
|
}
|
|
|
|
foreach ($rank as $num => $vals) {
|
|
if (! $teacher = get_record("user_teachers", "course", "$course->id", "userid", "$num")) {
|
|
error("No such teacher in course $course->shortname with user id $num");
|
|
}
|
|
$teacher->role = $vals['r'];
|
|
$teacher->authority = $vals['a'];
|
|
if (!update_record("user_teachers", $teacher)) {
|
|
error("Could not update teacher entry id = $teacher->id");
|
|
}
|
|
}
|
|
redirect("teacher.php?id=$course->id", get_string("changessaved"));
|
|
}
|
|
|
|
|
|
/// Get all existing teachers for this course.
|
|
$teachers = get_course_teachers($course->id);
|
|
|
|
|
|
/// Add a teacher if one is specified
|
|
|
|
if (!empty($_GET['add'])) {
|
|
if (!isteacher($course->id)){
|
|
error("You must be an administrator or teacher to modify this course.");
|
|
}
|
|
|
|
if (! $user = get_record("user", "id", $_GET['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!");
|
|
}
|
|
$user->authority = $teacher->authority;
|
|
$teachers[] = $user;
|
|
|
|
}
|
|
|
|
/// Remove a teacher if one is specified.
|
|
|
|
if (!empty($_GET['remove'])) {
|
|
|
|
if (!isteacher($course->id)){
|
|
error("You must be an administrator or teacher to modify this course.");
|
|
}
|
|
if (! $user = get_record("user", "id", $_GET['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_heading_with_help("$strexistingteachers $parateachers", "teachers");
|
|
|
|
if (empty($teachers)) {
|
|
echo "<p align=center>$strnoexistingteachers</a>";
|
|
$teacherlist = "";
|
|
|
|
} else {
|
|
|
|
$table->head = array ("", get_string("name"), get_string("order"), get_string("role"), " ");
|
|
$table->align = array ("right", "left", "center", "center", "center");
|
|
$table->size = array ("35", "", "", "", "");
|
|
|
|
$option[0] = get_string("hide");
|
|
for ($i=1; $i<=8; $i++) {
|
|
$option[$i] = $i;
|
|
}
|
|
|
|
$teacherarray = array();
|
|
|
|
echo "<form action=teacher.php method=post>";
|
|
foreach ($teachers as $teacher) {
|
|
$teacherarray[] = $teacher->id;
|
|
|
|
$picture = print_user_picture($teacher->id, $course->id, $teacher->picture, false, true);
|
|
|
|
$authority = choose_from_menu ($option, "a$teacher->id", $teacher->authority, "", "", "", true);
|
|
|
|
$removelink = "<a href=\"teacher.php?id=$course->id&remove=$teacher->id\">$strremoveteacher</a>";
|
|
|
|
if (!$teacher->role) {
|
|
$teacher->role = $course->teacher;
|
|
}
|
|
|
|
$table->data[] = array ($picture, "$teacher->firstname $teacher->lastname", $authority,
|
|
"<input type=text name=\"r$teacher->id\" value=\"$teacher->role\" size=30>",
|
|
$removelink);
|
|
}
|
|
$teacherlist = implode(",",$teacherarray);
|
|
unset($teacherarray);
|
|
|
|
print_table($table);
|
|
echo "<input type=hidden name=id value=\"$course->id\">";
|
|
echo "<center><input type=submit value=\"".get_string("savechanges")."\"> ";
|
|
echo "</center>";
|
|
echo "</form>";
|
|
echo "<br />";
|
|
}
|
|
|
|
|
|
/// Print list of potential teachers
|
|
|
|
print_heading("$strpotentialteachers $parateachers");
|
|
|
|
$usercount = get_users(false, $search, true, $teacherlist);
|
|
|
|
if ($usercount == 0) {
|
|
echo "<p align=center>$strnopotentialteachers</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, $teacherlist)) {
|
|
error("Could not get users!");
|
|
}
|
|
|
|
unset($table);
|
|
$table->head = array ("", get_string("name"), get_string("email"), "");
|
|
$table->align = array ("right", "left", "center", "center");
|
|
$table->size = array ("35", "", "", "");
|
|
|
|
|
|
foreach ($users as $user) {
|
|
$addlink = "<a href=\"teacher.php?id=$course->id&add=$user->id\">$straddteacher</a>";
|
|
$picture = print_user_picture($user->id, $course->id, $user->picture, false, true);
|
|
$table->data[] = array ($picture, "$user->firstname $user->lastname", $user->email, $addlink);
|
|
}
|
|
print_table($table);
|
|
}
|
|
|
|
if ($search or $usercount > MAX_USERS_PER_PAGE) {
|
|
echo "<form action=teacher.php 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 "</td></tr></table>";
|
|
|
|
print_footer();
|
|
|
|
?>
|