-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathajax_admin.php
More file actions
361 lines (269 loc) · 15.5 KB
/
ajax_admin.php
File metadata and controls
361 lines (269 loc) · 15.5 KB
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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
<?php // $Id:,v 2.0 2012/05/20 16:10:00 Serafim Panov
require_once("../../config.php");
$id = required_param('id', PARAM_INT);
$a = optional_param('a', NULL, PARAM_CLEAN);
$act = optional_param('act', NULL, PARAM_CLEAN);
$f = optional_param('f', NULL, PARAM_TEXT);
$promotionstop = optional_param('promotionstop', NULL, PARAM_INT);
$setgoal = optional_param('setgoal', NULL, PARAM_INT);
$nopromote = optional_param('nopromote', NULL, PARAM_INT);
$userid = optional_param('userid', NULL, PARAM_INT);
$startlevel = optional_param('startlevel', NULL, PARAM_INT);
$currentlevel = optional_param('currentlevel', NULL, PARAM_INT);
$length = optional_param('length', NULL, PARAM_CLEAN);
$bookid = optional_param('bookid', NULL, PARAM_INT);
$difficulty = optional_param('difficulty', NULL, PARAM_INT);
$words = optional_param('words', NULL, PARAM_INT);
$publishertitle = optional_param('publishertitle', NULL, PARAM_TEXT);
$publisher = optional_param('publisher', NULL, PARAM_TEXT);
$level = optional_param('level', NULL, PARAM_TEXT);
$masspublisherfrom = optional_param('masspublisherfrom', NULL, PARAM_TEXT);
$masspublisherto = optional_param('masspublisherto', NULL, PARAM_TEXT);
$masslevelto = optional_param('masslevelto', NULL, PARAM_TEXT);
$masslevelfrom = optional_param('masslevelfrom', NULL, PARAM_TEXT);
$masslengthfrom = optional_param('masslengthfrom', NULL, PARAM_TEXT);
$masslengthto = optional_param('masslengthto', NULL, PARAM_TEXT);
$massdifficultyto = optional_param('massdifficultyto', NULL, PARAM_TEXT);
$massdifficultyfrom = optional_param('massdifficultyfrom', NULL, PARAM_TEXT);
if (!$cm = get_coursemodule_from_id('reader', $id)) {
print_error('invalidcoursemodule');
}
if (!$course = $DB->get_record('course', array('id' => $cm->course))) {
print_error("coursemisconf");
}
if (!$reader = $DB->get_record('reader', array('id' => $cm->instance))) {
print_error('invalidcoursemodule');
}
require_login($course, true, $cm);
add_to_log($course->id, "reader", "admin ajax call", "ajax_admin.php?id=$id", "$cm->instance");
$contextmodule = get_context_instance(CONTEXT_MODULE, $cm->id);
/*
* PROMOTION STOP
*/
if (has_capability('mod/reader:manage', $contextmodule) && $f == 'promotionstop') {
if ($studentlevel = $DB->get_record("reader_levels", array("userid" => $userid, "readerid" => $reader->id))) {
$DB->set_field("reader_levels", 'promotionstop', $promotionstop, array( "userid" => $userid, "readerid" => $reader->id));
}
add_to_log($course->id, "reader", substr("AA-Student Promotion Stop Changed ({$userid} set to {$promotionstop})",0,39), "admin.php?id=$id", "$cm->instance");
$studentlevel->promotionstop = $promotionstop;
//echo reader_promotion_stop_box ($userid, $studentlevel);
echo $promotionstop;
die();
}
/*
* SET GOAL
*/
if (has_capability('mod/reader:manage', $contextmodule) && $f == 'setgoal') {
if ($data = $DB->get_record("reader_levels", array("userid" => $userid, "readerid" => $reader->id))) {
$DB->set_field("reader_levels", "goal", $setgoal, array( "id" => $data->id));
} else {
$data = new stdClass;
$data->userid = $userid;
$data->startlevel = 0;
$data->currentlevel = 0;
$data->readerid = $reader->id;
$data->goal = $setgoal;
$data->time = time();
$DB->insert_record("reader_levels", $data);
}
add_to_log($course->id, "reader", "AA-Change Student Goal ({$setgoal})", "admin.php?id=$id", "$cm->instance");
$data->goal = $setgoal;
//echo reader_goal_box ($userid, $data, $reader);
echo $setgoal;
die();
}
/*
* SET NO PROMOTE
*/
if (has_capability('mod/reader:manage', $contextmodule) && $f == 'nopromote') {
if ($studentlevel = $DB->get_record("reader_levels", array("userid" => $userid, "readerid" => $reader->id))) {
$DB->set_field("reader_levels", 'nopromote', $nopromote, array( "userid" => $userid, "readerid" => $reader->id));
}
add_to_log($course->id, "reader", substr("AA-Student NoPromote Changed ({$userid} set to {$nopromote})",0,39), "admin.php?id=$id", "$cm->instance");
$studentlevel->nopromote = $nopromote;
if ($nopromote == 0)
echo "Promo";
else
echo "NoPromo";
//echo reader_yes_no_box ($userid, $studentlevel);
die();
}
/*
* SET START LEVEL
*/
if (has_capability('mod/reader:manage', $contextmodule) && $f == 'startlevel') {
if ($studentlevel = $DB->get_record("reader_levels", array("userid" => $userid, "readerid" => $reader->id))) {
$DB->set_field("reader_levels", "startlevel", $startlevel, array( "userid" => $userid, "readerid" => $reader->id));
$DB->set_field("reader_levels", 'time', time(), array("userid" => $userid, "readerid" => $reader->id));
} else {
$data = new stdClass;
$data->userid = $userid;
$data->startlevel = $startlevel;
$data->currentlevel = $startlevel;
$data->readerid = $reader->id;
$data->time = time();
$DB->insert_record("reader_levels", $data);
}
add_to_log($course->id, "reader", substr("AA-Student Level Changed ({$userid} {$studentlevel->startlevel} to {$startlevel})", 0, 39), "admin.php?id=$id", "$cm->instance");
$studentlevel->startlevel = $startlevel;
//echo reader_selectlevel_box ($userid, $studentlevel, $slevel);
echo $startlevel;
die();
}
/*
* SET CURRENT LEVEL
*/
if (has_capability('mod/reader:manage', $contextmodule) && $f == 'currentlevel') {
if ($studentlevel = $DB->get_record("reader_levels", array("userid" => $userid, "readerid" => $reader->id))) {
$DB->set_field("reader_levels", "currentlevel", $currentlevel, array( "userid" => $userid, "readerid" => $reader->id));
$DB->set_field("reader_levels", 'time', time(), array("userid" => $userid, "readerid" => $reader->id));
} else {
$data = new stdClass;
$data->userid = $userid;
$data->startlevel = $currentlevel;
$data->currentlevel = $currentlevel;
$data->readerid = $reader->id;
$data->time = time();
$DB->insert_record("reader_levels", $data);
}
add_to_log($course->id, "reader", substr("AA-Student Level Changed ({$userid} {$studentlevel->currentlevel} to {$currentlevel})", 0, 39), "admin.php?id=$id", "$cm->instance");
$studentlevel->currentlevel = $currentlevel;
//echo reader_selectlevel_box ($userid, $studentlevel, $slevel);
echo $currentlevel;
die();
}
/*
* CHANGE BOOK LENGTH
*/
if (has_capability('mod/reader:manage', $contextmodule) && $f == "changelength") {
if ($reader->individualbooks == 0) {
if ($bookdata = $DB->get_record("reader_publisher", array("id" => $bookid))) {
$DB->set_field("reader_publisher", "length", $length, array( "id" => $bookid));
}
add_to_log($course->id, "reader", substr("AA-Change length ({$bookid} {$bookdata->length} to {$length})",0,39), "admin.php?id=$id", "$cm->instance");
} else {
if ($bookdata = $DB->get_record("reader_individual_books", array("readerid" => $reader->id, "bookid" => $bookid))) {
$DB->set_field("reader_individual_books", "length", $length, array( "readerid" => $reader->id, "bookid" => $bookid));
}
add_to_log($course->id, "reader", substr("AA-Change length individual ({$bookid} {$bookdata->length} to {$length})",0,39), "admin.php?id=$id", "$cm->instance");
}
//echo reader_select_length_box ($length, $book->id);
echo $length;
die();
}
/*
* CHANGE DIFFICULTY LENGTH
*/
if (has_capability('mod/reader:manage', $contextmodule) && $f == "changedifficulty") {
if ($reader->individualbooks == 0) {
if ($bookdata = $DB->get_record("reader_publisher", array("id" => $bookid))) {
$DB->set_field("reader_publisher", "difficulty", $difficulty, array( "id" => $bookid));
}
add_to_log($course->id, "reader", substr("AA-Change difficulty ({$bookid} {$bookdata->difficulty} to {$difficulty})",0,39), "admin.php?id=$id", "$cm->instance");
} else {
if ($bookdata = $DB->get_record("reader_individual_books", array("readerid" => $reader->id, "bookid" => $bookid))) {
$DB->set_field("reader_individual_books", "difficulty", $difficulty, array( "readerid" => $reader->id, "bookid" => $bookid));
}
add_to_log($course->id, "reader", substr("AA-Change difficulty individual ({$bookid} {$bookdata->difficulty} to {$difficulty})",0,39), "admin.php?id=$id", "$cm->instance");
}
//echo reader_select_difficulty_box (reader_get_reader_difficulty($reader, $bookid), $book->id);
echo $difficulty;
die();
}
/*
* CHANGE BOOK TITLE
*/
if (has_capability('mod/reader:manage', $contextmodule) && $f == "publishertitletext") {
$DB->set_field("reader_publisher", 'publisher', urldecode($publishertitle), array( "id" => $bookid));
echo $publishertitle;
die();
}
/*
* CHANGE BOOK LEVEL
*/
if (has_capability('mod/reader:manage', $contextmodule) && $f == "leveltext") {
$DB->set_field("reader_publisher", 'level', urldecode($level), array( "id" => $bookid));
echo $level;
die();
}
/*
* CHANGE BOOK WORDS
*/
if (has_capability('mod/reader:manage', $contextmodule) && $f == "wordstext") {
$DB->set_field("reader_publisher", 'words', urldecode($words), array( "id" => $bookid));
echo $words;
die();
}
/*
* CHANGE MASS PUBLISHER
*/
if (has_capability('mod/reader:manage', $contextmodule) && $f == "changereaderlevel_masspublisher") {
$DB->set_field("reader_publisher", 'publisher', urldecode($masspublisherto), array( "publisher" => urldecode($masspublisherfrom)));
add_to_log($course->id, "reader", substr("AA-Mass changes publisher (".urldecode($masspublisherfrom)." to ".urldecode($masspublisherto).")", 0, 39), "admin.php?id=$id", "$cm->instance");
echo 'Done ';
echo html_writer::link(new moodle_url('/mod/reader/admin.php', array('a'=>'admin', 'act'=>'changereaderlevel', 'id'=>$id)), 'Reload page');
die();
}
/*
* CHANGE MASS LEVEL
*/
if (has_capability('mod/reader:manage', $contextmodule) && $f == "changereaderlevel_masslevel") {
$DB->set_field("reader_publisher", 'level', urldecode($masslevelto), array( "level" => urldecode($masslevelfrom), "publisher" => urldecode($publisher)));
add_to_log($course->id, "reader", substr("AA-Mass changes level (".urldecode($masspublisherfrom)." to ".urldecode($masspublisherto).")", 0, 39), "admin.php?id=$id", "$cm->instance");
echo 'Done ';
echo html_writer::link(new moodle_url('/mod/reader/admin.php', array('a'=>'admin', 'act'=>'changereaderlevel', 'id'=>$id)), 'Reload page');
die();
}
/*
* CHANGE MASS LENGTH
*/
if (has_capability('mod/reader:manage', $contextmodule) && $f == "changereaderlevel_masslength") {
if (!empty($level)) {
$DB->set_field("reader_publisher", 'length', urldecode($masslengthto), array( "length" => urldecode($masslengthfrom), "publisher" => urldecode($publisher), "level" => urldecode($level)));
} else {
$DB->set_field("reader_publisher", 'length', urldecode($masslengthto), array( "length" => urldecode($masslengthfrom), "publisher" => urldecode($publisher)));
}
if (!empty($level)) {
$data = $DB->get_records("reader_publisher", array("publisher" => urldecode($publisher), "level" => urldecode($level)));
} else {
$data = $DB->get_records("reader_publisher", array("publisher" => urldecode($publisher)));
}
$lengthstring = "";
foreach ($data as $key => $value) {
$lengthstring .= $value->id.",";
}
$lengthstring = substr($lengthstring, 0, -1);
$DB->execute("UPDATE {reader_individual_books} SET length = ? WHERE length = ? and readerid = ? and bookid IN (?)", array(urldecode($masslengthto), urldecode($masslengthfrom), $reader->id, $lengthstring));
add_to_log($course->id, "reader", substr("AA-Mass changes length (".urldecode($masslengthfrom)." to ".urldecode($masslengthto).")", 0, 39), "admin.php?id=$id", "$cm->instance");
echo 'Done ';
echo html_writer::link(new moodle_url('/mod/reader/admin.php', array('a'=>'admin', 'act'=>'changereaderlevel', 'id'=>$id)), 'Reload page');
die();
}
/*
* CHANGE MASS DIFFICULTY
*/
if (has_capability('mod/reader:manage', $contextmodule) && $f == "changereaderlevel_massdifficulty") {
if ($reader->individualbooks == 0) {
if (!empty($level)) {
$DB->set_field("reader_publisher", 'difficulty', urldecode($massdifficultyto), array( "difficulty" => urldecode($massdifficultyfrom), "publisher" => urldecode($publisher), "level" => urldecode($level)));
} else {
$DB->set_field("reader_publisher", 'difficulty', urldecode($massdifficultyto), array( "difficulty" => urldecode($massdifficultyfrom), "publisher" => urldecode($publisher)));
}
} else {
if (!empty($level)) {
$data = $DB->get_records("reader_publisher", array("publisher" => urldecode($publisher), "level" => urldecode($level)));
} else {
$data = $DB->get_records("reader_publisher", array("publisher" => urldecode($publisher)));
}
$difficultystring = "";
foreach ($data as $key => $value) {
$difficultystring .= $value->id.",";
}
$difficultystring = substr($difficultystring, 0, -1);
$DB->execute("UPDATE {reader_individual_books} SET difficulty = ? WHERE difficulty = ? and readerid = ? and bookid IN (?)", array(urldecode($massdifficultyto), urldecode($massdifficultyfrom), $reader->id, $difficultystring));
}
add_to_log($course->id, "reader", substr("AA-Mass changes difficulty (".urldecode($massdifficultyfrom)." to ".urldecode($massdifficultyto).")", 0, 39), "admin.php?id=$id", "$cm->instance");
echo 'Done ';
echo html_writer::link(new moodle_url('/mod/reader/admin.php', array('a'=>'admin', 'act'=>'changereaderlevel', 'id'=>$id)), 'Reload page');
die();
}