18 require_once SQ_INCLUDE_PATH.
'/asset_attribute.inc';
62 if (!isset($this->_params[
'options'])) {
63 $this->_params[
'options'] = Array();
65 if (!isset($this->_params[
'multiple'])) {
66 $this->_params[
'multiple'] = FALSE;
68 if (!isset($this->_params[
'allow_empty'])) {
69 $this->_params[
'allow_empty'] = TRUE;
71 if (!isset($this->_params[
'allow_other'])) {
72 $this->_params[
'allow_other'] = FALSE;
76 $this->_edit_params[
'style'] =
'list';
77 $this->_edit_params[
'type'] =
'table';
78 $this->_edit_params[
'height'] =
'';
79 $this->_edit_params[
'columns'] =
'1';
80 $this->_edit_params[
'empty_text'] =
'';
81 $this->_edit_params[
'extras'] =
'';
97 if (!parent::setEditParams($node))
return FALSE;
99 foreach (Array(
'style',
'height',
'columns',
'empty_text',
'extras') as $param) {
100 if (isset($node->attributes()->{$param})) {
101 $this->_edit_params[$param] = (string)$node->attributes()->{$param};
119 function paintEditParams($prefix, $write_access=FALSE)
121 $searchStyles = Array();
122 $searchStyles[
'list'] =
'List';
123 $searchStyles[
'checkbox'] =
'Checkbox';
124 $searchTypes[
'table'] =
'Table';
125 $searchTypes[
'list'] =
'Unordered List';
127 if (!empty($this->name)) {
128 echo
'<b>Selection Attribute " '.ucwords(str_replace(
'_',
' ', $this->name)).
' " ('.$this->name.
')</b><br />';
131 <table
class=
"sq-backend-table">
133 <td
class=
"sq-backend-section-heading" style=
"width: 100px;"><?php echo translate(
'style'); ?></td>
134 <td
class=
"sq-backend-table-cell">
137 combo_box($prefix.
'_style', $searchStyles, FALSE, $this->_edit_params[
'style']);
139 echo $this->_edit_params[
'style'];
145 <td
class=
"sq-backend-section-heading" style=
"width: 100px;">Type</td>
146 <td
class=
"sq-backend-table-cell">
149 combo_box($prefix.
'_type', $searchTypes, FALSE, $this->_edit_params[
'type']);
151 echo $this->_edit_params[
'type'];
157 <td
class=
"sq-backend-section-heading" style=
"width: 100px;"><?php echo translate(
'height'); ?></td>
158 <td
class=
"sq-backend-table-cell">
161 text_box($prefix.
'_height', $this->_edit_params[
'height']);
163 echo $this->_edit_params[
'height'];
169 <td
class=
"sq-backend-section-heading" style=
"width: 100px;"><?php echo translate(
'columns'); ?></td>
170 <td
class=
"sq-backend-table-cell">
173 text_box($prefix.
'_columns', $this->_edit_params[
'columns']);
175 echo $this->_edit_params[
'columns'];
181 if ($this->_params[
'allow_empty']) {
184 <td
class=
"sq-backend-section-heading" style=
"width: 100px;"><?php echo translate(
'empty_text'); ?></td>
185 <td
class=
"sq-backend-table-cell">
188 text_box($prefix.
'_empty', $this->_edit_params[
'empty_text']);
190 echo $this->_edit_params[
'empty_text'];
212 function processEditParams($prefix)
214 if (!empty($_POST[$prefix.
'_style'])) {
215 $this->_edit_params[
'style'] = $_POST[$prefix.
'_style'];
218 if (!empty($_POST[$prefix.
'_type'])) {
219 $this->_edit_params[
'type'] = $_POST[$prefix.
'_type'];
222 if (!empty($_POST[$prefix.
'_height'])) {
223 $this->_edit_params[
'height'] = $_POST[$prefix.
'_height'];
226 if (!empty($_POST[$prefix.
'_columns'])) {
227 $this->_edit_params[
'columns'] = $_POST[$prefix.
'_columns'];
230 if (!empty($_POST[$prefix.
'_empty'])) {
231 $this->_edit_params[
'empty_text'] = $_POST[$prefix.
'_empty'];
235 $values[
'style'] = $this->_edit_params[
'style'];
236 $values[
'type'] = $this->_edit_params[
'type'];
237 $values[
'height'] = $this->_edit_params[
'height'];
238 $values[
'columns'] = $this->_edit_params[
'columns'];
239 $values[
'empty_text'] = $this->_edit_params[
'empty_text'];
240 $values[
'extras'] = $this->_edit_params[
'extras'];
255 function _ar2str($array)
257 return implode(
'|', array_intersect(array_keys($this->_params[
'options']), $array));
270 function _str2ar($string)
272 return array_intersect(array_keys($this->_params[
'options']), explode(
'|', $string));
286 function paint($prefix, $read_only=FALSE)
288 $options = $this->_params[
'options'];
289 if ($this->_params[
'allow_empty'] && !$this->_params[
'multiple']) {
290 if (empty($this->_edit_params[
'empty_text'])) {
291 $this->_edit_params[
'empty_text'] =
'-- Leave Empty --';
293 $options = Array(
'' => $this->_edit_params[
'empty_text']) + $options;
295 if (!empty($this->_params[
'multiple']) && !is_array($this->value)) {
296 $value = $this->_str2ar($this->value);
298 $value = $this->value;
302 if (empty($this->_params[
'multiple'])) {
303 if (!isset($options[$value])) {
305 if ($this->_params[
'allow_other']) {
306 echo translate(
'other').
': '.$value;
310 $value = $this->_str2ar($value);
311 if (empty($value) || !isset($options[$value[0]])) {
314 echo $options[$value[0]];
316 echo $options[$value];
321 foreach ($value as $k) {
322 if (!isset($options[$k]))
continue;
323 echo
'<li class="sq-backend-data">'.htmlspecialchars($options[$k]).
'</li>';
331 require_once SQ_LIB_PATH.
'/html_form/html_form.inc';
335 hidden_field($prefix.
'_posted',
'1');
337 if ($this->_edit_params[
'style'] ==
'list') {
338 if (empty($this->_params[
'multiple']) && $this->_params[
'allow_other']) {
339 $options[
'__other__'] = translate(
'other');
340 $onchange_code =
'document.getElementById(\''.$prefix.
'_other\').style.visibility = (this.options[this.selectedIndex].value == \'__other__\') ? \'visible\' : \'hidden\'';
341 $onchange_pos = strpos(strtolower($this->_edit_params[
'extras']),
'onchange=');
342 if (FALSE === $onchange_pos) {
343 $this->_edit_params[
'extras'] .=
' onchange="'.$onchange_code.
'"';
345 $this->_edit_params[
'extras'] = substr($this->edit_params[
'extras'], 0, $onchange_pos+10)
347 .substr($this->edit_params[
'extras'], $onchange_pos+11);
350 combo_box($prefix, $options, !empty($this->_params[
'multiple']), $this->hasUnlistedValue() ?
'__other__' : $value, $this->_edit_params[
'height'], $this->_edit_params[
'extras']);
351 if (array_get_index($this->_params,
'allow_other')) {
353 text_box($prefix.
'_other', $this->hasUnlistedValue() ? $this->value :
'',
'',
'', FALSE, $this->hasUnlistedValue() ?
'' :
'style="visibility: hidden"');
356 if (empty($this->_params[
'multiple']) && $this->_params[
'allow_other']) {
357 $options[
'__other__'] = translate(
'other');
358 $onclick_pos = strpos(strtolower($this->_edit_params[
'extras']),
'onchange=');
359 if (FALSE === $onclick_pos) {
360 $this->_edit_params[
'extras'] .=
' onclick="%on_click%"';
362 $this->_edit_params[
'extras'] = substr($this->edit_params[
'extras'], 0, $onclick_pos+10)
364 .substr($this->edit_params[
'extras'], $onclick_pos+11);
368 if ($this->_edit_params[
'type'] ==
'table') {
371 <table cellpadding=
"0" cellspacing=
"0" border=
"0">
375 while (list($key, $val) = each($options)) {
376 if (empty($this->_params[
'multiple'])) {
380 $selected = (($key ==
'__other__') && $this->_params[
'allow_other']) && $this->hasUnlistedValue() || ($key == $value);
381 $onclick =
'document.getElementById(\''.$prefix.
'_other\').style.visibility = \''.(($key ==
'__other__') ?
'visible' :
'hidden').
'\'';
382 $extras = str_replace(
'%on_click%', $onclick, $this->_edit_params[
'extras']);
383 $id = $prefix.
'_'.str_replace(
' ',
'_', $key);
384 $extras .=
' id="'.$id.
'"';
385 radio_button($prefix, $key, $selected,
'', $extras);
387 if (($key ==
'__other__') && $this->_params[
'allow_other']) {
389 text_box($prefix.
'_other', $this->hasUnlistedValue() ? $this->value :
'',
'',
'', FALSE, $selected ?
'' :
'style="visibility: hidden"');
395 $id = $prefix.
'_'.str_replace(
' ',
'_', $key);
396 $extras = $this->_edit_params[
'extras'].
' id="'.$id.
'"';
400 check_box($prefix.
'['.$i.
']', $key, (is_array($value) && in_array($key, $value)),
'', $extras);
407 if ((($i++) % $this->_edit_params[
'columns']) == ($this->_edit_params[
'columns'] - 1)) {
421 while (list($key, $val) = each($options)) {
423 if (empty($this->_params[
'multiple'])) {
424 $selected = (($key ==
'__other__') && $this->_params[
'allow_other']) && $this->hasUnlistedValue() || ($key == $value);
425 $onclick =
'document.getElementById(\''.$prefix.
'_other\').style.visibility = \''.(($key ==
'__other__') ?
'visible' :
'hidden').
'\'';
426 $extras = str_replace(
'%on_click%', $onclick, $this->_edit_params[
'extras']);
427 $id = $prefix.
'_'.str_replace(
' ',
'_', $key);
428 $extras .=
' id="'.$id.
'"';
429 radio_button($prefix, $key, $selected,
'', $extras);
431 if (($key ==
'__other__') && $this->_params[
'allow_other']) {
433 text_box($prefix.
'_other', $this->hasUnlistedValue() ? $this->value :
'',
'',
'', FALSE, $selected ?
'' :
'style="visibility: hidden"');
436 $id = $prefix.
'_'.str_replace(
' ',
'_', $key);
437 $extras = $this->_edit_params[
'extras'].
' id="'.$id.
'"';
438 check_box($prefix.
'['.$i.
']', $key, (is_array($value) && in_array($key, $value)),
'', $extras);
461 function process($prefix)
463 require_once SQ_FUDGE_PATH.
'/general/general.inc';
464 if (!isset($_REQUEST[$prefix.
'_posted']))
return FALSE;
465 $value = (isset($_REQUEST[$prefix])) ? $_REQUEST[$prefix] :
'';
466 if ($this->_params[
'allow_other'] && ($value ==
'__other__')) {
467 $value = $_REQUEST[$prefix.
'_other'];
470 if (is_array($value)) $value = $this->_ar2str($value);
472 if ($this->setValue($value)) {
473 $this->processed = TRUE;
475 $this->processed = FALSE;
489 function validateValue(&$value)
491 $options = $this->_params[
'options'];
492 if (is_array($value)) $value = $this->_ar2str($value);
493 $value = trim((
string) $value);
495 return $this->_params[
'allow_empty'];
499 if (empty($this->_params[
'multiple'])) {
500 if (!isset($options[$value])) {
501 return $this->_params[
'allow_other'];
504 $new_value = $this->_str2ar($value);
505 if (!is_array($new_value))
return FALSE;
506 $return_value = Array();
507 foreach ($new_value as $key) {
508 if (isset($options[$key])) $return_value[] = $key;
510 $value = $this->_ar2str($return_value);
524 function getOptions()
526 return $this->_params[
'options'];
538 function getValueArray()
540 $value = $this->_str2ar($this->value);
541 $value_arr = Array();
542 foreach ($value as $k) {
543 $value_arr[$k] = $this->_params[
'options'][$k];
556 function hasUnlistedValue()
558 return $this->_params[
'allow_other'] && !isset($this->_params[
'options'][$this->value]);
569 function exportContentsToXML()
573 foreach ($this->getValueArray() as $value => $display_name) {
574 $value_xml .=
'<selection displayname="'.$display_name.
'"><![CDATA['.$value.
']]></selection>';
576 $xml =
'<value>'.$value_xml.
'</value>';