PageRenderTime 44ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/enrol/paypal/edit_form.php

https://bitbucket.org/synergylearning/campusconnect
PHP | 108 lines | 60 code | 26 blank | 22 comment | 6 complexity | a993ffa51ab9a2cada3d81815d41f752 MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, LGPL-3.0, GPL-3.0, LGPL-2.1, Apache-2.0, BSD-3-Clause, AGPL-3.0
  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. * Adds new instance of enrol_paypal to specified course
  18. * or edits current instance.
  19. *
  20. * @package enrol_paypal
  21. * @copyright 2010 Petr Skoda {@link http://skodak.org}
  22. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23. */
  24. defined('MOODLE_INTERNAL') || die();
  25. require_once($CFG->libdir.'/formslib.php');
  26. class enrol_paypal_edit_form extends moodleform {
  27. function definition() {
  28. $mform = $this->_form;
  29. list($instance, $plugin, $context) = $this->_customdata;
  30. $mform->addElement('header', 'header', get_string('pluginname', 'enrol_paypal'));
  31. $mform->addElement('text', 'name', get_string('custominstancename', 'enrol'));
  32. $mform->setType('name', PARAM_TEXT);
  33. $options = array(ENROL_INSTANCE_ENABLED => get_string('yes'),
  34. ENROL_INSTANCE_DISABLED => get_string('no'));
  35. $mform->addElement('select', 'status', get_string('status', 'enrol_paypal'), $options);
  36. $mform->setDefault('status', $plugin->get_config('status'));
  37. $mform->addElement('text', 'cost', get_string('cost', 'enrol_paypal'), array('size'=>4));
  38. $mform->setType('cost', PARAM_RAW); // Use unformat_float to get real value.
  39. $mform->setDefault('cost', format_float($plugin->get_config('cost'), 2, true));
  40. $paypalcurrencies = $plugin->get_currencies();
  41. $mform->addElement('select', 'currency', get_string('currency', 'enrol_paypal'), $paypalcurrencies);
  42. $mform->setDefault('currency', $plugin->get_config('currency'));
  43. if ($instance->id) {
  44. $roles = get_default_enrol_roles($context, $instance->roleid);
  45. } else {
  46. $roles = get_default_enrol_roles($context, $plugin->get_config('roleid'));
  47. }
  48. $mform->addElement('select', 'roleid', get_string('assignrole', 'enrol_paypal'), $roles);
  49. $mform->setDefault('roleid', $plugin->get_config('roleid'));
  50. $mform->addElement('duration', 'enrolperiod', get_string('enrolperiod', 'enrol_paypal'), array('optional' => true, 'defaultunit' => 86400));
  51. $mform->setDefault('enrolperiod', $plugin->get_config('enrolperiod'));
  52. $mform->addHelpButton('enrolperiod', 'enrolperiod', 'enrol_paypal');
  53. $mform->addElement('date_selector', 'enrolstartdate', get_string('enrolstartdate', 'enrol_paypal'), array('optional' => true));
  54. $mform->setDefault('enrolstartdate', 0);
  55. $mform->addHelpButton('enrolstartdate', 'enrolstartdate', 'enrol_paypal');
  56. $mform->addElement('date_selector', 'enrolenddate', get_string('enrolenddate', 'enrol_paypal'), array('optional' => true));
  57. $mform->setDefault('enrolenddate', 0);
  58. $mform->addHelpButton('enrolenddate', 'enrolenddate', 'enrol_paypal');
  59. $mform->addElement('hidden', 'id');
  60. $mform->setType('id', PARAM_INT);
  61. $mform->addElement('hidden', 'courseid');
  62. $mform->setType('courseid', PARAM_INT);
  63. if (enrol_accessing_via_instance($instance)) {
  64. $mform->addElement('static', 'selfwarn', get_string('instanceeditselfwarning', 'core_enrol'), get_string('instanceeditselfwarningtext', 'core_enrol'));
  65. }
  66. $this->add_action_buttons(true, ($instance->id ? null : get_string('addinstance', 'enrol')));
  67. $this->set_data($instance);
  68. }
  69. function validation($data, $files) {
  70. global $DB, $CFG;
  71. $errors = parent::validation($data, $files);
  72. list($instance, $plugin, $context) = $this->_customdata;
  73. if (!empty($data['enrolenddate']) and $data['enrolenddate'] < $data['enrolstartdate']) {
  74. $errors['enrolenddate'] = get_string('enrolenddaterror', 'enrol_paypal');
  75. }
  76. $cost = str_replace(get_string('decsep', 'langconfig'), '.', $data['cost']);
  77. if (!is_numeric($cost)) {
  78. $errors['cost'] = get_string('costerror', 'enrol_paypal');
  79. }
  80. return $errors;
  81. }
  82. }