Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.
   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  /**
  18   * Class tinymce_managefiles_manage_form
  19   *
  20   * @package   tinymce_managefiles
  21   * @copyright 2013 Marina Glancy
  22   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  defined('MOODLE_INTERNAL') || die();
  26  
  27  require_once($CFG->libdir."/formslib.php");
  28  
  29  /**
  30   * Form allowing to edit files in one draft area
  31   *
  32   * No buttons are necessary since the draft area files are saved immediately using AJAX
  33   *
  34   * @package   tinymce_managefiles
  35   * @copyright 2013 Marina Glancy
  36   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  37   */
  38  class tinymce_managefiles_manage_form extends moodleform {
  39      function definition() {
  40          global $PAGE;
  41          $mform = $this->_form;
  42  
  43          $itemid           = $this->_customdata['draftitemid'];
  44          $options          = $this->_customdata['options'];
  45          $files            = $this->_customdata['files'];
  46  
  47          $mform->addElement('hidden', 'itemid');
  48          $mform->setType('itemid', PARAM_INT);
  49          $mform->addElement('hidden', 'maxbytes');
  50          $mform->setType('maxbytes', PARAM_INT);
  51          $mform->addElement('hidden', 'subdirs');
  52          $mform->setType('subdirs', PARAM_INT);
  53          $mform->addElement('hidden', 'accepted_types');
  54          $mform->setType('accepted_types', PARAM_RAW);
  55          $mform->addElement('hidden', 'return_types');
  56          $mform->setType('return_types', PARAM_INT);
  57          $mform->addElement('hidden', 'context');
  58          $mform->setType('context', PARAM_INT);
  59          $mform->addElement('hidden', 'areamaxbytes');
  60          $mform->setType('areamaxbytes', PARAM_INT);
  61  
  62          $mform->addElement('filemanager', 'files_filemanager', '', null, $options);
  63  
  64          $mform->addElement('submit', 'refresh', get_string('refreshfiles', 'tinymce_managefiles'));
  65          $mform->registerNoSubmitButton('refresh');
  66  
  67          $mform->addElement('static', '', '',
  68                  html_writer::tag('div', '', array('class' => 'managefilesstatus')));
  69  
  70          $mform->addElement('header', 'deletefiles', get_string('unusedfilesheader', 'tinymce_managefiles'));
  71          $mform->addElement('static', '', '',
  72                  html_writer::tag('span', get_string('unusedfilesdesc', 'tinymce_managefiles'), array('class' => 'managefilesunuseddesc')));
  73          foreach ($files as $file) {
  74              $mform->addElement('checkbox', 'deletefile['.$file.']', '', $file);
  75              $mform->setType('deletefile['.$file.']', PARAM_INT);
  76          }
  77          $mform->addElement('submit', 'delete', get_string('deleteselected', 'tinymce_managefiles'));
  78  
  79          $PAGE->requires->js_init_call('M.tinymce_managefiles.analysefiles', array(), true);
  80          $PAGE->requires->strings_for_js(array('allfilesok', 'hasmissingfiles'), 'tinymce_managefiles');
  81  
  82          $this->set_data(array('files_filemanager' => $itemid,
  83              'itemid' => $itemid,
  84              'subdirs' => $options['subdirs'],
  85              'maxbytes' => $options['maxbytes'],
  86              'areamaxbytes' => $options['areamaxbytes'],
  87              'accepted_types' => $options['accepted_types'],
  88              'return_types' => $options['return_types'],
  89              'context' => $options['context']->id,
  90              ));
  91      }
  92  }