Follow-up fix for Bug MDL-8617 "Implement groupings & course modules..." internal...
[moodle-pu.git] / grade / index.php
blob5d6e798a6c0a8c15aad4b770821f7a08d1f21155
1 <?PHP
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);
20 } else {
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') {
38 grade_stats();
39 exit();
40 } else if ($action == 'ods') {
41 grade_download('ods', $id);
42 exit();
43 } else if ($action == 'excel') {
44 grade_download('xls', $id);
45 exit();
46 } else if ($action == 'text') {
47 grade_download('txt', $id);
48 exit();
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))) {
58 switch ($action) {
59 case "cats":
60 grade_set_categories();
61 break;
62 case "insert_category":
63 grade_insert_category();
64 grade_set_categories();
65 break;
66 case "assign_categories":
67 grade_assign_categories();
68 grade_set_categories();
69 break;
70 case "set_grade_weights":
71 grade_set_grade_weights();
72 grade_display_grade_weights();
73 break;
74 case "weights":
75 grade_display_grade_weights();
76 break;
77 case "grades":
78 if ($preferences->use_advanced == 1) {
79 grade_view_all_grades($user);
81 else {
82 // all the grades will be in the 'uncategorized' category
83 grade_view_category_grades($user);
85 break;
86 case "vcats":
87 grade_view_category_grades($user);
88 break;
89 case "prefs":
90 case "set_grade_preferences":
91 grade_display_grade_preferences($course, $preferences);
92 break;
93 case "letters":
94 grade_display_letter_grades();
95 break;
96 case "set_letter_grades":
97 grade_set_letter_grades();
98 grade_display_letter_grades();
99 break;
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();
105 break;
106 case "view_student_grades":
107 grade_view_all_grades($user);
108 break;
109 case "view_student_category_grades":
110 grade_view_category_grades($user);
111 break;
112 default:
113 if ($preferences->use_advanced == 1) {
114 grade_view_all_grades($user);
116 else {
117 grade_view_category_grades($user);
119 } // end switch
120 } // end if isTeacher
121 else {
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);
128 else {
129 grade_view_category_grades($USER->id);
131 } else {
132 grade_view_category_grades($USER->id);
135 } else {
136 error(get_string('gradebookhiddenerror','grades'));
138 } // end else (!teacher)
140 print_footer($course);