1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace XoopsModules\Extcal; |
4
|
|
|
|
5
|
|
|
\xoops_load('XoopsForm'); |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Form that will output as a theme-enabled HTML table. |
9
|
|
|
* |
10
|
|
|
* Also adds JavaScript to validate required fields |
11
|
|
|
*/ |
12
|
|
|
class TableForm extends \XoopsForm |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* ad the balise html "table" to render. |
16
|
|
|
* |
17
|
|
|
* @var bool|string |
18
|
|
|
*/ |
19
|
|
|
public $_addBaliseTable = ''; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Gets the "value" attribute of a form element. |
23
|
|
|
* |
24
|
|
|
* @param $addBaliseTable |
25
|
|
|
* |
26
|
|
|
* @return string the "value" attribute assigned to a form element, null if not set |
27
|
|
|
* @internal param bool $encode To sanitizer the text? |
28
|
|
|
* |
29
|
|
|
* @internal param string $name the "name" attribute of a form element |
30
|
|
|
*/ |
31
|
|
|
public function setAddBaliseTable($addBaliseTable) |
32
|
|
|
{ |
33
|
|
|
$this->_addBaliseTable = $addBaliseTable; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* gets the "value" attribute of all form elements. |
38
|
|
|
* |
39
|
|
|
* @return bool|string array of name/value pairs assigned to form elements |
40
|
|
|
* @internal param bool $encode To sanitizer the text? |
41
|
|
|
* |
42
|
|
|
*/ |
43
|
|
|
public function getAddBaliseTable() |
44
|
|
|
{ |
45
|
|
|
return $this->_addBaliseTable; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Insert an empty row in the table to serve as a seperator. |
50
|
|
|
* |
51
|
|
|
* @param string $extra HTML to be displayed in the empty row. |
52
|
|
|
* @param string $class CSS class name for <td> tag |
53
|
|
|
*/ |
54
|
|
|
public function insertBreak($extra = '', $class = '') |
55
|
|
|
{ |
56
|
|
|
$class = ('' != $class) ? " class='" . \preg_replace('/[^A-Za-z0-9\s\s_-]/i', '', $class) . "'" : ''; |
57
|
|
|
// Fix for $extra tag not showing |
58
|
|
|
if ($extra) { |
59
|
|
|
$extra = '<tr><td colspan="2" ' . $class . '>' . $extra . '</td></tr>'; |
60
|
|
|
$this->addElement($extra); |
61
|
|
|
} else { |
62
|
|
|
$extra = '<tr><td colspan="2" ' . $class . '> </td></tr>'; |
63
|
|
|
$this->addElement($extra); |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* create HTML to output the form as a theme-enabled table with validation. |
69
|
|
|
* |
70
|
|
|
* YOU SHOULD AVOID TO USE THE FOLLOWING Nocolspan METHOD, IT WILL BE REMOVED |
71
|
|
|
* |
72
|
|
|
* To use the noColspan simply use the following example: |
73
|
|
|
* |
74
|
|
|
* $colspan = new \XoopsFormDhtmlTextArea( '', 'key', $value, '100%', '100%' ); |
75
|
|
|
* $colspan->setNocolspan(); |
76
|
|
|
* $form->addElement( $colspan ); |
77
|
|
|
* |
78
|
|
|
* @return string |
79
|
|
|
*/ |
80
|
|
|
public function render() |
81
|
|
|
{ |
82
|
|
|
$addBaliseTable = $this->_addBaliseTable; |
83
|
|
|
$title = $this->getTitle(); |
84
|
|
|
$ret = ''; |
85
|
|
|
|
86
|
|
|
if ($addBaliseTable) { |
87
|
|
|
$ret .= '<table width="100%" class="outer" cellspacing="1"> '; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
if ('' != $title) { |
91
|
|
|
$ret .= '<tr><th colspan="2">' . $title . '</th></tr>'; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
$hidden = ''; |
95
|
|
|
$class = 'even'; |
96
|
|
|
foreach ($this->getElements() as $ele) { |
97
|
|
|
if (!\is_object($ele)) { |
98
|
|
|
$ret .= $ele; |
99
|
|
|
} elseif (!$ele->isHidden()) { |
100
|
|
|
if (!$ele->getNocolspan()) { |
|
|
|
|
101
|
|
|
$ret .= '<tr valign="top" align="left"><td class="head">'; |
102
|
|
|
if ('' != ($caption = $ele->getCaption())) { |
103
|
|
|
$ret .= '<div class="xoops-form-element-caption' . ($ele->isRequired() ? '-required' : '') . '">'; |
104
|
|
|
$ret .= '<span class="caption-text">' . $caption . '</span>'; |
105
|
|
|
$ret .= '<span class="caption-marker">*</span>'; |
106
|
|
|
$ret .= '</div>'; |
107
|
|
|
} |
108
|
|
|
if ('' != ($desc = $ele->getDescription())) { |
109
|
|
|
$ret .= '<div class="xoops-form-element-help">' . $desc . '</div>'; |
110
|
|
|
} |
111
|
|
|
$ret .= '</td><td class="' . $class . '">' . $ele->render() . '</td></tr>' . NWLINE; |
|
|
|
|
112
|
|
|
} else { |
113
|
|
|
$ret .= '<tr valign="top" align="left"><td class="head" colspan="2">'; |
114
|
|
|
if ('' != ($caption = $ele->getCaption())) { |
115
|
|
|
$ret .= '<div class="xoops-form-element-caption' . ($ele->isRequired() ? '-required' : '') . '">'; |
116
|
|
|
$ret .= '<span class="caption-text">' . $caption . '</span>'; |
117
|
|
|
$ret .= '<span class="caption-marker">*</span>'; |
118
|
|
|
$ret .= '</div>'; |
119
|
|
|
} |
120
|
|
|
$ret .= '</td></tr><tr valign="top" align="left"><td class="' . $class . '" colspan="2">' . $ele->render() . '</td></tr>'; |
|
|
|
|
121
|
|
|
} |
122
|
|
|
} else { |
123
|
|
|
$hidden .= $ele->render(); |
|
|
|
|
124
|
|
|
} |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
if ($addBaliseTable) { |
128
|
|
|
$ret .= '</table>'; |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
$ret .= NWLINE . ' ' . $hidden . NWLINE; |
132
|
|
|
|
133
|
|
|
return $ret; |
134
|
|
|
} |
135
|
|
|
} // fin de la classe |
136
|
|
|
|
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.