Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
funnelback_search_page_edit_fns.inc
1 <?php
17 require_once SQ_PACKAGES_PATH.'/cms/listing_engine/listing_engine_edit_fns.inc';
18 require_once SQ_LIB_PATH.'/html_form/html_form.inc';
19 
31 {
32 
33 
38  function __construct()
39  {
40  parent::__construct();
41  $this->static_screens['details']['lock_type'] = 'content';
42  $this->static_screens['details']['force_unlock'] = FALSE;
43 
44  }//end constructor
45 
46 
56  function integratedSearch(&$owner, $prefix)
57  {
58  return ($owner->attr('search_type') == 'integrated');
59 
60  }//end integratedSearch()
61 
62 
73  function paintDefaultFormatLinks(&$asset, &$o, $prefix)
74  {
75  ?>
76  <table class="sq-backend-table">
77  <tr>
78  <th><?php echo translate('edit_format') ?></th>
79  <th><?php echo translate('note') ?></th>
80  </tr>
81  <?php
82  $this->_paintDefaultFormatLink($asset->id, 'initial', translate('funnelback_initial_bodycopy_desc'));
83  $this->_paintDefaultFormatLink($asset->id, 'results', translate('funnelback_results_bodycopy_desc'));
84  $this->_paintDefaultFormatLink($asset->id, 'no_results', translate('funnelback_no_results_bodycopy_desc'));
85 
86  $folder = $asset->getFolder('type_format');
87  $this->_paintDefaultFormatLink($folder->id, 'default_format', translate('funnelback_default_bodycopy_desc'));
88  $this->_paintDefaultFormatLink($folder->id, 'featured_format', translate('funnelback_featured_bodycopy_desc'));
89  ?>
90  </table>
91  <?php
92 
93  return FALSE;
94 
95  }//end paintDefaultFormatLinks()
96 
97 
108  function paintFlusterFormatLinks(&$asset, &$o, $prefix)
109  {
110  ?>
111  <table class="sq-backend-table">
112  <tr>
113  <th><?php echo translate('edit_format') ?></th>
114  <th><?php echo translate('note') ?></th>
115  </tr>
116  <?php
117  $folder = $asset->getFolder('fluster_format');
118  $this->_paintDefaultFormatLink($folder->id, 'context_format', translate('funnelback_fluster_format_desc'));
119  $this->_paintDefaultFormatLink($folder->id, 'cluster_format', translate('funnelback_cluster_format_desc'));
120  $this->_paintDefaultFormatLink($folder->id, 'navigation_format', translate('funnelback_navigation_format_desc'));
121  ?>
122  </table>
123  <?php
124 
125  return FALSE;
126 
127  }//end paintFlusterFormatLinks()
128 
129 
140  function paintSpellFormatLinks(&$asset, &$o, $prefix)
141  {
142  ?>
143  <table class="sq-backend-table">
144  <tr>
145  <th><?php echo translate('edit_format') ?></th>
146  <th><?php echo translate('note') ?></th>
147  </tr>
148  <?php
149  $folder = $asset->getFolder('spell_format');
150  $this->_paintDefaultFormatLink($folder->id, 'spell_format', translate('funnelback_spell_format_desc'));
151  ?>
152  </table>
153  <?php
154 
155  return FALSE;
156 
157  }//end paintSpellFormatLinks()
158 
159 
174  function _paintDefaultFormatLink($root_assetid, $bodycopy_name, $bodycopy_description, $delete_control=FALSE, $prefix='', $type_code='bodycopy', $screen='contents')
175  {
176  $link = $GLOBALS['SQ_SYSTEM']->am->getLink($root_assetid, SQ_LINK_TYPE_2, $type_code, TRUE, $bodycopy_name);
177  if (!empty($link)) {
178  $info = Array($link['minorid'] => 'contents');
179  $href = $GLOBALS['SQ_SYSTEM']->am->getAssetBackendHref($info);
180  ?>
181  <tr>
182  <td>
183  <?php echo get_asset_tag_line($link['minorid'], $screen); ?>
184  </td>
185  <td>
186  <?php echo $bodycopy_description; ?>
187  </td>
188  <?php
189  if ($delete_control) {
190  echo '<td>';
191  check_box($prefix.'_delete['.$bodycopy_name.']');
192  echo '</td>';
193  }//end if
194  ?>
195  </tr>
196  <?php
197  }//end if
198 
199  }//end _paintDefaultFormatLink()
200 
201 
212  function paintTypeFormats(&$asset, &$o, $prefix)
213  {
214  $write_access = $asset->writeAccess('links');
215  $folder = $asset->getFolder('type_format');
216  $formats = $asset->getFormats('type_format');
217 
218  if (count($formats) > 2) {
219  ?>
220  <table class="sq-backend-table">
221  <tr>
222  <th><?php echo translate('edit_format') ?></th>
223  <th><?php echo translate('note') ?></th>
224  <?php
225  if ($write_access) {
226  ?>
227  <th><?php echo translate('delete_question') ?></th>
228  <?php
229  }
230  ?>
231  </tr>
232  <?php
233  foreach ($formats as $minorid => $value) {
234  if ($value == 'default_format') continue;
235  if ($value == 'featured_format') continue;
236 
237  $this->_paintDefaultFormatLink($folder->id, $value, translate('funnelback_custom_format_desc', strtoupper($value)), $write_access, $prefix);
238  }//end foreach
239  ?>
240  </table>
241  <?php
242  } else {
243  echo translate('funnelback_no_type_formats');
244  }//end if cutomised formats
245 
246  if ($write_access) {
247  echo '<p><b>'.translate('funnelback_new_type_format').'</b> ';
248  text_box($prefix.'_new_type', '');
249  echo '</p>';
250  }
251  $o->note(translate('funnelback_custom_format_note'));
252  return TRUE;
253 
254  }//end paintTypeFormats()
255 
256 
267  function processTypeFormats(&$asset, &$o, $prefix)
268  {
269  $folder = $asset->getFolder('type_format');
270 
271  $new_type = array_get_index($_POST, $prefix.'_new_type', '');
272  $deleted_formats = array_get_index($_POST, $prefix.'_delete', Array());
273 
274  // User wants to delete and create the same one? No point wasting time, just leave it and move on
275  if (isset($deleted_formats[$new_type])) {
276  unset($deleted_formats[$new_type]);
277  $new_type = '';
278  }//end if
279 
280  foreach ($deleted_formats as $type => $on) {
281  $current_link = $GLOBALS['SQ_SYSTEM']->am->getLink($folder->id, SQ_LINK_TYPE_2, 'bodycopy', TRUE, $type);
282  if (!empty($current_link)) {
283  if (!$GLOBALS['SQ_SYSTEM']->am->deleteAssetLink($current_link['linkid'])) {
284  trigger_localised_error('FNB0006', E_USER_WARNING, $type);
285  }//end if
286  }//end if
287  }//end foreach
288 
289  if (!empty($new_type)) {
290  // check that this type isnt already customised
291  $current_link = $GLOBALS['SQ_SYSTEM']->am->getLink($folder->id, SQ_LINK_TYPE_2, 'bodycopy', TRUE, $new_type);
292  if (empty($current_link)) {
293  // create a new format bodycopy for this type
294  $GLOBALS['SQ_SYSTEM']->changeDatabaseConnection('db2');
295  $GLOBALS['SQ_SYSTEM']->doTransaction('BEGIN');
296  $GLOBALS['SQ_SYSTEM']->am->includeAsset('bodycopy');
297 
298  $copy_link = Array('asset' => &$folder, 'value' => $new_type, 'link_type' => SQ_LINK_TYPE_2, 'is_dependant' => 1, 'is_exclusive' => 1);
299 
300  $bodycopy = new Bodycopy();
301  $bodycopy->setAttrValue('name', strtoupper($new_type).' Format');
302  $copy_args = Array('content' => $asset->_getDefaultBodycopyContent('custom_format'));
303 
304  if (!$bodycopy->create($copy_link, $copy_args)) {
305  $GLOBALS['SQ_SYSTEM']->doTransaction('ROLLBACK');
306  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
307  return FALSE;
308  }//end if
309  $GLOBALS['SQ_SYSTEM']->doTransaction('COMMIT');
310  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
311  } else {
312  trigger_localised_error('FNB0005', E_USER_WARNING, $new_type);
313  }//end if
314  }//end if
315 
316  return FALSE;
317 
318  }//end processTypeFormats()
319 
320 
331  function paintFunnelbackOptions(&$asset, &$o, $prefix)
332  {
333  $wa = $asset->writeAccess('attributes');
334  $search_type = $asset->attr('search_type');
335  $web_url = $asset->attr('funnelback_url');
336  $collection = $asset->attr('collection');
337  $fm = $GLOBALS['SQ_SYSTEM']->am->getSystemAsset('funnelback_manager');
338  $all_collections = $fm->getCollections();
339  $local_collections = Array(''=>translate('funnelback_no_collection'));
340  $squiz_search_options = $this->_getSquizSearchSystems();
341  $suiteid = $asset->attr('systemid');
342  $systemname = array_get_index($squiz_search_options, $suiteid, '');
343  $squiz_collections = $this->_getSquizSearchCollections($suiteid);
344  foreach ($all_collections as $all_col_id => $all_col_info) {
345  $local_collections[$all_col_id] = array_get_index($all_col_info, 'name', '');
346  }//end foreach
347  if ($search_type == 'integrated') {
348  $hidden_web = 'style="display:none;"';
349  $hidden_local = '';
350  $hidden_squiz = 'style="display:none;"';
351  } else if ($search_type == 'squiz') {
352  $hidden_web = 'style="display:none;"';
353  $hidden_local = 'style="display:none;"';
354  $hidden_squiz = '';
355  } else {
356  $hidden_web = '';
357  $hidden_local = 'style="display:none;"';
358  $hidden_squiz = 'style="display:none;"';
359  }//end if
360  $object_type = 'this.form.'.$prefix.'_search_type.value';
361  $object_url1 = 'this.form.'.$prefix.'_search_url_web';
362  $object_url2 = 'document.getElementById(\''.$prefix.'_search_url_local\')';
363  $object_url3 = 'this.form.'.$prefix.'_search_url_squiz';
364  $object_url4 = 'document.getElementById(\''.$prefix.'_search_mode_hosted\')';
365  $object_coll1 = 'this.form.'.$prefix.'_search_collection_web';
366  $object_coll2 = 'this.form.'.$prefix.'_search_collection_local';
367  $object_coll3 = 'this.form.'.$prefix.'_search_collection_squiz';
368  $object_coll4 = 'this.form.'.$prefix.'_search_mode';
369  $js = 'onChange="chooseFunnelbackSearchType('.$object_type.', '.$object_url1.', '.$object_url2.', '.$object_url3.', '.$object_url4.', '.$object_coll1.', '.$object_coll2.', '.$object_coll3.', '.$object_coll4.');"';
370 
371  $o->openField('Search Type');
372  ?>
373  <script type="text/javascript">
374  function chooseFunnelbackSearchType(type, url1, url2, url3, url4, coll1, coll2, coll3, coll4) {
375  if (type == 'web' || type == 'hosted') {
376  url1.style.display='block';
377  url1.disabled=false;
378  url2.style.display='none';
379  url2.disabled=true;
380  url3.style.display='none';
381  url3.disabled=true;
382  coll1.style.display='block';
383  coll1.disabled=false;
384  coll2.style.display='none';
385  coll2.disabled=true;
386  coll3.style.display='none';
387  coll3.disabled=true;
388  if (type == 'hosted') {
389  url4.style.display='none';
390  url4.disabled=true;
391  coll4.style.display='block';
392  coll4.disabled=false;
393  } else {
394  url4.style.display='block';
395  url4.disabled=false;
396  coll4.style.display='none';
397  coll4.disabled=true;
398  }
399  } else if (type == 'squiz') {
400  url1.style.display='none';
401  url1.disabled=true;
402  url2.style.display='none';
403  url2.disabled=true;
404  url3.style.display='block';
405  url3.disabled=false;
406  url4.style.display='block';
407  url4.disabled=true;
408  coll1.style.display='none';
409  coll1.disabled=true;
410  coll2.style.display='none';
411  coll2.disabled=true;
412  coll3.style.display='block';
413  coll3.disabled=false;
414  coll4.style.display='none';
415  coll4.disabled=true;
416  } else {
417  url1.style.display='none';
418  url1.disabled=true;
419  url2.style.display='block';
420  url2.disabled=false;
421  url3.style.display='none';
422  url3.disabled=true;
423  url4.style.display='block';
424  url4.disabled=true;
425  coll1.style.display='none';
426  coll1.disabled=true;
427  coll2.style.display='block';
428  coll2.disabled=false;
429  coll3.style.display='none';
430  coll3.disabled=true;
431  coll4.style.display='none';
432  coll4.disabled=true;
433  }
434  }
435  </script>
436  <?php
437  $type_attribute = $asset->getAttribute('search_type');
438  $type_options = $type_attribute->getOptions();
439  if ($wa) {
440  echo combo_box($prefix.'_search_type', $type_options, FALSE, $search_type, 0, $js);
441  } else {
442  echo $type_options[$search_type];
443  }
444  $o->note(translate('funnelback_search_type_note'));
445  $o->closeField();
446  $o->openField('Mode to use');
447  $mode = $asset->attr('hosted_mode');
448  $modes = Array('0' => 'Classic', '1' => 'Advanced');
449  if($wa) {
450  echo combo_box($prefix.'_search_mode', $modes, FALSE, $mode, 0, $hidden_web);
451  echo '<span id="'.$prefix.'_search_mode_hosted" '.$hidden_local.'>';
452  echo 'Not Available';
453  echo '</span>';
454  } else {
455  echo $modes[$mode];
456  }
457  $o->closeField();
458  $o->openField('Search URL');
459  if ($wa) {
460  echo text_box($prefix.'_search_url_web', $web_url, '', '', FALSE, $hidden_web);
461  echo '<span id="'.$prefix.'_search_url_local" '.$hidden_local.'>';
462  echo 'Integrated Search';
463  echo '</span>';
464  echo combo_box($prefix.'_search_url_squiz', $squiz_search_options, FALSE, $suiteid, 0, $hidden_squiz);
465  } else {
466  if ($search_type == 'integrated') {
467  echo 'Integrated Search';
468  } else if ($search_type == 'squiz') {
469  echo $systemname;
470  } else {
471  echo $web_url;
472  }//end if
473  }//end if
474  $o->closeField();
475  $o->openField('Collection');
476  if ($wa) {
477  echo text_box($prefix.'_search_collection_web', $collection, '', '', FALSE, $hidden_web);
478  echo combo_box($prefix.'_search_collection_local', $local_collections, FALSE, $collection, 0, $hidden_local);
479  echo combo_box($prefix.'_search_collection_squiz', $squiz_collections, FALSE, $collection, 0, $hidden_squiz);
480  } else {
481  if ($search_type == 'integrated') {
482  if (empty($collection) || !isset($local_collections[$collection])) {
483  echo translate('funnelback_no_collection');
484  } else {
485  echo $local_collections[$collection];
486  }//end if
487  } else if ($search_type == 'squiz') {
488  if (empty($collection) || !isset($squiz_collections[$collection])) {
489  echo translate('funnelback_no_collection');
490  } else {
491  echo $squiz_collections[$collection];
492  }//end if
493  } else {
494  echo $collection;
495  }//end if
496  }//end if
497  $o->closeField();
498 
499  return TRUE;
500 
501  }//end paintFunnelbackOptions()
502 
503 
514  function processFunnelbackOptions(&$asset, &$o, $prefix)
515  {
516  // Save the values based on the type
517  $wa = $asset->writeAccess('attributes');
518  $status = FALSE;
519  $type = array_get_index($_POST, $prefix.'_search_type', 'integrated');
520  if ($wa) {
521  if ($type == 'integrated') {
522  $collection = array_get_index($_POST, $prefix.'_search_collection_local', '');
523  $fm = $GLOBALS['SQ_SYSTEM']->am->getSystemAsset('funnelback_manager');
524  $all_collections = $fm->getCollections();
525  // In case, the collection does not match the loaded collections
526  if (!array_key_exists($collection, $all_collections)) {
527  $collection = '';
528  }//end if
529  $url = '';
530  $suiteid = '';
531  } else if ($type == 'squiz') {
532  $collection = array_get_index($_POST, $prefix.'_search_collection_squiz', '');
533  $suiteid = array_get_index($_POST, $prefix.'_search_url_squiz', '');
534  $url = '';
535  $systems = $this->_getSquizSearchSystems();
536  $collections = $this->_getSquizSearchCollections($suiteid);
537  if (!array_key_exists($suiteid, $systems)) {
538  $suiteid = '';
539  }
540 
541  if (!array_key_exists($collection, $collections)) {
542  $collection = '';
543  }
544  } else if ($type == 'hosted') {
545  $collection = array_get_index($_POST, $prefix.'_search_collection_web', '');
546  $url = array_get_index($_POST, $prefix.'_search_url_web', '');
547  $suiteid = '';
548  } else {
549  $collection = array_get_index($_POST, $prefix.'_search_collection_web', '');
550  $url = array_get_index($_POST, $prefix.'_search_url_web', '');
551  $suiteid = '';
552  }//end if
553 
554  // get the mode value irrespective of the search type
555  $mode = array_get_index($_POST, $prefix.'_search_mode', 0);
556  $asset->setAttrValue('search_type', $type);
557  $asset->setAttrValue('funnelback_url', $url);
558  $asset->setAttrValue('systemid', $suiteid);
559  $asset->setAttrValue('collection', $collection);
560  $asset->setAttrValue('hosted_mode', $mode);
561  $status = $asset->saveAttributes();
562  }//end if
563 
564  return $status;
565 
566  }//end processFunnelbackOptions()
567 
568 
575  private function _getSquizSearchSystems()
576  {
577  $systems = array();
578  $suitem = $GLOBALS['SQ_SYSTEM']->am->getSystemAsset('suite_manager', TRUE);
579  if ($suitem !== NULL) {
580  $products = $suitem->getProducts(FALSE, FALSE);
581  foreach ($products as $product) {
582  if ($product['type'] == 'Squiz Search' && $product['status'] == 'live') {
583  $productname = array_get_index($product['connection'], 'name', '');
584  $systems[$product['suiteid']] = $productname;
585  }
586  }//end foreach
587  }//end if
588 
589  return $systems;
590 
591  }//end _getSquizSearchSystems()
592 
593 
602  private function _getSquizSearchCollections($suiteid='')
603  {
604  $collections = array();
605  $suitem = $GLOBALS['SQ_SYSTEM']->am->getSystemAsset('suite_manager', TRUE);
606  if ($suitem !== NULL) {
607  $system = $suitem->getProduct($suiteid);
608  if (empty($system) === FALSE) {
609  $productUrl = array_get_index($system, 'url', '');
610  $request = array();
611  $response = $suitem->sendRequest($suiteid, 'json', 'SquizSearch', 'getAvailableCollections', $request);
612  if (isset($response['curlInfo']['http_code']) === TRUE && $response['curlInfo']['http_code'] == 200) {
613  $resultData = $response['result'];
614  $resultData = (array) $suitem->decodeJson($resultData);
615  $results = (array) $resultData['result'];
616  if (empty($results) === FALSE) {
617  foreach ($results as $k => $v) {
618  $collections[$k] = $v;
619  }
620  }
621  }//end if
622  }//end if
623  }//end if
624 
625  return $collections;
626 
627  }//end _getSquizSearchCollections()
628 
629 
640  function paintSort(&$asset, &$o, $prefix)
641  {
642  $sort = $asset->attr('sort_order');
643  $sort_options = $asset->getSortOptions();
644 
645  if ($asset->writeAccess('attributes')) {
646  combo_box($prefix.'_sort_order', $sort_options, FALSE, $sort);
647  } else {
648  if (!isset($sort_options[$sort])) {
649  $sort = 'rank';
650  }//end if
651  echo $sort_options[$sort];
652  }//end if
653 
654  return TRUE;
655 
656  }//end paintSort()
657 
658 
669  function processSort(&$asset, &$o, $prefix)
670  {
671  // Save the values
672  if ($asset->writeAccess('attributes')) {
673  $processed_value = array_get_index($_POST, $prefix.'_sort_order', 'rank');
674  $current_value = $asset->attr('sort_order');
675  if ($processed_value != $current_value) {
676  $asset->setAttrValue('sort_order', $processed_value);
677  $asset->saveAttributes();
678  }//end if
679  }//end if
680 
681  return TRUE;
682 
683  }//end processScope()
684 
685 
696  function paintDefaultScope(&$asset, &$o, $prefix)
697  {
698  $scope = $asset->attr('scope');
699  $default = $asset->attr('default_scope');
700 
701  if ($asset->writeAccess('attributes')) {
702  echo combo_box($prefix.'_default_scope', $scope, FALSE, $default);
703  } else {
704  echo (isset($scope[$default])) ? $scope[$default] : translate('funnelback_no_default_scope');
705  }//end if
706 
707  return TRUE;
708 
709  }//end paintDefaultScope()
710 
711 
722  function processDefaultScope(&$asset, &$o, $prefix)
723  {
724  // Save the values
725  $processed_value = array_get_index($_POST, $prefix.'_default_scope', '');
726  if (!empty($processed_value) && $asset->writeAccess('attributes')) {
727  $asset->setAttrValue('default_scope', $processed_value);
728  $asset->saveAttributes();
729  }//end if
730 
731  return TRUE;
732 
733  }//end processDefaultScope()
734 
735 
746  function paintScope(&$asset, &$o, $prefix)
747  {
748  $scope = $asset->attr('scope');
749 
750  $this->_paintOptionValue($scope, $asset, $o, $prefix);
751 
752  return TRUE;
753 
754  }//end paintScope()
755 
756 
767  function processScope(&$asset, &$o, $prefix)
768  {
769  // Save the values
770  if (!isset($_REQUEST[$prefix.'_options'])) return;
771  $value = $_REQUEST[$prefix.'_options'];
772  foreach ($value as $i => $v) {
773  $value[$i] = htmlentities($v);
774  if ($v == '') unset($value[$i]);
775  }
776 
777  // Save the key fields
778  if (!isset($_REQUEST[$prefix.'_options_keys'])) return;
779  $key_value = $_REQUEST[$prefix.'_options_keys'];
780  foreach ($key_value as $j => $k) {
781  $key_value[$j] = htmlentities($k);
782  if (empty($key_value[$j])) {
783  unset($key_value[$j]);
784  }//end if
785  }//end foreach
786 
787  $values = Array();
788  foreach ($key_value as $index => $key) {
789  $values[$key] = (isset($value[$index])) ? $value[$index] : '';
790  }//end foreach
791 
792  $processed_value = $values;
793  if ($asset->writeAccess('attributes')) {
794  $asset->setAttrValue('scope', $processed_value);
795  $asset->saveAttributes();
796  }//end if
797 
798  return TRUE;
799 
800  }//end processScope()
801 
802 
814  function _paintOptionValue($values, &$asset, &$o, $prefix)
815  {
816  // Check for write access
817  if ($asset->writeAccess('attributes')) {
818  $read_only = FALSE;
819  } else {
820  $read_only = TRUE;
821  }
822 
823  if (!$read_only) {
824  ?>
825  <div id="option-list-<?php echo $prefix; ?>">
826  <?php
827  $order = 0;
828  if (count($values) > 0) {
829  foreach ($values as $k => $v) {
830  $k = html_entity_decode($k);
831  $v = html_entity_decode($v);
832  $printup = ($order < 1) ? FALSE : TRUE;
833  $this->_printOptionField($k, $v, $order, $prefix, 20);
834  $order++;
835  }
836  }
837  for ($i = 0; $i < 2; $i++) {
838  $k = '';
839  $v = '';
840  $printdown = ($i < 1) ? TRUE : FALSE;
841  $this->_printOptionField($k, $v, $order, $prefix, 20);
842  $order++;
843  }
844  ?>
845  </div>
846  <script type="text/javascript">
847  <?php
848  // Yeesh... this is hackish but this essentially (attempts to)
849  // correct the lack of delete-button class in front-end
850  // asset builder creation
851  if (!SQ_IN_BACKEND && !SQ_IN_LIMBO) {
852  ?>
853  buttons = document.getElementsByTagName('BUTTON');
854  for (i = 0; i < buttons.length; i++) {
855  if (buttons[i].className == 'delete-button') {
856  with (buttons[i].style) {
857  backgroundImage = 'url(<?php echo sq_web_path('lib') ?>/web/images/icons/delete.png)';
858  backgroundPosition = '50% 50%';
859  backgroundRepeat = 'no-repeat';
860  width = '16px';
861  height = '16px';
862  backgroundColor = 'transparent';
863  border = '0px';
864  cursor = 'pointer';
865  }
866  }
867  }
868  <?php
869  }//end if
870  ?>
871  // Some variables
872  var optionItemPrefix = '<?php echo $prefix; ?>';
873 
874  // Functions for option list attribute
875  var doExpandList = new Function('doExpandOptionList(this)');
876  var doDeleteRow = new Function('doDeleteOptionListRow(this); return false;');
877 
878  function doExpandOptionList(input)
879  {
880  // abort if we are not the last input in the lit
881  var nextInput = input.nextSibling;
882  while (nextInput !== null) {
883  if (nextInput.tagName == 'INPUT') {
884  return;
885  }
886  nextInput = nextInput.nextSibling;
887  }
888 
889  // abort if we and the second-last input are both empty
890  var lastInput = input.previousSibling;
891  var last2Input = lastInput.previousSibling;
892  if (input.value == '') {
893  while (lastInput !== null) {
894  if (lastInput.tagName == 'INPUT') {
895  last2Input = lastInput.previousSibling;
896  while (last2Input !== null) {
897  if (last2Input.tagName == 'INPUT') {
898  if (last2Input.value == '') {
899  return;
900  }
901  break;
902  }
903  last2Input = last2Input.previousSibling;
904  }
905  break;
906  }
907  lastInput = lastInput.previousSibling;
908  }
909  }
910 
911  var optionList = document.getElementById('option-list-<?php echo $prefix; ?>');
912  var inputs = optionList.getElementsByTagName('INPUT');
913 
914  var brElements = lastInput.parentNode.getElementsByTagName('BR');
915  input.parentNode.removeChild(brElements[brElements.length-1]);
916  input.parentNode.appendChild(document.createTextNode(' '));
917  input.parentNode.appendChild(document.createElement('BR'));
918 
919  // add the extra field
920  var newInput = input.cloneNode(true);
921  var newKeyInput = lastInput.cloneNode(true);
922  var newId = (inputs.length/2);
923  var newKeyId = (inputs.length/2);
924  newKeyInput.onfocus = doExpandList;
925  newKeyInput.value = '';
926  newKeyInput.id = optionItemPrefix+'_options_keys['+newId+']';
927  input.parentNode.appendChild(newKeyInput);
928  input.parentNode.appendChild(document.createTextNode(' '));
929  newInput.onfocus = doExpandList;
930  newInput.value = '';
931  newInput.id = optionItemPrefix+'_options['+newId+']';
932  input.parentNode.appendChild(newInput);
933  input.parentNode.appendChild(document.createTextNode(' '));
934  var delButton = input.nextSibling;
935  while (delButton.tagName != 'BUTTON') {
936  delButton = delButton.nextSibling;
937  }
938  delButton = delButton.cloneNode(true);
939  delButton.onclick = doDeleteRow;
940  input.parentNode.appendChild(delButton);
941  input.parentNode.appendChild(document.createTextNode(' '));
942 
943  input.parentNode.appendChild(document.createTextNode(' '));
944  input.parentNode.appendChild(document.createElement('BR'));
945 
946  }
947 
948  function doDeleteOptionListRow(button)
949  {
950  var input = button.previousSibling;
951  while (input.tagName != 'INPUT') {
952  input = input.previousSibling;
953  }
954 
955  var input2 = input.previousSibling;
956  while (input2.tagName != 'INPUT') {
957  input2 = input2.previousSibling;
958  }
959 
960  if (input.value == '') return;
961 
962  // If the input is disabled, don't respond
963  if (input.disabled) return;
964 
965  // Don't let the option list get down to a single element. Clear the field
966  // instead, but leave it as two elements
967  var inputs = input.parentNode.getElementsByTagName('INPUT');
968  if (inputs.length <= 2) {
969  input.value = '';
970  return;
971  }
972 
973 
974  var brTag = button.nextSibling;
975  while (brTag.tagName != 'BR') {
976  brTag = brTag.nextSibling;
977  }
978  button.parentNode.removeChild(input2);
979  button.parentNode.removeChild(input);
980  button.parentNode.removeChild(brTag);
981  button.parentNode.removeChild(button);
982  }
983 
984  // attach the event handlers
985  var optionList = document.getElementById('option-list-<?php echo $prefix; ?>');
986  var inputs = optionList.getElementsByTagName('INPUT');
987  for (var j=0; j < inputs.length; j++) {
988  inputs[j].onfocus = doExpandList;
989  }
990  var buttons = optionList.getElementsByTagName('BUTTON');
991  for (var j=0; j < buttons.length; j++) {
992  buttons[j].onclick = doDeleteRow;
993  }
994 
995  lastOrder = <?php echo $order; ?>;
996 
997  </script>
998  <?php
999  } else {
1000  if (count($values) > 0) {
1001  echo '<ul>';
1002  foreach ($values as $value) {
1003  if (!empty($value)) {
1004  echo '<li>'.html_entity_decode($value).'</li>';
1005  }//end if
1006  }//end foreach
1007  echo '</ul>';
1008  }//end if
1009  }//end if
1010 
1011  }//end _paintOptionValue()
1012 
1013 
1026  function _printOptionField($key, $value, $order, $prefix, $size='10')
1027  {
1028  // The order is key1=0, value1=1, key2=2, value2=3 etc. This is just the way they are ordered
1029  $current_button = ($order * 2) + 1;
1030 
1031  // Cut the key field down to half the value field
1032  $key_size = $size / 2;
1033 
1034  // Show the field
1035  ?>
1036  <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; ?>" />
1037  <input type="text" name="<?php echo $prefix; ?>_options[]" value="<?php echo $value; ?>" id="<?php echo $prefix; ?>_options[<?php echo $order; ?>]" size="<?=$size; ?>" />
1038  <button type="button" tabindex="99999" class="delete-button">&nbsp;</button>
1039  <br />
1040  <?php
1041 
1042  }//end _printOptionField()
1043 
1044 
1045 }//end class
1046 
1047 ?>