search_page.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <?php
  2. /* Copyright (C) 2005-2017 Laurent Destailleur <eldy@users.sourceforge.net>
  3. *
  4. * This file is a modified version of datepicker.php from phpBSM to fix some
  5. * bugs, to add new features and to dramatically increase speed.
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  19. */
  20. /**
  21. * \file htdocs/core/search_page.php
  22. * \brief File to return a page with the complete search form (all search input fields)
  23. */
  24. //if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER','1'); // Not disabled cause need to load personalized language
  25. //if (! defined('NOREQUIREDB')) define('NOREQUIREDB','1'); // Not disabled cause need to load personalized language
  26. //if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC','1');
  27. //if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN','1'); // Not disabled cause need to do translations
  28. if (!defined('NOCSRFCHECK')) {
  29. define('NOCSRFCHECK', 1);
  30. }
  31. if (!defined('NOTOKENRENEWAL')) {
  32. define('NOTOKENRENEWAL', 1);
  33. }
  34. //if (! defined('NOLOGIN')) define('NOLOGIN',1); // Not disabled cause need to load personalized language
  35. if (!defined('NOREQUIREMENU')) {
  36. define('NOREQUIREMENU', 1);
  37. }
  38. //if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML',1);
  39. require_once '../main.inc.php';
  40. if (GETPOST('lang', 'aZ09')) {
  41. $langs->setDefaultLang(GETPOST('lang', 'aZ09')); // If language was forced on URL by the main.inc.php
  42. }
  43. $langs->load("main");
  44. $right = ($langs->trans("DIRECTION") == 'rtl' ? 'left' : 'right');
  45. $left = ($langs->trans("DIRECTION") == 'rtl' ? 'right' : 'left');
  46. /*
  47. * View
  48. */
  49. // Important: Following code is to avoid page request by browser and PHP CPU at each Dolibarr page access.
  50. if (empty($dolibarr_nocache) && GETPOST('cache', 'int')) {
  51. header('Cache-Control: max-age='.GETPOST('cache', 'int').', public');
  52. // For a .php, we must set an Expires to avoid to have it forced to an expired value by the web server
  53. header('Expires: '.gmdate('D, d M Y H:i:s', dol_now('gmt') + GETPOST('cache', 'int')).' GMT');
  54. // HTTP/1.0
  55. header('Pragma: token=public');
  56. } else {
  57. // HTTP/1.0
  58. header('Cache-Control: no-cache');
  59. }
  60. $title = $langs->trans("Search");
  61. // URL http://mydolibarr/core/search_page?dol_use_jmobile=1 can be used for tests
  62. $head = '<!-- Quick access -->'."\n"; // This is used by DoliDroid to know page is a search page
  63. $arrayofjs = array();
  64. $arrayofcss = array();
  65. top_htmlhead($head, $title, 0, 0, $arrayofjs, $arrayofcss);
  66. print '<body>'."\n";
  67. print '<div>';
  68. //print '<br>';
  69. $nbofsearch = 0;
  70. // Instantiate hooks of thirdparty module
  71. $hookmanager->initHooks(array('searchform'));
  72. // Define $searchform
  73. $searchform = '';
  74. if ($conf->use_javascript_ajax && 1 == 2) { // select2 is not best with smartphone
  75. if (!is_object($form)) {
  76. $form = new Form($db);
  77. }
  78. $selected = -1;
  79. $searchform .= '<br><br>'.$form->selectArrayAjax('searchselectcombo', DOL_URL_ROOT.'/core/ajax/selectsearchbox.php', $selected, '', '', 0, 1, 'minwidth300', 1, $langs->trans("Search"), 0);
  80. } else {
  81. $usedbyinclude = 1; // Used into next include
  82. $showtitlebefore = GETPOST('showtitlebefore', 'int');
  83. $arrayresult = array();
  84. include DOL_DOCUMENT_ROOT.'/core/ajax/selectsearchbox.php';
  85. $i = 0;
  86. $accesskeyalreadyassigned = array();
  87. foreach ($arrayresult as $key => $val) {
  88. $tmp = explode('?', $val['url']);
  89. $urlaction = $tmp[0];
  90. $keysearch = 'search_all';
  91. $accesskey = '';
  92. if (!$accesskeyalreadyassigned[$val['label'][0]]) {
  93. $accesskey = $val['label'][0];
  94. $accesskeyalreadyassigned[$accesskey] = $accesskey;
  95. }
  96. $searchform .= printSearchForm($urlaction, $urlaction, $val['label'], 'minwidth200', $keysearch, $accesskey, $key, $val['img'], $showtitlebefore, ($i > 0 ? 0 : 1));
  97. $i++;
  98. }
  99. }
  100. // Execute hook printSearchForm
  101. $parameters = array('searchform'=>$searchform);
  102. $reshook = $hookmanager->executeHooks('printSearchForm', $parameters); // Note that $action and $object may have been modified by some hooks
  103. if (empty($reshook)) {
  104. $searchform .= $hookmanager->resPrint;
  105. } else {
  106. $searchform = $hookmanager->resPrint;
  107. }
  108. print "\n";
  109. print "<!-- Begin SearchForm -->\n";
  110. print '<div class="center"><div class="center" style="padding: 6px;">';
  111. print '<style>.menu_titre { padding-top: 7px; }</style>';
  112. print '<div id="blockvmenusearch" class="tagtable center searchpage">'."\n";
  113. print $searchform;
  114. print '</div>'."\n";
  115. print '</div></div>';
  116. print "\n<!-- End SearchForm -->\n";
  117. print '</div>';
  118. print '</body></html>'."\n";
  119. $db->close();