MDL-28117 include repo lib when hacking file_picker renderer
[moodle.git] / mod / assignment / index.php
blob71eb0237ed3b7053a46586999682b8c65d781420
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);
40 if ($usesections) {
41 $sections = get_all_sections($course->id);
44 $timenow = time();
46 $table = new html_table();
48 if ($usesections) {
49 $table->head = array ($strsectionname, $strname, $strassignmenttype, $strduedate, $strsubmitted, $strgrade);
50 } else {
51 $table->head = array ($strname, $strassignmenttype, $strduedate, $strsubmitted, $strgrade);
54 $currentsection = "";
56 $types = assignment_types();
58 $modinfo = get_fast_modinfo($course);
59 foreach ($modinfo->instances['assignment'] as $cm) {
60 if (!$cm->uservisible) {
61 continue;
64 $cm->timedue = $cms[$cm->id]->timedue;
65 $cm->assignmenttype = $cms[$cm->id]->assignmenttype;
66 $cm->idnumber = $cms[$cm->id]->idnumber;
68 //Show dimmed if the mod is hidden
69 $class = $cm->visible ? '' : 'class="dimmed"';
71 $link = "<a $class href=\"view.php?id=$cm->id\">".format_string($cm->name)."</a>";
73 $printsection = "";
74 if ($usesections) {
75 if ($cm->sectionnum !== $currentsection) {
76 if ($cm->sectionnum) {
77 $printsection = get_section_name($course, $sections[$cm->sectionnum]);
79 if ($currentsection !== "") {
80 $table->data[] = 'hr';
82 $currentsection = $cm->sectionnum;
86 if (!file_exists($CFG->dirroot.'/mod/assignment/type/'.$cm->assignmenttype.'/assignment.class.php')) {
87 continue;
90 require_once ($CFG->dirroot.'/mod/assignment/type/'.$cm->assignmenttype.'/assignment.class.php');
91 $assignmentclass = 'assignment_'.$cm->assignmenttype;
92 $assignmentinstance = new $assignmentclass($cm->id, NULL, $cm, $course);
94 $submitted = $assignmentinstance->submittedlink(true);
96 $grading_info = grade_get_grades($course->id, 'mod', 'assignment', $cm->instance, $USER->id);
97 if (isset($grading_info->items[0]) && !$grading_info->items[0]->grades[$USER->id]->hidden ) {
98 $grade = $grading_info->items[0]->grades[$USER->id]->str_grade;
100 else {
101 $grade = '-';
104 $type = $types[$cm->assignmenttype];
106 // if type has an 'all.php' defined, make this a link
107 $pathtoall = "{$CFG->dirroot}/mod/assignment/type/{$cm->assignmenttype}/all.php";
108 if (file_exists($pathtoall)) {
109 $type = "<a href=\"{$CFG->wwwroot}/mod/assignment/type/{$cm->assignmenttype}/".
110 "all.php?id={$course->id}\">$type</a>";
113 $due = $cm->timedue ? userdate($cm->timedue) : '-';
115 if ($usesections) {
116 $table->data[] = array ($printsection, $link, $type, $due, $submitted, $grade);
117 } else {
118 $table->data[] = array ($link, $type, $due, $submitted, $grade);
122 echo "<br />";
124 echo html_writer::table($table);
126 echo $OUTPUT->footer();