2 require_once("../config.php");
3 require_once("lib.php");
5 $id = required_param('id'); // course id
6 $download = optional_param('download');
7 $user = optional_param('user', -1);
8 $group = optional_param('group', -1);
9 $action = optional_param('action', 'grades');
10 $cview = optional_param('cview', -1);
12 if (!$course = get_record('course', 'id', $id)) {
13 error('No course ID');
16 require_login($course->id
);
18 if (has_capability('moodle/site:accessallgroups', get_context_instance(CONTEXT_COURSE
, $course->id
))) {
19 $group = get_and_set_current_group($course, $course->groupmode
, $group);
21 $group = get_current_group($course->id
);
25 // if the user set new prefs make sure they happen now
26 if ($action == 'set_grade_preferences' && $prefs = data_submitted()) {
27 if (!confirm_sesskey()) {
28 error(get_string('confirmsesskeybad', 'error'));
30 grade_set_preferences($course, $prefs);
33 $preferences = grade_get_preferences($course->id
);
36 // we want this in its own window
37 if ($action == 'stats') {
40 } else if ($action == 'ods') {
41 grade_download('ods', $id);
43 } else if ($action == 'excel') {
44 grade_download('xls', $id);
46 } else if ($action == 'text') {
47 grade_download('txt', $id);
51 print_header($course->shortname
.': '.get_string('grades'), $course->fullname
, grade_nav($course, $action));
53 grade_preferences_menu($action, $course, $group);
55 grade_set_uncategorized();
57 if (has_capability('moodle/course:viewcoursegrades', get_context_instance(CONTEXT_COURSE
, $course->id
))) {
60 grade_set_categories();
62 case "insert_category":
63 grade_insert_category();
64 grade_set_categories();
66 case "assign_categories":
67 grade_assign_categories();
68 grade_set_categories();
70 case "set_grade_weights":
71 grade_set_grade_weights();
72 grade_display_grade_weights();
75 grade_display_grade_weights();
78 if ($preferences->use_advanced
== 1) {
79 grade_view_all_grades($user);
82 // all the grades will be in the 'uncategorized' category
83 grade_view_category_grades($user);
87 grade_view_category_grades($user);
90 case "set_grade_preferences":
91 grade_display_grade_preferences($course, $preferences);
94 grade_display_letter_grades();
96 case "set_letter_grades":
97 grade_set_letter_grades();
98 grade_display_letter_grades();
100 case "delete_category":
101 grade_delete_category();
102 // re-run set_uncategorized as they may have deleted a category that had items in it
103 grade_set_uncategorized();
104 grade_set_categories();
106 case "view_student_grades":
107 grade_view_all_grades($user);
109 case "view_student_category_grades":
110 grade_view_category_grades($user);
113 if ($preferences->use_advanced
== 1) {
114 grade_view_all_grades($user);
117 grade_view_category_grades($user);
120 } // end if isTeacher
122 if ($preferences->show_weighted ||
$preferences->show_points ||
$preferences->show_percent
) {
124 if ($preferences->use_advanced
== 1) {
125 if($action != 'vcats') {
126 grade_view_all_grades($USER->id
);
129 grade_view_category_grades($USER->id
);
132 grade_view_category_grades($USER->id
);
136 error(get_string('gradebookhiddenerror','grades'));
138 } // end else (!teacher)
140 print_footer($course);