BxBaseSearch.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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 DolphinCore Dolphin 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. $aValue = isset($_GET['type']) ? bx_process_input($_GET['type']) : array_keys($aValues);
  30. $sIdForm = $this->_sIdForm . ($this->_bLiveSearch ? $this->_sSuffixLiveSearch : '');
  31. $sIdResults = $this->_sIdResults . ($this->_bLiveSearch ? $this->_sSuffixLiveSearch : '');
  32. $sIdLoadingContainer = $this->_bLiveSearch ? $sIdResults : $sIdForm;
  33. $sJsParams = "5, '#{$sIdForm}', '#{$sIdResults}', '#{$sIdLoadingContainer}', '{$this->_bLiveSearch}'";
  34. $aForm = array(
  35. 'form_attrs' => array(
  36. 'id' => $sIdForm,
  37. 'action' => BX_DOL_URL_ROOT . 'searchKeyword.php',
  38. 'method' => 'post',
  39. ),
  40. 'csrf' => array(
  41. 'disable' => true,
  42. ),
  43. 'inputs' => array(
  44. 'live_search' => array(
  45. 'type' => 'hidden',
  46. 'name' => 'live_search',
  47. 'value' => $this->_bLiveSearch ? 1 : 0,
  48. ),
  49. 'section' => array(
  50. 'type' => 'checkbox_set',
  51. 'name' => 'section',
  52. 'caption' => _t('_Section'),
  53. 'values' => $aValues,
  54. 'value' => $aValue,
  55. ),
  56. 'keyword' => array(
  57. 'type' => 'text',
  58. 'name' => 'keyword',
  59. 'caption' => _t('_Keyword'),
  60. 'value' => bx_get('keyword') ? bx_process_input(bx_get('keyword')) : '',
  61. ),
  62. 'search' => array(
  63. 'type' => 'submit',
  64. 'name' => 'search',
  65. 'value' => _t('_Search'),
  66. )
  67. )
  68. );
  69. if ($this->_bLiveSearch) {
  70. unset($aForm['inputs']['section']);
  71. unset($aForm['inputs']['search']);
  72. unset($aForm['inputs']['keyword']['caption']);
  73. $aForm['inputs']['keyword']['attrs']['placeholder'] = _t('_sys_search_placeholder');
  74. $aForm['inputs']['keyword']['attrs']['onkeypress'] = "return bx_search_on_type(event, $sJsParams);";
  75. $aForm['inputs']['keyword']['attrs']['onpaste'] = $aForm['inputs']['keyword']['attrs']['onkeypress'];
  76. }
  77. bx_import('BxTemplFormView');
  78. $oForm = new BxTemplFormView($aForm);
  79. $sForm = $oForm->getCode();
  80. if (!$this->_bLiveSearch) {
  81. bx_import('BxTemplPaginate');
  82. $o = new BxTemplPaginate(array());
  83. $o->addCssJs();
  84. }
  85. return '<div class="bx-page-block-container bx-def-padding-topbottom bx-clearfix">' . DesignBoxContent($sTitle, $sForm, $iDesignBoxTemplate) . '</div>';
  86. }
  87. public function getResultsContainer($sCode = '')
  88. {
  89. $sIdResults = $this->_sIdResults . ($this->_bLiveSearch ? $this->_sSuffixLiveSearch : '');
  90. return '<div id="' . $sIdResults . '">' . $sCode . '</div>';
  91. }
  92. }
  93. /** @} */