search_page.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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->loadLangs(array("main", "other"));
  44. $action = GETPOST('action', 'aZ09');
  45. /*$right = ($langs->trans("DIRECTION") == 'rtl' ? 'left' : 'right');
  46. $left = ($langs->trans("DIRECTION") == 'rtl' ? 'right' : 'left');*/
  47. /*
  48. * Actions
  49. */
  50. if ($action == 'redirect') {
  51. global $dolibarr_main_url_root;
  52. $url = GETPOST('url');
  53. $url = dol_sanitizeUrl($url);
  54. //$url = preg_replace('/^http(s?):\/\//i', '', $url);
  55. //var_dump($url);
  56. $tmpurlrootwithouthttp = preg_replace('/^http(s?):\/\//i', '', DOL_MAIN_URL_ROOT);
  57. //var_dump($dolibarr_main_url_root);
  58. //var_dump(DOL_MAIN_URL_ROOT);
  59. //var_dump($tmpurlrootwithouthttp);
  60. $url = preg_replace('/'.preg_quote($dolibarr_main_url_root, '/').'/', '', $url);
  61. $url = preg_replace('/'.preg_quote(DOL_MAIN_URL_ROOT, '/').'/', '', $url);
  62. $url = preg_replace('/'.preg_quote($tmpurlrootwithouthttp, '/').'/', '', $url);
  63. $urlrelativeforredirect = (DOL_URL_ROOT.(preg_match('/\//', $url) ? '' : '/').$url);
  64. //$urlrelativeforredirectwithoutparam = preg_replace('/\?.*$/', '', $urlrelativeforredirect);
  65. //var_dump($urlrelativeforredirect);
  66. dol_syslog("Ask search form to redirect on URL: ".$urlrelativeforredirect);
  67. header("Location: ".$urlrelativeforredirect);
  68. exit;
  69. }
  70. /*
  71. * View
  72. */
  73. // Important: Following code is to avoid page request by browser and PHP CPU at each Dolibarr page access.
  74. if (empty($dolibarr_nocache) && GETPOST('cache', 'int')) {
  75. header('Cache-Control: max-age='.GETPOST('cache', 'int').', public');
  76. // For a .php, we must set an Expires to avoid to have it forced to an expired value by the web server
  77. header('Expires: '.gmdate('D, d M Y H:i:s', dol_now('gmt') + GETPOST('cache', 'int')).' GMT');
  78. // HTTP/1.0
  79. header('Pragma: token=public');
  80. } else {
  81. // HTTP/1.0
  82. header('Cache-Control: no-cache');
  83. }
  84. $title = $langs->trans("Search");
  85. // URL http://mydolibarr/core/search_page?dol_use_jmobile=1 can be used for tests
  86. $head = '<!-- Quick access -->'."\n"; // This is used by DoliDroid to know page is a search page
  87. $arrayofjs = array();
  88. $arrayofcss = array();
  89. top_htmlhead($head, $title, 0, 0, $arrayofjs, $arrayofcss);
  90. print '<body>'."\n";
  91. print '<div>';
  92. //print '<br>';
  93. $nbofsearch = 0;
  94. // Instantiate hooks of thirdparty module
  95. $hookmanager->initHooks(array('searchform'));
  96. // Define $searchform
  97. $searchform = '';
  98. if ($conf->use_javascript_ajax && 1 == 2) { // select2 is not best with smartphone
  99. if (!is_object($form)) {
  100. $form = new Form($db);
  101. }
  102. $selected = -1;
  103. $searchform .= '<br><br>'.$form->selectArrayAjax('searchselectcombo', DOL_URL_ROOT.'/core/ajax/selectsearchbox.php', $selected, '', '', 0, 1, 'minwidth300', 1, $langs->trans("Search"), 0);
  104. } else {
  105. $usedbyinclude = 1; // Used into next include
  106. $showtitlebefore = GETPOST('showtitlebefore', 'int');
  107. $arrayresult = array();
  108. include DOL_DOCUMENT_ROOT.'/core/ajax/selectsearchbox.php';
  109. $i = 0;
  110. $accesskeyalreadyassigned = array();
  111. foreach ($arrayresult as $key => $val) {
  112. $tmp = explode('?', $val['url']);
  113. $urlaction = $tmp[0];
  114. $keysearch = 'search_all';
  115. $accesskey = '';
  116. if (empty($accesskeyalreadyassigned[$val['label'][0]])) {
  117. $accesskey = $val['label'][0]; // First char of string
  118. $accesskeyalreadyassigned[$accesskey] = $accesskey;
  119. }
  120. $searchform .= printSearchForm($urlaction, $urlaction, $val['label'], 'minwidth200', $keysearch, $accesskey, $key, $val['img'], $showtitlebefore, ($i > 0 ? 0 : 1));
  121. $i++;
  122. }
  123. }
  124. // Execute hook printSearchForm
  125. $parameters = array('searchform'=>$searchform);
  126. $reshook = $hookmanager->executeHooks('printSearchForm', $parameters); // Note that $action and $object may have been modified by some hooks
  127. if (empty($reshook)) {
  128. $searchform .= $hookmanager->resPrint;
  129. } else {
  130. $searchform = $hookmanager->resPrint;
  131. }
  132. $searchform .= '<br>';
  133. // Add search on URL
  134. $ret = '';
  135. $ret .= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST" class="searchform nowraponall tagtr">';
  136. $ret .= '<input type="hidden" name="token" value="'.newToken().'">';
  137. $ret .= '<input type="hidden" name="savelogin" value="'.dol_escape_htmltag($user->login).'">';
  138. $ret .= '<input type="hidden" name="action" value="redirect">';
  139. $ret .= '<div class="tagtd">';
  140. $ret .= img_picto('', 'url', '', false, 0, 0, '', 'paddingright width20');
  141. $ret .= '<input type="text" class="flat minwidth200"';
  142. $ret .= ' style="background-repeat: no-repeat; background-position: 3px;"';
  143. $ret .= ' placeholder="'.strip_tags($langs->trans("OrPasteAnURL")).'"';
  144. $ret .= ' name="url" id="url" />';
  145. $ret .= '<button type="submit" class="button bordertransp" style="padding-top: 4px; padding-bottom: 4px; padding-left: 6px; padding-right: 6px">';
  146. $ret .= '<span class="fa fa-search"></span>';
  147. $ret .= '</button>';
  148. $ret .= '</div>';
  149. $ret .= "</form>\n";
  150. $searchform .= $ret;
  151. // Show all forms
  152. print "\n";
  153. print "<!-- Begin SearchForm -->\n";
  154. print '<div class="center"><div class="center" style="padding: 6px;">';
  155. print '<style>.menu_titre { padding-top: 7px; }</style>';
  156. print '<div id="blockvmenusearch" class="tagtable center searchpage">'."\n";
  157. print $searchform;
  158. print '</div>'."\n";
  159. print '</div></div>';
  160. print "\n<!-- End SearchForm -->\n";
  161. print '</div>';
  162. print '</body></html>'."\n";
  163. $db->close();