MDL-22893, assignment module should use filepicker and filemanager
[moodle.git] / mod / assignment / type / uploadsingle / upload.php
1 <?php
3 // This file is part of Moodle - http://moodle.org/
4 //
5 // Moodle is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // Moodle is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
18 /**
19  *
20  * @package   mod-assignment
21  * @copyright 2010 Dongsheng Cai <dongsheng@moodle.com>
22  * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23  */
25 require_once(dirname(dirname(dirname(dirname(dirname(__FILE__))))).'/config.php');
26 require_once(dirname(__FILE__).'/upload_form.php');
27 require_once(dirname(__FILE__).'/assignment.class.php');
28 require_once("$CFG->dirroot/repository/lib.php");
30 $contextid = required_param('contextid', PARAM_INT);
32 $url = new moodle_url('/mod/assignment/type/uploadsingle/upload.php', array('contextid'=>$contextid));
34 list($context, $course, $cm) = get_context_info_array($contextid);
36 if (!$assignment = $DB->get_record('assignment', array('id'=>$cm->instance))) {
37     print_error('invalidid', 'assignment');
38 }
40 require_login($course, true, $cm);
41 if (isguestuser()) {
42     die();
43 }
44 $instance = new assignment_uploadsingle($cm->id, $assignment, $cm, $course);
46 $PAGE->set_url($url);
47 $PAGE->set_context($context);
48 $title = strip_tags($course->fullname.': '.get_string('modulename', 'assignment').': '.format_string($assignment->name,true));
49 $PAGE->set_title($title);
50 $PAGE->set_heading($title);
52 $options = array('subdirs'=>0, 'maxbytes'=>$CFG->userquota, 'maxfiles'=>1, 'accepted_types'=>'*', 'return_types'=>FILE_INTERNAL);
54 $mform = new mod_assignment_uploadsingle_form(null, array('contextid'=>$contextid, 'options'=>$options));
56 if ($mform->is_cancelled()) {
57     redirect(new moodle_url('/mod/assignment/view.php', array('id'=>$cm->id)));
58 } else if ($formdata = $mform->get_data()) {
59     $instance->upload($mform, $options);
60     redirect(new moodle_url('/mod/assignment/view.php', array('id'=>$cm->id)));
61 }
63 echo $OUTPUT->header();
64 echo $OUTPUT->box_start('generalbox');
65 $mform->display();
66 echo $OUTPUT->box_end();
67 echo $OUTPUT->footer();