FIxed bug 3383 ... intro texts no longer center-justified in standard
[moodle.git] / course / teacher.php
blob8f45b0493412f9a47be39ab9fce4273f6faa5737
1 <?php // $Id$
2 // Admin-only script to assign teachers to courses
4 require_once("../config.php");
6 define("MAX_USERS_PER_PAGE", 50);
8 require_variable($id); // course id
9 optional_variable($add, "");
10 optional_variable($remove, "");
11 optional_variable($search, ""); // search string
13 require_login();
15 if (! $course = get_record("course", "id", $id)) {
16 error("Course ID was incorrect (can't find it)");
19 if (!(isteacheredit($course->id) and iscreator()) and
20 !(isteacheredit($course->id) and !empty($CFG->teacherassignteachers) ) ) {
21 error("You must be an administrator or course creator to use this page.");
24 $strassignteachers = get_string("assignteachers");
25 $strcourses = get_string("courses");
26 $strteachers = get_string("teachers");
27 $stradministration = get_string("administration");
28 $strexistingteachers = get_string("existingteachers");
29 $strnoexistingteachers = get_string("noexistingteachers");
30 $strpotentialteachers = get_string("potentialteachers");
31 $strnopotentialteachers = get_string("nopotentialteachers");
32 $straddteacher = get_string("addteacher");
33 $strremoveteacher = get_string("removeteacher");
34 $strsearch = get_string("search");
35 $strsearchresults = get_string("searchresults");
36 $strsearchagain = get_string("searchagain");
37 $strtoomanytoshow = get_string("toomanytoshow");
38 $strname = get_string("name");
39 $strorder = get_string("order");
40 $strrole = get_string("role");
41 $stredit = get_string("editingteachershort");
42 $stryes = get_string("yes");
43 $strno = get_string("no");
45 if ($search) {
46 $searchstring = $strsearchagain;
47 } else {
48 $searchstring = $strsearch;
51 if ($course->teachers != $strteachers) {
52 $parateachers = " ($course->teachers)";
53 } else {
54 $parateachers = "";
59 /// Print headers
61 print_header("$course->shortname: $strassignteachers",
62 "$course->fullname",
63 "<a href=\"index.php\">$strcourses</a> -> ".
64 "<a href=\"view.php?id=$course->id\">$course->shortname</a> -> ".
65 "$strassignteachers", "");
68 /// If data submitted, then process and store.
70 if ($form = data_submitted() and confirm_sesskey()) {
71 unset ($form->sesskey);
72 $rank = array();
74 // Peel out all the data from variable names.
75 foreach ($form as $key => $val) {
76 if ($key <> "id") {
77 $type = substr($key,0,1);
78 $num = substr($key,1);
79 $rank[$num][$type] = $val;
83 foreach ($rank as $num => $vals) {
84 if (! $teacher = get_record("user_teachers", "course", "$course->id", "userid", "$num")) {
85 error("No such teacher in course $course->shortname with user id $num");
87 $teacher->role = $vals['r'];
88 $teacher->authority = $vals['a'];
89 $teacher->editall = $vals['e'];
90 if (!update_record("user_teachers", $teacher)) {
91 error("Could not update teacher entry id = $teacher->id");
94 redirect("teacher.php?id=$course->id", get_string("changessaved"));
97 /// Add a teacher if one is specified
99 if (!empty($_GET['add']) and confirm_sesskey()) {
100 if (! add_teacher($add, $course->id)) {
101 error("Could not add that teacher to this course!");
105 /// Remove a teacher if one is specified.
107 if (!empty($_GET['remove']) and confirm_sesskey()) {
108 if (! remove_teacher($remove, $course->id)) {
109 error("Could not remove that teacher from this course!");
113 /// Display all current teachers for this course.
114 $teachers = get_course_teachers($course->id);
116 print_heading_with_help("$strexistingteachers $parateachers", "teachers");
118 if (empty($teachers)) {
119 echo "<p align=\"center\">$strnoexistingteachers</a>";
120 $teacherlist = "";
122 } else {
124 $table->head = array ("", $strname, $strorder, $strrole, $stredit, "&nbsp;");
125 $table->align = array ("right", "left", "center", "center", "center", "center");
126 $table->size = array ("35", "", "", "", "10", "");
128 $ordermenu = NULL;
129 $ordermenu[0] = get_string("hide");
130 for ($i=1; $i<=8; $i++) {
131 $ordermenu[$i] = $i;
134 $editmenu = NULL;
135 $editmenu[0] = $strno;
136 $editmenu[1] = $stryes;
138 $teacherarray = array();
140 echo "<form action=\"teacher.php\" method=\"post\">";
141 foreach ($teachers as $teacher) {
142 $teacherarray[] = $teacher->id;
144 $picture = print_user_picture($teacher->id, $course->id, $teacher->picture, false, true);
146 $authority = choose_from_menu ($ordermenu, "a$teacher->id", $teacher->authority, "", "", "", true);
148 if ($USER->id == $teacher->id) {
149 $editall = "<input name=\"e$teacher->id\" type=\"hidden\" value=\"1\" />$stryes";
150 } else {
151 $editall = choose_from_menu ($editmenu, "e$teacher->id", $teacher->editall, "", "", "", true);
154 $removelink = "<a href=\"teacher.php?id=$course->id&amp;remove=$teacher->id&amp;sesskey=$USER->sesskey\">$strremoveteacher</a>";
156 if (!$teacher->role) {
157 $teacher->role = $course->teacher;
160 $table->data[] = array ($picture, fullname($teacher, true), $authority,
161 "<input type=\"text\" name=\"r$teacher->id\" value=\"$teacher->role\" size=\"30\" />",
162 $editall, $removelink);
164 $teacherlist = implode(",",$teacherarray);
165 unset($teacherarray);
167 print_table($table);
168 echo "<input type=\"hidden\" name=\"id\" value=\"$course->id\" />";
169 echo "<input type=\"hidden\" name=\"sesskey\" value=\"$USER->sesskey\" />";
170 echo "<center><input type=\"submit\" value=\"".get_string("savechanges")."\" /> ";
171 echo "</center>";
172 echo "</form>";
173 echo "<br />";
177 /// Print list of potential teachers
179 print_heading("$strpotentialteachers $parateachers");
181 $usercount = get_users(false, $search, true, $teacherlist);
183 if ($usercount == 0) {
184 echo "<p align=\"center\">$strnopotentialteachers</p>";
186 } else if ($usercount > MAX_USERS_PER_PAGE) {
187 echo "<p align=\"center\">$strtoomanytoshow ($usercount) </p>";
189 } else {
191 if ($search) {
192 echo "<p align=\"center\">($strsearchresults : $search)</p>";
195 if (!$users = get_users(true, $search, true, $teacherlist)) {
196 error("Could not get users!");
199 unset($table);
200 $table->head = array ("", get_string("name"), get_string("email"), "");
201 $table->align = array ("right", "left", "center", "center");
202 $table->size = array ("35", "", "", "");
205 foreach ($users as $user) {
206 $addlink = "<a href=\"teacher.php?id=$course->id&amp;add=$user->id&amp;sesskey=$USER->sesskey\">$straddteacher</a>";
207 $picture = print_user_picture($user->id, $course->id, $user->picture, false, true);
208 $table->data[] = array ($picture, fullname($user, true), $user->email, $addlink);
210 print_table($table);
213 if ($search or $usercount > MAX_USERS_PER_PAGE) {
214 echo "<center>";
215 echo "<form action=\"teacher.php\" method=\"get\">";
216 echo "<input type=\"hidden\" name=\"id\" value=\"$course->id\" />";
217 echo "<input type=\"text\" name=\"search\" size=\"20\" />";
218 echo "<input type=\"submit\" value=\"$searchstring\" />";
219 echo "</form>";
220 echo "</center>";
223 print_footer($course);