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