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
);
19 if (has_capability('moodle/site:accessallgroups', get_context_instance(CONTEXT_COURSE, $course->id))) {
20 $group = get_and_set_current_group($course, $course->groupmode, $group);
22 $group = get_current_group($course->id);
26 // if the user set new prefs make sure they happen now
27 if ($action == 'set_grade_preferences' && $prefs = data_submitted()) {
28 if (!confirm_sesskey()) {
29 error(get_string('confirmsesskeybad', 'error'));
31 grade_set_preferences($course, $prefs);
34 $preferences = grade_get_preferences($course->id
);
37 // we want this in its own window
38 if ($action == 'stats') {
41 } else if ($action == 'ods') {
42 grade_download('ods', $id);
44 } else if ($action == 'excel') {
45 grade_download('xls', $id);
47 } else if ($action == 'text') {
48 grade_download('txt', $id);
52 print_header($course->shortname
.': '.get_string('grades'), $course->fullname
, grade_nav($course, $action));
54 grade_preferences_menu($action, $course, $group);
56 /// copied code from assignment module, if this is not the way to do this please change it
57 /// the above code does not work
58 /// set_and_print_groups() is not fully implemented as function groups_instance_print_grouping_selector()
59 /// and function groups_instance_print_group_selector() are missing.
60 $context = get_context_instance(CONTEXT_COURSE
, $course->id
);
61 $changegroup = optional_param('group', -1, PARAM_INT
); // choose the current group
62 $groupmode = groupmode($course);
63 $currentgroup = get_and_set_current_group($course, $groupmode, $changegroup);
65 /// Now we need a menu for separategroups as well!
66 if ($groupmode == VISIBLEGROUPS ||
($groupmode
67 && has_capability('moodle/site:accessallgroups', $context))) {
69 //the following query really needs to change
70 if ($groups = groups_get_groups_names($course->id
)) { //TODO:
71 print_box_start('groupmenu');
72 print_group_menu($groups, $groupmode, $currentgroup, 'index.php?id='.$course->id
);
73 print_box_end(); // groupmenu
77 grade_set_uncategorized();
79 if (has_capability('moodle/course:viewcoursegrades', get_context_instance(CONTEXT_COURSE
, $course->id
))) {
82 grade_set_categories();
84 case "insert_category":
85 grade_insert_category();
86 grade_set_categories();
88 case "assign_categories":
89 grade_assign_categories();
90 grade_set_categories();
92 case "set_grade_weights":
93 grade_set_grade_weights();
94 grade_display_grade_weights();
97 grade_display_grade_weights();
100 if ($preferences->use_advanced
== 1) {
101 grade_view_all_grades($user);
104 // all the grades will be in the 'uncategorized' category
105 grade_view_category_grades($user);
109 grade_view_category_grades($user);
112 case "set_grade_preferences":
113 grade_display_grade_preferences($course, $preferences);
116 grade_display_letter_grades();
118 case "set_letter_grades":
119 grade_set_letter_grades();
120 grade_display_letter_grades();
122 case "delete_category":
123 grade_delete_category();
124 // re-run set_uncategorized as they may have deleted a category that had items in it
125 grade_set_uncategorized();
126 grade_set_categories();
128 case "view_student_grades":
129 grade_view_all_grades($user);
131 case "view_student_category_grades":
132 grade_view_category_grades($user);
135 if ($preferences->use_advanced
== 1) {
136 grade_view_all_grades($user);
139 grade_view_category_grades($user);
142 } // end if isTeacher
144 if ($preferences->show_weighted ||
$preferences->show_points ||
$preferences->show_percent
) {
146 if ($preferences->use_advanced
== 1) {
147 if($action != 'vcats') {
148 grade_view_all_grades($USER->id
);
151 grade_view_category_grades($USER->id
);
154 grade_view_category_grades($USER->id
);
158 error(get_string('gradebookhiddenerror','grades'));
160 } // end else (!teacher)
162 print_footer($course);