dolibarr 24.0.0-beta
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';
55if (GETPOST('lang', 'aZ09')) {
56 $langs->setDefaultLang(GETPOST('lang', 'aZ09')); // If language was forced on URL by the main.inc.php
57}
58
59$langs->loadLangs(array("main", "other"));
60
61$action = GETPOST('action', 'aZ09');
62
63/*$right = ($langs->trans("DIRECTION") == 'rtl' ? 'left' : 'right');
64$left = ($langs->trans("DIRECTION") == 'rtl' ? 'right' : 'left');*/
65
66
67/*
68 * Actions
69 */
70
71if ($action == 'redirect') { // Test on permission not required here. Test will be done on the targeted page.
73
74 $url = GETPOST('url');
75 $url = dol_sanitizeUrl($url);
76 //$url = preg_replace('/^http(s?):\/\//i', '', $url);
77
78 //var_dump($url);
79
80 $tmpurlrootwithouthttp = preg_replace('/^http(s?):\/\//i', '', DOL_MAIN_URL_ROOT);
81 //var_dump($dolibarr_main_url_root);
82 //var_dump(DOL_MAIN_URL_ROOT);
83 //var_dump($tmpurlrootwithouthttp);
84 $url = preg_replace('/'.preg_quote($dolibarr_main_url_root, '/').'/', '', $url);
85 $url = preg_replace('/'.preg_quote(DOL_MAIN_URL_ROOT, '/').'/', '', $url);
86 $url = preg_replace('/'.preg_quote($tmpurlrootwithouthttp, '/').'/', '', $url);
87 $urlrelativeforredirect = (DOL_URL_ROOT.(preg_match('/\//', $url) ? '' : '/').$url);
88 //$urlrelativeforredirectwithoutparam = preg_replace('/\?.*$/', '', $urlrelativeforredirect);
89 //var_dump($urlrelativeforredirect);
90
91 dol_syslog("Ask search form to redirect on URL: ".$urlrelativeforredirect);
92 header("Location: ".$urlrelativeforredirect);
93 exit;
94}
95
96
97/*
98 * View
99 */
100
101// Important: Following code is to avoid page request by browser and PHP CPU at each Dolibarr page access.
102if (GETPOSTINT('cache')) {
103 header('Cache-Control: max-age='.GETPOSTINT('cache').', public');
104 // For a .php, we must set an Expires to avoid to have it forced to an expired value by the web server
105 header('Expires: '.gmdate('D, d M Y H:i:s', dol_now('gmt') + GETPOSTINT('cache')).' GMT');
106 // HTTP/1.0
107 header('Pragma: token=public');
108} else {
109 // HTTP/1.0
110 header('Cache-Control: no-cache');
111}
112
113$title = $langs->trans("Search");
114
115// URL http://mydolibarr/core/search_page?dol_use_jmobile=1 can be used for tests
116$head = '<!-- Quick access -->'."\n"; // This is used by DoliDroid to know page is a search page
117$arrayofjs = array();
118$arrayofcss = array();
119top_htmlhead($head, $title, 0, 0, $arrayofjs, $arrayofcss);
120
121
122
123print '<body>'."\n";
124print '<div>';
125//print '<br>';
126
127// Instantiate hooks of thirdparty module
128$hookmanager->initHooks(array('searchform'));
129
130// Define $searchform
131$searchform = '';
132
133if ($conf->use_javascript_ajax && 1 == 2) { // select2 is not best with smartphone @phan-suppress-current-line PhanPluginBothLiteralsBinaryOp
134 if (!is_object($form)) {
135 $form = new Form($db);
136 }
137 $selected = '-1';
138 $searchform .= '<br><br>'.$form->selectArrayAjax('searchselectcombo', DOL_URL_ROOT.'/core/ajax/selectsearchbox.php', $selected, '', '', 0, 1, 'minwidth300', 1, $langs->trans("Search"), 0);
139} else {
140 $usedbyinclude = 1; // Used into next include
141 $showtitlebefore = GETPOSTINT('showtitlebefore');
142 $arrayresult = array();
143 include DOL_DOCUMENT_ROOT.'/core/ajax/selectsearchbox.php';
144
145 $i = 0;
146 $accesskeyalreadyassigned = array();
147 foreach ($arrayresult as $key => $val) { // @phan-suppress-current-line PhanEmptyForeach
148 $tmp = explode('?', $val['url']);
149 $urlaction = $tmp[0];
150 $keysearch = 'search_all';
151
152 $accesskey = '';
153 if (empty($accesskeyalreadyassigned[$val['label'][0]])) {
154 $accesskey = $val['label'][0]; // First char of string
155 $accesskeyalreadyassigned[$accesskey] = $accesskey;
156 }
157
158 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
159 $searchform .= printSearchForm($urlaction, $urlaction, $val['label'], 'minwidth200', $keysearch, $accesskey, $key, $val['img'], $showtitlebefore, ($i > 0 ? 0 : 1));
160
161 $i++;
162 }
163}
164
165
166// Execute hook printSearchForm
167$parameters = array('searchform' => $searchform);
168$reshook = $hookmanager->executeHooks('printSearchForm', $parameters); // Note that $action and $object may have been modified by some hooks
169if (empty($reshook)) {
170 $searchform .= $hookmanager->resPrint;
171} else {
172 $searchform = $hookmanager->resPrint;
173}
174
175$searchform .= '<br>';
176
177
178// Add search on URL
179if (!empty($conf->dol_use_jmobile)) {
180 $ret = '';
181 $ret .= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST" class="searchform nowraponall tagtr">';
182 $ret .= '<input type="hidden" name="token" value="'.newToken().'">';
183 $ret .= '<input type="hidden" name="savelogin" value="'.dol_escape_htmltag($user->login).'">';
184 $ret .= '<input type="hidden" name="action" value="redirect">';
185 $ret .= '<div class="tagtd">';
186 $ret .= img_picto('', 'url', '', 0, 0, 0, '', 'paddingright width20');
187 $ret .= '<input type="text" class="flat minwidth200"';
188 $ret .= ' style="background-repeat: no-repeat; background-position: 3px;"';
189 $ret .= ' placeholder="'.strip_tags($langs->trans("OrPasteAnURL")).'"';
190 $ret .= ' name="url" id="url" />';
191 $ret .= '<button type="submit" class="button bordertransp nohover" style="padding-top: 4px; padding-bottom: 4px; padding-left: 6px; padding-right: 6px">';
192 $ret .= '<span class="fa fa-search"></span>';
193 $ret .= '</button>';
194 $ret .= '</div>';
195 $ret .= "</form>\n";
196
197 $searchform .= $ret;
198}
199
200
201// Show all forms
202print "\n";
203print "<!-- Begin SearchForm -->\n";
204print '<div class="center"><div class="center" style="padding: 30px;">';
205print '<style>.menu_titre { padding-top: 7px; }</style>';
206print '<div id="blockvmenusearch" class="tagtable center searchpage">'."\n";
207print $searchform;
208print '</div>'."\n";
209print '</div></div>';
210print "\n<!-- End SearchForm -->\n";
211
212
213print '</div>';
214print '</body></html>'."\n";
215
216$db->close();
global $dolibarr_main_url_root
Class to manage generation of HTML components Only common components must be here.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
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.