Merge branch 'MDL-43534-master' of git://github.com/andrewnicols/moodle
[moodle.git] / mod / assignment / view.php
CommitLineData
81625028 1<?php
2
3require_once("../../config.php");
4require_once("lib.php");
5require_once($CFG->libdir . '/completionlib.php');
bce59524 6require_once($CFG->libdir . '/plagiarismlib.php');
81625028 7
8$id = optional_param('id', 0, PARAM_INT); // Course Module ID
9$a = optional_param('a', 0, PARAM_INT); // Assignment ID
10
a6855934 11$url = new moodle_url('/mod/assignment/view.php');
81625028 12if ($id) {
13 if (! $cm = get_coursemodule_from_id('assignment', $id)) {
14 print_error('invalidcoursemodule');
15 }
16
17 if (! $assignment = $DB->get_record("assignment", array("id"=>$cm->instance))) {
18 print_error('invalidid', 'assignment');
19 }
20
21 if (! $course = $DB->get_record("course", array("id"=>$assignment->course))) {
22 print_error('coursemisconf', 'assignment');
23 }
24 $url->param('id', $id);
25} else {
26 if (!$assignment = $DB->get_record("assignment", array("id"=>$a))) {
27 print_error('invalidid', 'assignment');
28 }
29 if (! $course = $DB->get_record("course", array("id"=>$assignment->course))) {
30 print_error('coursemisconf', 'assignment');
31 }
32 if (! $cm = get_coursemodule_from_instance("assignment", $assignment->id, $course->id)) {
33 print_error('invalidcoursemodule');
d699cd1e 34 }
81625028 35 $url->param('a', $a);
36}
d699cd1e 37
81625028 38$PAGE->set_url($url);
39require_login($course, true, $cm);
12acb98c 40
e92b7f60
PS
41$PAGE->requires->js('/mod/assignment/assignment.js');
42
79547e52
MN
43$classfile = "$CFG->dirroot/mod/assignment/type/$assignment->assignmenttype/assignment.class.php";
44if (!file_exists($classfile)) {
45 throw new moodle_exception('unsupportedsubplugin', 'assignment', new moodle_url('/course/view.php', array('id' => $course->id)), $assignment->assignmenttype);
46}
4550e762 47require_once($classfile);
81625028 48$assignmentclass = "assignment_$assignment->assignmenttype";
49$assignmentinstance = new $assignmentclass($cm->id, $assignment, $cm, $course);
ec81373f 50
18a2a0cb 51/// Mark as viewed
81625028 52$completion=new completion_info($course);
53$completion->set_module_viewed($cm);
d699cd1e 54
81625028 55$assignmentinstance->view(); // Actually display the assignment!