MDL-31763 mod_data: Fixed array iteration reference issue
[moodle.git] / enrol / paypal / edit_form.php
blobe2121d54a5bac0ad326d7123112950d5816c4dcc
1 <?php
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.
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/>.
18 /**
19 * Adds new instance of enrol_paypal to specified course
20 * or edits current instance.
22 * @package enrol
23 * @subpackage paypal
24 * @copyright 2010 Petr Skoda {@link http://skodak.org}
25 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
28 defined('MOODLE_INTERNAL') || die();
30 require_once($CFG->libdir.'/formslib.php');
32 class enrol_paypal_edit_form extends moodleform {
34 function definition() {
35 $mform = $this->_form;
37 list($instance, $plugin, $context) = $this->_customdata;
39 $mform->addElement('header', 'header', get_string('pluginname', 'enrol_paypal'));
41 $mform->addElement('text', 'name', get_string('custominstancename', 'enrol'));
43 $options = array(ENROL_INSTANCE_ENABLED => get_string('yes'),
44 ENROL_INSTANCE_DISABLED => get_string('no'));
45 $mform->addElement('select', 'status', get_string('status', 'enrol_paypal'), $options);
46 $mform->setDefault('status', $plugin->get_config('status'));
48 $mform->addElement('text', 'cost', get_string('cost', 'enrol_paypal'), array('size'=>4));
49 $mform->setDefault('cost', $plugin->get_config('cost'));
51 $paypalcurrencies = array('USD' => 'US Dollars',
52 'EUR' => 'Euros',
53 'JPY' => 'Japanese Yen',
54 'GBP' => 'British Pounds',
55 'CAD' => 'Canadian Dollars',
56 'AUD' => 'Australian Dollars'
58 $mform->addElement('select', 'currency', get_string('currency', 'enrol_paypal'), $paypalcurrencies);
59 $mform->setDefault('currency', $plugin->get_config('currency'));
61 if ($instance->id) {
62 $roles = get_default_enrol_roles($context, $instance->roleid);
63 } else {
64 $roles = get_default_enrol_roles($context, $plugin->get_config('roleid'));
66 $mform->addElement('select', 'roleid', get_string('assignrole', 'enrol_paypal'), $roles);
67 $mform->setDefault('roleid', $plugin->get_config('roleid'));
70 $mform->addElement('duration', 'enrolperiod', get_string('enrolperiod', 'enrol_paypal'), array('optional' => true, 'defaultunit' => 86400));
71 $mform->setDefault('enrolperiod', $plugin->get_config('enrolperiod'));
72 $mform->addHelpButton('enrolperiod', 'enrolperiod', 'enrol_paypal');
74 $mform->addElement('date_selector', 'enrolstartdate', get_string('enrolstartdate', 'enrol_paypal'), array('optional' => true));
75 $mform->setDefault('enrolstartdate', 0);
76 $mform->addHelpButton('enrolstartdate', 'enrolstartdate', 'enrol_paypal');
78 $mform->addElement('date_selector', 'enrolenddate', get_string('enrolenddate', 'enrol_paypal'), array('optional' => true));
79 $mform->setDefault('enrolenddate', 0);
80 $mform->addHelpButton('enrolenddate', 'enrolenddate', 'enrol_paypal');
82 $mform->addElement('hidden', 'id');
83 $mform->addElement('hidden', 'courseid');
85 $this->add_action_buttons(true, ($instance->id ? null : get_string('addinstance', 'enrol')));
87 $this->set_data($instance);
90 function validation($data, $files) {
91 global $DB, $CFG;
92 $errors = parent::validation($data, $files);
94 list($instance, $plugin, $context) = $this->_customdata;
96 if ($data['status'] == ENROL_INSTANCE_ENABLED) {
97 if (!empty($data['enrolenddate']) and $data['enrolenddate'] < $data['enrolstartdate']) {
98 $errors['enrolenddate'] = get_string('enrolenddaterror', 'enrol_paypal');
101 if (!is_numeric($data['cost'])) {
102 $errors['cost'] = get_string('costerror', 'enrol_paypal');
107 return $errors;