Merge commit 'catalyst/MOODLE_19_STABLE' into mdl19-linuxchix
[moodle-linuxchix.git] / mod / assignment / index.php
blob334266e95be041d086e1c51d48b9ab95d30617e5
1 <?php // $Id$
3 require_once("../../config.php");
4 require_once("lib.php");
5 require_once($CFG->libdir.'/gradelib.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_course_login($course);
14 add_to_log($course->id, "assignment", "view all", "index.php?id=$course->id", "");
16 $strassignments = get_string("modulenameplural", "assignment");
17 $strassignment = get_string("modulename", "assignment");
18 $strassignmenttype = get_string("assignmenttype", "assignment");
19 $strweek = get_string("week");
20 $strtopic = get_string("topic");
21 $strname = get_string("name");
22 $strduedate = get_string("duedate", "assignment");
23 $strsubmitted = get_string("submitted", "assignment");
24 $strgrade = get_string("grade");
26 $navlinks = array();
27 $navlinks[] = array('name' => $strassignments, 'link' => '', 'type' => 'activity');
28 $navigation = build_navigation($navlinks);
30 print_header_simple($strassignments, "", $navigation, "", "", true, "", navmenu($course));
32 if (!$cms = get_coursemodules_in_course('assignment', $course->id, 'm.assignmenttype, m.timedue')) {
33 notice(get_string('noassignments', 'assignment'), "../../course/view.php?id=$course->id");
34 die;
37 $timenow = time();
39 if ($course->format == "weeks") {
40 $table->head = array ($strweek, $strname, $strassignmenttype, $strduedate, $strsubmitted, $strgrade);
41 $table->align = array ("center", "left", "left", "left", "right");
42 } else if ($course->format == "topics") {
43 $table->head = array ($strtopic, $strname, $strassignmenttype, $strduedate, $strsubmitted, $strgrade);
44 $table->align = array ("center", "left", "left", "left", "right");
45 } else {
46 $table->head = array ($strname, $strassignmenttype, $strduedate, $strsubmitted, $strgrade);
47 $table->align = array ("left", "left", "left", "right");
50 $currentsection = "";
52 $types = assignment_types();
54 $modinfo = get_fast_modinfo($course);
55 foreach ($modinfo->instances['assignment'] as $cm) {
56 if (!$cm->uservisible) {
57 continue;
60 $cm->timedue = $cms[$cm->id]->timedue;
61 $cm->assignmenttype = $cms[$cm->id]->assignmenttype;
63 //Show dimmed if the mod is hidden
64 $class = $cm->visible ? '' : 'class="dimmed"';
66 $link = "<a $class href=\"view.php?id=$cm->id\">".format_string($cm->name)."</a>";
68 $printsection = "";
69 if ($cm->sectionnum !== $currentsection) {
70 if ($cm->sectionnum) {
71 $printsection = $cm->sectionnum;
73 if ($currentsection !== "") {
74 $table->data[] = 'hr';
76 $currentsection = $cm->sectionnum;
79 if (!file_exists($CFG->dirroot.'/mod/assignment/type/'.$cm->assignmenttype.'/assignment.class.php')) {
80 continue;
83 require_once ($CFG->dirroot.'/mod/assignment/type/'.$cm->assignmenttype.'/assignment.class.php');
84 $assignmentclass = 'assignment_'.$cm->assignmenttype;
85 $assignmentinstance = new $assignmentclass($cm->id, NULL, $cm, $course);
87 $submitted = $assignmentinstance->submittedlink(true);
89 $grading_info = grade_get_grades($course->id, 'mod', 'assignment', $cm->instance, $USER->id);
90 if (isset($grading_info->items[0])) {
91 $grade = $grading_info->items[0]->grades[$USER->id]->str_grade;
93 else {
94 $grade = '-';
97 $type = $types[$cm->assignmenttype];
99 $due = $cm->timedue ? userdate($cm->timedue) : '-';
101 if ($course->format == "weeks" or $course->format == "topics") {
102 $table->data[] = array ($printsection, $link, $type, $due, $submitted, $grade);
103 } else {
104 $table->data[] = array ($link, $type, $due, $submitted, $grade);
108 echo "<br />";
110 print_table($table);
112 print_footer($course);