[ Index ]

PHP Cross Reference of moodle-2.8

title

Body

[close]

/enrol/manual/ -> edit_form.php (source)

   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   * Adds new instance of enrol_manual to specified course
  19   * or edits current instance.
  20   *
  21   * @package    enrol_manual
  22   * @copyright  2010 Petr Skoda  {@link http://skodak.org}
  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  class enrol_manual_edit_form extends moodleform {
  31  
  32      function definition() {
  33          $mform = $this->_form;
  34  
  35          list($instance, $plugin, $context) = $this->_customdata;
  36  
  37          $mform->addElement('header', 'header', get_string('pluginname', 'enrol_manual'));
  38  
  39          $options = array(ENROL_INSTANCE_ENABLED  => get_string('yes'),
  40                           ENROL_INSTANCE_DISABLED => get_string('no'));
  41          $mform->addElement('select', 'status', get_string('status', 'enrol_manual'), $options);
  42          $mform->addHelpButton('status', 'status', 'enrol_manual');
  43          $mform->setDefault('status', $plugin->get_config('status'));
  44  
  45          if ($instance->id) {
  46              $roles = get_default_enrol_roles($context, $instance->roleid);
  47          } else {
  48              $roles = get_default_enrol_roles($context, $plugin->get_config('roleid'));
  49          }
  50          $mform->addElement('select', 'roleid', get_string('defaultrole', 'role'), $roles);
  51          $mform->setDefault('roleid', $plugin->get_config('roleid'));
  52  
  53          $mform->addElement('duration', 'enrolperiod', get_string('defaultperiod', 'enrol_manual'), array('optional' => true, 'defaultunit' => 86400));
  54          $mform->setDefault('enrolperiod', $plugin->get_config('enrolperiod'));
  55          $mform->addHelpButton('enrolperiod', 'defaultperiod', 'enrol_manual');
  56  
  57          $options = array(0 => get_string('no'), 1 => get_string('expirynotifyenroller', 'core_enrol'), 2 => get_string('expirynotifyall', 'core_enrol'));
  58          $mform->addElement('select', 'expirynotify', get_string('expirynotify', 'core_enrol'), $options);
  59          $mform->addHelpButton('expirynotify', 'expirynotify', 'core_enrol');
  60  
  61          $mform->addElement('duration', 'expirythreshold', get_string('expirythreshold', 'core_enrol'), array('optional' => false, 'defaultunit' => 86400));
  62          $mform->addHelpButton('expirythreshold', 'expirythreshold', 'core_enrol');
  63          $mform->disabledIf('expirythreshold', 'expirynotify', 'eq', 0);
  64  
  65          $mform->addElement('hidden', 'courseid');
  66          $mform->setType('courseid', PARAM_INT);
  67  
  68          if (enrol_accessing_via_instance($instance)) {
  69              $mform->addElement('static', 'selfwarn', get_string('instanceeditselfwarning', 'core_enrol'), get_string('instanceeditselfwarningtext', 'core_enrol'));
  70          }
  71  
  72          $this->add_action_buttons(true, ($instance->id ? null : get_string('addinstance', 'enrol')));
  73  
  74          $this->set_data($instance);
  75      }
  76  
  77      function validation($data, $files) {
  78          global $DB;
  79  
  80          $errors = parent::validation($data, $files);
  81  
  82          if ($data['expirynotify'] > 0 and $data['expirythreshold'] < 86400) {
  83              $errors['expirythreshold'] = get_string('errorthresholdlow', 'core_enrol');
  84          }
  85  
  86          return $errors;
  87      }
  88  }


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