Re-applying one fix that was fixed some time ago (rev 1.52) and
[moodle.git] / grade / index.php
CommitLineData
cbff94ba 1<?PHP
2 require_once("../config.php");
3 require_once("lib.php");
4
281ffa4a 5 $id = required_param('id'); // course id
6 $download = optional_param('download');
5305e2eb 7 $user = optional_param('user', -1);
281ffa4a 8 $action = optional_param('action', 'grades');
7f7d5063 9 $cview = optional_param('cview', -1);
cbff94ba 10
281ffa4a 11 if (!$course = get_record('course', 'id', $id)) {
12 error('No course ID');
cbff94ba 13 }
cbff94ba 14
281ffa4a 15 require_login($course->id);
f1efbe0a 16
281ffa4a 17 // if the user set new prefs make sure they happen now
18 if ($action == 'set_grade_preferences' && $prefs = data_submitted()) {
19 if (!confirm_sesskey()) {
20 error(get_string('confirmsesskeybad', 'error'));
cbff94ba 21 }
281ffa4a 22 grade_set_preferences($course, $prefs);
cbff94ba 23 }
24
281ffa4a 25 $preferences = grade_get_preferences($course->id);
cbff94ba 26
cbff94ba 27
281ffa4a 28 // we want this in its own window
cbff94ba 29 if ($action == 'stats') {
30 grade_stats();
31 exit();
9c61ba4d 32 } else if ($action == 'ods') {
33 grade_download('ods', $id);
34 exit();
281ffa4a 35 } else if ($action == 'excel') {
6cd8c592 36 grade_download('xls', $id);
cbff94ba 37 exit();
281ffa4a 38 } else if ($action == 'text') {
6cd8c592 39 grade_download('txt', $id);
cbff94ba 40 exit();
41 }
281ffa4a 42
a983b6ec 43 print_header($course->shortname.': '.get_string('grades'), $course->fullname, grade_nav($course, $action));
281ffa4a 44
f1efbe0a 45 print_heading('This old gradebook may not work properly. See the <a href="report.php?id='.$course->id.'">new 1.9 gradebook</a>');
46
47 /// find out current groups mode
2d7617c6 48 $groupmode = groupmode($course);
f1efbe0a 49 $currentgroup = setup_and_print_groups($course, $groupmode, 'index.php?id=' . $course->id);
50 echo '<div class="clearer"></div>';
51
52 grade_preferences_menu($action, $course);
2d7617c6 53
cbff94ba 54 grade_set_uncategorized();
55
1c45e42e 56 if (has_capability('moodle/course:viewcoursegrades', get_context_instance(CONTEXT_COURSE, $course->id))) {
cbff94ba 57 switch ($action) {
58 case "cats":
59 grade_set_categories();
60 break;
61 case "insert_category":
62 grade_insert_category();
63 grade_set_categories();
64 break;
65 case "assign_categories":
66 grade_assign_categories();
67 grade_set_categories();
68 break;
69 case "set_grade_weights":
70 grade_set_grade_weights();
71 grade_display_grade_weights();
72 break;
73 case "weights":
74 grade_display_grade_weights();
75 break;
76 case "grades":
77 if ($preferences->use_advanced == 1) {
5305e2eb 78 grade_view_all_grades($user);
cbff94ba 79 }
80 else {
81 // all the grades will be in the 'uncategorized' category
5305e2eb 82 grade_view_category_grades($user);
cbff94ba 83 }
84 break;
85 case "vcats":
5305e2eb 86 grade_view_category_grades($user);
cbff94ba 87 break;
88 case "prefs":
cbff94ba 89 case "set_grade_preferences":
b623ea5e 90 grade_display_grade_preferences($course, $preferences);
cbff94ba 91 break;
92 case "letters":
93 grade_display_letter_grades();
94 break;
95 case "set_letter_grades":
96 grade_set_letter_grades();
97 grade_display_letter_grades();
98 break;
99 case "delete_category":
100 grade_delete_category();
101 // re-run set_uncategorized as they may have deleted a category that had items in it
102 grade_set_uncategorized();
103 grade_set_categories();
104 break;
105 case "view_student_grades":
5305e2eb 106 grade_view_all_grades($user);
cbff94ba 107 break;
108 case "view_student_category_grades":
5305e2eb 109 grade_view_category_grades($user);
cbff94ba 110 break;
111 default:
112 if ($preferences->use_advanced == 1) {
5305e2eb 113 grade_view_all_grades($user);
cbff94ba 114 }
115 else {
5305e2eb 116 grade_view_category_grades($user);
cbff94ba 117 }
118 } // end switch
119 } // end if isTeacher
120 else {
58173120 121 if ($preferences->show_weighted || $preferences->show_points || $preferences->show_percent) {
5305e2eb 122
123 if ($preferences->use_advanced == 1) {
6cd8c592 124 if($action != 'vcats') {
125 grade_view_all_grades($USER->id);
126 }
127 else {
128 grade_view_category_grades($USER->id);
129 }
5305e2eb 130 } else {
131 grade_view_category_grades($USER->id);
132 }
133
134 } else {
cbff94ba 135 error(get_string('gradebookhiddenerror','grades'));
136 }
137 } // end else (!teacher)
138
139 print_footer($course);
140
141
142?>