[ Index ]

PHP Cross Reference of moodle-2.8

title

Body

[close]

/enrol/paypal/ -> edit_form.php (source)

   1  <?php
   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   *
  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
  24   */
  25  
  26  defined('MOODLE_INTERNAL') || die();
  27  
  28  require_once($CFG->libdir.'/formslib.php');
  29  
  30  class 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'));
  40          $mform->setType('name', PARAM_TEXT);
  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));
  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));
  50  
  51          $paypalcurrencies = $plugin->get_currencies();
  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'));
  66          $mform->addHelpButton('enrolperiod', 'enrolperiod', 'enrol_paypal');
  67  
  68          $mform->addElement('date_time_selector', 'enrolstartdate', get_string('enrolstartdate', 'enrol_paypal'), array('optional' => true));
  69          $mform->setDefault('enrolstartdate', 0);
  70          $mform->addHelpButton('enrolstartdate', 'enrolstartdate', 'enrol_paypal');
  71  
  72          $mform->addElement('date_time_selector', 'enrolenddate', get_string('enrolenddate', 'enrol_paypal'), array('optional' => true));
  73          $mform->setDefault('enrolenddate', 0);
  74          $mform->addHelpButton('enrolenddate', 'enrolenddate', 'enrol_paypal');
  75  
  76          $mform->addElement('hidden', 'id');
  77          $mform->setType('id', PARAM_INT);
  78  
  79          $mform->addElement('hidden', 'courseid');
  80          $mform->setType('courseid', PARAM_INT);
  81  
  82          if (enrol_accessing_via_instance($instance)) {
  83              $mform->addElement('static', 'selfwarn', get_string('instanceeditselfwarning', 'core_enrol'), get_string('instanceeditselfwarningtext', 'core_enrol'));
  84          }
  85  
  86          $this->add_action_buttons(true, ($instance->id ? null : get_string('addinstance', 'enrol')));
  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  
  97          if (!empty($data['enrolenddate']) and $data['enrolenddate'] < $data['enrolstartdate']) {
  98              $errors['enrolenddate'] = get_string('enrolenddaterror', 'enrol_paypal');
  99          }
 100  
 101          $cost = str_replace(get_string('decsep', 'langconfig'), '.', $data['cost']);
 102          if (!is_numeric($cost)) {
 103              $errors['cost'] = get_string('costerror', 'enrol_paypal');
 104          }
 105  
 106          return $errors;
 107      }
 108  }


Generated: Fri Nov 28 20:29:05 2014 Cross-referenced by PHPXref 0.7.1