21 defined(
'XOOPS_ROOT_PATH') or die('Restricted access');
33 var $_options = array();
41 var $_value = array();
68 $this->setCaption($caption);
69 $this->setName($name);
71 $this->setValue($value);
73 $this->_delimeter = $delimeter;
74 $this->setFormType(
'checkbox');
83 function getValue($encode =
false)
89 foreach($this->_value as $val) {
90 $value[] = $val ? htmlspecialchars($val, ENT_QUOTES) : $val;
100 function setValue($value)
102 $this->_value = array();
103 if (is_array($value)) {
104 foreach($value as $v) {
105 $this->_value[] = $v;
108 $this->_value[] = $value;
118 function addOption($value, $name =
'')
121 $this->_options[$value] = $name;
123 $this->_options[$value] = $value;
136 $this->addOption($k, $v);
147 function getOptions($encode =
false)
150 return $this->_options;
153 foreach($this->_options as $val => $name) {
154 $value[$encode ? htmlspecialchars($val, ENT_QUOTES) : $val] = ($encode > 1) ? htmlspecialchars($name, ENT_QUOTES) : $name;
165 function getDelimeter($encode =
false)
167 return $encode ? htmlspecialchars(str_replace(
' ',
' ', $this->_delimeter)) : $this->_delimeter;
177 $ele_name = $this->getName();
178 $ele_title = $this->getTitle();
180 $ele_value = $this->getValue();
181 $ele_options = $this->getOptions();
182 $ele_extra = $this->getExtra();
183 $ele_delimeter = empty($this->columns) ? $this->getDelimeter() :
'';
185 if (count($ele_options) > 1 && substr($ele_name, - 2, 2) !=
'[]') {
186 $ele_name = $ele_name .
'[]';
187 $this->setName($ele_name);
190 if (! empty($this->columns)) {
191 $ret .=
'<table><tr>';
195 foreach($ele_options as $value => $name) {
197 if (! empty($this->columns)) {
198 if (
$i % $this->columns == 0) {
204 $ret .=
"<input type='checkbox' name='{$ele_name}' id='{$ele_id}{$id_ele}' title='" . $ele_title .
"' value='" . htmlspecialchars($value, ENT_QUOTES) .
"'";
205 if (count($ele_value) > 0 && in_array($value, $ele_value)) {
206 $ret .=
' checked="checked"';
208 $ret .= $ele_extra .
' />'.
"<label name='xolb_{$ele_name}' for='{$ele_id}{$id_ele}'>" . $name .
"</label>" . $ele_delimeter ;
209 if (! empty($this->columns)) {
211 if (++
$i % $this->columns == 0) {
216 if (! empty($this->columns)) {
217 if ($span =
$i % $this->columns) {
218 $ret .=
'<td colspan="' . ($this->columns - $span) .
'"></td></tr>';
230 function renderValidationJS()
233 if (! empty($this->customValidationCode)) {
234 return implode(NWLINE, $this->customValidationCode);
236 } elseif ($this->isRequired()) {
237 $eltname = $this->getName();
238 $eltcaption = $this->getCaption();
240 $eltmsg = str_replace(
'"',
'\"', stripslashes($eltmsg));
241 return NWLINE .
"var hasChecked = false; var checkBox = myform.elements['{$eltname}']; if (checkBox.length) {for (var i = 0; i < checkBox.length; i++) {if (checkBox[i].checked == true) {hasChecked = true; break;}}}else{if (checkBox.checked == true) {hasChecked = true;}}if (!hasChecked) {window.alert(\"{$eltmsg}\");if (checkBox.length) {checkBox[0].focus();}else{checkBox.focus();}return false;}";