Merge branch 'MDL-35644-MOODLE_22_STABLE' of git://github.com/mouneyrac/moodle into...
[moodle.git] / mod / assignment / submissions.php
blob23584656c6460eb3d80e954495f4a3a3be9298fc
1 <?php
3 require_once("../../config.php");
4 require_once("lib.php");
5 require_once($CFG->libdir.'/plagiarismlib.php');
7 $id = optional_param('id', 0, PARAM_INT); // Course module ID
8 $a = optional_param('a', 0, PARAM_INT); // Assignment ID
9 $mode = optional_param('mode', 'all', PARAM_ALPHA); // What mode are we in?
10 $download = optional_param('download' , 'none', PARAM_ALPHA); //ZIP download asked for?
12 $url = new moodle_url('/mod/assignment/submissions.php');
13 if ($id) {
14 if (! $cm = get_coursemodule_from_id('assignment', $id)) {
15 print_error('invalidcoursemodule');
18 if (! $assignment = $DB->get_record("assignment", array("id"=>$cm->instance))) {
19 print_error('invalidid', 'assignment');
22 if (! $course = $DB->get_record("course", array("id"=>$assignment->course))) {
23 print_error('coursemisconf', 'assignment');
25 $url->param('id', $id);
26 } else {
27 if (!$assignment = $DB->get_record("assignment", array("id"=>$a))) {
28 print_error('invalidcoursemodule');
30 if (! $course = $DB->get_record("course", array("id"=>$assignment->course))) {
31 print_error('coursemisconf', 'assignment');
33 if (! $cm = get_coursemodule_from_instance("assignment", $assignment->id, $course->id)) {
34 print_error('invalidcoursemodule');
36 $url->param('a', $a);
39 if ($mode !== 'all') {
40 $url->param('mode', $mode);
42 $PAGE->set_url($url);
43 require_login($course->id, false, $cm);
45 require_capability('mod/assignment:grade', get_context_instance(CONTEXT_MODULE, $cm->id));
47 $PAGE->requires->js('/mod/assignment/assignment.js');
49 /// Load up the required assignment code
50 require($CFG->dirroot.'/mod/assignment/type/'.$assignment->assignmenttype.'/assignment.class.php');
51 $assignmentclass = 'assignment_'.$assignment->assignmenttype;
52 $assignmentinstance = new $assignmentclass($cm->id, $assignment, $cm, $course);
54 if($download == "zip") {
55 $assignmentinstance->download_submissions();
56 } else {
57 $assignmentinstance->submissions($mode); // Display or process the submissions