ui.passwordwidget.class.inc.php 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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('../application/webpage.class.inc.php');
  26. require_once('../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. $sHtmlValue = '';
  51. $sHtmlValue = '<input type="password" maxlength="255" name="attr_'.$sCode.'" id="'.$this->iId.'" value="*****"/>&nbsp;<span id="v_'.$this->iId.'"></span><br/>';
  52. $sHtmlValue .= '<input type="password" maxlength="255" id="'.$this->iId.'_confirm" value="*****"/> '.Dict::S('UI:PasswordConfirm').' <input type="button" value="'.Dict::S('UI:Button:ResetPassword').'" onClick="ResetPwd(\''.$this->iId.'\');">';
  53. $sHtmlValue .= '<input type="hidden" id="'.$this->iId.'_changed" name="attr_'.$sCode.'_changed" value="0"/>';
  54. $oPage->add_ready_script("$('#$this->iId').bind('keyup change', function(evt) { return PasswordFieldChanged('$this->iId') } );"); // Bind to a custom event: validate
  55. $oPage->add_ready_script("$('#$this->iId').bind('keyup change', function(evt) { return PasswordFieldChanged('$this->iId') } );"); // Bind to a custom event: validate
  56. $oPage->add_ready_script("$('#$this->iId').bind('keyup change validate', function(evt, sFormId) { return ValidatePasswordField('$this->iId', sFormId) } );"); // Bind to a custom event: validate
  57. $oPage->add_ready_script("$('#{$this->iId}_confirm').bind('keyup change', function(evt, sFormId) { return ValidatePasswordField('$this->iId', sFormId) } );"); // Bind to a custom event: validate
  58. return $sHtmlValue;
  59. }
  60. }
  61. ?>