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