[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/lib/form/ -> passwordunmask.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  /**
  19   * Password type form element with unmask option
  20   *
  21   * Contains HTML class for a password type element with unmask option
  22   *
  23   * @package   core_form
  24   * @copyright 2009 Petr Skoda
  25   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  26   */
  27  
  28  if (!defined('MOODLE_INTERNAL')) {
  29      die('Direct access to this script is forbidden.');    ///  It must be included from a Moodle page
  30  }
  31  
  32  global $CFG;
  33  require_once($CFG->libdir.'/form/password.php');
  34  
  35  /**
  36   * Password type form element with unmask option
  37   *
  38   * HTML class for a password type element with unmask option
  39   *
  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
  44   */
  45  class MoodleQuickForm_passwordunmask extends MoodleQuickForm_password {
  46      /**
  47       * constructor
  48       *
  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
  53       */
  54      public function __construct($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" ';
  64              }
  65          }
  66  
  67          parent::__construct($elementName, $elementLabel, $attributes);
  68      }
  69  
  70      /**
  71       * Old syntax of class constructor. Deprecated in PHP7.
  72       *
  73       * @deprecated since Moodle 3.1
  74       */
  75      public function MoodleQuickForm_passwordunmask($elementName=null, $elementLabel=null, $attributes=null) {
  76          debugging('Use of class name as constructor is deprecated', DEBUG_DEVELOPER);
  77          self::__construct($elementName, $elementLabel, $attributes);
  78      }
  79  
  80      /**
  81       * Returns HTML for password form element.
  82       *
  83       * @return string
  84       */
  85      function toHtml() {
  86          global $PAGE;
  87  
  88          if ($this->_flagFrozen) {
  89              return $this->getFrozenHtml();
  90          } else {
  91              $unmask = get_string('unmaskpassword', 'form');
  92              //Pass id of the element, so that unmask checkbox can be attached.
  93              $attributes = array('formid' => $this->getAttribute('id'),
  94                  'checkboxlabel' => $unmask,
  95                  'checkboxname' => $this->getAttribute('name'));
  96              $PAGE->requires->yui_module('moodle-form-passwordunmask', 'M.form.passwordunmask',
  97                      array($attributes));
  98              return $this->_getTabs() . '<input' . $this->_getAttrString($this->_attributes) . ' />';
  99          }
 100      }
 101  
 102  }


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1