2 // This file is part of Moodle - http://moodle.org/
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.
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.
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/>.
18 * Adds new instance of enrol_paypal to specified course
19 * or edits current instance.
21 * @package enrol_paypal
22 * @copyright 2010 Petr Skoda {@link http://skodak.org}
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');
30 class enrol_paypal_edit_form
extends moodleform
{
32 function definition() {
33 $mform = $this->_form
;
35 list($instance, $plugin, $context) = $this->_customdata
;
37 $mform->addElement('header', 'header', get_string('pluginname', 'enrol_paypal'));
39 $mform->addElement('text', 'name', get_string('custominstancename', 'enrol'));
40 $mform->setType('name', PARAM_TEXT
);
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'));
47 $mform->addElement('text', 'cost', get_string('cost', 'enrol_paypal'), array('size'=>4));
48 $mform->setType('cost', PARAM_RAW
); // Use unformat_float to get real value.
49 $mform->setDefault('cost', format_float($plugin->get_config('cost'), 2, true));
51 $paypalcurrencies = $plugin->get_currencies();
52 $mform->addElement('select', 'currency', get_string('currency', 'enrol_paypal'), $paypalcurrencies);
53 $mform->setDefault('currency', $plugin->get_config('currency'));
56 $roles = get_default_enrol_roles($context, $instance->roleid
);
58 $roles = get_default_enrol_roles($context, $plugin->get_config('roleid'));
60 $mform->addElement('select', 'roleid', get_string('assignrole', 'enrol_paypal'), $roles);
61 $mform->setDefault('roleid', $plugin->get_config('roleid'));
64 $mform->addElement('duration', 'enrolperiod', get_string('enrolperiod', 'enrol_paypal'), array('optional' => true, 'defaultunit' => 86400));
65 $mform->setDefault('enrolperiod', $plugin->get_config('enrolperiod'));
66 $mform->addHelpButton('enrolperiod', 'enrolperiod', 'enrol_paypal');
68 $mform->addElement('date_selector', 'enrolstartdate', get_string('enrolstartdate', 'enrol_paypal'), array('optional' => true));
69 $mform->setDefault('enrolstartdate', 0);
70 $mform->addHelpButton('enrolstartdate', 'enrolstartdate', 'enrol_paypal');
72 $mform->addElement('date_selector', 'enrolenddate', get_string('enrolenddate', 'enrol_paypal'), array('optional' => true));
73 $mform->setDefault('enrolenddate', 0);
74 $mform->addHelpButton('enrolenddate', 'enrolenddate', 'enrol_paypal');
76 $mform->addElement('hidden', 'id');
77 $mform->setType('id', PARAM_INT
);
79 $mform->addElement('hidden', 'courseid');
80 $mform->setType('courseid', PARAM_INT
);
82 if (enrol_accessing_via_instance($instance)) {
83 $mform->addElement('static', 'selfwarn', get_string('instanceeditselfwarning', 'core_enrol'), get_string('instanceeditselfwarningtext', 'core_enrol'));
86 $this->add_action_buttons(true, ($instance->id ?
null : get_string('addinstance', 'enrol')));
88 $this->set_data($instance);
91 function validation($data, $files) {
93 $errors = parent
::validation($data, $files);
95 list($instance, $plugin, $context) = $this->_customdata
;
97 if (!empty($data['enrolenddate']) and $data['enrolenddate'] < $data['enrolstartdate']) {
98 $errors['enrolenddate'] = get_string('enrolenddaterror', 'enrol_paypal');
101 $cost = str_replace(get_string('decsep', 'langconfig'), '.', $data['cost']);
102 if (!is_numeric($cost)) {
103 $errors['cost'] = get_string('costerror', 'enrol_paypal');