|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 // This file is part of Moodle - http://moodle.org/ 00003 // 00004 // Moodle is free software: you can redistribute it and/or modify 00005 // it under the terms of the GNU General Public License as published by 00006 // the Free Software Foundation, either version 3 of the License, or 00007 // (at your option) any later version. 00008 // 00009 // Moodle is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 // GNU General Public License for more details. 00013 // 00014 // You should have received a copy of the GNU General Public License 00015 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 00016 00026 defined('MOODLE_INTERNAL') || die(); 00027 00028 require_once("$CFG->libdir/formslib.php"); 00029 00030 class enrol_guest_enrol_form extends moodleform { 00031 protected $instance; 00032 00033 public function definition() { 00034 $mform = $this->_form; 00035 $instance = $this->_customdata; 00036 $this->instance = $instance; 00037 $plugin = enrol_get_plugin('guest'); 00038 00039 $heading = $plugin->get_instance_name($instance); 00040 $mform->addElement('header', 'guestheader', $heading); 00041 00042 $mform->addElement('passwordunmask', 'guestpassword', get_string('password', 'enrol_guest')); 00043 00044 $this->add_action_buttons(false, get_string('submit')); 00045 00046 $mform->addElement('hidden', 'id'); 00047 $mform->setType('id', PARAM_INT); 00048 $mform->setDefault('id', $instance->courseid); 00049 00050 $mform->addElement('hidden', 'instance'); 00051 $mform->setType('instance', PARAM_INT); 00052 $mform->setDefault('instance', $instance->id); 00053 } 00054 00055 public function validation($data, $files) { 00056 global $DB, $CFG; 00057 00058 $errors = parent::validation($data, $files); 00059 $instance = $this->instance; 00060 00061 if ($instance->password !== '') { 00062 if ($data['guestpassword'] !== $instance->password) { 00063 $plugin = enrol_get_plugin('guest'); 00064 if ($plugin->get_config('showhint')) { 00065 $textlib = textlib_get_instance(); 00066 $hint = $textlib->substr($instance->password, 0, 1); 00067 $errors['guestpassword'] = get_string('passwordinvalidhint', 'enrol_guest', $hint); 00068 } else { 00069 $errors['guestpassword'] = get_string('passwordinvalid', 'enrol_guest'); 00070 } 00071 } 00072 } 00073 00074 return $errors; 00075 } 00076 }