MDL-61967 core_user: Allow filtering by No groups on participants page
[moodle.git] / user / files.php
blobdadaf619d94f3730fcbf0da5ef1cef06e9661916
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('privatefiles');
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(fullname($USER));
51 $PAGE->set_pagelayout('standard');
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 // Attempt to generate an inbound message address to support e-mail to private files.
68 $generator = new \core\message\inbound\address_manager();
69 $generator->set_handler('\core\message\inbound\private_files_handler');
70 $generator->set_data(-1);
71 $data->emaillink = $generator->generate($USER->id);
73 $mform = new user_files_form(null, array('data' => $data, 'options' => $options));
75 if ($mform->is_cancelled()) {
76 redirect($returnurl);
77 } else if ($formdata = $mform->get_data()) {
78 $formdata = file_postupdate_standard_filemanager($formdata, 'files', $options, $context, 'user', 'private', 0);
79 redirect($returnurl);
82 echo $OUTPUT->header();
83 echo $OUTPUT->box_start('generalbox');
85 // Show file area space usage.
86 if ($maxareabytes != FILE_AREA_MAX_BYTES_UNLIMITED) {
87 $fileareainfo = file_get_file_area_info($context->id, 'user', 'private');
88 // Display message only if we have files.
89 if ($fileareainfo['filecount']) {
90 $a = (object) [
91 'used' => display_size($fileareainfo['filesize_without_references']),
92 'total' => display_size($maxareabytes)
94 $quotamsg = get_string('quotausage', 'moodle', $a);
95 $notification = new \core\output\notification($quotamsg, \core\output\notification::NOTIFY_INFO);
96 echo $OUTPUT->render($notification);
100 $mform->display();
101 echo $OUTPUT->box_end();
102 echo $OUTPUT->footer();