18 require_once dirname(__FILE__).
'/../../form_question/form_question_edit_fns.inc';
58 if (!$asset->writeAccess(
'attributes'))
return FALSE;
59 $options = $asset->getOptions();
60 if (count($options) > 0) {
61 foreach ($options as $key => $value) {
62 hidden_field($prefix.
'_old_options['.$key.
']', $value,
'id='.$prefix.
'_old_options['.htmlspecialchars($key).
']');
65 $multiple = ($asset->attr(
'multiple')) ? TRUE : FALSE;
66 return combo_box($prefix.
'_default', $options, $multiple, $asset->attr(
'default'));
83 if (isset($_POST[$prefix.
'_default'])) {
85 $default = $_POST[$prefix.
'_default'];
86 if (!is_array($default)) $default = Array($default);
88 $old_options = array_get_index($_POST, $prefix.
'_old_options', Array());
90 if (!empty($old_options)) {
91 $new_options = $asset->getOptions();
92 $new_values = Array();
93 $new_default_vals = Array();
94 foreach ($default as $str_key) {
95 if ($str_key ===
'') {
96 trigger_error(
'Key text for the selected default option(s) cannot be empty string', E_USER_WARNING);
100 if (is_numeric($str_key)) {
101 $str_key = (int) $str_key;
103 $new_default_vals[] = $old_options[$str_key];
106 $new_default = Array();
107 foreach ($new_default_vals as $val) {
108 if (($idx = array_search($val, $new_options)) !== FALSE) {
109 $new_default[] = $idx;
112 if (!empty($new_default)) {
113 $default = $new_default;
117 if (!$asset->setAttrValue(
'default', $default)) {
140 file_upload($prefix.
'_option_upload');
141 return $write_access;
158 if (isset($_FILES[$prefix.
'_option_upload'])) {
159 $file = $_FILES[$prefix.
'_option_upload'];
161 if ($file[
'error'] === UPLOAD_ERR_OK) {
182 if ($asset->writeAccess(
'attributes')) {
188 $prefix = str_replace(
':',
'_',$prefix);
189 $value = $asset->attr(
'options');
193 <div
id=
"option-list-<?php echo $prefix; ?>">
196 if (count($value) > 0) {
197 foreach ($value as $k => $v) {
198 $k = html_entity_decode($k, ENT_COMPAT, SQ_CONF_DEFAULT_CHARACTER_SET);
199 $v = html_entity_decode($v, ENT_COMPAT, SQ_CONF_DEFAULT_CHARACTER_SET);
200 $printup = ($order < 1) ? FALSE : TRUE;
205 for ($i = 0; $i < 2; $i++) {
208 $printdown = ($i < 1) ? TRUE : FALSE;
214 <script type=
"text/javascript">
219 if (!SQ_IN_BACKEND && !SQ_IN_LIMBO) {
221 buttons = document.getElementsByTagName(
'BUTTON');
222 for (i = 0; i < buttons.length; i++) {
223 if (buttons[i].className ==
'delete-button') {
224 with (buttons[i].style) {
225 backgroundImage =
'url(<?php echo sq_web_path('lib
') ?>/web/images/icons/delete.png)';
226 backgroundPosition =
'50% 50%';
227 backgroundRepeat =
'no-repeat';
230 backgroundColor =
'transparent';
240 var optionItemPrefix =
'<?php echo $prefix; ?>';
243 var doExpandList =
new Function(
'doExpandOptionList(this)');
244 var doDeleteRow =
new Function(
'doDeleteOptionListRow(this); return false;');
245 var doMoveDn =
new Function(
'sListMoveDown(this); return false;');
246 var doMoveUp =
new Function(
'sListMoveUp(this); return false;');
248 function sListMoveDown(obj) {
249 var currentOrder = 0;
251 var list = document.getElementById(
'option-list-<?php echo $prefix; ?>');
252 var inputs = list.getElementsByTagName(
'INPUT');
253 for (var i=0 ; i < inputs.length; i++) {
254 if (obj.id == inputs[i].id) {
260 if (currentOrder == inputs.length)
return;
263 if (inputs[currentOrder].disabled)
return;
266 if (currentOrder > 2) {
267 sListMoveMe(currentOrder, currentOrder-2);
271 function sListMoveUp(obj) {
272 var optionList = document.getElementById(
'option-list-<?php echo $prefix; ?>');
273 var currentOrder = 0;
275 var inputs = optionList.getElementsByTagName(
'INPUT');
276 for (var i=0 ; i < inputs.length; i++) {
277 if (obj.id == inputs[i].id) {
283 if (currentOrder == inputs.length)
return;
286 if (inputs[currentOrder].disabled)
return;
289 if (currentOrder > 0) {
290 sListMoveMe(currentOrder-2, currentOrder);
294 function doExpandOptionList(input)
297 var nextInput = input.nextSibling;
298 while (nextInput !== null) {
299 if (nextInput.tagName ==
'INPUT') {
302 nextInput = nextInput.nextSibling;
306 var lastInput = input.previousSibling;
307 var last2Input = lastInput.previousSibling;
309 while (lastInput !== null) {
310 if (lastInput.tagName ==
'INPUT') {
311 last2Input = lastInput.previousSibling;
312 while (last2Input !== null) {
313 if (last2Input.tagName ==
'INPUT') {
314 if (last2Input.value ==
'') {
319 last2Input = last2Input.previousSibling;
323 lastInput = lastInput.previousSibling;
326 var optionList = document.getElementById(
'option-list-<?php echo $prefix; ?>');
327 var inputs = optionList.getElementsByTagName(
'INPUT');
330 var moveDownButton = lastInput.previousSibling;
331 while (moveDownButton != null) {
332 moveDownButton = moveDownButton.previousSibling;
333 if (moveDownButton.tagName ==
'A' && moveDownButton.name==
"movedown") {
337 var newMoveDownButton = moveDownButton.cloneNode(
true);
338 newMoveDownButton.id = optionItemPrefix+
'_options['+(inputs.length/2)+
']';
339 newMoveDownButton.onclick = doMoveDn;
343 var buttonScript = newMoveDownButton.getElementsByTagName(
"script")[0];
344 var browserAgent = navigator.userAgent.toLowerCase();
345 if ((browserAgent.indexOf(
"safari") != -1) && buttonScript != null) {
346 newMoveDownButton.removeChild(buttonScript);
351 var brElements = lastInput.parentNode.getElementsByTagName(
'BR');
352 input.parentNode.removeChild(brElements[brElements.length-1]);
353 input.parentNode.appendChild(document.createTextNode(
' '));
354 input.parentNode.appendChild(newMoveDownButton);
355 input.parentNode.appendChild(document.createElement(
'BR'));
358 var newInput = input.cloneNode(
true);
359 var newKeyInput = lastInput.cloneNode(
true);
360 var newId = (inputs.length/2);
361 var newKeyId = (inputs.length/2);
362 newKeyInput.onfocus = doExpandList;
363 newKeyInput.value =
'';
364 newKeyInput.id = optionItemPrefix+
'_options_keys['+newId+
']';
365 input.parentNode.appendChild(newKeyInput);
366 input.parentNode.appendChild(document.createTextNode(
' '));
367 newInput.onfocus = doExpandList;
369 newInput.id = optionItemPrefix+
'_options['+newId+
']';
370 input.parentNode.appendChild(newInput);
371 input.parentNode.appendChild(document.createTextNode(
' '));
372 var delButton = input.nextSibling;
373 while (delButton.tagName !=
'BUTTON') {
374 delButton = delButton.nextSibling;
376 delButton = delButton.cloneNode(
true);
377 delButton.onclick = doDeleteRow;
378 input.parentNode.appendChild(delButton);
379 input.parentNode.appendChild(document.createTextNode(
' '));
382 var moveUpButton = input.nextSibling;
383 while (moveUpButton != null) {
384 if (moveUpButton.tagName ==
'A' && moveUpButton.name ==
'moveup') {
387 moveUpButton = moveUpButton.nextSibling;
389 moveUpButton = moveUpButton.cloneNode(
true);
390 moveUpButton.id = optionItemPrefix+
'_options['+((inputs.length/2)-1)+
']';
391 moveUpButton.onclick = doMoveUp;
394 var buttonScript = moveUpButton.getElementsByTagName(
"script")[0];
395 var browserAgent = navigator.userAgent.toLowerCase();
396 if ((browserAgent.indexOf(
"safari") != -1) && buttonScript != null) {
397 moveUpButton.removeChild(buttonScript);
400 input.parentNode.appendChild(moveUpButton);
401 input.parentNode.appendChild(document.createTextNode(
' '));
402 input.parentNode.appendChild(document.createElement(
'BR'));
406 function doDeleteOptionListRow(button)
408 var input = button.previousSibling;
409 while (input.tagName !=
'INPUT') {
410 input = input.previousSibling;
413 var input2 = input.previousSibling;
414 while (input2.tagName !=
'INPUT') {
415 input2 = input2.previousSibling;
418 if (input.value ==
'')
return;
421 if (input.disabled)
return;
426 var inputs = input.parentNode.getElementsByTagName(
'INPUT');
427 if (inputs.length <= 4) {
433 var moveUpBut = button.nextSibling;
434 while (moveUpBut != null) {
435 if (moveUpBut.tagName ==
'A' && moveUpBut.name ==
'moveup') {
438 moveUpBut = moveUpBut.nextSibling;
440 button.parentNode.removeChild(moveUpBut);
442 var moveDownBut = button.nextSibling;
443 while (moveDownBut != null) {
444 if (moveDownBut.tagName ==
'A' && moveDownBut.name ==
'movedown') {
447 moveDownBut = moveDownBut.nextSibling;
450 if (moveDownBut != null) {
451 button.parentNode.removeChild(moveDownBut);
455 var brTag = button.nextSibling;
456 while (brTag.tagName !=
'BR') {
457 brTag = brTag.nextSibling;
459 button.parentNode.removeChild(input2);
460 button.parentNode.removeChild(input);
461 button.parentNode.removeChild(brTag);
462 button.parentNode.removeChild(button);
466 var optionList = document.getElementById(
'option-list-<?php echo $prefix; ?>');
467 var inputs = optionList.getElementsByTagName(
'INPUT');
468 for (var j=0; j < inputs.length; j++) {
469 inputs[j].onfocus = doExpandList;
471 var buttons = optionList.getElementsByTagName(
'BUTTON');
472 for (var j=0; j < buttons.length; j++) {
473 buttons[j].onclick = doDeleteRow;
476 lastOrder = <?php echo $order; ?>;
478 function sListMoveMe(first, second) {
479 var l = document.getElementById(
'option-list-<?php echo $prefix; ?>');
480 var f = l.getElementsByTagName(
'INPUT');
481 var tempkey = f[first-1].value;
483 f[first-1].value = f[second-1].value;
484 f[second-1].value = tempkey;
486 var temp = f[first].value;
487 f[first].value = f[second].value;
488 f[second].value = temp;
494 if (count($value) > 0) {
495 echo
'<ul><li>'.html_entity_decode(implode(
'</li><li>', $value), ENT_COMPAT, SQ_CONF_DEFAULT_CHARACTER_SET).
'</li></ul>';
514 $prefix = str_replace(
':',
'_',$prefix);
517 if (!isset($_REQUEST[$prefix.
'_options']))
return;
518 $value = $_REQUEST[$prefix.
'_options'];
519 foreach ($value as $i => $v) {
520 $value[$i] = htmlentities($v, ENT_COMPAT, SQ_CONF_DEFAULT_CHARACTER_SET);
521 if ($v ==
'') unset($value[$i]);
525 if (!isset($_REQUEST[$prefix.
'_options_keys']))
return;
526 $key_value = $_REQUEST[$prefix.
'_options_keys'];
527 foreach ($key_value as $j => $k) {
528 $key_value[$j] = htmlentities($k, ENT_COMPAT, SQ_CONF_DEFAULT_CHARACTER_SET);
529 if (($k ==
'') && (isset($value[$j]) && !($value[$j] ==
''))) {
530 $key_value[$j] = $value[$j];
531 }
else if (($k ==
'') && (!isset($value[$j]) || ($value[$j] ==
''))) {
532 unset($key_value[$j]);
536 $key_value_count = count($key_value);
537 $value_count = count($value);
538 if($key_value_count != $value_count)
return;
539 if ($key_value_count > 0) {
540 $values = array_combine($key_value, $value);
545 $processed_value = $values;
546 if ($asset->writeAccess(
'attributes')) {
547 $asset->setAttrValue(
'options', $processed_value);
548 $asset->saveAttributes();
566 $orderdn = $order + 2;
568 <a href=
"#" style=
"cursor:pointer;" onclick=
"sListMoveMe(<?php echo $order; ?>, <?php echo ($orderdn); ?>);return false;" tabindex=
"99999" name=
"movedown" id=
"<?php echo $prefix; ?>_options[<?php echo $order; ?>]"><script type=
"text/javascript">sq_print_icon(
"<?php echo sq_web_path('lib').'/web/images/icons/down_arrow.png' ?>",
"16",
"16",
"Move Down");</script></a>
586 $orderup = $order - 2;
588 <a href=
"#" style=
"cursor:pointer;" onclick=
"sListMoveMe(<?php echo $order; ?>, <?php echo ($orderup); ?>);return false;" tabindex=
"99999" name=
"moveup" id=
"<?php echo $prefix; ?>_options[<?php echo $order; ?>]"><script type=
"text/javascript">sq_print_icon(
"<?php echo sq_web_path('lib').'/web/images/icons/up_arrow.png' ?>",
"16",
"16",
"Move Up");</script></a>
608 function _printOptionField($key, $value, $order, $prefix, $size=
'10', $showup=TRUE, $showdown=TRUE)
611 $current_button = ($order * 2) + 1;
614 $key_size = $size / 2;
618 <input type=
"text" name=
"<?php echo $prefix; ?>_options_keys[]" value=
"<?php echo $key; ?>" id=
"<?php echo $prefix; ?>_options_keys[<?php echo $order; ?>]" size=
"<?=$key_size; ?>" />
619 <input type=
"text" name=
"<?php echo $prefix; ?>_options[]" value=
"<?php echo $value; ?>" id=
"<?php echo $prefix; ?>_options[<?php echo $order; ?>]" size=
"<?=$size; ?>" />
620 <button type=
"button" tabindex=
"99999" class=
"delete-button"> </button>