MDL-37717 warn teachers before disabling or deleting their enrolment method
[moodle.git] / enrol / manual / edit_form.php
CommitLineData
eafb7a72 1<?php
eafb7a72
PS
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 *
6f6c9e5c 21 * @package enrol_manual
eafb7a72
PS
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
97795859 26defined('MOODLE_INTERNAL') || die();
eafb7a72
PS
27
28require_once($CFG->libdir.'/formslib.php');
29
30class 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
eafb7a72
PS
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'));
eafb7a72 52
129e6d36
PS
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
8e941204
PS
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');
129e6d36 60
8e941204
PS
61 $mform->addElement('duration', 'expirythreshold', get_string('expirythreshold', 'core_enrol'), array('optional' => false, 'defaultunit' => 86400));
62 $mform->addHelpButton('expirythreshold', 'expirythreshold', 'core_enrol');
129e6d36
PS
63 $mform->disabledIf('expirythreshold', 'expirynotify', 'eq', 0);
64
eafb7a72 65 $mform->addElement('hidden', 'courseid');
361c4da2 66 $mform->setType('courseid', PARAM_INT);
eafb7a72 67
12c92bca
PS
68 if (enrol_accessing_via_instance($instance)) {
69 $mform->addElement('static', 'selfwarn', get_string('instanceeditselfwarning', 'core_enrol'), get_string('instanceeditselfwarningtext', 'core_enrol'));
70 }
71
684784c8 72 $this->add_action_buttons(true, ($instance->id ? null : get_string('addinstance', 'enrol')));
eafb7a72
PS
73
74 $this->set_data($instance);
75 }
129e6d36
PS
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) {
8e941204 83 $errors['expirythreshold'] = get_string('errorthresholdlow', 'core_enrol');
129e6d36
PS
84 }
85
86 return $errors;
87 }
6f6c9e5c 88}