forked from imartel/rgrade
-
Notifications
You must be signed in to change notification settings - Fork 1
/
rgrade_json_update_grade.php
44 lines (33 loc) · 1.09 KB
/
rgrade_json_update_grade.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
<?php
define('AJAX_SCRIPT', true);
define('NO_DEBUG_DISPLAY', true);
header("Content-Type: application/json; charset=UTF-8");
require_once("../../config.php");
require_once('rgrade_lib.php');
if(!isloggedin()) {
rgrade_json_error('User not logged in');
}
$courseid = optional_param('courseid', '', PARAM_NUMBER);
if(!$courseid || ! $course = rgrade_get_course($courseid)) {
rgrade_json_error('Course not valid');
}
$id = optional_param('id', 0, PARAM_NUMBER);
if(!$id) {
rgrade_json_error('Grade id required');
}
$grade = rgrade_get_rcontent_grade($id);
if(!$grade) {
rgrade_json_error('Grade not valid');
}
//Somehow required for has_capability to work correctly.
require_login($courseid, false);
if (!rgrade_check_capability("moodle/grade:edit")) {
rgrade_json_error('No capabilities (moodle/grade:edit)');
}
$txtgrade = optional_param('grade', '', PARAM_TEXT);
$comments = optional_param('comments', '', PARAM_CLEANHTML);
$updated = rgrade_update_grade($grade, $txtgrade, $comments);
if(!$updated) {
rgrade_json_error(rgrade_get_string('error_saving_grade', $grade));
}
echo json_encode($updated);