MDL-35073 badges: fix xmldb editor diff
[moodle.git] / mod / assignment / index.php
blob5adcbf2b91cf8830ec672b0ef67c579107409998
1 <?php
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 = $DB->get_record('course', array('id'=>$id))) {
10 print_error('invalidcourseid');
13 require_course_login($course);
14 $PAGE->set_pagelayout('incourse');
16 add_to_log($course->id, "assignment", "view all", "index.php?id=$course->id", "");
18 $strassignments = get_string("modulenameplural", "assignment");
19 $strassignment = get_string("modulename", "assignment");
20 $strassignmenttype = get_string("assignmenttype", "assignment");
21 $strsectionname = get_string('sectionname', 'format_'.$course->format);
22 $strname = get_string("name");
23 $strduedate = get_string("duedate", "assignment");
24 $strsubmitted = get_string("submitted", "assignment");
25 $strgrade = get_string("grade");
28 $PAGE->set_url('/mod/assignment/index.php', array('id'=>$course->id));
29 $PAGE->navbar->add($strassignments);
30 $PAGE->set_title($strassignments);
31 $PAGE->set_heading($course->fullname);
32 echo $OUTPUT->header();
34 if (!$cms = get_coursemodules_in_course('assignment', $course->id, 'cm.idnumber, m.assignmenttype, m.timedue')) {
35 notice(get_string('noassignments', 'assignment'), "../../course/view.php?id=$course->id");
36 die;
39 $usesections = course_format_uses_sections($course->format);
41 $timenow = time();
43 $table = new html_table();
45 if ($usesections) {
46 $table->head = array ($strsectionname, $strname, $strassignmenttype, $strduedate, $strsubmitted, $strgrade);
47 } else {
48 $table->head = array ($strname, $strassignmenttype, $strduedate, $strsubmitted, $strgrade);
51 $currentsection = "";
53 $types = assignment_types();
55 $modinfo = get_fast_modinfo($course);
56 foreach ($modinfo->instances['assignment'] as $cm) {
57 if (!$cm->uservisible) {
58 continue;
61 $cm->timedue = $cms[$cm->id]->timedue;
62 $cm->assignmenttype = $cms[$cm->id]->assignmenttype;
63 $cm->idnumber = $cms[$cm->id]->idnumber;
65 //Show dimmed if the mod is hidden
66 $class = $cm->visible ? '' : 'class="dimmed"';
68 $link = "<a $class href=\"view.php?id=$cm->id\">".format_string($cm->name)."</a>";
70 $printsection = "";
71 if ($usesections) {
72 if ($cm->sectionnum !== $currentsection) {
73 if ($cm->sectionnum) {
74 $printsection = get_section_name($course, $cm->sectionnum);
76 if ($currentsection !== "") {
77 $table->data[] = 'hr';
79 $currentsection = $cm->sectionnum;
83 if (!file_exists($CFG->dirroot.'/mod/assignment/type/'.$cm->assignmenttype.'/assignment.class.php')) {
84 continue;
87 require_once ($CFG->dirroot.'/mod/assignment/type/'.$cm->assignmenttype.'/assignment.class.php');
88 $assignmentclass = 'assignment_'.$cm->assignmenttype;
89 $assignmentinstance = new $assignmentclass($cm->id, NULL, $cm, $course);
91 $submitted = $assignmentinstance->submittedlink(true);
93 $grading_info = grade_get_grades($course->id, 'mod', 'assignment', $cm->instance, $USER->id);
94 if (isset($grading_info->items[0]) && !$grading_info->items[0]->grades[$USER->id]->hidden ) {
95 $grade = $grading_info->items[0]->grades[$USER->id]->str_grade;
97 else {
98 $grade = '-';
101 $type = $types[$cm->assignmenttype];
103 // if type has an 'all.php' defined, make this a link
104 $pathtoall = "{$CFG->dirroot}/mod/assignment/type/{$cm->assignmenttype}/all.php";
105 if (file_exists($pathtoall)) {
106 $type = "<a href=\"{$CFG->wwwroot}/mod/assignment/type/{$cm->assignmenttype}/".
107 "all.php?id={$course->id}\">$type</a>";
110 $due = $cm->timedue ? userdate($cm->timedue) : '-';
112 if ($usesections) {
113 $table->data[] = array ($printsection, $link, $type, $due, $submitted, $grade);
114 } else {
115 $table->data[] = array ($link, $type, $due, $submitted, $grade);
119 echo "<br />";
121 echo html_writer::table($table);
123 echo $OUTPUT->footer();