1: <?php
 2: /**
 3:  * This file contains the cHTMLPasswordbox class.
 4:  *
 5:  * @package Core
 6:  * @subpackage GUI_HTML
 7:  * @version SVN Revision $Rev:$
 8:  *
 9:  * @author Simon Sprankel
10:  * @copyright four for business AG <www.4fb.de>
11:  * @license http://www.contenido.org/license/LIZENZ.txt
12:  * @link http://www.4fb.de
13:  * @link http://www.contenido.org
14:  */
15: 
16: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
17: 
18: /**
19:  * cHTMLPasswordbox class represents a password form field.
20:  *
21:  * @package Core
22:  * @subpackage GUI_HTML
23:  */
24: class cHTMLPasswordbox extends cHTMLFormElement {
25: 
26:     /**
27:      * Constructor.
28:      * Creates an HTML password box.
29:      *
30:      * If no additional parameters are specified, the
31:      * default width is 20 units.
32:      *
33:      * @param string $name Name of the element
34:      * @param string $initvalue Initial value of the box
35:      * @param int $width width of the text box
36:      * @param int $maxlength maximum input length of the box
37:      * @param string $id ID of the element
38:      * @param string $disabled Item disabled flag (non-empty to set disabled)
39:      * @param string $tabindex Tab index for form elements
40:      * @param string $accesskey Key to access the field
41:      * @param string $class the class of this element
42:      */
43:     public function __construct($name, $initvalue = '', $width = '', $maxlength = '', $id = '', $disabled = false, $tabindex = NULL, $accesskey = '', $class = '') {
44:         parent::__construct($name, $id, $disabled, $tabindex, $accesskey);
45:         $this->_tag = 'input';
46:         $this->setValue($initvalue);
47: 
48:         $this->setWidth($width);
49:         $this->setMaxLength($maxlength);
50: 
51:         $this->updateAttribute('type', 'password');
52:         $this->setClass($class);
53:     }
54: 
55:     /**
56:      * Sets the width of the text box.
57:      *
58:      * @param int $width width of the text box
59:      * @return cHTMLPasswordbox $this
60:      */
61:     public function setWidth($width) {
62:         $width = intval($width);
63: 
64:         if ($width <= 0) {
65:             $width = 20;
66:         }
67: 
68:         return $this->updateAttribute('size', $width);
69:     }
70: 
71:     /**
72:      * Sets the maximum input length of the text box.
73:      *
74:      * @param int $maxlen maximum input length
75:      * @return cHTMLPasswordbox $this
76:      */
77:     public function setMaxLength($maxlen) {
78:         $maxlen = intval($maxlen);
79: 
80:         if ($maxlen <= 0) {
81:             return $this->removeAttribute('maxlength');
82:         } else {
83:             return $this->updateAttribute('maxlength', $maxlen);
84:         }
85:     }
86: 
87:     /**
88:      * Sets the initial value of the text box.
89:      *
90:      * @param string $value Initial value
91:      * @return cHTMLPasswordbox $this
92:      */
93:     public function setValue($value) {
94:         return $this->updateAttribute('value', $value);
95:     }
96: 
97: }
98: 
99: