Assignment MDL-7206 - download all submissions as a zip - finally pushing this into...
[moodle.git] / mod / assignment / submissions.php
1 <?php
3 require_once("../../config.php");
4 require_once("lib.php");
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?
9 $download = optional_param('download' , 'none', PARAM_ALPHA); //ZIP download asked for?
11 $url = new moodle_url('/mod/assignment/submissions.php');
12 if ($id) {
13     if (! $cm = get_coursemodule_from_id('assignment', $id)) {
14         print_error('invalidcoursemodule');
15     }
17     if (! $assignment = $DB->get_record("assignment", array("id"=>$cm->instance))) {
18         print_error('invalidid', 'assignment');
19     }
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 }
38 if ($mode !== 'all') {
39     $url->param('mode', $mode);
40 }
41 $PAGE->set_url($url);
42 require_login($course->id, false, $cm);
44 require_capability('mod/assignment:grade', get_context_instance(CONTEXT_MODULE, $cm->id));
46 $PAGE->requires->js('/mod/assignment/assignment.js');
48 /// Load up the required assignment code
49 require($CFG->dirroot.'/mod/assignment/type/'.$assignment->assignmenttype.'/assignment.class.php');
50 $assignmentclass = 'assignment_'.$assignment->assignmenttype;
51 $assignmentinstance = new $assignmentclass($cm->id, $assignment, $cm, $course);
53 if($download == "zip") {
54     $assignmentinstance->download_submissions();
55 } else {
56     $assignmentinstance->submissions($mode);   // Display or process the submissions
57 }