MDL-28019 Added plugin tinymce_managefiles
[moodle.git] / lib / editor / tinymce / plugins / managefiles / manage_form.php
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/>.
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  */
25 defined('MOODLE_INTERNAL') || die();
27 require_once($CFG->libdir."/formslib.php");
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;
43         $itemid           = $this->_customdata['draftitemid'];
44         $options          = $this->_customdata['options'];
45         $files            = $this->_customdata['files'];
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);
62         $mform->addElement('filemanager', 'files_filemanager', '', null, $options);
64         $mform->addElement('submit', 'refresh', get_string('refreshfiles', 'tinymce_managefiles'));
65         $mform->registerNoSubmitButton('refresh');
67         $mform->addElement('static', '', '',
68                 html_writer::tag('span', '', array('class' => 'managefilesstatus')));
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'));
79         $PAGE->requires->js_init_call('M.tinymce_managefiles.analysefiles', array(), true);
80         $PAGE->requires->strings_for_js(array('allfilesok', 'hasmissingfiles'), 'tinymce_managefiles');
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 }