Fixes bug MDL-8234, "New groups code & AS keyword"
[moodle-pu.git] / mod / exercise / index.php
blob28e55acdf8de5cadbacbbc04e885da74a8b57bd7
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 print_header_simple("$strexercises", "", "$strexercises", "", "", true, "", navmenu($course));
29 if (! $exercises = get_all_instances_in_course("exercise", $course)) {
30 notice("There are no exercises", "../../course/view.php?id=$course->id");
31 die;
34 $timenow = time();
36 if ($course->format == "weeks") {
37 if (isteacher($course->id)) {
38 $table->head = array ($strweek, $strname, $strtitle, $strphase, $strsubmitted, $strdeadline);
39 } else {
40 $table->head = array ($strweek, $strname, $strtitle, $strgrade, $strsubmitted, $strdeadline);
42 $table->align = array ("center", "left", "left","center","left", "left");
43 } else if ($course->format == "topics") {
44 if (isteacher($course->id)) {
45 $table->head = array ($strtopic, $strname, $strtitle, $strphase, $strsubmitted, $strdeadline);
46 } else {
47 $table->head = array ($strtopic, $strname, $strtitle, $strgrade, $strsubmitted, $strdeadline);
49 $table->align = array ("center", "left", "left", "center", "left", "left");
50 } else {
51 $table->head = array ($strname, $strsubmitted, $strdeadline);
52 $table->align = array ("left", "left", "left");
55 foreach ($exercises as $exercise) {
56 if ($exercise->deadline > $timenow) {
57 $due = userdate($exercise->deadline);
58 } else {
59 $due = "<font color=\"red\">".userdate($exercise->deadline)."</font>";
61 if ($submissions = exercise_get_user_submissions($exercise, $USER)) {
62 foreach ($submissions as $submission) {
63 if ($submission->late) {
64 $submitted = "<font color=\"red\">".userdate($submission->timecreated)."</font>";
66 else {
67 $submitted = userdate($submission->timecreated);
69 $link = "<a href=\"view.php?id=$exercise->coursemodule\">".format_string($exercise->name,true)."</a>";
70 $title = $submission->title;
71 if ($course->format == "weeks" or $course->format == "topics") {
72 if (isteacher($course->id)) {
73 $phase = '';
74 switch ($exercise->phase) {
75 case 0:
76 case 1: $phase = get_string("phase1short", "exercise");
77 break;
78 case 2: $phase = get_string("phase2short", "exercise");
79 if ($num = exercise_count_unassessed_student_submissions($exercise)) {
80 $phase .= " [".get_string("unassessed", "exercise", $num)."]";
82 break;
83 case 3: $phase = get_string("phase3short", "exercise");
84 if ($num = exercise_count_unassessed_student_submissions($exercise)) {
85 $phase .= " [".get_string("unassessed", "exercise", $num)."]";
87 break;
89 $table->data[] = array ($exercise->section, $link, $title, $phase,
90 $submitted, $due);
91 } else { // it's a student
92 if ($assessments = exercise_get_user_assessments($exercise, $USER)) { // should be only one...
93 foreach ($assessments as $studentassessment) {
94 break;
96 if ($studentassessment->timegraded) { // it's been assessed
97 if ($teacherassessment = exercise_get_submission_assessment($submission)) {
98 $actualgrade = number_format(($studentassessment->gradinggrade *
99 $exercise->gradinggrade / 100.0) + ($teacherassessment->grade *
100 $exercise->grade / 100.0), 1);
101 if ($submission->late) {
102 $actualgrade = "<font color=\"red\">(".$actualgrade.")<font color=\"red\">";
104 $actualgrade .= " (".get_string("maximumshort").": ".
105 number_format($exercise->gradinggrade + $exercise->grade, 0).")";
106 $table->data[] = array ($exercise->section, $link, $title, $actualgrade,
107 $submitted, $due);
109 } else {
110 $table->data[] = array ($exercise->section, $link, $title,
111 "-", $submitted, $due);
115 } else {
116 $table->data[] = array ($link, $submitted, $due);
119 } else {
120 $submitted = get_string("no");
121 $title = '';
122 $link = "<a href=\"view.php?id=$exercise->coursemodule\">".format_string($exercise->name,true)."</a>";
123 if ($course->format == "weeks" or $course->format == "topics") {
124 if (isteacher($course->id)) {
125 $table->data[] = array ($exercise->section, $link, $title, $exercise->phase,
126 $submitted, $due);
127 } else {
128 $table->data[] = array ($exercise->section, $link, $title, "-", $submitted, $due);
130 } else {
131 $table->data[] = array ($link, $submitted, $due);
135 echo "<br />";
137 print_table($table);
139 print_footer($course);