3 /*************************************************
12 displayfinalgrades (teachers only)
13 listforassessmentstudent
14 listforassessmentteacher
20 ************************************************/
22 require_once("../../config.php");
23 require_once("lib.php");
24 require_once("locallib.php");
25 require_once("version.php");
27 $id = required_param('id', PARAM_INT
); // Course Module ID
28 $action = required_param('action', PARAM_ALPHA
);
29 $aid = optional_param('aid', 0, PARAM_INT
);
30 $sid = optional_param('sid', 0, PARAM_INT
);
31 $title = optional_param('title', '', PARAM_CLEAN
);
33 // get some essential stuff...
34 if (! $cm = get_coursemodule_from_id('exercise', $id)) {
35 error("Course Module ID was incorrect");
38 if (! $course = get_record("course", "id", $cm->course
)) {
39 error("Course is misconfigured");
42 if (! $exercise = get_record("exercise", "id", $cm->instance
)) {
43 error("Course module is incorrect");
46 require_login($course->id
, false, $cm);
48 $strexercises = get_string("modulenameplural", "exercise");
49 $strexercise = get_string("modulename", "exercise");
50 $strsubmissions = get_string("submissions", "exercise");
52 // ... print the header and...
53 print_header_simple(format_string($exercise->name
), "",
54 "<a href=\"index.php?id=$course->id\">$strexercises</a> ->
55 <a href=\"view.php?id=$cm->id\">".format_string($exercise->name
,true)."</a> -> $strsubmissions",
59 /******************* admin amend title ************************************/
60 if ($action == 'adminamendtitle' ) {
62 if (!isteacher($course->id
)) {
63 error("Only teachers can look at this page");
66 error("Admin Amend Title: submission id missing");
69 $submission = get_record("exercise_submissions", "id", $sid);
70 print_heading(get_string("amendtitle", "exercise"));
72 <form id
="amendtitleform" action
="submissions.php" method
="post">
73 <input type
="hidden" name
="action" value
="adminupdatetitle" />
74 <input type
="hidden" name
="id" value
="<?php echo $cm->id ?>" />
75 <input type
="hidden" name
="sid" value
="<?php echo $sid ?>" />
77 <table celpadding
="5" border
="1">
80 // now get the comment
81 echo "<tr valign=\"top\">\n";
82 echo " <td align=\"right\"><p><b>". get_string("title", "exercise").":</b></p></td>\n";
84 echo " <input type=\"text\" name=\"title\" size=\"60\" maxlength=\"100\" value=\"$submission->title\" />\n";
85 echo " </td></tr></table>\n";
86 echo "<input type=\"submit\" value=\"".get_string("amendtitle", "exercise")."\" />\n";
87 echo "</center></form>\n";
92 /******************* admin clear late (flag) ************************************/
93 elseif ($action == 'adminclearlate' ) {
95 if (!isteacher($course->id
)) {
96 error("Only teachers can look at this page");
99 error("Admin clear late flag: submission id missing");
102 if (!$submission = get_record("exercise_submissions", "id", $sid)) {
103 error("Admin clear late flag: can not get submission record");
105 if (set_field("exercise_submissions", "late", 0, "id", $sid)) {
106 print_heading(get_string("clearlateflag", "exercise")." ".get_string("ok"));
109 add_to_log($course->id
, "exercise", "late flag cleared", "view.php?id=$cm->id", "submission $submission->id");
111 redirect("submissions.php?id=$cm->id&action=adminlist");
115 /******************* admin confirm delete ************************************/
116 elseif ($action == 'adminconfirmdelete' ) {
118 if (!isteacher($course->id
)) {
119 error("Only teachers can look at this page");
122 error("Admin confirm delete: submission id missing");
124 if (!$submission = get_record("exercise_submissions", "id", $sid)) {
125 error("Admin delete: can not get submission record");
128 if (isteacher($course->id
, $submission->userid
)) {
129 if (!isteacheredit($course->id
)) {
130 error("Only teacher with editing permissions can delete teacher submissions.");
132 if ($assessments = exercise_get_assessments($submission)) {
133 echo "<p align=\"center\">".get_string("deletesubmissionwarning", "exercise", count($assessments)).
137 notice_yesno(get_string("confirmdeletionofthisitem","exercise", get_string("submission", "exercise")),
138 "submissions.php?action=admindelete&id=$cm->id&sid=$sid", "submissions.php?id=$cm->id&action=adminlist");
142 /******************* admin delete ************************************/
143 elseif ($action == 'admindelete' ) {
145 if (!isteacher($course->id
)) {
146 error("Only teachers can look at this page");
149 error("Admin delete: submission id missing");
152 if (!$submission = get_record("exercise_submissions", "id", $sid)) {
153 error("Admin delete: can not get submission record");
155 print_string("deleting", "exercise");
156 // first get any assessments...
157 if ($assessments = exercise_get_assessments($submission)) {
158 foreach($assessments as $assessment) {
159 // ...and all the associated records...
160 delete_records("exercise_grades", "assessmentid", $assessment->id
);
163 // ...now delete the assessments...
164 delete_records("exercise_assessments", "submissionid", $submission->id
);
166 // ...and the submission record...
167 delete_records("exercise_submissions", "id", $submission->id
);
168 // ..and finally the submitted file
169 exercise_delete_submitted_files($exercise, $submission);
170 add_to_log($course->id
, "exercise", "delete", "view.php?id=$cm->id", "submission $submission->id");
172 print_continue("submissions.php?id=$cm->id&action=adminlist");
176 /******************* admin (confirm) late flag ************************************/
177 elseif ($action == 'adminlateflag' ) {
179 if (!isteacher($course->id
)) {
180 error("Only teachers can look at this page");
183 error("Admin confirm late flag: submission id missing");
185 if (!$submission = get_record("exercise_submissions", "id", $sid)) {
186 error("Admin confirm late flag: can not get submission record");
189 notice_yesno(get_string("clearlateflag","exercise")."?",
190 "submissions.php?action=adminclearlate&id=$cm->id&sid=$sid",
191 "submissions.php?id=$cm->id&action=adminlist");
195 /******************* list all submissions ************************************/
196 elseif ($action == 'adminlist' ) {
198 if (!isteacher($course->id
)) {
199 error("Only teachers can look at this page");
202 echo "<p><small>Exercise Version-> $module->version</small></p>";
203 exercise_list_submissions_for_admin($exercise);
204 print_continue("view.php?id=$cm->id");
209 /******************* admin update title ************************************/
210 elseif ($action == 'adminupdatetitle' ) {
212 if (!isteacher($course->id
)) {
213 error("Only teachers can look at this page");
216 error("Admin Update Title: submission id missing");
219 if (set_field("exercise_submissions", "title", $title, "id", $sid)) {
220 print_heading(get_string("amendtitle", "exercise")." ".get_string("ok"));
222 redirect("submissions.php?id=$cm->id&action=adminlist");
226 /*************** display final grades (by teacher) ***************************/
227 elseif ($action == 'displayfinalgrades') {
228 $groupid = get_current_group($course->id
);
229 // Get all the students
230 if (!$users = get_course_students($course->id
, "u.lastname, u.firstname")) {
231 print_heading(get_string("nostudentsyet"));
232 print_footer($course);
236 // show the final grades as stored in the tables...
237 print_heading_with_help(get_string("displayoffinalgrades", "exercise"), "finalgrades", "exercise");
238 echo "<center><table border=\"1\" width=\"90%\"><tr>\n";
239 echo "<td><b>".$course->student
."</b></td>";
240 echo "<td><b>".get_string("submission", "exercise")."</b></td>";
241 echo "<td align=\"center\"><b>".get_string("gradeforassessment", "exercise")."</b></td>";
242 echo "<td align=\"center\"><b>".get_string("gradeforsubmission", "exercise")."</b></td>";
243 echo "<td align=\"center\"><b>".get_string("overallgrade", "exercise")."</b></td></tr>\n";
245 echo "<tr><td><b>".get_string("maximumgrade")."</b></td>";
246 echo "<td><b> </b></td>\n";
247 echo "<td align=\"center\"><b>$exercise->gradinggrade</b></td>\n";
248 echo "<td align=\"center\"><b>$exercise->grade</b></td>\n";
249 echo "<td><b> </b></td></tr>\n";
250 foreach ($users as $user) {
251 // check group membership, if necessary
253 // check user's group
254 if (!ismember($groupid, $user->id
)) {
255 continue; // skip this user
258 // first get user's own assessment reord, it should contain their grading grade
259 if ($ownassessments = exercise_get_user_assessments($exercise, $user)) {
260 foreach ($ownassessments as $ownassessment) {
261 break; // there should only be one
265 $ownassessment->gradinggrade
= 0;
267 if ($submissions = exercise_get_user_submissions($exercise, $user)) {
268 foreach ($submissions as $submission) {
269 if ($assessments = exercise_get_assessments($submission)) {
270 foreach ($assessments as $assessment) { // (normally there should only be one
271 $gradinggrade = number_format($ownassessment->gradinggrade
* $exercise->gradinggrade
/
273 $grade = number_format($assessment->grade
* $exercise->grade
/ 100.0, 1);
274 $overallgrade = number_format(($assessment->grade
* $exercise->grade
/ 100.0) +
275 ($ownassessment->gradinggrade
* $exercise->gradinggrade
/ 100.0), 1);
276 if ($submission->late
) {
277 $grade = "<font color=\"red\">(".$grade.")</font>";
278 $overallgrade = "<font color=\"red\">(".$overallgrade.")</font>";
280 echo "<tr><td>".fullname($user)."</td>\n";
281 echo "<td>".exercise_print_submission_title($exercise, $submission)."</td>\n";
282 echo "<td align=\"center\">$gradinggrade</td>";
283 echo "<td align=\"center\">$grade</td>";
284 echo "<td align=\"center\">$overallgrade</td></tr>\n";
290 echo "</table><br clear=\"all\" />\n";
291 if ($exercise->showleaguetable
) {
292 exercise_print_league_table($exercise);
295 echo get_string("maximumgrade").": $exercise->grade\n";
296 print_continue("view.php?id=$cm->id");
300 /******************* list for assessment student (submissions) ************************************/
301 elseif ($action == 'listforassessmentstudent' ) {
302 if (!$users = get_course_students($course->id
)) {
303 print_heading(get_string("nostudentsyet"));
304 print_footer($course);
307 if (!isteacher($course->id
)) {
308 error("Only teachers can look at this page");
310 exercise_list_unassessed_student_submissions($exercise, $USER);
311 print_continue("view.php?id=$cm->id");
316 /******************* list for assessment teacher (submissions) ************************************/
317 elseif ($action == 'listforassessmentteacher' ) {
318 if (!$users = get_course_students($course->id
)) {
319 print_heading(get_string("nostudentsyet"));
320 print_footer($course);
323 exercise_list_unassessed_teacher_submissions($exercise, $USER);
324 print_continue("view.php?id=$cm->id");
329 /****************** save league table entries and anonimity setting (by teacher) **************/
330 elseif ($action == 'saveleaguetable') {
332 $form = (object)$_POST;
334 if (!isteacher($course->id
)) {
335 error("Only teachers can look at this page");
338 // save the number of league table entries from the form...
339 if ($form->nentries
== 'All') {
342 $nentries = $form->nentries
;
345 set_field("exercise", "showleaguetable", $nentries, "id", "$exercise->id");
347 // ...and save the anonimity setting
348 set_field("exercise", "anonymous", $form->anonymous
, "id", "$exercise->id");
350 redirect("submissions.php?id=$cm->id&action=adminlist", get_string("entriessaved", "exercise"));
353 /*************** save weights (by teacher) ***************************/
354 elseif ($action == 'saveweights') {
356 $form = (object)$_POST;
358 if (!isteacher($course->id
)) {
359 error("Only teachers can look at this page");
362 // save the weights from the form...
363 if (isset($form->teacherweight
)) {
364 $teacherweight = $form->teacherweight
;
366 set_field("exercise", "teacherweight", $teacherweight, "id", "$exercise->id");
369 if (isset($form->gradingweight
)) {
370 $gradingweight = $form->gradingweight
;
372 set_field("exercise", "gradingweight", $gradingweight, "id", "$exercise->id");
375 redirect("submissions.php?id=$cm->id&action=adminlist", get_string("weightssaved", "exercise"));
379 /******************* user confirm delete ************************************/
380 elseif ($action == 'userconfirmdelete' ) {
383 error("User Confirm Delete: submission id missing");
386 notice_yesno(get_string("confirmdeletionofthisitem","exercise", get_string("submission", "exercise")),
387 "submissions.php?action=userdelete&id=$cm->id&sid=$sid", "view.php?id=$cm->id");
391 /******************* user delete ************************************/
392 elseif ($action == 'userdelete' ) {
395 error("User Delete: submission id missing");
398 if (!$submission = get_record("exercise_submissions", "id", $sid)) {
399 error("User Delete: can not get submission record");
401 print_string("deleting", "exercise");
402 // first get any assessments...
403 if ($assessments = exercise_get_assessments($submission)) {
404 foreach($assessments as $assessment) {
405 // ...and all the associated records...
406 delete_records("exercise_grades", "assessmentid", $assessment->id
);
409 // ...now delete the assessments...
410 delete_records("exercise_assessments", "submissionid", $submission->id
);
412 // ...and the submission record...
413 delete_records("exercise_submissions", "id", $submission->id
);
414 // ..and finally the submitted file
415 exercise_delete_submitted_files($exercise, $submission);
416 add_to_log($course->id
, "exercise", "delete", "view.php?id=$cm->id", "submission $submission->id");
418 print_continue("view.php?id=$cm->id");
422 /*************** no man's land **************************************/
426 error("Fatal Error: Unknown Action: ".$action."\n");
431 print_footer($course);