Updated the HEAD build version to 20090923
[moodle.git] / mod / assignment / view.php
CommitLineData
9a58f7cb 1<?php // $Id$
d699cd1e 2
b0e3a925 3 require_once("../../config.php");
4 require_once("lib.php");
4e1132a8 5 require_once($CFG->libdir . '/completionlib.php');
6
5d00b3ad 7 $id = optional_param('id', 0, PARAM_INT); // Course Module ID
8 $a = optional_param('a', 0, PARAM_INT); // Assignment ID
d699cd1e 9
10 if ($id) {
f9d5371b 11 if (! $cm = get_coursemodule_from_id('assignment', $id)) {
a939f681 12 print_error('invalidcoursemodule');
d699cd1e 13 }
3a4c2fd0 14
607d2b2a 15 if (! $assignment = $DB->get_record("assignment", array("id"=>$cm->instance))) {
a939f681 16 print_error('invalidid', 'assignment');
d699cd1e 17 }
18
607d2b2a 19 if (! $course = $DB->get_record("course", array("id"=>$assignment->course))) {
a939f681 20 print_error('coursemisconf', 'assignment');
b0f2597e 21 }
d699cd1e 22 } else {
607d2b2a 23 if (!$assignment = $DB->get_record("assignment", array("id"=>$a))) {
a939f681 24 print_error('invalidid', 'assignment');
d699cd1e 25 }
607d2b2a 26 if (! $course = $DB->get_record("course", array("id"=>$assignment->course))) {
a939f681 27 print_error('coursemisconf', 'assignment');
d699cd1e 28 }
29 if (! $cm = get_coursemodule_from_instance("assignment", $assignment->id, $course->id)) {
a939f681 30 print_error('invalidcoursemodule');
d699cd1e 31 }
32 }
33
f8e3d5f0 34 require_login($course, true, $cm);
12acb98c 35
b0f2597e 36 require ("$CFG->dirroot/mod/assignment/type/$assignment->assignmenttype/assignment.class.php");
37 $assignmentclass = "assignment_$assignment->assignmenttype";
73097f07 38 $assignmentinstance = new $assignmentclass($cm->id, $assignment, $cm, $course);
ec81373f 39
18a2a0cb 40/// Mark as viewed
41 $completion=new completion_info($course);
42 $completion->set_module_viewed($cm);
d699cd1e 43
18a2a0cb 44 $assignmentinstance->view(); // Actually display the assignment!
d699cd1e 45?>