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