MDL-37717 warn teachers before disabling or deleting their enrolment method
[moodle.git] / enrol / paypal / edit_form.php
CommitLineData
42761bc6 1<?php
42761bc6
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_paypal to specified course
19 * or edits current instance.
20 *
31ac2aef 21 * @package enrol_paypal
42761bc6
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();
42761bc6
PS
27
28require_once($CFG->libdir.'/formslib.php');
29
30class enrol_paypal_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_paypal'));
38
39 $mform->addElement('text', 'name', get_string('custominstancename', 'enrol'));
eeb6c4ac 40 $mform->setType('name', PARAM_TEXT);
42761bc6
PS
41
42 $options = array(ENROL_INSTANCE_ENABLED => get_string('yes'),
43 ENROL_INSTANCE_DISABLED => get_string('no'));
44 $mform->addElement('select', 'status', get_string('status', 'enrol_paypal'), $options);
45 $mform->setDefault('status', $plugin->get_config('status'));
46
47 $mform->addElement('text', 'cost', get_string('cost', 'enrol_paypal'), array('size'=>4));
881afa48 48 $mform->setType('cost', PARAM_RAW); // Use unformat_float to get real value.
ee4df06f 49 $mform->setDefault('cost', format_float($plugin->get_config('cost'), 2, true));
42761bc6 50
0456edb4 51 $paypalcurrencies = $plugin->get_currencies();
42761bc6
PS
52 $mform->addElement('select', 'currency', get_string('currency', 'enrol_paypal'), $paypalcurrencies);
53 $mform->setDefault('currency', $plugin->get_config('currency'));
54
55 if ($instance->id) {
56 $roles = get_default_enrol_roles($context, $instance->roleid);
57 } else {
58 $roles = get_default_enrol_roles($context, $plugin->get_config('roleid'));
59 }
60 $mform->addElement('select', 'roleid', get_string('assignrole', 'enrol_paypal'), $roles);
61 $mform->setDefault('roleid', $plugin->get_config('roleid'));
62
63
64 $mform->addElement('duration', 'enrolperiod', get_string('enrolperiod', 'enrol_paypal'), array('optional' => true, 'defaultunit' => 86400));
65 $mform->setDefault('enrolperiod', $plugin->get_config('enrolperiod'));
94f630e3 66 $mform->addHelpButton('enrolperiod', 'enrolperiod', 'enrol_paypal');
42761bc6
PS
67
68 $mform->addElement('date_selector', 'enrolstartdate', get_string('enrolstartdate', 'enrol_paypal'), array('optional' => true));
69 $mform->setDefault('enrolstartdate', 0);
94f630e3 70 $mform->addHelpButton('enrolstartdate', 'enrolstartdate', 'enrol_paypal');
42761bc6
PS
71
72 $mform->addElement('date_selector', 'enrolenddate', get_string('enrolenddate', 'enrol_paypal'), array('optional' => true));
73 $mform->setDefault('enrolenddate', 0);
94f630e3 74 $mform->addHelpButton('enrolenddate', 'enrolenddate', 'enrol_paypal');
42761bc6
PS
75
76 $mform->addElement('hidden', 'id');
eeb6c4ac
DM
77 $mform->setType('id', PARAM_INT);
78
42761bc6 79 $mform->addElement('hidden', 'courseid');
eeb6c4ac 80 $mform->setType('courseid', PARAM_INT);
42761bc6 81
12c92bca
PS
82 if (enrol_accessing_via_instance($instance)) {
83 $mform->addElement('static', 'selfwarn', get_string('instanceeditselfwarning', 'core_enrol'), get_string('instanceeditselfwarningtext', 'core_enrol'));
84 }
85
684784c8 86 $this->add_action_buttons(true, ($instance->id ? null : get_string('addinstance', 'enrol')));
42761bc6
PS
87
88 $this->set_data($instance);
89 }
90
91 function validation($data, $files) {
92 global $DB, $CFG;
93 $errors = parent::validation($data, $files);
94
95 list($instance, $plugin, $context) = $this->_customdata;
96
ee4df06f
PS
97 if (!empty($data['enrolenddate']) and $data['enrolenddate'] < $data['enrolstartdate']) {
98 $errors['enrolenddate'] = get_string('enrolenddaterror', 'enrol_paypal');
99 }
42761bc6 100
ee4df06f
PS
101 $cost = str_replace(get_string('decsep', 'langconfig'), '.', $data['cost']);
102 if (!is_numeric($cost)) {
103 $errors['cost'] = get_string('costerror', 'enrol_paypal');
42761bc6
PS
104 }
105
106 return $errors;
107 }
eeb6c4ac 108}