Proyectos de Subversion Moodle

Rev

Rev 1 | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 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
 
1441 ariadna 17
 
18
defined('MOODLE_INTERNAL') || die();
19
 
20
require_once("$CFG->libdir/formslib.php");
21
 
1 efrain 22
/**
23
 * Guest access plugin implementation.
24
 *
1441 ariadna 25
 * @deprecated since Moodle 5.0 - please use {@see enrol_guest\form\enrol_form}
26
 *
1 efrain 27
 * @package    enrol_guest
28
 * @copyright  2010 Petr Skoda  {@link http://skodak.org}
29
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
30
 */
1441 ariadna 31
#[\core\attribute\deprecated(replacement: enrol_guest\form\enrol_form::class, since: '5.0', reason: 'Now a dynamic form is used')]
1 efrain 32
class enrol_guest_enrol_form extends moodleform {
33
    protected $instance;
34
 
1441 ariadna 35
    /**
36
     * Constructor
37
     *
38
     * @param mixed $action
39
     * @param mixed $customdata
40
     * @param string $method
41
     * @param string $target
42
     * @param mixed $attributes
43
     * @param bool $editable
44
     * @param array $ajaxformdata
45
     */
46
    public function __construct($action=null, $customdata=null, $method='post', $target='', $attributes=null, $editable=true,
47
                                $ajaxformdata=null) {
48
        \core\deprecation::emit_deprecation([$this, __FUNCTION__]);
49
        parent::__construct($action, $customdata, $method, $target, $attributes, $editable, $ajaxformdata);
50
    }
51
 
1 efrain 52
    public function definition() {
53
        $mform = $this->_form;
54
        $instance = $this->_customdata;
55
        $this->instance = $instance;
56
        $plugin = enrol_get_plugin('guest');
57
 
58
        $heading = $plugin->get_instance_name($instance);
59
        $mform->addElement('header', 'guestheader', $heading);
60
 
61
        $mform->addElement('password', 'guestpassword', get_string('password', 'enrol_guest'));
62
 
63
        $this->add_action_buttons(false, get_string('submit'));
64
 
65
        $mform->addElement('hidden', 'id');
66
        $mform->setType('id', PARAM_INT);
67
        $mform->setDefault('id', $instance->courseid);
68
 
69
        $mform->addElement('hidden', 'instance');
70
        $mform->setType('instance', PARAM_INT);
71
        $mform->setDefault('instance', $instance->id);
72
    }
73
 
74
    public function validation($data, $files) {
75
        global $DB, $CFG;
76
 
77
        $errors = parent::validation($data, $files);
78
        $instance = $this->instance;
79
 
80
        if ($instance->password !== '') {
81
            if ($data['guestpassword'] !== $instance->password) {
82
                $plugin = enrol_get_plugin('guest');
83
                if ($plugin->get_config('showhint')) {
84
                    $hint = core_text::substr($instance->password, 0, 1);
85
                    $errors['guestpassword'] = get_string('passwordinvalidhint', 'enrol_guest', $hint);
86
                } else {
87
                    $errors['guestpassword'] = get_string('passwordinvalid', 'enrol_guest');
88
                }
89
            }
90
        }
91
 
92
        return $errors;
93
    }
94
}