dolibarr 23.0.4
search_page.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (C) 2005-2017 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
5 * Copyright (C) 2025 MDW <mdeweerd@users.noreply.github.com>
6 *
7 * This file is a modified version of datepicker.php from phpBSM to fix some
8 * bugs, to add new features and to dramatically increase speed.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 */
23
29//if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER','1'); // Not disabled cause need to load personalized language
30//if (! defined('NOREQUIREDB')) define('NOREQUIREDB','1'); // Not disabled cause need to load personalized language
31//if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC','1');
32//if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN','1'); // Not disabled cause need to do translations
33if (!defined('NOCSRFCHECK')) {
34 define('NOCSRFCHECK', 1);
35}
36if (!defined('NOTOKENRENEWAL')) {
37 define('NOTOKENRENEWAL', 1);
38}
39//if (! defined('NOLOGIN')) define('NOLOGIN',1); // Not disabled cause need to load personalized language
40if (!defined('NOREQUIREMENU')) {
41 define('NOREQUIREMENU', 1);
42}
43//if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML',1);
44
45require_once '../main.inc.php';
57if (GETPOST('lang', 'aZ09')) {
58 $langs->setDefaultLang(GETPOST('lang', 'aZ09')); // If language was forced on URL by the main.inc.php
59}
60
61$langs->loadLangs(array("main", "other"));
62
63$action = GETPOST('action', 'aZ09');
64
65/*$right = ($langs->trans("DIRECTION") == 'rtl' ? 'left' : 'right');
66$left = ($langs->trans("DIRECTION") == 'rtl' ? 'right' : 'left');*/
67
68
69/*
70 * Actions
71 */
72
73if ($action == 'redirect') { // Test on permission not required here. Test will be done on the targeted page.
75
76 $url = GETPOST('url');
77 $url = dol_sanitizeUrl($url);
78 //$url = preg_replace('/^http(s?):\/\//i', '', $url);
79
80 //var_dump($url);
81
82 $tmpurlrootwithouthttp = preg_replace('/^http(s?):\/\//i', '', DOL_MAIN_URL_ROOT);
83 //var_dump($dolibarr_main_url_root);
84 //var_dump(DOL_MAIN_URL_ROOT);
85 //var_dump($tmpurlrootwithouthttp);
86 $url = preg_replace('/'.preg_quote($dolibarr_main_url_root, '/').'/', '', $url);
87 $url = preg_replace('/'.preg_quote(DOL_MAIN_URL_ROOT, '/').'/', '', $url);
88 $url = preg_replace('/'.preg_quote($tmpurlrootwithouthttp, '/').'/', '', $url);
89 // After the removal of the root url, what remains must be a path inside this site. We remove the leading slashes, or a pasted url
90 // like https://host//evil.com would give //evil.com, an url that the browser takes for another site when DOL_URL_ROOT is empty.
91 $url = ltrim($url, '/\\');
92 $urlrelativeforredirect = DOL_URL_ROOT.'/'.$url;
93 //$urlrelativeforredirectwithoutparam = preg_replace('/\?.*$/', '', $urlrelativeforredirect);
94 //var_dump($urlrelativeforredirect);
95
96 dol_syslog("Ask search form to redirect on URL: ".$urlrelativeforredirect);
97 header("Location: ".$urlrelativeforredirect);
98 exit;
99}
100
101
102/*
103 * View
104 */
105
106// Important: Following code is to avoid page request by browser and PHP CPU at each Dolibarr page access.
107if (empty($dolibarr_nocache) && GETPOSTINT('cache')) {
108 header('Cache-Control: max-age='.GETPOSTINT('cache').', public');
109 // For a .php, we must set an Expires to avoid to have it forced to an expired value by the web server
110 header('Expires: '.gmdate('D, d M Y H:i:s', dol_now('gmt') + GETPOSTINT('cache')).' GMT');
111 // HTTP/1.0
112 header('Pragma: token=public');
113} else {
114 // HTTP/1.0
115 header('Cache-Control: no-cache');
116}
117
118$title = $langs->trans("Search");
119
120// URL http://mydolibarr/core/search_page?dol_use_jmobile=1 can be used for tests
121$head = '<!-- Quick access -->'."\n"; // This is used by DoliDroid to know page is a search page
122$arrayofjs = array();
123$arrayofcss = array();
124top_htmlhead($head, $title, 0, 0, $arrayofjs, $arrayofcss);
125
126
127
128print '<body>'."\n";
129print '<div>';
130//print '<br>';
131
132// Instantiate hooks of thirdparty module
133$hookmanager->initHooks(array('searchform'));
134
135// Define $searchform
136$searchform = '';
137
138if ($conf->use_javascript_ajax && 1 == 2) { // select2 is not best with smartphone @phan-suppress-current-line PhanPluginBothLiteralsBinaryOp
139 if (!is_object($form)) {
140 $form = new Form($db);
141 }
142 $selected = '-1';
143 $searchform .= '<br><br>'.$form->selectArrayAjax('searchselectcombo', DOL_URL_ROOT.'/core/ajax/selectsearchbox.php', $selected, '', '', 0, 1, 'minwidth300', 1, $langs->trans("Search"), 0);
144} else {
145 $usedbyinclude = 1; // Used into next include
146 $showtitlebefore = GETPOSTINT('showtitlebefore');
147 $arrayresult = array();
148 include DOL_DOCUMENT_ROOT.'/core/ajax/selectsearchbox.php';
149
150 $i = 0;
151 $accesskeyalreadyassigned = array();
152 foreach ($arrayresult as $key => $val) { // @phan-suppress-current-line PhanEmptyForeach
153 $tmp = explode('?', $val['url']);
154 $urlaction = $tmp[0];
155 $keysearch = 'search_all';
156
157 $accesskey = '';
158 if (empty($accesskeyalreadyassigned[$val['label'][0]])) {
159 $accesskey = $val['label'][0]; // First char of string
160 $accesskeyalreadyassigned[$accesskey] = $accesskey;
161 }
162
163 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
164 $searchform .= printSearchForm($urlaction, $urlaction, $val['label'], 'minwidth200', $keysearch, $accesskey, $key, $val['img'], $showtitlebefore, ($i > 0 ? 0 : 1));
165
166 $i++;
167 }
168}
169
170
171// Execute hook printSearchForm
172$parameters = array('searchform' => $searchform);
173$reshook = $hookmanager->executeHooks('printSearchForm', $parameters); // Note that $action and $object may have been modified by some hooks
174if (empty($reshook)) {
175 $searchform .= $hookmanager->resPrint;
176} else {
177 $searchform = $hookmanager->resPrint;
178}
179
180$searchform .= '<br>';
181
182
183// Add search on URL
184if (!empty($conf->dol_use_jmobile) || 1) {
185 $ret = '';
186 $ret .= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST" class="searchform nowraponall tagtr">';
187 $ret .= '<input type="hidden" name="token" value="'.newToken().'">';
188 $ret .= '<input type="hidden" name="savelogin" value="'.dol_escape_htmltag($user->login).'">';
189 $ret .= '<input type="hidden" name="action" value="redirect">';
190 $ret .= '<div class="tagtd">';
191 $ret .= img_picto('', 'url', '', 0, 0, 0, '', 'paddingright width20');
192 $ret .= '<input type="text" class="flat minwidth200"';
193 $ret .= ' style="background-repeat: no-repeat; background-position: 3px;"';
194 $ret .= ' placeholder="'.strip_tags($langs->trans("OrPasteAnURL")).'"';
195 $ret .= ' name="url" id="url" />';
196 $ret .= '<button type="submit" class="button bordertransp nohover" style="padding-top: 4px; padding-bottom: 4px; padding-left: 6px; padding-right: 6px">';
197 $ret .= '<span class="fa fa-search"></span>';
198 $ret .= '</button>';
199 $ret .= '</div>';
200 $ret .= "</form>\n";
201
202 $searchform .= $ret;
203}
204
205
206// Show all forms
207print "\n";
208print "<!-- Begin SearchForm -->\n";
209print '<div class="center"><div class="center" style="padding: 30px;">';
210print '<style>.menu_titre { padding-top: 7px; }</style>';
211print '<div id="blockvmenusearch" class="tagtable center searchpage">'."\n";
212print $searchform;
213print '</div>'."\n";
214print '</div></div>';
215print "\n<!-- End SearchForm -->\n";
216
217
218print '</div>';
219print '</body></html>'."\n";
220
221$db->close();
global $dolibarr_main_url_root
Class to manage generation of HTML components Only common components must be here.
dol_now($mode='gmt')
Return date for now.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_sanitizeUrl($stringtoclean, $type=1)
Clean a string to use it as an URL (into a href or src attribute)
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
top_htmlhead($head, $title='', $disablejs=0, $disablehead=0, $arrayofjs=array(), $arrayofcss=array(), $disableforlogin=0, $disablenofollow=0, $disablenoindex=0)
Output html header of a page.
printSearchForm($urlaction, $urlobject, $title, $htmlmorecss, $htmlinputname, $accesskey='', $prefhtmlinputname='', $img='', $showtitlebefore=0, $autofocus=0)
Show a search area.