forked from moodle/moodle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathteacher.php
226 lines (173 loc) · 7.95 KB
/
teacher.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
<?php // $Id$
// Admin-only script to assign teachers to courses
/// This page is deprecated
require_once("../config.php");
define("MAX_USERS_PER_PAGE", 50);
$id = required_param('id', PARAM_INT); // course id
$add = optional_param('add', 0, PARAM_INT);
$remove = optional_param('remove', 0, PARAM_INT);
$search = optional_param('search', '', PARAM_RAW); // search string
require_login();
if (! $course = get_record("course", "id", $id)) {
error("Course ID was incorrect (can't find it)");
}
if (!(isteacheredit($course->id) and has_capability('moodle/course:create', get_context_instance(CONTEXT_SYSTEM, SITEID))) and
!(isteacheredit($course->id) and !empty($CFG->teacherassignteachers) ) ) {
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");
$strname = get_string("name");
$strorder = get_string("order");
$strrole = get_string("role");
$stredit = get_string("editingteachershort");
$stryes = get_string("yes");
$strno = get_string("no");
if ($search) {
$searchstring = $strsearchagain;
} else {
$searchstring = $strsearch;
}
if ($course->teachers != $strteachers) {
$parateachers = " ($course->teachers)";
} else {
$parateachers = "";
}
/// If data submitted, then process and store.
if ($form = data_submitted() and confirm_sesskey()) {
unset ($form->sesskey);
$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'];
$teacher->editall = $vals['e'];
if (!update_record("user_teachers", $teacher)) {
error("Could not update teacher entry id = $teacher->id");
}
}
redirect("teacher.php?id=$course->id", get_string("changessaved"));
}
/// 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", "");
/// Add a teacher if one is specified
if (!empty($add) and confirm_sesskey()) {
if (! add_teacher($add, $course->id)) {
error("Could not add that teacher to this course!");
}
}
/// Remove a teacher if one is specified.
if (!empty($remove) and confirm_sesskey()) {
if (! remove_teacher($remove, $course->id)) {
error("Could not remove that teacher from this course!");
}
}
/// Display all current teachers for this course.
$teachers = get_course_teachers($course->id);
print_heading_with_help("$strexistingteachers $parateachers", "teachers");
if (empty($teachers)) {
echo "<p align=\"center\">$strnoexistingteachers</a>";
$teacherlist = "";
} else {
$table->head = array ("", $strname, $strorder, $strrole, $stredit, " ");
$table->align = array ("right", "left", "center", "center", "center", "center");
$table->size = array ("35", "", "", "", "10", "");
$ordermenu = NULL;
$ordermenu[0] = get_string("hide");
for ($i=1; $i<=8; $i++) {
$ordermenu[$i] = $i;
}
$editmenu = NULL;
$editmenu[0] = $strno;
$editmenu[1] = $stryes;
$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 ($ordermenu, "a$teacher->id", $teacher->authority, "", "", "", true);
if ($USER->id == $teacher->id) {
$editall = "<input name=\"e$teacher->id\" type=\"hidden\" value=\"1\" />$stryes";
} else {
$editall = choose_from_menu ($editmenu, "e$teacher->id", $teacher->editall, "", "", "", true);
}
$removelink = "<a href=\"teacher.php?id=$course->id&remove=$teacher->id&sesskey=$USER->sesskey\">$strremoveteacher</a>";
if (!$teacher->role) {
$teacher->role = $course->teacher;
}
$table->data[] = array ($picture, fullname($teacher, true), $authority,
"<input type=\"text\" name=\"r$teacher->id\" value=\"$teacher->role\" size=\"30\" maxlength=\"40\" />",
$editall, $removelink);
}
$teacherlist = implode(",",$teacherarray);
unset($teacherarray);
print_table($table);
echo "<input type=\"hidden\" name=\"id\" value=\"$course->id\" />";
echo "<input type=\"hidden\" name=\"sesskey\" value=\"$USER->sesskey\" />";
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 ($usercount) </p>";
} else {
if ($search != '') {
echo "<p align=\"center\">($strsearchresults : ".s($search, true).")</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&sesskey=$USER->sesskey\">$straddteacher</a>";
$picture = print_user_picture($user->id, $course->id, $user->picture, false, true);
$table->data[] = array ($picture, fullname($user, true), $user->email, $addlink);
}
print_table($table);
}
if (($search != '') or $usercount > MAX_USERS_PER_PAGE) {
echo "<center>";
echo "<form action=\"teacher.php\" method=\"get\">";
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 "</center>";
}
print_footer($course);
?>