Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/enrol/paypal/edit_form.php
Go to the documentation of this file.
00001 <?php
00002 
00003 // This file is part of Moodle - http://moodle.org/
00004 //
00005 // Moodle is free software: you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation, either version 3 of the License, or
00008 // (at your option) any later version.
00009 //
00010 // Moodle is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
00017 
00028 defined('MOODLE_INTERNAL') || die();
00029 
00030 require_once($CFG->libdir.'/formslib.php');
00031 
00032 class enrol_paypal_edit_form extends moodleform {
00033 
00034     function definition() {
00035         $mform = $this->_form;
00036 
00037         list($instance, $plugin, $context) = $this->_customdata;
00038 
00039         $mform->addElement('header', 'header', get_string('pluginname', 'enrol_paypal'));
00040 
00041         $mform->addElement('text', 'name', get_string('custominstancename', 'enrol'));
00042 
00043         $options = array(ENROL_INSTANCE_ENABLED  => get_string('yes'),
00044                          ENROL_INSTANCE_DISABLED => get_string('no'));
00045         $mform->addElement('select', 'status', get_string('status', 'enrol_paypal'), $options);
00046         $mform->setDefault('status', $plugin->get_config('status'));
00047 
00048         $mform->addElement('text', 'cost', get_string('cost', 'enrol_paypal'), array('size'=>4));
00049         $mform->setDefault('cost', $plugin->get_config('cost'));
00050 
00051         $paypalcurrencies = array('USD' => 'US Dollars',
00052                                   'EUR' => 'Euros',
00053                                   'JPY' => 'Japanese Yen',
00054                                   'GBP' => 'British Pounds',
00055                                   'CAD' => 'Canadian Dollars',
00056                                   'AUD' => 'Australian Dollars'
00057                                  );
00058         $mform->addElement('select', 'currency', get_string('currency', 'enrol_paypal'), $paypalcurrencies);
00059         $mform->setDefault('currency', $plugin->get_config('currency'));
00060 
00061         if ($instance->id) {
00062             $roles = get_default_enrol_roles($context, $instance->roleid);
00063         } else {
00064             $roles = get_default_enrol_roles($context, $plugin->get_config('roleid'));
00065         }
00066         $mform->addElement('select', 'roleid', get_string('assignrole', 'enrol_paypal'), $roles);
00067         $mform->setDefault('roleid', $plugin->get_config('roleid'));
00068 
00069 
00070         $mform->addElement('duration', 'enrolperiod', get_string('enrolperiod', 'enrol_paypal'), array('optional' => true, 'defaultunit' => 86400));
00071         $mform->setDefault('enrolperiod', $plugin->get_config('enrolperiod'));
00072         $mform->addHelpButton('enrolperiod', 'enrolperiod', 'enrol_paypal');
00073 
00074         $mform->addElement('date_selector', 'enrolstartdate', get_string('enrolstartdate', 'enrol_paypal'), array('optional' => true));
00075         $mform->setDefault('enrolstartdate', 0);
00076         $mform->addHelpButton('enrolstartdate', 'enrolstartdate', 'enrol_paypal');
00077 
00078         $mform->addElement('date_selector', 'enrolenddate', get_string('enrolenddate', 'enrol_paypal'), array('optional' => true));
00079         $mform->setDefault('enrolenddate', 0);
00080         $mform->addHelpButton('enrolenddate', 'enrolenddate', 'enrol_paypal');
00081 
00082         $mform->addElement('hidden', 'id');
00083         $mform->addElement('hidden', 'courseid');
00084 
00085         $this->add_action_buttons(true, ($instance->id ? null : get_string('addinstance', 'enrol')));
00086 
00087         $this->set_data($instance);
00088     }
00089 
00090     function validation($data, $files) {
00091         global $DB, $CFG;
00092         $errors = parent::validation($data, $files);
00093 
00094         list($instance, $plugin, $context) = $this->_customdata;
00095 
00096         if ($data['status'] == ENROL_INSTANCE_ENABLED) {
00097             if (!empty($data['enrolenddate']) and $data['enrolenddate'] < $data['enrolstartdate']) {
00098                 $errors['enrolenddate'] = get_string('enrolenddaterror', 'enrol_paypal');
00099             }
00100 
00101             if (!is_numeric($data['cost'])) {
00102                 $errors['cost'] = get_string('costerror', 'enrol_paypal');
00103 
00104             }
00105         }
00106 
00107         return $errors;
00108     }
00109 }
 All Data Structures Namespaces Files Functions Variables Enumerations