BxBaseSearch.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup UnaBaseView UNA Base Representation Classes
  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. if (!is_array($aChoice) && $aChoice != '')
  19. $aChoice = array($aChoice);
  20. parent::__construct($aChoice);
  21. $this->_oTemplate = $oTemplate ? $oTemplate : BxDolTemplate::getInstance();
  22. }
  23. public function getForm($iDesignBoxTemplate = BX_DB_PADDING_DEF, $sTitle = false)
  24. {
  25. if ($this->_sMetaType || $this->_sCategoryObject)
  26. return '';
  27. if (false === $sTitle)
  28. $sTitle = _t( "_Search");
  29. $aValues = array_merge(array('' => _t('_search_in_all_section')), $this->getKeyTitlesPairs());
  30. if (bx_get('type'))
  31. $aValue = bx_process_input(bx_get('type'));
  32. elseif (bx_get('section'))
  33. $aValue = bx_process_input(bx_get('section'));
  34. else
  35. $aValue = '';
  36. $sIdForm = $this->_sIdForm . ($this->_bLiveSearch ? $this->_sSuffixLiveSearch : '');
  37. $sIdResults = $this->_sIdResults . ($this->_bLiveSearch ? $this->_sSuffixLiveSearch : '');
  38. $sIdLoadingContainer = $this->_bLiveSearch ? $sIdResults : $sIdForm;
  39. $sJsParams = "5, '#{$sIdForm}', '#{$sIdResults}', '#{$sIdLoadingContainer}', '{$this->_bLiveSearch}'";
  40. $aForm = array(
  41. 'form_attrs' => array(
  42. 'id' => $sIdForm,
  43. 'action' => BX_DOL_URL_ROOT . 'searchKeyword.php',
  44. 'method' => 'post',
  45. ),
  46. 'params' => array(
  47. 'csrf' => array(
  48. 'disable' => true,
  49. ),
  50. ),
  51. 'inputs' => array(
  52. 'live_search' => array(
  53. 'type' => 'hidden',
  54. 'name' => 'live_search',
  55. 'value' => $this->_bLiveSearch ? 1 : 0,
  56. ),
  57. 'section' => array(
  58. 'type' => 'select',
  59. 'name' => 'section',
  60. 'caption' => _t('_Section'),
  61. 'values' => $aValues,
  62. 'value' => $aValue,
  63. ),
  64. 'keyword' => array(
  65. 'type' => 'text',
  66. 'name' => 'keyword',
  67. 'caption' => _t('_Keyword'),
  68. 'value' => bx_get('keyword') ? bx_process_input(bx_get('keyword')) : '',
  69. ),
  70. 'search' => array(
  71. 'type' => 'submit',
  72. 'name' => 'search',
  73. 'value' => _t('_Search'),
  74. )
  75. )
  76. );
  77. if ($this->_bLiveSearch) {
  78. unset($aForm['inputs']['section']);
  79. unset($aForm['inputs']['search']);
  80. unset($aForm['inputs']['keyword']['caption']);
  81. $aForm['inputs']['keyword']['attrs']['placeholder'] = _t('_sys_search_placeholder');
  82. $aForm['inputs']['keyword']['attrs']['onkeypress'] = "return bx_search_on_type(event, $sJsParams);";
  83. $aForm['inputs']['keyword']['attrs']['onpaste'] = $aForm['inputs']['keyword']['attrs']['onkeypress'];
  84. }
  85. $oForm = new BxTemplFormView($aForm);
  86. $sForm = $oForm->getCode();
  87. if (!$this->_bLiveSearch) {
  88. $o = new BxTemplPaginate(array());
  89. $o->addCssJs();
  90. }
  91. return '<div class="bx-page-block-container bx-def-padding-sec-topbottom bx-clearfix">' . DesignBoxContent($sTitle, $sForm, $iDesignBoxTemplate) . '</div>';
  92. }
  93. public function getResultsContainer($sCode = '')
  94. {
  95. $sIdResults = $this->_sIdResults . ($this->_bLiveSearch ? $this->_sSuffixLiveSearch : '');
  96. return '<div id="' . $sIdResults . '">' . $sCode . '</div>';
  97. }
  98. protected function getKeyTitlesPairs ()
  99. {
  100. $a = array();
  101. foreach ($this->aClasses as $sKey => $r)
  102. if ($this->_sMetaType || $r['GlobalSearch'])
  103. $a[$sKey] = _t($r['title']);
  104. return $a;
  105. }
  106. }
  107. /** @} */