Assignment MDL-7206 - download all submissions as a zip - finally pushing this into...
[moodle.git] / mod / assignment / submissions.php
CommitLineData
81625028 1<?php
2
3require_once("../../config.php");
4require_once("lib.php");
5
6$id = optional_param('id', 0, PARAM_INT); // Course module ID
7$a = optional_param('a', 0, PARAM_INT); // Assignment ID
8$mode = optional_param('mode', 'all', PARAM_ALPHA); // What mode are we in?
b37ce778 9$download = optional_param('download' , 'none', PARAM_ALPHA); //ZIP download asked for?
81625028 10
a6855934 11$url = new moodle_url('/mod/assignment/submissions.php');
81625028 12if ($id) {
13 if (! $cm = get_coursemodule_from_id('assignment', $id)) {
14 print_error('invalidcoursemodule');
b7e16e6a 15 }
ec81373f 16
81625028 17 if (! $assignment = $DB->get_record("assignment", array("id"=>$cm->instance))) {
18 print_error('invalidid', 'assignment');
19 }
fdc47ee6 20
81625028 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('invalidcoursemodule');
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');
34 }
35 $url->param('a', $a);
36}
b7b42874 37
81625028 38if ($mode !== 'all') {
39 $url->param('mode', $mode);
40}
41$PAGE->set_url($url);
42require_login($course->id, false, $cm);
ec81373f 43
81625028 44require_capability('mod/assignment:grade', get_context_instance(CONTEXT_MODULE, $cm->id));
45
e92b7f60
PS
46$PAGE->requires->js('/mod/assignment/assignment.js');
47
81625028 48/// Load up the required assignment code
49require($CFG->dirroot.'/mod/assignment/type/'.$assignment->assignmenttype.'/assignment.class.php');
50$assignmentclass = 'assignment_'.$assignment->assignmenttype;
51$assignmentinstance = new $assignmentclass($cm->id, $assignment, $cm, $course);
ec81373f 52
b37ce778
DM
53if($download == "zip") {
54 $assignmentinstance->download_submissions();
55} else {
56 $assignmentinstance->submissions($mode); // Display or process the submissions
57}