Fix a possible race condition in the PaintWeb DML code.
[moodle/mihaisucan.git] / mod / exercise / index.php
blob7b50f834f829d0c8abe85160e34ced06e9429164
1 <?php // $Id$
3 require_once("../../config.php");
4 require_once("lib.php");
5 require_once("locallib.php");
7 $id = required_param('id', PARAM_INT); // course
9 if (! $course = get_record("course", "id", $id)) {
10 error("Course ID is incorrect");
13 require_login($course->id);
14 add_to_log($course->id, "exercise", "view all", "index.php?id=$course->id", "");
16 $strexercises = get_string("modulenameplural", "exercise");
17 $strexercise = get_string("modulename", "exercise");
18 $strweek = get_string("week");
19 $strtopic = get_string("topic");
20 $strname = get_string("name");
21 $strtitle = get_string("title", "exercise");
22 $strphase = get_string("phase", "exercise");
23 $strgrade = get_string("grade");
24 $strdeadline = get_string("deadline", "exercise");
25 $strsubmitted = get_string("submitted", "assignment");
27 $navlinks = array();
28 $navlinks[] = array('name' => $strexercises, 'link' => '', 'type' => 'activity');
29 $navigation = build_navigation($navlinks);
31 print_header_simple("$strexercises", "", $navigation, "", "", true, "", navmenu($course));
33 if (! $exercises = get_all_instances_in_course("exercise", $course)) {
34 notice(get_string('thereareno', 'moodle', $strexercises), "../../course/view.php?id=$course->id");
35 die;
38 $timenow = time();
40 if ($course->format == "weeks") {
41 if (isteacher($course->id)) {
42 $table->head = array ($strweek, $strname, $strtitle, $strphase, $strsubmitted, $strdeadline);
43 } else {
44 $table->head = array ($strweek, $strname, $strtitle, $strgrade, $strsubmitted, $strdeadline);
46 $table->align = array ("center", "left", "left","center","left", "left");
47 } else if ($course->format == "topics") {
48 if (isteacher($course->id)) {
49 $table->head = array ($strtopic, $strname, $strtitle, $strphase, $strsubmitted, $strdeadline);
50 } else {
51 $table->head = array ($strtopic, $strname, $strtitle, $strgrade, $strsubmitted, $strdeadline);
53 $table->align = array ("center", "left", "left", "center", "left", "left");
54 } else {
55 $table->head = array ($strname, $strsubmitted, $strdeadline);
56 $table->align = array ("left", "left", "left");
59 foreach ($exercises as $exercise) {
60 if ($exercise->deadline > $timenow) {
61 $due = userdate($exercise->deadline);
62 } else {
63 $due = "<font color=\"red\">".userdate($exercise->deadline)."</font>";
65 if ($submissions = exercise_get_user_submissions($exercise, $USER)) {
66 foreach ($submissions as $submission) {
67 if ($submission->late) {
68 $submitted = "<font color=\"red\">".userdate($submission->timecreated)."</font>";
70 else {
71 $submitted = userdate($submission->timecreated);
73 $link = "<a href=\"view.php?id=$exercise->coursemodule\">".format_string($exercise->name,true)."</a>";
74 $title = $submission->title;
75 if ($course->format == "weeks" or $course->format == "topics") {
76 if (isteacher($course->id)) {
77 $phase = '';
78 switch ($exercise->phase) {
79 case 0:
80 case 1: $phase = get_string("phase1short", "exercise");
81 break;
82 case 2: $phase = get_string("phase2short", "exercise");
83 if ($num = exercise_count_unassessed_student_submissions($exercise)) {
84 $phase .= " [".get_string("unassessed", "exercise", $num)."]";
86 break;
87 case 3: $phase = get_string("phase3short", "exercise");
88 if ($num = exercise_count_unassessed_student_submissions($exercise)) {
89 $phase .= " [".get_string("unassessed", "exercise", $num)."]";
91 break;
93 $table->data[] = array ($exercise->section, $link, $title, $phase,
94 $submitted, $due);
95 } else { // it's a student
96 if ($assessments = exercise_get_user_assessments($exercise, $USER)) { // should be only one...
97 foreach ($assessments as $studentassessment) {
98 break;
100 if ($studentassessment->timegraded) { // it's been assessed
101 if ($teacherassessment = exercise_get_submission_assessment($submission)) {
102 $actualgrade = number_format(($studentassessment->gradinggrade *
103 $exercise->gradinggrade / 100.0) + ($teacherassessment->grade *
104 $exercise->grade / 100.0), 1);
105 if ($submission->late) {
106 $actualgrade = "<font color=\"red\">(".$actualgrade.")<font color=\"red\">";
108 $actualgrade .= " (".get_string("maximumshort").": ".
109 number_format($exercise->gradinggrade + $exercise->grade, 0).")";
110 $table->data[] = array ($exercise->section, $link, $title, $actualgrade,
111 $submitted, $due);
113 } else {
114 $table->data[] = array ($exercise->section, $link, $title,
115 "-", $submitted, $due);
119 } else {
120 $table->data[] = array ($link, $submitted, $due);
123 } else {
124 $submitted = get_string("no");
125 $title = '';
126 $link = "<a href=\"view.php?id=$exercise->coursemodule\">".format_string($exercise->name,true)."</a>";
127 if ($course->format == "weeks" or $course->format == "topics") {
128 if (isteacher($course->id)) {
129 $table->data[] = array ($exercise->section, $link, $title, $exercise->phase,
130 $submitted, $due);
131 } else {
132 $table->data[] = array ($exercise->section, $link, $title, "-", $submitted, $due);
134 } else {
135 $table->data[] = array ($link, $submitted, $due);
139 echo "<br />";
141 print_table($table);
143 print_footer($course);