Merge branch 'MDL-32088-27' of git://github.com/danpoltawski/moodle into MOODLE_27_STABLE
[moodle.git] / user / files.php
blobf1f03b77f666c477d4f5b7a0729c9b6ac23acf96
1 <?php
2 // This file is part of Moodle - http://moodle.org/
3 //
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
17 /**
18 * Manage files in folder in private area.
20 * @package core_user
21 * @category files
22 * @copyright 2010 Petr Skoda (http://skodak.org)
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26 require('../config.php');
27 require_once("$CFG->dirroot/user/files_form.php");
28 require_once("$CFG->dirroot/repository/lib.php");
30 require_login();
31 if (isguestuser()) {
32 die();
35 $returnurl = optional_param('returnurl', '', PARAM_LOCALURL);
37 if (empty($returnurl)) {
38 $returnurl = new moodle_url('/user/files.php');
41 $context = context_user::instance($USER->id);
42 require_capability('moodle/user:manageownfiles', $context);
44 $title = get_string('myfiles');
45 $struser = get_string('user');
47 $PAGE->set_url('/user/files.php');
48 $PAGE->set_context($context);
49 $PAGE->set_title($title);
50 $PAGE->set_heading($title);
51 $PAGE->set_pagelayout('mydashboard');
52 $PAGE->set_pagetype('user-files');
54 $maxbytes = $CFG->userquota;
55 $maxareabytes = $CFG->userquota;
56 if (has_capability('moodle/user:ignoreuserquota', $context)) {
57 $maxbytes = USER_CAN_IGNORE_FILE_SIZE_LIMITS;
58 $maxareabytes = FILE_AREA_MAX_BYTES_UNLIMITED;
61 $data = new stdClass();
62 $data->returnurl = $returnurl;
63 $options = array('subdirs' => 1, 'maxbytes' => $maxbytes, 'maxfiles' => -1, 'accepted_types' => '*',
64 'areamaxbytes' => $maxareabytes);
65 file_prepare_standard_filemanager($data, 'files', $options, $context, 'user', 'private', 0);
67 $mform = new user_files_form(null, array('data' => $data, 'options' => $options));
69 if ($mform->is_cancelled()) {
70 redirect($returnurl);
71 } else if ($formdata = $mform->get_data()) {
72 $formdata = file_postupdate_standard_filemanager($formdata, 'files', $options, $context, 'user', 'private', 0);
73 redirect($returnurl);
76 echo $OUTPUT->header();
77 echo $OUTPUT->box_start('generalbox');
78 $mform->display();
79 echo $OUTPUT->box_end();
80 echo $OUTPUT->footer();