ui.passwordwidget.class.inc.php 4.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. // Copyright (C) 2010 Combodo SARL
  3. //
  4. // This program 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; version 3 of the License.
  7. //
  8. // This program is distributed in the hope that it will be useful,
  9. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. // GNU General Public License for more details.
  12. //
  13. // You should have received a copy of the GNU General Public License
  14. // along with this program; if not, write to the Free Software
  15. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16. /**
  17. * Class UIPasswordWidget
  18. * UI wdiget for displaying and editing one-way encrypted passwords
  19. *
  20. * @author Erwan Taloc <erwan.taloc@combodo.com>
  21. * @author Romain Quetiez <romain.quetiez@combodo.com>
  22. * @author Denis Flaven <denis.flaven@combodo.com>
  23. * @license http://www.opensource.org/licenses/gpl-3.0.html LGPL
  24. */
  25. require_once(APPROOT.'/application/webpage.class.inc.php');
  26. require_once(APPROOT.'/application/displayblock.class.inc.php');
  27. class UIPasswordWidget
  28. {
  29. protected static $iWidgetIndex = 0;
  30. protected $sAttCode;
  31. protected $sNameSuffix;
  32. protected $iId;
  33. public function __construct($sAttCode, $iInputId, $sNameSuffix = '')
  34. {
  35. self::$iWidgetIndex++;
  36. $this->sAttCode = $sAttCode;
  37. $this->sNameSuffix = $sNameSuffix;
  38. $this->iId = $iInputId;
  39. }
  40. /**
  41. * Get the HTML fragment corresponding to the linkset editing widget
  42. * @param WebPage $oP The web page used for all the output
  43. * @param Hash $aArgs Extra context arguments
  44. * @return string The HTML fragment to be inserted into the page
  45. */
  46. public function Display(WebPage $oPage, $aArgs = array())
  47. {
  48. $sCode = $this->sAttCode.$this->sNameSuffix;
  49. $iWidgetIndex = self::$iWidgetIndex;
  50. $sPasswordValue = utils::ReadPostedParam("attr_{$sCode}[value]", '*****', 'raw_data');
  51. $sConfirmPasswordValue = utils::ReadPostedParam("attr_{$sCode}[confirm]", '*****', 'raw_data');
  52. $sChangedValue = (($sPasswordValue != '*****') || ($sConfirmPasswordValue != '*****')) ? 1 : 0;
  53. $sHtmlValue = '';
  54. $sHtmlValue = '<input type="password" maxlength="255" name="attr_'.$sCode.'[value]" id="'.$this->iId.'" value="'.htmlentities($sPasswordValue, ENT_QUOTES, 'UTF-8').'"/>&nbsp;<span class="form_validation" id="v_'.$this->iId.'"></span><br/>';
  55. $sHtmlValue .= '<input type="password" maxlength="255" id="'.$this->iId.'_confirm" value="'.htmlentities($sConfirmPasswordValue, ENT_QUOTES, 'UTF-8').'" name="attr_'.$sCode.'[confirm]"/> '.Dict::S('UI:PasswordConfirm').' <input id="'.$this->iId.'_reset" type="button" value="'.Dict::S('UI:Button:ResetPassword').'" onClick="ResetPwd(\''.$this->iId.'\');">';
  56. $sHtmlValue .= '<input type="hidden" id="'.$this->iId.'_changed" name="attr_'.$sCode.'[changed]" value="'.$sChangedValue.'"/>';
  57. $oPage->add_ready_script("$('#$this->iId').bind('keyup change', function(evt) { return PasswordFieldChanged('$this->iId') } );"); // Bind to a custom event: validate
  58. $oPage->add_ready_script("$('#$this->iId').bind('keyup change validate', function(evt, sFormId) { return ValidatePasswordField('$this->iId', sFormId) } );"); // Bind to a custom event: validate
  59. $oPage->add_ready_script("$('#{$this->iId}_confirm').bind('keyup change', function(evt, sFormId) { return ValidatePasswordField('$this->iId', sFormId) } );"); // Bind to a custom event: validate
  60. $oPage->add_ready_script("$('#{$this->iId}').bind('update', function(evt, sFormId)
  61. {
  62. if ($(this).attr('disabled'))
  63. {
  64. $('#{$this->iId}_confirm').attr('disabled', 'disabled');
  65. $('#{$this->iId}_changed').attr('disabled', 'disabled');
  66. $('#{$this->iId}_reset').attr('disabled', 'disabled');
  67. }
  68. else
  69. {
  70. $('#{$this->iId}_confirm').removeAttr('disabled');
  71. $('#{$this->iId}_changed').removeAttr('disabled');
  72. $('#{$this->iId}_reset').removeAttr('disabled');
  73. }
  74. }
  75. );"); // Bind to a custom event: update to handle enabling/disabling
  76. return $sHtmlValue;
  77. }
  78. }
  79. ?>