files_form.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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.
  13. //
  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/>.
  16. /**
  17. * minimalistic edit form
  18. *
  19. * @package core_user
  20. * @category files
  21. * @copyright 2010 Petr Skoda (http://skodak.org)
  22. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23. */
  24. defined('MOODLE_INTERNAL') || die();
  25. require_once("$CFG->libdir/formslib.php");
  26. /**
  27. * Class user_files_form
  28. * @copyright 2010 Petr Skoda (http://skodak.org)
  29. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  30. */
  31. class user_files_form extends moodleform {
  32. /**
  33. * Add elements to this form.
  34. */
  35. public function definition() {
  36. $mform = $this->_form;
  37. $data = $this->_customdata['data'];
  38. $options = $this->_customdata['options'];
  39. $mform->addElement('filemanager', 'files_filemanager', get_string('files'), null, $options);
  40. $mform->addElement('hidden', 'returnurl', $data->returnurl);
  41. if (isset($data->emaillink)) {
  42. $emaillink = html_writer::link(new moodle_url('mailto:' . $data->emaillink), $data->emaillink);
  43. $mform->addElement('static', 'emailaddress', '',
  44. get_string('emailtoprivatefiles', 'moodle', $emaillink));
  45. }
  46. $mform->setType('returnurl', PARAM_LOCALURL);
  47. $this->add_action_buttons(true, get_string('savechanges'));
  48. $this->set_data($data);
  49. }
  50. /**
  51. * Validate incoming data.
  52. *
  53. * @param array $data
  54. * @param array $files
  55. * @return array
  56. */
  57. public function validation($data, $files) {
  58. $errors = array();
  59. $draftitemid = $data['files_filemanager'];
  60. if (file_is_draft_area_limit_reached($draftitemid, $this->_customdata['options']['areamaxbytes'])) {
  61. $errors['files_filemanager'] = get_string('userquotalimit', 'error');
  62. }
  63. return $errors;
  64. }
  65. }