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