dolibarr 19.0.4
main.inc.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2002-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2003 Xavier Dutoit <doli@sydesy.com>
4 * Copyright (C) 2004-2021 Laurent Destailleur <eldy@users.sourceforge.net>
5 * Copyright (C) 2004 Sebastien Di Cintio <sdicintio@ressource-toi.org>
6 * Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
7 * Copyright (C) 2005-2021 Regis Houssin <regis.houssin@inodbox.com>
8 * Copyright (C) 2011-2014 Philippe Grand <philippe.grand@atoo-net.com>
9 * Copyright (C) 2008 Matteli
10 * Copyright (C) 2011-2016 Juanjo Menent <jmenent@2byte.es>
11 * Copyright (C) 2012 Christophe Battarel <christophe.battarel@altairis.fr>
12 * Copyright (C) 2014-2015 Marcos García <marcosgdf@gmail.com>
13 * Copyright (C) 2015 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
14 * Copyright (C) 2020 Demarest Maxime <maxime@indelog.fr>
15 * Copyright (C) 2020 Charlene Benke <charlie@patas-monkey.com>
16 * Copyright (C) 2021 Frédéric France <frederic.france@netlogic.fr>
17 * Copyright (C) 2021 Alexandre Spangaro <aspangaro@open-dsi.fr>
18 * Copyright (C) 2023 Joachim Küter <git-jk@bloxera.com>
19 * Copyright (C) 2023 Eric Seigne <eric.seigne@cap-rel.fr>
20 *
21 * This program is free software; you can redistribute it and/or modify
22 * it under the terms of the GNU General Public License as published by
23 * the Free Software Foundation; either version 3 of the License, or
24 * (at your option) any later version.
25 *
26 * This program is distributed in the hope that it will be useful,
27 * but WITHOUT ANY WARRANTY; without even the implied warranty of
28 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29 * GNU General Public License for more details.
30 *
31 * You should have received a copy of the GNU General Public License
32 * along with this program. If not, see <https://www.gnu.org/licenses/>.
33 */
34
41//@ini_set('memory_limit', '128M'); // This may be useless if memory is hard limited by your PHP
42
43// For optional tuning. Enabled if environment variable MAIN_SHOW_TUNING_INFO is defined.
44$micro_start_time = 0;
45if (!empty($_SERVER['MAIN_SHOW_TUNING_INFO'])) {
46 list($usec, $sec) = explode(" ", microtime());
47 $micro_start_time = ((float) $usec + (float) $sec);
48 // Add Xdebug code coverage
49 //define('XDEBUGCOVERAGE',1);
50 if (defined('XDEBUGCOVERAGE')) {
51 xdebug_start_code_coverage();
52 }
53}
54
55
64{
65 $newstringnumentity = preg_replace('/;$/', '', $matches[1]);
66 //print ' $newstringnumentity='.$newstringnumentity;
67
68 if (preg_match('/^x/i', $newstringnumentity)) {
69 $newstringnumentity = hexdec(preg_replace('/^x/i', '', $newstringnumentity));
70 }
71
72 // The numeric value we don't want as entities because they encode ascii char, and why using html entities on ascii except for haking ?
73 if (($newstringnumentity >= 65 && $newstringnumentity <= 90) || ($newstringnumentity >= 97 && $newstringnumentity <= 122)) {
74 return chr((int) $newstringnumentity);
75 }
76
77 return '&#'.$matches[1]; // Value will be unchanged because regex was /&#( )/
78}
79
89function testSqlAndScriptInject($val, $type)
90{
91 // Decode string first because a lot of things are obfuscated by encoding or multiple encoding.
92 // So <svg o&#110;load='console.log(&quot;123&quot;)' become <svg onload='console.log(&quot;123&quot;)'
93 // So "&colon;&apos;" become ":'" (due to ENT_HTML5)
94 // So "&Tab;&NewLine;" become ""
95 // So "&lpar;&rpar;" become "()"
96
97 // Loop to decode until no more things to decode.
98 //print "before decoding $val\n";
99 do {
100 $oldval = $val;
101 $val = html_entity_decode($val, ENT_QUOTES | ENT_HTML5); // Decode '&colon;', '&apos;', '&Tab;', '&NewLine', ...
102 // Sometimes we have entities without the ; at end so html_entity_decode does not work but entities is still interpreted by browser.
103 $val = preg_replace_callback('/&#(x?[0-9][0-9a-f]+;?)/i', function ($m) {
104 // Decode '&#110;', ...
105 return realCharForNumericEntities($m); }, $val);
106
107 // We clean html comments because some hacks try to obfuscate evil strings by inserting HTML comments. Example: on<!-- -->error=alert(1)
108 $val = preg_replace('/<!--[^>]*-->/', '', $val);
109 $val = preg_replace('/[\r\n\t]/', '', $val);
110 } while ($oldval != $val);
111 //print "type = ".$type." after decoding: ".$val."\n";
112
113 $inj = 0;
114
115 // We check string because some hacks try to obfuscate evil strings by inserting non printable chars. Example: 'java(ascci09)scr(ascii00)ipt' is processed like 'javascript' (whatever is place of evil ascii char)
116 // We should use dol_string_nounprintableascii but function is not yet loaded/available
117 // Example of valid UTF8 chars:
118 // utf8=utf8mb3: '\x09', '\x0A', '\x0D', '\x7E'
119 // utf8=utf8mb3: '\xE0\xA0\x80'
120 // utf8mb4: '\xF0\x9D\x84\x9E' (but this may be refused by the database insert if pagecode is utf8=utf8mb3)
121 $newval = preg_replace('/[\x00-\x08\x0B-\x0C\x0E-\x1F\x7F]/u', '', $val); // /u operator makes UTF8 valid characters being ignored so are not included into the replace
122
123 // Note that $newval may also be completely empty '' when non valid UTF8 are found.
124 if ($newval != $val) {
125 // If $val has changed after removing non valid UTF8 chars, it means we have an evil string.
126 $inj += 1;
127 }
128 //print 'type='.$type.'-val='.$val.'-newval='.$newval."-inj=".$inj."\n";
129
130 // For SQL Injection (only GET are used to scan for such injection strings)
131 if ($type == 1 || $type == 3) {
132 // Note the \s+ is replaced into \s* because some spaces may have been modified in previous loop
133 $inj += preg_match('/delete\s*from/i', $val);
134 $inj += preg_match('/create\s*table/i', $val);
135 $inj += preg_match('/insert\s*into/i', $val);
136 $inj += preg_match('/select\s*from/i', $val);
137 $inj += preg_match('/into\s*(outfile|dumpfile)/i', $val);
138 $inj += preg_match('/user\s*\‍(/i', $val); // avoid to use function user() or mysql_user() that return current database login
139 $inj += preg_match('/information_schema/i', $val); // avoid to use request that read information_schema database
140 $inj += preg_match('/<svg/i', $val); // <svg can be allowed in POST
141 $inj += preg_match('/update[^&=\w].*set.+=/i', $val); // the [^&=\w] test is to avoid error when request is like action=update&...set... or &updatemodule=...set...
142 $inj += preg_match('/union.+select/i', $val);
143 }
144 if ($type == 3) {
145 // Note the \s+ is replaced into \s* because some spaces may have been modified in previous loop
146 $inj += preg_match('/select|update|delete|truncate|replace|group\s*by|concat|count|from|union/i', $val);
147 }
148 if ($type != 2) { // Not common key strings, so we can check them both on GET and POST
149 $inj += preg_match('/updatexml\‍(/i', $val);
150 $inj += preg_match('/(\.\.%2f)+/i', $val);
151 $inj += preg_match('/\s@@/', $val);
152 }
153 // For XSS Injection done by closing textarea to execute content into a textarea field
154 $inj += preg_match('/<\/textarea/i', $val);
155 // For XSS Injection done by adding javascript with script
156 // This is all cases a browser consider text is javascript:
157 // When it found '<script', 'javascript:', '<style', 'onload\s=' on body tag, '="&' on a tag size with old browsers
158 // All examples on page: http://ha.ckers.org/xss.html#XSScalc
159 // More on https://www.owasp.org/index.php/XSS_Filter_Evasion_Cheat_Sheet
160 $inj += preg_match('/<audio/i', $val);
161 $inj += preg_match('/<embed/i', $val);
162 $inj += preg_match('/<iframe/i', $val);
163 $inj += preg_match('/<object/i', $val);
164 $inj += preg_match('/<script/i', $val);
165 $inj += preg_match('/Set\.constructor/i', $val); // ECMA script 6
166 if (!defined('NOSTYLECHECK')) {
167 $inj += preg_match('/<style/i', $val);
168 }
169 $inj += preg_match('/base\s+href/si', $val);
170 $inj += preg_match('/=data:/si', $val);
171 // List of dom events is on https://www.w3schools.com/jsref/dom_obj_event.asp and https://developer.mozilla.org/en-US/docs/Web/Events
172 $inj += preg_match('/on(mouse|drag|key|load|touch|pointer|select|transition)[a-z]*\s*=/i', $val); // onmousexxx can be set on img or any html tag like <img title='...' onmouseover=alert(1)>
173 $inj += preg_match('/on(abort|after|animation|auxclick|before|blur|bounce|cancel|canplay|canplaythrough|change|click|close|contextmenu|cuechange|copy|cut)[a-z]*\s*=/i', $val);
174 $inj += preg_match('/on(dblclick|drop|durationchange|emptied|end|ended|error|focus|focusin|focusout|formdata|gotpointercapture|hashchange|input|invalid)[a-z]*\s*=/i', $val);
175 $inj += preg_match('/on(lostpointercapture|offline|online|pagehide|pageshow)[a-z]*\s*=/i', $val);
176 $inj += preg_match('/on(paste|pause|play|playing|progress|ratechange|reset|resize|scroll|search|seeked|seeking|show|stalled|start|submit|suspend)[a-z]*\s*=/i', $val);
177 $inj += preg_match('/on(timeupdate|toggle|unload|volumechange|waiting|wheel)[a-z]*\s*=/i', $val);
178 // More not into the previous list
179 $inj += preg_match('/on(repeat|begin|finish)[a-z]*\s*=/i', $val);
180
181 // We refuse html into html because some hacks try to obfuscate evil strings by inserting HTML into HTML. Example: <img on<a>error=alert(1) to bypass test on onerror
182 $tmpval = preg_replace('/<[^<]+>/', '', $val);
183 // List of dom events is on https://www.w3schools.com/jsref/dom_obj_event.asp and https://developer.mozilla.org/en-US/docs/Web/Events
184 $inj += preg_match('/on(mouse|drag|key|load|touch|pointer|select|transition)[a-z]*\s*=/i', $tmpval); // onmousexxx can be set on img or any html tag like <img title='...' onmouseover=alert(1)>
185 $inj += preg_match('/on(abort|after|animation|auxclick|before|blur|bounce|cancel|canplay|canplaythrough|change|click|close|contextmenu|cuechange|copy|cut)[a-z]*\s*=/i', $tmpval);
186 $inj += preg_match('/on(dblclick|drop|durationchange|emptied|end|ended|error|focus|focusin|focusout|formdata|gotpointercapture|hashchange|input|invalid)[a-z]*\s*=/i', $tmpval);
187 $inj += preg_match('/on(lostpointercapture|offline|online|pagehide|pageshow)[a-z]*\s*=/i', $tmpval);
188 $inj += preg_match('/on(paste|pause|play|playing|progress|ratechange|reset|resize|scroll|search|seeked|seeking|show|stalled|start|submit|suspend)[a-z]*\s*=/i', $tmpval);
189 $inj += preg_match('/on(timeupdate|toggle|unload|volumechange|waiting|wheel)[a-z]*\s*=/i', $tmpval);
190 // More not into the previous list
191 $inj += preg_match('/on(repeat|begin|finish)[a-z]*\s*=/i', $tmpval);
192
193 //$inj += preg_match('/on[A-Z][a-z]+\*=/', $val); // To lock event handlers onAbort(), ...
194 $inj += preg_match('/&#58;|&#0000058|&#x3A/i', $val); // refused string ':' encoded (no reason to have it encoded) to lock 'javascript:...'
195 $inj += preg_match('/j\s*a\s*v\s*a\s*s\s*c\s*r\s*i\s*p\s*t\s*:/i', $val);
196 $inj += preg_match('/vbscript\s*:/i', $val);
197 // For XSS Injection done by adding javascript closing html tags like with onmousemove, etc... (closing a src or href tag with not cleaned param)
198 if ($type == 1 || $type == 3) {
199 $val = str_replace('enclosure="', 'enclosure=X', $val); // We accept enclosure=" for the export/import module
200 $inj += preg_match('/"/i', $val); // We refused " in GET parameters value.
201 }
202 if ($type == 2) {
203 $inj += preg_match('/[:;"\'<>\?\‍(\‍){}\$%]/', $val); // PHP_SELF is a file system (or url path without parameters). It can contains spaces.
204 }
205
206 return $inj;
207}
208
217{
218 if (is_array($var)) {
219 foreach ($var as $key => $value) { // Warning, $key may also be used for attacks
221 //$var[$key] = $value; // This is useless
222 } else {
223 http_response_code(403);
224
225 // Get remote IP: PS: We do not use getRemoteIP(), function is not yet loaded and we need a value that can't be spoofed
226 $ip = (empty($_SERVER['REMOTE_ADDR']) ? 'unknown' : $_SERVER['REMOTE_ADDR']);
227
228 $errormessage = 'Access refused to '.htmlentities($ip, ENT_COMPAT, 'UTF-8').' by SQL or Script injection protection in main.inc.php:analyseVarsForSqlAndScriptsInjection type='.htmlentities($type, ENT_COMPAT, 'UTF-8');
229
230 $errormessage2 = 'paramkey='.htmlentities($key, ENT_COMPAT, 'UTF-8');
231 $errormessage2 .= ' paramvalue='.htmlentities($value, ENT_COMPAT, 'UTF-8');
232 $errormessage2 .= ' page='.htmlentities($_SERVER["REQUEST_URI"], ENT_COMPAT, 'UTF-8');
233
234 print $errormessage;
235 print "<br>\n";
236 print 'Try to go back, fix data of your form and resubmit it. You can contact also your technical support.';
237
238 print '<!--'."\n";
239 print $errormessage2;
240 print "\n".'-->';
241
242 // Add entry into error the PHP server error log
243 if (function_exists('error_log')) {
244 error_log($errormessage.' '.$errormessage2);
245 }
246
247 // Note: No addition into security audit table is done because we don't want to execute code in such a case.
248 // Detection of too many such requests can be done with a fail2ban rule on 403 error code or into the PHP server error log.
249
250 exit;
251 }
252 }
253 return true;
254 } else {
255 return (testSqlAndScriptInject($var, $type) <= 0);
256 }
257}
258
259// To disable the WAF for GET and POST and PHP_SELF, uncomment this
260//define('NOSCANPHPSELFFORINJECTION', 1);
261//define('NOSCANGETFORINJECTION', 1);
262//define('NOSCANPOSTFORINJECTION', 1);
263
264// Check consistency of NOREQUIREXXX DEFINES
265if ((defined('NOREQUIREDB') || defined('NOREQUIRETRAN')) && !defined('NOREQUIREMENU')) {
266 print 'If define NOREQUIREDB or NOREQUIRETRAN are set, you must also set NOREQUIREMENU or not set them.';
267 exit;
268}
269if (defined('NOREQUIREUSER') && !defined('NOREQUIREMENU')) {
270 print 'If define NOREQUIREUSER is set, you must also set NOREQUIREMENU or not set it.';
271 exit;
272}
273
274// Sanity check on URL
275if (!defined('NOSCANPHPSELFFORINJECTION') && !empty($_SERVER["PHP_SELF"])) {
276 $morevaltochecklikepost = array($_SERVER["PHP_SELF"]);
277 analyseVarsForSqlAndScriptsInjection($morevaltochecklikepost, 2);
278}
279// Sanity check on GET parameters
280if (!defined('NOSCANGETFORINJECTION') && !empty($_SERVER["QUERY_STRING"])) {
281 // Note: QUERY_STRING is url encoded, but $_GET and $_POST are already decoded
282 // Because the analyseVarsForSqlAndScriptsInjection is designed for already url decoded value, we must decode QUERY_STRING
283 // Another solution is to provide $_GET as parameter with analyseVarsForSqlAndScriptsInjection($_GET, 1);
284 $morevaltochecklikeget = array(urldecode($_SERVER["QUERY_STRING"]));
285 analyseVarsForSqlAndScriptsInjection($morevaltochecklikeget, 1);
286}
287// Sanity check on POST
288if (!defined('NOSCANPOSTFORINJECTION')) {
290}
291
292// This is to make Dolibarr working with Plesk
293if (!empty($_SERVER['DOCUMENT_ROOT']) && substr($_SERVER['DOCUMENT_ROOT'], -6) !== 'htdocs') {
294 set_include_path($_SERVER['DOCUMENT_ROOT'].'/htdocs');
295}
296
297// Include the conf.php and functions.lib.php and security.lib.php. This defined the constants like DOL_DOCUMENT_ROOT, DOL_DATA_ROOT, DOL_URL_ROOT...
298require_once 'filefunc.inc.php';
307// If there is a POST parameter to tell to save automatically some POST parameters into cookies, we do it.
308// This is used for example by form of boxes to save personalization of some options.
309// DOL_AUTOSET_COOKIE=cookiename:val1,val2 and cookiename_val1=aaa cookiename_val2=bbb will set cookie_name with value json_encode(array('val1'=> , ))
310if (!empty($_POST["DOL_AUTOSET_COOKIE"])) {
311 $tmpautoset = explode(':', $_POST["DOL_AUTOSET_COOKIE"], 2);
312 $tmplist = explode(',', $tmpautoset[1]);
313 $cookiearrayvalue = array();
314 foreach ($tmplist as $tmpkey) {
315 $postkey = $tmpautoset[0].'_'.$tmpkey;
316 //var_dump('tmpkey='.$tmpkey.' postkey='.$postkey.' value='.$_POST[$postkey]);
317 if (!empty($_POST[$postkey])) {
318 $cookiearrayvalue[$tmpkey] = $_POST[$postkey];
319 }
320 }
321 $cookiename = $tmpautoset[0];
322 $cookievalue = json_encode($cookiearrayvalue);
323 //var_dump('setcookie cookiename='.$cookiename.' cookievalue='.$cookievalue);
324 if (PHP_VERSION_ID < 70300) {
325 setcookie($cookiename, empty($cookievalue) ? '' : $cookievalue, empty($cookievalue) ? 0 : (time() + (86400 * 354)), '/', null, ((empty($dolibarr_main_force_https) && isHTTPS() === false) ? false : true), true); // keep cookie 1 year and add tag httponly
326 } else {
327 // Only available for php >= 7.3
328 $cookieparams = array(
329 'expires' => empty($cookievalue) ? 0 : (time() + (86400 * 354)),
330 'path' => '/',
331 //'domain' => '.mywebsite.com', // the dot at the beginning allows compatibility with subdomains
332 'secure' => ((empty($dolibarr_main_force_https) && isHTTPS() === false) ? false : true),
333 'httponly' => true,
334 'samesite' => 'Lax' // None || Lax || Strict
335 );
336 setcookie($cookiename, empty($cookievalue) ? '' : $cookievalue, $cookieparams);
337 }
338 if (empty($cookievalue)) {
339 unset($_COOKIE[$cookiename]);
340 }
341}
342
343// Set the handler of session
344// if (ini_get('session.save_handler') == 'user')
345if (!empty($php_session_save_handler) && $php_session_save_handler == 'db') {
346 require_once 'core/lib/phpsessionin'.$php_session_save_handler.'.lib.php';
347}
348
349 // Init session. Name of session is specific to Dolibarr instance.
350 // Must be done after the include of filefunc.inc.php so global variables of conf file are defined (like $dolibarr_main_instance_unique_id or $dolibarr_main_force_https).
351 // Note: the function dol_getprefix() is defined into functions.lib.php but may have been defined to return a different key to manage another area to protect.
352 $prefix = dol_getprefix('');
353 $sessionname = 'DOLSESSID_'.$prefix;
354 $sessiontimeout = 'DOLSESSTIMEOUT_'.$prefix;
355if (!empty($_COOKIE[$sessiontimeout])) {
356 ini_set('session.gc_maxlifetime', $_COOKIE[$sessiontimeout]);
357}
358
359 // This create lock, released by session_write_close() or end of page.
360 // We need this lock as long as we read/write $_SESSION ['vars']. We can remove lock when finished.
361if (!defined('NOSESSION')) {
362 if (PHP_VERSION_ID < 70300) {
363 session_set_cookie_params(0, '/', null, ((empty($dolibarr_main_force_https) && isHTTPS() === false) ? false : true), true); // Add tag secure and httponly on session cookie (same as setting session.cookie_httponly into php.ini). Must be called before the session_start.
364 } else {
365 // Only available for php >= 7.3
366 $sessioncookieparams = array(
367 'lifetime' => 0,
368 'path' => '/',
369 //'domain' => '.mywebsite.com', // the dot at the beginning allows compatibility with subdomains
370 'secure' => ((empty($dolibarr_main_force_https) && isHTTPS() === false) ? false : true),
371 'httponly' => true,
372 'samesite' => 'Lax' // None || Lax || Strict
373 );
374 session_set_cookie_params($sessioncookieparams);
375 }
376 session_name($sessionname);
377 session_start(); // This call the open and read of session handler
378 //exit; // this exist generates a call to write and close
379}
380
381
382 // Init the 6 global objects, this include will make the 'new Xxx()' and set properties for: $conf, $db, $langs, $user, $mysoc, $hookmanager
383 require_once 'master.inc.php';
384
385 // Uncomment this and set session.save_handler = user to use local session storing
386 // include DOL_DOCUMENT_ROOT.'/core/lib/phpsessionindb.inc.php
387
388 // If software has been locked. Only login $conf->global->MAIN_ONLY_LOGIN_ALLOWED is allowed.
389if (getDolGlobalString('MAIN_ONLY_LOGIN_ALLOWED')) {
390 $ok = 0;
391 if ((!session_id() || !isset($_SESSION["dol_login"])) && !isset($_POST["username"]) && !empty($_SERVER["GATEWAY_INTERFACE"])) {
392 $ok = 1; // We let working pages if not logged and inside a web browser (login form, to allow login by admin)
393 } elseif (isset($_POST["username"]) && $_POST["username"] == $conf->global->MAIN_ONLY_LOGIN_ALLOWED) {
394 $ok = 1; // We let working pages that is a login submission (login submit, to allow login by admin)
395 } elseif (defined('NOREQUIREDB')) {
396 $ok = 1; // We let working pages that don't need database access (xxx.css.php)
397 } elseif (defined('EVEN_IF_ONLY_LOGIN_ALLOWED')) {
398 $ok = 1; // We let working pages that ask to work even if only login enabled (logout.php)
399 } elseif (session_id() && isset($_SESSION["dol_login"]) && $_SESSION["dol_login"] == $conf->global->MAIN_ONLY_LOGIN_ALLOWED) {
400 $ok = 1; // We let working if user is allowed admin
401 }
402 if (!$ok) {
403 if (session_id() && isset($_SESSION["dol_login"]) && $_SESSION["dol_login"] != $conf->global->MAIN_ONLY_LOGIN_ALLOWED) {
404 print 'Sorry, your application is offline.'."\n";
405 print 'You are logged with user "'.$_SESSION["dol_login"].'" and only administrator user "' . getDolGlobalString('MAIN_ONLY_LOGIN_ALLOWED').'" is allowed to connect for the moment.'."\n";
406 $nexturl = DOL_URL_ROOT.'/user/logout.php?token='.newToken();
407 print 'Please try later or <a href="'.$nexturl.'">click here to disconnect and change login user</a>...'."\n";
408 } else {
409 print 'Sorry, your application is offline. Only administrator user "' . getDolGlobalString('MAIN_ONLY_LOGIN_ALLOWED').'" is allowed to connect for the moment.'."\n";
410 $nexturl = DOL_URL_ROOT.'/';
411 print 'Please try later or <a href="'.$nexturl.'">click here to change login user</a>...'."\n";
412 }
413 exit;
414 }
415}
416
417
418 // Activate end of page function
419 register_shutdown_function('dol_shutdown');
420
421 // Load debugbar
422if (isModEnabled('debugbar') && !GETPOST('dol_use_jmobile') && empty($_SESSION['dol_use_jmobile'])) {
423 global $debugbar;
424 include_once DOL_DOCUMENT_ROOT.'/debugbar/class/DebugBar.php';
425 $debugbar = new DolibarrDebugBar();
426 $renderer = $debugbar->getRenderer();
427 if (!getDolGlobalString('MAIN_HTML_HEADER')) {
428 $conf->global->MAIN_HTML_HEADER = '';
429 }
430 $conf->global->MAIN_HTML_HEADER .= $renderer->renderHead();
431
432 $debugbar['time']->startMeasure('pageaftermaster', 'Page generation (after environment init)');
433}
434
435 // Detection browser
436if (isset($_SERVER["HTTP_USER_AGENT"])) {
437 $tmp = getBrowserInfo($_SERVER["HTTP_USER_AGENT"]);
438 $conf->browser->name = $tmp['browsername'];
439 $conf->browser->os = $tmp['browseros'];
440 $conf->browser->version = $tmp['browserversion'];
441 $conf->browser->ua = $tmp['browserua'];
442 $conf->browser->layout = $tmp['layout']; // 'classic', 'phone', 'tablet'
443 //var_dump($conf->browser);
444
445 if ($conf->browser->layout == 'phone') {
446 $conf->dol_no_mouse_hover = 1;
447 }
448}
449
450 // If theme is forced
451if (GETPOST('theme', 'aZ09')) {
452 $conf->theme = GETPOST('theme', 'aZ09');
453 $conf->css = "/theme/".$conf->theme."/style.css.php";
454}
455
456 // Set global MAIN_OPTIMIZEFORTEXTBROWSER (must be before login part)
457if (GETPOST('textbrowser', 'int') || (!empty($conf->browser->name) && $conf->browser->name == 'lynxlinks')) { // If we must enable text browser
458 $conf->global->MAIN_OPTIMIZEFORTEXTBROWSER = 1;
459}
460
461 // Force HTTPS if required ($conf->file->main_force_https is 0/1 or 'https dolibarr root url')
462 // $_SERVER["HTTPS"] is 'on' when link is https, otherwise $_SERVER["HTTPS"] is empty or 'off'
463if (!empty($conf->file->main_force_https) && (empty($_SERVER["HTTPS"]) || $_SERVER["HTTPS"] != 'on') && !defined('NOHTTPSREDIRECT')) {
464 $newurl = '';
465 if (is_numeric($conf->file->main_force_https)) {
466 if ($conf->file->main_force_https == '1' && !empty($_SERVER["SCRIPT_URI"])) { // If SCRIPT_URI supported by server
467 if (preg_match('/^http:/i', $_SERVER["SCRIPT_URI"]) && !preg_match('/^https:/i', $_SERVER["SCRIPT_URI"])) { // If link is http
468 $newurl = preg_replace('/^http:/i', 'https:', $_SERVER["SCRIPT_URI"]);
469 }
470 } else {
471 // Check HTTPS environment variable (Apache/mod_ssl only)
472 $newurl = preg_replace('/^http:/i', 'https:', DOL_MAIN_URL_ROOT).$_SERVER["REQUEST_URI"];
473 }
474 } else {
475 // Check HTTPS environment variable (Apache/mod_ssl only)
476 $newurl = $conf->file->main_force_https.$_SERVER["REQUEST_URI"];
477 }
478 // Start redirect
479 if ($newurl) {
480 header_remove(); // Clean header already set to be sure to remove any header like "Set-Cookie: DOLSESSID_..." from non HTTPS answers
481 dol_syslog("main.inc: dolibarr_main_force_https is on, we make a redirect to ".$newurl);
482 header("Location: ".$newurl);
483 exit;
484 } else {
485 dol_syslog("main.inc: dolibarr_main_force_https is on but we failed to forge new https url so no redirect is done", LOG_WARNING);
486 }
487}
488
489if (!defined('NOLOGIN') && !defined('NOIPCHECK') && !empty($dolibarr_main_restrict_ip)) {
490 $listofip = explode(',', $dolibarr_main_restrict_ip);
491 $found = false;
492 foreach ($listofip as $ip) {
493 $ip = trim($ip);
494 if ($ip == $_SERVER['REMOTE_ADDR']) {
495 $found = true;
496 break;
497 }
498 }
499 if (!$found) {
500 print 'Access refused by IP protection. Your detected IP is '.$_SERVER['REMOTE_ADDR'];
501 exit;
502 }
503}
504
505 // Loading of additional presentation includes
506if (!defined('NOREQUIREHTML')) {
507 require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php'; // Need 660ko memory (800ko in 2.2)
508}
509if (!defined('NOREQUIREAJAX')) {
510 require_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php'; // Need 22ko memory
511}
512
513 // If install or upgrade process not done or not completely finished, we call the install page.
514if (getDolGlobalString('MAIN_NOT_INSTALLED') || getDolGlobalString('MAIN_NOT_UPGRADED')) {
515 dol_syslog("main.inc: A previous install or upgrade was not complete. Redirect to install page.", LOG_WARNING);
516 header("Location: ".DOL_URL_ROOT."/install/index.php");
517 exit;
518}
519 // If an upgrade process is required, we call the install page.
520if ((getDolGlobalString('MAIN_VERSION_LAST_UPGRADE') && ($conf->global->MAIN_VERSION_LAST_UPGRADE != DOL_VERSION))
521 || (!getDolGlobalString('MAIN_VERSION_LAST_UPGRADE') && getDolGlobalString('MAIN_VERSION_LAST_INSTALL') && ($conf->global->MAIN_VERSION_LAST_INSTALL != DOL_VERSION))) {
522 $versiontocompare = !getDolGlobalString('MAIN_VERSION_LAST_UPGRADE') ? $conf->global->MAIN_VERSION_LAST_INSTALL : $conf->global->MAIN_VERSION_LAST_UPGRADE;
523 require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
524 $dolibarrversionlastupgrade = preg_split('/[.-]/', $versiontocompare);
525 $dolibarrversionprogram = preg_split('/[.-]/', DOL_VERSION);
526 $rescomp = versioncompare($dolibarrversionprogram, $dolibarrversionlastupgrade);
527 if ($rescomp > 0) { // Programs have a version higher than database.
528 if (!getDolGlobalString('MAIN_NO_UPGRADE_REDIRECT_ON_LEVEL_3_CHANGE') || $rescomp < 3) {
529 // We did not add "&& $rescomp < 3" because we want upgrade process for build upgrades
530 dol_syslog("main.inc: database version ".$versiontocompare." is lower than programs version ".DOL_VERSION.". Redirect to install/upgrade page.", LOG_WARNING);
531 header("Location: ".DOL_URL_ROOT."/install/index.php");
532 exit;
533 }
534 }
535}
536
537 // Creation of a token against CSRF vulnerabilities
538if (!defined('NOTOKENRENEWAL') && !defined('NOSESSION')) {
539 // No token renewal on .css.php, .js.php and .json.php (even if the NOTOKENRENEWAL was not provided)
540 if (!preg_match('/\.(css|js|json)\.php$/', $_SERVER["PHP_SELF"])) {
541 // Rolling token at each call ($_SESSION['token'] contains token of previous page)
542 if (isset($_SESSION['newtoken'])) {
543 $_SESSION['token'] = $_SESSION['newtoken'];
544 }
545
546 if (!isset($_SESSION['newtoken']) || getDolGlobalInt('MAIN_SECURITY_CSRF_TOKEN_RENEWAL_ON_EACH_CALL')) {
547 // Note: Using MAIN_SECURITY_CSRF_TOKEN_RENEWAL_ON_EACH_CALL is not recommended: if a user succeed in entering a data from
548 // a public page with a link that make a token regeneration, it can make use of the backoffice no more possible !
549 // Save in $_SESSION['newtoken'] what will be next token. Into forms, we will add param token = $_SESSION['newtoken']
550 $token = dol_hash(uniqid(mt_rand(), false), 'md5'); // Generates a hash of a random number. We don't need a secured hash, just a changing random value.
551 $_SESSION['newtoken'] = $token;
552 dol_syslog("NEW TOKEN generated by : ".$_SERVER['PHP_SELF'], LOG_DEBUG);
553 }
554 }
555}
556
557 //dol_syslog("CSRF info: ".defined('NOCSRFCHECK')." - ".$dolibarr_nocsrfcheck." - ".$conf->global->MAIN_SECURITY_CSRF_WITH_TOKEN." - ".$_SERVER['REQUEST_METHOD']." - ".GETPOST('token', 'alpha'));
558
559 // Check validity of token, only if option MAIN_SECURITY_CSRF_WITH_TOKEN enabled or if constant CSRFCHECK_WITH_TOKEN is set into page
560if ((!defined('NOCSRFCHECK') && empty($dolibarr_nocsrfcheck) && getDolGlobalInt('MAIN_SECURITY_CSRF_WITH_TOKEN')) || defined('CSRFCHECK_WITH_TOKEN')) {
561 // Array of action code where CSRFCHECK with token will be forced (so token must be provided on url request)
562 $sensitiveget = false;
563 if ((GETPOSTISSET('massaction') || GETPOST('action', 'aZ09')) && getDolGlobalInt('MAIN_SECURITY_CSRF_WITH_TOKEN') >= 3) {
564 // All GET actions (except the listed exception) and mass actions are processed as sensitive.
565 if (GETPOSTISSET('massaction') || !in_array(GETPOST('action', 'aZ09'), array('create', 'createsite', 'createcard', 'edit', 'editvalidator', 'file_manager', 'presend', 'presend_addmessage', 'preview', 'specimen'))) { // We exclude some action that are legitimate
566 $sensitiveget = true;
567 }
568 } elseif (getDolGlobalInt('MAIN_SECURITY_CSRF_WITH_TOKEN') >= 2) {
569 // Few GET actions coded with a &token into url are also processed as sensitive.
570 $arrayofactiontoforcetokencheck = array(
571 'activate',
572 'doprev', 'donext', 'dvprev', 'dvnext',
573 'freezone', 'install',
574 'reopen'
575 );
576 if (in_array(GETPOST('action', 'aZ09'), $arrayofactiontoforcetokencheck)) {
577 $sensitiveget = true;
578 }
579 // We also need a valid token for actions matching one of these values
580 if (preg_match('/^(confirm_)?(add|classify|close|confirm|copy|del|disable|enable|remove|set|unset|update|save)/', GETPOST('action', 'aZ09'))) {
581 $sensitiveget = true;
582 }
583 }
584
585 // Check a token is provided for all cases that need a mandatory token
586 // (all POST actions + all sensitive GET actions + all mass actions + all login/actions/logout on pages with CSRFCHECK_WITH_TOKEN set)
587 if (
588 (!empty($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == 'POST') ||
589 $sensitiveget ||
590 GETPOSTISSET('massaction') ||
591 ((GETPOSTISSET('actionlogin') || GETPOSTISSET('action')) && defined('CSRFCHECK_WITH_TOKEN'))
592 ) {
593 // If token is not provided or empty, error (we are in case it is mandatory)
594 if (!GETPOST('token', 'alpha') || GETPOST('token', 'alpha') == 'notrequired') {
595 top_httphead();
596 if (GETPOST('uploadform', 'int')) {
597 dol_syslog("--- Access to ".(empty($_SERVER["REQUEST_METHOD"]) ? '' : $_SERVER["REQUEST_METHOD"].' ').$_SERVER["PHP_SELF"]." refused. File size too large or not provided.");
598 $langs->loadLangs(array("errors", "install"));
599 print $langs->trans("ErrorFileSizeTooLarge").' ';
600 print $langs->trans("ErrorGoBackAndCorrectParameters");
601 } else {
602 http_response_code(403);
603 if (defined('CSRFCHECK_WITH_TOKEN')) {
604 dol_syslog("--- Access to ".(empty($_SERVER["REQUEST_METHOD"]) ? '' : $_SERVER["REQUEST_METHOD"].' ').$_SERVER["PHP_SELF"]." refused by CSRF protection (CSRFCHECK_WITH_TOKEN protection) in main.inc.php. Token not provided.", LOG_WARNING);
605 print "Access to a page that needs a token (constant CSRFCHECK_WITH_TOKEN is defined) is refused by CSRF protection in main.inc.php. Token not provided.\n";
606 } else {
607 dol_syslog("--- Access to ".(empty($_SERVER["REQUEST_METHOD"]) ? '' : $_SERVER["REQUEST_METHOD"].' ').$_SERVER["PHP_SELF"]." refused by CSRF protection (POST method or GET with a sensible value for 'action' parameter) in main.inc.php. Token not provided.", LOG_WARNING);
608 print "Access to this page this way (POST method or GET with a sensible value for 'action' parameter) is refused by CSRF protection in main.inc.php. Token not provided.\n";
609 print "If you access your server behind a proxy using url rewriting and the parameter is provided by caller, you might check that all HTTP header are propagated (or add the line \$dolibarr_nocsrfcheck=1 into your conf.php file or MAIN_SECURITY_CSRF_WITH_TOKEN to 0";
610 if (getDolGlobalString('MAIN_SECURITY_CSRF_WITH_TOKEN')) {
611 print " instead of " . getDolGlobalString('MAIN_SECURITY_CSRF_WITH_TOKEN');
612 }
613 print " into setup).\n";
614 }
615 }
616 die;
617 }
618 }
619
620 $sessiontokenforthisurl = (empty($_SESSION['token']) ? '' : $_SESSION['token']);
621 // TODO Get the sessiontokenforthisurl into an array of session token (one array per base URL so we can use the CSRF per page and we keep ability for several tabs per url in a browser)
622 if (GETPOSTISSET('token') && GETPOST('token') != 'notrequired' && GETPOST('token', 'alpha') != $sessiontokenforthisurl) {
623 dol_syslog("--- Access to ".(empty($_SERVER["REQUEST_METHOD"]) ? '' : $_SERVER["REQUEST_METHOD"].' ').$_SERVER["PHP_SELF"]." refused by CSRF protection (invalid token), so we disable POST and some GET parameters - referer=".(empty($_SERVER['HTTP_REFERER'])?'':$_SERVER['HTTP_REFERER']).", action=".GETPOST('action', 'aZ09').", _GET|POST['token']=".GETPOST('token', 'alpha'), LOG_WARNING);
624 //dol_syslog("_SESSION['token']=".$sessiontokenforthisurl, LOG_DEBUG);
625 // Do not output anything on standard output because this create problems when using the BACK button on browsers. So we just set a message into session.
626 if (!defined('NOTOKENRENEWAL')) {
627 // If the page is not a page that disable the token renewal, we report a warning message to explain token has epired.
628 setEventMessages('SecurityTokenHasExpiredSoActionHasBeenCanceledPleaseRetry', null, 'warnings', '', 1);
629 }
630 $savid = null;
631 if (isset($_POST['id'])) {
632 $savid = ((int) $_POST['id']);
633 }
634 unset($_POST);
635 unset($_GET['confirm']);
636 unset($_GET['action']);
637 unset($_GET['confirmmassaction']);
638 unset($_GET['massaction']);
639 unset($_GET['token']); // TODO Make a redirect if we have a token in url to remove it ?
640 if (isset($savid)) {
641 $_POST['id'] = ((int) $savid);
642 }
643 // So rest of code can know something was wrong here
644 $_GET['errorcode'] = 'InvalidToken';
645 }
646
647 // Note: There is another CSRF protection into the filefunc.inc.php
648}
649
650
651if (!empty($dolibarr_main_demo)) {
652 // Disable modules (this must be after session_start and after conf has been loaded)
653 if (GETPOSTISSET('disablemodules')) {
654 $_SESSION["disablemodules"] = GETPOST('disablemodules', 'alpha');
655 }
656 if (!empty($_SESSION["disablemodules"])) {
657 $modulepartkeys = array('css', 'js', 'tabs', 'triggers', 'login', 'substitutions', 'menus', 'theme', 'sms', 'tpl', 'barcode', 'models', 'societe', 'hooks', 'dir', 'syslog', 'tpllinkable', 'contactelement', 'moduleforexternal');
658
659 $disabled_modules = explode(',', $_SESSION["disablemodules"]);
660 foreach ($disabled_modules as $module) {
661 if ($module) {
662 if (empty($conf->$module)) {
663 $conf->$module = new stdClass(); // To avoid warnings
664 }
665
666 $conf->$module->enabled = false; // Old usage
667
668 foreach ($modulepartkeys as $modulepartkey) {
669 unset($conf->modules_parts[$modulepartkey][$module]);
670 }
671 if ($module == 'fournisseur') { // Special case
672 $conf->supplier_order->enabled = 0;
673 $conf->supplier_invoice->enabled = 0;
674 }
675 }
676 }
677 }
678}
679
680// Set current modulepart
681$modulepart = explode("/", $_SERVER["PHP_SELF"]);
682if (is_array($modulepart) && count($modulepart) > 0) {
683 foreach ($conf->modules as $module) {
684 if (in_array($module, $modulepart)) {
685 $modulepart = $module;
686 break;
687 }
688 }
689}
690if (is_array($modulepart)) {
691 $modulepart = '';
692}
693
694
695/*
696 * Phase authentication / login
697 */
698
699$login = '';
700if (!defined('NOLOGIN')) {
701 // $authmode lists the different method of identification to be tested in order of preference.
702 // Example: 'http', 'dolibarr', 'ldap', 'http,forceuser', '...'
703
704 if (defined('MAIN_AUTHENTICATION_MODE')) {
705 $dolibarr_main_authentication = constant('MAIN_AUTHENTICATION_MODE');
706 } else {
707 // Authentication mode
708 if (empty($dolibarr_main_authentication)) {
709 $dolibarr_main_authentication = 'dolibarr';
710 }
711 // Authentication mode: forceuser
712 if ($dolibarr_main_authentication == 'forceuser' && empty($dolibarr_auto_user)) {
713 $dolibarr_auto_user = 'auto';
714 }
715 }
716 // Set authmode
717 $authmode = explode(',', $dolibarr_main_authentication);
718
719 // No authentication mode
720 if (!count($authmode)) {
721 $langs->load('main');
722 dol_print_error('', $langs->trans("ErrorConfigParameterNotDefined", 'dolibarr_main_authentication'));
723 exit;
724 }
725
726 // If login request was already post, we retrieve login from the session
727 // Call module if not realized that his request.
728 // At the end of this phase, the variable $login is defined.
729 $resultFetchUser = '';
730 $test = true;
731 if (!isset($_SESSION["dol_login"])) {
732 // It is not already authenticated and it requests the login / password
733 include_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php';
734
735 $dol_dst_observed = GETPOST("dst_observed", 'int', 3);
736 $dol_dst_first = GETPOST("dst_first", 'int', 3);
737 $dol_dst_second = GETPOST("dst_second", 'int', 3);
738 $dol_screenwidth = GETPOST("screenwidth", 'int', 3);
739 $dol_screenheight = GETPOST("screenheight", 'int', 3);
740 $dol_hide_topmenu = GETPOST('dol_hide_topmenu', 'int', 3);
741 $dol_hide_leftmenu = GETPOST('dol_hide_leftmenu', 'int', 3);
742 $dol_optimize_smallscreen = GETPOST('dol_optimize_smallscreen', 'int', 3);
743 $dol_no_mouse_hover = GETPOST('dol_no_mouse_hover', 'int', 3);
744 $dol_use_jmobile = GETPOST('dol_use_jmobile', 'int', 3); // 0=default, 1=to say we use app from a webview app, 2=to say we use app from a webview app and keep ajax
745 //dol_syslog("POST key=".join(array_keys($_POST),',').' value='.join($_POST,','));
746
747 // If in demo mode, we check we go to home page through the public/demo/index.php page
748 if (!empty($dolibarr_main_demo) && $_SERVER['PHP_SELF'] == DOL_URL_ROOT.'/index.php') { // We ask index page
749 if (empty($_SERVER['HTTP_REFERER']) || !preg_match('/public/', $_SERVER['HTTP_REFERER'])) {
750 dol_syslog("Call index page from another url than demo page (call is done from page ".(empty($_SERVER['HTTP_REFERER']) ? '' : $_SERVER['HTTP_REFER']).")");
751 $url = '';
752 $url .= ($url ? '&' : '').($dol_hide_topmenu ? 'dol_hide_topmenu='.$dol_hide_topmenu : '');
753 $url .= ($url ? '&' : '').($dol_hide_leftmenu ? 'dol_hide_leftmenu='.$dol_hide_leftmenu : '');
754 $url .= ($url ? '&' : '').($dol_optimize_smallscreen ? 'dol_optimize_smallscreen='.$dol_optimize_smallscreen : '');
755 $url .= ($url ? '&' : '').($dol_no_mouse_hover ? 'dol_no_mouse_hover='.$dol_no_mouse_hover : '');
756 $url .= ($url ? '&' : '').($dol_use_jmobile ? 'dol_use_jmobile='.$dol_use_jmobile : '');
757 $url = DOL_URL_ROOT.'/public/demo/index.php'.($url ? '?'.$url : '');
758 header("Location: ".$url);
759 exit;
760 }
761 }
762
763 // Hooks for security access
764 $action = '';
765 $hookmanager->initHooks(array('login'));
766 $parameters = array();
767 $reshook = $hookmanager->executeHooks('beforeLoginAuthentication', $parameters, $user, $action); // Note that $action and $object may have been modified by some hooks
768 if ($reshook < 0) {
769 $test = false;
770 $error++;
771 }
772
773 // Verification security graphic code
774 if ($test && GETPOST("username", "alpha", 2) && getDolGlobalString('MAIN_SECURITY_ENABLECAPTCHA') && !isset($_SESSION['dol_bypass_antispam'])) {
775 $sessionkey = 'dol_antispam_value';
776 $ok = (array_key_exists($sessionkey, $_SESSION) === true && (strtolower($_SESSION[$sessionkey]) === strtolower(GETPOST('code', 'restricthtml'))));
777
778 // Check code
779 if (!$ok) {
780 dol_syslog('Bad value for code, connexion refused', LOG_NOTICE);
781 // Load translation files required by page
782 $langs->loadLangs(array('main', 'errors'));
783
784 $_SESSION["dol_loginmesg"] = $langs->transnoentitiesnoconv("ErrorBadValueForCode");
785 $test = false;
786
787 // Call trigger for the "security events" log
788 $user->context['audit'] = 'ErrorBadValueForCode - login='.GETPOST("username", "alpha", 2);
789
790 // Call trigger
791 $result = $user->call_trigger('USER_LOGIN_FAILED', $user);
792 if ($result < 0) {
793 $error++;
794 }
795 // End call triggers
796
797 // Hooks on failed login
798 $action = '';
799 $hookmanager->initHooks(array('login'));
800 $parameters = array('dol_authmode'=>$authmode, 'dol_loginmesg'=>$_SESSION["dol_loginmesg"]);
801 $reshook = $hookmanager->executeHooks('afterLoginFailed', $parameters, $user, $action); // Note that $action and $object may have been modified by some hooks
802 if ($reshook < 0) {
803 $error++;
804 }
805
806 // Note: exit is done later
807 }
808 }
809
810 $allowedmethodtopostusername = 3;
811 if (defined('MAIN_AUTHENTICATION_POST_METHOD')) {
812 $allowedmethodtopostusername = constant('MAIN_AUTHENTICATION_POST_METHOD'); // Note a value of 2 is not compatible with some authentication methods that put username as GET parameter
813 }
814 // TODO Remove use of $_COOKIE['login_dolibarr'] ? Replace $usertotest = with $usertotest = GETPOST("username", "alpha", $allowedmethodtopostusername);
815 $usertotest = (!empty($_COOKIE['login_dolibarr']) ? preg_replace('/[^a-zA-Z0-9_@\-\.]/', '', $_COOKIE['login_dolibarr']) : GETPOST("username", "alpha", $allowedmethodtopostusername));
816 $passwordtotest = GETPOST('password', 'none', $allowedmethodtopostusername);
817 $entitytotest = (GETPOST('entity', 'int') ? GETPOST('entity', 'int') : (!empty($conf->entity) ? $conf->entity : 1));
818
819 // Define if we received the correct data to go into the test of the login with the checkLoginPassEntity().
820 $goontestloop = false;
821 if (isset($_SERVER["REMOTE_USER"]) && in_array('http', $authmode)) { // For http basic login test
822 $goontestloop = true;
823 }
824 if ($dolibarr_main_authentication == 'forceuser' && !empty($dolibarr_auto_user)) { // For automatic login with a forced user
825 $goontestloop = true;
826 }
827 if (GETPOST("username", "alpha", $allowedmethodtopostusername)) { // For posting the login form
828 $goontestloop = true;
829 }
830 if (GETPOST('openid_mode', 'alpha', 1)) { // For openid_connect ?
831 $goontestloop = true;
832 }
833 if (GETPOST('beforeoauthloginredirect') || GETPOST('afteroauthloginreturn')) { // For oauth login
834 $goontestloop = true;
835 }
836 if (!empty($_COOKIE['login_dolibarr'])) { // TODO For ? Remove this ?
837 $goontestloop = true;
838 }
839
840 if (!is_object($langs)) { // This can occurs when calling page with NOREQUIRETRAN defined, however we need langs for error messages.
841 include_once DOL_DOCUMENT_ROOT.'/core/class/translate.class.php';
842 $langs = new Translate("", $conf);
843 $langcode = (GETPOST('lang', 'aZ09', 1) ?GETPOST('lang', 'aZ09', 1) : getDolGlobalString('MAIN_LANG_DEFAULT', 'auto'));
844 if (defined('MAIN_LANG_DEFAULT')) {
845 $langcode = constant('MAIN_LANG_DEFAULT');
846 }
847 $langs->setDefaultLang($langcode);
848 }
849
850 // Validation of login/pass/entity
851 // If ok, the variable login will be returned
852 // If error, we will put error message in session under the name dol_loginmesg
853 if ($test && $goontestloop && (GETPOST('actionlogin', 'aZ09') == 'login' || $dolibarr_main_authentication != 'dolibarr')) {
854 // Loop on each test mode defined into $authmode
855 // $authmode is an array for example: array('0'=>'dolibarr', '1'=>'googleoauth');
856 $oauthmodetotestarray = array('google');
857 foreach ($oauthmodetotestarray as $oauthmodetotest) {
858 if (in_array($oauthmodetotest.'oauth', $authmode)) { // This is an authmode that is currently qualified. Do we have to remove it ?
859 // If we click on the link to use OAuth authentication or if we goes after callback return, we do nothing
860 if (GETPOST('beforeoauthloginredirect') == $oauthmodetotest || GETPOST('afteroauthloginreturn')) {
861 // TODO Use: if (GETPOST('beforeoauthloginredirect') == $oauthmodetotest || GETPOST('afteroauthloginreturn') == $oauthmodetotest) {
862 continue;
863 }
864 dol_syslog("User did not click on link for OAuth or is not on the OAuth return, so we disable check using ".$oauthmodetotest);
865 foreach ($authmode as $tmpkey => $tmpval) {
866 if ($tmpval == $oauthmodetotest.'oauth') {
867 unset($authmode[$tmpkey]);
868 break;
869 }
870 }
871 }
872 }
873
874 // Check login for all qualified modes in array $authmode.
875 $login = checkLoginPassEntity($usertotest, $passwordtotest, $entitytotest, $authmode);
876 if ($login === '--bad-login-validity--') {
877 $login = '';
878 }
879
880 $dol_authmode = '';
881
882 if ($login) {
883 $dol_authmode = $conf->authmode; // This properties is defined only when logged, to say what mode was successfully used
884 $dol_tz = empty($_POST["tz"]) ? (empty($_SESSION["tz"]) ? '' : $_SESSION["tz"]) : $_POST["tz"];
885 $dol_tz_string = empty($_POST["tz_string"]) ? (empty($_SESSION["tz_string"]) ? '' : $_SESSION["tz_string"]) : $_POST["tz_string"];
886 $dol_tz_string = preg_replace('/\s*\‍(.+\‍)$/', '', $dol_tz_string);
887 $dol_tz_string = preg_replace('/,/', '/', $dol_tz_string);
888 $dol_tz_string = preg_replace('/\s/', '_', $dol_tz_string);
889 $dol_dst = 0;
890 // Keep $_POST here. Do not use GETPOSTISSET
891 $dol_dst_first = empty($_POST["dst_first"]) ? (empty($_SESSION["dst_first"]) ? '' : $_SESSION["dst_first"]) : $_POST["dst_first"];
892 $dol_dst_second = empty($_POST["dst_second"]) ? (empty($_SESSION["dst_second"]) ? '' : $_SESSION["dst_second"]) : $_POST["dst_second"];
893 if ($dol_dst_first && $dol_dst_second) {
894 include_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
895 $datenow = dol_now();
896 $datefirst = dol_stringtotime($dol_dst_first);
897 $datesecond = dol_stringtotime($dol_dst_second);
898 if ($datenow >= $datefirst && $datenow < $datesecond) {
899 $dol_dst = 1;
900 }
901 }
902 $dol_screenheight = empty($_POST["screenheight"]) ? (empty($_SESSION["dol_screenheight"]) ? '' : $_SESSION["dol_screenheight"]) : $_POST["screenheight"];
903 $dol_screenwidth = empty($_POST["screenwidth"]) ? (empty($_SESSION["dol_screenwidth"]) ? '' : $_SESSION["dol_screenwidth"]) : $_POST["screenwidth"];
904 //print $datefirst.'-'.$datesecond.'-'.$datenow.'-'.$dol_tz.'-'.$dol_tzstring.'-'.$dol_dst.'-'.sdol_screenheight.'-'.sdol_screenwidth; exit;
905 }
906
907 if (!$login) {
908 dol_syslog('Bad password, connexion refused (see a previous notice message for more info)', LOG_NOTICE);
909 // Load translation files required by page
910 $langs->loadLangs(array('main', 'errors'));
911
912 // Bad password. No authmode has found a good password.
913 // We set a generic message if not defined inside function checkLoginPassEntity or subfunctions
914 if (empty($_SESSION["dol_loginmesg"])) {
915 $_SESSION["dol_loginmesg"] = $langs->transnoentitiesnoconv("ErrorBadLoginPassword");
916 }
917
918 // Call trigger for the "security events" log
919 $user->context['audit'] = $langs->trans("ErrorBadLoginPassword").' - login='.GETPOST("username", "alpha", 2);
920
921 // Call trigger
922 $result = $user->call_trigger('USER_LOGIN_FAILED', $user);
923 if ($result < 0) {
924 $error++;
925 }
926 // End call triggers
927
928 // Hooks on failed login
929 $action = '';
930 $hookmanager->initHooks(array('login'));
931 $parameters = array('dol_authmode'=>$dol_authmode, 'dol_loginmesg'=>$_SESSION["dol_loginmesg"]);
932 $reshook = $hookmanager->executeHooks('afterLoginFailed', $parameters, $user, $action); // Note that $action and $object may have been modified by some hooks
933 if ($reshook < 0) {
934 $error++;
935 }
936
937 // Note: exit is done in next chapter
938 }
939 }
940
941 // End test login / passwords
942 if (!$login || (in_array('ldap', $authmode) && empty($passwordtotest))) { // With LDAP we refused empty password because some LDAP are "opened" for anonymous access so connexion is a success.
943 // No data to test login, so we show the login page.
944 dol_syslog("--- Access to ".(empty($_SERVER["REQUEST_METHOD"]) ? '' : $_SERVER["REQUEST_METHOD"].' ').$_SERVER["PHP_SELF"]." - action=".GETPOST('action', 'aZ09')." - actionlogin=".GETPOST('actionlogin', 'aZ09')." - showing the login form and exit", LOG_NOTICE);
945 if (defined('NOREDIRECTBYMAINTOLOGIN')) {
946 // When used with NOREDIRECTBYMAINTOLOGIN set, the http header must already be set when including the main.
947 // See example with selectsearchbox.php. This case is reserverd for the selectesearchbox.php so we can
948 // report a message to ask to login when search ajax component is used after a timeout.
949 //top_httphead();
950 return 'ERROR_NOT_LOGGED';
951 } else {
952 if (!empty($_SERVER["HTTP_USER_AGENT"]) && $_SERVER["HTTP_USER_AGENT"] == 'securitytest') {
953 http_response_code(401); // It makes easier to understand if session was broken during security tests
954 }
955 dol_loginfunction($langs, $conf, (!empty($mysoc) ? $mysoc : '')); // This include http headers
956 }
957 exit;
958 }
959
960 $resultFetchUser = $user->fetch('', $login, '', 1, ($entitytotest > 0 ? $entitytotest : -1)); // value for $login was retrieved previously when checking password.
961 if ($resultFetchUser <= 0 || $user->isNotIntoValidityDateRange()) {
962 dol_syslog('User not found or not valid, connexion refused');
963 session_destroy();
964 session_set_cookie_params(0, '/', null, (empty($dolibarr_main_force_https) ? false : true), true); // Add tag secure and httponly on session cookie
965 session_name($sessionname);
966 session_start();
967
968 if ($resultFetchUser == 0) {
969 // Load translation files required by page
970 $langs->loadLangs(array('main', 'errors'));
971
972 $_SESSION["dol_loginmesg"] = $langs->transnoentitiesnoconv("ErrorCantLoadUserFromDolibarrDatabase", $login);
973
974 $user->context['audit'] = 'ErrorCantLoadUserFromDolibarrDatabase - login='.$login;
975 } elseif ($resultFetchUser < 0) {
976 $_SESSION["dol_loginmesg"] = $user->error;
977
978 $user->context['audit'] = $user->error;
979 } else {
980 // Load translation files required by the page
981 $langs->loadLangs(array('main', 'errors'));
982
983 $_SESSION["dol_loginmesg"] = $langs->transnoentitiesnoconv("ErrorLoginDateValidity");
984
985 $user->context['audit'] = $langs->trans("ErrorLoginDateValidity").' - login='.$login;
986 }
987
988 // Call trigger
989 $result = $user->call_trigger('USER_LOGIN_FAILED', $user);
990 if ($result < 0) {
991 $error++;
992 }
993 // End call triggers
994
995
996 // Hooks on failed login
997 $action = '';
998 $hookmanager->initHooks(array('login'));
999 $parameters = array('dol_authmode'=>$dol_authmode, 'dol_loginmesg'=>$_SESSION["dol_loginmesg"]);
1000 $reshook = $hookmanager->executeHooks('afterLoginFailed', $parameters, $user, $action); // Note that $action and $object may have been modified by some hooks
1001 if ($reshook < 0) {
1002 $error++;
1003 }
1004
1005 $paramsurl = array();
1006 if (GETPOST('textbrowser', 'int')) {
1007 $paramsurl[] = 'textbrowser='.GETPOST('textbrowser', 'int');
1008 }
1009 if (GETPOST('nojs', 'int')) {
1010 $paramsurl[] = 'nojs='.GETPOST('nojs', 'int');
1011 }
1012 if (GETPOST('lang', 'aZ09')) {
1013 $paramsurl[] = 'lang='.GETPOST('lang', 'aZ09');
1014 }
1015 header('Location: '.DOL_URL_ROOT.'/index.php'.(count($paramsurl) ? '?'.implode('&', $paramsurl) : ''));
1016 exit;
1017 } else {
1018 // User is loaded, we may need to change language for him according to its choice
1019 if (!empty($user->conf->MAIN_LANG_DEFAULT)) {
1020 $langs->setDefaultLang($user->conf->MAIN_LANG_DEFAULT);
1021 }
1022 }
1023 } else {
1024 // We are already into an authenticated session
1025 $login = $_SESSION["dol_login"];
1026 $entity = isset($_SESSION["dol_entity"]) ? $_SESSION["dol_entity"] : 0;
1027 dol_syslog("- This is an already logged session. _SESSION['dol_login']=".$login." _SESSION['dol_entity']=".$entity, LOG_DEBUG);
1028
1029 $resultFetchUser = $user->fetch('', $login, '', 1, ($entity > 0 ? $entity : -1));
1030
1031 //var_dump(dol_print_date($user->flagdelsessionsbefore, 'dayhour', 'gmt')." ".dol_print_date($_SESSION["dol_logindate"], 'dayhour', 'gmt'));
1032
1033 if ($resultFetchUser <= 0
1034 || ($user->flagdelsessionsbefore && !empty($_SESSION["dol_logindate"]) && $user->flagdelsessionsbefore > $_SESSION["dol_logindate"])
1035 || ($user->status != $user::STATUS_ENABLED)
1036 || ($user->isNotIntoValidityDateRange())) {
1037 if ($resultFetchUser <= 0) {
1038 // Account has been removed after login
1039 dol_syslog("Can't load user even if session logged. _SESSION['dol_login']=".$login, LOG_WARNING);
1040 } elseif ($user->flagdelsessionsbefore && !empty($_SESSION["dol_logindate"]) && $user->flagdelsessionsbefore > $_SESSION["dol_logindate"]) {
1041 // Session is no more valid
1042 dol_syslog("The user has a date for session invalidation = ".$user->flagdelsessionsbefore." and a session date = ".$_SESSION["dol_logindate"].". We must invalidate its sessions.");
1043 } elseif ($user->status != $user::STATUS_ENABLED) {
1044 // User is not enabled
1045 dol_syslog("The user login is disabled");
1046 } else {
1047 // User validity dates are no more valid
1048 dol_syslog("The user login has a validity between [".$user->datestartvalidity." and ".$user->dateendvalidity."], curren date is ".dol_now());
1049 }
1050 session_destroy();
1051 session_set_cookie_params(0, '/', null, (empty($dolibarr_main_force_https) ? false : true), true); // Add tag secure and httponly on session cookie
1052 session_name($sessionname);
1053 session_start();
1054
1055 if ($resultFetchUser == 0) {
1056 $langs->loadLangs(array('main', 'errors'));
1057
1058 $_SESSION["dol_loginmesg"] = $langs->transnoentitiesnoconv("ErrorCantLoadUserFromDolibarrDatabase", $login);
1059
1060 $user->context['audit'] = 'ErrorCantLoadUserFromDolibarrDatabase - login='.$login;
1061 } elseif ($resultFetchUser < 0) {
1062 $_SESSION["dol_loginmesg"] = $user->error;
1063
1064 $user->context['audit'] = $user->error;
1065 } else {
1066 $langs->loadLangs(array('main', 'errors'));
1067
1068 $_SESSION["dol_loginmesg"] = $langs->transnoentitiesnoconv("ErrorSessionInvalidatedAfterPasswordChange");
1069
1070 $user->context['audit'] = 'ErrorUserSessionWasInvalidated - login='.$login;
1071 }
1072
1073 // Call trigger
1074 $result = $user->call_trigger('USER_LOGIN_FAILED', $user);
1075 if ($result < 0) {
1076 $error++;
1077 }
1078 // End call triggers
1079
1080 // Hooks on failed login
1081 $action = '';
1082 $hookmanager->initHooks(array('login'));
1083 $parameters = array('dol_authmode' => (isset($dol_authmode) ? $dol_authmode : ''), 'dol_loginmesg' => $_SESSION["dol_loginmesg"]);
1084 $reshook = $hookmanager->executeHooks('afterLoginFailed', $parameters, $user, $action); // Note that $action and $object may have been modified by some hooks
1085 if ($reshook < 0) {
1086 $error++;
1087 }
1088
1089 $paramsurl = array();
1090 if (GETPOST('textbrowser', 'int')) {
1091 $paramsurl[] = 'textbrowser='.GETPOST('textbrowser', 'int');
1092 }
1093 if (GETPOST('nojs', 'int')) {
1094 $paramsurl[] = 'nojs='.GETPOST('nojs', 'int');
1095 }
1096 if (GETPOST('lang', 'aZ09')) {
1097 $paramsurl[] = 'lang='.GETPOST('lang', 'aZ09');
1098 }
1099
1100 header('Location: '.DOL_URL_ROOT.'/index.php'.(count($paramsurl) ? '?'.implode('&', $paramsurl) : ''));
1101 exit;
1102 } else {
1103 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
1104 $hookmanager->initHooks(array('main'));
1105
1106 // Code for search criteria persistence.
1107 if (!empty($_GET['save_lastsearch_values']) && !empty($_SERVER["HTTP_REFERER"])) { // We must use $_GET here
1108 $relativepathstring = preg_replace('/\?.*$/', '', $_SERVER["HTTP_REFERER"]);
1109 $relativepathstring = preg_replace('/^https?:\/\/[^\/]*/', '', $relativepathstring); // Get full path except host server
1110 // Clean $relativepathstring
1111 if (constant('DOL_URL_ROOT')) {
1112 $relativepathstring = preg_replace('/^'.preg_quote(constant('DOL_URL_ROOT'), '/').'/', '', $relativepathstring);
1113 }
1114 $relativepathstring = preg_replace('/^\//', '', $relativepathstring);
1115 $relativepathstring = preg_replace('/^custom\//', '', $relativepathstring);
1116 //var_dump($relativepathstring);
1117
1118 // We click on a link that leave a page we have to save search criteria, contextpage, limit and page and mode. We save them from tmp to no tmp
1119 if (!empty($_SESSION['lastsearch_values_tmp_'.$relativepathstring])) {
1120 $_SESSION['lastsearch_values_'.$relativepathstring] = $_SESSION['lastsearch_values_tmp_'.$relativepathstring];
1121 unset($_SESSION['lastsearch_values_tmp_'.$relativepathstring]);
1122 }
1123 if (!empty($_SESSION['lastsearch_contextpage_tmp_'.$relativepathstring])) {
1124 $_SESSION['lastsearch_contextpage_'.$relativepathstring] = $_SESSION['lastsearch_contextpage_tmp_'.$relativepathstring];
1125 unset($_SESSION['lastsearch_contextpage_tmp_'.$relativepathstring]);
1126 }
1127 if (!empty($_SESSION['lastsearch_limit_tmp_'.$relativepathstring]) && $_SESSION['lastsearch_limit_tmp_'.$relativepathstring] != $conf->liste_limit) {
1128 $_SESSION['lastsearch_limit_'.$relativepathstring] = $_SESSION['lastsearch_limit_tmp_'.$relativepathstring];
1129 unset($_SESSION['lastsearch_limit_tmp_'.$relativepathstring]);
1130 }
1131 if (!empty($_SESSION['lastsearch_page_tmp_'.$relativepathstring]) && $_SESSION['lastsearch_page_tmp_'.$relativepathstring] > 0) {
1132 $_SESSION['lastsearch_page_'.$relativepathstring] = $_SESSION['lastsearch_page_tmp_'.$relativepathstring];
1133 unset($_SESSION['lastsearch_page_tmp_'.$relativepathstring]);
1134 }
1135 if (!empty($_SESSION['lastsearch_mode_tmp_'.$relativepathstring])) {
1136 $_SESSION['lastsearch_mode_'.$relativepathstring] = $_SESSION['lastsearch_mode_tmp_'.$relativepathstring];
1137 unset($_SESSION['lastsearch_mode_tmp_'.$relativepathstring]);
1138 }
1139 }
1140 if (!empty($_GET['save_pageforbacktolist']) && !empty($_SERVER["HTTP_REFERER"])) { // We must use $_GET here
1141 if (empty($_SESSION['pageforbacktolist'])) {
1142 $pageforbacktolistarray = array();
1143 } else {
1144 $pageforbacktolistarray = $_SESSION['pageforbacktolist'];
1145 }
1146 $tmparray = explode(':', $_GET['save_pageforbacktolist'], 2);
1147 if (!empty($tmparray[0]) && !empty($tmparray[1])) {
1148 $pageforbacktolistarray[$tmparray[0]] = $tmparray[1];
1149 $_SESSION['pageforbacktolist'] = $pageforbacktolistarray;
1150 }
1151 }
1152
1153 $action = '';
1154 $parameters = array();
1155 $reshook = $hookmanager->executeHooks('updateSession', $parameters, $user, $action);
1156 if ($reshook < 0) {
1157 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
1158 }
1159 }
1160 }
1161
1162 // Is it a new session that has started ?
1163 // If we are here, this means authentication was successfull.
1164 if (!isset($_SESSION["dol_login"])) {
1165 // New session for this login has started.
1166 $error = 0;
1167
1168 // Store value into session (values always stored)
1169 $_SESSION["dol_login"] = $user->login;
1170 $_SESSION["dol_logindate"] = dol_now('gmt');
1171 $_SESSION["dol_authmode"] = isset($dol_authmode) ? $dol_authmode : '';
1172 $_SESSION["dol_tz"] = isset($dol_tz) ? $dol_tz : '';
1173 $_SESSION["dol_tz_string"] = isset($dol_tz_string) ? $dol_tz_string : '';
1174 $_SESSION["dol_dst"] = isset($dol_dst) ? $dol_dst : '';
1175 $_SESSION["dol_dst_observed"] = isset($dol_dst_observed) ? $dol_dst_observed : '';
1176 $_SESSION["dol_dst_first"] = isset($dol_dst_first) ? $dol_dst_first : '';
1177 $_SESSION["dol_dst_second"] = isset($dol_dst_second) ? $dol_dst_second : '';
1178 $_SESSION["dol_screenwidth"] = isset($dol_screenwidth) ? $dol_screenwidth : '';
1179 $_SESSION["dol_screenheight"] = isset($dol_screenheight) ? $dol_screenheight : '';
1180 $_SESSION["dol_company"] = getDolGlobalString("MAIN_INFO_SOCIETE_NOM");
1181 $_SESSION["dol_entity"] = $conf->entity;
1182 // Store value into session (values stored only if defined)
1183 if (!empty($dol_hide_topmenu)) {
1184 $_SESSION['dol_hide_topmenu'] = $dol_hide_topmenu;
1185 }
1186 if (!empty($dol_hide_leftmenu)) {
1187 $_SESSION['dol_hide_leftmenu'] = $dol_hide_leftmenu;
1188 }
1189 if (!empty($dol_optimize_smallscreen)) {
1190 $_SESSION['dol_optimize_smallscreen'] = $dol_optimize_smallscreen;
1191 }
1192 if (!empty($dol_no_mouse_hover)) {
1193 $_SESSION['dol_no_mouse_hover'] = $dol_no_mouse_hover;
1194 }
1195 if (!empty($dol_use_jmobile)) {
1196 $_SESSION['dol_use_jmobile'] = $dol_use_jmobile;
1197 }
1198
1199 dol_syslog("This is a new started user session. _SESSION['dol_login']=".$_SESSION["dol_login"]." Session id=".session_id());
1200
1201 $db->begin();
1202
1203 $user->update_last_login_date();
1204
1205 $loginfo = 'TZ='.$_SESSION["dol_tz"].';TZString='.$_SESSION["dol_tz_string"].';Screen='.$_SESSION["dol_screenwidth"].'x'.$_SESSION["dol_screenheight"];
1206 $loginfo .= ' - authmode='.$dol_authmode.' - entity='.$conf->entity;
1207
1208 // Call triggers for the "security events" log
1209 $user->context['audit'] = $loginfo;
1210 $user->context['authentication_method'] = $dol_authmode;
1211
1212 // Call trigger
1213 $result = $user->call_trigger('USER_LOGIN', $user);
1214 if ($result < 0) {
1215 $error++;
1216 }
1217 // End call triggers
1218
1219 // Hooks on successfull login
1220 $action = '';
1221 $hookmanager->initHooks(array('login'));
1222 $parameters = array('dol_authmode'=>$dol_authmode, 'dol_loginfo'=>$loginfo);
1223 $reshook = $hookmanager->executeHooks('afterLogin', $parameters, $user, $action); // Note that $action and $object may have been modified by some hooks
1224 if ($reshook < 0) {
1225 $error++;
1226 }
1227
1228 if ($error) {
1229 $db->rollback();
1230 session_destroy();
1231 dol_print_error($db, 'Error in some triggers USER_LOGIN or in some hooks afterLogin');
1232 exit;
1233 } else {
1234 $db->commit();
1235 }
1236
1237 // Change landing page if defined.
1238 $landingpage = (empty($user->conf->MAIN_LANDING_PAGE) ? (!getDolGlobalString('MAIN_LANDING_PAGE') ? '' : $conf->global->MAIN_LANDING_PAGE) : $user->conf->MAIN_LANDING_PAGE);
1239 if (!empty($landingpage)) { // Example: /index.php
1240 $newpath = dol_buildpath($landingpage, 1);
1241 if ($_SERVER["PHP_SELF"] != $newpath) { // not already on landing page (avoid infinite loop)
1242 header('Location: '.$newpath);
1243 exit;
1244 }
1245 }
1246 }
1247
1248
1249 // If user admin, we force the rights-based modules
1250 if ($user->admin) {
1251 $user->rights->user->user->lire = 1;
1252 $user->rights->user->user->creer = 1;
1253 $user->rights->user->user->password = 1;
1254 $user->rights->user->user->supprimer = 1;
1255 $user->rights->user->self->creer = 1;
1256 $user->rights->user->self->password = 1;
1257
1258 //Required if advanced permissions are used with MAIN_USE_ADVANCED_PERMS
1259 if (getDolGlobalString('MAIN_USE_ADVANCED_PERMS')) {
1260 if (!$user->hasRight('user', 'user_advance')) {
1261 $user->rights->user->user_advance = new stdClass(); // To avoid warnings
1262 }
1263 if (!$user->hasRight('user', 'self_advance')) {
1264 $user->rights->user->self_advance = new stdClass(); // To avoid warnings
1265 }
1266 if (!$user->hasRight('user', 'group_advance')) {
1267 $user->rights->user->group_advance = new stdClass(); // To avoid warnings
1268 }
1269
1270 $user->rights->user->user_advance->readperms = 1;
1271 $user->rights->user->user_advance->write = 1;
1272 $user->rights->user->self_advance->readperms = 1;
1273 $user->rights->user->self_advance->writeperms = 1;
1274 $user->rights->user->group_advance->read = 1;
1275 $user->rights->user->group_advance->readperms = 1;
1276 $user->rights->user->group_advance->write = 1;
1277 $user->rights->user->group_advance->delete = 1;
1278 }
1279 }
1280
1281 /*
1282 * Overwrite some configs globals (try to avoid this and have code to use instead $user->conf->xxx)
1283 */
1284
1285 // Set liste_limit
1286 if (isset($user->conf->MAIN_SIZE_LISTE_LIMIT)) {
1287 $conf->liste_limit = $user->conf->MAIN_SIZE_LISTE_LIMIT; // Can be 0
1288 }
1289 if (isset($user->conf->PRODUIT_LIMIT_SIZE)) {
1290 $conf->product->limit_size = $user->conf->PRODUIT_LIMIT_SIZE; // Can be 0
1291 }
1292
1293 // Replace conf->css by personalized value if theme not forced
1294 if (!getDolGlobalString('MAIN_FORCETHEME') && !empty($user->conf->MAIN_THEME)) {
1295 $conf->theme = $user->conf->MAIN_THEME;
1296 $conf->css = "/theme/".$conf->theme."/style.css.php";
1297 }
1298} else {
1299 // We may have NOLOGIN set, but NOREQUIREUSER not
1300 if (!empty($user) && method_exists($user, 'loadDefaultValues') && !defined('NODEFAULTVALUES')) {
1301 $user->loadDefaultValues(); // Load default values for everybody (works even if $user->id = 0
1302 }
1303}
1304
1305
1306 // Case forcing style from url
1307if (GETPOST('theme', 'aZ09')) {
1308 $conf->theme = GETPOST('theme', 'aZ09', 1);
1309 $conf->css = "/theme/".$conf->theme."/style.css.php";
1310}
1311
1312 // Set javascript option
1313if (GETPOST('nojs', 'int')) { // If javascript was not disabled on URL
1314 $conf->use_javascript_ajax = 0;
1315} else {
1316 if (!empty($user->conf->MAIN_DISABLE_JAVASCRIPT)) {
1317 $conf->use_javascript_ajax = !$user->conf->MAIN_DISABLE_JAVASCRIPT;
1318 }
1319}
1320
1321 // Set MAIN_OPTIMIZEFORTEXTBROWSER for user (must be after login part)
1322if (!getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER') && !empty($user->conf->MAIN_OPTIMIZEFORTEXTBROWSER)) {
1323 $conf->global->MAIN_OPTIMIZEFORTEXTBROWSER = $user->conf->MAIN_OPTIMIZEFORTEXTBROWSER;
1324}
1325
1326 // set MAIN_OPTIMIZEFORCOLORBLIND for user
1327 $conf->global->MAIN_OPTIMIZEFORCOLORBLIND = empty($user->conf->MAIN_OPTIMIZEFORCOLORBLIND) ? '' : $user->conf->MAIN_OPTIMIZEFORCOLORBLIND;
1328
1329 // Set terminal output option according to conf->browser.
1330if (GETPOST('dol_hide_leftmenu', 'int') || !empty($_SESSION['dol_hide_leftmenu'])) {
1331 $conf->dol_hide_leftmenu = 1;
1332}
1333if (GETPOST('dol_hide_topmenu', 'int') || !empty($_SESSION['dol_hide_topmenu'])) {
1334 $conf->dol_hide_topmenu = 1;
1335}
1336if (GETPOST('dol_optimize_smallscreen', 'int') || !empty($_SESSION['dol_optimize_smallscreen'])) {
1337 $conf->dol_optimize_smallscreen = 1;
1338}
1339if (GETPOST('dol_no_mouse_hover', 'int') || !empty($_SESSION['dol_no_mouse_hover'])) {
1340 $conf->dol_no_mouse_hover = 1;
1341}
1342if (GETPOST('dol_use_jmobile', 'int') || !empty($_SESSION['dol_use_jmobile'])) {
1343 $conf->dol_use_jmobile = 1;
1344}
1345 // If not on Desktop
1346if (!empty($conf->browser->layout) && $conf->browser->layout != 'classic') {
1347 $conf->dol_no_mouse_hover = 1;
1348}
1349
1350 // If on smartphone or optmized for small screen
1351if ((!empty($conf->browser->layout) && $conf->browser->layout == 'phone')
1352 || (!empty($_SESSION['dol_screenwidth']) && $_SESSION['dol_screenwidth'] < 400)
1353 || (!empty($_SESSION['dol_screenheight']) && $_SESSION['dol_screenheight'] < 400
1354 || getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER'))
1355 ) {
1356 $conf->dol_optimize_smallscreen = 1;
1357
1358 if (getDolGlobalInt('PRODUIT_DESC_IN_FORM') == 1) {
1359 $conf->global->PRODUIT_DESC_IN_FORM_ACCORDING_TO_DEVICE = 0;
1360 }
1361}
1362 // Replace themes bugged with jmobile with eldy
1363if (!empty($conf->dol_use_jmobile) && in_array($conf->theme, array('bureau2crea', 'cameleo', 'amarok'))) {
1364 $conf->theme = 'eldy';
1365 $conf->css = "/theme/".$conf->theme."/style.css.php";
1366}
1367
1368if (!defined('NOREQUIRETRAN')) {
1369 if (!GETPOST('lang', 'aZ09')) { // If language was not forced on URL
1370 // If user has chosen its own language
1371 if (!empty($user->conf->MAIN_LANG_DEFAULT)) {
1372 // If different than current language
1373 //print ">>>".$langs->getDefaultLang()."-".$user->conf->MAIN_LANG_DEFAULT;
1374 if ($langs->getDefaultLang() != $user->conf->MAIN_LANG_DEFAULT) {
1375 $langs->setDefaultLang($user->conf->MAIN_LANG_DEFAULT);
1376 }
1377 }
1378 }
1379}
1380
1381if (!defined('NOLOGIN')) {
1382 // If the login is not recovered, it is identified with an account that does not exist.
1383 // Hacking attempt?
1384 if (!$user->login) {
1386 }
1387
1388 // Check if user is active
1389 if ($user->statut < 1) {
1390 // If not active, we refuse the user
1391 $langs->loadLangs(array("errors", "other"));
1392 dol_syslog("Authentication KO as login is disabled", LOG_NOTICE);
1393 accessforbidden("ErrorLoginDisabled");
1394 }
1395
1396 // Load permissions
1397 $user->getrights();
1398}
1399
1400 dol_syslog("--- Access to ".(empty($_SERVER["REQUEST_METHOD"]) ? '' : $_SERVER["REQUEST_METHOD"].' ').$_SERVER["PHP_SELF"].' - action='.GETPOST('action', 'aZ09').', massaction='.GETPOST('massaction', 'aZ09').(defined('NOTOKENRENEWAL') ? ' NOTOKENRENEWAL='.constant('NOTOKENRENEWAL') : ''), LOG_NOTICE);
1401 //Another call for easy debugg
1402 //dol_syslog("Access to ".$_SERVER["PHP_SELF"].' '.$_SERVER["HTTP_REFERER"].' GET='.join(',',array_keys($_GET)).'->'.join(',',$_GET).' POST:'.join(',',array_keys($_POST)).'->'.join(',',$_POST));
1403
1404 // Load main languages files
1405if (!defined('NOREQUIRETRAN')) {
1406 // Load translation files required by page
1407 $langs->loadLangs(array('main', 'dict'));
1408}
1409
1410 // Define some constants used for style of arrays
1411 $bc = array(0=>'class="impair"', 1=>'class="pair"');
1412 $bcdd = array(0=>'class="drag drop oddeven"', 1=>'class="drag drop oddeven"');
1413 $bcnd = array(0=>'class="nodrag nodrop nohover"', 1=>'class="nodrag nodrop nohoverpair"'); // Used for tr to add new lines
1414 $bctag = array(0=>'class="impair tagtr"', 1=>'class="pair tagtr"');
1415
1416 // Define messages variables
1417 $mesg = ''; $warning = ''; $error = 0;
1418 // deprecated, see setEventMessages() and dol_htmloutput_events()
1419 $mesgs = array(); $warnings = array(); $errors = array();
1420
1421 // Constants used to defined number of lines in textarea
1422if (empty($conf->browser->firefox)) {
1423 define('ROWS_1', 1);
1424 define('ROWS_2', 2);
1425 define('ROWS_3', 3);
1426 define('ROWS_4', 4);
1427 define('ROWS_5', 5);
1428 define('ROWS_6', 6);
1429 define('ROWS_7', 7);
1430 define('ROWS_8', 8);
1431 define('ROWS_9', 9);
1432} else {
1433 define('ROWS_1', 0);
1434 define('ROWS_2', 1);
1435 define('ROWS_3', 2);
1436 define('ROWS_4', 3);
1437 define('ROWS_5', 4);
1438 define('ROWS_6', 5);
1439 define('ROWS_7', 6);
1440 define('ROWS_8', 7);
1441 define('ROWS_9', 8);
1442}
1443
1444 $heightforframes = 50;
1445
1446 // Init menu manager
1447if (!defined('NOREQUIREMENU')) {
1448 if (empty($user->socid)) { // If internal user or not defined
1449 $conf->standard_menu = (!getDolGlobalString('MAIN_MENU_STANDARD_FORCED') ? (!getDolGlobalString('MAIN_MENU_STANDARD') ? 'eldy_menu.php' : $conf->global->MAIN_MENU_STANDARD) : $conf->global->MAIN_MENU_STANDARD_FORCED);
1450 } else {
1451 // If external user
1452 $conf->standard_menu = (!getDolGlobalString('MAIN_MENUFRONT_STANDARD_FORCED') ? (!getDolGlobalString('MAIN_MENUFRONT_STANDARD') ? 'eldy_menu.php' : $conf->global->MAIN_MENUFRONT_STANDARD) : $conf->global->MAIN_MENUFRONT_STANDARD_FORCED);
1453 }
1454
1455 // Load the menu manager (only if not already done)
1456 $file_menu = $conf->standard_menu;
1457 if (GETPOST('menu', 'alpha')) {
1458 $file_menu = GETPOST('menu', 'alpha'); // example: menu=eldy_menu.php
1459 }
1460 if (!class_exists('MenuManager')) {
1461 $menufound = 0;
1462 $dirmenus = array_merge(array("/core/menus/"), (array) $conf->modules_parts['menus']);
1463 foreach ($dirmenus as $dirmenu) {
1464 $menufound = dol_include_once($dirmenu."standard/".$file_menu);
1465 if (class_exists('MenuManager')) {
1466 break;
1467 }
1468 }
1469 if (!class_exists('MenuManager')) { // If failed to include, we try with standard eldy_menu.php
1470 dol_syslog("You define a menu manager '".$file_menu."' that can not be loaded.", LOG_WARNING);
1471 $file_menu = 'eldy_menu.php';
1472 include_once DOL_DOCUMENT_ROOT."/core/menus/standard/".$file_menu;
1473 }
1474 }
1475 $menumanager = new MenuManager($db, empty($user->socid) ? 0 : 1);
1476 $menumanager->loadMenu();
1477}
1478
1479if (!empty(GETPOST('seteventmessages', 'alpha'))) {
1480 $message = GETPOST('seteventmessages', 'alpha');
1481 $messages = explode(',', $message);
1482 foreach ($messages as $key => $msg) {
1483 $tmp = explode(':', $msg);
1484 setEventMessages($tmp[0], null, !empty($tmp[1]) ? $tmp[1] : 'mesgs');
1485 }
1486}
1487
1488 // Functions
1489
1490if (!function_exists("llxHeader")) {
1511 function llxHeader($head = '', $title = '', $help_url = '', $target = '', $disablejs = 0, $disablehead = 0, $arrayofjs = '', $arrayofcss = '', $morequerystring = '', $morecssonbody = '', $replacemainareaby = '', $disablenofollow = 0, $disablenoindex = 0)
1512 {
1513 global $conf, $hookmanager;
1514
1515 $parameters = array(
1516 'head' =>& $head,
1517 'title' =>& $title,
1518 'help_url' =>& $help_url,
1519 'target' =>& $target,
1520 'disablejs' =>& $disablejs,
1521 'disablehead' =>& $disablehead,
1522 'arrayofjs' =>& $arrayofjs,
1523 'arrayofcss' =>& $arrayofcss,
1524 'morequerystring' =>& $morequerystring,
1525 'morecssonbody' =>& $morecssonbody,
1526 'replacemainareaby' =>& $replacemainareaby,
1527 'disablenofollow' =>& $disablenofollow,
1528 'disablenoindex' =>& $disablenoindex
1529
1530 );
1531 $reshook = $hookmanager->executeHooks('llxHeader', $parameters);
1532 if ($reshook > 0) {
1533 print $hookmanager->resPrint;
1534 return;
1535 }
1536
1537 // html header
1538 top_htmlhead($head, $title, $disablejs, $disablehead, $arrayofjs, $arrayofcss, 0, $disablenofollow, $disablenoindex);
1539
1540 $tmpcsstouse = 'sidebar-collapse'.($morecssonbody ? ' '.$morecssonbody : '');
1541 // If theme MD and classic layer, we open the menulayer by default.
1542 if ($conf->theme == 'md' && !in_array($conf->browser->layout, array('phone', 'tablet')) && !getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
1543 global $mainmenu;
1544 if ($mainmenu != 'website') {
1545 $tmpcsstouse = $morecssonbody; // We do not use sidebar-collpase by default to have menuhider open by default.
1546 }
1547 }
1548
1549 if (getDolGlobalString('MAIN_OPTIMIZEFORCOLORBLIND')) {
1550 $tmpcsstouse .= ' colorblind-'.strip_tags($conf->global->MAIN_OPTIMIZEFORCOLORBLIND);
1551 }
1552
1553 print '<body id="mainbody" class="'.$tmpcsstouse.'">'."\n";
1554
1555 // top menu and left menu area
1556 if ((empty($conf->dol_hide_topmenu) || GETPOST('dol_invisible_topmenu', 'int')) && !GETPOST('dol_openinpopup', 'aZ09')) {
1557 top_menu($head, $title, $target, $disablejs, $disablehead, $arrayofjs, $arrayofcss, $morequerystring, $help_url);
1558 }
1559
1560 if (empty($conf->dol_hide_leftmenu) && !GETPOST('dol_openinpopup', 'aZ09')) {
1561 left_menu(array(), $help_url, '', '', 1, $title, 1); // $menumanager is retrieved with a global $menumanager inside this function
1562 }
1563
1564 // main area
1565 if ($replacemainareaby) {
1566 print $replacemainareaby;
1567 return;
1568 }
1569 main_area($title);
1570 }
1571}
1572
1573
1581function top_httphead($contenttype = 'text/html', $forcenocache = 0)
1582{
1583 global $db, $conf, $hookmanager;
1584
1585 if ($contenttype == 'text/html') {
1586 header("Content-Type: text/html; charset=".$conf->file->character_set_client);
1587 } else {
1588 header("Content-Type: ".$contenttype);
1589 }
1590
1591 // Security options
1592
1593 // X-Content-Type-Options
1594 header("X-Content-Type-Options: nosniff"); // With the nosniff option, if the server says the content is text/html, the browser will render it as text/html (note that most browsers now force this option to on)
1595
1596 // X-Frame-Options
1597 if (!defined('XFRAMEOPTIONS_ALLOWALL')) {
1598 header("X-Frame-Options: SAMEORIGIN"); // By default, frames allowed only if on same domain (stop some XSS attacks)
1599 } else {
1600 header("X-Frame-Options: ALLOWALL");
1601 }
1602
1603 if (getDolGlobalString('MAIN_SECURITY_FORCE_ACCESS_CONTROL_ALLOW_ORIGIN')) {
1604 $tmpurl = constant('DOL_MAIN_URL_ROOT');
1605 $tmpurl = preg_replace('/^(https?:\/\/[^\/]+)\/.*$/', '\1', $tmpurl);
1606 header('Access-Control-Allow-Origin: '.$tmpurl);
1607 header('Vary: Origin');
1608 }
1609
1610 // X-XSS-Protection
1611 //header("X-XSS-Protection: 1"); // XSS filtering protection of some browsers (note: use of Content-Security-Policy is more efficient). Disabled as deprecated.
1612
1613 // Content-Security-Policy-Report-Only
1614 if (!defined('MAIN_SECURITY_FORCECSPRO')) {
1615 // If CSP not forced from the page
1616
1617 // A default security policy that keep usage of js external component like ckeditor, stripe, google, working
1618 // For example: to restrict to only local resources, except for css (cloudflare+google), and js (transifex + google tags) and object/iframe (youtube)
1619 // default-src 'self'; style-src: https://cdnjs.cloudflare.com https://fonts.googleapis.com; script-src: https://cdn.transifex.com https://www.googletagmanager.com; object-src https://youtube.com; frame-src https://youtube.com; img-src: *;
1620 // For example, to restrict everything to itself except img that can be on other servers:
1621 // default-src 'self'; img-src *;
1622 // Pre-existing site that uses too much js code to fix but wants to ensure resources are loaded only over https and disable plugins:
1623 // default-src https: 'unsafe-inline' 'unsafe-eval'; object-src 'none'
1624 //
1625 // $contentsecuritypolicy = "frame-ancestors 'self'; img-src * data:; font-src *; default-src 'self' 'unsafe-inline' 'unsafe-eval' *.paypal.com *.stripe.com *.google.com *.googleapis.com *.google-analytics.com *.googletagmanager.com;";
1626 // $contentsecuritypolicy = "frame-ancestors 'self'; img-src * data:; font-src *; default-src *; script-src 'self' 'unsafe-inline' *.paypal.com *.stripe.com *.google.com *.googleapis.com *.google-analytics.com *.googletagmanager.com; style-src 'self' 'unsafe-inline'; connect-src 'self';";
1627 $contentsecuritypolicy = getDolGlobalString('MAIN_SECURITY_FORCECSPRO');
1628
1629 if (!is_object($hookmanager)) {
1630 include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
1631 $hookmanager = new HookManager($db);
1632 }
1633 $hookmanager->initHooks(array("main"));
1634
1635 $parameters = array('contentsecuritypolicy'=>$contentsecuritypolicy, 'mode'=>'reportonly');
1636 $result = $hookmanager->executeHooks('setContentSecurityPolicy', $parameters); // Note that $action and $object may have been modified by some hooks
1637 if ($result > 0) {
1638 $contentsecuritypolicy = $hookmanager->resPrint; // Replace CSP
1639 } else {
1640 $contentsecuritypolicy .= $hookmanager->resPrint; // Concat CSP
1641 }
1642
1643 if (!empty($contentsecuritypolicy)) {
1644 header("Content-Security-Policy-Report-Only: ".$contentsecuritypolicy);
1645 }
1646 } else {
1647 header("Content-Security-Policy: ".constant('MAIN_SECURITY_FORCECSPRO'));
1648 }
1649
1650 // Content-Security-Policy
1651 if (!defined('MAIN_SECURITY_FORCECSP')) {
1652 // If CSP not forced from the page
1653
1654 // A default security policy that keep usage of js external component like ckeditor, stripe, google, working
1655 // For example: to restrict to only local resources, except for css (cloudflare+google), and js (transifex + google tags) and object/iframe (youtube)
1656 // default-src 'self'; style-src: https://cdnjs.cloudflare.com https://fonts.googleapis.com; script-src: https://cdn.transifex.com https://www.googletagmanager.com; object-src https://youtube.com; frame-src https://youtube.com; img-src: *;
1657 // For example, to restrict everything to itself except img that can be on other servers:
1658 // default-src 'self'; img-src *;
1659 // Pre-existing site that uses too much js code to fix but wants to ensure resources are loaded only over https and disable plugins:
1660 // default-src https: 'unsafe-inline' 'unsafe-eval'; object-src 'none'
1661 //
1662 // $contentsecuritypolicy = "frame-ancestors 'self'; img-src * data:; font-src *; default-src 'self' 'unsafe-inline' 'unsafe-eval' *.paypal.com *.stripe.com *.google.com *.googleapis.com *.google-analytics.com *.googletagmanager.com;";
1663 // $contentsecuritypolicy = "frame-ancestors 'self'; img-src * data:; font-src *; default-src *; script-src 'self' 'unsafe-inline' *.paypal.com *.stripe.com *.google.com *.googleapis.com *.google-analytics.com *.googletagmanager.com; style-src 'self' 'unsafe-inline'; connect-src 'self';";
1664 $contentsecuritypolicy = getDolGlobalString('MAIN_SECURITY_FORCECSP');
1665
1666 if (!is_object($hookmanager)) {
1667 include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
1668 $hookmanager = new HookManager($db);
1669 }
1670 $hookmanager->initHooks(array("main"));
1671
1672 $parameters = array('contentsecuritypolicy'=>$contentsecuritypolicy, 'mode'=>'active');
1673 $result = $hookmanager->executeHooks('setContentSecurityPolicy', $parameters); // Note that $action and $object may have been modified by some hooks
1674 if ($result > 0) {
1675 $contentsecuritypolicy = $hookmanager->resPrint; // Replace CSP
1676 } else {
1677 $contentsecuritypolicy .= $hookmanager->resPrint; // Concat CSP
1678 }
1679
1680 if (!empty($contentsecuritypolicy)) {
1681 header("Content-Security-Policy: ".$contentsecuritypolicy);
1682 }
1683 } else {
1684 header("Content-Security-Policy: ".constant('MAIN_SECURITY_FORCECSP'));
1685 }
1686
1687 // Referrer-Policy
1688 // Say if we must provide the referrer when we jump onto another web page.
1689 // Default browser are 'strict-origin-when-cross-origin' (only domain is sent on other domain switching), we want more so we use 'same-origin' so browser doesn't send any referrer at all when going into another web site domain.
1690 // Note that we do not use 'strict-origin' as this breaks feature to restore filters when clicking on "back to page" link on some cases.
1691 if (!defined('MAIN_SECURITY_FORCERP')) {
1692 $referrerpolicy = getDolGlobalString('MAIN_SECURITY_FORCERP', "same-origin");
1693
1694 header("Referrer-Policy: ".$referrerpolicy);
1695 }
1696
1697 if ($forcenocache) {
1698 header("Cache-Control: no-cache, no-store, must-revalidate, max-age=0");
1699 }
1700
1701 // No need to add this token in header, we use instead the one into the forms.
1702 //header("anti-csrf-token: ".newToken());
1703}
1704
1720function top_htmlhead($head, $title = '', $disablejs = 0, $disablehead = 0, $arrayofjs = array(), $arrayofcss = array(), $disableforlogin = 0, $disablenofollow = 0, $disablenoindex = 0)
1721{
1722 global $db, $conf, $langs, $user, $mysoc, $hookmanager;
1723
1724 top_httphead();
1725
1726 if (empty($conf->css)) {
1727 $conf->css = '/theme/eldy/style.css.php'; // If not defined, eldy by default
1728 }
1729
1730 print '<!doctype html>'."\n";
1731
1732 print '<html lang="'.substr($langs->defaultlang, 0, 2).'">'."\n";
1733
1734 //print '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr">'."\n";
1735 if (empty($disablehead)) {
1736 if (!is_object($hookmanager)) {
1737 include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
1738 $hookmanager = new HookManager($db);
1739 }
1740 $hookmanager->initHooks(array("main"));
1741
1742 $ext = 'layout='.(empty($conf->browser->layout) ? '' : $conf->browser->layout).'&amp;version='.urlencode(DOL_VERSION);
1743
1744 print "<head>\n";
1745
1746 if (GETPOST('dol_basehref', 'alpha')) {
1747 print '<base href="'.dol_escape_htmltag(GETPOST('dol_basehref', 'alpha')).'">'."\n";
1748 }
1749
1750 // Displays meta
1751 print '<meta charset="utf-8">'."\n";
1752 print '<meta name="robots" content="'.($disablenoindex ? 'index' : 'noindex').($disablenofollow ? ',follow' : ',nofollow').'">'."\n"; // Do not index
1753 print '<meta name="viewport" content="width=device-width, initial-scale=1.0">'."\n"; // Scale for mobile device
1754 print '<meta name="author" content="Dolibarr Development Team">'."\n";
1755 print '<meta name="anti-csrf-newtoken" content="'.newToken().'">'."\n";
1756 print '<meta name="anti-csrf-currenttoken" content="'.currentToken().'">'."\n";
1757 if (getDolGlobalInt('MAIN_FEATURES_LEVEL')) {
1758 print '<meta name="MAIN_FEATURES_LEVEL" content="'.getDolGlobalInt('MAIN_FEATURES_LEVEL').'">'."\n";
1759 }
1760 // Favicon
1761 $favicon = DOL_URL_ROOT.'/theme/dolibarr_256x256_color.png';
1762 if (!empty($mysoc->logo_squarred_mini)) {
1763 $favicon = DOL_URL_ROOT.'/viewimage.php?cache=1&modulepart=mycompany&file='.urlencode('logos/thumbs/'.$mysoc->logo_squarred_mini);
1764 }
1765 if (getDolGlobalString('MAIN_FAVICON_URL')) {
1766 $favicon = getDolGlobalString('MAIN_FAVICON_URL');
1767 }
1768 if (empty($conf->dol_use_jmobile)) {
1769 print '<link rel="shortcut icon" type="image/x-icon" href="'.$favicon.'"/>'."\n"; // Not required into an Android webview
1770 }
1771
1772 //if (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) print '<link rel="top" title="'.$langs->trans("Home").'" href="'.(DOL_URL_ROOT?DOL_URL_ROOT:'/').'">'."\n";
1773 //if (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) print '<link rel="copyright" title="GNU General Public License" href="https://www.gnu.org/copyleft/gpl.html#SEC1">'."\n";
1774 //if (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) print '<link rel="author" title="Dolibarr Development Team" href="https://www.dolibarr.org">'."\n";
1775
1776 // Mobile appli like icon
1777 $manifest = DOL_URL_ROOT.'/theme/'.$conf->theme.'/manifest.json.php';
1778 if (!empty($manifest)) {
1779 print '<link rel="manifest" href="'.$manifest.'" />'."\n";
1780 }
1781
1782 if (getDolGlobalString('THEME_ELDY_TOPMENU_BACK1')) {
1783 // TODO: use auto theme color switch
1784 print '<meta name="theme-color" content="rgb(' . getDolGlobalString('THEME_ELDY_TOPMENU_BACK1').')">'."\n";
1785 }
1786
1787 // Auto refresh page
1788 if (GETPOST('autorefresh', 'int') > 0) {
1789 print '<meta http-equiv="refresh" content="'.GETPOST('autorefresh', 'int').'">';
1790 }
1791
1792 // Displays title
1793 $appli = constant('DOL_APPLICATION_TITLE');
1794 if (getDolGlobalString('MAIN_APPLICATION_TITLE')) {
1795 $appli = $conf->global->MAIN_APPLICATION_TITLE;
1796 }
1797
1798 print '<title>';
1799 $titletoshow = '';
1800 if ($title && getDolGlobalString('MAIN_HTML_TITLE') && preg_match('/noapp/', $conf->global->MAIN_HTML_TITLE)) {
1801 $titletoshow = dol_htmlentities($title);
1802 } elseif ($title) {
1803 $titletoshow = dol_htmlentities($appli.' - '.$title);
1804 } else {
1805 $titletoshow = dol_htmlentities($appli);
1806 }
1807
1808 $parameters = array('title'=>$titletoshow);
1809 $result = $hookmanager->executeHooks('setHtmlTitle', $parameters); // Note that $action and $object may have been modified by some hooks
1810 if ($result > 0) {
1811 $titletoshow = $hookmanager->resPrint; // Replace Title to show
1812 } else {
1813 $titletoshow .= $hookmanager->resPrint; // Concat to Title to show
1814 }
1815
1816 print $titletoshow;
1817 print '</title>';
1818
1819 print "\n";
1820
1821 if (GETPOST('version', 'int')) {
1822 $ext = 'version='.GETPOST('version', 'int'); // usefull to force no cache on css/js
1823 }
1824 // Refresh value of MAIN_IHM_PARAMS_REV before forging the parameter line.
1825 if (GETPOST('dol_resetcache')) {
1826 include_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
1827 dolibarr_set_const($db, "MAIN_IHM_PARAMS_REV", getDolGlobalInt('MAIN_IHM_PARAMS_REV') + 1, 'chaine', 0, '', $conf->entity);
1828 }
1829
1830 $themeparam = '?lang='.$langs->defaultlang.'&amp;theme='.$conf->theme.(GETPOST('optioncss', 'aZ09') ? '&amp;optioncss='.GETPOST('optioncss', 'aZ09', 1) : '').(empty($user->id) ? '' : ('&amp;userid='.$user->id)).'&amp;entity='.$conf->entity;
1831
1832 $themeparam .= ($ext ? '&amp;'.$ext : '').'&amp;revision='.getDolGlobalInt("MAIN_IHM_PARAMS_REV");
1833 if (GETPOSTISSET('dol_hide_topmenu')) {
1834 $themeparam .= '&amp;dol_hide_topmenu='.GETPOST('dol_hide_topmenu', 'int');
1835 }
1836 if (GETPOSTISSET('dol_hide_leftmenu')) {
1837 $themeparam .= '&amp;dol_hide_leftmenu='.GETPOST('dol_hide_leftmenu', 'int');
1838 }
1839 if (GETPOSTISSET('dol_optimize_smallscreen')) {
1840 $themeparam .= '&amp;dol_optimize_smallscreen='.GETPOST('dol_optimize_smallscreen', 'int');
1841 }
1842 if (GETPOSTISSET('dol_no_mouse_hover')) {
1843 $themeparam .= '&amp;dol_no_mouse_hover='.GETPOST('dol_no_mouse_hover', 'int');
1844 }
1845 if (GETPOSTISSET('dol_use_jmobile')) {
1846 $themeparam .= '&amp;dol_use_jmobile='.GETPOST('dol_use_jmobile', 'int'); $conf->dol_use_jmobile = GETPOST('dol_use_jmobile', 'int');
1847 }
1848 if (GETPOSTISSET('THEME_DARKMODEENABLED')) {
1849 $themeparam .= '&amp;THEME_DARKMODEENABLED='.GETPOST('THEME_DARKMODEENABLED', 'int');
1850 }
1851 if (GETPOSTISSET('THEME_SATURATE_RATIO')) {
1852 $themeparam .= '&amp;THEME_SATURATE_RATIO='.GETPOST('THEME_SATURATE_RATIO', 'int');
1853 }
1854
1855 if (getDolGlobalString('MAIN_ENABLE_FONT_ROBOTO')) {
1856 print '<link rel="preconnect" href="https://fonts.gstatic.com">'."\n";
1857 print '<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@200;300;400;500;600&display=swap" rel="stylesheet">'."\n";
1858 }
1859
1860 if (!defined('DISABLE_JQUERY') && !$disablejs && $conf->use_javascript_ajax) {
1861 print '<!-- Includes CSS for JQuery (Ajax library) -->'."\n";
1862 $jquerytheme = 'base';
1863 if (getDolGlobalString('MAIN_USE_JQUERY_THEME')) {
1864 $jquerytheme = $conf->global->MAIN_USE_JQUERY_THEME;
1865 }
1866 if (constant('JS_JQUERY_UI')) {
1867 print '<link rel="stylesheet" type="text/css" href="'.JS_JQUERY_UI.'css/'.$jquerytheme.'/jquery-ui.min.css'.($ext ? '?'.$ext : '').'">'."\n"; // Forced JQuery
1868 } else {
1869 print '<link rel="stylesheet" type="text/css" href="'.DOL_URL_ROOT.'/includes/jquery/css/'.$jquerytheme.'/jquery-ui.css'.($ext ? '?'.$ext : '').'">'."\n"; // JQuery
1870 }
1871 if (!defined('DISABLE_JQUERY_JNOTIFY')) {
1872 print '<link rel="stylesheet" type="text/css" href="'.DOL_URL_ROOT.'/includes/jquery/plugins/jnotify/jquery.jnotify-alt.min.css'.($ext ? '?'.$ext : '').'">'."\n"; // JNotify
1873 }
1874 if (!defined('DISABLE_SELECT2') && (getDolGlobalString('MAIN_USE_JQUERY_MULTISELECT') || defined('REQUIRE_JQUERY_MULTISELECT'))) { // jQuery plugin "mutiselect", "multiple-select", "select2"...
1875 $tmpplugin = !getDolGlobalString('MAIN_USE_JQUERY_MULTISELECT') ?constant('REQUIRE_JQUERY_MULTISELECT') : $conf->global->MAIN_USE_JQUERY_MULTISELECT;
1876 print '<link rel="stylesheet" type="text/css" href="'.DOL_URL_ROOT.'/includes/jquery/plugins/'.$tmpplugin.'/dist/css/'.$tmpplugin.'.css'.($ext ? '?'.$ext : '').'">'."\n";
1877 }
1878 }
1879
1880 if (!defined('DISABLE_FONT_AWSOME')) {
1881 print '<!-- Includes CSS for font awesome -->'."\n";
1882 $fontawesome_directory = getDolGlobalString('MAIN_FONTAWESOME_DIRECTORY', '/theme/common/fontawesome-5');
1883 print '<link rel="stylesheet" type="text/css" href="'.DOL_URL_ROOT.$fontawesome_directory.'/css/all.min.css'.($ext ? '?'.$ext : '').'">'."\n";
1884 }
1885
1886 print '<!-- Includes CSS for Dolibarr theme -->'."\n";
1887 // Output style sheets (optioncss='print' or ''). Note: $conf->css looks like '/theme/eldy/style.css.php'
1888 $themepath = dol_buildpath($conf->css, 1);
1889 $themesubdir = '';
1890 if (!empty($conf->modules_parts['theme'])) { // This slow down
1891 foreach ($conf->modules_parts['theme'] as $reldir) {
1892 if (file_exists(dol_buildpath($reldir.$conf->css, 0))) {
1893 $themepath = dol_buildpath($reldir.$conf->css, 1);
1894 $themesubdir = $reldir;
1895 break;
1896 }
1897 }
1898 }
1899
1900 //print 'themepath='.$themepath.' themeparam='.$themeparam;exit;
1901 print '<link rel="stylesheet" type="text/css" href="'.$themepath.$themeparam.'">'."\n";
1902 if (getDolGlobalString('MAIN_FIX_FLASH_ON_CHROME')) {
1903 print '<!-- Includes CSS that does not exists as a workaround of flash bug of chrome -->'."\n".'<link rel="stylesheet" type="text/css" href="filethatdoesnotexiststosolvechromeflashbug">'."\n";
1904 }
1905
1906 // CSS forced by modules (relative url starting with /)
1907 if (!empty($conf->modules_parts['css'])) {
1908 $arraycss = (array) $conf->modules_parts['css'];
1909 foreach ($arraycss as $modcss => $filescss) {
1910 $filescss = (array) $filescss; // To be sure filecss is an array
1911 foreach ($filescss as $cssfile) {
1912 if (empty($cssfile)) {
1913 dol_syslog("Warning: module ".$modcss." declared a css path file into its descriptor that is empty.", LOG_WARNING);
1914 }
1915 // cssfile is a relative path
1916 $urlforcss = dol_buildpath($cssfile, 1);
1917 if ($urlforcss && $urlforcss != '/') {
1918 print '<!-- Includes CSS added by module '.$modcss.' -->'."\n".'<link rel="stylesheet" type="text/css" href="'.$urlforcss;
1919 // We add params only if page is not static, because some web server setup does not return content type text/css if url has parameters, so browser cache is not used.
1920 if (!preg_match('/\.css$/i', $cssfile)) {
1921 print $themeparam;
1922 }
1923 print '">'."\n";
1924 } else {
1925 dol_syslog("Warning: module ".$modcss." declared a css path file for a file we can't find.", LOG_WARNING);
1926 }
1927 }
1928 }
1929 }
1930 // CSS forced by page in top_htmlhead call (relative url starting with /)
1931 if (is_array($arrayofcss)) {
1932 foreach ($arrayofcss as $cssfile) {
1933 if (preg_match('/^(http|\/\/)/i', $cssfile)) {
1934 $urltofile = $cssfile;
1935 } else {
1936 $urltofile = dol_buildpath($cssfile, 1);
1937 }
1938 print '<!-- Includes CSS added by page -->'."\n".'<link rel="stylesheet" type="text/css" title="default" href="'.$urltofile;
1939 // We add params only if page is not static, because some web server setup does not return content type text/css if url has parameters and browser cache is not used.
1940 if (!preg_match('/\.css$/i', $cssfile)) {
1941 print $themeparam;
1942 }
1943 print '">'."\n";
1944 }
1945 }
1946
1947 // Custom CSS
1948 if (getDolGlobalString('MAIN_IHM_CUSTOM_CSS')) {
1949 // If a custom CSS was set, we add link to the custom css php file
1950 print '<link rel="stylesheet" type="text/css" href="'.DOL_URL_ROOT.'/theme/custom.css.php'.($ext ? '?'.$ext : '').'&amp;revision='.getDolGlobalInt("MAIN_IHM_PARAMS_REV").'">'."\n";
1951 }
1952
1953 // Output standard javascript links
1954 if (!defined('DISABLE_JQUERY') && !$disablejs && !empty($conf->use_javascript_ajax)) {
1955 // JQuery. Must be before other includes
1956 print '<!-- Includes JS for JQuery -->'."\n";
1957 if (defined('JS_JQUERY') && constant('JS_JQUERY')) {
1958 print '<script nonce="'.getNonce().'" src="'.JS_JQUERY.'jquery.min.js'.($ext ? '?'.$ext : '').'"></script>'."\n";
1959 } else {
1960 print '<script nonce="'.getNonce().'" src="'.DOL_URL_ROOT.'/includes/jquery/js/jquery.min.js'.($ext ? '?'.$ext : '').'"></script>'."\n";
1961 }
1962 if (defined('JS_JQUERY_UI') && constant('JS_JQUERY_UI')) {
1963 print '<script nonce="'.getNonce().'" src="'.JS_JQUERY_UI.'jquery-ui.min.js'.($ext ? '?'.$ext : '').'"></script>'."\n";
1964 } else {
1965 print '<script nonce="'.getNonce().'" src="'.DOL_URL_ROOT.'/includes/jquery/js/jquery-ui.min.js'.($ext ? '?'.$ext : '').'"></script>'."\n";
1966 }
1967 // jQuery jnotify
1968 if (!getDolGlobalString('MAIN_DISABLE_JQUERY_JNOTIFY') && !defined('DISABLE_JQUERY_JNOTIFY')) {
1969 print '<script nonce="'.getNonce().'" src="'.DOL_URL_ROOT.'/includes/jquery/plugins/jnotify/jquery.jnotify.min.js'.($ext ? '?'.$ext : '').'"></script>'."\n";
1970 }
1971 // Table drag and drop lines
1972 if (empty($disableforlogin) && !defined('DISABLE_JQUERY_TABLEDND')) {
1973 print '<script nonce="'.getNonce().'" src="'.DOL_URL_ROOT.'/includes/jquery/plugins/tablednd/jquery.tablednd.min.js'.($ext ? '?'.$ext : '').'"></script>'."\n";
1974 }
1975 // Chart
1976 if (empty($disableforlogin) && (!getDolGlobalString('MAIN_JS_GRAPH') || getDolGlobalString('MAIN_JS_GRAPH') == 'chart') && !defined('DISABLE_JS_GRAPH')) {
1977 print '<script nonce="'.getNonce().'" src="'.DOL_URL_ROOT.'/includes/nnnick/chartjs/dist/chart.min.js'.($ext ? '?'.$ext : '').'"></script>'."\n";
1978 }
1979
1980 // jQuery jeditable for Edit In Place features
1981 if (getDolGlobalString('MAIN_USE_JQUERY_JEDITABLE') && !defined('DISABLE_JQUERY_JEDITABLE')) {
1982 print '<!-- JS to manage editInPlace feature -->'."\n";
1983 print '<script nonce="'.getNonce().'" src="'.DOL_URL_ROOT.'/includes/jquery/plugins/jeditable/jquery.jeditable.js'.($ext ? '?'.$ext : '').'"></script>'."\n";
1984 print '<script nonce="'.getNonce().'" src="'.DOL_URL_ROOT.'/includes/jquery/plugins/jeditable/jquery.jeditable.ui-datepicker.js'.($ext ? '?'.$ext : '').'"></script>'."\n";
1985 print '<script nonce="'.getNonce().'" src="'.DOL_URL_ROOT.'/includes/jquery/plugins/jeditable/jquery.jeditable.ui-autocomplete.js'.($ext ? '?'.$ext : '').'"></script>'."\n";
1986 print '<script>'."\n";
1987 print 'var urlSaveInPlace = \''.DOL_URL_ROOT.'/core/ajax/saveinplace.php\';'."\n";
1988 print 'var urlLoadInPlace = \''.DOL_URL_ROOT.'/core/ajax/loadinplace.php\';'."\n";
1989 print 'var tooltipInPlace = \''.$langs->transnoentities('ClickToEdit').'\';'."\n"; // Added in title attribute of span
1990 print 'var placeholderInPlace = \'&nbsp;\';'."\n"; // If we put another string than $langs->trans("ClickToEdit") here, nothing is shown. If we put empty string, there is error, Why ?
1991 print 'var cancelInPlace = \''.$langs->trans("Cancel").'\';'."\n";
1992 print 'var submitInPlace = \''.$langs->trans('Ok').'\';'."\n";
1993 print 'var indicatorInPlace = \'<img src="'.DOL_URL_ROOT."/theme/".$conf->theme."/img/working.gif".'">\';'."\n";
1994 print 'var withInPlace = 300;'; // width in pixel for default string edit
1995 print '</script>'."\n";
1996 print '<script nonce="'.getNonce().'" src="'.DOL_URL_ROOT.'/core/js/editinplace.js'.($ext ? '?'.$ext : '').'"></script>'."\n";
1997 print '<script nonce="'.getNonce().'" src="'.DOL_URL_ROOT.'/includes/jquery/plugins/jeditable/jquery.jeditable.ckeditor.js'.($ext ? '?'.$ext : '').'"></script>'."\n";
1998 }
1999 // jQuery Timepicker
2000 if (getDolGlobalString('MAIN_USE_JQUERY_TIMEPICKER') || defined('REQUIRE_JQUERY_TIMEPICKER')) {
2001 print '<script nonce="'.getNonce().'" src="'.DOL_URL_ROOT.'/includes/jquery/plugins/timepicker/jquery-ui-timepicker-addon.js'.($ext ? '?'.$ext : '').'"></script>'."\n";
2002 print '<script nonce="'.getNonce().'" src="'.DOL_URL_ROOT.'/core/js/timepicker.js.php?lang='.$langs->defaultlang.($ext ? '&amp;'.$ext : '').'"></script>'."\n";
2003 }
2004 if (!defined('DISABLE_SELECT2') && (getDolGlobalString('MAIN_USE_JQUERY_MULTISELECT') || defined('REQUIRE_JQUERY_MULTISELECT'))) {
2005 // jQuery plugin "mutiselect", "multiple-select", "select2", ...
2006 $tmpplugin = !getDolGlobalString('MAIN_USE_JQUERY_MULTISELECT') ?constant('REQUIRE_JQUERY_MULTISELECT') : $conf->global->MAIN_USE_JQUERY_MULTISELECT;
2007 print '<script nonce="'.getNonce().'" src="'.DOL_URL_ROOT.'/includes/jquery/plugins/'.$tmpplugin.'/dist/js/'.$tmpplugin.'.full.min.js'.($ext ? '?'.$ext : '').'"></script>'."\n"; // We include full because we need the support of containerCssClass
2008 }
2009 if (!defined('DISABLE_MULTISELECT')) { // jQuery plugin "mutiselect" to select with checkboxes. Can be removed once we have an enhanced search tool
2010 print '<script nonce="'.getNonce().'" src="'.DOL_URL_ROOT.'/includes/jquery/plugins/multiselect/jquery.multi-select.js'.($ext ? '?'.$ext : '').'"></script>'."\n";
2011 }
2012 }
2013
2014 if (!$disablejs && !empty($conf->use_javascript_ajax)) {
2015 // CKEditor
2016 if (empty($disableforlogin) && (isModEnabled('fckeditor') && (!getDolGlobalString('FCKEDITOR_EDITORNAME') || getDolGlobalString('FCKEDITOR_EDITORNAME') == 'ckeditor') && !defined('DISABLE_CKEDITOR')) || defined('FORCE_CKEDITOR')) {
2017 print '<!-- Includes JS for CKEditor -->'."\n";
2018 $pathckeditor = DOL_URL_ROOT.'/includes/ckeditor/ckeditor/';
2019 $jsckeditor = 'ckeditor.js';
2020 if (constant('JS_CKEDITOR')) {
2021 // To use external ckeditor 4 js lib
2022 $pathckeditor = constant('JS_CKEDITOR');
2023 }
2024 print '<script nonce="'.getNonce().'">';
2025 print '/* enable ckeditor by main.inc.php */';
2026 print 'var CKEDITOR_BASEPATH = \''.dol_escape_js($pathckeditor).'\';'."\n";
2027 print 'var ckeditorConfig = \''.dol_escape_js(dol_buildpath($themesubdir.'/theme/'.$conf->theme.'/ckeditor/config.js'.($ext ? '?'.$ext : ''), 1)).'\';'."\n"; // $themesubdir='' in standard usage
2028 print 'var ckeditorFilebrowserBrowseUrl = \''.DOL_URL_ROOT.'/core/filemanagerdol/browser/default/browser.php?Connector='.DOL_URL_ROOT.'/core/filemanagerdol/connectors/php/connector.php\';'."\n";
2029 print 'var ckeditorFilebrowserImageBrowseUrl = \''.DOL_URL_ROOT.'/core/filemanagerdol/browser/default/browser.php?Type=Image&Connector='.DOL_URL_ROOT.'/core/filemanagerdol/connectors/php/connector.php\';'."\n";
2030 print '</script>'."\n";
2031 print '<script src="'.$pathckeditor.$jsckeditor.($ext ? '?'.$ext : '').'"></script>'."\n";
2032 print '<script>';
2033 if (GETPOST('mode', 'aZ09') == 'Full_inline') {
2034 print 'CKEDITOR.disableAutoInline = false;'."\n";
2035 } else {
2036 print 'CKEDITOR.disableAutoInline = true;'."\n";
2037 }
2038 print '</script>'."\n";
2039 }
2040
2041 // Browser notifications (if NOREQUIREMENU is on, it is mostly a page for popup, so we do not enable notif too. We hide also for public pages).
2042 if (!defined('NOBROWSERNOTIF') && !defined('NOREQUIREMENU') && !defined('NOLOGIN')) {
2043 $enablebrowsernotif = false;
2044 if (isModEnabled('agenda') && getDolGlobalString('AGENDA_REMINDER_BROWSER')) {
2045 $enablebrowsernotif = true;
2046 }
2047 if ($conf->browser->layout == 'phone') {
2048 $enablebrowsernotif = false;
2049 }
2050 if ($enablebrowsernotif) {
2051 print '<!-- Includes JS of Dolibarr (browser layout = '.$conf->browser->layout.')-->'."\n";
2052 print '<script nonce="'.getNonce().'" src="'.DOL_URL_ROOT.'/core/js/lib_notification.js.php'.($ext ? '?'.$ext : '').'"></script>'."\n";
2053 }
2054 }
2055
2056 // Global js function
2057 print '<!-- Includes JS of Dolibarr -->'."\n";
2058 print '<script nonce="'.getNonce().'" src="'.DOL_URL_ROOT.'/core/js/lib_head.js.php?lang='.$langs->defaultlang.($ext ? '&amp;'.$ext : '').'"></script>'."\n";
2059
2060 // JS forced by modules (relative url starting with /)
2061 if (!empty($conf->modules_parts['js'])) { // $conf->modules_parts['js'] is array('module'=>array('file1','file2'))
2062 $arrayjs = (array) $conf->modules_parts['js'];
2063 foreach ($arrayjs as $modjs => $filesjs) {
2064 $filesjs = (array) $filesjs; // To be sure filejs is an array
2065 foreach ($filesjs as $jsfile) {
2066 // jsfile is a relative path
2067 $urlforjs = dol_buildpath($jsfile, 1);
2068 if ($urlforjs && $urlforjs != '/') {
2069 print '<!-- Include JS added by module '.$modjs.'-->'."\n";
2070 print '<script nonce="'.getNonce().'" src="'.$urlforjs.((strpos($jsfile, '?') === false) ? '?' : '&amp;').'lang='.$langs->defaultlang.'"></script>'."\n";
2071 } else {
2072 dol_syslog("Warning: module ".$modjs." declared a js path file for a file we can't find.", LOG_WARNING);
2073 }
2074 }
2075 }
2076 }
2077 // JS forced by page in top_htmlhead (relative url starting with /)
2078 if (is_array($arrayofjs)) {
2079 print '<!-- Includes JS added by page -->'."\n";
2080 foreach ($arrayofjs as $jsfile) {
2081 if (preg_match('/^(http|\/\/)/i', $jsfile)) {
2082 print '<script nonce="'.getNonce().'" src="'.$jsfile.((strpos($jsfile, '?') === false) ? '?' : '&amp;').'lang='.$langs->defaultlang.'"></script>'."\n";
2083 } else {
2084 print '<script nonce="'.getNonce().'" src="'.dol_buildpath($jsfile, 1).((strpos($jsfile, '?') === false) ? '?' : '&amp;').'lang='.$langs->defaultlang.'"></script>'."\n";
2085 }
2086 }
2087 }
2088 }
2089
2090 //If you want to load custom javascript file from your selected theme directory
2091 if (getDolGlobalString('ALLOW_THEME_JS')) {
2092 $theme_js = dol_buildpath('/theme/'.$conf->theme.'/'.$conf->theme.'.js', 0);
2093 if (file_exists($theme_js)) {
2094 print '<script nonce="'.getNonce().'" src="'.DOL_URL_ROOT.'/theme/'.$conf->theme.'/'.$conf->theme.'.js'.($ext ? '?'.$ext : '').'"></script>'."\n";
2095 }
2096 }
2097
2098 if (!empty($head)) {
2099 print $head."\n";
2100 }
2101 if (getDolGlobalString('MAIN_HTML_HEADER')) {
2102 print getDolGlobalString('MAIN_HTML_HEADER') . "\n";
2103 }
2104
2105 $parameters = array();
2106 $result = $hookmanager->executeHooks('addHtmlHeader', $parameters); // Note that $action and $object may have been modified by some hooks
2107 print $hookmanager->resPrint; // Replace Title to show
2108
2109 print "</head>\n\n";
2110 }
2111
2112 $conf->headerdone = 1; // To tell header was output
2113}
2114
2115
2132function top_menu($head, $title = '', $target = '', $disablejs = 0, $disablehead = 0, $arrayofjs = array(), $arrayofcss = array(), $morequerystring = '', $helppagename = '')
2133{
2134 global $user, $conf, $langs, $db, $form;
2135 global $dolibarr_main_authentication, $dolibarr_main_demo;
2136 global $hookmanager, $menumanager;
2137
2138 $searchform = '';
2139
2140 // Instantiate hooks for external modules
2141 $hookmanager->initHooks(array('toprightmenu'));
2142
2143 $toprightmenu = '';
2144
2145 // For backward compatibility with old modules
2146 if (empty($conf->headerdone)) {
2147 $disablenofollow = 0;
2148 top_htmlhead($head, $title, $disablejs, $disablehead, $arrayofjs, $arrayofcss, 0, $disablenofollow);
2149 print '<body id="mainbody">';
2150 }
2151
2152 /*
2153 * Top menu
2154 */
2155 if ((empty($conf->dol_hide_topmenu) || GETPOST('dol_invisible_topmenu', 'int')) && (!defined('NOREQUIREMENU') || !constant('NOREQUIREMENU'))) {
2156 if (!isset($form) || !is_object($form)) {
2157 include_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
2158 $form = new Form($db);
2159 }
2160
2161 print "\n".'<!-- Start top horizontal -->'."\n";
2162
2163 print '<header id="id-top" class="side-nav-vert'.(GETPOST('dol_invisible_topmenu', 'int') ? ' hidden' : '').'">'; // dol_invisible_topmenu differs from dol_hide_topmenu: dol_invisible_topmenu means we output menu but we make it invisible.
2164
2165 // Show menu entries
2166 print '<div id="tmenu_tooltip'.(!getDolGlobalString('MAIN_MENU_INVERT') ? '' : 'invert').'" class="tmenu">'."\n";
2167 $menumanager->atarget = $target;
2168 $menumanager->showmenu('top', array('searchform'=>$searchform)); // This contains a \n
2169 print "</div>\n";
2170
2171 // Define link to login card
2172 $appli = constant('DOL_APPLICATION_TITLE');
2173 if (getDolGlobalString('MAIN_APPLICATION_TITLE')) {
2174 $appli = $conf->global->MAIN_APPLICATION_TITLE;
2175 if (preg_match('/\d\.\d/', $appli)) {
2176 if (!preg_match('/'.preg_quote(DOL_VERSION).'/', $appli)) {
2177 $appli .= " (".DOL_VERSION.")"; // If new title contains a version that is different than core
2178 }
2179 } else {
2180 $appli .= " ".DOL_VERSION;
2181 }
2182 } else {
2183 $appli .= " ".DOL_VERSION;
2184 }
2185
2186 if (getDolGlobalInt('MAIN_FEATURES_LEVEL')) {
2187 $appli .= "<br>".$langs->trans("LevelOfFeature").': '.getDolGlobalInt('MAIN_FEATURES_LEVEL');
2188 }
2189
2190 $logouttext = '';
2191 $logouthtmltext = '';
2192 if (!getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
2193 //$logouthtmltext=$appli.'<br>';
2194 $stringforfirstkey = $langs->trans("KeyboardShortcut");
2195 if ($conf->browser->name == 'chrome') {
2196 $stringforfirstkey .= ' ALT +';
2197 } elseif ($conf->browser->name == 'firefox') {
2198 $stringforfirstkey .= ' ALT + SHIFT +';
2199 } else {
2200 $stringforfirstkey .= ' CTL +';
2201 }
2202 if ($_SESSION["dol_authmode"] != 'forceuser' && $_SESSION["dol_authmode"] != 'http') {
2203 $logouthtmltext .= $langs->trans("Logout").'<br>';
2204 $logouttext .= '<a accesskey="l" href="'.DOL_URL_ROOT.'/user/logout.php?token='.newToken().'">';
2205 $logouttext .= img_picto($langs->trans('Logout').' ('.$stringforfirstkey.' l)', 'sign-out', '', false, 0, 0, '', 'atoplogin valignmiddle');
2206 $logouttext .= '</a>';
2207 } else {
2208 $logouthtmltext .= $langs->trans("NoLogoutProcessWithAuthMode", $_SESSION["dol_authmode"]);
2209 $logouttext .= img_picto($langs->trans('Logout').' ('.$stringforfirstkey.' l)', 'sign-out', '', false, 0, 0, '', 'atoplogin valignmiddle opacitymedium');
2210 }
2211 }
2212
2213 print '<div class="login_block usedropdown">'."\n";
2214
2215 $toprightmenu .= '<div class="login_block_other">';
2216
2217 // Execute hook printTopRightMenu (hooks should output string like '<div class="login"><a href="">mylink</a></div>')
2218 $parameters = array();
2219 $result = $hookmanager->executeHooks('printTopRightMenu', $parameters); // Note that $action and $object may have been modified by some hooks
2220 if (is_numeric($result)) {
2221 if ($result == 0) {
2222 $toprightmenu .= $hookmanager->resPrint; // add
2223 } else {
2224 $toprightmenu = $hookmanager->resPrint; // replace
2225 }
2226 } else {
2227 $toprightmenu .= $result; // For backward compatibility
2228 }
2229
2230 // Link to module builder
2231 if (isModEnabled('modulebuilder')) {
2232 $text = '<a href="'.DOL_URL_ROOT.'/modulebuilder/index.php?mainmenu=home&leftmenu=admintools" target="modulebuilder">';
2233 //$text.= img_picto(":".$langs->trans("ModuleBuilder"), 'printer_top.png', 'class="printer"');
2234 $text .= '<span class="fa fa-bug atoplogin valignmiddle"></span>';
2235 $text .= '</a>';
2236 $toprightmenu .= $form->textwithtooltip('', $langs->trans("ModuleBuilder"), 2, 1, $text, 'login_block_elem', 2);
2237 }
2238
2239 // Link to print main content area (optioncss=print)
2240 if (!getDolGlobalString('MAIN_PRINT_DISABLELINK') && !getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
2241 $qs = dol_escape_htmltag($_SERVER["QUERY_STRING"]);
2242
2243 if (isset($_POST) && is_array($_POST)) {
2244 foreach ($_POST as $key => $value) {
2245 $key = preg_replace('/[^a-z0-9_\.\-\[\]]/i', '', $key);
2246 if (in_array($key, array('action', 'massaction', 'password'))) {
2247 continue;
2248 }
2249 if (!is_array($value)) {
2250 if ($value !== '') {
2251 $qs .= '&'.urlencode($key).'='.urlencode($value);
2252 }
2253 } else {
2254 foreach ($value as $value2) {
2255 if (($value2 !== '') && (!is_array($value2))) {
2256 $qs .= '&'.urlencode($key).'[]='.urlencode($value2);
2257 }
2258 }
2259 }
2260 }
2261 }
2262 $qs .= (($qs && $morequerystring) ? '&' : '').$morequerystring;
2263 $text = '<a href="'.dol_escape_htmltag($_SERVER["PHP_SELF"]).'?'.$qs.($qs ? '&' : '').'optioncss=print" target="_blank" rel="noopener noreferrer">';
2264 //$text.= img_picto(":".$langs->trans("PrintContentArea"), 'printer_top.png', 'class="printer"');
2265 $text .= '<span class="fa fa-print atoplogin valignmiddle"></span>';
2266 $text .= '</a>';
2267 $toprightmenu .= $form->textwithtooltip('', $langs->trans("PrintContentArea"), 2, 1, $text, 'login_block_elem', 2);
2268 }
2269
2270 // Link to Dolibarr wiki pages
2271 if (!getDolGlobalString('MAIN_HELP_DISABLELINK') && !getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
2272 $langs->load("help");
2273
2274 $helpbaseurl = '';
2275 $helppage = '';
2276 $mode = '';
2277 $helppresent = '';
2278
2279 if (empty($helppagename)) {
2280 $helppagename = 'EN:User_documentation|FR:Documentation_utilisateur|ES:Documentación_usuarios|DE:Benutzerdokumentation';
2281 } else {
2282 $helppresent = 'helppresent';
2283 }
2284
2285 // Get helpbaseurl, helppage and mode from helppagename and langs
2286 $arrayres = getHelpParamFor($helppagename, $langs);
2287 $helpbaseurl = $arrayres['helpbaseurl'];
2288 $helppage = $arrayres['helppage'];
2289 $mode = $arrayres['mode'];
2290
2291 // Link to help pages
2292 if ($helpbaseurl && $helppage) {
2293 $text = '';
2294 $title = $langs->trans($mode == 'wiki' ? 'GoToWikiHelpPage' : 'GoToHelpPage').', ';
2295 if ($mode == 'wiki') {
2296 $title .= '<br>'.img_picto('', 'globe', 'class="pictofixedwidth"').$langs->trans("PageWiki").' '.dol_escape_htmltag('"'.strtr($helppage, '_', ' ').'"');
2297 if ($helppresent) {
2298 $title .= ' <span class="opacitymedium">('.$langs->trans("DedicatedPageAvailable").')</span>';
2299 } else {
2300 $title .= ' <span class="opacitymedium">('.$langs->trans("HomePage").')</span>';
2301 }
2302 }
2303 $text .= '<a class="help" target="_blank" rel="noopener noreferrer" href="';
2304 if ($mode == 'wiki') {
2305 $text .= sprintf($helpbaseurl, urlencode(html_entity_decode($helppage)));
2306 } else {
2307 $text .= sprintf($helpbaseurl, $helppage);
2308 }
2309 $text .= '">';
2310 $text .= '<span class="fa fa-question-circle atoplogin valignmiddle'.($helppresent ? ' '.$helppresent : '').'"></span>';
2311 $text .= '<span class="fa fa-long-arrow-alt-up helppresentcircle'.($helppresent ? '' : ' unvisible').'"></span>';
2312 $text .= '</a>';
2313 $toprightmenu .= $form->textwithtooltip('', $title, 2, 1, $text, 'login_block_elem', 2);
2314 }
2315
2316 // Version
2317 if (getDolGlobalString('MAIN_SHOWDATABASENAMEINHELPPAGESLINK')) {
2318 $langs->load('admin');
2319 $appli .= '<br>'.$langs->trans("Database").': '.$db->database_name;
2320 }
2321 }
2322
2323 if (!getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
2324 $text = '<span class="aversion"><span class="hideonsmartphone small">'.DOL_VERSION.'</span></span>';
2325 $toprightmenu .= $form->textwithtooltip('', $appli, 2, 1, $text, 'login_block_elem', 2);
2326 }
2327
2328 // Logout link
2329 $toprightmenu .= $form->textwithtooltip('', $logouthtmltext, 2, 1, $logouttext, 'login_block_elem logout-btn', 2);
2330
2331 $toprightmenu .= '</div>'; // end div class="login_block_other"
2332
2333
2334 // Add login user link
2335 $toprightmenu .= '<div class="login_block_user">';
2336
2337 // Login name with photo and tooltip
2338 $mode = -1;
2339 $toprightmenu .= '<div class="inline-block login_block_elem login_block_elem_name nowrap centpercent" style="padding: 0px;">';
2340
2341 if (getDolGlobalString('MAIN_USE_TOP_MENU_SEARCH_DROPDOWN')) {
2342 // Add search dropdown
2343 $toprightmenu .= top_menu_search();
2344 }
2345
2346 if (getDolGlobalString('MAIN_USE_TOP_MENU_QUICKADD_DROPDOWN')) {
2347 // Add search dropdown
2348 $toprightmenu .= top_menu_quickadd();
2349 }
2350
2351 // Add bookmark dropdown
2352 $toprightmenu .= top_menu_bookmark();
2353
2354 // Add user dropdown
2355 $toprightmenu .= top_menu_user();
2356
2357 $toprightmenu .= '</div>';
2358
2359 $toprightmenu .= '</div>'."\n";
2360
2361
2362 print $toprightmenu;
2363
2364 print "</div>\n"; // end div class="login_block"
2365
2366 print '</header>';
2367 //print '<header class="header2">&nbsp;</header>';
2368
2369 print '<div style="clear: both;"></div>';
2370 print "<!-- End top horizontal menu -->\n\n";
2371 }
2372
2373 if (empty($conf->dol_hide_leftmenu) && empty($conf->dol_use_jmobile)) {
2374 print '<!-- Begin div id-container --><div id="id-container" class="id-container">';
2375 }
2376}
2377
2378
2386function top_menu_user($hideloginname = 0, $urllogout = '')
2387{
2388 global $langs, $conf, $db, $hookmanager, $user, $mysoc;
2389 global $dolibarr_main_authentication, $dolibarr_main_demo;
2390 global $menumanager;
2391
2392 $langs->load('companies');
2393
2394 $userImage = $userDropDownImage = '';
2395 if (!empty($user->photo)) {
2396 $userImage = Form::showphoto('userphoto', $user, 0, 0, 0, 'photouserphoto userphoto', 'small', 0, 1);
2397 $userDropDownImage = Form::showphoto('userphoto', $user, 0, 0, 0, 'dropdown-user-image', 'small', 0, 1);
2398 } else {
2399 $nophoto = '/public/theme/common/user_anonymous.png';
2400 if ($user->gender == 'man') {
2401 $nophoto = '/public/theme/common/user_man.png';
2402 }
2403 if ($user->gender == 'woman') {
2404 $nophoto = '/public/theme/common/user_woman.png';
2405 }
2406
2407 $userImage = '<img class="photo photouserphoto userphoto" alt="No photo" src="'.DOL_URL_ROOT.$nophoto.'">';
2408 $userDropDownImage = '<img class="photo dropdown-user-image" alt="No photo" src="'.DOL_URL_ROOT.$nophoto.'">';
2409 }
2410
2411 $dropdownBody = '';
2412 $dropdownBody .= '<span id="topmenulogincompanyinfo-btn"><i class="fa fa-caret-right"></i> '.$langs->trans("ShowCompanyInfos").'</span>';
2413 $dropdownBody .= '<div id="topmenulogincompanyinfo" >';
2414
2415 $dropdownBody .= '<br><b>'.$langs->trans("Company").'</b>: <span>'.dol_escape_htmltag($mysoc->name).'</span>';
2416 if ($langs->transcountry("ProfId1", $mysoc->country_code) != '-') {
2417 $dropdownBody .= '<br><b>'.$langs->transcountry("ProfId1", $mysoc->country_code).'</b>: <span>'.dol_print_profids(getDolGlobalString("MAIN_INFO_SIREN"), 1).'</span>';
2418 }
2419 if ($langs->transcountry("ProfId2", $mysoc->country_code) != '-') {
2420 $dropdownBody .= '<br><b>'.$langs->transcountry("ProfId2", $mysoc->country_code).'</b>: <span>'.dol_print_profids(getDolGlobalString("MAIN_INFO_SIRET"), 2).'</span>';
2421 }
2422 if ($langs->transcountry("ProfId3", $mysoc->country_code) != '-') {
2423 $dropdownBody .= '<br><b>'.$langs->transcountry("ProfId3", $mysoc->country_code).'</b>: <span>'.dol_print_profids(getDolGlobalString("MAIN_INFO_APE"), 3).'</span>';
2424 }
2425 if ($langs->transcountry("ProfId4", $mysoc->country_code) != '-') {
2426 $dropdownBody .= '<br><b>'.$langs->transcountry("ProfId4", $mysoc->country_code).'</b>: <span>'.dol_print_profids(getDolGlobalString("MAIN_INFO_RCS"), 4).'</span>';
2427 }
2428 if ($langs->transcountry("ProfId5", $mysoc->country_code) != '-') {
2429 $dropdownBody .= '<br><b>'.$langs->transcountry("ProfId5", $mysoc->country_code).'</b>: <span>'.dol_print_profids(getDolGlobalString("MAIN_INFO_PROFID5"), 5).'</span>';
2430 }
2431 if ($langs->transcountry("ProfId6", $mysoc->country_code) != '-') {
2432 $dropdownBody .= '<br><b>'.$langs->transcountry("ProfId6", $mysoc->country_code).'</b>: <span>'.dol_print_profids(getDolGlobalString("MAIN_INFO_PROFID6"), 6).'</span>';
2433 }
2434 $dropdownBody .= '<br><b>'.$langs->trans("VATIntraShort").'</b>: <span>'.dol_print_profids(getDolGlobalString("MAIN_INFO_TVAINTRA"), 'VAT').'</span>';
2435 $dropdownBody .= '<br><b>'.$langs->trans("Country").'</b>: <span>'.($mysoc->country_code ? $langs->trans("Country".$mysoc->country_code) : '').'</span>';
2436 if (isModEnabled('multicurrency')) {
2437 $dropdownBody .= '<br><b>'.$langs->trans("Currency").'</b>: <span>'.$conf->currency.'</span>';
2438 }
2439 $dropdownBody .= '</div>';
2440
2441 $dropdownBody .= '<br>';
2442 $dropdownBody .= '<span id="topmenuloginmoreinfo-btn"><i class="fa fa-caret-right"></i> '.$langs->trans("ShowMoreInfos").'</span>';
2443 $dropdownBody .= '<div id="topmenuloginmoreinfo" >';
2444
2445 // login infos
2446 if (!empty($user->admin)) {
2447 $dropdownBody .= '<br><b>'.$langs->trans("Administrator").'</b>: '.yn($user->admin);
2448 }
2449 if (!empty($user->socid)) { // Add thirdparty for external users
2450 $thirdpartystatic = new Societe($db);
2451 $thirdpartystatic->fetch($user->socid);
2452 $companylink = ' '.$thirdpartystatic->getNomUrl(2); // picto only of company
2453 $company = ' ('.$langs->trans("Company").': '.$thirdpartystatic->name.')';
2454 }
2455 $type = ($user->socid ? $langs->trans("External").$company : $langs->trans("Internal"));
2456 $dropdownBody .= '<br><b>'.$langs->trans("Type").':</b> '.$type;
2457 $dropdownBody .= '<br><b>'.$langs->trans("Status").'</b>: '.$user->getLibStatut(0);
2458 $dropdownBody .= '<br>';
2459
2460 $dropdownBody .= '<br><u>'.$langs->trans("Session").'</u>';
2461 $dropdownBody .= '<br><b>'.$langs->trans("IPAddress").'</b>: '.dol_escape_htmltag($_SERVER["REMOTE_ADDR"]);
2462 if (getDolGlobalString('MAIN_MODULE_MULTICOMPANY')) {
2463 $dropdownBody .= '<br><b>'.$langs->trans("ConnectedOnMultiCompany").':</b> '.$conf->entity.' (user entity '.$user->entity.')';
2464 }
2465 $dropdownBody .= '<br><b>'.$langs->trans("AuthenticationMode").':</b> '.$_SESSION["dol_authmode"].(empty($dolibarr_main_demo) ? '' : ' (demo)');
2466 $dropdownBody .= '<br><b>'.$langs->trans("ConnectedSince").':</b> '.dol_print_date($user->datelastlogin, "dayhour", 'tzuser');
2467 $dropdownBody .= '<br><b>'.$langs->trans("PreviousConnexion").':</b> '.dol_print_date($user->datepreviouslogin, "dayhour", 'tzuser');
2468 $dropdownBody .= '<br><b>'.$langs->trans("CurrentTheme").':</b> '.$conf->theme;
2469 $dropdownBody .= '<br><b>'.$langs->trans("CurrentMenuManager").':</b> '.(isset($menumanager) ? $menumanager->name : 'unknown');
2470 $langFlag = picto_from_langcode($langs->getDefaultLang());
2471 $dropdownBody .= '<br><b>'.$langs->trans("CurrentUserLanguage").':</b> '.($langFlag ? $langFlag.' ' : '').$langs->getDefaultLang();
2472
2473 $tz = (int) $_SESSION['dol_tz'] + (int) $_SESSION['dol_dst'];
2474 $dropdownBody .= '<br><b>'.$langs->trans("ClientTZ").':</b> '.($tz ? ($tz >= 0 ? '+' : '').$tz : '');
2475 $dropdownBody .= ' ('.$_SESSION['dol_tz_string'].')';
2476 //$dropdownBody .= ' &nbsp; &nbsp; &nbsp; '.$langs->trans("DaylingSavingTime").': ';
2477 //if ($_SESSION['dol_dst'] > 0) $dropdownBody .= yn(1);
2478 //else $dropdownBody .= yn(0);
2479
2480 $dropdownBody .= '<br><b>'.$langs->trans("Browser").':</b> '.$conf->browser->name.($conf->browser->version ? ' '.$conf->browser->version : '').' <small class="opacitymedium">('.dol_escape_htmltag($_SERVER['HTTP_USER_AGENT']).')</small>';
2481 $dropdownBody .= '<br><b>'.$langs->trans("Layout").':</b> '.$conf->browser->layout;
2482 $dropdownBody .= '<br><b>'.$langs->trans("Screen").':</b> '.$_SESSION['dol_screenwidth'].' x '.$_SESSION['dol_screenheight'];
2483 if ($conf->browser->layout == 'phone') {
2484 $dropdownBody .= '<br><b>'.$langs->trans("Phone").':</b> '.$langs->trans("Yes");
2485 }
2486 if (!empty($_SESSION["disablemodules"])) {
2487 $dropdownBody .= '<br><b>'.$langs->trans("DisabledModules").':</b> <br>'.join(', ', explode(',', $_SESSION["disablemodules"]));
2488 }
2489 $dropdownBody .= '</div>';
2490
2491 // Execute hook
2492 $parameters = array('user'=>$user, 'langs' => $langs);
2493 $result = $hookmanager->executeHooks('printTopRightMenuLoginDropdownBody', $parameters); // Note that $action and $object may have been modified by some hooks
2494 if (is_numeric($result)) {
2495 if ($result == 0) {
2496 $dropdownBody .= $hookmanager->resPrint; // add
2497 } else {
2498 $dropdownBody = $hookmanager->resPrint; // replace
2499 }
2500 }
2501
2502 if (empty($urllogout)) {
2503 $urllogout = DOL_URL_ROOT.'/user/logout.php?token='.newToken();
2504 }
2505
2506 // accesskey is for Windows or Linux: ALT + key for chrome, ALT + SHIFT + KEY for firefox
2507 // accesskey is for Mac: CTRL + key for all browsers
2508 $stringforfirstkey = $langs->trans("KeyboardShortcut");
2509 if ($conf->browser->name == 'chrome') {
2510 $stringforfirstkey .= ' ALT +';
2511 } elseif ($conf->browser->name == 'firefox') {
2512 $stringforfirstkey .= ' ALT + SHIFT +';
2513 } else {
2514 $stringforfirstkey .= ' CTL +';
2515 }
2516
2517 // Defined the links for bottom of card
2518 $profilLink = '<a accesskey="u" href="'.DOL_URL_ROOT.'/user/card.php?id='.$user->id.'" class="button-top-menu-dropdown" title="'.dol_escape_htmltag($langs->trans("YourUserFile").' ('.$stringforfirstkey.' u)').'"><i class="fa fa-user"></i> '.$langs->trans("Card").'</a>';
2519 $urltovirtualcard = '/user/virtualcard.php?id='.((int) $user->id);
2520 $virtuelcardLink = dolButtonToOpenUrlInDialogPopup('publicvirtualcardmenu', $langs->transnoentitiesnoconv("PublicVirtualCardUrl").(is_object($user) ? ' - '.$user->getFullName($langs) : '').' ('.$stringforfirstkey.' v)', img_picto($langs->trans("PublicVirtualCardUrl").' ('.$stringforfirstkey.' v)', 'card', ''), $urltovirtualcard, '', 'button-top-menu-dropdown marginleftonly nohover', "closeTopMenuLoginDropdown()", '', 'v');
2521 $logoutLink = '<a accesskey="l" href="'.$urllogout.'" class="button-top-menu-dropdown" title="'.dol_escape_htmltag($langs->trans("Logout").' ('.$stringforfirstkey.' l)').'"><i class="fa fa-sign-out-alt padingright"></i><span class="hideonsmartphone">'.$langs->trans("Logout").'</span></a>';
2522
2523 $profilName = $user->getFullName($langs).' ('.$user->login.')';
2524 if (!empty($user->admin)) {
2525 $profilName = '<i class="far fa-star classfortooltip" title="'.$langs->trans("Administrator").'" ></i> '.$profilName;
2526 }
2527
2528 // Define version to show
2529 $appli = constant('DOL_APPLICATION_TITLE');
2530 if (getDolGlobalString('MAIN_APPLICATION_TITLE')) {
2531 $appli = $conf->global->MAIN_APPLICATION_TITLE;
2532 if (preg_match('/\d\.\d/', $appli)) {
2533 if (!preg_match('/'.preg_quote(DOL_VERSION).'/', $appli)) {
2534 $appli .= " (".DOL_VERSION.")"; // If new title contains a version that is different than core
2535 }
2536 } else {
2537 $appli .= " ".DOL_VERSION;
2538 }
2539 } else {
2540 $appli .= " ".DOL_VERSION;
2541 }
2542
2543 if (!getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
2544 $btnUser = '<!-- div for user link -->
2545 <div id="topmenu-login-dropdown" class="userimg atoplogin dropdown user user-menu inline-block">
2546 <a href="'.DOL_URL_ROOT.'/user/card.php?id='.$user->id.'" class="dropdown-toggle login-dropdown-a valignmiddle" data-toggle="dropdown">
2547 '.$userImage.(empty($user->photo) ? '<!-- no photo so show also the login --><span class="hidden-xs maxwidth200 atoploginusername hideonsmartphone paddingleft valignmiddle small">'.dol_trunc($user->firstname ? $user->firstname : $user->login, 10).'</span>' : '').'
2548 </a>
2549 <div class="dropdown-menu">
2550 <!-- User image -->
2551 <div class="user-header">
2552 '.$userDropDownImage.'
2553 <p>
2554 '.$profilName.'<br>';
2555 if ($user->datelastlogin) {
2556 $title = $langs->trans("ConnectedSince").' : '.dol_print_date($user->datelastlogin, "dayhour", 'tzuser');
2557 if ($user->datepreviouslogin) {
2558 $title .= '<br>'.$langs->trans("PreviousConnexion").' : '.dol_print_date($user->datepreviouslogin, "dayhour", 'tzuser');
2559 }
2560 }
2561 $btnUser .= '<small class="classfortooltip" title="'.dol_escape_htmltag($title).'" ><i class="fa fa-user-clock"></i> '.dol_print_date($user->datelastlogin, "dayhour", 'tzuser').'</small><br>';
2562 if ($user->datepreviouslogin) {
2563 $btnUser .= '<small class="classfortooltip" title="'.dol_escape_htmltag($title).'" ><i class="fa fa-user-clock opacitymedium"></i> '.dol_print_date($user->datepreviouslogin, "dayhour", 'tzuser').'</small><br>';
2564 }
2565
2566 //$btnUser .= '<small class="classfortooltip"><i class="fa fa-cog"></i> '.$langs->trans("Version").' '.$appli.'</small>';
2567 $btnUser .= '
2568 </p>
2569 </div>
2570
2571 <!-- Menu Body user-->
2572 <div class="user-body">'.$dropdownBody.'</div>
2573
2574 <!-- Menu Footer-->
2575 <div class="user-footer">
2576 <div class="pull-left">
2577 '.$profilLink.'
2578 </div>
2579 <div class="pull-left">
2580 '.$virtuelcardLink.'
2581 </div>
2582 <div class="pull-right">
2583 '.$logoutLink.'
2584 </div>
2585 <div class="clearboth"></div>
2586 </div>
2587
2588 </div>
2589 </div>';
2590 } else {
2591 $btnUser = '<!-- div for user link text browser -->
2592 <div id="topmenu-login-dropdown" class="userimg atoplogin dropdown user user-menu inline-block">
2593 <a href="'.DOL_URL_ROOT.'/user/card.php?id='.$user->id.'" class="valignmiddle">
2594 '.$userImage.(empty($user->photo) ? '<span class="hidden-xs maxwidth200 atoploginusername hideonsmartphone paddingleft small">'.dol_trunc($user->firstname ? $user->firstname : $user->login, 10).'</span>' : '').'
2595 </a>
2596 </div>';
2597 }
2598
2599 if (!defined('JS_JQUERY_DISABLE_DROPDOWN') && !empty($conf->use_javascript_ajax)) { // This may be set by some pages that use different jquery version to avoid errors
2600 $btnUser .= '
2601 <!-- Code to show/hide the user drop-down -->
2602 <script>
2603 function closeTopMenuLoginDropdown() {
2604 //console.log("close login dropdown"); // This is call at each click on page, so we disable the log
2605 // Hide the menus.
2606 jQuery("#topmenu-login-dropdown").removeClass("open");
2607 }
2608 jQuery(document).ready(function() {
2609 jQuery(document).on("click", function(event) {
2610 // console.log("Click somewhere on screen");
2611 if (!$(event.target).closest("#topmenu-login-dropdown").length) {
2612 closeTopMenuLoginDropdown();
2613 }
2614 });
2615 ';
2616
2617
2618 //if ($conf->theme != 'md') {
2619 $btnUser .= '
2620 jQuery("#topmenu-login-dropdown .dropdown-toggle").on("click", function(event) {
2621 console.log("Click on #topmenu-login-dropdown .dropdown-toggle");
2622 event.preventDefault();
2623 jQuery("#topmenu-login-dropdown").toggleClass("open");
2624 });
2625
2626 jQuery("#topmenulogincompanyinfo-btn").on("click", function() {
2627 console.log("Clik on #topmenulogincompanyinfo-btn");
2628 jQuery("#topmenulogincompanyinfo").slideToggle();
2629 });
2630
2631 jQuery("#topmenuloginmoreinfo-btn").on("click", function() {
2632 console.log("Clik on #topmenuloginmoreinfo-btn");
2633 jQuery("#topmenuloginmoreinfo").slideToggle();
2634 });';
2635 //}
2636
2637 $btnUser .= '
2638 });
2639 </script>
2640 ';
2641 }
2642
2643 return $btnUser;
2644}
2645
2652{
2653 global $conf, $langs;
2654
2655 $html = '';
2656
2657 // accesskey is for Windows or Linux: ALT + key for chrome, ALT + SHIFT + KEY for firefox
2658 // accesskey is for Mac: CTRL + key for all browsers
2659 $stringforfirstkey = $langs->trans("KeyboardShortcut");
2660 if ($conf->browser->os === 'macintosh') {
2661 $stringforfirstkey .= ' CTL +';
2662 } else {
2663 if ($conf->browser->name == 'chrome') {
2664 $stringforfirstkey .= ' ALT +';
2665 } elseif ($conf->browser->name == 'firefox') {
2666 $stringforfirstkey .= ' ALT + SHIFT +';
2667 } else {
2668 $stringforfirstkey .= ' CTL +';
2669 }
2670 }
2671
2672 $html .= '<!-- div for quick add link -->
2673 <div id="topmenu-quickadd-dropdown" class="atoplogin dropdown inline-block">
2674 <a accesskey="a" class="dropdown-toggle login-dropdown-a nofocusvisible" data-toggle="dropdown" href="#" title="'.$langs->trans('QuickAdd').' ('.$stringforfirstkey.' a)"><i class="fa fa-plus-circle"></i></a>
2675 <div class="dropdown-menu">'.printDropdownQuickadd().'</div>
2676 </div>';
2677 if (!defined('JS_JQUERY_DISABLE_DROPDOWN') && !empty($conf->use_javascript_ajax)) { // This may be set by some pages that use different jquery version to avoid errors
2678 $html .= '
2679 <!-- Code to show/hide the user drop-down for the quick add -->
2680 <script>
2681 jQuery(document).ready(function() {
2682 jQuery(document).on("click", function(event) {
2683 if (!$(event.target).closest("#topmenu-quickadd-dropdown").length) {
2684 // Hide the menus.
2685 $("#topmenu-quickadd-dropdown").removeClass("open");
2686 }
2687 });
2688 $("#topmenu-quickadd-dropdown .dropdown-toggle").on("click", function(event) {
2689 console.log("Click on #topmenu-quickadd-dropdown .dropdown-toggle");
2690 openQuickAddDropDown(event);
2691 });
2692
2693 // Key map shortcut
2694 $(document).keydown(function(event){
2695 var ostype = \''.dol_escape_js($conf->browser->os).'\';
2696 if (ostype === "macintosh") {
2697 if ( event.which === 65 && event.ctrlKey ) {
2698 console.log(\'control + a : trigger open quick add dropdown\');
2699 openQuickAddDropDown(event);
2700 }
2701 } else {
2702 if ( event.which === 65 && event.ctrlKey && event.shiftKey ) {
2703 console.log(\'control + shift + a : trigger open quick add dropdown\');
2704 openQuickAddDropDown(event);
2705 }
2706 }
2707 });
2708
2709 var openQuickAddDropDown = function(event) {
2710 event.preventDefault();
2711 $("#topmenu-quickadd-dropdown").toggleClass("open");
2712 //$("#top-quickadd-search-input").focus();
2713 }
2714 });
2715 </script>
2716 ';
2717 }
2718 return $html;
2719}
2720
2727{
2728 global $conf, $user, $langs, $hookmanager;
2729
2730 $items = array(
2731 'items' => array(
2732 array(
2733 "url" => "/adherents/card.php?action=create&amp;mainmenu=members",
2734 "title" => "MenuNewMember@members",
2735 "name" => "Adherent@members",
2736 "picto" => "object_member",
2737 "activation" => isModEnabled('adherent') && $user->hasRight("adherent", "write"), // vs hooking
2738 "position" => 5,
2739 ),
2740 array(
2741 "url" => "/societe/card.php?action=create&amp;mainmenu=companies",
2742 "title" => "MenuNewThirdParty@companies",
2743 "name" => "ThirdParty@companies",
2744 "picto" => "object_company",
2745 "activation" => isModEnabled("societe") && $user->hasRight("societe", "write"), // vs hooking
2746 "position" => 10,
2747 ),
2748 array(
2749 "url" => "/contact/card.php?action=create&amp;mainmenu=companies",
2750 "title" => "NewContactAddress@companies",
2751 "name" => "Contact@companies",
2752 "picto" => "object_contact",
2753 "activation" => isModEnabled("societe") && $user->hasRight("societe", "contact", "write"), // vs hooking
2754 "position" => 20,
2755 ),
2756 array(
2757 "url" => "/comm/propal/card.php?action=create&amp;mainmenu=commercial",
2758 "title" => "NewPropal@propal",
2759 "name" => "Proposal@propal",
2760 "picto" => "object_propal",
2761 "activation" => isModEnabled("propal") && $user->hasRight("propal", "write"), // vs hooking
2762 "position" => 30,
2763 ),
2764
2765 array(
2766 "url" => "/commande/card.php?action=create&amp;mainmenu=commercial",
2767 "title" => "NewOrder@orders",
2768 "name" => "Order@orders",
2769 "picto" => "object_order",
2770 "activation" => isModEnabled('commande') && $user->hasRight("commande", "write"), // vs hooking
2771 "position" => 40,
2772 ),
2773 array(
2774 "url" => "/compta/facture/card.php?action=create&amp;mainmenu=billing",
2775 "title" => "NewBill@bills",
2776 "name" => "Bill@bills",
2777 "picto" => "object_bill",
2778 "activation" => isModEnabled('facture') && $user->hasRight("facture", "write"), // vs hooking
2779 "position" => 50,
2780 ),
2781 array(
2782 "url" => "/contrat/card.php?action=create&amp;mainmenu=commercial",
2783 "title" => "NewContractSubscription@contracts",
2784 "name" => "Contract@contracts",
2785 "picto" => "object_contract",
2786 "activation" => isModEnabled('contrat') && $user->hasRight("contrat", "write"), // vs hooking
2787 "position" => 60,
2788 ),
2789 array(
2790 "url" => "/supplier_proposal/card.php?action=create&amp;mainmenu=commercial",
2791 "title" => "SupplierProposalNew@supplier_proposal",
2792 "name" => "SupplierProposal@supplier_proposal",
2793 "picto" => "supplier_proposal",
2794 "activation" => isModEnabled('supplier_proposal') && $user->hasRight("supplier_invoice", "write"), // vs hooking
2795 "position" => 70,
2796 ),
2797 array(
2798 "url" => "/fourn/commande/card.php?action=create&amp;mainmenu=commercial",
2799 "title" => "NewSupplierOrderShort@orders",
2800 "name" => "SupplierOrder@orders",
2801 "picto" => "supplier_order",
2802 "activation" => (isModEnabled("fournisseur") && !getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD') && $user->hasRight("fournisseur", "commande", "write")) || (isModEnabled("supplier_order") && $user->hasRight("supplier_invoice", "write")), // vs hooking
2803 "position" => 80,
2804 ),
2805 array(
2806 "url" => "/fourn/facture/card.php?action=create&amp;mainmenu=billing",
2807 "title" => "NewBill@bills",
2808 "name" => "SupplierBill@bills",
2809 "picto" => "supplier_invoice",
2810 "activation" => (isModEnabled("fournisseur") && !getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD') && $user->hasRight("fournisseur", "facture", "write")) || (isModEnabled("supplier_invoice") && $user->hasRight("supplier_invoice", "write")), // vs hooking
2811 "position" => 90,
2812 ),
2813 array(
2814 "url" => "/ticket/card.php?action=create&amp;mainmenu=ticket",
2815 "title" => "NewTicket@ticket",
2816 "name" => "Ticket@ticket",
2817 "picto" => "ticket",
2818 "activation" => isModEnabled('ticket') && $user->hasRight("ticket", "write"), // vs hooking
2819 "position" => 100,
2820 ),
2821 array(
2822 "url" => "/fichinter/card.php?action=create&mainmenu=commercial",
2823 "title" => "NewIntervention@interventions",
2824 "name" => "Intervention@interventions",
2825 "picto" => "intervention",
2826 "activation" => isModEnabled('ficheinter') && $user->hasRight("ficheinter", "creer"), // vs hooking
2827 "position" => 110,
2828 ),
2829 array(
2830 "url" => "/product/card.php?action=create&amp;type=0&amp;mainmenu=products",
2831 "title" => "NewProduct@products",
2832 "name" => "Product@products",
2833 "picto" => "object_product",
2834 "activation" => isModEnabled("product") && $user->hasRight("produit", "write"), // vs hooking
2835 "position" => 400,
2836 ),
2837 array(
2838 "url" => "/product/card.php?action=create&amp;type=1&amp;mainmenu=products",
2839 "title" => "NewService@products",
2840 "name" => "Service@products",
2841 "picto" => "object_service",
2842 "activation" => isModEnabled("service") && $user->hasRight("service", "write"), // vs hooking
2843 "position" => 410,
2844 ),
2845 array(
2846 "url" => "/user/card.php?action=create&amp;type=1&amp;mainmenu=home",
2847 "title" => "AddUser@users",
2848 "name" => "User@users",
2849 "picto" => "user",
2850 "activation" => $user->hasRight("user", "user", "write"), // vs hooking
2851 "position" => 500,
2852 ),
2853 ),
2854 );
2855
2856 $dropDownQuickAddHtml = '';
2857
2858 // Define $dropDownQuickAddHtml
2859 $dropDownQuickAddHtml .= '<div class="quickadd-body dropdown-body">';
2860 $dropDownQuickAddHtml .= '<div class="dropdown-quickadd-list">';
2861
2862 // Allow the $items of the menu to be manipulated by modules
2863 $parameters = array();
2864 $hook_items = $items;
2865 $reshook = $hookmanager->executeHooks('menuDropdownQuickaddItems', $parameters, $hook_items); // Note that $action and $object may have been modified by some hooks
2866 if (is_numeric($reshook) && !empty($hookmanager->resArray) && is_array($hookmanager->resArray)) {
2867 if ($reshook == 0) {
2868 $items['items'] = array_merge($items['items'], $hookmanager->resArray); // add
2869 } else {
2870 $items = $hookmanager->resArray; // replace
2871 }
2872
2873 // Sort menu items by 'position' value
2874 $position = array();
2875 foreach ($items['items'] as $key => $row) {
2876 $position[$key] = $row['position'];
2877 }
2878 $array1_sort_order = SORT_ASC;
2879 array_multisort($position, $array1_sort_order, $items['items']);
2880 }
2881
2882 foreach ($items['items'] as $item) {
2883 if (!$item['activation']) {
2884 continue;
2885 }
2886 $langs->load(explode('@', $item['title'])[1]);
2887 $langs->load(explode('@', $item['name'])[1]);
2888 $dropDownQuickAddHtml .= '
2889 <a class="dropdown-item quickadd-item" href="'.DOL_URL_ROOT.$item['url'].'" title="'.$langs->trans(explode('@', $item['title'])[0]).'">
2890 '. img_picto('', $item['picto'], 'style="width:18px;"') . ' ' . $langs->trans(explode('@', $item['name'])[0]) . '</a>
2891 ';
2892 }
2893
2894 $dropDownQuickAddHtml .= '</div>';
2895 $dropDownQuickAddHtml .= '</div>';
2896
2897 return $dropDownQuickAddHtml;
2898}
2899
2906{
2907 global $langs, $conf, $db, $user;
2908
2909 $html = '';
2910
2911 // Define $bookmarks
2912 if (!isModEnabled('bookmark') || !$user->hasRight('bookmark', 'lire')) {
2913 return $html;
2914 }
2915
2916 // accesskey is for Windows or Linux: ALT + key for chrome, ALT + SHIFT + KEY for firefox
2917 // accesskey is for Mac: CTRL + key for all browsers
2918 $stringforfirstkey = $langs->trans("KeyboardShortcut");
2919 if ($conf->browser->os === 'macintosh') {
2920 $stringforfirstkey .= ' CTL +';
2921 } else {
2922 if ($conf->browser->name == 'chrome') {
2923 $stringforfirstkey .= ' ALT +';
2924 } elseif ($conf->browser->name == 'firefox') {
2925 $stringforfirstkey .= ' ALT + SHIFT +';
2926 } else {
2927 $stringforfirstkey .= ' CTL +';
2928 }
2929 }
2930
2931 if (!defined('JS_JQUERY_DISABLE_DROPDOWN') && !empty($conf->use_javascript_ajax)) { // This may be set by some pages that use different jquery version to avoid errors
2932 include_once DOL_DOCUMENT_ROOT.'/bookmarks/bookmarks.lib.php';
2933 $langs->load("bookmarks");
2934
2935 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
2936 $html .= '<div id="topmenu-bookmark-dropdown" class="dropdown inline-block">';
2937 $html .= printDropdownBookmarksList();
2938 $html .= '</div>';
2939 } else {
2940 $html .= '<!-- div for bookmark link -->
2941 <div id="topmenu-bookmark-dropdown" class="dropdown inline-block">
2942 <a accesskey="b" class="dropdown-toggle login-dropdown-a nofocusvisible" data-toggle="dropdown" href="#" title="'.$langs->trans('Bookmarks').' ('.$stringforfirstkey.' b)"><i class="fa fa-star"></i></a>
2943 <div class="dropdown-menu">
2945 </div>
2946 </div>';
2947
2948 $html .= '
2949 <!-- Code to show/hide the bookmark drop-down -->
2950 <script>
2951 jQuery(document).ready(function() {
2952 jQuery(document).on("click", function(event) {
2953 if (!$(event.target).closest("#topmenu-bookmark-dropdown").length) {
2954 //console.log("close bookmark dropdown - we click outside");
2955 // Hide the menus.
2956 $("#topmenu-bookmark-dropdown").removeClass("open");
2957 }
2958 });
2959
2960 jQuery("#topmenu-bookmark-dropdown .dropdown-toggle").on("click", function(event) {
2961 console.log("Click on #topmenu-bookmark-dropdown .dropdown-toggle");
2962 openBookMarkDropDown(event);
2963 });
2964
2965 // Key map shortcut
2966 jQuery(document).keydown(function(event) {
2967 var ostype = \''.dol_escape_js($conf->browser->os).'\';
2968 if (ostype === "macintosh") {
2969 if ( event.which === 66 && event.ctrlKey ) {
2970 console.log("Click on control + b : trigger open bookmark dropdown");
2971 openBookMarkDropDown(event);
2972 }
2973 } else {
2974 if ( event.which === 66 && event.ctrlKey && event.shiftKey ) {
2975 console.log("Click on control + shift + b : trigger open bookmark dropdown");
2976 openBookMarkDropDown(event);
2977 }
2978 }
2979 });
2980
2981 var openBookMarkDropDown = function(event) {
2982 event.preventDefault();
2983 jQuery("#topmenu-bookmark-dropdown").toggleClass("open");
2984 jQuery("#top-bookmark-search-input").focus();
2985 }
2986
2987 });
2988 </script>
2989 ';
2990 }
2991 }
2992 return $html;
2993}
2994
3000function top_menu_search()
3001{
3002 global $langs, $conf, $db, $user, $hookmanager;
3003
3004 $html = '';
3005
3006 $usedbyinclude = 1;
3007 $arrayresult = array();
3008 include DOL_DOCUMENT_ROOT.'/core/ajax/selectsearchbox.php'; // This sets $arrayresult
3009
3010 // accesskey is for Windows or Linux: ALT + key for chrome, ALT + SHIFT + KEY for firefox
3011 // accesskey is for Mac: CTRL + key for all browsers
3012 $stringforfirstkey = $langs->trans("KeyboardShortcut");
3013 if ($conf->browser->name == 'chrome') {
3014 $stringforfirstkey .= ' ALT +';
3015 } elseif ($conf->browser->name == 'firefox') {
3016 $stringforfirstkey .= ' ALT + SHIFT +';
3017 } else {
3018 $stringforfirstkey .= ' CTL +';
3019 }
3020
3021 $searchInput = '<input type="search" name="search_all"'.($stringforfirstkey ? ' title="'.dol_escape_htmltag($stringforfirstkey.' s').'"' : '').' id="top-global-search-input" class="dropdown-search-input search_component_input" placeholder="'.$langs->trans('Search').'" autocomplete="off">';
3022
3023 $defaultAction = '';
3024 $buttonList = '<div class="dropdown-global-search-button-list" >';
3025 // Menu with all searchable items
3026 foreach ($arrayresult as $keyItem => $item) {
3027 if (empty($defaultAction)) {
3028 $defaultAction = $item['url'];
3029 }
3030 $buttonList .= '<button class="dropdown-item global-search-item tdoverflowmax300" data-target="'.dol_escape_htmltag($item['url']).'" >';
3031 $buttonList .= $item['text'];
3032 $buttonList .= '</button>';
3033 }
3034 $buttonList .= '</div>';
3035
3036 $dropDownHtml = '<form role="search" id="top-menu-action-search" name="actionsearch" method="GET" action="'.$defaultAction.'">';
3037
3038 $dropDownHtml .= '
3039 <!-- search input -->
3040 <div class="dropdown-header search-dropdown-header">
3041 ' . $searchInput.'
3042 </div>
3043 ';
3044
3045 $dropDownHtml .= '
3046 <!-- Menu Body search -->
3047 <div class="dropdown-body search-dropdown-body">
3048 '.$buttonList.'
3049 </div>
3050 ';
3051
3052 $dropDownHtml .= '</form>';
3053
3054 // accesskey is for Windows or Linux: ALT + key for chrome, ALT + SHIFT + KEY for firefox
3055 // accesskey is for Mac: CTRL + key for all browsers
3056 $stringforfirstkey = $langs->trans("KeyboardShortcut");
3057 if ($conf->browser->name == 'chrome') {
3058 $stringforfirstkey .= ' ALT +';
3059 } elseif ($conf->browser->name == 'firefox') {
3060 $stringforfirstkey .= ' ALT + SHIFT +';
3061 } else {
3062 $stringforfirstkey .= ' CTL +';
3063 }
3064
3065 $html .= '<!-- div for Global Search -->
3066 <div id="topmenu-global-search-dropdown" class="atoplogin dropdown inline-block">
3067 <a accesskey="s" class="dropdown-toggle login-dropdown-a nofocusvisible" data-toggle="dropdown" href="#" title="'.$langs->trans('Search').' ('.$stringforfirstkey.' s)">
3068 <i class="fa fa-search" aria-hidden="true" ></i>
3069 </a>
3070 <div class="dropdown-menu dropdown-search">
3071 '.$dropDownHtml.'
3072 </div>
3073 </div>';
3074
3075 $html .= '
3076 <!-- Code to show/hide the user drop-down -->
3077 <script>
3078 jQuery(document).ready(function() {
3079
3080 // prevent submiting form on press ENTER
3081 jQuery("#top-global-search-input").keydown(function (e) {
3082 if (e.keyCode == 13 || e.keyCode == 40) {
3083 var inputs = $(this).parents("form").eq(0).find(":button");
3084 if (inputs[inputs.index(this) + 1] != null) {
3085 inputs[inputs.index(this) + 1].focus();
3086 if (e.keyCode == 13){
3087 inputs[inputs.index(this) + 1].trigger("click");
3088 }
3089
3090 }
3091 e.preventDefault();
3092 return false;
3093 }
3094 });
3095
3096 // arrow key nav
3097 jQuery(document).keydown(function(e) {
3098 // Get the focused element:
3099 var $focused = $(":focus");
3100 if($focused.length && $focused.hasClass("global-search-item")){
3101
3102 // UP - move to the previous line
3103 if (e.keyCode == 38) {
3104 e.preventDefault();
3105 $focused.prev().focus();
3106 }
3107
3108 // DOWN - move to the next line
3109 if (e.keyCode == 40) {
3110 e.preventDefault();
3111 $focused.next().focus();
3112 }
3113 }
3114 });
3115
3116
3117 // submit form action
3118 jQuery(".dropdown-global-search-button-list .global-search-item").on("click", function(event) {
3119 jQuery("#top-menu-action-search").attr("action", $(this).data("target"));
3120 jQuery("#top-menu-action-search").submit();
3121 });
3122
3123 // close drop down
3124 jQuery(document).on("click", function(event) {
3125 if (!$(event.target).closest("#topmenu-global-search-dropdown").length) {
3126 console.log("click close search - we click outside");
3127 // Hide the menus.
3128 jQuery("#topmenu-global-search-dropdown").removeClass("open");
3129 }
3130 });
3131
3132 // Open drop down
3133 jQuery("#topmenu-global-search-dropdown .dropdown-toggle").on("click", function(event) {
3134 console.log("click on toggle #topmenu-global-search-dropdown .dropdown-toggle");
3135 openGlobalSearchDropDown();
3136 });
3137
3138 // Key map shortcut
3139 jQuery(document).keydown(function(e){
3140 if ( e.which === 70 && e.ctrlKey && e.shiftKey ) {
3141 console.log(\'control + shift + f : trigger open global-search dropdown\');
3142 openGlobalSearchDropDown();
3143 }
3144 if ( e.which === 70 && e.alKey ) {
3145 console.log(\'alt + f : trigger open global-search dropdown\');
3146 openGlobalSearchDropDown();
3147 }
3148 });
3149
3150 var openGlobalSearchDropDown = function() {
3151 jQuery("#topmenu-global-search-dropdown").toggleClass("open");
3152 jQuery("#top-global-search-input").focus();
3153 }
3154
3155 });
3156 </script>
3157 ';
3158
3159 return $html;
3160}
3161
3176function left_menu($menu_array_before, $helppagename = '', $notused = '', $menu_array_after = array(), $leftmenuwithoutmainarea = 0, $title = '', $acceptdelayedhtml = 0)
3177{
3178 global $user, $conf, $langs, $db, $form;
3179 global $hookmanager, $menumanager;
3180
3181 $searchform = '';
3182
3183 if (!empty($menu_array_before)) {
3184 dol_syslog("Deprecated parameter menu_array_before was used when calling main::left_menu function. Menu entries of module should now be defined into module descriptor and not provided when calling left_menu.", LOG_WARNING);
3185 }
3186
3187 if (empty($conf->dol_hide_leftmenu) && (!defined('NOREQUIREMENU') || !constant('NOREQUIREMENU'))) {
3188 // Instantiate hooks for external modules
3189 $hookmanager->initHooks(array('leftblock'));
3190
3191 print "\n".'<!-- Begin side-nav id-left -->'."\n".'<div class="side-nav"><div id="id-left">'."\n";
3192 print "\n";
3193
3194 if (!is_object($form)) {
3195 $form = new Form($db);
3196 }
3197 $selected = -1;
3198 if (!getDolGlobalString('MAIN_USE_TOP_MENU_SEARCH_DROPDOWN')) {
3199 // Select into select2 is awfull on smartphone. TODO Is this still true with select2 v4 ?
3200 if ($conf->browser->layout == 'phone') {
3201 $conf->global->MAIN_USE_OLD_SEARCH_FORM = 1;
3202 }
3203
3204 $usedbyinclude = 1;
3205 $arrayresult = array();
3206 include DOL_DOCUMENT_ROOT.'/core/ajax/selectsearchbox.php'; // This make initHooks('searchform') then set $arrayresult
3207
3208 if ($conf->use_javascript_ajax && !getDolGlobalString('MAIN_USE_OLD_SEARCH_FORM')) {
3209 // accesskey is for Windows or Linux: ALT + key for chrome, ALT + SHIFT + KEY for firefox
3210 // accesskey is for Mac: CTRL + key for all browsers
3211 $stringforfirstkey = $langs->trans("KeyboardShortcut");
3212 if ($conf->browser->name == 'chrome') {
3213 $stringforfirstkey .= ' ALT +';
3214 } elseif ($conf->browser->name == 'firefox') {
3215 $stringforfirstkey .= ' ALT + SHIFT +';
3216 } else {
3217 $stringforfirstkey .= ' CTL +';
3218 }
3219
3220 $searchform .= $form->selectArrayFilter('searchselectcombo', $arrayresult, $selected, 'accesskey="s"', 1, 0, (!getDolGlobalString('MAIN_SEARCHBOX_CONTENT_LOADED_BEFORE_KEY') ? 1 : 0), 'vmenusearchselectcombo', 1, $langs->trans("Search"), 1, $stringforfirstkey.' s');
3221 } else {
3222 if (is_array($arrayresult)) {
3223 foreach ($arrayresult as $key => $val) {
3224 $searchform .= printSearchForm($val['url'], $val['url'], $val['label'], 'maxwidth125', 'search_all', (empty($val['shortcut']) ? '' : $val['shortcut']), 'searchleft'.$key, $val['img']);
3225 }
3226 }
3227 }
3228
3229 // Execute hook printSearchForm
3230 $parameters = array('searchform' => $searchform);
3231 $reshook = $hookmanager->executeHooks('printSearchForm', $parameters); // Note that $action and $object may have been modified by some hooks
3232 if (empty($reshook)) {
3233 $searchform .= $hookmanager->resPrint;
3234 } else {
3235 $searchform = $hookmanager->resPrint;
3236 }
3237
3238 // Force special value for $searchform for text browsers or very old search form
3239 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER') || empty($conf->use_javascript_ajax)) {
3240 $urltosearch = DOL_URL_ROOT.'/core/search_page.php?showtitlebefore=1';
3241 $searchform = '<div class="blockvmenuimpair blockvmenusearchphone"><div id="divsearchforms1"><a href="'.$urltosearch.'" accesskey="s" alt="'.dol_escape_htmltag($langs->trans("ShowSearchFields")).'">'.$langs->trans("Search").'...</a></div></div>';
3242 } elseif ($conf->use_javascript_ajax && getDolGlobalString('MAIN_USE_OLD_SEARCH_FORM')) {
3243 $searchform = '<div class="blockvmenuimpair blockvmenusearchphone"><div id="divsearchforms1"><a href="#" alt="'.dol_escape_htmltag($langs->trans("ShowSearchFields")).'">'.$langs->trans("Search").'...</a></div><div id="divsearchforms2" style="display: none">'.$searchform.'</div>';
3244 $searchform .= '<script>
3245 jQuery(document).ready(function () {
3246 jQuery("#divsearchforms1").click(function(){
3247 jQuery("#divsearchforms2").toggle();
3248 });
3249 });
3250 </script>' . "\n";
3251 $searchform .= '</div>';
3252 }
3253
3254 // Key map shortcut
3255 $searchform .= '<script>
3256 jQuery(document).keydown(function(e){
3257 if( e.which === 70 && e.ctrlKey && e.shiftKey ){
3258 console.log(\'control + shift + f : trigger open global-search dropdown\');
3259 openGlobalSearchDropDown();
3260 }
3261 if( (e.which === 83 || e.which === 115) && e.altKey ){
3262 console.log(\'alt + s : trigger open global-search dropdown\');
3263 openGlobalSearchDropDown();
3264 }
3265 });
3266
3267 var openGlobalSearchDropDown = function() {
3268 jQuery("#searchselectcombo").select2(\'open\');
3269 }
3270 </script>';
3271 }
3272
3273 // Left column
3274 print '<!-- Begin left menu -->'."\n";
3275
3276 print '<div class="vmenu"'.(!getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER') ? '' : ' title="Left menu"').'>'."\n\n";
3277
3278 // Show left menu with other forms
3279 $menumanager->menu_array = $menu_array_before;
3280 $menumanager->menu_array_after = $menu_array_after;
3281 $menumanager->showmenu('left', array('searchform'=>$searchform)); // output menu_array and menu found in database
3282
3283 // Dolibarr version + help + bug report link
3284 print "\n";
3285 print "<!-- Begin Help Block-->\n";
3286 print '<div id="blockvmenuhelp" class="blockvmenuhelp">'."\n";
3287
3288 // Version
3289 if (getDolGlobalString('MAIN_SHOW_VERSION')) { // Version is already on help picto and on login page.
3290 $doliurl = 'https://www.dolibarr.org';
3291 //local communities
3292 if (preg_match('/fr/i', $langs->defaultlang)) {
3293 $doliurl = 'https://www.dolibarr.fr';
3294 }
3295 if (preg_match('/es/i', $langs->defaultlang)) {
3296 $doliurl = 'https://www.dolibarr.es';
3297 }
3298 if (preg_match('/de/i', $langs->defaultlang)) {
3299 $doliurl = 'https://www.dolibarr.de';
3300 }
3301 if (preg_match('/it/i', $langs->defaultlang)) {
3302 $doliurl = 'https://www.dolibarr.it';
3303 }
3304 if (preg_match('/gr/i', $langs->defaultlang)) {
3305 $doliurl = 'https://www.dolibarr.gr';
3306 }
3307
3308 $appli = constant('DOL_APPLICATION_TITLE');
3309 if (getDolGlobalString('MAIN_APPLICATION_TITLE')) {
3310 $appli = $conf->global->MAIN_APPLICATION_TITLE; $doliurl = '';
3311 if (preg_match('/\d\.\d/', $appli)) {
3312 if (!preg_match('/'.preg_quote(DOL_VERSION).'/', $appli)) {
3313 $appli .= " (".DOL_VERSION.")"; // If new title contains a version that is different than core
3314 }
3315 } else {
3316 $appli .= " ".DOL_VERSION;
3317 }
3318 } else {
3319 $appli .= " ".DOL_VERSION;
3320 }
3321 print '<div id="blockvmenuhelpapp" class="blockvmenuhelp">';
3322 if ($doliurl) {
3323 print '<a class="help" target="_blank" rel="noopener noreferrer" href="'.$doliurl.'">';
3324 } else {
3325 print '<span class="help">';
3326 }
3327 print $appli;
3328 if ($doliurl) {
3329 print '</a>';
3330 } else {
3331 print '</span>';
3332 }
3333 print '</div>'."\n";
3334 }
3335
3336 // Link to bugtrack
3337 if (getDolGlobalString('MAIN_BUGTRACK_ENABLELINK')) {
3338 require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
3339
3340 if (getDolGlobalString('MAIN_BUGTRACK_ENABLELINK') == 'github') {
3341 $bugbaseurl = 'https://github.com/Dolibarr/dolibarr/issues/new?labels=Bug';
3342 $bugbaseurl .= '&title=';
3343 $bugbaseurl .= urlencode("Bug: ");
3344 $bugbaseurl .= '&body=';
3345 $bugbaseurl .= urlencode("# Instructions\n");
3346 $bugbaseurl .= urlencode("*This is a template to help you report good issues. You may use [Github Markdown](https://help.github.com/articles/getting-started-with-writing-and-formatting-on-github/) syntax to format your issue report.*\n");
3347 $bugbaseurl .= urlencode("*Please:*\n");
3348 $bugbaseurl .= urlencode("- *replace the bracket enclosed texts with meaningful information*\n");
3349 $bugbaseurl .= urlencode("- *remove any unused sub-section*\n");
3350 $bugbaseurl .= urlencode("\n");
3351 $bugbaseurl .= urlencode("\n");
3352 $bugbaseurl .= urlencode("# Bug\n");
3353 $bugbaseurl .= urlencode("[*Short description*]\n");
3354 $bugbaseurl .= urlencode("\n");
3355 $bugbaseurl .= urlencode("## Environment\n");
3356 $bugbaseurl .= urlencode("- **Version**: ".DOL_VERSION."\n");
3357 $bugbaseurl .= urlencode("- **OS**: ".php_uname('s')."\n");
3358 $bugbaseurl .= urlencode("- **Web server**: ".$_SERVER["SERVER_SOFTWARE"]."\n");
3359 $bugbaseurl .= urlencode("- **PHP**: ".php_sapi_name().' '.phpversion()."\n");
3360 $bugbaseurl .= urlencode("- **Database**: ".$db::LABEL.' '.$db->getVersion()."\n");
3361 $bugbaseurl .= urlencode("- **URL(s)**: ".$_SERVER["REQUEST_URI"]."\n");
3362 $bugbaseurl .= urlencode("\n");
3363 $bugbaseurl .= urlencode("## Expected and actual behavior\n");
3364 $bugbaseurl .= urlencode("[*Verbose description*]\n");
3365 $bugbaseurl .= urlencode("\n");
3366 $bugbaseurl .= urlencode("## Steps to reproduce the behavior\n");
3367 $bugbaseurl .= urlencode("[*Verbose description*]\n");
3368 $bugbaseurl .= urlencode("\n");
3369 $bugbaseurl .= urlencode("## [Attached files](https://help.github.com/articles/issue-attachments) (Screenshots, screencasts, dolibarr.log, debugging informations…)\n");
3370 $bugbaseurl .= urlencode("[*Files*]\n");
3371 $bugbaseurl .= urlencode("\n");
3372
3373 $bugbaseurl .= urlencode("\n");
3374 $bugbaseurl .= urlencode("## Report\n");
3375 } elseif (getDolGlobalString('MAIN_BUGTRACK_ENABLELINK')) {
3376 $bugbaseurl = $conf->global->MAIN_BUGTRACK_ENABLELINK;
3377 } else {
3378 $bugbaseurl = "";
3379 }
3380
3381 // Execute hook printBugtrackInfo
3382 $parameters = array('bugbaseurl' => $bugbaseurl);
3383 $reshook = $hookmanager->executeHooks('printBugtrackInfo', $parameters); // Note that $action and $object may have been modified by some hooks
3384 if (empty($reshook)) {
3385 $bugbaseurl .= $hookmanager->resPrint;
3386 } else {
3387 $bugbaseurl = $hookmanager->resPrint;
3388 }
3389
3390 print '<div id="blockvmenuhelpbugreport" class="blockvmenuhelp">';
3391 print '<a class="help" target="_blank" rel="noopener noreferrer" href="'.$bugbaseurl.'"><i class="fas fa-bug"></i> '.$langs->trans("FindBug").'</a>';
3392 print '</div>';
3393 }
3394
3395 print "</div>\n";
3396 print "<!-- End Help Block-->\n";
3397 print "\n";
3398
3399 print "</div>\n";
3400 print "<!-- End left menu -->\n";
3401 print "\n";
3402
3403 // Execute hook printLeftBlock
3404 $parameters = array();
3405 $reshook = $hookmanager->executeHooks('printLeftBlock', $parameters); // Note that $action and $object may have been modified by some hooks
3406 print $hookmanager->resPrint;
3407
3408 print '</div></div> <!-- End side-nav id-left -->'; // End div id="side-nav" div id="id-left"
3409 }
3410
3411 print "\n";
3412 print '<!-- Begin right area -->'."\n";
3413
3414 if (empty($leftmenuwithoutmainarea)) {
3415 main_area($title);
3416 }
3417}
3418
3419
3426function main_area($title = '')
3427{
3428 global $conf, $langs, $hookmanager;
3429
3430 if (empty($conf->dol_hide_leftmenu) && !GETPOST('dol_openinpopup')) {
3431 print '<div id="id-right">';
3432 }
3433
3434 print "\n";
3435
3436 print '<!-- Begin div class="fiche" -->'."\n".'<div class="fiche">'."\n";
3437
3438 $hookmanager->initHooks(array('main'));
3439 $parameters = array();
3440 $reshook = $hookmanager->executeHooks('printMainArea', $parameters); // Note that $action and $object may have been modified by some hooks
3441 print $hookmanager->resPrint;
3442
3443 if (getDolGlobalString('MAIN_ONLY_LOGIN_ALLOWED')) {
3444 print info_admin($langs->trans("WarningYouAreInMaintenanceMode", $conf->global->MAIN_ONLY_LOGIN_ALLOWED), 0, 0, 1, 'warning maintenancemode');
3445 }
3446
3447 // Permit to add user company information on each printed document by setting SHOW_SOCINFO_ON_PRINT
3448 if (getDolGlobalString('SHOW_SOCINFO_ON_PRINT') && GETPOST('optioncss', 'aZ09') == 'print' && empty(GETPOST('disable_show_socinfo_on_print', 'aZ09'))) {
3449 $parameters = array();
3450 $reshook = $hookmanager->executeHooks('showSocinfoOnPrint', $parameters);
3451 if (empty($reshook)) {
3452 print '<!-- Begin show mysoc info header -->'."\n";
3453 print '<div id="mysoc-info-header">'."\n";
3454 print '<table class="centpercent div-table-responsive">'."\n";
3455 print '<tbody>';
3456 print '<tr><td rowspan="0" class="width20p">';
3457 if ($conf->global->MAIN_SHOW_LOGO && !getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER') && getDolGlobalString('MAIN_INFO_SOCIETE_LOGO')) {
3458 print '<img id="mysoc-info-header-logo" style="max-width:100%" alt="" src="'.DOL_URL_ROOT.'/viewimage.php?cache=1&modulepart=mycompany&file='.urlencode('logos/'.dol_escape_htmltag(getDolGlobalString('MAIN_INFO_SOCIETE_LOGO'))).'">';
3459 }
3460 print '</td><td rowspan="0" class="width50p"></td></tr>'."\n";
3461 print '<tr><td class="titre bold">'.dol_escape_htmltag(getDolGlobalString('MAIN_INFO_SOCIETE_NOM')).'</td></tr>'."\n";
3462 print '<tr><td>'.dol_escape_htmltag(getDolGlobalString('MAIN_INFO_SOCIETE_ADDRESS')).'<br>'.dol_escape_htmltag(getDolGlobalString('MAIN_INFO_SOCIETE_ZIP')).' '.dol_escape_htmltag(getDolGlobalString('MAIN_INFO_SOCIETE_TOWN')).'</td></tr>'."\n";
3463 if (getDolGlobalString('MAIN_INFO_SOCIETE_TEL')) {
3464 print '<tr><td style="padding-left: 1em" class="small">'.$langs->trans("Phone").' : '.dol_escape_htmltag(getDolGlobalString('MAIN_INFO_SOCIETE_TEL')).'</td></tr>';
3465 }
3466 if (getDolGlobalString('MAIN_INFO_SOCIETE_MAIL')) {
3467 print '<tr><td style="padding-left: 1em" class="small">'.$langs->trans("Email").' : '.dol_escape_htmltag(getDolGlobalString('MAIN_INFO_SOCIETE_MAIL')).'</td></tr>';
3468 }
3469 if (getDolGlobalString('MAIN_INFO_SOCIETE_WEB')) {
3470 print '<tr><td style="padding-left: 1em" class="small">'.$langs->trans("Web").' : '.dol_escape_htmltag(getDolGlobalString('MAIN_INFO_SOCIETE_WEB')).'</td></tr>';
3471 }
3472 print '</tbody>';
3473 print '</table>'."\n";
3474 print '</div>'."\n";
3475 print '<!-- End show mysoc info header -->'."\n";
3476 }
3477 }
3478}
3479
3480
3488function getHelpParamFor($helppagename, $langs)
3489{
3490 $helpbaseurl = '';
3491 $helppage = '';
3492 $mode = '';
3493
3494 if (preg_match('/^http/i', $helppagename)) {
3495 // If complete URL
3496 $helpbaseurl = '%s';
3497 $helppage = $helppagename;
3498 $mode = 'local';
3499 } else {
3500 // If WIKI URL
3501 $reg = array();
3502 if (preg_match('/^es/i', $langs->defaultlang)) {
3503 $helpbaseurl = 'http://wiki.dolibarr.org/index.php/%s';
3504 if (preg_match('/ES:([^|]+)/i', $helppagename, $reg)) {
3505 $helppage = $reg[1];
3506 }
3507 }
3508 if (preg_match('/^fr/i', $langs->defaultlang)) {
3509 $helpbaseurl = 'http://wiki.dolibarr.org/index.php/%s';
3510 if (preg_match('/FR:([^|]+)/i', $helppagename, $reg)) {
3511 $helppage = $reg[1];
3512 }
3513 }
3514 if (preg_match('/^de/i', $langs->defaultlang)) {
3515 $helpbaseurl = 'http://wiki.dolibarr.org/index.php/%s';
3516 if (preg_match('/DE:([^|]+)/i', $helppagename, $reg)) {
3517 $helppage = $reg[1];
3518 }
3519 }
3520 if (empty($helppage)) { // If help page not already found
3521 $helpbaseurl = 'http://wiki.dolibarr.org/index.php/%s';
3522 if (preg_match('/EN:([^|]+)/i', $helppagename, $reg)) {
3523 $helppage = $reg[1];
3524 }
3525 }
3526 $mode = 'wiki';
3527 }
3528 return array('helpbaseurl'=>$helpbaseurl, 'helppage'=>$helppage, 'mode'=>$mode);
3529}
3530
3531
3548function printSearchForm($urlaction, $urlobject, $title, $htmlmorecss, $htmlinputname, $accesskey = '', $prefhtmlinputname = '', $img = '', $showtitlebefore = 0, $autofocus = 0)
3549{
3550 global $langs, $user;
3551
3552 $ret = '';
3553 $ret .= '<form action="'.$urlaction.'" method="post" class="searchform nowraponall tagtr">';
3554 $ret .= '<input type="hidden" name="token" value="'.newToken().'">';
3555 $ret .= '<input type="hidden" name="savelogin" value="'.dol_escape_htmltag($user->login).'">';
3556 if ($showtitlebefore) {
3557 $ret .= '<div class="tagtd left">'.$title.'</div> ';
3558 }
3559 $ret .= '<div class="tagtd">';
3560 $ret .= img_picto('', $img, '', false, 0, 0, '', 'paddingright width20');
3561 $ret .= '<input type="text" class="flat '.$htmlmorecss.'"';
3562 $ret .= ' style="background-repeat: no-repeat; background-position: 3px;"';
3563 $ret .= ($accesskey ? ' accesskey="'.$accesskey.'"' : '');
3564 $ret .= ' placeholder="'.strip_tags($title).'"';
3565 $ret .= ($autofocus ? ' autofocus' : '');
3566 $ret .= ' name="'.$htmlinputname.'" id="'.$prefhtmlinputname.$htmlinputname.'" />';
3567 $ret .= '<button type="submit" class="button bordertransp" style="padding-top: 4px; padding-bottom: 4px; padding-left: 6px; padding-right: 6px">';
3568 $ret .= '<span class="fa fa-search"></span>';
3569 $ret .= '</button>';
3570 $ret .= '</div>';
3571 $ret .= "</form>\n";
3572 return $ret;
3573}
3574
3575
3576if (!function_exists("llxFooter")) {
3587 function llxFooter($comment = '', $zone = 'private', $disabledoutputofmessages = 0)
3588 {
3589 global $conf, $db, $langs, $user, $mysoc, $object, $hookmanager, $action;
3590 global $delayedhtmlcontent;
3591 global $contextpage, $page, $limit, $mode;
3592 global $dolibarr_distrib;
3593
3594 $ext = 'layout='.urlencode($conf->browser->layout).'&version='.urlencode(DOL_VERSION);
3595
3596 // Hook to add more things on all pages within fiche DIV
3597 $llxfooter = '';
3598 $parameters = array();
3599 $reshook = $hookmanager->executeHooks('llxFooter', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
3600 if (empty($reshook)) {
3601 $llxfooter .= $hookmanager->resPrint;
3602 } elseif ($reshook > 0) {
3603 $llxfooter = $hookmanager->resPrint;
3604 }
3605 if ($llxfooter) {
3606 print $llxfooter;
3607 }
3608
3609 // Global html output events ($mesgs, $errors, $warnings)
3610 dol_htmloutput_events($disabledoutputofmessages);
3611
3612 // Code for search criteria persistence.
3613 // $user->lastsearch_values was set by the GETPOST when form field search_xxx exists
3614 if (is_object($user) && !empty($user->lastsearch_values_tmp) && is_array($user->lastsearch_values_tmp)) {
3615 // Clean and save data
3616 foreach ($user->lastsearch_values_tmp as $key => $val) {
3617 unset($_SESSION['lastsearch_values_tmp_'.$key]); // Clean array to rebuild it just after
3618 if (count($val) && empty($_POST['button_removefilter']) && empty($_POST['button_removefilter_x'])) {
3619 if (empty($val['sortfield'])) {
3620 unset($val['sortfield']);
3621 }
3622 if (empty($val['sortorder'])) {
3623 unset($val['sortorder']);
3624 }
3625 dol_syslog('Save lastsearch_values_tmp_'.$key.'='.json_encode($val, 0)." (systematic recording of last search criterias)");
3626 $_SESSION['lastsearch_values_tmp_'.$key] = json_encode($val);
3627 unset($_SESSION['lastsearch_values_'.$key]);
3628 }
3629 }
3630 }
3631
3632
3633 $relativepathstring = $_SERVER["PHP_SELF"];
3634 // Clean $relativepathstring
3635 if (constant('DOL_URL_ROOT')) {
3636 $relativepathstring = preg_replace('/^'.preg_quote(constant('DOL_URL_ROOT'), '/').'/', '', $relativepathstring);
3637 }
3638 $relativepathstring = preg_replace('/^\//', '', $relativepathstring);
3639 $relativepathstring = preg_replace('/^custom\//', '', $relativepathstring);
3640 if (preg_match('/list\.php$/', $relativepathstring)) {
3641 unset($_SESSION['lastsearch_contextpage_tmp_'.$relativepathstring]);
3642 unset($_SESSION['lastsearch_page_tmp_'.$relativepathstring]);
3643 unset($_SESSION['lastsearch_limit_tmp_'.$relativepathstring]);
3644 unset($_SESSION['lastsearch_mode_tmp_'.$relativepathstring]);
3645
3646 if (!empty($contextpage)) {
3647 $_SESSION['lastsearch_contextpage_tmp_'.$relativepathstring] = $contextpage;
3648 }
3649 if (!empty($page) && $page > 0) {
3650 $_SESSION['lastsearch_page_tmp_'.$relativepathstring] = $page;
3651 }
3652 if (!empty($limit) && $limit != $conf->liste_limit) {
3653 $_SESSION['lastsearch_limit_tmp_'.$relativepathstring] = $limit;
3654 }
3655 if (!empty($mode)) {
3656 $_SESSION['lastsearch_mode_tmp_'.$relativepathstring] = $mode;
3657 }
3658
3659 unset($_SESSION['lastsearch_contextpage_'.$relativepathstring]);
3660 unset($_SESSION['lastsearch_page_'.$relativepathstring]);
3661 unset($_SESSION['lastsearch_limit_'.$relativepathstring]);
3662 unset($_SESSION['lastsearch_mode_'.$relativepathstring]);
3663 }
3664
3665 // Core error message
3666 if (getDolGlobalString('MAIN_CORE_ERROR')) {
3667 // Ajax version
3668 if ($conf->use_javascript_ajax) {
3669 $title = img_warning().' '.$langs->trans('CoreErrorTitle');
3670 print ajax_dialog($title, $langs->trans('CoreErrorMessage'));
3671 } else {
3672 // html version
3673 $msg = img_warning().' '.$langs->trans('CoreErrorMessage');
3674 print '<div class="error">'.$msg.'</div>';
3675 }
3676
3677 //define("MAIN_CORE_ERROR",0); // Constant was defined and we can't change value of a constant
3678 }
3679
3680 print "\n\n";
3681
3682 print '</div> <!-- End div class="fiche" -->'."\n"; // End div fiche
3683
3684 if (empty($conf->dol_hide_leftmenu) && !GETPOST('dol_openinpopup')) {
3685 print '</div> <!-- End div id-right -->'."\n"; // End div id-right
3686 }
3687
3688 if (empty($conf->dol_hide_leftmenu) && empty($conf->dol_use_jmobile)) {
3689 print '</div> <!-- End div id-container -->'."\n"; // End div container
3690 }
3691
3692 print "\n";
3693 if ($comment) {
3694 print '<!-- '.$comment.' -->'."\n";
3695 }
3696
3697 printCommonFooter($zone);
3698
3699 if (!empty($delayedhtmlcontent)) {
3700 print $delayedhtmlcontent;
3701 }
3702
3703 if (!empty($conf->use_javascript_ajax)) {
3704 print "\n".'<!-- Includes JS Footer of Dolibarr -->'."\n";
3705 print '<script src="'.DOL_URL_ROOT.'/core/js/lib_foot.js.php?lang='.$langs->defaultlang.($ext ? '&'.$ext : '').'"></script>'."\n";
3706 }
3707
3708 // Wrapper to add log when clicking on download or preview
3709 if (isModEnabled('blockedlog') && is_object($object) && !empty($object->id) && $object->id > 0) {
3710 if (in_array($object->element, array('facture')) && $object->statut > 0) { // Restrict for the moment to element 'facture'
3711 print "\n<!-- JS CODE TO ENABLE log when making a download or a preview of a document -->\n";
3712 ?>
3713 <script>
3714 jQuery(document).ready(function () {
3715 $('a.documentpreview').click(function() {
3716 $.post('<?php echo DOL_URL_ROOT."/blockedlog/ajax/block-add.php" ?>'
3717 , {
3718 id:<?php echo $object->id; ?>
3719 , element:'<?php echo $object->element ?>'
3720 , action:'DOC_PREVIEW'
3721 , token: '<?php echo currentToken(); ?>'
3722 }
3723 );
3724 });
3725 $('a.documentdownload').click(function() {
3726 $.post('<?php echo DOL_URL_ROOT."/blockedlog/ajax/block-add.php" ?>'
3727 , {
3728 id:<?php echo $object->id; ?>
3729 , element:'<?php echo $object->element ?>'
3730 , action:'DOC_DOWNLOAD'
3731 , token: '<?php echo currentToken(); ?>'
3732 }
3733 );
3734 });
3735 });
3736 </script>
3737 <?php
3738 }
3739 }
3740
3741 // A div for the address popup
3742 print "\n<!-- A div to allow dialog popup by jQuery('#dialogforpopup').dialog() -->\n";
3743 print '<div id="dialogforpopup" style="display: none;"></div>'."\n";
3744
3745 // Add code for the asynchronous anonymous first ping (for telemetry)
3746 // You can use &forceping=1 in parameters to force the ping if the ping was already sent.
3747 $forceping = GETPOST('forceping', 'alpha');
3748 if (($_SERVER["PHP_SELF"] == DOL_URL_ROOT.'/index.php') || $forceping) {
3749 //print '<!-- instance_unique_id='.$conf->file->instance_unique_id.' MAIN_FIRST_PING_OK_ID='.$conf->global->MAIN_FIRST_PING_OK_ID.' -->';
3750 $hash_unique_id = dol_hash('dolibarr'.$conf->file->instance_unique_id, 'sha256'); // Note: if the global salt changes, this hash changes too so ping may be counted twice. We don't mind. It is for statistics purpose only.
3751
3752 if (!getDolGlobalString('MAIN_FIRST_PING_OK_DATE')
3753 || (!empty($conf->file->instance_unique_id) && ($hash_unique_id != $conf->global->MAIN_FIRST_PING_OK_ID) && (getDolGlobalString('MAIN_FIRST_PING_OK_ID') != 'disabled'))
3754 || $forceping) {
3755 // No ping done if we are into an alpha version
3756 if (strpos('alpha', DOL_VERSION) > 0 && !$forceping) {
3757 print "\n<!-- NO JS CODE TO ENABLE the anonymous Ping. It is an alpha version -->\n";
3758 } elseif (empty($_COOKIE['DOLINSTALLNOPING_'.$hash_unique_id]) || $forceping) { // Cookie is set when we uncheck the checkbox in the installation wizard.
3759 // MAIN_LAST_PING_KO_DATE
3760 // Disable ping if MAIN_LAST_PING_KO_DATE is set and is recent (this month)
3761 if (getDolGlobalString('MAIN_LAST_PING_KO_DATE') && substr($conf->global->MAIN_LAST_PING_KO_DATE, 0, 6) == dol_print_date(dol_now(), '%Y%m') && !$forceping) {
3762 print "\n<!-- NO JS CODE TO ENABLE the anonymous Ping. An error already occured this month, we will try later. -->\n";
3763 } else {
3764 include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
3765
3766 print "\n".'<!-- Includes JS for Ping of Dolibarr forceping='.$forceping.' MAIN_FIRST_PING_OK_DATE='.getDolGlobalString("MAIN_FIRST_PING_OK_DATE").' MAIN_FIRST_PING_OK_ID='.getDolGlobalString("MAIN_FIRST_PING_OK_ID").' MAIN_LAST_PING_KO_DATE='.getDolGlobalString("MAIN_LAST_PING_KO_DATE").' -->'."\n";
3767 print "\n<!-- JS CODE TO ENABLE the anonymous Ping -->\n";
3768 $url_for_ping = (!getDolGlobalString('MAIN_URL_FOR_PING') ? "https://ping.dolibarr.org/" : $conf->global->MAIN_URL_FOR_PING);
3769 // Try to guess the distrib used
3770 $distrib = 'standard';
3771 if ($_SERVER["SERVER_ADMIN"] == 'doliwamp@localhost') {
3772 $distrib = 'doliwamp';
3773 }
3774 if (!empty($dolibarr_distrib)) {
3775 $distrib = $dolibarr_distrib;
3776 }
3777 ?>
3778 <script>
3779 jQuery(document).ready(function (tmp) {
3780 console.log("Try Ping with hash_unique_id is dol_hash('dolibarr'+instance_unique_id, 'sha256')");
3781 $.ajax({
3782 method: "POST",
3783 url: "<?php echo $url_for_ping ?>",
3784 timeout: 500, // timeout milliseconds
3785 cache: false,
3786 data: {
3787 hash_algo: 'dol_hash-sha256',
3788 hash_unique_id: '<?php echo dol_escape_js($hash_unique_id); ?>',
3789 action: 'dolibarrping',
3790 version: '<?php echo (float) DOL_VERSION; ?>',
3791 entity: '<?php echo (int) $conf->entity; ?>',
3792 dbtype: '<?php echo dol_escape_js($db->type); ?>',
3793 country_code: '<?php echo $mysoc->country_code ? dol_escape_js($mysoc->country_code) : 'unknown'; ?>',
3794 php_version: '<?php echo dol_escape_js(phpversion()); ?>',
3795 os_version: '<?php echo dol_escape_js(version_os('smr')); ?>',
3796 db_version: '<?php echo dol_escape_js(version_db()); ?>',
3797 distrib: '<?php echo $distrib ? dol_escape_js($distrib) : 'unknown'; ?>',
3798 token: 'notrequired'
3799 },
3800 success: function (data, status, xhr) { // success callback function (data contains body of response)
3801 console.log("Ping ok");
3802 $.ajax({
3803 method: 'GET',
3804 url: '<?php echo DOL_URL_ROOT.'/core/ajax/pingresult.php'; ?>',
3805 timeout: 500, // timeout milliseconds
3806 cache: false,
3807 data: { hash_algo: 'dol_hash-sha256', hash_unique_id: '<?php echo dol_escape_js($hash_unique_id); ?>', action: 'firstpingok', token: '<?php echo currentToken(); ?>' }, // for update
3808 });
3809 },
3810 error: function (data,status,xhr) { // error callback function
3811 console.log("Ping ko: " + data);
3812 $.ajax({
3813 method: 'GET',
3814 url: '<?php echo DOL_URL_ROOT.'/core/ajax/pingresult.php'; ?>',
3815 timeout: 500, // timeout milliseconds
3816 cache: false,
3817 data: { hash_algo: 'dol_hash-sha256', hash_unique_id: '<?php echo dol_escape_js($hash_unique_id); ?>', action: 'firstpingko', token: '<?php echo currentToken(); ?>' },
3818 });
3819 }
3820 });
3821 });
3822 </script>
3823 <?php
3824 }
3825 } else {
3826 $now = dol_now();
3827 print "\n<!-- NO JS CODE TO ENABLE the anonymous Ping. It was disabled -->\n";
3828 include_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
3829 dolibarr_set_const($db, 'MAIN_FIRST_PING_OK_DATE', dol_print_date($now, 'dayhourlog', 'gmt'), 'chaine', 0, '', $conf->entity);
3830 dolibarr_set_const($db, 'MAIN_FIRST_PING_OK_ID', 'disabled', 'chaine', 0, '', $conf->entity);
3831 }
3832 }
3833 }
3834
3835 $parameters = array();
3836 $reshook = $hookmanager->executeHooks('beforeBodyClose', $parameters); // Note that $action and $object may have been modified by some hooks
3837 if ($reshook > 0) {
3838 print $hookmanager->resPrint;
3839 }
3840
3841 print "</body>\n";
3842 print "</html>\n";
3843 }
3844}
print $langs trans("AuditedSecurityEvents").'</strong >< span class="opacitymedium"></span >< br > status
Definition security.php:604
dolibarr_set_const($db, $name, $value, $type='chaine', $visible=0, $note='', $entity=1)
Insert a parameter (key,value) into database (delete old key then insert it again).
versioncompare($versionarray1, $versionarray2)
Compare 2 versions (stored into 2 arrays).
Definition admin.lib.php:67
ajax_dialog($title, $message, $w=350, $h=150)
Show an ajax dialog.
Definition ajax.lib.php:410
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
Definition wrapper.php:55
llxFooter()
Empty footer.
Definition wrapper.php:69
printDropdownBookmarksList()
Add area with bookmarks in top menu.
DolibarrDebugBar class.
Definition DebugBar.php:46
Class to manage generation of HTML components Only common components must be here.
static showphoto($modulepart, $object, $width=100, $height=0, $caneditfield=0, $cssclass='photowithmargin', $imagesize='', $addlinktofullsize=1, $cache=0, $forcecapture='', $noexternsourceoverwrite=0)
Class to manage hooks.
Class to manage left menus.
Class to manage menu Auguria.
loadMenu($forcemainmenu='', $forceleftmenu='')
Load this->tabMenu.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage translations.
dol_stringtotime($string, $gm=1)
Convert a string date into a GM Timestamps date Warning: YYYY-MM-DDTHH:MM:SS+02:00 (RFC3339) is not s...
Definition date.lib.php:426
picto_from_langcode($codelang, $moreatt='', $notitlealt=0)
Return img flag of country for a language code or country code.
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
yn($yesno, $case=1, $color=0)
Return yes or no in current language.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dolButtonToOpenUrlInDialogPopup($name, $label, $buttonstring, $url, $disabled='', $morecss='classlink button bordertransp', $jsonopen='', $backtopagejsfields='', $accesskey='')
Return HTML code to output a button to open a dialog popup box.
isHTTPS()
Return if we are using a HTTPS connexion Check HTTPS (no way to be modified by user but may be empty ...
printCommonFooter($zone='private')
Print common footer : conf->global->MAIN_HTML_FOOTER js for switch of menu hider js for conf->global-...
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
if(!function_exists( 'dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
dol_htmlentities($string, $flags=ENT_QUOTES|ENT_SUBSTITUTE, $encoding='UTF-8', $double_encode=false)
Replace htmlentities functions.
getBrowserInfo($user_agent)
Return information about user browser.
dol_htmloutput_events($disabledoutputofmessages=0)
Print formated messages to output (Used to show messages on html output).
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='')
Show information for admin users or standard users.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
dol_print_profids($profID, $profIDtype, $countrycode='', $addcpButton=1)
Format professional IDs according to their country.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
conf($dolibarr_main_document_root)
Load conf file (file must exists)
Definition inc.php:403
top_menu_quickadd()
Build the tooltip on top menu quick add.
top_htmlhead($head, $title='', $disablejs=0, $disablehead=0, $arrayofjs=array(), $arrayofcss=array(), $disableforlogin=0, $disablenofollow=0, $disablenoindex=0)
Ouput html header of a page.
analyseVarsForSqlAndScriptsInjection(&$var, $type)
Return true if security check on parameters are OK, false otherwise.
Definition main.inc.php:216
top_menu_user($hideloginname=0, $urllogout='')
Build the tooltip on user login.
testSqlAndScriptInject($val, $type)
Security: WAF layer for SQL Injection and XSS Injection (scripts) protection (Filters on GET,...
Definition main.inc.php:89
left_menu($menu_array_before, $helppagename='', $notused='', $menu_array_after=array(), $leftmenuwithoutmainarea=0, $title='', $acceptdelayedhtml=0)
Show left menu bar.
if(!defined( 'NOREQUIREMENU')) if(!empty(GETPOST('seteventmessages', 'alpha'))) if(!function_exists("llxHeader")) top_httphead($contenttype='text/html', $forcenocache=0)
Show HTTP header.
main_area($title='')
Begin main area.
getHelpParamFor($helppagename, $langs)
Return helpbaseurl, helppage and mode.
if(!empty( $_SERVER[ 'MAIN_SHOW_TUNING_INFO'])) realCharForNumericEntities($matches)
Return the real char for a numeric entities.
Definition main.inc.php:63
printSearchForm($urlaction, $urlobject, $title, $htmlmorecss, $htmlinputname, $accesskey='', $prefhtmlinputname='', $img='', $showtitlebefore=0, $autofocus=0)
Show a search area.
top_menu($head, $title='', $target='', $disablejs=0, $disablehead=0, $arrayofjs=array(), $arrayofcss=array(), $morequerystring='', $helppagename='')
Show an HTML header + a BODY + The top menu bar.
top_menu_search()
Build the tooltip on top menu tsearch.
printDropdownQuickadd()
Generate list of quickadd items.
top_menu_bookmark()
Build the tooltip on top menu bookmark.
ui dialog ui datepicker calendar ui widget content ui state ui datepicker calendar ui widget header ui state ui datepicker calendar ui button
0 = Do not include form tag and submit button -1 = Do not include form tag but include submit button
global $dolibarr_main_demo
Definition index.php:50
$conf db user
Definition repair.php:125
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition repair.php:121
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:124
checkLoginPassEntity($usertotest, $passwordtotest, $entitytotest, $authmode, $context='')
Return a login if login/pass was successfull.
dol_hash($chain, $type='0', $nosalt=0)
Returns a hash (non reversible encryption) of a string.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.