Release of 1.0.7
[moodle.git] / course / teachers.php
blobd81f8634115f8df2c782ca7e712acb832198d709
1 <?PHP // $Id$
2 // Allows a teacher to edit teacher order and roles for a course
4 require("../config.php");
5 require("lib.php");
7 require_variable($id); // course id
9 if (! $course = get_record("course", "id", $id)) {
10 error("Course ID was incorrect");
13 require_login($course->id);
15 if (!isteacher($course->id)) {
16 error("Only teachers can edit the course!");
20 /// If data submitted, then process and store.
22 if (match_referer() && isset($HTTP_POST_VARS)) {
24 $rank = array();
26 // Peel out all the data from variable names.
27 foreach ($HTTP_POST_VARS as $key => $val) {
28 if ($key <> "id") {
29 $type = substr($key,0,1);
30 $num = substr($key,1);
31 $rank[$num][$type] = $val;
35 foreach ($rank as $num => $vals) {
36 if (! $teacher = get_record_sql("SELECT * FROM user_teachers WHERE course='$course->id' and user='$num'")) {
37 error("No such teacher in course $course->shortname with user id $num");
39 $teacher->role = $vals[r];
40 $teacher->authority = $vals[a];
41 if (!update_record("user_teachers", $teacher)) {
42 error("Could not update teacher entry id = $teacher->id");
45 redirect("teachers.php?id=$course->id", get_string("changessaved"));
48 /// Otherwise fill and print the form.
50 print_header("$course->shortname: $course->teachers", "$course->fullname",
51 "<A HREF=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</A>
52 -> $course->teachers");
54 if (!$teachers = get_course_teachers($course->id)) {
55 error("No teachers found in this course!");
58 print_heading($course->teachers);
60 $table->head = array ("", get_string("name"), get_string("order"), get_string("role"));
61 $table->align = array ("RIGHT", "LEFT", "CENTER", "CENTER");
62 $table->size = array ("35", "", "", "");
64 $option[0] = get_string("hide");
65 for ($i=1; $i<=8; $i++) {
66 $option[$i] = $i;
69 echo "<FORM ACTION=teachers.php METHOD=post>";
70 foreach ($teachers as $teacher) {
72 $picture = print_user_picture($teacher->id, $course->id, $teacher->picture, false, true);
74 $authority = choose_from_menu ($option, "a$teacher->id", $teacher->authority, "", "", "", true);
76 if (!$teacher->role) {
77 $teacher->role = $course->teacher;
80 $table->data[] = array ($picture, "$teacher->firstname $teacher->lastname", $authority,
81 "<INPUT TYPE=text NAME=\"r$teacher->id\" VALUE=\"$teacher->role\" SIZE=30>");
83 print_table($table);
84 echo "<INPUT TYPE=hidden NAME=id VALUE=\"$course->id\">";
85 echo "<CENTER><BR><INPUT TYPE=submit VALUE=\"".get_string("savechanges")."\"> ";
86 helpbutton("teachers", $course->teachers);
87 echo "</CENTER>";
88 echo "</FORM>";
90 print_footer($course);