[ Index ]

PHP Cross Reference of moodle-2.8

title

Body

[close]

/admin/tool/installaddon/classes/ -> installfromzip_form.php (source)

   1  <?php
   2  
   3  // This file is part of Moodle - http://moodle.org/
   4  //
   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.
   9  //
  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.
  14  //
  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/>.
  17  
  18  /**
  19   * @package     tool_installaddon
  20   * @subpackage  classes
  21   * @category    form
  22   * @copyright   2013 David Mudrak <[email protected]>
  23   * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  24   */
  25  
  26  defined('MOODLE_INTERNAL') || die();
  27  
  28  require_once($CFG->libdir.'/formslib.php');
  29  
  30  /**
  31   * Defines a simple form for uploading the add-on ZIP package
  32   *
  33   * @copyright 2013 David Mudrak <[email protected]>
  34   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  35   */
  36  class tool_installaddon_installfromzip_form extends moodleform {
  37  
  38      /**
  39       * Defines the form elements
  40       */
  41      public function definition() {
  42  
  43          $mform = $this->_form;
  44          $installer = $this->_customdata['installer'];
  45  
  46          $mform->addElement('header', 'general', get_string('installfromzip', 'tool_installaddon'));
  47          $mform->addHelpButton('general', 'installfromzip', 'tool_installaddon');
  48  
  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');
  54  
  55          $mform->addElement('static', 'permcheck', '',
  56              html_writer::span(get_string('permcheck', 'tool_installaddon'), '',
  57                  array('id' => 'tool_installaddon_installfromzip_permcheck')));
  58  
  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');
  63  
  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');
  68  
  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');
  72  
  73          $this->add_action_buttons(false, get_string('installfromzipsubmit', 'tool_installaddon'));
  74      }
  75  
  76      /**
  77       * Validate the form fields
  78       *
  79       * @param array $data
  80       * @param array $files
  81       * @return array (string)field name => (string)validation error text
  82       */
  83      public function validation($data, $files) {
  84  
  85          $installer = $this->_customdata['installer'];
  86          $errors = parent::validation($data, $files);
  87  
  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));
  91          }
  92  
  93          return $errors;
  94      }
  95  }


Generated: Fri Nov 28 20:29:05 2014 Cross-referenced by PHPXref 0.7.1