BxBaseSearch.php 4.0 KB

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