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