BxBaseSearch.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
  4. * CC-BY License - http://creativecommons.org/licenses/by/3.0/
  5. *
  6. * @defgroup TridentCore Trident Core
  7. * @{
  8. */
  9. require_once(BX_DIRECTORY_PATH_INC . "design.inc.php");
  10. class BxBaseSearch extends BxDolSearch
  11. {
  12. protected $_oTemplate;
  13. protected $_sIdForm = 'sys_search_form';
  14. protected $_sIdResults = 'sys_search_results';
  15. protected $_sSuffixLiveSearch = '_quick';
  16. public function __construct($aChoice, $oTemplate)
  17. {
  18. parent::__construct($aChoice);
  19. $this->_oTemplate = $oTemplate ? $oTemplate : BxDolTemplate::getInstance();
  20. }
  21. public function getForm($iDesignBoxTemplate = BX_DB_PADDING_DEF, $sTitle = false)
  22. {
  23. if ($this->_sMetaType)
  24. return '';
  25. if (false === $sTitle)
  26. $sTitle = _t( "_Search");
  27. $aValues = $this->getKeyTitlesPairs ();
  28. if (bx_get('type'))
  29. $aValue = bx_process_input(bx_get('type'));
  30. elseif (bx_get('section'))
  31. $aValue = bx_process_input(bx_get('section'));
  32. else
  33. $aValue = array_keys($aValues);
  34. $sIdForm = $this->_sIdForm . ($this->_bLiveSearch ? $this->_sSuffixLiveSearch : '');
  35. $sIdResults = $this->_sIdResults . ($this->_bLiveSearch ? $this->_sSuffixLiveSearch : '');
  36. $sIdLoadingContainer = $this->_bLiveSearch ? $sIdResults : $sIdForm;
  37. $sJsParams = "5, '#{$sIdForm}', '#{$sIdResults}', '#{$sIdLoadingContainer}', '{$this->_bLiveSearch}'";
  38. $aForm = array(
  39. 'form_attrs' => array(
  40. 'id' => $sIdForm,
  41. 'action' => BX_DOL_URL_ROOT . 'searchKeyword.php',
  42. 'method' => 'post',
  43. ),
  44. 'csrf' => array(
  45. 'disable' => true,
  46. ),
  47. 'inputs' => array(
  48. 'live_search' => array(
  49. 'type' => 'hidden',
  50. 'name' => 'live_search',
  51. 'value' => $this->_bLiveSearch ? 1 : 0,
  52. ),
  53. 'section' => array(
  54. 'type' => 'checkbox_set',
  55. 'name' => 'section',
  56. 'caption' => _t('_Section'),
  57. 'values' => $aValues,
  58. 'value' => $aValue,
  59. ),
  60. 'keyword' => array(
  61. 'type' => 'text',
  62. 'name' => 'keyword',
  63. 'caption' => _t('_Keyword'),
  64. 'value' => bx_get('keyword') ? bx_process_input(bx_get('keyword')) : '',
  65. ),
  66. 'search' => array(
  67. 'type' => 'submit',
  68. 'name' => 'search',
  69. 'value' => _t('_Search'),
  70. )
  71. )
  72. );
  73. if ($this->_bLiveSearch) {
  74. unset($aForm['inputs']['section']);
  75. unset($aForm['inputs']['search']);
  76. unset($aForm['inputs']['keyword']['caption']);
  77. $aForm['inputs']['keyword']['attrs']['placeholder'] = _t('_sys_search_placeholder');
  78. $aForm['inputs']['keyword']['attrs']['onkeypress'] = "return bx_search_on_type(event, $sJsParams);";
  79. $aForm['inputs']['keyword']['attrs']['onpaste'] = $aForm['inputs']['keyword']['attrs']['onkeypress'];
  80. }
  81. $oForm = new BxTemplFormView($aForm);
  82. $sForm = $oForm->getCode();
  83. if (!$this->_bLiveSearch) {
  84. $o = new BxTemplPaginate(array());
  85. $o->addCssJs();
  86. }
  87. return '<div class="bx-page-block-container bx-def-padding-topbottom bx-clearfix">' . DesignBoxContent($sTitle, $sForm, $iDesignBoxTemplate) . '</div>';
  88. }
  89. public function getResultsContainer($sCode = '')
  90. {
  91. $sIdResults = $this->_sIdResults . ($this->_bLiveSearch ? $this->_sSuffixLiveSearch : '');
  92. return '<div id="' . $sIdResults . '">' . $sCode . '</div>';
  93. }
  94. }
  95. /** @} */