First cut of cleaned-up CDC gradebook. I've renamed some database fields,
[moodle.git] / grade / index.php
CommitLineData
cbff94ba 1<?PHP
2 require_once("../config.php");
3 require_once("lib.php");
4
5 $action = optional_param('action');
6 if (!isset($action)) {
7 $action = 'grades';
8 }
9
10 require_variable($id); // course id
11 optional_variable($download);
12 if (! $course = get_record("course", "id", $id)) {
13 error(get_string('errornocourse','grades'));
14 }
15
16 if (isset($_REQUEST['group'])) {
17 $group = clean_param($_REQUEST['group'], PARAM_INT);
18 }
19 else {
20 $group = NULL;
21 }
22
23 require_login($course->id);
24
25 if (! $course = get_record("course", "id", $id)) {
26 error(get_string('incorrectcourseid', 'grades'));
27 }
28
29 if (!isset($USER->editing)) {
30 $USER->editing = false;
31 }
32
33 $editing = false;
34
35 if (isteacheredit($course->id)) {
36 if (isset($edit)) {
37 if ($edit == "on") {
38 $USER->editing = true;
39 } else if ($edit == "off") {
40 $USER->editing = false;
41 }
42 }
43
44 $editing = $USER->editing;
45 }
46
47 // if the user set new prefs make sure they happen now
48 if ($action == 'set_grade_preferences') {
49 grade_set_grade_preferences();
50 }
51
52 $preferences = grade_get_preferences();
53
54 // we want this in it's own window
55 if ($action == 'stats') {
56 grade_stats();
57 exit();
58 }
59 elseif ($action == 'excel') {
60 grade_download_excel();
61 exit();
62 }
63 elseif ($action == 'text') {
64 grade_download_text();
65 exit();
66 }
67
68 $loggedinas = user_login_string($course, $USER);
69
70 if (isteacher($course->id)) {
71 if (isset($_REQUEST['student'])) {
72 $student = clean_param($_REQUEST['student'], PARAM_CLEAN);
73 }
74 else if (!isset($student)) {
75 $student = -1;
76 }
77 }
78 else {
79 $student = $USER->id;
80 }
81
82 $grade_menu = grade_get_grades_menu();
83
84 print_header($course->shortname, $course->fullname, $grade_menu,"", "", true, grade_preferences_button(), $loggedinas);
85 grade_preferences_menu();
86 grade_set_uncategorized();
87
88 if (isteacher($course->id)) {
89 switch ($action) {
90 case "cats":
91 grade_set_categories();
92 break;
93 case "insert_category":
94 grade_insert_category();
95 grade_set_categories();
96 break;
97 case "assign_categories":
98 grade_assign_categories();
99 grade_set_categories();
100 break;
101 case "set_grade_weights":
102 grade_set_grade_weights();
103 grade_display_grade_weights();
104 break;
105 case "weights":
106 grade_display_grade_weights();
107 break;
108 case "grades":
109 if ($preferences->use_advanced == 1) {
110 grade_view_all_grades($student);
111 }
112 else {
113 // all the grades will be in the 'uncategorized' category
114 grade_view_category_grades($student);
115 }
116 break;
117 case "vcats":
118 grade_view_category_grades($student);
119 break;
120 case "prefs":
121 grade_display_grade_preferences();
122 break;
123 case "set_grade_preferences":
124 grade_display_grade_preferences();
125 break;
126 case "letters":
127 grade_display_letter_grades();
128 break;
129 case "set_letter_grades":
130 grade_set_letter_grades();
131 grade_display_letter_grades();
132 break;
133 case "delete_category":
134 grade_delete_category();
135 // re-run set_uncategorized as they may have deleted a category that had items in it
136 grade_set_uncategorized();
137 grade_set_categories();
138 break;
139 case "view_student_grades":
140 grade_view_student_grades();
141 break;
142 case "view_student_category_grades":
143 grade_view_student_category_grades();
144 break;
145 default:
146 if ($preferences->use_advanced == 1) {
147 grade_view_all_grades($student);
148 }
149 else {
150 grade_view_category_grades($student);
151 }
152 } // end switch
153 } // end if isTeacher
154 else {
155 if ($preferences->show_weighted || $preferences->show_points || $preferences->show_points)
156 {
157 // teacher has set to show student something
158 $student = $USER->id;
159 switch ($action) {
160 case "view_student_category_grades":
161 grade_view_student_category_grades();
162 break;
163 case "view_student_grades":
164 if ($preferences->use_advanced == 1) {
165 grade_view_student_grades();
166 }
167 else {
168 grade_view_student_category_grades();
169 }
170 break;
171 case "vcats":
172 grade_view_category_grades($student);
173 break;
174 default:
175 if ($preferences->use_advanced == 1) {
176 grade_view_student_grades($student);
177 }
178 else {
179 grade_view_student_category_grades();
180 }
181 break;
182 } // end switch
183 } // end if display something
184 else {
185 error(get_string('gradebookhiddenerror','grades'));
186 }
187 } // end else (!teacher)
188
189 print_footer($course);
190
191
192?>