18 require_once SQ_PACKAGES_PATH.
'/cms/page_templates/page_decision_tree/decision_tree_question/decision_tree_question_edit_fns.inc';
40 parent::__construct();
57 if ($asset->writeAccess(
'attributes')) {
63 $prefix = str_replace(
':',
'_',$prefix);
64 $value = $asset->attr(
'options');
68 <div
id=
"option-list-<?php echo $prefix; ?>">
71 if (count($value) > 0) {
72 foreach ($value as $k => $v) {
73 $k = html_entity_decode($k, ENT_COMPAT, SQ_CONF_DEFAULT_CHARACTER_SET);
74 $v = html_entity_decode($v, ENT_COMPAT, SQ_CONF_DEFAULT_CHARACTER_SET);
75 $printup = ($order < 1) ? FALSE : TRUE;
80 for ($i = 0; $i < 2; $i++) {
83 $printdown = ($i < 1) ? TRUE : FALSE;
89 <script type=
"text/javascript">
94 if (!SQ_IN_BACKEND && !SQ_IN_LIMBO) {
96 buttons = document.getElementsByTagName(
'BUTTON');
97 for (i = 0; i < buttons.length; i++) {
98 if (buttons[i].className ==
'delete-button') {
99 with (buttons[i].style) {
100 backgroundImage =
'url(<?php echo sq_web_path('lib
') ?>/web/images/icons/delete.png)';
101 backgroundPosition =
'50% 50%';
102 backgroundRepeat =
'no-repeat';
105 backgroundColor =
'transparent';
115 var optionItemPrefix =
'<?php echo $prefix; ?>';
118 var doExpandList =
new Function(
'doExpandOptionList(this)');
119 var doDeleteRow =
new Function(
'doDeleteOptionListRow(this); return false;');
120 var doMoveDn =
new Function(
'sListMoveDown(this); return false;');
121 var doMoveUp =
new Function(
'sListMoveUp(this); return false;');
123 function sListMoveDown(obj) {
124 var currentOrder = 0;
126 var list = document.getElementById(
'option-list-<?php echo $prefix; ?>');
127 var inputs = list.getElementsByTagName(
'INPUT');
128 for (var i=0 ; i < inputs.length; i++) {
129 if (obj.id == inputs[i].id) {
135 if (currentOrder == inputs.length)
return;
138 if (inputs[currentOrder].disabled)
return;
141 if (currentOrder > 2) {
142 sListMoveMe(currentOrder, currentOrder-2);
146 function sListMoveUp(obj) {
147 var optionList = document.getElementById(
'option-list-<?php echo $prefix; ?>');
148 var currentOrder = 0;
150 var inputs = optionList.getElementsByTagName(
'INPUT');
151 for (var i=0 ; i < inputs.length; i++) {
152 if (obj.id == inputs[i].id) {
158 if (currentOrder == inputs.length)
return;
161 if (inputs[currentOrder].disabled)
return;
164 if (currentOrder > 0) {
165 sListMoveMe(currentOrder-2, currentOrder);
169 function doExpandOptionList(input)
172 var nextInput = input.nextSibling;
173 while (nextInput !== null) {
174 if (nextInput.tagName ==
'INPUT') {
177 nextInput = nextInput.nextSibling;
181 var lastInput = input.previousSibling;
182 var last2Input = lastInput.previousSibling;
184 while (lastInput !== null) {
185 if (lastInput.tagName ==
'INPUT') {
186 last2Input = lastInput.previousSibling;
187 while (last2Input !== null) {
188 if (last2Input.tagName ==
'INPUT') {
189 if (last2Input.value ==
'') {
194 last2Input = last2Input.previousSibling;
198 lastInput = lastInput.previousSibling;
201 var optionList = document.getElementById(
'option-list-<?php echo $prefix; ?>');
202 var inputs = optionList.getElementsByTagName(
'INPUT');
205 var moveDownButton = lastInput.previousSibling;
206 while (moveDownButton != null) {
207 moveDownButton = moveDownButton.previousSibling;
208 if (moveDownButton.tagName ==
'A' && moveDownButton.name==
"movedown") {
212 var newMoveDownButton = moveDownButton.cloneNode(
true);
213 newMoveDownButton.id = optionItemPrefix+
'_options['+(inputs.length/2)+
']';
214 newMoveDownButton.onclick = doMoveDn;
218 var buttonScript = newMoveDownButton.getElementsByTagName(
"script")[0];
219 var browserAgent = navigator.userAgent.toLowerCase();
220 if ((browserAgent.indexOf(
"safari") != -1) && buttonScript != null) {
221 newMoveDownButton.removeChild(buttonScript);
226 var brElements = lastInput.parentNode.getElementsByTagName(
'BR');
227 input.parentNode.removeChild(brElements[brElements.length-1]);
228 input.parentNode.appendChild(document.createTextNode(
' '));
229 input.parentNode.appendChild(newMoveDownButton);
230 input.parentNode.appendChild(document.createElement(
'BR'));
233 var newInput = input.cloneNode(
true);
234 var newKeyInput = lastInput.cloneNode(
true);
235 var newId = (inputs.length/2);
236 var newKeyId = (inputs.length/2);
237 newKeyInput.onfocus = doExpandList;
238 newKeyInput.value =
'';
239 newKeyInput.id = optionItemPrefix+
'_options_keys['+newId+
']';
240 input.parentNode.appendChild(newKeyInput);
241 input.parentNode.appendChild(document.createTextNode(
' '));
242 newInput.onfocus = doExpandList;
244 newInput.id = optionItemPrefix+
'_options['+newId+
']';
245 input.parentNode.appendChild(newInput);
246 input.parentNode.appendChild(document.createTextNode(
' '));
247 var delButton = input.nextSibling;
248 while (delButton.tagName !=
'BUTTON') {
249 delButton = delButton.nextSibling;
251 delButton = delButton.cloneNode(
true);
252 delButton.onclick = doDeleteRow;
253 input.parentNode.appendChild(delButton);
254 input.parentNode.appendChild(document.createTextNode(
' '));
257 var moveUpButton = input.nextSibling;
258 while (moveUpButton != null) {
259 if (moveUpButton.tagName ==
'A' && moveUpButton.name ==
'moveup') {
262 moveUpButton = moveUpButton.nextSibling;
264 moveUpButton = moveUpButton.cloneNode(
true);
265 moveUpButton.id = optionItemPrefix+
'_options['+((inputs.length/2)-1)+
']';
266 moveUpButton.onclick = doMoveUp;
269 var buttonScript = moveUpButton.getElementsByTagName(
"script")[0];
270 var browserAgent = navigator.userAgent.toLowerCase();
271 if ((browserAgent.indexOf(
"safari") != -1) && buttonScript != null) {
272 moveUpButton.removeChild(buttonScript);
275 input.parentNode.appendChild(moveUpButton);
276 input.parentNode.appendChild(document.createTextNode(
' '));
277 input.parentNode.appendChild(document.createElement(
'BR'));
281 function doDeleteOptionListRow(button)
283 var input = button.previousSibling;
284 while (input.tagName !=
'INPUT') {
285 input = input.previousSibling;
288 var input2 = input.previousSibling;
289 while (input2.tagName !=
'INPUT') {
290 input2 = input2.previousSibling;
293 if (input.value ==
'')
return;
296 if (input.disabled)
return;
300 var inputs = input.parentNode.getElementsByTagName(
'INPUT');
301 if (inputs.length <= 2) {
306 var moveUpBut = button.nextSibling;
307 while (moveUpBut != null) {
308 if (moveUpBut.tagName ==
'A' && moveUpBut.name ==
'moveup') {
311 moveUpBut = moveUpBut.nextSibling;
313 button.parentNode.removeChild(moveUpBut);
315 var moveDownBut = button.nextSibling;
316 while (moveDownBut != null) {
317 if (moveDownBut.tagName ==
'A' && moveDownBut.name ==
'movedown') {
320 moveDownBut = moveDownBut.nextSibling;
322 button.parentNode.removeChild(moveDownBut);
325 var brTag = button.nextSibling;
326 while (brTag.tagName !=
'BR') {
327 brTag = brTag.nextSibling;
329 button.parentNode.removeChild(input2);
330 button.parentNode.removeChild(input);
331 button.parentNode.removeChild(brTag);
332 button.parentNode.removeChild(button);
336 var optionList = document.getElementById(
'option-list-<?php echo $prefix; ?>');
337 var inputs = optionList.getElementsByTagName(
'INPUT');
338 for (var j=0; j < inputs.length; j++) {
339 inputs[j].onfocus = doExpandList;
341 var buttons = optionList.getElementsByTagName(
'BUTTON');
342 for (var j=0; j < buttons.length; j++) {
343 buttons[j].onclick = doDeleteRow;
346 lastOrder = <?php echo $order; ?>;
348 function sListMoveMe(first, second) {
349 var l = document.getElementById(
'option-list-<?php echo $prefix; ?>');
350 var f = l.getElementsByTagName(
'INPUT');
351 var tempkey = f[first-1].value;
353 f[first-1].value = f[second-1].value;
354 f[second-1].value = tempkey;
356 var temp = f[first].value;
357 f[first].value = f[second].value;
358 f[second].value = temp;
364 if (count($value) > 0) {
365 echo
'<ul><li>'.html_entity_decode(implode(
'</li><li>', $value), ENT_COMPAT, SQ_CONF_DEFAULT_CHARACTER_SET).
'</li></ul>';
384 $prefix = str_replace(
':',
'_',$prefix);
387 if (!isset($_REQUEST[$prefix.
'_options']))
return;
388 $value = $_REQUEST[$prefix.
'_options'];
389 foreach ($value as $i => $v) {
390 $value[$i] = htmlentities($v, ENT_COMPAT, SQ_CONF_DEFAULT_CHARACTER_SET);
391 if ($v ==
'') unset($value[$i]);
395 if (!isset($_REQUEST[$prefix.
'_options_keys']))
return;
396 $key_value = $_REQUEST[$prefix.
'_options_keys'];
397 foreach ($key_value as $j => $k) {
398 $key_value[$j] = htmlentities($k, ENT_COMPAT, SQ_CONF_DEFAULT_CHARACTER_SET);
399 if (($k ==
'') && (isset($value[$j]) && !($value[$j] ==
''))) {
400 $key_value[$j] = $value[$j];
401 }
else if (($k ==
'') && (!isset($value[$j]) || ($value[$j] ==
''))) {
402 unset($key_value[$j]);
406 $key_value_count = count($key_value);
407 $value_count = count($value);
408 if ($key_value_count != $value_count)
return;
409 if ($key_value_count > 0) {
410 $values = array_combine($key_value, $value);
415 $processed_value = $values;
416 if ($asset->writeAccess(
'attributes')) {
417 $asset->setAttrValue(
'options', $processed_value);
418 $asset->saveAttributes();
436 $orderdn = $order + 2;
438 <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>
456 $orderup = $order - 2;
458 <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>
478 function _printOptionField($key, $value, $order, $prefix, $size=
'10', $showup=TRUE, $showdown=TRUE)
481 $current_button = ($order * 2) + 1;
484 $key_size = $size / 2;
488 <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; ?>" />
489 <input type=
"text" name=
"<?php echo $prefix; ?>_options[]" value=
"<?php echo $value; ?>" id=
"<?php echo $prefix; ?>_options[<?php echo $order; ?>]" size=
"<?=$size; ?>" />
490 <button type=
"button" tabindex=
"99999" class=
"delete-button"> </button>
517 $write_access = $asset->writeAccess(
'attributes');
518 $options = $asset->getOptions();
519 $q_dest = $asset->attr(
'question_destinations');
522 <table
class=
"sq-backend-table">
524 <td
class=
"sq-backend-table-header">
525 <?php echo translate(
'answer_key'); ?>
527 <td
class=
"sq-backend-table-header">
528 <?php echo translate(
'next_question'); ?>
530 <td
class=
"sq-backend-table-header">
531 <?php echo translate(
'result_bodycopy'); ?>
533 <td
class=
"sq-backend-table-header">
534 <?php echo translate(
'points_value'); ?>
538 foreach ($options as $key => $value){
539 if ($key === $asset->attr(
'empty_key'))
continue;
542 <td
class=
"sq-backend-table-cell">
547 <td
class=
"sq-backend-table-cell">
549 $nxt_q = (!empty($q_dest[$key][
'next_question'])) ? $q_dest[$key][
'next_question'] :
'';
551 $type_codes = Array (
552 'decision_tree_question_type_select' =>
'I',
553 'decision_tree_question_type_numeric' =>
'I',
555 asset_finder($prefix.
'_next_question_'.$key, $nxt_q, $type_codes);
557 if ($nxt_q) echo get_asset_tag_line($nxt_q,
'details');
561 <td
class=
"sq-backend-table-cell">
563 $res_body = (!empty($q_dest[$key][
'result_bodycopy'])) ? $q_dest[$key][
'result_bodycopy'] :
'';
565 $type_codes = Array (
568 asset_finder($prefix.
'_bodycopy_'.$key, $res_body, $type_codes);
570 if ($res_body) echo get_asset_tag_line($res_body,
'details');
574 <td
class=
"sq-backend-table-cell">
576 $points = (!empty($q_dest[$key][
'points_value'])) ? $q_dest[$key][
'points_value'] : 0;
578 text_box($prefix.
'_points_value_'.$key, $points);
606 if (!$asset->writeAccess(
'attributes'))
return FALSE;
607 $options = $asset->getOptions();
610 foreach ($options as $key => $value){
611 if ($key === $asset->attr(
'empty_key'))
continue;
612 $nxt_q = (isset($_POST[$prefix.
'_next_question_'.$key])) ? $_POST[$prefix.
'_next_question_'.$key][
'assetid'] :
'';
615 $parents = $GLOBALS[
'SQ_SYSTEM']->am->getParents($nxt_q,
'decision_tree_question', FALSE, NULL, NULL, TRUE, 1, 1);
616 if (!array_key_exists($asset->id, $parents)){
617 $minor = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($nxt_q);
618 if(!$GLOBALS[
'SQ_SYSTEM']->am->createAssetLink($asset, $minor, SQ_LINK_TYPE_2)) $nxt_q =
'';
621 $q_dest[$key][
'next_question'] = $nxt_q;
623 $res_body = (isset($_POST[$prefix.
'_bodycopy_'.$key])) ? $_POST[$prefix.
'_bodycopy_'.$key][
'assetid'] :
'';
624 $q_dest[$key][
'result_bodycopy'] = $res_body;
626 $points = (!empty($_POST[$prefix.
'_points_value_'.$key])) ? $_POST[$prefix.
'_points_value_'.$key] : 0;
628 if (!is_numeric($points)) {
629 trigger_localised_error(
'CMS0114', E_USER_NOTICE);
632 $q_dest[$key][
'points_value'] = $points;
636 $asset->setAttrValue(
'question_destinations', $q_dest);
637 $asset->saveAttributes();