MDL-39888 mnet: Removal of an old sql statement invloving the mdl_log table.
[moodle.git] / lib / form / passwordunmask.php
blob15bd4bc35d27a1285fd02052a6d777be73b9fa09
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.
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/>.
18 /**
19 * Password type form element with unmask option
21 * Contains HTML class for a password type element with unmask option
23 * @package core_form
24 * @copyright 2009 Petr Skoda
25 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
28 if (!defined('MOODLE_INTERNAL')) {
29 die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
32 global $CFG;
33 require_once($CFG->libdir.'/form/password.php');
35 /**
36 * Password type form element with unmask option
38 * HTML class for a password type element with unmask option
40 * @package core_form
41 * @category form
42 * @copyright 2009 Petr Skoda {@link http://skodak.org}
43 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
45 class MoodleQuickForm_passwordunmask extends MoodleQuickForm_password {
46 /**
47 * constructor
49 * @param string $elementName (optional) name of the password element
50 * @param string $elementLabel (optional) label for password element
51 * @param mixed $attributes (optional) Either a typical HTML attribute string
52 * or an associative array
54 function MoodleQuickForm_passwordunmask($elementName=null, $elementLabel=null, $attributes=null) {
55 global $CFG;
56 // no standard mform in moodle should allow autocomplete of passwords
57 if (empty($attributes)) {
58 $attributes = array('autocomplete'=>'off');
59 } else if (is_array($attributes)) {
60 $attributes['autocomplete'] = 'off';
61 } else {
62 if (strpos($attributes, 'autocomplete') === false) {
63 $attributes .= ' autocomplete="off" ';
67 parent::MoodleQuickForm_password($elementName, $elementLabel, $attributes);
70 /**
71 * Returns HTML for password form element.
73 * @return string
75 function toHtml() {
76 global $PAGE;
78 if ($this->_flagFrozen) {
79 return $this->getFrozenHtml();
80 } else {
81 $unmask = get_string('unmaskpassword', 'form');
82 //Pass id of the element, so that unmask checkbox can be attached.
83 $attributes = array('formid' => $this->getAttribute('id'),
84 'checkboxlabel' => $unmask,
85 'checkboxname' => $this->getAttribute('name'));
86 $PAGE->requires->yui_module('moodle-form-passwordunmask', 'M.form.passwordunmask',
87 array($attributes));
88 return $this->_getTabs() . '<input' . $this->_getAttrString($this->_attributes) . ' />';