3 // This file is part of Moodle - http://moodle.org/
5 // Moodle is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
10 // Moodle is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
19 * @package tool_installaddon
22 * @copyright 2013 David Mudrak <david@moodle.com>
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26 defined('MOODLE_INTERNAL') || die();
28 require_once($CFG->libdir.'/formslib.php');
31 * Defines a simple form for uploading the add-on ZIP package
33 * @copyright 2013 David Mudrak <david@moodle.com>
34 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
36 class tool_installaddon_installfromzip_form extends moodleform {
39 * Defines the form elements
41 public function definition() {
43 $mform = $this->_form;
44 $installer = $this->_customdata['installer'];
46 $mform->addElement('header', 'general', get_string('installfromzip', 'tool_installaddon'));
47 $mform->addHelpButton('general', 'installfromzip', 'tool_installaddon');
49 $options = $installer->get_plugin_types_menu();
50 $mform->addElement('select', 'plugintype', get_string('installfromziptype', 'tool_installaddon'), $options,
51 array('id' => 'tool_installaddon_installfromzip_plugintype'));
52 $mform->addHelpButton('plugintype', 'installfromziptype', 'tool_installaddon');
53 $mform->addRule('plugintype', null, 'required', null, 'client');
55 $mform->addElement('static', 'permcheck', '',
56 html_writer::span(get_string('permcheck', 'tool_installaddon'), '',
57 array('id' => 'tool_installaddon_installfromzip_permcheck')));
59 $mform->addElement('filepicker', 'zipfile', get_string('installfromzipfile', 'tool_installaddon'),
60 null, array('accepted_types' => '.zip'));
61 $mform->addHelpButton('zipfile', 'installfromzipfile', 'tool_installaddon');
62 $mform->addRule('zipfile', null, 'required', null, 'client');
64 $mform->addElement('text', 'rootdir', get_string('installfromziprootdir', 'tool_installaddon'));
65 $mform->addHelpButton('rootdir', 'installfromziprootdir', 'tool_installaddon');
66 $mform->setType('rootdir', PARAM_PLUGIN);
67 $mform->setAdvanced('rootdir');
69 $mform->addElement('checkbox', 'acknowledgement', get_string('acknowledgement', 'tool_installaddon'),
70 ' '.get_string('acknowledgementtext', 'tool_installaddon'));
71 $mform->addRule('acknowledgement', get_string('acknowledgementmust', 'tool_installaddon'), 'required', null, 'client');
73 $this->add_action_buttons(false, get_string('installfromzipsubmit', 'tool_installaddon'));
77 * Validate the form fields
81 * @return array (string)field name => (string)validation error text
83 public function validation($data, $files) {
85 $installer = $this->_customdata['installer'];
86 $errors = parent::validation($data, $files);
88 if (!$installer->is_plugintype_writable($data['plugintype'])) {
89 $path = $installer->get_plugintype_root($data['plugintype']);
90 $errors['plugintype'] = get_string('permcheckresultno', 'tool_installaddon', array('path' => $path));