2004-10-20 23:06:45 +02:00
< ? php
2015-04-23 17:52:05 +02:00
/* Copyright ( C ) 2002 - 2007 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
* Copyright ( C ) 2003 Xavier Dutoit < doli @ sydesy . com >
2021-03-19 11:27:31 +01:00
* Copyright ( C ) 2004 - 2021 Laurent Destailleur < eldy @ users . sourceforge . net >
2015-04-23 17:52:05 +02:00
* Copyright ( C ) 2004 Sebastien Di Cintio < sdicintio @ ressource - toi . org >
* Copyright ( C ) 2004 Benoit Mortier < benoit . mortier @ opensides . be >
2021-03-19 11:27:31 +01:00
* Copyright ( C ) 2005 - 2021 Regis Houssin < regis . houssin @ inodbox . com >
2015-04-23 17:52:05 +02:00
* Copyright ( C ) 2011 - 2014 Philippe Grand < philippe . grand @ atoo - net . com >
* Copyright ( C ) 2008 Matteli
2016-05-27 10:56:39 +02:00
* Copyright ( C ) 2011 - 2016 Juanjo Menent < jmenent @ 2 byte . es >
2015-04-23 17:52:05 +02:00
* Copyright ( C ) 2012 Christophe Battarel < christophe . battarel @ altairis . fr >
* Copyright ( C ) 2014 - 2015 Marcos García < marcosgdf @ gmail . com >
* Copyright ( C ) 2015 Raphaël Doursenaud < rdoursenaud @ gpcsolutions . fr >
2020-04-20 15:49:31 +02:00
* Copyright ( C ) 2020 Demarest Maxime < maxime @ indelog . fr >
2021-03-21 22:58:21 +01:00
* Copyright ( C ) 2020 Charlene Benke < charlie @ patas - monkey . com >
2021-03-14 17:58:05 +01:00
* Copyright ( C ) 2021 Frédéric France < frederic . france @ netlogic . fr >
2021-03-21 22:58:21 +01:00
* Copyright ( C ) 2021 Alexandre Spangaro < aspangaro @ open - dsi . fr >
2012-02-29 19:41:12 +01:00
*
2012-02-23 08:45:26 +01:00
* This program is free software ; you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
2013-01-16 15:36:08 +01:00
* the Free Software Foundation ; either version 3 of the License , or
2012-02-23 08:45:26 +01:00
* ( at your option ) any later version .
2012-02-29 19:41:12 +01:00
*
2012-02-23 08:45:26 +01:00
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
2012-02-29 19:41:12 +01:00
*
2012-02-23 08:45:26 +01:00
* You should have received a copy of the GNU General Public License
2019-09-23 21:55:30 +02:00
* along with this program . If not , see < https :// www . gnu . org / licenses />.
2012-02-23 08:45:26 +01:00
*/
2003-06-18 15:56:26 +02:00
2005-03-21 20:53:50 +01:00
/**
2008-11-28 00:02:49 +01:00
* \file htdocs / main . inc . php
2012-02-23 08:45:26 +01:00
* \ingroup core
2017-04-14 12:38:52 +02:00
* \brief File that defines environment for Dolibarr GUI pages only ( file not required by scripts )
2012-02-23 08:45:26 +01:00
*/
2004-10-29 00:15:31 +02:00
2017-04-14 12:38:52 +02:00
//@ini_set('memory_limit', '128M'); // This may be useless if memory is hard limited by your PHP
2010-02-28 03:01:46 +01:00
2015-06-06 14:21:18 +02:00
// For optional tuning. Enabled if environment variable MAIN_SHOW_TUNING_INFO is defined.
2019-11-13 19:37:08 +01:00
$micro_start_time = 0 ;
2021-02-23 20:26:57 +01:00
if ( ! empty ( $_SERVER [ 'MAIN_SHOW_TUNING_INFO' ])) {
2017-10-16 08:47:05 +02:00
list ( $usec , $sec ) = explode ( " " , microtime ());
2019-11-13 19:37:08 +01:00
$micro_start_time = (( float ) $usec + ( float ) $sec );
2017-10-16 08:47:05 +02:00
// Add Xdebug code coverage
//define('XDEBUGCOVERAGE',1);
if ( defined ( 'XDEBUGCOVERAGE' )) {
xdebug_start_code_coverage ();
}
2008-01-10 18:12:07 +01:00
}
2021-05-17 23:47:16 +02:00
/**
* Return the real char for a numeric entities .
2021-06-29 18:17:27 +02:00
* WARNING : This function is required by testSqlAndScriptInject () and the GETPOST 'restricthtml' . Regex calling must be similar .
2021-05-17 23:47:16 +02:00
*
* @ param string $matches String of numeric entity
* @ return string New value
*/
function realCharForNumericEntities ( $matches )
{
2021-06-29 19:05:18 +02:00
$newstringnumentity = preg_replace ( '/;$/' , '' , $matches [ 1 ]);
//print ' $newstringnumentity='.$newstringnumentity;
2021-05-17 23:47:16 +02:00
if ( preg_match ( '/^x/i' , $newstringnumentity )) {
2021-06-29 19:05:18 +02:00
$newstringnumentity = hexdec ( preg_replace ( '/^x/i' , '' , $newstringnumentity ));
2021-05-17 23:47:16 +02:00
}
2021-06-29 18:17:27 +02:00
// The numeric value we don't want as entities because they encode ascii char, and why using html entities on ascii except for haking ?
2021-05-17 23:47:16 +02:00
if (( $newstringnumentity >= 65 && $newstringnumentity <= 90 ) || ( $newstringnumentity >= 97 && $newstringnumentity <= 122 )) {
return chr (( int ) $newstringnumentity );
}
2021-10-23 22:22:10 +02:00
return '&#' . $matches [ 1 ]; // Value will be unchanged because regex was /&#( )/
2021-05-17 23:47:16 +02:00
}
2011-09-12 19:08:02 +02:00
/**
2020-09-20 19:20:34 +02:00
* Security : WAF layer for SQL Injection and XSS Injection ( scripts ) protection ( Filters on GET , POST , PHP_SELF ) .
2021-05-17 23:47:16 +02:00
* Warning : Such a protection can ' t be enough . It is not reliable as it will always be possible to bypass this . Good protection can
2021-01-25 22:46:09 +01:00
* only be guaranted by escaping data during output .
2011-09-12 19:08:02 +02:00
*
2022-11-28 18:42:59 +01:00
* @ param string $val Brute value found into $_GET , $_POST or PHP_SELF
2021-03-29 15:49:34 +02:00
* @ param string $type 0 = POST , 1 = GET , 2 = PHP_SELF , 3 = GET without sql reserved keywords ( the less tolerant test )
2018-04-06 18:33:51 +02:00
* @ return int > 0 if there is an injection , 0 if none
2011-09-12 19:08:02 +02:00
*/
2018-09-01 17:42:16 +02:00
function testSqlAndScriptInject ( $val , $type )
2007-01-19 19:25:10 +01:00
{
2021-05-17 23:47:16 +02:00
// Decode string first because a lot of things are obfuscated by encoding or multiple encoding.
2020-10-15 19:36:08 +02:00
// So <svg onload='console.log("123")' become <svg onload='console.log("123")'
// So ":'" become ":'" (due to ENT_HTML5)
2022-12-05 15:05:40 +01:00
// So "	
" become ""
// So "()" become "()"
2022-04-02 14:32:53 +02:00
// Loop to decode until no more things to decode.
2021-03-14 15:06:40 +01:00
//print "before decoding $val\n";
do {
$oldval = $val ;
2022-12-05 15:05:40 +01:00
$val = html_entity_decode ( $val , ENT_QUOTES | ENT_HTML5 ); // Decode ':', ''', '	', '&NewLine', ...
// Sometimes we have entities without the ; at end so html_entity_decode does not work but entities is still interpreted by browser.
2022-01-17 09:12:09 +01:00
$val = preg_replace_callback ( '/&#(x?[0-9][0-9a-f]+;?)/i' , function ( $m ) {
2022-12-05 15:05:40 +01:00
// Decode 'n', ...
2022-01-17 09:12:09 +01:00
return realCharForNumericEntities ( $m ); }, $val );
2022-02-24 17:49:52 +01:00
// We clean html comments because some hacks try to obfuscate evil strings by inserting HTML comments. Example: on<!-- -->error=alert(1)
$val = preg_replace ( '/<!--[^>]*-->/' , '' , $val );
2022-12-05 15:05:40 +01:00
$val = preg_replace ( '/[\r\n\t]/' , '' , $val );
2021-03-14 15:06:40 +01:00
} while ( $oldval != $val );
2022-04-02 14:32:53 +02:00
//print "type = ".$type." after decoding: ".$val."\n";
2020-09-19 03:25:25 +02:00
2017-10-16 08:47:05 +02:00
$inj = 0 ;
2022-04-02 14:32:53 +02:00
// 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)
2020-10-15 19:36:08 +02:00
// We should use dol_string_nounprintableascii but function is not yet loaded/available
2022-04-02 15:26:40 +02:00
// Example of valid UTF8 chars:
2022-04-19 23:39:09 +02:00
// utf8=utf8mb3: '\x09', '\x0A', '\x0D', '\x7E'
2022-04-02 15:26:40 +02:00
// utf8=utf8mb3: '\xE0\xA0\x80'
// utf8mb4: '\xF0\x9D\x84\x9E' (but this may be refused by the database insert if pagecode is utf8=utf8mb3)
2022-04-19 23:39:09 +02:00
$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
2022-04-02 15:26:40 +02:00
// Note that $newval may also be completely empty '' when non valid UTF8 are found.
2022-04-02 14:32:53 +02:00
if ( $newval != $val ) {
// If $val has changed after removing non valid UTF8 chars, it means we have an evil string.
$inj += 1 ;
}
//print 'type='.$type.'-val='.$val.'-newval='.$newval."-inj=".$inj."\n";
2020-09-20 04:56:45 +02:00
2021-06-25 10:47:31 +02:00
// For SQL Injection (only GET are used to scan for such injection strings)
2021-02-23 20:26:57 +01:00
if ( $type == 1 || $type == 3 ) {
2022-12-06 12:01:26 +01:00
// Note the \s+ is replaced into \s* because some spaces may have been modified in previous loop
2022-12-05 15:05:40 +01:00
$inj += preg_match ( '/delete\s*from/i' , $val );
$inj += preg_match ( '/create\s*table/i' , $val );
$inj += preg_match ( '/insert\s*into/i' , $val );
$inj += preg_match ( '/select\s*from/i' , $val );
$inj += preg_match ( '/into\s*(outfile|dumpfile)/i' , $val );
2021-06-25 10:50:58 +02:00
$inj += preg_match ( '/user\s*\(/i' , $val ); // avoid to use function user() or mysql_user() that return current database login
2019-11-13 19:37:08 +01:00
$inj += preg_match ( '/information_schema/i' , $val ); // avoid to use request that read information_schema database
2020-10-27 19:46:07 +01:00
$inj += preg_match ( '/<svg/i' , $val ); // <svg can be allowed in POST
2022-06-29 16:40:19 +02:00
$inj += preg_match ( '/update[^&].*set.+=/i' , $val ); // the [^&] test is to avoir error when request is like action=update&...set...
2021-06-25 10:47:31 +02:00
$inj += preg_match ( '/union.+select/i' , $val );
2017-12-01 17:22:32 +01:00
}
2021-02-23 20:26:57 +01:00
if ( $type == 3 ) {
2022-12-06 12:01:26 +01:00
// Note the \s+ is replaced into \s* because some spaces may have been modified in previous loop
$inj += preg_match ( '/select|update|delete|truncate|replace|group\s*by|concat|count|from|union/i' , $val );
2018-06-25 14:06:09 +02:00
}
2021-02-23 20:26:57 +01:00
if ( $type != 2 ) { // Not common key strings, so we can check them both on GET and POST
2019-02-09 12:00:49 +01:00
$inj += preg_match ( '/updatexml\(/i' , $val );
$inj += preg_match ( '/(\.\.%2f)+/i' , $val );
2021-06-25 10:47:31 +02:00
$inj += preg_match ( '/\s@@/' , $val );
2017-10-16 08:47:05 +02:00
}
2020-09-19 03:25:25 +02:00
// For XSS Injection done by closing textarea to execute content into a textarea field
2019-09-18 14:44:31 +02:00
$inj += preg_match ( '/<\/textarea/i' , $val );
2017-10-16 08:47:05 +02:00
// For XSS Injection done by adding javascript with script
// This is all cases a browser consider text is javascript:
// When it found '<script', 'javascript:', '<style', 'onload\s=' on body tag, '="&' on a tag size with old browsers
// All examples on page: http://ha.ckers.org/xss.html#XSScalc
2017-09-07 13:50:16 +02:00
// More on https://www.owasp.org/index.php/XSS_Filter_Evasion_Cheat_Sheet
2018-04-06 19:12:13 +02:00
$inj += preg_match ( '/<audio/i' , $val );
2020-09-20 19:20:34 +02:00
$inj += preg_match ( '/<embed/i' , $val );
2020-09-18 13:25:56 +02:00
$inj += preg_match ( '/<iframe/i' , $val );
$inj += preg_match ( '/<object/i' , $val );
$inj += preg_match ( '/<script/i' , $val );
2019-11-22 14:16:38 +01:00
$inj += preg_match ( '/Set\.constructor/i' , $val ); // ECMA script 6
2021-02-23 20:26:57 +01:00
if ( ! defined ( 'NOSTYLECHECK' )) {
$inj += preg_match ( '/<style/i' , $val );
}
2020-09-20 19:20:34 +02:00
$inj += preg_match ( '/base\s+href/si' , $val );
$inj += preg_match ( '/=data:/si' , $val );
2021-05-21 12:17:56 +02:00
// 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
$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)>
2021-10-08 12:14:42 +02:00
$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 );
2022-02-22 22:19:32 +01:00
$inj += preg_match ( '/on(dblclick|drop|durationchange|emptied|end|ended|error|focus|focusin|focusout|formdata|gotpointercapture|hashchange|input|invalid)\s*=/i' , $val );
2021-05-21 14:03:52 +02:00
$inj += preg_match ( '/on(lostpointercapture|offline|online|pagehide|pageshow)\s*=/i' , $val );
$inj += preg_match ( '/on(paste|pause|play|playing|progress|ratechange|reset|resize|scroll|search|seeked|seeking|show|stalled|start|submit|suspend)\s*=/i' , $val );
2021-05-21 12:17:56 +02:00
$inj += preg_match ( '/on(timeupdate|toggle|unload|volumechange|waiting|wheel)\s*=/i' , $val );
2021-01-25 22:46:09 +01:00
// 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
$tmpval = preg_replace ( '/<[^<]+>/' , '' , $val );
2021-05-21 12:17:56 +02:00
// 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
$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)>
2022-02-22 22:19:32 +01:00
$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 );
$inj += preg_match ( '/on(dblclick|drop|durationchange|emptied|end|ended|error|focus|focusin|focusout|formdata|gotpointercapture|hashchange|input|invalid)\s*=/i' , $tmpval );
2021-05-21 12:17:56 +02:00
$inj += preg_match ( '/on(lostpointercapture|offline|online|pagehide|pageshow)\s*=/i' , $tmpval );
2021-05-21 14:03:52 +02:00
$inj += preg_match ( '/on(paste|pause|play|playing|progress|ratechange|reset|resize|scroll|search|seeked|seeking|show|stalled|start|submit|suspend)\s*=/i' , $tmpval );
2021-05-21 12:17:56 +02:00
$inj += preg_match ( '/on(timeupdate|toggle|unload|volumechange|waiting|wheel)\s*=/i' , $tmpval );
2021-01-25 22:46:09 +01:00
2017-10-16 08:47:05 +02:00
//$inj += preg_match('/on[A-Z][a-z]+\*=/', $val); // To lock event handlers onAbort(), ...
2019-11-22 14:16:38 +01:00
$inj += preg_match ( '/:|:|:/i' , $val ); // refused string ':' encoded (no reason to have it encoded) to lock 'javascript:...'
2022-12-05 15:05:40 +01:00
$inj += preg_match ( '/j\s*a\s*v\s*a\s*s\s*c\s*r\s*i\s*p\s*t\s*:/i' , $val );
2020-09-20 19:20:34 +02:00
$inj += preg_match ( '/vbscript\s*:/i' , $val );
2017-10-16 08:47:05 +02:00
// For XSS Injection done by adding javascript closing html tags like with onmousemove, etc... (closing a src or href tag with not cleaned param)
2022-06-30 22:52:08 +02:00
if ( $type == 1 || $type == 3 ) {
2021-03-14 15:06:40 +01:00
$val = str_replace ( 'enclosure="' , 'enclosure=X' , $val ); // We accept enclosure=" for the export/import module
2020-09-28 20:05:58 +02:00
$inj += preg_match ( '/"/i' , $val ); // We refused " in GET parameters value.
}
2021-02-23 20:26:57 +01:00
if ( $type == 2 ) {
2021-03-29 21:17:41 +02:00
$inj += preg_match ( '/[:;"\'<>\?\(\){}\$%]/' , $val ); // PHP_SELF is a file system (or url path without parameters). It can contains spaces.
2021-02-23 20:26:57 +01:00
}
2021-03-14 15:06:40 +01:00
2017-10-16 08:47:05 +02:00
return $inj ;
2007-01-19 19:25:10 +01:00
}
2011-09-12 19:43:31 +02:00
2011-09-12 19:08:02 +02:00
/**
2015-06-06 14:34:57 +02:00
* Return true if security check on parameters are OK , false otherwise .
2011-09-12 19:08:02 +02:00
*
2022-08-11 01:13:25 +02:00
* @ param string | array $var Variable name
2015-04-06 12:22:52 +02:00
* @ param string $type 1 = GET , 0 = POST , 2 = PHP_SELF
2018-04-06 18:33:51 +02:00
* @ return boolean | null true if there is no injection . Stop code if injection found .
2011-09-12 19:08:02 +02:00
*/
2015-04-06 12:22:52 +02:00
function analyseVarsForSqlAndScriptsInjection ( & $var , $type )
2007-01-19 19:25:10 +01:00
{
2021-02-23 20:26:57 +01:00
if ( is_array ( $var )) {
foreach ( $var as $key => $value ) { // Warning, $key may also be used for attacks
if ( analyseVarsForSqlAndScriptsInjection ( $key , $type ) && analyseVarsForSqlAndScriptsInjection ( $value , $type )) {
2018-04-06 18:33:51 +02:00
//$var[$key] = $value; // This is useless
2020-05-21 01:03:03 +02:00
} else {
2020-09-20 19:20:34 +02:00
// Get remote IP: PS: We do not use getRemoteIP(), function is not yet loaded and we need a value that can't be spoofed
$ip = ( empty ( $_SERVER [ 'REMOTE_ADDR' ]) ? 'unknown' : $_SERVER [ 'REMOTE_ADDR' ]);
2022-07-22 19:25:15 +02:00
$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' );
2020-09-20 19:20:34 +02:00
print $errormessage ;
// Add entry into error log
2020-09-22 16:26:53 +02:00
if ( function_exists ( 'error_log' )) {
error_log ( $errormessage );
}
2020-09-20 19:20:34 +02:00
// TODO Add entry into security audit table
2017-10-16 08:47:05 +02:00
exit ;
}
}
return true ;
2020-05-21 01:03:03 +02:00
} else {
2018-09-01 17:42:16 +02:00
return ( testSqlAndScriptInject ( $var , $type ) <= 0 );
2017-10-16 08:47:05 +02:00
}
2007-01-19 19:25:10 +01:00
}
2011-09-12 20:15:11 +02:00
2022-11-28 20:18:12 +01:00
// To disable the WAF for GET and POST and PHP_SELF, uncomment this
//define('NOSCANPHPSELFFORINJECTION', 1);
2022-11-28 18:42:59 +01:00
//define('NOSCANGETFORINJECTION', 1);
//define('NOSCANPOSTFORINJECTION', 1);
2013-02-24 14:54:08 +01:00
2014-01-21 18:55:45 +01:00
// Check consistency of NOREQUIREXXX DEFINES
2021-02-19 15:06:36 +01:00
if (( defined ( 'NOREQUIREDB' ) || defined ( 'NOREQUIRETRAN' )) && ! defined ( 'NOREQUIREMENU' )) {
print 'If define NOREQUIREDB or NOREQUIRETRAN are set, you must also set NOREQUIREMENU or not set them.' ;
exit ;
}
if ( defined ( 'NOREQUIREUSER' ) && ! defined ( 'NOREQUIREMENU' )) {
print 'If define NOREQUIREUSER is set, you must also set NOREQUIREMENU or not set it.' ;
2017-12-19 00:15:22 +01:00
exit ;
}
2013-02-24 14:54:08 +01:00
2011-03-07 23:35:35 +01:00
// Sanity check on URL
2022-11-28 20:18:12 +01:00
if ( ! defined ( 'NOSCANPHPSELFFORINJECTION' ) && ! empty ( $_SERVER [ " PHP_SELF " ])) {
2019-11-13 19:37:08 +01:00
$morevaltochecklikepost = array ( $_SERVER [ " PHP_SELF " ]);
2019-01-27 11:55:16 +01:00
analyseVarsForSqlAndScriptsInjection ( $morevaltochecklikepost , 2 );
2011-03-08 17:38:58 +01:00
}
2011-03-07 23:35:35 +01:00
// Sanity check on GET parameters
2021-02-23 20:26:57 +01:00
if ( ! defined ( 'NOSCANGETFORINJECTION' ) && ! empty ( $_SERVER [ " QUERY_STRING " ])) {
2020-09-26 05:20:33 +02:00
// Note: QUERY_STRING is url encoded, but $_GET and $_POST are already decoded
// Because the analyseVarsForSqlAndScriptsInjection is designed for already url decoded value, we must decode QUERY_STRING
// Another solution is to provide $_GET as parameter
$morevaltochecklikeget = array ( urldecode ( $_SERVER [ " QUERY_STRING " ]));
2019-01-27 11:55:16 +01:00
analyseVarsForSqlAndScriptsInjection ( $morevaltochecklikeget , 1 );
2011-03-08 17:38:58 +01:00
}
2011-03-07 23:35:35 +01:00
// Sanity check on POST
2021-02-23 20:26:57 +01:00
if ( ! defined ( 'NOSCANPOSTFORINJECTION' )) {
2019-01-27 11:55:16 +01:00
analyseVarsForSqlAndScriptsInjection ( $_POST , 0 );
2015-05-19 22:08:51 +02:00
}
2011-03-06 21:42:36 +01:00
2010-12-15 00:27:17 +01:00
// This is to make Dolibarr working with Plesk
2021-02-23 20:26:57 +01:00
if ( ! empty ( $_SERVER [ 'DOCUMENT_ROOT' ]) && substr ( $_SERVER [ 'DOCUMENT_ROOT' ], - 6 ) !== 'htdocs' ) {
2019-11-13 19:37:08 +01:00
set_include_path ( $_SERVER [ 'DOCUMENT_ROOT' ] . '/htdocs' );
2015-09-17 19:26:52 +02:00
}
2008-01-20 22:53:43 +01:00
2022-01-14 10:15:46 +01:00
// 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...
2012-08-22 23:11:24 +02:00
require_once 'filefunc.inc.php' ;
2010-12-29 13:13:36 +01:00
2017-09-24 19:50:32 +02:00
// If there is a POST parameter to tell to save automatically some POST parameters into cookies, we do it.
// This is used for example by form of boxes to save personalization of some options.
// DOL_AUTOSET_COOKIE=cookiename:val1,val2 and cookiename_val1=aaa cookiename_val2=bbb will set cookie_name with value json_encode(array('val1'=> , ))
2021-02-23 20:26:57 +01:00
if ( ! empty ( $_POST [ " DOL_AUTOSET_COOKIE " ])) {
2019-11-13 19:37:08 +01:00
$tmpautoset = explode ( ':' , $_POST [ " DOL_AUTOSET_COOKIE " ], 2 );
$tmplist = explode ( ',' , $tmpautoset [ 1 ]);
$cookiearrayvalue = array ();
2021-02-23 20:26:57 +01:00
foreach ( $tmplist as $tmpkey ) {
2019-11-13 19:37:08 +01:00
$postkey = $tmpautoset [ 0 ] . '_' . $tmpkey ;
2013-09-21 12:30:44 +02:00
//var_dump('tmpkey='.$tmpkey.' postkey='.$postkey.' value='.$_POST[$postkey]);
2021-02-23 20:26:57 +01:00
if ( ! empty ( $_POST [ $postkey ])) {
$cookiearrayvalue [ $tmpkey ] = $_POST [ $postkey ];
}
2013-07-29 17:32:43 +02:00
}
2019-11-13 19:37:08 +01:00
$cookiename = $tmpautoset [ 0 ];
$cookievalue = json_encode ( $cookiearrayvalue );
2013-09-21 12:30:44 +02:00
//var_dump('setcookie cookiename='.$cookiename.' cookievalue='.$cookievalue);
2022-03-29 11:06:18 +02:00
if ( PHP_VERSION_ID < 70300 ) {
2022-03-29 12:03:18 +02:00
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
2022-03-29 11:06:18 +02:00
} else {
2022-03-29 11:10:41 +02:00
// Only available for php >= 7.3
2022-03-29 11:06:18 +02:00
$cookieparams = array (
'expires' => empty ( $cookievalue ) ? 0 : ( time () + ( 86400 * 354 )),
'path' => '/' ,
//'domain' => '.mywebsite.com', // the dot at the beginning allows compatibility with subdomains
2022-03-29 12:03:18 +02:00
'secure' => (( empty ( $dolibarr_main_force_https ) && isHTTPS () === false ) ? false : true ),
2022-03-29 11:06:18 +02:00
'httponly' => true ,
'samesite' => 'Lax' // None || Lax || Strict
);
setcookie ( $cookiename , empty ( $cookievalue ) ? '' : $cookievalue , $cookieparams );
}
2021-02-23 20:26:57 +01:00
if ( empty ( $cookievalue )) {
unset ( $_COOKIE [ $cookiename ]);
}
2013-07-29 17:32:43 +02:00
}
2013-04-28 18:46:34 +02:00
2020-11-24 12:26:32 +01:00
// Set the handler of session
2021-12-07 17:39:28 +01:00
// if (ini_get('session.save_handler') == 'user')
2021-12-08 15:07:55 +01:00
if ( ! empty ( $php_session_save_handler ) && $php_session_save_handler == 'db' ) {
2021-12-07 17:39:28 +01:00
require_once 'core/lib/phpsessionin' . $php_session_save_handler . '.lib.php' ;
2020-11-24 12:26:32 +01:00
}
2009-05-22 00:28:05 +02:00
// Init session. Name of session is specific to Dolibarr instance.
2020-12-05 13:26:58 +01:00
// 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).
2022-02-21 11:26:03 +01:00
// 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.
2020-12-05 13:26:58 +01:00
$prefix = dol_getprefix ( '' );
2019-11-13 19:37:08 +01:00
$sessionname = 'DOLSESSID_' . $prefix ;
$sessiontimeout = 'DOLSESSTIMEOUT_' . $prefix ;
2021-02-23 20:26:57 +01:00
if ( ! empty ( $_COOKIE [ $sessiontimeout ])) {
ini_set ( 'session.gc_maxlifetime' , $_COOKIE [ $sessiontimeout ]);
}
2021-08-22 00:44:51 +02:00
2020-10-11 13:18:16 +02:00
// This create lock, released by session_write_close() or end of page.
2017-12-22 01:03:40 +01:00
// We need this lock as long as we read/write $_SESSION ['vars']. We can remove lock when finished.
2021-02-23 20:26:57 +01:00
if ( ! defined ( 'NOSESSION' )) {
2022-03-29 11:06:18 +02:00
if ( PHP_VERSION_ID < 70300 ) {
2022-03-29 12:03:18 +02:00
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.
2022-03-29 11:06:18 +02:00
} else {
2022-03-29 11:10:41 +02:00
// Only available for php >= 7.3
2022-03-29 11:06:18 +02:00
$sessioncookieparams = array (
'lifetime' => 0 ,
'path' => '/' ,
//'domain' => '.mywebsite.com', // the dot at the beginning allows compatibility with subdomains
2022-03-29 12:03:18 +02:00
'secure' => (( empty ( $dolibarr_main_force_https ) && isHTTPS () === false ) ? false : true ),
2022-03-29 11:06:18 +02:00
'httponly' => true ,
'samesite' => 'Lax' // None || Lax || Strict
);
session_set_cookie_params ( $sessioncookieparams );
}
2020-12-04 13:22:47 +01:00
session_name ( $sessionname );
2021-12-07 17:39:28 +01:00
session_start (); // This call the open and read of session handler
//exit; // this exist generates a call to write and close
2012-04-20 20:38:49 +02:00
}
2009-05-22 00:28:05 +02:00
2020-12-04 23:50:55 +01:00
2020-12-05 13:26:58 +01:00
// Init the 5 global objects, this include will make the 'new Xxx()' and set properties for: $conf, $db, $langs, $user, $mysoc
require_once 'master.inc.php' ;
2020-12-04 23:50:55 +01:00
// If software has been locked. Only login $conf->global->MAIN_ONLY_LOGIN_ALLOWED is allowed.
2021-02-23 20:26:57 +01:00
if ( ! empty ( $conf -> global -> MAIN_ONLY_LOGIN_ALLOWED )) {
2020-12-04 23:50:55 +01:00
$ok = 0 ;
2021-02-23 20:26:57 +01:00
if (( ! session_id () || ! isset ( $_SESSION [ " dol_login " ])) && ! isset ( $_POST [ " username " ]) && ! empty ( $_SERVER [ " GATEWAY_INTERFACE " ])) {
$ok = 1 ; // We let working pages if not logged and inside a web browser (login form, to allow login by admin)
} elseif ( isset ( $_POST [ " username " ]) && $_POST [ " username " ] == $conf -> global -> MAIN_ONLY_LOGIN_ALLOWED ) {
$ok = 1 ; // We let working pages that is a login submission (login submit, to allow login by admin)
} elseif ( defined ( 'NOREQUIREDB' )) {
$ok = 1 ; // We let working pages that don't need database access (xxx.css.php)
} elseif ( defined ( 'EVEN_IF_ONLY_LOGIN_ALLOWED' )) {
$ok = 1 ; // We let working pages that ask to work even if only login enabled (logout.php)
} elseif ( session_id () && isset ( $_SESSION [ " dol_login " ]) && $_SESSION [ " dol_login " ] == $conf -> global -> MAIN_ONLY_LOGIN_ALLOWED ) {
$ok = 1 ; // We let working if user is allowed admin
}
if ( ! $ok ) {
if ( session_id () && isset ( $_SESSION [ " dol_login " ]) && $_SESSION [ " dol_login " ] != $conf -> global -> MAIN_ONLY_LOGIN_ALLOWED ) {
2020-12-04 23:50:55 +01:00
print 'Sorry, your application is offline.' . " \n " ;
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 " ;
2021-12-31 14:33:12 +01:00
$nexturl = DOL_URL_ROOT . '/user/logout.php?token=' . newToken ();
2020-12-04 23:50:55 +01:00
print 'Please try later or <a href="' . $nexturl . '">click here to disconnect and change login user</a>...' . " \n " ;
} else {
print 'Sorry, your application is offline. Only administrator user "' . $conf -> global -> MAIN_ONLY_LOGIN_ALLOWED . '" is allowed to connect for the moment.' . " \n " ;
$nexturl = DOL_URL_ROOT . '/' ;
print 'Please try later or <a href="' . $nexturl . '">click here to change login user</a>...' . " \n " ;
}
exit ;
}
}
2011-04-30 03:17:51 +02:00
// Activate end of page function
2011-03-09 16:06:33 +01:00
register_shutdown_function ( 'dol_shutdown' );
2010-12-29 13:13:36 +01:00
2019-03-23 14:37:54 +01:00
// Load debugbar
2022-06-09 21:51:48 +02:00
if ( isModEnabled ( 'debugbar' ) && ! GETPOST ( 'dol_use_jmobile' ) && empty ( $_SESSION [ 'dol_use_jmobile' ])) {
2020-10-27 19:46:07 +01:00
global $debugbar ;
include_once DOL_DOCUMENT_ROOT . '/debugbar/class/DebugBar.php' ;
$debugbar = new DolibarrDebugBar ();
$renderer = $debugbar -> getRenderer ();
2021-02-23 20:26:57 +01:00
if ( empty ( $conf -> global -> MAIN_HTML_HEADER )) {
$conf -> global -> MAIN_HTML_HEADER = '' ;
}
2020-10-27 19:46:07 +01:00
$conf -> global -> MAIN_HTML_HEADER .= $renderer -> renderHead ();
2019-03-23 14:37:54 +01:00
2020-10-27 19:46:07 +01:00
$debugbar [ 'time' ] -> startMeasure ( 'pageaftermaster' , 'Page generation (after environment init)' );
2019-03-23 14:37:54 +01:00
}
2011-02-20 13:16:18 +01:00
// Detection browser
2021-02-23 20:26:57 +01:00
if ( isset ( $_SERVER [ " HTTP_USER_AGENT " ])) {
2019-11-22 14:16:38 +01:00
$tmp = getBrowserInfo ( $_SERVER [ " HTTP_USER_AGENT " ]);
$conf -> browser -> name = $tmp [ 'browsername' ];
$conf -> browser -> os = $tmp [ 'browseros' ];
$conf -> browser -> version = $tmp [ 'browserversion' ];
$conf -> browser -> layout = $tmp [ 'layout' ]; // 'classic', 'phone', 'tablet'
2017-10-16 08:47:05 +02:00
//var_dump($conf->browser);
2021-02-23 20:26:57 +01:00
if ( $conf -> browser -> layout == 'phone' ) {
$conf -> dol_no_mouse_hover = 1 ;
}
2016-06-17 16:28:16 +02:00
}
2011-02-20 13:16:18 +01:00
2021-12-12 21:20:12 +01:00
// If theme is forced
if ( GETPOST ( 'theme' , 'aZ09' )) {
$conf -> theme = GETPOST ( 'theme' , 'aZ09' );
$conf -> css = " /theme/ " . $conf -> theme . " /style.css.php " ;
}
2020-06-10 12:35:39 +02:00
// Set global MAIN_OPTIMIZEFORTEXTBROWSER (must be before login part)
2021-02-23 20:26:57 +01:00
if ( GETPOST ( 'textbrowser' , 'int' ) || ( ! empty ( $conf -> browser -> name ) && $conf -> browser -> name == 'lynxlinks' )) { // If we must enable text browser
2020-06-10 12:35:39 +02:00
$conf -> global -> MAIN_OPTIMIZEFORTEXTBROWSER = 1 ;
}
2020-03-22 02:16:33 +01:00
// Force HTTPS if required ($conf->file->main_force_https is 0/1 or 'https dolibarr root url')
2015-09-07 16:43:17 +02:00
// $_SERVER["HTTPS"] is 'on' when link is https, otherwise $_SERVER["HTTPS"] is empty or 'off'
2021-02-23 20:26:57 +01:00
if ( ! empty ( $conf -> file -> main_force_https ) && ( empty ( $_SERVER [ " HTTPS " ]) || $_SERVER [ " HTTPS " ] != 'on' )) {
2019-11-22 14:16:38 +01:00
$newurl = '' ;
2021-02-23 20:26:57 +01:00
if ( is_numeric ( $conf -> file -> main_force_https )) {
if ( $conf -> file -> main_force_https == '1' && ! empty ( $_SERVER [ " SCRIPT_URI " ])) { // If SCRIPT_URI supported by server
if ( preg_match ( '/^http:/i' , $_SERVER [ " SCRIPT_URI " ]) && ! preg_match ( '/^https:/i' , $_SERVER [ " SCRIPT_URI " ])) { // If link is http
2019-11-22 14:16:38 +01:00
$newurl = preg_replace ( '/^http:/i' , 'https:' , $_SERVER [ " SCRIPT_URI " ]);
2017-10-16 08:47:05 +02:00
}
2020-05-21 15:08:14 +02:00
} else {
2020-05-21 01:03:03 +02:00
// Check HTTPS environment variable (Apache/mod_ssl only)
2019-11-22 14:16:38 +01:00
$newurl = preg_replace ( '/^http:/i' , 'https:' , DOL_MAIN_URL_ROOT ) . $_SERVER [ " REQUEST_URI " ];
2017-10-16 08:47:05 +02:00
}
2020-05-21 01:03:03 +02:00
} else {
2017-10-16 08:47:05 +02:00
// Check HTTPS environment variable (Apache/mod_ssl only)
2019-11-22 14:16:38 +01:00
$newurl = $conf -> file -> main_force_https . $_SERVER [ " REQUEST_URI " ];
2017-10-16 08:47:05 +02:00
}
// Start redirect
2021-02-23 20:26:57 +01:00
if ( $newurl ) {
2020-04-10 10:59:32 +02:00
header_remove (); // Clean header already set to be sure to remove any header like "Set-Cookie: DOLSESSID_..." from non HTTPS answers
2017-10-16 08:47:05 +02:00
dol_syslog ( " main.inc: dolibarr_main_force_https is on, we make a redirect to " . $newurl );
header ( " Location: " . $newurl );
exit ;
2020-05-21 01:03:03 +02:00
} else {
2017-10-16 08:47:05 +02:00
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 );
}
2008-04-06 22:17:11 +02:00
}
2008-03-12 22:26:53 +01:00
2021-02-23 20:26:57 +01:00
if ( ! defined ( 'NOLOGIN' ) && ! defined ( 'NOIPCHECK' ) && ! empty ( $dolibarr_main_restrict_ip )) {
2019-11-13 19:37:08 +01:00
$listofip = explode ( ',' , $dolibarr_main_restrict_ip );
2018-02-15 19:49:50 +01:00
$found = false ;
2021-02-23 20:26:57 +01:00
foreach ( $listofip as $ip ) {
2019-11-13 19:37:08 +01:00
$ip = trim ( $ip );
2021-02-23 20:26:57 +01:00
if ( $ip == $_SERVER [ 'REMOTE_ADDR' ]) {
2018-02-15 19:49:50 +01:00
$found = true ;
break ;
}
}
2021-02-23 20:26:57 +01:00
if ( ! $found ) {
2019-12-09 09:43:38 +01:00
print 'Access refused by IP protection. Your detected IP is ' . $_SERVER [ 'REMOTE_ADDR' ];
2018-02-15 19:49:50 +01:00
exit ;
}
}
2009-02-02 19:33:44 +01:00
2014-02-26 16:51:38 +01:00
// Loading of additional presentation includes
2021-02-23 20:26:57 +01:00
if ( ! defined ( 'NOREQUIREHTML' )) {
require_once DOL_DOCUMENT_ROOT . '/core/class/html.form.class.php' ; // Need 660ko memory (800ko in 2.2)
}
if ( ! defined ( 'NOREQUIREAJAX' )) {
require_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php' ; // Need 22ko memory
}
2006-06-03 01:20:36 +02:00
2009-08-08 18:26:06 +02:00
// If install or upgrade process not done or not completely finished, we call the install page.
2021-02-23 20:26:57 +01:00
if ( ! empty ( $conf -> global -> MAIN_NOT_INSTALLED ) || ! empty ( $conf -> global -> MAIN_NOT_UPGRADED )) {
2017-10-16 08:47:05 +02:00
dol_syslog ( " main.inc: A previous install or upgrade was not complete. Redirect to install page. " , LOG_WARNING );
header ( " Location: " . DOL_URL_ROOT . " /install/index.php " );
exit ;
2009-08-08 18:26:06 +02:00
}
// If an upgrade process is required, we call the install page.
2019-11-13 19:37:08 +01:00
if (( ! empty ( $conf -> global -> MAIN_VERSION_LAST_UPGRADE ) && ( $conf -> global -> MAIN_VERSION_LAST_UPGRADE != DOL_VERSION ))
2021-02-23 20:26:57 +01:00
|| ( empty ( $conf -> global -> MAIN_VERSION_LAST_UPGRADE ) && ! empty ( $conf -> global -> MAIN_VERSION_LAST_INSTALL ) && ( $conf -> global -> MAIN_VERSION_LAST_INSTALL != DOL_VERSION ))) {
2019-11-13 19:37:08 +01:00
$versiontocompare = empty ( $conf -> global -> MAIN_VERSION_LAST_UPGRADE ) ? $conf -> global -> MAIN_VERSION_LAST_INSTALL : $conf -> global -> MAIN_VERSION_LAST_UPGRADE ;
require_once DOL_DOCUMENT_ROOT . '/core/lib/admin.lib.php' ;
$dolibarrversionlastupgrade = preg_split ( '/[.-]/' , $versiontocompare );
$dolibarrversionprogram = preg_split ( '/[.-]/' , DOL_VERSION );
$rescomp = versioncompare ( $dolibarrversionprogram , $dolibarrversionlastupgrade );
2022-06-16 09:17:00 +02:00
if ( $rescomp > 0 ) { // Programs have a version higher than database.
if ( empty ( $conf -> global -> MAIN_NO_UPGRADE_REDIRECT_ON_LEVEL_3_CHANGE ) || $rescomp < 3 ) {
// We did not add "&& $rescomp < 3" because we want upgrade process for build upgrades
dol_syslog ( " main.inc: database version " . $versiontocompare . " is lower than programs version " . DOL_VERSION . " . Redirect to install/upgrade page. " , LOG_WARNING );
header ( " Location: " . DOL_URL_ROOT . " /install/index.php " );
exit ;
}
2017-10-16 08:47:05 +02:00
}
2009-08-08 18:26:06 +02:00
}
2010-02-19 14:50:49 +01:00
// Creation of a token against CSRF vulnerabilities
2021-08-24 21:48:38 +02:00
if ( ! defined ( 'NOTOKENRENEWAL' ) && ! defined ( 'NOSESSION' )) {
2021-06-21 13:06:40 +02:00
// No token renewal on .css.php, .js.php and .json.php
if ( ! preg_match ( '/\.(css|js|json)\.php$/' , $_SERVER [ " PHP_SELF " ])) {
// Rolling token at each call ($_SESSION['token'] contains token of previous page)
2021-06-23 11:39:17 +02:00
if ( isset ( $_SESSION [ 'newtoken' ])) {
$_SESSION [ 'token' ] = $_SESSION [ 'newtoken' ];
}
2017-06-10 16:29:25 +02:00
2021-09-26 20:56:40 +02:00
if ( ! isset ( $_SESSION [ 'newtoken' ]) || getDolGlobalInt ( 'MAIN_SECURITY_CSRF_TOKEN_RENEWAL_ON_EACH_CALL' )) {
2022-09-03 18:00:31 +02:00
// Note: Using MAIN_SECURITY_CSRF_TOKEN_RENEWAL_ON_EACH_CALL is not recommended: if a user succeed in entering a data from
// a public page with a link that make a token regeneration, it can make use of the backoffice no more possible !
2021-09-26 20:56:40 +02:00
// Save in $_SESSION['newtoken'] what will be next token. Into forms, we will add param token = $_SESSION['newtoken']
$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.
$_SESSION [ 'newtoken' ] = $token ;
2021-10-23 22:22:10 +02:00
dol_syslog ( " NEW TOKEN generated by : " . $_SERVER [ 'PHP_SELF' ], LOG_DEBUG );
2021-09-26 20:56:40 +02:00
}
2021-06-21 13:06:40 +02:00
}
2009-05-26 19:01:18 +02:00
}
2019-01-15 15:04:15 +01:00
2021-03-19 12:08:40 +01:00
//dol_syslog("aaaa - ".defined('NOCSRFCHECK')." - ".$dolibarr_nocsrfcheck." - ".$conf->global->MAIN_SECURITY_CSRF_WITH_TOKEN." - ".$_SERVER['REQUEST_METHOD']." - ".GETPOST('token', 'alpha'));
2021-03-18 21:22:50 +01:00
// Check validity of token, only if option MAIN_SECURITY_CSRF_WITH_TOKEN enabled or if constant CSRFCHECK_WITH_TOKEN is set into page
2021-09-19 14:49:11 +02:00
if (( ! defined ( 'NOCSRFCHECK' ) && empty ( $dolibarr_nocsrfcheck ) && getDolGlobalInt ( 'MAIN_SECURITY_CSRF_WITH_TOKEN' )) || defined ( 'CSRFCHECK_WITH_TOKEN' )) {
2021-03-19 12:44:59 +01:00
// Array of action code where CSRFCHECK with token will be forced (so token must be provided on url request)
$sensitiveget = false ;
2021-10-01 12:37:32 +02:00
if (( GETPOSTISSET ( 'massaction' ) || GETPOST ( 'action' , 'aZ09' )) && getDolGlobalInt ( 'MAIN_SECURITY_CSRF_WITH_TOKEN' ) >= 3 ) {
2021-09-19 18:03:38 +02:00
// All GET actions and mass actions are processed as sensitive.
2022-10-13 04:34:11 +02:00
if ( GETPOSTISSET ( 'massaction' ) || ! in_array ( GETPOST ( 'action' , 'aZ09' ), array ( 'create' , 'createsite' , 'createcard' , 'edit' , 'editvalidator' , 'file_manager' , 'presend' , 'presend_addmessage' , 'preview' , 'specimen' ))) { // We exclude the case action='create' and action='file_manager' that are legitimate
2022-02-11 15:30:45 +01:00
$sensitiveget = true ;
}
2021-10-01 12:37:32 +02:00
} elseif ( getDolGlobalInt ( 'MAIN_SECURITY_CSRF_WITH_TOKEN' ) >= 2 ) {
2021-10-01 12:30:24 +02:00
// Few GET actions coded with a &token into url are processed as sensitive.
2021-09-19 14:49:11 +02:00
$arrayofactiontoforcetokencheck = array (
2021-10-02 12:58:15 +02:00
'activate' ,
2021-09-19 14:49:11 +02:00
'doprev' , 'donext' , 'dvprev' , 'dvnext' ,
2022-09-17 14:08:21 +02:00
'freezone' , 'install' ,
2021-09-19 14:49:11 +02:00
'reopen'
);
if ( in_array ( GETPOST ( 'action' , 'aZ09' ), $arrayofactiontoforcetokencheck )) {
$sensitiveget = true ;
}
2022-09-17 14:08:21 +02:00
// We also match for value with just a simple string that must match
2021-10-02 13:04:57 +02:00
if ( preg_match ( '/^(add|classify|close|confirm|copy|del|disable|enable|remove|set|unset|update|save)/' , GETPOST ( 'action' , 'aZ09' ))) {
2021-09-19 14:49:11 +02:00
$sensitiveget = true ;
}
2021-03-19 12:44:59 +01:00
}
2022-03-30 12:02:20 +02:00
2021-06-17 03:37:52 +02:00
// Check a token is provided for all cases that need a mandatory token
2022-08-10 22:24:45 +02:00
// (all POST actions + all sensitive GET actions + all mass actions + all login/actions/logout on pages with CSRFCHECK_WITH_TOKEN set)
2021-03-17 19:27:15 +01:00
if (
$_SERVER [ 'REQUEST_METHOD' ] == 'POST' ||
2021-03-19 12:44:59 +01:00
$sensitiveget ||
2021-09-18 22:38:25 +02:00
GETPOSTISSET ( 'massaction' ) ||
(( GETPOSTISSET ( 'actionlogin' ) || GETPOSTISSET ( 'action' )) && defined ( 'CSRFCHECK_WITH_TOKEN' ))
2021-03-17 19:27:15 +01:00
) {
2021-06-17 03:37:52 +02:00
// If token is not provided or empty, error (we are in case it is mandatory)
if ( ! GETPOST ( 'token' , 'alpha' ) || GETPOST ( 'token' , 'alpha' ) == 'notrequired' ) {
2022-09-09 13:58:54 +02:00
top_httphead ();
2020-10-06 17:45:08 +02:00
if ( GETPOST ( 'uploadform' , 'int' )) {
2022-02-28 16:01:07 +01:00
dol_syslog ( " --- Access to " . ( empty ( $_SERVER [ " REQUEST_METHOD " ]) ? '' : $_SERVER [ " REQUEST_METHOD " ] . ' ' ) . $_SERVER [ " PHP_SELF " ] . " refused. File size too large or not provided. " );
2020-10-03 14:02:53 +02:00
$langs -> loadLangs ( array ( " errors " , " install " ));
print $langs -> trans ( " ErrorFileSizeTooLarge " ) . ' ' ;
print $langs -> trans ( " ErrorGoBackAndCorrectParameters " );
} else {
2022-02-16 14:34:32 +01:00
http_response_code ( 403 );
2021-01-16 13:03:34 +01:00
if ( defined ( 'CSRFCHECK_WITH_TOKEN' )) {
2021-10-23 22:22:10 +02:00
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 );
2021-01-16 13:03:34 +01:00
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 " ;
} else {
2021-10-23 22:22:10 +02:00
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 );
2021-01-16 13:03:34 +01:00
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 " ;
2021-09-27 15:41:58 +02:00
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 " ;
2021-10-23 22:22:10 +02:00
if ( ! empty ( $conf -> global -> MAIN_SECURITY_CSRF_WITH_TOKEN )) {
2021-09-27 15:41:58 +02:00
print " instead of " . $conf -> global -> MAIN_SECURITY_CSRF_WITH_TOKEN ;
}
print " into setup). \n " ;
2021-01-16 13:03:34 +01:00
}
2020-10-03 14:02:53 +02:00
}
2022-09-09 13:58:54 +02:00
die ;
2020-09-18 04:30:24 +02:00
}
2017-10-16 08:47:05 +02:00
}
2018-12-22 18:09:26 +01:00
2021-03-20 12:35:41 +01:00
$sessiontokenforthisurl = ( empty ( $_SESSION [ 'token' ]) ? '' : $_SESSION [ 'token' ]);
2022-04-11 02:01:32 +02:00
// 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)
2021-06-17 03:37:52 +02:00
if ( GETPOSTISSET ( 'token' ) && GETPOST ( 'token' ) != 'notrequired' && GETPOST ( 'token' , 'alpha' ) != $sessiontokenforthisurl ) {
2022-07-25 13:12:08 +02:00
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 );
2022-04-11 02:01:32 +02:00
//dol_syslog("_SESSION['token']=".$sessiontokenforthisurl, LOG_DEBUG);
// 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.
2020-09-18 04:30:24 +02:00
setEventMessages ( 'SecurityTokenHasExpiredSoActionHasBeenCanceledPleaseRetry' , null , 'warnings' );
2022-02-20 18:07:10 +01:00
$savid = null ;
if ( isset ( $_POST [ 'id' ])) {
$savid = (( int ) $_POST [ 'id' ]);
}
2020-09-22 15:31:09 +02:00
unset ( $_POST );
2020-09-25 15:01:15 +02:00
//unset($_POST['action']); unset($_POST['massaction']);
//unset($_POST['confirm']); unset($_POST['confirmmassaction']);
2018-12-22 18:09:26 +01:00
unset ( $_GET [ 'confirm' ]);
2020-09-19 16:05:55 +02:00
unset ( $_GET [ 'action' ]);
2020-09-25 15:01:15 +02:00
unset ( $_GET [ 'confirmmassaction' ]);
unset ( $_GET [ 'massaction' ]);
2022-02-20 18:07:10 +01:00
unset ( $_GET [ 'token' ]); // TODO Make a redirect if we have a token in url to remove it ?
if ( isset ( $savid )) {
$_POST [ 'id' ] = (( int ) $savid );
}
2017-10-16 08:47:05 +02:00
}
2021-03-16 11:58:03 +01:00
// Note: There is another CSRF protection into the filefunc.inc.php
2009-05-16 17:45:26 +02:00
}
2009-05-22 02:20:45 +02:00
// Disable modules (this must be after session_start and after conf has been loaded)
2021-02-23 20:26:57 +01:00
if ( GETPOSTISSET ( 'disablemodules' )) {
$_SESSION [ " disablemodules " ] = GETPOST ( 'disablemodules' , 'alpha' );
}
if ( ! empty ( $_SESSION [ " disablemodules " ])) {
2020-10-27 19:46:07 +01:00
$modulepartkeys = array ( 'css' , 'js' , 'tabs' , 'triggers' , 'login' , 'substitutions' , 'menus' , 'theme' , 'sms' , 'tpl' , 'barcode' , 'models' , 'societe' , 'hooks' , 'dir' , 'syslog' , 'tpllinkable' , 'contactelement' , 'moduleforexternal' );
2019-05-29 11:06:01 +02:00
2019-11-22 14:16:38 +01:00
$disabled_modules = explode ( ',' , $_SESSION [ " disablemodules " ]);
2021-02-23 20:26:57 +01:00
foreach ( $disabled_modules as $module ) {
if ( $module ) {
if ( empty ( $conf -> $module )) {
$conf -> $module = new stdClass (); // To avoid warnings
}
2019-11-22 14:16:38 +01:00
$conf -> $module -> enabled = false ;
2021-02-23 20:26:57 +01:00
foreach ( $modulepartkeys as $modulepartkey ) {
2020-10-27 19:46:07 +01:00
unset ( $conf -> modules_parts [ $modulepartkey ][ $module ]);
2019-05-29 11:06:01 +02:00
}
2021-02-23 20:26:57 +01:00
if ( $module == 'fournisseur' ) { // Special case
2019-11-22 14:16:38 +01:00
$conf -> supplier_order -> enabled = 0 ;
$conf -> supplier_invoice -> enabled = 0 ;
2017-10-16 08:47:05 +02:00
}
}
}
2008-11-28 00:24:50 +01:00
}
2019-02-04 17:52:15 +01:00
// Set current modulepart
2019-02-04 18:27:47 +01:00
$modulepart = explode ( " / " , $_SERVER [ " PHP_SELF " ]);
2021-02-23 20:26:57 +01:00
if ( is_array ( $modulepart ) && count ( $modulepart ) > 0 ) {
foreach ( $conf -> modules as $module ) {
if ( in_array ( $module , $modulepart )) {
2022-12-13 18:40:30 +01:00
$modulepart = $module ;
2020-10-27 19:46:07 +01:00
break ;
2019-02-04 17:52:15 +01:00
}
}
}
2022-12-13 18:40:30 +01:00
if ( is_array ( $modulepart )) {
$modulepart = '' ;
}
2019-02-04 17:52:15 +01:00
2006-07-02 02:43:40 +02:00
/*
2009-05-08 03:23:33 +02:00
* Phase authentication / login
2013-02-24 02:47:30 +01:00
*/
2019-11-13 19:37:08 +01:00
$login = '' ;
2021-02-23 20:26:57 +01:00
if ( ! defined ( 'NOLOGIN' )) {
2019-04-07 15:44:17 +02:00
// $authmode lists the different method of identification to be tested in order of preference.
2018-01-14 20:11:38 +01:00
// Example: 'http', 'dolibarr', 'ldap', 'http,forceuser', '...'
2017-10-16 08:47:05 +02:00
2021-02-23 20:26:57 +01:00
if ( defined ( 'MAIN_AUTHENTICATION_MODE' )) {
2018-01-14 20:11:38 +01:00
$dolibarr_main_authentication = constant ( 'MAIN_AUTHENTICATION_MODE' );
2020-05-21 01:03:03 +02:00
} else {
2018-01-14 20:11:38 +01:00
// Authentication mode
2021-02-23 20:26:57 +01:00
if ( empty ( $dolibarr_main_authentication )) {
$dolibarr_main_authentication = 'http,dolibarr' ;
}
2018-01-14 20:11:38 +01:00
// Authentication mode: forceuser
2021-02-23 20:26:57 +01:00
if ( $dolibarr_main_authentication == 'forceuser' && empty ( $dolibarr_auto_user )) {
$dolibarr_auto_user = 'auto' ;
}
2018-01-14 20:11:38 +01:00
}
2017-10-16 08:47:05 +02:00
// Set authmode
2019-11-13 19:37:08 +01:00
$authmode = explode ( ',' , $dolibarr_main_authentication );
2017-10-16 08:47:05 +02:00
// No authentication mode
2021-02-23 20:26:57 +01:00
if ( ! count ( $authmode )) {
2017-10-16 08:47:05 +02:00
$langs -> load ( 'main' );
2019-01-27 11:55:16 +01:00
dol_print_error ( '' , $langs -> trans ( " ErrorConfigParameterNotDefined " , 'dolibarr_main_authentication' ));
2017-10-16 08:47:05 +02:00
exit ;
}
2012-02-22 12:02:12 +01:00
2017-10-16 08:47:05 +02:00
// If login request was already post, we retrieve login from the session
// Call module if not realized that his request.
// At the end of this phase, the variable $login is defined.
2019-11-22 14:16:38 +01:00
$resultFetchUser = '' ;
$test = true ;
2021-02-23 20:26:57 +01:00
if ( ! isset ( $_SESSION [ " dol_login " ])) {
2017-10-16 08:47:05 +02:00
// It is not already authenticated and it requests the login / password
include_once DOL_DOCUMENT_ROOT . '/core/lib/security2.lib.php' ;
2019-11-22 14:16:38 +01:00
$dol_dst_observed = GETPOST ( " dst_observed " , 'int' , 3 );
$dol_dst_first = GETPOST ( " dst_first " , 'int' , 3 );
$dol_dst_second = GETPOST ( " dst_second " , 'int' , 3 );
$dol_screenwidth = GETPOST ( " screenwidth " , 'int' , 3 );
$dol_screenheight = GETPOST ( " screenheight " , 'int' , 3 );
$dol_hide_topmenu = GETPOST ( 'dol_hide_topmenu' , 'int' , 3 );
$dol_hide_leftmenu = GETPOST ( 'dol_hide_leftmenu' , 'int' , 3 );
$dol_optimize_smallscreen = GETPOST ( 'dol_optimize_smallscreen' , 'int' , 3 );
$dol_no_mouse_hover = GETPOST ( 'dol_no_mouse_hover' , 'int' , 3 );
$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
2017-10-16 08:47:05 +02:00
//dol_syslog("POST key=".join(array_keys($_POST),',').' value='.join($_POST,','));
// If in demo mode, we check we go to home page through the public/demo/index.php page
2021-02-23 20:26:57 +01:00
if ( ! empty ( $dolibarr_main_demo ) && $_SERVER [ 'PHP_SELF' ] == DOL_URL_ROOT . '/index.php' ) { // We ask index page
if ( empty ( $_SERVER [ 'HTTP_REFERER' ]) || ! preg_match ( '/public/' , $_SERVER [ 'HTTP_REFERER' ])) {
2017-10-16 08:47:05 +02:00
dol_syslog ( " Call index page from another url than demo page (call is done from page " . $_SERVER [ 'HTTP_REFERER' ] . " ) " );
2019-11-22 14:16:38 +01:00
$url = '' ;
$url .= ( $url ? '&' : '' ) . ( $dol_hide_topmenu ? 'dol_hide_topmenu=' . $dol_hide_topmenu : '' );
$url .= ( $url ? '&' : '' ) . ( $dol_hide_leftmenu ? 'dol_hide_leftmenu=' . $dol_hide_leftmenu : '' );
$url .= ( $url ? '&' : '' ) . ( $dol_optimize_smallscreen ? 'dol_optimize_smallscreen=' . $dol_optimize_smallscreen : '' );
$url .= ( $url ? '&' : '' ) . ( $dol_no_mouse_hover ? 'dol_no_mouse_hover=' . $dol_no_mouse_hover : '' );
$url .= ( $url ? '&' : '' ) . ( $dol_use_jmobile ? 'dol_use_jmobile=' . $dol_use_jmobile : '' );
$url = DOL_URL_ROOT . '/public/demo/index.php' . ( $url ? '?' . $url : '' );
2017-10-16 08:47:05 +02:00
header ( " Location: " . $url );
exit ;
}
}
2012-02-22 12:02:12 +01:00
2020-12-08 19:26:24 +01:00
// Hooks for security access
$action = '' ;
2020-12-08 19:30:40 +01:00
$hookmanager -> initHooks ( array ( 'login' ));
2020-12-09 08:36:52 +01:00
$parameters = array ();
$reshook = $hookmanager -> executeHooks ( 'beforeLoginAuthentication' , $parameters , $user , $action ); // Note that $action and $object may have been modified by some hooks
if ( $reshook < 0 ) {
2021-02-23 20:26:57 +01:00
$test = false ;
$error ++ ;
2020-12-09 08:36:52 +01:00
}
2020-12-08 19:26:24 +01:00
2017-10-16 08:47:05 +02:00
// Verification security graphic code
2021-02-23 20:26:57 +01:00
if ( $test && GETPOST ( " username " , " alpha " , 2 ) && ! empty ( $conf -> global -> MAIN_SECURITY_ENABLECAPTCHA ) && ! isset ( $_SESSION [ 'dol_bypass_antispam' ])) {
2017-10-16 08:47:05 +02:00
$sessionkey = 'dol_antispam_value' ;
2022-01-19 15:20:10 +01:00
$ok = ( array_key_exists ( $sessionkey , $_SESSION ) === true && ( strtolower ( $_SESSION [ $sessionkey ]) === strtolower ( GETPOST ( 'code' , 'restricthtml' ))));
2012-02-22 12:02:12 +01:00
2017-10-16 08:47:05 +02:00
// Check code
2021-02-23 20:26:57 +01:00
if ( ! $ok ) {
2017-10-16 08:47:05 +02:00
dol_syslog ( 'Bad value for code, connexion refused' );
2018-05-26 16:03:19 +02:00
// Load translation files required by page
2018-05-26 15:41:32 +02:00
$langs -> loadLangs ( array ( 'main' , 'errors' ));
2017-10-16 08:47:05 +02:00
2021-08-20 12:38:44 +02:00
$_SESSION [ " dol_loginmesg " ] = $langs -> transnoentitiesnoconv ( " ErrorBadValueForCode " );
2019-11-22 14:16:38 +01:00
$test = false ;
2017-10-16 08:47:05 +02:00
2018-12-10 11:19:52 +01:00
// Call trigger for the "security events" log
2019-11-22 14:16:38 +01:00
$user -> trigger_mesg = 'ErrorBadValueForCode - login=' . GETPOST ( " username " , " alpha " , 2 );
2020-04-02 12:03:29 +02:00
// Call trigger
$result = $user -> call_trigger ( 'USER_LOGIN_FAILED' , $user );
2021-02-23 20:26:57 +01:00
if ( $result < 0 ) {
$error ++ ;
}
2020-04-02 12:03:29 +02:00
// End call triggers
2018-12-10 17:50:58 +01:00
2017-10-16 08:47:05 +02:00
// Hooks on failed login
2019-11-22 14:16:38 +01:00
$action = '' ;
2017-10-16 08:47:05 +02:00
$hookmanager -> initHooks ( array ( 'login' ));
2021-06-26 12:00:25 +02:00
$parameters = array ( 'dol_authmode' => $authmode , 'dol_loginmesg' => $_SESSION [ " dol_loginmesg " ]);
2019-11-22 14:16:38 +01:00
$reshook = $hookmanager -> executeHooks ( 'afterLoginFailed' , $parameters , $user , $action ); // Note that $action and $object may have been modified by some hooks
2021-02-23 20:26:57 +01:00
if ( $reshook < 0 ) {
$error ++ ;
}
2017-10-16 08:47:05 +02:00
// Note: exit is done later
}
}
2013-02-24 02:47:30 +01:00
2018-03-16 01:52:07 +01:00
$allowedmethodtopostusername = 2 ;
2021-02-23 20:26:57 +01:00
if ( defined ( 'MAIN_AUTHENTICATION_POST_METHOD' )) {
$allowedmethodtopostusername = constant ( 'MAIN_AUTHENTICATION_POST_METHOD' );
}
2020-09-18 16:00:47 +02:00
$usertotest = ( ! empty ( $_COOKIE [ 'login_dolibarr' ]) ? preg_replace ( '/[^a-zA-Z0-9_\-]/' , '' , $_COOKIE [ 'login_dolibarr' ]) : GETPOST ( " username " , " alpha " , $allowedmethodtopostusername ));
2019-11-13 19:37:08 +01:00
$passwordtotest = GETPOST ( 'password' , 'none' , $allowedmethodtopostusername );
$entitytotest = ( GETPOST ( 'entity' , 'int' ) ? GETPOST ( 'entity' , 'int' ) : ( ! empty ( $conf -> entity ) ? $conf -> entity : 1 ));
2012-02-22 12:02:12 +01:00
2017-10-16 08:47:05 +02:00
// Define if we received data to test the login.
2019-11-13 19:37:08 +01:00
$goontestloop = false ;
2021-02-23 20:26:57 +01:00
if ( isset ( $_SERVER [ " REMOTE_USER " ]) && in_array ( 'http' , $authmode )) {
$goontestloop = true ;
}
if ( $dolibarr_main_authentication == 'forceuser' && ! empty ( $dolibarr_auto_user )) {
$goontestloop = true ;
}
if ( GETPOST ( " username " , " alpha " , $allowedmethodtopostusername ) || ! empty ( $_COOKIE [ 'login_dolibarr' ]) || GETPOST ( 'openid_mode' , 'alpha' , 1 )) {
$goontestloop = true ;
}
2015-06-27 21:52:23 +02:00
2021-02-23 20:26:57 +01:00
if ( ! is_object ( $langs )) { // This can occurs when calling page with NOREQUIRETRAN defined, however we need langs for error messages.
2017-10-16 08:47:05 +02:00
include_once DOL_DOCUMENT_ROOT . '/core/class/translate.class.php' ;
2019-11-13 19:37:08 +01:00
$langs = new Translate ( " " , $conf );
$langcode = ( GETPOST ( 'lang' , 'aZ09' , 1 ) ? GETPOST ( 'lang' , 'aZ09' , 1 ) : ( empty ( $conf -> global -> MAIN_LANG_DEFAULT ) ? 'auto' : $conf -> global -> MAIN_LANG_DEFAULT ));
2021-02-23 20:26:57 +01:00
if ( defined ( 'MAIN_LANG_DEFAULT' )) {
$langcode = constant ( 'MAIN_LANG_DEFAULT' );
}
2017-10-16 08:47:05 +02:00
$langs -> setDefaultLang ( $langcode );
}
2015-06-27 21:52:23 +02:00
2017-10-16 08:47:05 +02:00
// Validation of login/pass/entity
// If ok, the variable login will be returned
// If error, we will put error message in session under the name dol_loginmesg
2022-03-26 09:40:22 +01:00
// Note authmode is an array for example: array('0'=>'dolibarr', '1'=>'google');
2021-02-23 20:26:57 +01:00
if ( $test && $goontestloop && ( GETPOST ( 'actionlogin' , 'aZ09' ) == 'login' || $dolibarr_main_authentication != 'dolibarr' )) {
2019-01-27 11:55:16 +01:00
$login = checkLoginPassEntity ( $usertotest , $passwordtotest , $entitytotest , $authmode );
2020-09-22 14:45:19 +02:00
if ( $login === '--bad-login-validity--' ) {
$login = '' ;
}
2022-04-08 00:14:29 +02:00
$dol_authmode = '' ;
2021-02-23 20:26:57 +01:00
if ( $login ) {
2019-11-13 19:37:08 +01:00
$dol_authmode = $conf -> authmode ; // This properties is defined only when logged, to say what mode was successfully used
$dol_tz = $_POST [ " tz " ];
$dol_tz_string = $_POST [ " tz_string " ];
$dol_tz_string = preg_replace ( '/\s*\(.+\)$/' , '' , $dol_tz_string );
$dol_tz_string = preg_replace ( '/,/' , '/' , $dol_tz_string );
$dol_tz_string = preg_replace ( '/\s/' , '_' , $dol_tz_string );
$dol_dst = 0 ;
2020-02-16 19:33:58 +01:00
// Keep $_POST here. Do not use GETPOSTISSET
2021-02-23 20:26:57 +01:00
if ( isset ( $_POST [ " dst_first " ]) && isset ( $_POST [ " dst_second " ])) {
2017-10-16 08:47:05 +02:00
include_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php' ;
2019-11-13 19:37:08 +01:00
$datenow = dol_now ();
$datefirst = dol_stringtotime ( $_POST [ " dst_first " ]);
$datesecond = dol_stringtotime ( $_POST [ " dst_second " ]);
2021-02-23 20:26:57 +01:00
if ( $datenow >= $datefirst && $datenow < $datesecond ) {
$dol_dst = 1 ;
}
2017-10-16 08:47:05 +02:00
}
//print $datefirst.'-'.$datesecond.'-'.$datenow.'-'.$dol_tz.'-'.$dol_tzstring.'-'.$dol_dst; exit;
}
2021-02-23 20:26:57 +01:00
if ( ! $login ) {
2019-01-27 11:55:16 +01:00
dol_syslog ( 'Bad password, connexion refused' , LOG_DEBUG );
2018-05-26 16:03:19 +02:00
// Load translation files required by page
2018-05-26 15:41:32 +02:00
$langs -> loadLangs ( array ( 'main' , 'errors' ));
2017-10-16 08:47:05 +02:00
// Bad password. No authmode has found a good password.
// We set a generic message if not defined inside function checkLoginPassEntity or subfunctions
2021-02-23 20:26:57 +01:00
if ( empty ( $_SESSION [ " dol_loginmesg " ])) {
2021-08-20 12:38:44 +02:00
$_SESSION [ " dol_loginmesg " ] = $langs -> transnoentitiesnoconv ( " ErrorBadLoginPassword " );
2021-02-23 20:26:57 +01:00
}
2017-10-16 08:47:05 +02:00
2018-12-10 11:19:52 +01:00
// Call trigger for the "security events" log
2019-11-13 19:37:08 +01:00
$user -> trigger_mesg = $langs -> trans ( " ErrorBadLoginPassword " ) . ' - login=' . GETPOST ( " username " , " alpha " , 2 );
2020-04-02 12:03:29 +02:00
// Call trigger
$result = $user -> call_trigger ( 'USER_LOGIN_FAILED' , $user );
2021-02-23 20:26:57 +01:00
if ( $result < 0 ) {
$error ++ ;
}
2020-04-02 12:03:29 +02:00
// End call triggers
2018-12-10 11:19:52 +01:00
2017-10-16 08:47:05 +02:00
// Hooks on failed login
2019-11-13 19:37:08 +01:00
$action = '' ;
2017-10-16 08:47:05 +02:00
$hookmanager -> initHooks ( array ( 'login' ));
2019-11-13 19:37:08 +01:00
$parameters = array ( 'dol_authmode' => $dol_authmode , 'dol_loginmesg' => $_SESSION [ " dol_loginmesg " ]);
$reshook = $hookmanager -> executeHooks ( 'afterLoginFailed' , $parameters , $user , $action ); // Note that $action and $object may have been modified by some hooks
2021-02-23 20:26:57 +01:00
if ( $reshook < 0 ) {
$error ++ ;
}
2017-10-16 08:47:05 +02:00
// Note: exit is done in next chapter
}
}
2012-02-22 12:02:12 +01:00
2017-10-16 08:47:05 +02:00
// End test login / passwords
2021-02-23 20:26:57 +01:00
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.
2021-02-26 11:29:16 +01:00
// No data to test login, so we show the login page.
2022-09-28 19:03:01 +02:00
dol_syslog ( " --- Access to " . ( empty ( $_SERVER [ " REQUEST_METHOD " ]) ? '' : $_SERVER [ " REQUEST_METHOD " ] . ' ' ) . $_SERVER [ " PHP_SELF " ] . " - action= " . GETPOST ( 'action' , 'aZ09' ) . " - actionlogin= " . GETPOST ( 'actionlogin' , 'aZ09' ) . " - showing the login form and exit " , LOG_NOTICE );
2021-02-23 20:26:57 +01:00
if ( defined ( 'NOREDIRECTBYMAINTOLOGIN' )) {
2022-09-09 13:58:54 +02:00
// When used with NOREDIRECTBYMAINTOLOGIN set, the http header must already be set when including the main.
// See example with selectsearchbox.php. This case is reserverd for the selectesearchbox.php so we can
// report a message to ask to login when search ajax component is used after a timeout.
//top_httphead();
2021-02-23 20:26:57 +01:00
return 'ERROR_NOT_LOGGED' ;
} else {
2020-09-24 13:00:56 +02:00
if ( $_SERVER [ " HTTP_USER_AGENT " ] == 'securitytest' ) {
2020-10-27 19:46:07 +01:00
http_response_code ( 401 ); // It makes easier to understand if session was broken during security tests
2020-09-24 13:00:56 +02:00
}
2022-09-09 13:58:54 +02:00
dol_loginfunction ( $langs , $conf , ( ! empty ( $mysoc ) ? $mysoc : '' )); // This include http headers
2020-09-24 13:00:56 +02:00
}
2017-10-16 08:47:05 +02:00
exit ;
}
2012-02-22 12:02:12 +01:00
2023-01-27 14:06:31 +01:00
$resultFetchUser = $user -> fetch ( '' , $login , '' , 1 , ( $entitytotest > 0 ? $entitytotest : - 1 )); // value for $login was retrieved previously when checking password.
if ( $resultFetchUser <= 0 || $user -> isNotIntoValidityDateRange ()) {
2017-10-16 08:47:05 +02:00
dol_syslog ( 'User not found, connexion refused' );
session_destroy ();
2020-03-22 01:59:32 +01:00
session_set_cookie_params ( 0 , '/' , null , ( empty ( $dolibarr_main_force_https ) ? false : true ), true ); // Add tag secure and httponly on session cookie
2020-04-06 11:16:35 +02:00
session_name ( $sessionname );
2019-08-14 15:30:03 +02:00
session_start ();
2016-03-18 10:56:55 +01:00
2021-02-23 20:26:57 +01:00
if ( $resultFetchUser == 0 ) {
2018-05-26 16:03:19 +02:00
// Load translation files required by page
2018-05-26 15:41:32 +02:00
$langs -> loadLangs ( array ( 'main' , 'errors' ));
2016-03-18 10:56:55 +01:00
2021-08-20 12:38:44 +02:00
$_SESSION [ " dol_loginmesg " ] = $langs -> transnoentitiesnoconv ( " ErrorCantLoadUserFromDolibarrDatabase " , $login );
2018-12-10 17:50:58 +01:00
2019-11-22 14:16:38 +01:00
$user -> trigger_mesg = 'ErrorCantLoadUserFromDolibarrDatabase - login=' . $login ;
2023-01-27 14:06:31 +01:00
} elseif ( $resultFetchUser < 0 ) {
2019-11-22 14:16:38 +01:00
$_SESSION [ " dol_loginmesg " ] = $user -> error ;
2018-12-10 17:50:58 +01:00
2019-11-22 14:16:38 +01:00
$user -> trigger_mesg = $user -> error ;
2023-01-27 14:06:31 +01:00
} else {
// Load translation files required by the page
$langs -> loadLangs ( array ( 'main' , 'errors' ));
$_SESSION [ " dol_loginmesg " ] = $langs -> transnoentitiesnoconv ( " ErrorLoginDateValidity " );
$user -> trigger_mesg = $langs -> trans ( " ErrorLoginDateValidity " ) . ' - login=' . $login ;
2017-10-16 08:47:05 +02:00
}
2020-04-02 12:03:29 +02:00
// Call trigger
$result = $user -> call_trigger ( 'USER_LOGIN_FAILED' , $user );
2021-02-23 20:26:57 +01:00
if ( $result < 0 ) {
$error ++ ;
}
2018-12-10 11:19:52 +01:00
// End call triggers
2018-12-10 17:50:58 +01:00
2020-04-02 12:03:29 +02:00
2017-10-16 08:47:05 +02:00
// Hooks on failed login
2019-11-22 14:16:38 +01:00
$action = '' ;
2017-10-16 08:47:05 +02:00
$hookmanager -> initHooks ( array ( 'login' ));
2019-11-22 14:16:38 +01:00
$parameters = array ( 'dol_authmode' => $dol_authmode , 'dol_loginmesg' => $_SESSION [ " dol_loginmesg " ]);
$reshook = $hookmanager -> executeHooks ( 'afterLoginFailed' , $parameters , $user , $action ); // Note that $action and $object may have been modified by some hooks
2021-02-23 20:26:57 +01:00
if ( $reshook < 0 ) {
$error ++ ;
}
2017-10-16 08:47:05 +02:00
2019-11-22 14:16:38 +01:00
$paramsurl = array ();
2021-02-23 20:26:57 +01:00
if ( GETPOST ( 'textbrowser' , 'int' )) {
$paramsurl [] = 'textbrowser=' . GETPOST ( 'textbrowser' , 'int' );
}
if ( GETPOST ( 'nojs' , 'int' )) {
$paramsurl [] = 'nojs=' . GETPOST ( 'nojs' , 'int' );
}
if ( GETPOST ( 'lang' , 'aZ09' )) {
$paramsurl [] = 'lang=' . GETPOST ( 'lang' , 'aZ09' );
}
2019-11-22 14:16:38 +01:00
header ( 'Location: ' . DOL_URL_ROOT . '/index.php' . ( count ( $paramsurl ) ? '?' . implode ( '&' , $paramsurl ) : '' ));
2017-10-16 08:47:05 +02:00
exit ;
2020-08-07 14:05:05 +02:00
} else {
// User is loaded, we may need to change language for him according to its choice
2020-09-07 10:18:17 +02:00
if ( ! empty ( $user -> conf -> MAIN_LANG_DEFAULT )) {
2020-08-07 14:05:05 +02:00
$langs -> setDefaultLang ( $user -> conf -> MAIN_LANG_DEFAULT );
}
2017-10-16 08:47:05 +02:00
}
2020-05-21 01:03:03 +02:00
} else {
2017-10-16 08:47:05 +02:00
// We are already into an authenticated session
2019-11-22 14:16:38 +01:00
$login = $_SESSION [ " dol_login " ];
2021-03-14 17:58:05 +01:00
$entity = isset ( $_SESSION [ " dol_entity " ]) ? $_SESSION [ " dol_entity " ] : 0 ;
2017-10-16 08:47:05 +02:00
dol_syslog ( " - This is an already logged session. _SESSION['dol_login']= " . $login . " _SESSION['dol_entity']= " . $entity , LOG_DEBUG );
2012-02-22 12:02:12 +01:00
2019-11-22 14:16:38 +01:00
$resultFetchUser = $user -> fetch ( '' , $login , '' , 1 , ( $entity > 0 ? $entity : - 1 ));
2023-01-27 14:06:31 +01:00
if ( $resultFetchUser <= 0
|| ( $user -> flagdelsessionsbefore && ! empty ( $_SESSION [ " dol_logindate " ]) && $user -> flagdelsessionsbefore > $_SESSION [ " dol_logindate " ])
|| ( $user -> isNotIntoValidtyDateRange ())) {
2023-01-16 11:48:34 +01:00
if ( $resultFetchUser <= 0 ) {
// Account has been removed after login
dol_syslog ( " Can't load user even if session logged. _SESSION['dol_login']= " . $login , LOG_WARNING );
2023-01-27 14:06:31 +01:00
} elseif ( $user -> flagdelsessionsbefore && ! empty ( $_SESSION [ " dol_logindate " ]) && $user -> flagdelsessionsbefore > $_SESSION [ " dol_logindate " ]) {
2023-01-16 11:48:34 +01:00
// Session is no more valid
dol_syslog ( " The user has a date for session invalidation = " . $user -> flagdelsessionsbefore . " and a session date = " . $_SESSION [ " dol_logindate " ] . " . We must invalidate its sessions. " );
2023-01-27 14:06:31 +01:00
} else {
// User validity dates are no more valid
dol_syslog ( " The user login has a validity between [ " . $user -> datestartvalidity . " and " . $user -> dateendvalidity . " ], curren date is " . dol_now ());
2023-01-16 11:48:34 +01:00
}
2017-10-16 08:47:05 +02:00
session_destroy ();
2020-03-22 01:59:32 +01:00
session_set_cookie_params ( 0 , '/' , null , ( empty ( $dolibarr_main_force_https ) ? false : true ), true ); // Add tag secure and httponly on session cookie
2020-04-06 11:16:35 +02:00
session_name ( $sessionname );
2019-08-14 15:30:03 +02:00
session_start ();
2017-10-16 08:47:05 +02:00
2021-02-23 20:26:57 +01:00
if ( $resultFetchUser == 0 ) {
2018-05-26 15:41:32 +02:00
$langs -> loadLangs ( array ( 'main' , 'errors' ));
2016-03-18 10:56:55 +01:00
2021-08-20 12:38:44 +02:00
$_SESSION [ " dol_loginmesg " ] = $langs -> transnoentitiesnoconv ( " ErrorCantLoadUserFromDolibarrDatabase " , $login );
2018-12-10 11:19:52 +01:00
2019-11-22 14:16:38 +01:00
$user -> trigger_mesg = 'ErrorCantLoadUserFromDolibarrDatabase - login=' . $login ;
2023-01-16 11:48:34 +01:00
} elseif ( $resultFetchUser < 0 ) {
2019-11-22 14:16:38 +01:00
$_SESSION [ " dol_loginmesg " ] = $user -> error ;
2018-12-10 17:50:58 +01:00
2019-11-22 14:16:38 +01:00
$user -> trigger_mesg = $user -> error ;
2023-01-16 11:48:34 +01:00
} else {
$langs -> loadLangs ( array ( 'main' , 'errors' ));
$_SESSION [ " dol_loginmesg " ] = $langs -> transnoentitiesnoconv ( " ErrorSessionInvalidatedAfterPasswordChange " );
$user -> trigger_mesg = 'ErrorUserSessionWasInvalidated - login=' . $login ;
2017-10-16 08:47:05 +02:00
}
2020-04-02 12:03:29 +02:00
// Call trigger
$result = $user -> call_trigger ( 'USER_LOGIN_FAILED' , $user );
2021-02-23 20:26:57 +01:00
if ( $result < 0 ) {
$error ++ ;
}
2018-12-10 11:19:52 +01:00
// End call triggers
2018-12-10 17:50:58 +01:00
2017-10-16 08:47:05 +02:00
// Hooks on failed login
2019-11-22 14:16:38 +01:00
$action = '' ;
2017-10-16 08:47:05 +02:00
$hookmanager -> initHooks ( array ( 'login' ));
2023-01-16 12:33:54 +01:00
$parameters = array ( 'dol_authmode' => ( isset ( $dol_authmode ) ? $dol_authmode : '' ), 'dol_loginmesg' => $_SESSION [ " dol_loginmesg " ]);
2019-11-22 14:16:38 +01:00
$reshook = $hookmanager -> executeHooks ( 'afterLoginFailed' , $parameters , $user , $action ); // Note that $action and $object may have been modified by some hooks
2021-02-23 20:26:57 +01:00
if ( $reshook < 0 ) {
$error ++ ;
}
2017-10-16 08:47:05 +02:00
2019-11-22 14:16:38 +01:00
$paramsurl = array ();
2021-02-23 20:26:57 +01:00
if ( GETPOST ( 'textbrowser' , 'int' )) {
$paramsurl [] = 'textbrowser=' . GETPOST ( 'textbrowser' , 'int' );
}
if ( GETPOST ( 'nojs' , 'int' )) {
$paramsurl [] = 'nojs=' . GETPOST ( 'nojs' , 'int' );
}
if ( GETPOST ( 'lang' , 'aZ09' )) {
$paramsurl [] = 'lang=' . GETPOST ( 'lang' , 'aZ09' );
}
2019-11-22 14:16:38 +01:00
header ( 'Location: ' . DOL_URL_ROOT . '/index.php' . ( count ( $paramsurl ) ? '?' . implode ( '&' , $paramsurl ) : '' ));
2017-10-16 08:47:05 +02:00
exit ;
2020-05-21 01:03:03 +02:00
} else {
2020-10-27 19:46:07 +01:00
// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
$hookmanager -> initHooks ( array ( 'main' ));
// Code for search criteria persistence.
2022-12-22 12:27:32 +01:00
if ( ! empty ( $_GET [ 'save_lastsearch_values' ]) && ! empty ( $_SERVER [ " HTTP_REFERER " ])) { // We must use $_GET here
2020-10-27 19:46:07 +01:00
$relativepathstring = preg_replace ( '/\?.*$/' , '' , $_SERVER [ " HTTP_REFERER " ]);
$relativepathstring = preg_replace ( '/^https?:\/\/[^\/]*/' , '' , $relativepathstring ); // Get full path except host server
// Clean $relativepathstring
2021-02-23 20:26:57 +01:00
if ( constant ( 'DOL_URL_ROOT' )) {
$relativepathstring = preg_replace ( '/^' . preg_quote ( constant ( 'DOL_URL_ROOT' ), '/' ) . '/' , '' , $relativepathstring );
}
2020-10-27 19:46:07 +01:00
$relativepathstring = preg_replace ( '/^\//' , '' , $relativepathstring );
$relativepathstring = preg_replace ( '/^custom\//' , '' , $relativepathstring );
//var_dump($relativepathstring);
2022-02-09 15:21:25 +01:00
// 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
2021-02-23 20:26:57 +01:00
if ( ! empty ( $_SESSION [ 'lastsearch_values_tmp_' . $relativepathstring ])) {
2020-10-27 19:46:07 +01:00
$_SESSION [ 'lastsearch_values_' . $relativepathstring ] = $_SESSION [ 'lastsearch_values_tmp_' . $relativepathstring ];
unset ( $_SESSION [ 'lastsearch_values_tmp_' . $relativepathstring ]);
}
2021-02-23 20:26:57 +01:00
if ( ! empty ( $_SESSION [ 'lastsearch_contextpage_tmp_' . $relativepathstring ])) {
2020-10-27 19:46:07 +01:00
$_SESSION [ 'lastsearch_contextpage_' . $relativepathstring ] = $_SESSION [ 'lastsearch_contextpage_tmp_' . $relativepathstring ];
unset ( $_SESSION [ 'lastsearch_contextpage_tmp_' . $relativepathstring ]);
}
2022-02-09 15:21:25 +01:00
if ( ! empty ( $_SESSION [ 'lastsearch_limit_tmp_' . $relativepathstring ]) && $_SESSION [ 'lastsearch_limit_tmp_' . $relativepathstring ] != $conf -> liste_limit ) {
$_SESSION [ 'lastsearch_limit_' . $relativepathstring ] = $_SESSION [ 'lastsearch_limit_tmp_' . $relativepathstring ];
unset ( $_SESSION [ 'lastsearch_limit_tmp_' . $relativepathstring ]);
}
2021-02-23 20:26:57 +01:00
if ( ! empty ( $_SESSION [ 'lastsearch_page_tmp_' . $relativepathstring ]) && $_SESSION [ 'lastsearch_page_tmp_' . $relativepathstring ] > 0 ) {
2020-10-27 19:46:07 +01:00
$_SESSION [ 'lastsearch_page_' . $relativepathstring ] = $_SESSION [ 'lastsearch_page_tmp_' . $relativepathstring ];
unset ( $_SESSION [ 'lastsearch_page_tmp_' . $relativepathstring ]);
}
2022-02-09 15:21:25 +01:00
if ( ! empty ( $_SESSION [ 'lastsearch_mode_tmp_' . $relativepathstring ])) {
$_SESSION [ 'lastsearch_mode_' . $relativepathstring ] = $_SESSION [ 'lastsearch_mode_tmp_' . $relativepathstring ];
unset ( $_SESSION [ 'lastsearch_mode_tmp_' . $relativepathstring ]);
2020-10-27 19:46:07 +01:00
}
}
$action = '' ;
$reshook = $hookmanager -> executeHooks ( 'updateSession' , array (), $user , $action );
if ( $reshook < 0 ) {
setEventMessages ( $hookmanager -> error , $hookmanager -> errors , 'errors' );
}
2017-10-16 08:47:05 +02:00
}
}
2017-06-10 16:29:25 +02:00
2017-10-16 08:47:05 +02:00
// Is it a new session that has started ?
// If we are here, this means authentication was successfull.
2021-02-23 20:26:57 +01:00
if ( ! isset ( $_SESSION [ " dol_login " ])) {
2017-10-16 08:47:05 +02:00
// New session for this login has started.
2019-11-13 19:37:08 +01:00
$error = 0 ;
2017-10-16 08:47:05 +02:00
// Store value into session (values always stored)
2019-11-13 19:37:08 +01:00
$_SESSION [ " dol_login " ] = $user -> login ;
2023-01-14 21:21:48 +01:00
$_SESSION [ " dol_logindate " ] = dol_now ( 'gmt' );
2019-11-13 19:37:08 +01:00
$_SESSION [ " dol_authmode " ] = isset ( $dol_authmode ) ? $dol_authmode : '' ;
$_SESSION [ " dol_tz " ] = isset ( $dol_tz ) ? $dol_tz : '' ;
$_SESSION [ " dol_tz_string " ] = isset ( $dol_tz_string ) ? $dol_tz_string : '' ;
$_SESSION [ " dol_dst " ] = isset ( $dol_dst ) ? $dol_dst : '' ;
$_SESSION [ " dol_dst_observed " ] = isset ( $dol_dst_observed ) ? $dol_dst_observed : '' ;
$_SESSION [ " dol_dst_first " ] = isset ( $dol_dst_first ) ? $dol_dst_first : '' ;
$_SESSION [ " dol_dst_second " ] = isset ( $dol_dst_second ) ? $dol_dst_second : '' ;
$_SESSION [ " dol_screenwidth " ] = isset ( $dol_screenwidth ) ? $dol_screenwidth : '' ;
$_SESSION [ " dol_screenheight " ] = isset ( $dol_screenheight ) ? $dol_screenheight : '' ;
2021-05-17 18:39:08 +02:00
$_SESSION [ " dol_company " ] = getDolGlobalString ( " MAIN_INFO_SOCIETE_NOM " );
2019-11-13 19:37:08 +01:00
$_SESSION [ " dol_entity " ] = $conf -> entity ;
2017-10-16 08:47:05 +02:00
// Store value into session (values stored only if defined)
2021-02-23 20:26:57 +01:00
if ( ! empty ( $dol_hide_topmenu )) {
$_SESSION [ 'dol_hide_topmenu' ] = $dol_hide_topmenu ;
}
if ( ! empty ( $dol_hide_leftmenu )) {
$_SESSION [ 'dol_hide_leftmenu' ] = $dol_hide_leftmenu ;
}
if ( ! empty ( $dol_optimize_smallscreen )) {
$_SESSION [ 'dol_optimize_smallscreen' ] = $dol_optimize_smallscreen ;
}
if ( ! empty ( $dol_no_mouse_hover )) {
$_SESSION [ 'dol_no_mouse_hover' ] = $dol_no_mouse_hover ;
}
if ( ! empty ( $dol_use_jmobile )) {
$_SESSION [ 'dol_use_jmobile' ] = $dol_use_jmobile ;
}
2017-10-16 08:47:05 +02:00
dol_syslog ( " This is a new started user session. _SESSION['dol_login']= " . $_SESSION [ " dol_login " ] . " Session id= " . session_id ());
$db -> begin ();
$user -> update_last_login_date ();
$loginfo = 'TZ=' . $_SESSION [ " dol_tz " ] . ';TZString=' . $_SESSION [ " dol_tz_string " ] . ';Screen=' . $_SESSION [ " dol_screenwidth " ] . 'x' . $_SESSION [ " dol_screenheight " ];
2018-12-10 11:19:52 +01:00
// Call triggers for the "security events" log
$user -> trigger_mesg = $loginfo ;
2020-04-02 12:03:29 +02:00
// Call trigger
$result = $user -> call_trigger ( 'USER_LOGIN' , $user );
2021-02-23 20:26:57 +01:00
if ( $result < 0 ) {
$error ++ ;
}
2018-12-10 11:19:52 +01:00
// End call triggers
2018-12-10 17:50:58 +01:00
2017-10-16 08:47:05 +02:00
// Hooks on successfull login
2019-11-13 19:37:08 +01:00
$action = '' ;
2017-10-16 08:47:05 +02:00
$hookmanager -> initHooks ( array ( 'login' ));
2019-11-13 19:37:08 +01:00
$parameters = array ( 'dol_authmode' => $dol_authmode , 'dol_loginfo' => $loginfo );
$reshook = $hookmanager -> executeHooks ( 'afterLogin' , $parameters , $user , $action ); // Note that $action and $object may have been modified by some hooks
2021-02-23 20:26:57 +01:00
if ( $reshook < 0 ) {
$error ++ ;
}
2015-06-27 21:52:23 +02:00
2021-02-23 20:26:57 +01:00
if ( $error ) {
2017-10-16 08:47:05 +02:00
$db -> rollback ();
session_destroy ();
2019-01-27 11:55:16 +01:00
dol_print_error ( $db , 'Error in some triggers USER_LOGIN or in some hooks afterLogin' );
2017-10-16 08:47:05 +02:00
exit ;
2020-05-21 01:03:03 +02:00
} else {
2017-10-16 08:47:05 +02:00
$db -> commit ();
}
2016-01-24 17:40:07 +01:00
2017-10-16 08:47:05 +02:00
// Change landing page if defined.
2019-11-13 19:37:08 +01:00
$landingpage = ( empty ( $user -> conf -> MAIN_LANDING_PAGE ) ? ( empty ( $conf -> global -> MAIN_LANDING_PAGE ) ? '' : $conf -> global -> MAIN_LANDING_PAGE ) : $user -> conf -> MAIN_LANDING_PAGE );
2021-02-23 20:26:57 +01:00
if ( ! empty ( $landingpage )) { // Example: /index.php
2019-11-13 19:37:08 +01:00
$newpath = dol_buildpath ( $landingpage , 1 );
2021-02-23 20:26:57 +01:00
if ( $_SERVER [ " PHP_SELF " ] != $newpath ) { // not already on landing page (avoid infinite loop)
2017-10-16 08:47:05 +02:00
header ( 'Location: ' . $newpath );
exit ;
}
}
}
2012-02-22 12:02:12 +01:00
2017-10-16 08:47:05 +02:00
// If user admin, we force the rights-based modules
2021-02-23 20:26:57 +01:00
if ( $user -> admin ) {
2019-11-13 19:37:08 +01:00
$user -> rights -> user -> user -> lire = 1 ;
$user -> rights -> user -> user -> creer = 1 ;
$user -> rights -> user -> user -> password = 1 ;
$user -> rights -> user -> user -> supprimer = 1 ;
$user -> rights -> user -> self -> creer = 1 ;
$user -> rights -> user -> self -> password = 1 ;
2021-09-19 22:32:07 +02:00
2021-09-19 22:26:49 +02:00
//Required if advanced permissions are used with MAIN_USE_ADVANCED_PERMS
2021-09-20 12:24:44 +02:00
if ( ! empty ( $conf -> global -> MAIN_USE_ADVANCED_PERMS )) {
2021-09-21 00:50:48 +02:00
if ( empty ( $user -> rights -> user -> user_advance )) {
$user -> rights -> user -> user_advance = new stdClass (); // To avoid warnings
}
2021-09-21 00:53:10 +02:00
if ( empty ( $user -> rights -> user -> self_advance )) {
2021-09-21 00:50:48 +02:00
$user -> rights -> user -> self_advance = new stdClass (); // To avoid warnings
}
2021-09-21 00:53:10 +02:00
if ( empty ( $user -> rights -> user -> group_advance )) {
2021-09-21 00:50:48 +02:00
$user -> rights -> user -> group_advance = new stdClass (); // To avoid warnings
}
2021-09-20 12:24:44 +02:00
$user -> rights -> user -> user_advance -> readperms = 1 ;
$user -> rights -> user -> user_advance -> write = 1 ;
$user -> rights -> user -> self_advance -> readperms = 1 ;
$user -> rights -> user -> self_advance -> writeperms = 1 ;
$user -> rights -> user -> group_advance -> read = 1 ;
$user -> rights -> user -> group_advance -> readperms = 1 ;
$user -> rights -> user -> group_advance -> write = 1 ;
$user -> rights -> user -> group_advance -> delete = 1 ;
}
2017-10-16 08:47:05 +02:00
}
2012-02-22 12:02:12 +01:00
2017-10-16 08:47:05 +02:00
/*
2021-02-23 20:26:57 +01:00
* Overwrite some configs globals ( try to avoid this and have code to use instead $user -> conf -> xxx )
*/
2013-04-03 15:20:56 +02:00
2017-10-16 08:47:05 +02:00
// Set liste_limit
2021-02-23 20:26:57 +01:00
if ( isset ( $user -> conf -> MAIN_SIZE_LISTE_LIMIT )) {
$conf -> liste_limit = $user -> conf -> MAIN_SIZE_LISTE_LIMIT ; // Can be 0
}
if ( isset ( $user -> conf -> PRODUIT_LIMIT_SIZE )) {
$conf -> product -> limit_size = $user -> conf -> PRODUIT_LIMIT_SIZE ; // Can be 0
}
2013-04-03 15:20:56 +02:00
2017-10-16 08:47:05 +02:00
// Replace conf->css by personalized value if theme not forced
2021-02-23 20:26:57 +01:00
if ( empty ( $conf -> global -> MAIN_FORCETHEME ) && ! empty ( $user -> conf -> MAIN_THEME )) {
2019-11-13 19:37:08 +01:00
$conf -> theme = $user -> conf -> MAIN_THEME ;
2019-11-22 14:16:38 +01:00
$conf -> css = " /theme/ " . $conf -> theme . " /style.css.php " ;
2017-10-16 08:47:05 +02:00
}
2022-09-01 10:54:20 +02:00
} else {
// We may have NOLOGIN set, but NOREQUIREUSER not
if ( ! empty ( $user ) && method_exists ( $user , 'loadDefaultValues' )) {
$user -> loadDefaultValues (); // Load default values for everybody (works even if $user->id = 0
}
2013-04-03 15:20:56 +02:00
}
2012-02-22 12:02:12 +01:00
2021-12-12 21:20:12 +01:00
2013-04-03 15:20:56 +02:00
// Case forcing style from url
2022-01-30 17:24:10 +01:00
if ( GETPOST ( 'theme' , 'aZ09' )) {
$conf -> theme = GETPOST ( 'theme' , 'aZ09' , 1 );
2019-11-28 12:36:20 +01:00
$conf -> css = " /theme/ " . $conf -> theme . " /style.css.php " ;
2013-04-03 15:20:56 +02:00
}
2013-06-24 17:36:33 +02:00
2013-06-05 16:24:32 +02:00
// Set javascript option
2020-08-02 00:41:26 +02:00
if ( GETPOST ( 'nojs' , 'int' )) { // If javascript was not disabled on URL
$conf -> use_javascript_ajax = 0 ;
} else {
if ( ! empty ( $user -> conf -> MAIN_DISABLE_JAVASCRIPT )) {
2019-11-22 14:16:38 +01:00
$conf -> use_javascript_ajax = ! $user -> conf -> MAIN_DISABLE_JAVASCRIPT ;
2013-06-05 16:24:32 +02:00
}
2020-08-02 00:41:26 +02:00
}
2020-06-10 12:35:39 +02:00
// Set MAIN_OPTIMIZEFORTEXTBROWSER for user (must be after login part)
if ( empty ( $conf -> global -> MAIN_OPTIMIZEFORTEXTBROWSER ) && ! empty ( $user -> conf -> MAIN_OPTIMIZEFORTEXTBROWSER )) {
2019-11-22 14:16:38 +01:00
$conf -> global -> MAIN_OPTIMIZEFORTEXTBROWSER = $user -> conf -> MAIN_OPTIMIZEFORTEXTBROWSER ;
2017-10-17 14:03:22 +02:00
}
2013-04-03 15:20:56 +02:00
2020-06-10 12:35:39 +02:00
// set MAIN_OPTIMIZEFORCOLORBLIND for user
2020-10-30 04:13:31 +01:00
$conf -> global -> MAIN_OPTIMIZEFORCOLORBLIND = empty ( $user -> conf -> MAIN_OPTIMIZEFORCOLORBLIND ) ? '' : $user -> conf -> MAIN_OPTIMIZEFORCOLORBLIND ;
2019-08-07 12:15:55 +02:00
2014-10-19 19:57:42 +02:00
// Set terminal output option according to conf->browser.
2021-02-23 20:26:57 +01:00
if ( GETPOST ( 'dol_hide_leftmenu' , 'int' ) || ! empty ( $_SESSION [ 'dol_hide_leftmenu' ])) {
$conf -> dol_hide_leftmenu = 1 ;
}
if ( GETPOST ( 'dol_hide_topmenu' , 'int' ) || ! empty ( $_SESSION [ 'dol_hide_topmenu' ])) {
$conf -> dol_hide_topmenu = 1 ;
}
if ( GETPOST ( 'dol_optimize_smallscreen' , 'int' ) || ! empty ( $_SESSION [ 'dol_optimize_smallscreen' ])) {
$conf -> dol_optimize_smallscreen = 1 ;
}
if ( GETPOST ( 'dol_no_mouse_hover' , 'int' ) || ! empty ( $_SESSION [ 'dol_no_mouse_hover' ])) {
$conf -> dol_no_mouse_hover = 1 ;
}
if ( GETPOST ( 'dol_use_jmobile' , 'int' ) || ! empty ( $_SESSION [ 'dol_use_jmobile' ])) {
$conf -> dol_use_jmobile = 1 ;
}
2022-10-21 11:14:28 +02:00
// If not on Desktop
2021-02-23 20:26:57 +01:00
if ( ! empty ( $conf -> browser -> layout ) && $conf -> browser -> layout != 'classic' ) {
$conf -> dol_no_mouse_hover = 1 ;
}
2022-10-21 11:14:28 +02:00
// If on smartphone or optmized for small screen
2019-11-22 14:16:38 +01:00
if (( ! empty ( $conf -> browser -> layout ) && $conf -> browser -> layout == 'phone' )
|| ( ! empty ( $_SESSION [ 'dol_screenwidth' ]) && $_SESSION [ 'dol_screenwidth' ] < 400 )
2022-10-21 11:14:28 +02:00
|| ( ! empty ( $_SESSION [ 'dol_screenheight' ]) && $_SESSION [ 'dol_screenheight' ] < 400
|| ! empty ( $conf -> global -> MAIN_OPTIMIZEFORTEXTBROWSER ))
2021-02-23 20:26:57 +01:00
) {
2019-11-22 14:16:38 +01:00
$conf -> dol_optimize_smallscreen = 1 ;
2022-10-21 11:14:28 +02:00
if ( isset ( $conf -> global -> PRODUIT_DESC_IN_FORM ) && $conf -> global -> PRODUIT_DESC_IN_FORM == 1 ) {
$conf -> global -> PRODUIT_DESC_IN_FORM_ACCORDING_TO_DEVICE = 0 ;
}
2007-10-02 15:54:34 +02:00
}
2014-10-19 19:57:42 +02:00
// Replace themes bugged with jmobile with eldy
2021-02-23 20:26:57 +01:00
if ( ! empty ( $conf -> dol_use_jmobile ) && in_array ( $conf -> theme , array ( 'bureau2crea' , 'cameleo' , 'amarok' ))) {
2019-11-22 14:16:38 +01:00
$conf -> theme = 'eldy' ;
2019-11-28 12:36:20 +01:00
$conf -> css = " /theme/ " . $conf -> theme . " /style.css.php " ;
2013-06-20 16:13:42 +02:00
}
2021-02-23 20:26:57 +01:00
if ( ! defined ( 'NOREQUIRETRAN' )) {
if ( ! GETPOST ( 'lang' , 'aZ09' )) { // If language was not forced on URL
2021-02-26 11:29:16 +01:00
// If user has chosen its own language
2021-02-23 20:26:57 +01:00
if ( ! empty ( $user -> conf -> MAIN_LANG_DEFAULT )) {
2017-10-16 08:47:05 +02:00
// If different than current language
//print ">>>".$langs->getDefaultLang()."-".$user->conf->MAIN_LANG_DEFAULT;
2021-02-23 20:26:57 +01:00
if ( $langs -> getDefaultLang () != $user -> conf -> MAIN_LANG_DEFAULT ) {
2017-10-16 08:47:05 +02:00
$langs -> setDefaultLang ( $user -> conf -> MAIN_LANG_DEFAULT );
}
}
}
2005-08-11 22:04:33 +02:00
}
2005-10-02 22:38:46 +02:00
2021-02-23 20:26:57 +01:00
if ( ! defined ( 'NOLOGIN' )) {
2017-10-16 08:47:05 +02:00
// If the login is not recovered, it is identified with an account that does not exist.
// Hacking attempt?
2021-02-23 20:26:57 +01:00
if ( ! $user -> login ) {
accessforbidden ();
}
2017-10-16 08:47:05 +02:00
// Check if user is active
2021-02-23 20:26:57 +01:00
if ( $user -> statut < 1 ) {
2017-10-16 08:47:05 +02:00
// If not active, we refuse the user
2021-12-10 12:36:51 +01:00
$langs -> loadLangs ( array ( " errors " , " other " ));
2020-02-02 15:57:41 +01:00
dol_syslog ( " Authentication KO as login is disabled " , LOG_NOTICE );
2022-09-09 13:58:54 +02:00
accessforbidden ( " ErrorLoginDisabled " );
2017-10-16 08:47:05 +02:00
}
2012-02-22 12:02:12 +01:00
2017-10-16 08:47:05 +02:00
// Load permissions
$user -> getrights ();
2006-09-02 03:17:50 +02:00
}
2009-01-21 14:06:34 +01:00
2021-10-23 22:22:10 +02:00
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 );
2009-08-29 00:46:40 +02:00
//Another call for easy debugg
2021-03-19 12:08:40 +01:00
//dol_syslog("Access to ".$_SERVER["PHP_SELF"].' '.$_SERVER["HTTP_REFERER"].' GET='.join(',',array_keys($_GET)).'->'.join(',',$_GET).' POST:'.join(',',array_keys($_POST)).'->'.join(',',$_POST));
2005-08-11 22:04:33 +02:00
2010-02-28 15:16:46 +01:00
// Load main languages files
2021-02-23 20:26:57 +01:00
if ( ! defined ( 'NOREQUIRETRAN' )) {
2018-05-26 16:03:19 +02:00
// Load translation files required by page
2018-05-26 15:41:32 +02:00
$langs -> loadLangs ( array ( 'main' , 'dict' ));
2010-02-28 15:16:46 +01:00
}
2003-03-11 17:25:07 +01:00
2008-04-09 20:13:45 +02:00
// Define some constants used for style of arrays
2019-11-13 19:37:08 +01:00
$bc = array ( 0 => 'class="impair"' , 1 => 'class="pair"' );
$bcdd = array ( 0 => 'class="drag drop oddeven"' , 1 => 'class="drag drop oddeven"' );
$bcnd = array ( 0 => 'class="nodrag nodrop nohover"' , 1 => 'class="nodrag nodrop nohoverpair"' ); // Used for tr to add new lines
$bctag = array ( 0 => 'class="impair tagtr"' , 1 => 'class="pair tagtr"' );
2003-09-06 14:41:17 +02:00
2012-07-23 20:52:55 +02:00
// Define messages variables
2019-11-13 19:37:08 +01:00
$mesg = '' ; $warning = '' ; $error = 0 ;
2015-12-21 22:59:12 +01:00
// deprecated, see setEventMessages() and dol_htmloutput_events()
2019-11-13 19:37:08 +01:00
$mesgs = array (); $warnings = array (); $errors = array ();
2012-07-23 20:52:55 +02:00
2009-06-14 14:38:45 +02:00
// Constants used to defined number of lines in textarea
2021-02-23 20:26:57 +01:00
if ( empty ( $conf -> browser -> firefox )) {
2019-01-27 11:55:16 +01:00
define ( 'ROWS_1' , 1 );
define ( 'ROWS_2' , 2 );
define ( 'ROWS_3' , 3 );
define ( 'ROWS_4' , 4 );
define ( 'ROWS_5' , 5 );
define ( 'ROWS_6' , 6 );
define ( 'ROWS_7' , 7 );
define ( 'ROWS_8' , 8 );
define ( 'ROWS_9' , 9 );
2020-05-21 01:03:03 +02:00
} else {
2019-01-27 11:55:16 +01:00
define ( 'ROWS_1' , 0 );
define ( 'ROWS_2' , 1 );
define ( 'ROWS_3' , 2 );
define ( 'ROWS_4' , 3 );
define ( 'ROWS_5' , 4 );
define ( 'ROWS_6' , 5 );
define ( 'ROWS_7' , 6 );
define ( 'ROWS_8' , 7 );
define ( 'ROWS_9' , 8 );
2005-09-29 21:30:59 +02:00
}
2019-11-22 14:16:38 +01:00
$heightforframes = 50 ;
2010-04-03 17:08:09 +02:00
2013-01-19 16:29:16 +01:00
// Init menu manager
2021-02-23 20:26:57 +01:00
if ( ! defined ( 'NOREQUIREMENU' )) {
if ( empty ( $user -> socid )) { // If internal user or not defined
2019-11-22 14:16:38 +01:00
$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 );
2020-05-21 01:03:03 +02:00
} else {
// If external user
2019-11-22 14:16:38 +01:00
$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 );
2013-01-19 16:29:16 +01:00
}
2013-02-24 03:45:19 +01:00
// Load the menu manager (only if not already done)
2019-11-22 14:16:38 +01:00
$file_menu = $conf -> standard_menu ;
2021-02-23 20:26:57 +01:00
if ( GETPOST ( 'menu' , 'alpha' )) {
$file_menu = GETPOST ( 'menu' , 'alpha' ); // example: menu=eldy_menu.php
}
if ( ! class_exists ( 'MenuManager' )) {
2019-11-22 14:16:38 +01:00
$menufound = 0 ;
$dirmenus = array_merge ( array ( " /core/menus/ " ), ( array ) $conf -> modules_parts [ 'menus' ]);
2021-02-23 20:26:57 +01:00
foreach ( $dirmenus as $dirmenu ) {
2019-11-22 14:16:38 +01:00
$menufound = dol_include_once ( $dirmenu . " standard/ " . $file_menu );
2021-02-23 20:26:57 +01:00
if ( class_exists ( 'MenuManager' )) {
break ;
}
2013-02-24 03:45:19 +01:00
}
2021-02-23 20:26:57 +01:00
if ( ! class_exists ( 'MenuManager' )) { // If failed to include, we try with standard eldy_menu.php
2013-02-24 03:45:19 +01:00
dol_syslog ( " You define a menu manager ' " . $file_menu . " ' that can not be loaded. " , LOG_WARNING );
2019-11-22 14:16:38 +01:00
$file_menu = 'eldy_menu.php' ;
2013-02-24 03:45:19 +01:00
include_once DOL_DOCUMENT_ROOT . " /core/menus/standard/ " . $file_menu ;
}
}
2019-11-22 14:16:38 +01:00
$menumanager = new MenuManager ( $db , empty ( $user -> socid ) ? 0 : 1 );
2013-03-05 15:42:26 +01:00
$menumanager -> loadMenu ();
2013-02-24 03:45:19 +01:00
}
2013-01-17 18:39:15 +01:00
2010-04-03 17:08:09 +02:00
2011-04-01 11:50:30 +02:00
// Functions
2004-02-21 01:15:04 +01:00
2021-02-23 20:26:57 +01:00
if ( ! function_exists ( " llxHeader " )) {
2017-10-16 08:47:05 +02:00
/**
* Show HTML header HTML + BODY + Top menu + left menu + DIV
*
2020-12-27 16:53:15 +01:00
* @ param string $head Optionnal head lines
* @ param string $title HTML title
* @ param string $help_url Url links to help page
* Syntax is : For a wiki page : EN : EnglishPage | FR : FrenchPage | ES : SpanishPage
* For other external page : http :// server / url
* @ param string $target Target to use on links
* @ param int $disablejs More content into html header
* @ param int $disablehead More content into html header
* @ param array | string $arrayofjs Array of complementary js files
* @ param array | string $arrayofcss Array of complementary css files
* @ param string $morequerystring Query string to add to the link " print " to get same parameters ( use only if autodetect fails )
* @ param string $morecssonbody More CSS on body tag . For example 'classforhorizontalscrolloftabs' .
* @ param string $replacemainareaby Replace call to main_area () by a print of this string
2022-05-01 11:48:11 +02:00
* @ param int $disablenofollow Disable the " nofollow " on meta robot header
* @ param int $disablenoindex Disable the " noindex " on meta robot header
2017-10-16 08:47:05 +02:00
* @ return void
*/
2022-05-01 11:48:11 +02:00
function llxHeader ( $head = '' , $title = '' , $help_url = '' , $target = '' , $disablejs = 0 , $disablehead = 0 , $arrayofjs = '' , $arrayofcss = '' , $morequerystring = '' , $morecssonbody = '' , $replacemainareaby = '' , $disablenofollow = 0 , $disablenoindex = 0 )
2012-05-07 17:05:15 +02:00
{
2022-06-28 13:28:31 +02:00
global $conf , $hookmanager ;
2013-01-28 20:30:33 +01:00
2017-10-16 08:47:05 +02:00
// html header
2022-05-01 11:48:11 +02:00
top_htmlhead ( $head , $title , $disablejs , $disablehead , $arrayofjs , $arrayofcss , 0 , $disablenofollow , $disablenoindex );
2012-12-12 02:37:15 +01:00
2019-11-22 14:16:38 +01:00
$tmpcsstouse = 'sidebar-collapse' . ( $morecssonbody ? ' ' . $morecssonbody : '' );
2019-04-03 14:36:27 +02:00
// If theme MD and classic layer, we open the menulayer by default.
2021-02-23 20:26:57 +01:00
if ( $conf -> theme == 'md' && ! in_array ( $conf -> browser -> layout , array ( 'phone' , 'tablet' )) && empty ( $conf -> global -> MAIN_OPTIMIZEFORTEXTBROWSER )) {
2020-10-27 19:46:07 +01:00
global $mainmenu ;
2021-02-23 20:26:57 +01:00
if ( $mainmenu != 'website' ) {
$tmpcsstouse = $morecssonbody ; // We do not use sidebar-collpase by default to have menuhider open by default.
}
2019-04-03 14:36:27 +02:00
}
2019-03-15 20:10:39 +01:00
2019-11-22 14:16:38 +01:00
if ( ! empty ( $conf -> global -> MAIN_OPTIMIZEFORCOLORBLIND )) {
$tmpcsstouse .= ' colorblind-' . strip_tags ( $conf -> global -> MAIN_OPTIMIZEFORCOLORBLIND );
2019-08-07 12:15:55 +02:00
}
2019-11-22 14:16:38 +01:00
print '<body id="mainbody" class="' . $tmpcsstouse . '">' . " \n " ;
2017-05-13 15:19:35 +02:00
2022-06-28 13:28:31 +02:00
$parameters = array ( 'help_url' => $help_url );
$reshook = $hookmanager -> executeHooks ( 'changeHelpURL' , $parameters );
if ( $reshook > 0 ) {
$help_url = $hookmanager -> resPrint ;
}
2013-01-17 18:39:15 +01:00
// top menu and left menu area
2022-05-12 20:18:58 +02:00
if (( empty ( $conf -> dol_hide_topmenu ) || GETPOST ( 'dol_invisible_topmenu' , 'int' )) && ! GETPOST ( 'dol_openinpopup' , 'aZ09' )) {
2015-11-14 22:38:29 +01:00
top_menu ( $head , $title , $target , $disablejs , $disablehead , $arrayofjs , $arrayofcss , $morequerystring , $help_url );
2012-08-05 21:14:17 +02:00
}
2017-06-10 16:29:25 +02:00
2022-05-12 20:18:58 +02:00
if ( empty ( $conf -> dol_hide_leftmenu ) && ! GETPOST ( 'dol_openinpopup' , 'aZ09' )) {
2023-01-06 19:34:45 +01:00
left_menu ( array (), $help_url , '' , '' , 1 , $title , 1 ); // $menumanager is retrieved with a global $menumanager inside this function
2012-05-07 17:05:15 +02:00
}
2013-01-28 20:30:33 +01:00
2013-01-17 18:39:15 +01:00
// main area
2021-02-23 20:26:57 +01:00
if ( $replacemainareaby ) {
2017-10-13 13:22:24 +02:00
print $replacemainareaby ;
return ;
}
2012-05-07 17:05:15 +02:00
main_area ( $title );
}
2010-02-28 05:32:18 +01:00
}
2010-08-30 20:31:59 +02:00
/**
2021-03-19 12:08:40 +01:00
* Show HTTP header . Called by top_htmlhead () .
2011-09-25 00:43:52 +02:00
*
2017-05-09 21:01:37 +02:00
* @ param string $contenttype Content type . For example , 'text/html'
2018-01-24 13:40:39 +01:00
* @ param int $forcenocache Force disabling of cache for the page
2011-09-25 00:43:52 +02:00
* @ return void
2010-08-30 20:31:59 +02:00
*/
2019-01-27 15:20:16 +01:00
function top_httphead ( $contenttype = 'text/html' , $forcenocache = 0 )
2010-08-30 20:31:59 +02:00
{
2018-04-30 14:39:12 +02:00
global $db , $conf , $hookmanager ;
2017-10-16 08:47:05 +02:00
2021-02-23 20:26:57 +01:00
if ( $contenttype == 'text/html' ) {
header ( " Content-Type: text/html; charset= " . $conf -> file -> character_set_client );
} else {
header ( " Content-Type: " . $contenttype );
}
2019-08-02 19:21:25 +02:00
2017-10-16 08:47:05 +02:00
// Security options
2022-08-16 15:19:21 +02:00
// X-Content-Type-Options
2019-11-22 14:16:38 +01:00
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)
2022-08-16 15:19:21 +02:00
// X-Frame-Options
2021-02-23 20:26:57 +01:00
if ( ! defined ( 'XFRAMEOPTIONS_ALLOWALL' )) {
header ( " X-Frame-Options: SAMEORIGIN " ); // Frames allowed only if on same domain (stop some XSS attacks)
} else {
header ( " X-Frame-Options: ALLOWALL " );
}
2022-08-16 15:19:21 +02:00
// X-XSS-Protection
2019-12-07 15:46:14 +01:00
//header("X-XSS-Protection: 1"); // XSS filtering protection of some browsers (note: use of Content-Security-Policy is more efficient). Disabled as deprecated.
2022-08-16 15:19:21 +02:00
// Content-Security-Policy
if ( ! defined ( 'MAIN_SECURITY_FORCECSP' )) {
// If CSP not forced from the page
// A default security policy that keep usage of js external component like ckeditor, stripe, google, working
2023-01-23 11:28:37 +01:00
// $contentsecuritypolicy = "frame-ancestors 'self'; 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';";
2022-08-16 15:19:21 +02:00
$contentsecuritypolicy = getDolGlobalString ( 'MAIN_SECURITY_FORCECSP' );
2018-04-30 14:39:12 +02:00
2021-02-23 20:26:57 +01:00
if ( ! is_object ( $hookmanager )) {
2022-09-11 22:17:07 +02:00
include_once DOL_DOCUMENT_ROOT . '/core/class/hookmanager.class.php' ;
2021-02-23 20:26:57 +01:00
$hookmanager = new HookManager ( $db );
}
2019-05-15 18:59:46 +02:00
$hookmanager -> initHooks ( array ( " main " ));
2018-04-30 14:39:12 +02:00
2019-11-22 14:16:38 +01:00
$parameters = array ( 'contentsecuritypolicy' => $contentsecuritypolicy );
$result = $hookmanager -> executeHooks ( 'setContentSecurityPolicy' , $parameters ); // Note that $action and $object may have been modified by some hooks
2021-02-23 20:26:57 +01:00
if ( $result > 0 ) {
$contentsecuritypolicy = $hookmanager -> resPrint ; // Replace CSP
} else {
$contentsecuritypolicy .= $hookmanager -> resPrint ; // Concat CSP
}
2018-04-30 14:39:12 +02:00
2021-02-23 20:26:57 +01:00
if ( ! empty ( $contentsecuritypolicy )) {
2018-04-30 14:39:12 +02:00
// For example, to restrict 'script', 'object', 'frames' or 'img' to some domains:
2023-01-23 11:28:37 +01:00
// frame-ancestors 'self'; 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
2018-04-30 14:39:12 +02:00
// For example, to restrict everything to one domain, except 'object', ...:
// default-src https://cdn.example.net; object-src 'none'
// For example, to restrict everything to itself except img that can be on other servers:
// default-src 'self'; img-src *;
2022-08-16 15:19:21 +02:00
// Pre-existing site that uses too much js code to fix but wants to ensure resources are loaded only over https and disable plugins:
// default-src https: 'unsafe-inline' 'unsafe-eval'; object-src 'none'
2018-04-30 14:39:12 +02:00
header ( " Content-Security-Policy: " . $contentsecuritypolicy );
}
2022-08-16 15:19:21 +02:00
} else {
header ( " Content-Security-Policy: " . constant ( 'MAIN_SECURITY_FORCECSP' ));
2017-10-16 08:47:05 +02:00
}
2022-08-16 15:49:29 +02:00
// Referrer-Policy
// Say if we must provide the referrer when we jump onto another web page.
2022-11-20 22:42:35 +01:00
// Default browser are 'strict-origin-when-cross-origin' (only domain is sent on other domain switching), we want more so we use 'same-origin' so browser doesn't send any referrer when going into another web site domain.
2022-08-16 15:49:29 +02:00
if ( ! defined ( 'MAIN_SECURITY_FORCERP' )) {
$referrerpolicy = getDolGlobalString ( 'MAIN_SECURITY_FORCERP' , " same-origin " );
header ( " Referrer-Policy: " . $referrerpolicy );
}
2021-02-23 20:26:57 +01:00
if ( $forcenocache ) {
2018-01-24 13:40:39 +01:00
header ( " Cache-Control: no-cache, no-store, must-revalidate, max-age=0 " );
}
2022-08-16 15:19:21 +02:00
// No need to add this token in header, we use instead the one into the forms.
//header("anti-csrf-token: ".newToken());
2010-08-30 20:31:59 +02:00
}
2005-01-01 20:48:22 +01:00
/**
2021-03-19 12:08:40 +01:00
* Ouput html header of a page . It calls also top_httphead ()
2012-02-18 17:10:29 +01:00
* This code is also duplicated into security2 . lib . php :: dol_loginfunction
2011-08-28 16:18:14 +02:00
*
2017-02-23 00:45:27 +01:00
* @ param string $head Optionnal head lines
* @ param string $title HTML title
* @ param int $disablejs Disable js output
* @ param int $disablehead Disable head output
* @ param array $arrayofjs Array of complementary js files
* @ param array $arrayofcss Array of complementary css files
2022-01-29 16:22:55 +01:00
* @ param int $disableforlogin Do not load heavy js and css for login pages
2022-05-01 11:48:11 +02:00
* @ param int $disablenofollow Disable nofollow tag for meta robots
* @ param int $disablenoindex Disable noindex tag for meta robots
2011-09-12 19:43:31 +02:00
* @ return void
2002-12-31 15:10:59 +01:00
*/
2022-05-01 11:48:11 +02:00
function top_htmlhead ( $head , $title = '' , $disablejs = 0 , $disablehead = 0 , $arrayofjs = '' , $arrayofcss = '' , $disableforlogin = 0 , $disablenofollow = 0 , $disablenoindex = 0 )
2002-12-31 15:10:59 +01:00
{
2019-10-11 12:28:13 +02:00
global $db , $conf , $langs , $user , $mysoc , $hookmanager ;
2012-02-22 12:02:12 +01:00
2017-10-16 08:47:05 +02:00
top_httphead ();
2012-02-22 12:02:12 +01:00
2021-02-23 20:26:57 +01:00
if ( empty ( $conf -> css )) {
$conf -> css = '/theme/eldy/style.css.php' ; // If not defined, eldy by default
}
2012-02-22 12:02:12 +01:00
2018-03-29 11:34:01 +02:00
print '<!doctype html>' . " \n " ;
2022-03-16 19:45:39 +01:00
print '<html lang="' . substr ( $langs -> defaultlang , 0 , 2 ) . '">' . " \n " ;
2017-10-16 08:47:05 +02:00
//print '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr">'."\n";
2021-02-23 20:26:57 +01:00
if ( empty ( $disablehead )) {
if ( ! is_object ( $hookmanager )) {
$hookmanager = new HookManager ( $db );
}
2020-10-27 19:46:07 +01:00
$hookmanager -> initHooks ( array ( " main " ));
2019-01-12 14:35:51 +01:00
2020-10-27 19:46:07 +01:00
$ext = 'layout=' . $conf -> browser -> layout . '&version=' . urlencode ( DOL_VERSION );
2017-11-09 09:50:55 +01:00
2017-10-16 08:47:05 +02:00
print " <head> \n " ;
2018-08-16 14:47:12 +02:00
2021-02-23 20:26:57 +01:00
if ( GETPOST ( 'dol_basehref' , 'alpha' )) {
print '<base href="' . dol_escape_htmltag ( GETPOST ( 'dol_basehref' , 'alpha' )) . '">' . " \n " ;
}
2018-08-16 14:47:12 +02:00
2017-10-16 08:47:05 +02:00
// Displays meta
2019-08-16 06:06:36 +02:00
print '<meta charset="utf-8">' . " \n " ;
2022-05-01 11:48:11 +02:00
print '<meta name="robots" content="' . ( $disablenoindex ? 'index' : 'noindex' ) . ( $disablenofollow ? ',follow' : ',nofollow' ) . '">' . " \n " ; // Do not index
2019-11-22 14:16:38 +01:00
print '<meta name="viewport" content="width=device-width, initial-scale=1.0">' . " \n " ; // Scale for mobile device
2017-10-16 08:47:05 +02:00
print '<meta name="author" content="Dolibarr Development Team">' . " \n " ;
2022-10-06 15:24:23 +02:00
print '<meta name="anti-csrf-token" content="' . newToken () . '">' . " \n " ;
2021-11-05 14:23:19 +01:00
if ( getDolGlobalInt ( 'MAIN_FEATURES_LEVEL' )) {
print '<meta name="MAIN_FEATURES_LEVEL" content="' . getDolGlobalInt ( 'MAIN_FEATURES_LEVEL' ) . '">' . " \n " ;
2021-10-16 16:58:55 +02:00
}
2017-10-16 08:47:05 +02:00
// Favicon
2020-05-25 12:50:29 +02:00
$favicon = DOL_URL_ROOT . '/theme/dolibarr_256x256_color.png' ;
2021-02-23 20:26:57 +01:00
if ( ! empty ( $mysoc -> logo_squarred_mini )) {
$favicon = DOL_URL_ROOT . '/viewimage.php?cache=1&modulepart=mycompany&file=' . urlencode ( 'logos/thumbs/' . $mysoc -> logo_squarred_mini );
}
2022-10-06 15:24:23 +02:00
if ( getDolGlobalString ( 'MAIN_FAVICON_URL' )) {
$favicon = getDolGlobalString ( 'MAIN_FAVICON_URL' );
2021-02-23 20:26:57 +01:00
}
if ( empty ( $conf -> dol_use_jmobile )) {
print '<link rel="shortcut icon" type="image/x-icon" href="' . $favicon . '"/>' . " \n " ; // Not required into an Android webview
}
2019-10-11 12:28:13 +02:00
2017-10-17 14:03:22 +02:00
//if (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) print '<link rel="top" title="'.$langs->trans("Home").'" href="'.(DOL_URL_ROOT?DOL_URL_ROOT:'/').'">'."\n";
2019-09-23 21:55:30 +02:00
//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";
2017-10-17 14:03:22 +02:00
//if (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) print '<link rel="author" title="Dolibarr Development Team" href="https://www.dolibarr.org">'."\n";
2017-10-16 08:47:05 +02:00
2020-10-27 19:46:07 +01:00
// Mobile appli like icon
$manifest = DOL_URL_ROOT . '/theme/' . $conf -> theme . '/manifest.json.php' ;
if ( ! empty ( $manifest )) {
print '<link rel="manifest" href="' . $manifest . '" />' . " \n " ;
}
2019-04-04 11:45:54 +02:00
2020-10-27 19:46:07 +01:00
if ( ! empty ( $conf -> global -> THEME_ELDY_TOPMENU_BACK1 )) {
// TODO: use auto theme color switch
print '<meta name="theme-color" content="rgb(' . $conf -> global -> THEME_ELDY_TOPMENU_BACK1 . ')">' . " \n " ;
}
2019-04-04 11:45:54 +02:00
2018-08-16 14:47:12 +02:00
// Auto refresh page
2021-02-23 20:26:57 +01:00
if ( GETPOST ( 'autorefresh' , 'int' ) > 0 ) {
print '<meta http-equiv="refresh" content="' . GETPOST ( 'autorefresh' , 'int' ) . '">' ;
}
2018-08-16 14:47:12 +02:00
2017-10-16 08:47:05 +02:00
// Displays title
2019-11-22 14:16:38 +01:00
$appli = constant ( 'DOL_APPLICATION_TITLE' );
2021-02-23 20:26:57 +01:00
if ( ! empty ( $conf -> global -> MAIN_APPLICATION_TITLE )) {
$appli = $conf -> global -> MAIN_APPLICATION_TITLE ;
}
2017-10-16 08:47:05 +02:00
2018-06-28 22:59:53 +02:00
print '<title>' ;
2019-11-22 14:16:38 +01:00
$titletoshow = '' ;
2021-02-23 20:26:57 +01:00
if ( $title && ! empty ( $conf -> global -> MAIN_HTML_TITLE ) && preg_match ( '/noapp/' , $conf -> global -> MAIN_HTML_TITLE )) {
$titletoshow = dol_htmlentities ( $title );
} elseif ( $title ) {
$titletoshow = dol_htmlentities ( $appli . ' - ' . $title );
} else {
$titletoshow = dol_htmlentities ( $appli );
}
2018-06-28 22:59:53 +02:00
2019-11-22 14:16:38 +01:00
$parameters = array ( 'title' => $titletoshow );
$result = $hookmanager -> executeHooks ( 'setHtmlTitle' , $parameters ); // Note that $action and $object may have been modified by some hooks
2021-02-23 20:26:57 +01:00
if ( $result > 0 ) {
$titletoshow = $hookmanager -> resPrint ; // Replace Title to show
} else {
$titletoshow .= $hookmanager -> resPrint ; // Concat to Title to show
}
2018-06-28 22:59:53 +02:00
print $titletoshow ;
print '</title>' ;
2017-10-16 08:47:05 +02:00
print " \n " ;
2021-02-23 20:26:57 +01:00
if ( GETPOST ( 'version' , 'int' )) {
$ext = 'version=' . GETPOST ( 'version' , 'int' ); // usefull to force no cache on css/js
}
2022-02-06 22:11:44 +01:00
// Refresh value of MAIN_IHM_PARAMS_REV before forging the parameter line.
if ( GETPOST ( 'dol_resetcache' )) {
dolibarr_set_const ( $db , " MAIN_IHM_PARAMS_REV " , (( int ) $conf -> global -> MAIN_IHM_PARAMS_REV ) + 1 , 'chaine' , 0 , '' , $conf -> entity );
}
2017-10-16 08:47:05 +02:00
2022-09-01 16:13:21 +02:00
$themeparam = '?lang=' . $langs -> defaultlang . '&theme=' . $conf -> theme . ( GETPOST ( 'optioncss' , 'aZ09' ) ? '&optioncss=' . GETPOST ( 'optioncss' , 'aZ09' , 1 ) : '' ) . ( empty ( $user -> id ) ? '' : ( '&userid=' . $user -> id )) . '&entity=' . $conf -> entity ;
2022-02-06 22:11:44 +01:00
2021-03-20 12:40:24 +01:00
$themeparam .= ( $ext ? '&' . $ext : '' ) . '&revision=' . getDolGlobalInt ( " MAIN_IHM_PARAMS_REV " );
2021-02-23 20:26:57 +01:00
if ( GETPOSTISSET ( 'dol_hide_topmenu' )) {
$themeparam .= '&dol_hide_topmenu=' . GETPOST ( 'dol_hide_topmenu' , 'int' );
}
if ( GETPOSTISSET ( 'dol_hide_leftmenu' )) {
$themeparam .= '&dol_hide_leftmenu=' . GETPOST ( 'dol_hide_leftmenu' , 'int' );
}
if ( GETPOSTISSET ( 'dol_optimize_smallscreen' )) {
$themeparam .= '&dol_optimize_smallscreen=' . GETPOST ( 'dol_optimize_smallscreen' , 'int' );
}
if ( GETPOSTISSET ( 'dol_no_mouse_hover' )) {
$themeparam .= '&dol_no_mouse_hover=' . GETPOST ( 'dol_no_mouse_hover' , 'int' );
}
if ( GETPOSTISSET ( 'dol_use_jmobile' )) {
$themeparam .= '&dol_use_jmobile=' . GETPOST ( 'dol_use_jmobile' , 'int' ); $conf -> dol_use_jmobile = GETPOST ( 'dol_use_jmobile' , 'int' );
}
if ( GETPOSTISSET ( 'THEME_DARKMODEENABLED' )) {
$themeparam .= '&THEME_DARKMODEENABLED=' . GETPOST ( 'THEME_DARKMODEENABLED' , 'int' );
}
if ( GETPOSTISSET ( 'THEME_SATURATE_RATIO' )) {
$themeparam .= '&THEME_SATURATE_RATIO=' . GETPOST ( 'THEME_SATURATE_RATIO' , 'int' );
}
2017-10-16 08:47:05 +02:00
2020-11-28 03:32:25 +01:00
if ( ! empty ( $conf -> global -> MAIN_ENABLE_FONT_ROBOTO )) {
print '<link rel="preconnect" href="https://fonts.gstatic.com">' . " \n " ;
2020-11-28 03:35:32 +01:00
print '<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@200;300;400;500;600&display=swap" rel="stylesheet">' . " \n " ;
2020-11-28 03:32:25 +01:00
}
2021-02-23 20:26:57 +01:00
if ( ! defined ( 'DISABLE_JQUERY' ) && ! $disablejs && $conf -> use_javascript_ajax ) {
2017-10-16 08:47:05 +02:00
print '<!-- Includes CSS for JQuery (Ajax library) -->' . " \n " ;
2017-12-20 20:18:41 +01:00
$jquerytheme = 'base' ;
2021-02-23 20:26:57 +01:00
if ( ! empty ( $conf -> global -> MAIN_USE_JQUERY_THEME )) {
$jquerytheme = $conf -> global -> MAIN_USE_JQUERY_THEME ;
}
if ( constant ( 'JS_JQUERY_UI' )) {
print '<link rel="stylesheet" type="text/css" href="' . JS_JQUERY_UI . 'css/' . $jquerytheme . '/jquery-ui.min.css' . ( $ext ? '?' . $ext : '' ) . '">' . " \n " ; // Forced JQuery
} else {
print '<link rel="stylesheet" type="text/css" href="' . DOL_URL_ROOT . '/includes/jquery/css/' . $jquerytheme . '/jquery-ui.css' . ( $ext ? '?' . $ext : '' ) . '">' . " \n " ; // JQuery
}
if ( ! defined ( 'DISABLE_JQUERY_JNOTIFY' )) {
print '<link rel="stylesheet" type="text/css" href="' . DOL_URL_ROOT . '/includes/jquery/plugins/jnotify/jquery.jnotify-alt.min.css' . ( $ext ? '?' . $ext : '' ) . '">' . " \n " ; // JNotify
}
if ( ! defined ( 'DISABLE_SELECT2' ) && ( ! empty ( $conf -> global -> MAIN_USE_JQUERY_MULTISELECT ) || defined ( 'REQUIRE_JQUERY_MULTISELECT' ))) { // jQuery plugin "mutiselect", "multiple-select", "select2"...
2019-11-22 14:16:38 +01:00
$tmpplugin = empty ( $conf -> global -> MAIN_USE_JQUERY_MULTISELECT ) ? constant ( 'REQUIRE_JQUERY_MULTISELECT' ) : $conf -> global -> MAIN_USE_JQUERY_MULTISELECT ;
print '<link rel="stylesheet" type="text/css" href="' . DOL_URL_ROOT . '/includes/jquery/plugins/' . $tmpplugin . '/dist/css/' . $tmpplugin . '.css' . ( $ext ? '?' . $ext : '' ) . '">' . " \n " ;
2017-10-16 08:47:05 +02:00
}
}
2017-06-10 16:29:25 +02:00
2021-02-23 20:26:57 +01:00
if ( ! defined ( 'DISABLE_FONT_AWSOME' )) {
2017-10-16 08:47:05 +02:00
print '<!-- Includes CSS for font awesome -->' . " \n " ;
2020-10-27 19:46:07 +01:00
print '<link rel="stylesheet" type="text/css" href="' . DOL_URL_ROOT . '/theme/common/fontawesome-5/css/all.min.css' . ( $ext ? '?' . $ext : '' ) . '">' . " \n " ;
print '<link rel="stylesheet" type="text/css" href="' . DOL_URL_ROOT . '/theme/common/fontawesome-5/css/v4-shims.min.css' . ( $ext ? '?' . $ext : '' ) . '">' . " \n " ;
2017-10-16 08:47:05 +02:00
}
2017-06-10 16:29:25 +02:00
2017-10-16 08:47:05 +02:00
print '<!-- Includes CSS for Dolibarr theme -->' . " \n " ;
// Output style sheets (optioncss='print' or ''). Note: $conf->css looks like '/theme/eldy/style.css.php'
2019-11-22 14:16:38 +01:00
$themepath = dol_buildpath ( $conf -> css , 1 );
$themesubdir = '' ;
2021-02-23 20:26:57 +01:00
if ( ! empty ( $conf -> modules_parts [ 'theme' ])) { // This slow down
foreach ( $conf -> modules_parts [ 'theme' ] as $reldir ) {
if ( file_exists ( dol_buildpath ( $reldir . $conf -> css , 0 ))) {
2019-11-22 14:16:38 +01:00
$themepath = dol_buildpath ( $reldir . $conf -> css , 1 );
$themesubdir = $reldir ;
2013-01-08 15:21:56 +01:00
break ;
2017-10-16 08:47:05 +02:00
}
}
}
2017-12-19 00:15:22 +01:00
2017-10-16 08:47:05 +02:00
//print 'themepath='.$themepath.' themeparam='.$themeparam;exit;
print '<link rel="stylesheet" type="text/css" href="' . $themepath . $themeparam . '">' . " \n " ;
2021-02-23 20:26:57 +01:00
if ( ! empty ( $conf -> global -> MAIN_FIX_FLASH_ON_CHROME )) {
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 " ;
}
2012-08-08 20:43:23 +02:00
2017-10-16 08:47:05 +02:00
// CSS forced by modules (relative url starting with /)
2021-02-23 20:26:57 +01:00
if ( ! empty ( $conf -> modules_parts [ 'css' ])) {
2019-11-13 19:37:08 +01:00
$arraycss = ( array ) $conf -> modules_parts [ 'css' ];
2021-02-23 20:26:57 +01:00
foreach ( $arraycss as $modcss => $filescss ) {
2019-11-13 19:37:08 +01:00
$filescss = ( array ) $filescss ; // To be sure filecss is an array
2021-02-23 20:26:57 +01:00
foreach ( $filescss as $cssfile ) {
if ( empty ( $cssfile )) {
dol_syslog ( " Warning: module " . $modcss . " declared a css path file into its descriptor that is empty. " , LOG_WARNING );
}
2017-10-16 08:47:05 +02:00
// cssfile is a relative path
2022-01-15 20:53:16 +01:00
$urlforcss = dol_buildpath ( $cssfile , 1 );
2022-01-18 15:27:43 +01:00
if ( $urlforcss && $urlforcss != '/' ) {
2022-01-15 20:53:16 +01:00
print '<!-- Includes CSS added by module ' . $modcss . ' -->' . " \n " . '<link rel="stylesheet" type="text/css" href="' . $urlforcss ;
// 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.
if ( ! preg_match ( '/\.css$/i' , $cssfile )) {
print $themeparam ;
}
print '">' . " \n " ;
} else {
dol_syslog ( " Warning: module " . $modcss . " declared a css path file for a file we can't find. " , LOG_WARNING );
2021-02-23 20:26:57 +01:00
}
2017-10-16 08:47:05 +02:00
}
}
}
// CSS forced by page in top_htmlhead call (relative url starting with /)
2021-02-23 20:26:57 +01:00
if ( is_array ( $arrayofcss )) {
foreach ( $arrayofcss as $cssfile ) {
if ( preg_match ( '/^(http|\/\/)/i' , $cssfile )) {
2020-10-27 19:46:07 +01:00
$urltofile = $cssfile ;
} else {
$urltofile = dol_buildpath ( $cssfile , 1 );
}
2019-02-15 00:46:11 +01:00
print '<!-- Includes CSS added by page -->' . " \n " . '<link rel="stylesheet" type="text/css" title="default" href="' . $urltofile ;
2017-10-16 08:47:05 +02:00
// 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.
2021-02-23 20:26:57 +01:00
if ( ! preg_match ( '/\.css$/i' , $cssfile )) {
print $themeparam ;
}
2017-10-16 08:47:05 +02:00
print '">' . " \n " ;
}
}
2012-02-22 12:02:12 +01:00
2017-10-16 08:47:05 +02:00
// Output standard javascript links
2021-02-23 20:26:57 +01:00
if ( ! defined ( 'DISABLE_JQUERY' ) && ! $disablejs && ! empty ( $conf -> use_javascript_ajax )) {
2017-10-16 08:47:05 +02:00
// JQuery. Must be before other includes
print '<!-- Includes JS for JQuery -->' . " \n " ;
2021-02-23 20:26:57 +01:00
if ( defined ( 'JS_JQUERY' ) && constant ( 'JS_JQUERY' )) {
print '<script src="' . JS_JQUERY . 'jquery.min.js' . ( $ext ? '?' . $ext : '' ) . '"></script>' . " \n " ;
} else {
print '<script src="' . DOL_URL_ROOT . '/includes/jquery/js/jquery.min.js' . ( $ext ? '?' . $ext : '' ) . '"></script>' . " \n " ;
}
if ( defined ( 'JS_JQUERY_UI' ) && constant ( 'JS_JQUERY_UI' )) {
print '<script src="' . JS_JQUERY_UI . 'jquery-ui.min.js' . ( $ext ? '?' . $ext : '' ) . '"></script>' . " \n " ;
} else {
print '<script src="' . DOL_URL_ROOT . '/includes/jquery/js/jquery-ui.min.js' . ( $ext ? '?' . $ext : '' ) . '"></script>' . " \n " ;
}
2017-10-16 08:47:05 +02:00
// jQuery jnotify
2020-05-21 09:07:10 +02:00
if ( empty ( $conf -> global -> MAIN_DISABLE_JQUERY_JNOTIFY ) && ! defined ( 'DISABLE_JQUERY_JNOTIFY' )) {
2019-11-28 12:36:20 +01:00
print '<script src="' . DOL_URL_ROOT . '/includes/jquery/plugins/jnotify/jquery.jnotify.min.js' . ( $ext ? '?' . $ext : '' ) . '"></script>' . " \n " ;
2017-10-16 08:47:05 +02:00
}
2022-01-29 16:22:55 +01:00
// Table drag and drop lines
if ( empty ( $disableforlogin ) && ! defined ( 'DISABLE_JQUERY_TABLEDND' )) {
print '<script src="' . DOL_URL_ROOT . '/includes/jquery/plugins/tablednd/jquery.tablednd.min.js' . ( $ext ? '?' . $ext : '' ) . '"></script>' . " \n " ;
}
2020-03-04 22:29:21 +01:00
// Chart
2022-01-29 16:22:55 +01:00
if ( empty ( $disableforlogin ) && ( empty ( $conf -> global -> MAIN_JS_GRAPH ) || $conf -> global -> MAIN_JS_GRAPH == 'chart' ) && ! defined ( 'DISABLE_JS_GRAPH' )) {
2022-04-03 11:52:25 +02:00
print '<script src="' . DOL_URL_ROOT . '/includes/nnnick/chartjs/dist/chart.min.js' . ( $ext ? '?' . $ext : '' ) . '"></script>' . " \n " ;
2020-03-04 22:29:21 +01:00
}
2020-03-13 02:35:28 +01:00
// jQuery jeditable for Edit In Place features
2020-05-21 09:07:10 +02:00
if ( ! empty ( $conf -> global -> MAIN_USE_JQUERY_JEDITABLE ) && ! defined ( 'DISABLE_JQUERY_JEDITABLE' )) {
2017-10-16 08:47:05 +02:00
print '<!-- JS to manage editInPlace feature -->' . " \n " ;
2019-11-28 12:36:20 +01:00
print '<script src="' . DOL_URL_ROOT . '/includes/jquery/plugins/jeditable/jquery.jeditable.js' . ( $ext ? '?' . $ext : '' ) . '"></script>' . " \n " ;
print '<script src="' . DOL_URL_ROOT . '/includes/jquery/plugins/jeditable/jquery.jeditable.ui-datepicker.js' . ( $ext ? '?' . $ext : '' ) . '"></script>' . " \n " ;
print '<script src="' . DOL_URL_ROOT . '/includes/jquery/plugins/jeditable/jquery.jeditable.ui-autocomplete.js' . ( $ext ? '?' . $ext : '' ) . '"></script>' . " \n " ;
2019-01-20 23:36:39 +01:00
print '<script>' . " \n " ;
2017-10-16 08:47:05 +02:00
print 'var urlSaveInPlace = \'' . DOL_URL_ROOT . '/core/ajax/saveinplace.php\';' . " \n " ;
print 'var urlLoadInPlace = \'' . DOL_URL_ROOT . '/core/ajax/loadinplace.php\';' . " \n " ;
2019-11-28 12:36:20 +01:00
print 'var tooltipInPlace = \'' . $langs -> transnoentities ( 'ClickToEdit' ) . '\';' . " \n " ; // Added in title attribute of span
print 'var placeholderInPlace = \' \';' . " \n " ; // If we put another string than $langs->trans("ClickToEdit") here, nothing is shown. If we put empty string, there is error, Why ?
2020-11-23 15:12:52 +01:00
print 'var cancelInPlace = \'' . $langs -> trans ( " Cancel " ) . '\';' . " \n " ;
2017-10-16 08:47:05 +02:00
print 'var submitInPlace = \'' . $langs -> trans ( 'Ok' ) . '\';' . " \n " ;
print 'var indicatorInPlace = \'<img src="' . DOL_URL_ROOT . " /theme/ " . $conf -> theme . " /img/working.gif " . '">\';' . " \n " ;
2019-11-28 12:36:20 +01:00
print 'var withInPlace = 300;' ; // width in pixel for default string edit
2017-10-16 08:47:05 +02:00
print '</script>' . " \n " ;
2019-11-28 12:36:20 +01:00
print '<script src="' . DOL_URL_ROOT . '/core/js/editinplace.js' . ( $ext ? '?' . $ext : '' ) . '"></script>' . " \n " ;
print '<script src="' . DOL_URL_ROOT . '/includes/jquery/plugins/jeditable/jquery.jeditable.ckeditor.js' . ( $ext ? '?' . $ext : '' ) . '"></script>' . " \n " ;
2017-10-16 08:47:05 +02:00
}
2020-10-27 19:46:07 +01:00
// jQuery Timepicker
if ( ! empty ( $conf -> global -> MAIN_USE_JQUERY_TIMEPICKER ) || defined ( 'REQUIRE_JQUERY_TIMEPICKER' )) {
print '<script src="' . DOL_URL_ROOT . '/includes/jquery/plugins/timepicker/jquery-ui-timepicker-addon.js' . ( $ext ? '?' . $ext : '' ) . '"></script>' . " \n " ;
print '<script src="' . DOL_URL_ROOT . '/core/js/timepicker.js.php?lang=' . $langs -> defaultlang . ( $ext ? '&' . $ext : '' ) . '"></script>' . " \n " ;
}
if ( ! defined ( 'DISABLE_SELECT2' ) && ( ! empty ( $conf -> global -> MAIN_USE_JQUERY_MULTISELECT ) || defined ( 'REQUIRE_JQUERY_MULTISELECT' ))) {
// jQuery plugin "mutiselect", "multiple-select", "select2", ...
$tmpplugin = empty ( $conf -> global -> MAIN_USE_JQUERY_MULTISELECT ) ? constant ( 'REQUIRE_JQUERY_MULTISELECT' ) : $conf -> global -> MAIN_USE_JQUERY_MULTISELECT ;
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
}
2021-02-23 20:26:57 +01:00
if ( ! defined ( 'DISABLE_MULTISELECT' )) { // jQuery plugin "mutiselect" to select with checkboxes. Can be removed once we have an enhanced search tool
2020-10-31 14:32:18 +01:00
print '<script src="' . DOL_URL_ROOT . '/includes/jquery/plugins/multiselect/jquery.multi-select.js' . ( $ext ? '?' . $ext : '' ) . '"></script>' . " \n " ;
2020-10-27 19:46:07 +01:00
}
2018-09-15 13:31:25 +02:00
}
2013-04-01 23:38:39 +02:00
2020-10-27 19:46:07 +01:00
if ( ! $disablejs && ! empty ( $conf -> use_javascript_ajax )) {
// CKEditor
2022-06-09 21:51:48 +02:00
if ( empty ( $disableforlogin ) && ( isModEnabled ( 'fckeditor' ) && ( empty ( $conf -> global -> FCKEDITOR_EDITORNAME ) || $conf -> global -> FCKEDITOR_EDITORNAME == 'ckeditor' ) && ! defined ( 'DISABLE_CKEDITOR' )) || defined ( 'FORCE_CKEDITOR' )) {
2020-10-27 19:46:07 +01:00
print '<!-- Includes JS for CKEditor -->' . " \n " ;
$pathckeditor = DOL_URL_ROOT . '/includes/ckeditor/ckeditor/' ;
$jsckeditor = 'ckeditor.js' ;
if ( constant ( 'JS_CKEDITOR' )) {
// To use external ckeditor 4 js lib
$pathckeditor = constant ( 'JS_CKEDITOR' );
}
2021-02-09 21:13:54 +01:00
print '<script>' ;
2021-02-23 20:26:57 +01:00
print '/* enable ckeditor by main.inc.php */' ;
2022-01-30 17:24:10 +01:00
print 'var CKEDITOR_BASEPATH = \'' . dol_escape_js ( $pathckeditor ) . '\';' . " \n " ;
print 'var ckeditorConfig = \'' . dol_escape_js ( dol_buildpath ( $themesubdir . '/theme/' . $conf -> theme . '/ckeditor/config.js' . ( $ext ? '?' . $ext : '' ), 1 )) . '\';' . " \n " ; // $themesubdir='' in standard usage
2020-10-27 19:46:07 +01:00
print 'var ckeditorFilebrowserBrowseUrl = \'' . DOL_URL_ROOT . '/core/filemanagerdol/browser/default/browser.php?Connector=' . DOL_URL_ROOT . '/core/filemanagerdol/connectors/php/connector.php\';' . " \n " ;
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 " ;
print '</script>' . " \n " ;
print '<script src="' . $pathckeditor . $jsckeditor . ( $ext ? '?' . $ext : '' ) . '"></script>' . " \n " ;
print '<script>' ;
2021-02-09 21:13:54 +01:00
if ( GETPOST ( 'mode' , 'aZ09' ) == 'Full_inline' ) {
2020-10-27 19:46:07 +01:00
print 'CKEDITOR.disableAutoInline = false;' . " \n " ;
} else {
print 'CKEDITOR.disableAutoInline = true;' . " \n " ;
}
print '</script>' . " \n " ;
}
2017-06-10 16:29:25 +02:00
2020-10-27 19:46:07 +01:00
// 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).
2021-02-23 20:26:57 +01:00
if ( ! defined ( 'NOBROWSERNOTIF' ) && ! defined ( 'NOREQUIREMENU' ) && ! defined ( 'NOLOGIN' )) {
2020-10-27 19:46:07 +01:00
$enablebrowsernotif = false ;
2022-06-09 21:51:48 +02:00
if ( isModEnabled ( 'agenda' ) && ! empty ( $conf -> global -> AGENDA_REMINDER_BROWSER )) {
2021-02-23 20:26:57 +01:00
$enablebrowsernotif = true ;
}
if ( $conf -> browser -> layout == 'phone' ) {
$enablebrowsernotif = false ;
}
if ( $enablebrowsernotif ) {
2020-10-27 19:46:07 +01:00
print '<!-- Includes JS of Dolibarr (browser layout = ' . $conf -> browser -> layout . ')-->' . " \n " ;
print '<script src="' . DOL_URL_ROOT . '/core/js/lib_notification.js.php' . ( $ext ? '?' . $ext : '' ) . '"></script>' . " \n " ;
}
}
2017-06-10 16:29:25 +02:00
2020-10-27 19:46:07 +01:00
// Global js function
print '<!-- Includes JS of Dolibarr -->' . " \n " ;
2021-07-08 22:16:47 +02:00
print '<script src="' . DOL_URL_ROOT . '/core/js/lib_head.js.php?lang=' . $langs -> defaultlang . ( $ext ? '&' . $ext : '' ) . '"></script>' . " \n " ;
2009-08-09 13:37:32 +02:00
2020-10-27 19:46:07 +01:00
// JS forced by modules (relative url starting with /)
2021-02-23 20:26:57 +01:00
if ( ! empty ( $conf -> modules_parts [ 'js' ])) { // $conf->modules_parts['js'] is array('module'=>array('file1','file2'))
2020-10-27 19:46:07 +01:00
$arrayjs = ( array ) $conf -> modules_parts [ 'js' ];
2021-02-23 20:26:57 +01:00
foreach ( $arrayjs as $modjs => $filesjs ) {
2020-10-27 19:46:07 +01:00
$filesjs = ( array ) $filesjs ; // To be sure filejs is an array
2021-02-23 20:26:57 +01:00
foreach ( $filesjs as $jsfile ) {
2020-10-27 19:46:07 +01:00
// jsfile is a relative path
2022-01-15 20:53:16 +01:00
$urlforjs = dol_buildpath ( $jsfile , 1 );
2022-01-18 15:27:43 +01:00
if ( $urlforjs && $urlforjs != '/' ) {
2022-01-15 20:53:16 +01:00
print '<!-- Include JS added by module ' . $modjs . '-->' . " \n " . '<script src="' . $urlforjs . (( strpos ( $jsfile , '?' ) === false ) ? '?' : '&' ) . 'lang=' . $langs -> defaultlang . '"></script>' . " \n " ;
} else {
dol_syslog ( " Warning: module " . $modjs . " declared a js path file for a file we can't find. " , LOG_WARNING );
}
2020-10-27 19:46:07 +01:00
}
}
}
// JS forced by page in top_htmlhead (relative url starting with /)
2021-02-23 20:26:57 +01:00
if ( is_array ( $arrayofjs )) {
2020-10-27 19:46:07 +01:00
print '<!-- Includes JS added by page -->' . " \n " ;
2021-02-23 20:26:57 +01:00
foreach ( $arrayofjs as $jsfile ) {
if ( preg_match ( '/^(http|\/\/)/i' , $jsfile )) {
2021-07-08 22:16:47 +02:00
print '<script src="' . $jsfile . (( strpos ( $jsfile , '?' ) === false ) ? '?' : '&' ) . 'lang=' . $langs -> defaultlang . '"></script>' . " \n " ;
2020-10-27 19:46:07 +01:00
} else {
2021-07-08 22:16:47 +02:00
print '<script src="' . dol_buildpath ( $jsfile , 1 ) . (( strpos ( $jsfile , '?' ) === false ) ? '?' : '&' ) . 'lang=' . $langs -> defaultlang . '"></script>' . " \n " ;
2020-10-27 19:46:07 +01:00
}
}
}
}
2022-01-20 07:47:57 +01:00
2022-01-20 07:42:59 +01:00
//If you want to load custom javascript file from your selected theme directory
2022-01-20 07:47:57 +01:00
if ( ! empty ( $conf -> global -> ALLOW_THEME_JS )) {
2022-01-20 07:42:59 +01:00
$theme_js = dol_buildpath ( '/theme/' . $conf -> theme . '/' . $conf -> theme . '.js' , 0 );
if ( file_exists ( $theme_js )) {
print '<script src="' . DOL_URL_ROOT . '/theme/' . $conf -> theme . '/' . $conf -> theme . '.js' . ( $ext ? '?' . $ext : '' ) . '"></script>' . " \n " ;
}
}
2009-10-16 19:15:32 +02:00
2021-02-23 20:26:57 +01:00
if ( ! empty ( $head )) {
print $head . " \n " ;
}
if ( ! empty ( $conf -> global -> MAIN_HTML_HEADER )) {
print $conf -> global -> MAIN_HTML_HEADER . " \n " ;
}
2019-01-12 14:35:51 +01:00
2020-10-27 19:46:07 +01:00
$parameters = array ();
$result = $hookmanager -> executeHooks ( 'addHtmlHeader' , $parameters ); // Note that $action and $object may have been modified by some hooks
print $hookmanager -> resPrint ; // Replace Title to show
print " </head> \n \n " ;
}
2010-04-06 23:56:03 +02:00
2020-10-27 19:46:07 +01:00
$conf -> headerdone = 1 ; // To tell header was output
2005-08-20 18:43:30 +02:00
}
2006-09-10 20:07:09 +02:00
2004-08-21 14:18:03 +02:00
2010-04-05 20:41:34 +02:00
/**
2011-01-19 11:37:59 +01:00
* Show an HTML header + a BODY + The top menu bar
2011-08-28 16:18:14 +02:00
*
2011-09-12 19:08:02 +02:00
* @ param string $head Lines in the HEAD
* @ param string $title Title of web page
2014-04-23 12:22:01 +02:00
* @ param string $target Target to use in menu links ( Example : '' or '_top' )
2011-09-12 19:08:02 +02:00
* @ param int $disablejs Do not output links to js ( Ex : qd fonction utilisee par sous formulaire Ajax )
* @ param int $disablehead Do not output head section
* @ param array $arrayofjs Array of js files to add in header
* @ param array $arrayofcss Array of css files to add in header
* @ param string $morequerystring Query string to add to the link " print " to get same parameters ( use only if autodetect fails )
2015-11-14 22:38:29 +01:00
* @ param string $helppagename Name of wiki page for help ( '' by default ) .
* Syntax is : For a wiki page : EN : EnglishPage | FR : FrenchPage | ES : SpanishPage
2018-08-09 11:31:48 +02:00
* For other external page : http :// server / url
2011-09-25 00:43:52 +02:00
* @ return void
2010-04-05 20:41:34 +02:00
*/
2019-01-27 15:20:16 +01:00
function top_menu ( $head , $title = '' , $target = '' , $disablejs = 0 , $disablehead = 0 , $arrayofjs = '' , $arrayofcss = '' , $morequerystring = '' , $helppagename = '' )
2010-04-05 20:41:34 +02:00
{
2017-10-16 08:47:05 +02:00
global $user , $conf , $langs , $db ;
global $dolibarr_main_authentication , $dolibarr_main_demo ;
2019-11-13 19:37:08 +01:00
global $hookmanager , $menumanager ;
2012-02-29 19:41:12 +01:00
2019-11-13 19:37:08 +01:00
$searchform = '' ;
2016-07-07 09:47:12 +02:00
2020-12-08 22:16:38 +01:00
// Instantiate hooks for external modules
2017-10-16 08:47:05 +02:00
$hookmanager -> initHooks ( array ( 'toprightmenu' ));
2010-04-05 20:41:34 +02:00
2019-11-13 19:37:08 +01:00
$toprightmenu = '' ;
2010-06-27 15:19:38 +02:00
2017-10-16 08:47:05 +02:00
// For backward compatibility with old modules
2021-02-23 20:26:57 +01:00
if ( empty ( $conf -> headerdone )) {
2020-11-07 12:47:42 +01:00
$disablenofollow = 0 ;
top_htmlhead ( $head , $title , $disablejs , $disablehead , $arrayofjs , $arrayofcss , 0 , $disablenofollow );
2017-10-16 08:47:05 +02:00
print '<body id="mainbody">' ;
}
2010-11-02 13:14:06 +01:00
2017-10-16 08:47:05 +02:00
/*
2021-02-23 20:26:57 +01:00
* Top menu
*/
if (( empty ( $conf -> dol_hide_topmenu ) || GETPOST ( 'dol_invisible_topmenu' , 'int' )) && ( ! defined ( 'NOREQUIREMENU' ) || ! constant ( 'NOREQUIREMENU' ))) {
2020-10-30 05:45:36 +01:00
if ( ! isset ( $form ) || ! is_object ( $form )) {
include_once DOL_DOCUMENT_ROOT . '/core/class/html.form.class.php' ;
$form = new Form ( $db );
}
2017-10-16 08:47:05 +02:00
print " \n " . '<!-- Start top horizontal -->' . " \n " ;
2021-10-23 15:01:28 +02:00
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.
2017-10-16 08:47:05 +02:00
// Show menu entries
2019-11-13 19:37:08 +01:00
print '<div id="tmenu_tooltip' . ( empty ( $conf -> global -> MAIN_MENU_INVERT ) ? '' : 'invert' ) . '" class="tmenu">' . " \n " ;
$menumanager -> atarget = $target ;
2021-10-25 12:09:17 +02:00
$menumanager -> showmenu ( 'top' , array ( 'searchform' => $searchform )); // This contains a \n
2017-10-16 08:47:05 +02:00
print " </div> \n " ;
// Define link to login card
2019-11-13 19:37:08 +01:00
$appli = constant ( 'DOL_APPLICATION_TITLE' );
2021-02-23 20:26:57 +01:00
if ( ! empty ( $conf -> global -> MAIN_APPLICATION_TITLE )) {
2019-11-13 19:37:08 +01:00
$appli = $conf -> global -> MAIN_APPLICATION_TITLE ;
2021-02-23 20:26:57 +01:00
if ( preg_match ( '/\d\.\d/' , $appli )) {
if ( ! preg_match ( '/' . preg_quote ( DOL_VERSION ) . '/' , $appli )) {
$appli .= " ( " . DOL_VERSION . " ) " ; // If new title contains a version that is different than core
}
} else {
$appli .= " " . DOL_VERSION ;
}
} else {
$appli .= " " . DOL_VERSION ;
}
2017-10-16 08:47:05 +02:00
2021-11-05 14:23:19 +01:00
if ( getDolGlobalInt ( 'MAIN_FEATURES_LEVEL' )) {
$appli .= " <br> " . $langs -> trans ( " LevelOfFeature " ) . ': ' . getDolGlobalInt ( 'MAIN_FEATURES_LEVEL' );
2021-02-23 20:26:57 +01:00
}
2017-10-16 08:47:05 +02:00
2019-11-13 19:37:08 +01:00
$logouttext = '' ;
2020-10-26 19:02:26 +01:00
$logouthtmltext = '' ;
2021-02-23 20:26:57 +01:00
if ( empty ( $conf -> global -> MAIN_OPTIMIZEFORTEXTBROWSER )) {
2017-10-16 08:47:05 +02:00
//$logouthtmltext=$appli.'<br>';
2021-02-23 20:26:57 +01:00
if ( $_SESSION [ " dol_authmode " ] != 'forceuser' && $_SESSION [ " dol_authmode " ] != 'http' ) {
2019-11-13 19:37:08 +01:00
$logouthtmltext .= $langs -> trans ( " Logout " ) . '<br>' ;
2017-10-16 08:47:05 +02:00
2021-12-31 14:33:12 +01:00
$logouttext .= '<a accesskey="l" href="' . DOL_URL_ROOT . '/user/logout.php?token=' . newToken () . '">' ;
2019-11-13 19:37:08 +01:00
$logouttext .= img_picto ( $langs -> trans ( 'Logout' ), 'sign-out' , '' , false , 0 , 0 , '' , 'atoplogin' );
$logouttext .= '</a>' ;
2020-05-21 01:03:03 +02:00
} else {
2019-11-13 19:37:08 +01:00
$logouthtmltext .= $langs -> trans ( " NoLogoutProcessWithAuthMode " , $_SESSION [ " dol_authmode " ]);
2019-02-11 11:45:29 +01:00
$logouttext .= img_picto ( $langs -> trans ( 'Logout' ), 'sign-out' , '' , false , 0 , 0 , '' , 'atoplogin opacitymedium' );
2017-10-16 08:47:05 +02:00
}
}
2019-04-03 16:34:02 +02:00
print '<div class="login_block usedropdown">' . " \n " ;
2017-10-16 08:47:05 +02:00
2019-11-22 14:16:38 +01:00
$toprightmenu .= '<div class="login_block_other">' ;
2017-06-10 16:29:25 +02:00
2013-07-28 17:02:13 +02:00
// Execute hook printTopRightMenu (hooks should output string like '<div class="login"><a href="">mylink</a></div>')
2019-11-22 14:16:38 +01:00
$parameters = array ();
$result = $hookmanager -> executeHooks ( 'printTopRightMenu' , $parameters ); // Note that $action and $object may have been modified by some hooks
2021-02-23 20:26:57 +01:00
if ( is_numeric ( $result )) {
if ( $result == 0 ) {
2019-11-22 14:16:38 +01:00
$toprightmenu .= $hookmanager -> resPrint ; // add
2021-02-23 20:26:57 +01:00
} else {
2019-11-22 14:16:38 +01:00
$toprightmenu = $hookmanager -> resPrint ; // replace
2020-05-21 01:03:03 +02:00
}
} else {
2019-11-22 14:16:38 +01:00
$toprightmenu .= $result ; // For backward compatibility
2018-04-13 10:37:40 +02:00
}
2018-04-16 13:51:16 +02:00
2017-10-16 08:47:05 +02:00
// Link to module builder
2022-06-09 21:51:48 +02:00
if ( isModEnabled ( 'modulebuilder' )) {
2019-12-12 11:33:07 +01:00
$text = '<a href="' . DOL_URL_ROOT . '/modulebuilder/index.php?mainmenu=home&leftmenu=admintools" target="modulebuilder">' ;
2017-10-16 08:47:05 +02:00
//$text.= img_picto(":".$langs->trans("ModuleBuilder"), 'printer_top.png', 'class="printer"');
2019-11-22 14:16:38 +01:00
$text .= '<span class="fa fa-bug atoplogin valignmiddle"></span>' ;
$text .= '</a>' ;
2020-10-30 05:45:36 +01:00
$toprightmenu .= $form -> textwithtooltip ( '' , $langs -> trans ( " ModuleBuilder " ), 2 , 1 , $text , 'login_block_elem' , 2 );
2017-10-16 08:47:05 +02:00
}
2017-03-29 21:36:50 +02:00
// Link to print main content area
2021-10-25 13:04:52 +02:00
if ( empty ( $conf -> global -> MAIN_PRINT_DISABLELINK ) && empty ( $conf -> global -> MAIN_OPTIMIZEFORTEXTBROWSER )) {
2019-11-22 14:16:38 +01:00
$qs = dol_escape_htmltag ( $_SERVER [ " QUERY_STRING " ]);
2017-10-16 08:47:05 +02:00
2021-07-08 11:13:15 +02:00
if ( isset ( $_POST ) && is_array ( $_POST )) {
2021-02-23 20:26:57 +01:00
foreach ( $_POST as $key => $value ) {
if ( $key !== 'action' && $key !== 'password' && ! is_array ( $value )) {
$qs .= '&' . $key . '=' . urlencode ( $value );
}
2017-10-16 08:47:05 +02:00
}
}
2019-11-22 14:16:38 +01:00
$qs .= (( $qs && $morequerystring ) ? '&' : '' ) . $morequerystring ;
2021-11-22 02:35:55 +01:00
$text = '<a href="' . dol_escape_htmltag ( $_SERVER [ " PHP_SELF " ]) . '?' . $qs . ( $qs ? '&' : '' ) . 'optioncss=print" target="_blank" rel="noopener noreferrer">' ;
2017-10-16 08:47:05 +02:00
//$text.= img_picto(":".$langs->trans("PrintContentArea"), 'printer_top.png', 'class="printer"');
2019-11-22 14:16:38 +01:00
$text .= '<span class="fa fa-print atoplogin valignmiddle"></span>' ;
$text .= '</a>' ;
2020-10-30 05:45:36 +01:00
$toprightmenu .= $form -> textwithtooltip ( '' , $langs -> trans ( " PrintContentArea " ), 2 , 1 , $text , 'login_block_elem' , 2 );
2017-10-16 08:47:05 +02:00
}
// Link to Dolibarr wiki pages
2021-02-23 20:26:57 +01:00
if ( empty ( $conf -> global -> MAIN_HELP_DISABLELINK ) && empty ( $conf -> global -> MAIN_OPTIMIZEFORTEXTBROWSER )) {
2017-10-16 08:47:05 +02:00
$langs -> load ( " help " );
2019-11-22 14:16:38 +01:00
$helpbaseurl = '' ;
$helppage = '' ;
$mode = '' ;
2020-10-14 19:01:37 +02:00
$helppresent = '' ;
2017-10-16 08:47:05 +02:00
2020-10-14 18:52:41 +02:00
if ( empty ( $helppagename )) {
$helppagename = 'EN:User_documentation|FR:Documentation_utilisateur|ES:Documentación_usuarios' ;
} else {
2020-10-14 19:01:37 +02:00
$helppresent = 'helppresent' ;
2020-10-14 18:52:41 +02:00
}
2017-10-16 08:47:05 +02:00
// Get helpbaseurl, helppage and mode from helppagename and langs
2019-11-22 14:16:38 +01:00
$arrayres = getHelpParamFor ( $helppagename , $langs );
$helpbaseurl = $arrayres [ 'helpbaseurl' ];
$helppage = $arrayres [ 'helppage' ];
$mode = $arrayres [ 'mode' ];
2017-10-16 08:47:05 +02:00
// Link to help pages
2021-02-23 20:26:57 +01:00
if ( $helpbaseurl && $helppage ) {
2019-11-22 14:16:38 +01:00
$text = '' ;
2021-12-22 20:57:14 +01:00
$title = $langs -> trans ( $mode == 'wiki' ? 'GoToWikiHelpPage' : 'GoToHelpPage' ) . ', ' ;
2020-11-29 15:16:53 +01:00
if ( $mode == 'wiki' ) {
2021-12-22 20:57:14 +01:00
$title .= '<br>' . img_picto ( '' , 'globe' , 'class="pictofixedwidth"' ) . $langs -> trans ( " PageWiki " ) . ' ' . dol_escape_htmltag ( '"' . strtr ( $helppage , '_' , ' ' ) . '"' );
2021-02-23 20:26:57 +01:00
if ( $helppresent ) {
$title .= ' <span class="opacitymedium">(' . $langs -> trans ( " DedicatedPageAvailable " ) . ')</span>' ;
} else {
$title .= ' <span class="opacitymedium">(' . $langs -> trans ( " HomePage " ) . ')</span>' ;
}
2020-11-29 15:16:53 +01:00
}
2021-11-22 02:35:55 +01:00
$text .= '<a class="help" target="_blank" rel="noopener noreferrer" href="' ;
2021-02-23 20:26:57 +01:00
if ( $mode == 'wiki' ) {
$text .= sprintf ( $helpbaseurl , urlencode ( html_entity_decode ( $helppage )));
} else {
$text .= sprintf ( $helpbaseurl , $helppage );
}
2019-11-22 14:16:38 +01:00
$text .= '">' ;
2020-10-14 19:01:37 +02:00
$text .= '<span class="fa fa-question-circle atoplogin valignmiddle' . ( $helppresent ? ' ' . $helppresent : '' ) . '"></span>' ;
2021-12-22 20:57:14 +01:00
$text .= '<span class="fa fa-long-arrow-alt-up helppresentcircle' . ( $helppresent ? '' : ' unvisible' ) . '"></span>' ;
2019-11-22 14:16:38 +01:00
$text .= '</a>' ;
2020-10-30 05:45:36 +01:00
$toprightmenu .= $form -> textwithtooltip ( '' , $title , 2 , 1 , $text , 'login_block_elem' , 2 );
2017-10-16 08:47:05 +02:00
}
2020-02-15 17:20:11 +01:00
2020-02-18 09:37:59 +01:00
// Version
2020-02-15 17:20:11 +01:00
if ( ! empty ( $conf -> global -> MAIN_SHOWDATABASENAMEINHELPPAGESLINK )) {
$langs -> load ( 'admin' );
$appli .= '<br>' . $langs -> trans ( " Database " ) . ': ' . $db -> database_name ;
}
2017-10-16 08:47:05 +02:00
}
2016-03-18 10:56:55 +01:00
2020-09-16 13:15:57 +02:00
if ( empty ( $conf -> global -> MAIN_OPTIMIZEFORTEXTBROWSER )) {
2020-11-27 14:24:15 +01:00
$text = '<span class="aversion"><span class="hideonsmartphone small">' . DOL_VERSION . '</span></span>' ;
2020-10-30 05:45:36 +01:00
$toprightmenu .= $form -> textwithtooltip ( '' , $appli , 2 , 1 , $text , 'login_block_elem' , 2 );
2020-09-16 13:15:57 +02:00
}
2019-03-22 11:49:10 +01:00
2015-05-30 20:07:44 +02:00
// Logout link
2020-10-30 05:45:36 +01:00
$toprightmenu .= $form -> textwithtooltip ( '' , $logouthtmltext , 2 , 1 , $logouttext , 'login_block_elem logout-btn' , 2 );
2015-05-30 20:07:44 +02:00
2020-04-10 10:59:32 +02:00
$toprightmenu .= '</div>' ; // end div class="login_block_other"
2020-02-21 17:18:01 +01:00
// Add login user link
$toprightmenu .= '<div class="login_block_user">' ;
// Login name with photo and tooltip
$mode = - 1 ;
$toprightmenu .= '<div class="inline-block nowrap"><div class="inline-block login_block_elem login_block_elem_name" style="padding: 0px;">' ;
if ( ! empty ( $conf -> global -> MAIN_USE_TOP_MENU_SEARCH_DROPDOWN )) {
// Add search dropdown
$toprightmenu .= top_menu_search ();
}
2020-05-05 21:35:03 +02:00
if ( ! empty ( $conf -> global -> MAIN_USE_TOP_MENU_QUICKADD_DROPDOWN )) {
// Add search dropdown
$toprightmenu .= top_menu_quickadd ();
}
2020-02-21 17:18:01 +01:00
// Add bookmark dropdown
$toprightmenu .= top_menu_bookmark ();
// Add user dropdown
$toprightmenu .= top_menu_user ();
$toprightmenu .= '</div></div>' ;
$toprightmenu .= '</div>' . " \n " ;
2012-08-05 21:14:17 +02:00
2017-10-16 08:47:05 +02:00
print $toprightmenu ;
2012-08-05 21:14:17 +02:00
2019-11-22 14:16:38 +01:00
print " </div> \n " ; // end div class="login_block"
2018-03-29 11:34:01 +02:00
2021-10-23 15:01:28 +02:00
print '</header>' ;
2022-05-07 19:47:51 +02:00
//print '<header class="header2"> </header>';
2013-07-28 17:02:13 +02:00
2017-02-04 14:16:17 +01:00
print '<div style="clear: both;"></div>' ;
2017-10-16 08:47:05 +02:00
print " <!-- End top horizontal menu --> \n \n " ;
}
2012-02-22 12:02:12 +01:00
2021-02-23 20:26:57 +01:00
if ( empty ( $conf -> dol_hide_leftmenu ) && empty ( $conf -> dol_use_jmobile )) {
print '<!-- Begin div id-container --><div id="id-container" class="id-container">' ;
}
2010-04-05 20:41:34 +02:00
}
2019-03-22 11:49:10 +01:00
/**
* Build the tooltip on user login
*
2020-02-24 19:24:38 +01:00
* @ param int $hideloginname Hide login name . Show only the image .
2021-12-31 14:33:12 +01:00
* @ param string $urllogout URL for logout ( Will use DOL_URL_ROOT . '/user/logout.php?token=...' if empty )
2020-02-24 19:24:38 +01:00
* @ return string HTML content
2019-03-22 11:49:10 +01:00
*/
2020-02-24 19:24:38 +01:00
function top_menu_user ( $hideloginname = 0 , $urllogout = '' )
2019-03-22 11:49:10 +01:00
{
2021-05-11 00:04:11 +02:00
global $langs , $conf , $db , $hookmanager , $user , $mysoc ;
2020-10-27 19:46:07 +01:00
global $dolibarr_main_authentication , $dolibarr_main_demo ;
global $menumanager ;
2021-09-04 11:30:03 +02:00
$langs -> load ( 'companies' );
2021-09-09 15:12:02 +02:00
2020-10-27 19:46:07 +01:00
$userImage = $userDropDownImage = '' ;
2021-02-23 20:26:57 +01:00
if ( ! empty ( $user -> photo )) {
2020-10-27 19:46:07 +01:00
$userImage = Form :: showphoto ( 'userphoto' , $user , 0 , 0 , 0 , 'photouserphoto userphoto' , 'small' , 0 , 1 );
$userDropDownImage = Form :: showphoto ( 'userphoto' , $user , 0 , 0 , 0 , 'dropdown-user-image' , 'small' , 0 , 1 );
} else {
$nophoto = '/public/theme/common/user_anonymous.png' ;
2021-02-23 20:26:57 +01:00
if ( $user -> gender == 'man' ) {
$nophoto = '/public/theme/common/user_man.png' ;
}
if ( $user -> gender == 'woman' ) {
$nophoto = '/public/theme/common/user_woman.png' ;
}
2020-10-27 19:46:07 +01:00
$userImage = '<img class="photo photouserphoto userphoto" alt="No photo" src="' . DOL_URL_ROOT . $nophoto . '">' ;
$userDropDownImage = '<img class="photo dropdown-user-image" alt="No photo" src="' . DOL_URL_ROOT . $nophoto . '">' ;
}
$dropdownBody = '' ;
2021-03-21 22:58:21 +01:00
$dropdownBody .= '<span id="topmenulogincompanyinfo-btn"><i class="fa fa-caret-right"></i> ' . $langs -> trans ( " ShowCompanyInfos " ) . '</span>' ;
$dropdownBody .= '<div id="topmenulogincompanyinfo" >' ;
2021-08-05 15:57:51 +02:00
if ( $langs -> transcountry ( " ProfId1 " , $mysoc -> country_code ) != '-' ) {
2022-01-28 19:06:41 +01:00
$dropdownBody .= '<br><b>' . $langs -> transcountry ( " ProfId1 " , $mysoc -> country_code ) . '</b>: <span>' . dol_print_profids ( getDolGlobalString ( " MAIN_INFO_SIREN " ), 1 ) . '</span>' ;
2021-05-11 00:04:11 +02:00
}
2021-08-05 15:57:51 +02:00
if ( $langs -> transcountry ( " ProfId2 " , $mysoc -> country_code ) != '-' ) {
2022-01-28 19:06:41 +01:00
$dropdownBody .= '<br><b>' . $langs -> transcountry ( " ProfId2 " , $mysoc -> country_code ) . '</b>: <span>' . dol_print_profids ( getDolGlobalString ( " MAIN_INFO_SIRET " ), 2 ) . '</span>' ;
2021-05-11 00:04:11 +02:00
}
2021-08-05 15:57:51 +02:00
if ( $langs -> transcountry ( " ProfId3 " , $mysoc -> country_code ) != '-' ) {
2022-01-28 19:06:41 +01:00
$dropdownBody .= '<br><b>' . $langs -> transcountry ( " ProfId3 " , $mysoc -> country_code ) . '</b>: <span>' . dol_print_profids ( getDolGlobalString ( " MAIN_INFO_APE " ), 3 ) . '</span>' ;
2021-05-11 00:04:11 +02:00
}
2021-08-05 15:57:51 +02:00
if ( $langs -> transcountry ( " ProfId4 " , $mysoc -> country_code ) != '-' ) {
2022-01-28 19:06:41 +01:00
$dropdownBody .= '<br><b>' . $langs -> transcountry ( " ProfId4 " , $mysoc -> country_code ) . '</b>: <span>' . dol_print_profids ( getDolGlobalString ( " MAIN_INFO_RCS " ), 4 ) . '</span>' ;
2021-05-11 00:04:11 +02:00
}
2021-08-05 15:57:51 +02:00
if ( $langs -> transcountry ( " ProfId5 " , $mysoc -> country_code ) != '-' ) {
2022-01-28 19:06:41 +01:00
$dropdownBody .= '<br><b>' . $langs -> transcountry ( " ProfId5 " , $mysoc -> country_code ) . '</b>: <span>' . dol_print_profids ( getDolGlobalString ( " MAIN_INFO_PROFID5 " ), 5 ) . '</span>' ;
2021-05-11 00:04:11 +02:00
}
2021-08-05 15:57:51 +02:00
if ( $langs -> transcountry ( " ProfId6 " , $mysoc -> country_code ) != '-' ) {
2022-01-28 19:06:41 +01:00
$dropdownBody .= '<br><b>' . $langs -> transcountry ( " ProfId6 " , $mysoc -> country_code ) . '</b>: <span>' . dol_print_profids ( getDolGlobalString ( " MAIN_INFO_PROFID6 " ), 6 ) . '</span>' ;
2021-05-11 00:04:11 +02:00
}
2022-01-28 19:06:41 +01:00
$dropdownBody .= '<br><b>' . $langs -> trans ( " VATIntraShort " ) . '</b>: <span>' . dol_print_profids ( getDolGlobalString ( " MAIN_INFO_TVAINTRA " ), 'VAT' ) . '</span>' ;
2022-05-08 15:18:34 +02:00
$dropdownBody .= '<br><b>' . $langs -> trans ( " Country " ) . '</b>: <span>' . ( $mysoc -> country_code ? $langs -> trans ( " Country " . $mysoc -> country_code ) : '' ) . '</span>' ;
2021-03-21 22:58:21 +01:00
$dropdownBody .= '</div>' ;
$dropdownBody .= '<br>' ;
2020-10-27 19:46:07 +01:00
$dropdownBody .= '<span id="topmenuloginmoreinfo-btn"><i class="fa fa-caret-right"></i> ' . $langs -> trans ( " ShowMoreInfos " ) . '</span>' ;
$dropdownBody .= '<div id="topmenuloginmoreinfo" >' ;
// login infos
if ( ! empty ( $user -> admin )) {
$dropdownBody .= '<br><b>' . $langs -> trans ( " Administrator " ) . '</b>: ' . yn ( $user -> admin );
}
2021-02-23 20:26:57 +01:00
if ( ! empty ( $user -> socid )) { // Add thirdparty for external users
2020-10-27 19:46:07 +01:00
$thirdpartystatic = new Societe ( $db );
$thirdpartystatic -> fetch ( $user -> socid );
$companylink = ' ' . $thirdpartystatic -> getNomUrl ( 2 ); // picto only of company
$company = ' (' . $langs -> trans ( " Company " ) . ': ' . $thirdpartystatic -> name . ')' ;
}
$type = ( $user -> socid ? $langs -> trans ( " External " ) . $company : $langs -> trans ( " Internal " ));
$dropdownBody .= '<br><b>' . $langs -> trans ( " Type " ) . ':</b> ' . $type ;
$dropdownBody .= '<br><b>' . $langs -> trans ( " Status " ) . '</b>: ' . $user -> getLibStatut ( 0 );
$dropdownBody .= '<br>' ;
$dropdownBody .= '<br><u>' . $langs -> trans ( " Session " ) . '</u>' ;
$dropdownBody .= '<br><b>' . $langs -> trans ( " IPAddress " ) . '</b>: ' . dol_escape_htmltag ( $_SERVER [ " REMOTE_ADDR " ]);
2021-02-23 20:26:57 +01:00
if ( ! empty ( $conf -> global -> MAIN_MODULE_MULTICOMPANY )) {
$dropdownBody .= '<br><b>' . $langs -> trans ( " ConnectedOnMultiCompany " ) . ':</b> ' . $conf -> entity . ' (user entity ' . $user -> entity . ')' ;
}
2020-10-27 19:46:07 +01:00
$dropdownBody .= '<br><b>' . $langs -> trans ( " AuthenticationMode " ) . ':</b> ' . $_SESSION [ " dol_authmode " ] . ( empty ( $dolibarr_main_demo ) ? '' : ' (demo)' );
$dropdownBody .= '<br><b>' . $langs -> trans ( " ConnectedSince " ) . ':</b> ' . dol_print_date ( $user -> datelastlogin , " dayhour " , 'tzuser' );
$dropdownBody .= '<br><b>' . $langs -> trans ( " PreviousConnexion " ) . ':</b> ' . dol_print_date ( $user -> datepreviouslogin , " dayhour " , 'tzuser' );
$dropdownBody .= '<br><b>' . $langs -> trans ( " CurrentTheme " ) . ':</b> ' . $conf -> theme ;
2021-07-08 12:17:32 +02:00
$dropdownBody .= '<br><b>' . $langs -> trans ( " CurrentMenuManager " ) . ':</b> ' . ( isset ( $menumanager ) ? $menumanager -> name : 'unknown' );
2020-10-27 19:46:07 +01:00
$langFlag = picto_from_langcode ( $langs -> getDefaultLang ());
$dropdownBody .= '<br><b>' . $langs -> trans ( " CurrentUserLanguage " ) . ':</b> ' . ( $langFlag ? $langFlag . ' ' : '' ) . $langs -> getDefaultLang ();
2021-02-02 00:19:41 +01:00
$tz = ( int ) $_SESSION [ 'dol_tz' ] + ( int ) $_SESSION [ 'dol_dst' ];
$dropdownBody .= '<br><b>' . $langs -> trans ( " ClientTZ " ) . ':</b> ' . ( $tz ? ( $tz >= 0 ? '+' : '' ) . $tz : '' );
$dropdownBody .= ' (' . $_SESSION [ 'dol_tz_string' ] . ')' ;
//$dropdownBody .= ' '.$langs->trans("DaylingSavingTime").': ';
//if ($_SESSION['dol_dst'] > 0) $dropdownBody .= yn(1);
//else $dropdownBody .= yn(0);
2020-10-27 19:46:07 +01:00
$dropdownBody .= '<br><b>' . $langs -> trans ( " Browser " ) . ':</b> ' . $conf -> browser -> name . ( $conf -> browser -> version ? ' ' . $conf -> browser -> version : '' ) . ' (' . dol_escape_htmltag ( $_SERVER [ 'HTTP_USER_AGENT' ]) . ')' ;
$dropdownBody .= '<br><b>' . $langs -> trans ( " Layout " ) . ':</b> ' . $conf -> browser -> layout ;
$dropdownBody .= '<br><b>' . $langs -> trans ( " Screen " ) . ':</b> ' . $_SESSION [ 'dol_screenwidth' ] . ' x ' . $_SESSION [ 'dol_screenheight' ];
2021-02-23 20:26:57 +01:00
if ( $conf -> browser -> layout == 'phone' ) {
$dropdownBody .= '<br><b>' . $langs -> trans ( " Phone " ) . ':</b> ' . $langs -> trans ( " Yes " );
}
if ( ! empty ( $_SESSION [ " disablemodules " ])) {
$dropdownBody .= '<br><b>' . $langs -> trans ( " DisabledModules " ) . ':</b> <br>' . join ( ', ' , explode ( ',' , $_SESSION [ " disablemodules " ]));
}
2020-10-27 19:46:07 +01:00
$dropdownBody .= '</div>' ;
// Execute hook
$parameters = array ( 'user' => $user , 'langs' => $langs );
$result = $hookmanager -> executeHooks ( 'printTopRightMenuLoginDropdownBody' , $parameters ); // Note that $action and $object may have been modified by some hooks
2021-02-23 20:26:57 +01:00
if ( is_numeric ( $result )) {
2020-10-27 19:46:07 +01:00
if ( $result == 0 ) {
$dropdownBody .= $hookmanager -> resPrint ; // add
} else {
$dropdownBody = $hookmanager -> resPrint ; // replace
}
}
if ( empty ( $urllogout )) {
2021-12-31 14:33:12 +01:00
$urllogout = DOL_URL_ROOT . '/user/logout.php?token=' . newToken ();
2020-10-27 19:46:07 +01:00
}
2023-01-07 12:36:53 +01:00
// Defined the links for bottom of card
$profilLink = '<a accesskey="c" href="' . DOL_URL_ROOT . '/user/card.php?id=' . $user -> id . '" class="button-top-menu-dropdown" title="' . dol_escape_htmltag ( $langs -> trans ( " YourUserFile " )) . '"><i class="fa fa-user"></i> ' . $langs -> trans ( " Card " ) . '</a>' ;
$urltovirtualcard = '/user/virtualcard.php?id=' . (( int ) $user -> id );
2023-01-07 18:35:26 +01:00
$virtuelcardLink = dolButtonToOpenUrlInDialogPopup ( 'publicvirtualcardmenu' , $langs -> trans ( " PublicVirtualCardUrl " ) . ( is_object ( $user ) ? ' - ' . $user -> getFullName ( $langs ) : '' ), img_picto ( $langs -> trans ( " PublicVirtualCardUrl " ), 'card' , '' ), $urltovirtualcard , '' , 'button-top-menu-dropdown marginleftonly nohover' , " closeTopMenuLoginDropdown() " , '' , 'v' );
2023-01-07 12:36:53 +01:00
$logoutLink = '<a accesskey="l" href="' . $urllogout . '" class="button-top-menu-dropdown" title="' . dol_escape_htmltag ( $langs -> trans ( " Logout " )) . '"><i class="fa fa-sign-out-alt"></i> ' . $langs -> trans ( " Logout " ) . '</a>' ;
2020-10-27 19:46:07 +01:00
$profilName = $user -> getFullName ( $langs ) . ' (' . $user -> login . ')' ;
if ( ! empty ( $user -> admin )) {
$profilName = '<i class="far fa-star classfortooltip" title="' . $langs -> trans ( " Administrator " ) . '" ></i> ' . $profilName ;
}
// Define version to show
$appli = constant ( 'DOL_APPLICATION_TITLE' );
2021-02-23 20:26:57 +01:00
if ( ! empty ( $conf -> global -> MAIN_APPLICATION_TITLE )) {
2020-10-27 19:46:07 +01:00
$appli = $conf -> global -> MAIN_APPLICATION_TITLE ;
2021-02-23 20:26:57 +01:00
if ( preg_match ( '/\d\.\d/' , $appli )) {
if ( ! preg_match ( '/' . preg_quote ( DOL_VERSION ) . '/' , $appli )) {
$appli .= " ( " . DOL_VERSION . " ) " ; // If new title contains a version that is different than core
}
} else {
$appli .= " " . DOL_VERSION ;
}
} else {
$appli .= " " . DOL_VERSION ;
}
2020-10-27 19:46:07 +01:00
if ( empty ( $conf -> global -> MAIN_OPTIMIZEFORTEXTBROWSER )) {
$btnUser = ' <!-- div for user link -->
2020-02-27 18:35:32 +01:00
< div id = " topmenu-login-dropdown " class = " userimg atoplogin dropdown user user-menu inline-block " >
2020-02-26 20:11:42 +01:00
< a href = " '.DOL_URL_ROOT.'/user/card.php?id='. $user->id .' " class = " dropdown-toggle login-dropdown-a " data - toggle = " dropdown " >
2022-06-09 11:47:29 +02:00
'.$userImage.(empty($user->photo) ? ' < span class = " hidden-xs maxwidth200 atoploginusername hideonsmartphone paddingleft " > '.dol_trunc($user->firstname ? $user->firstname : $user->login, 10).' </ span > ' : ' ').'
2020-02-26 20:11:42 +01:00
</ a >
< div class = " dropdown-menu " >
<!-- User image -->
< div class = " user-header " >
'.$userDropDownImage.'
< p >
2020-04-04 23:31:17 +02:00
'.$profilName.' < br > ' ;
2021-04-11 15:57:58 +02:00
if ( $user -> datelastlogin ) {
$title = $langs -> trans ( " ConnectedSince " ) . ' : ' . dol_print_date ( $user -> datelastlogin , " dayhour " , 'tzuser' );
if ( $user -> datepreviouslogin ) {
$title .= '<br>' . $langs -> trans ( " PreviousConnexion " ) . ' : ' . dol_print_date ( $user -> datepreviouslogin , " dayhour " , 'tzuser' );
}
}
$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>' ;
2020-04-05 15:47:34 +02:00
if ( $user -> datepreviouslogin ) {
2021-04-11 15:57:58 +02:00
$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>' ;
2020-04-05 15:47:34 +02:00
}
2021-04-11 15:57:58 +02:00
2020-09-10 17:35:18 +02:00
//$btnUser .= '<small class="classfortooltip"><i class="fa fa-cog"></i> '.$langs->trans("Version").' '.$appli.'</small>';
$btnUser .= '
2020-02-26 20:11:42 +01:00
</ p >
</ div >
<!-- Menu Body -->
< div class = " user-body " > '.$dropdownBody.' </ div >
<!-- Menu Footer -->
< div class = " user-footer " >
< div class = " pull-left " >
'.$profilLink.'
</ div >
2023-01-07 12:36:53 +01:00
< div class = " pull-left " >
'.$virtuelcardLink.'
</ div >
2020-02-26 20:11:42 +01:00
< div class = " pull-right " >
'.$logoutLink.'
</ div >
< div style = " clear:both; " ></ div >
</ div >
</ div >
</ div > ' ;
2020-10-27 19:46:07 +01:00
} else {
$btnUser = ' <!-- div for user link -->
2022-03-26 11:44:36 +01:00
< div id = " topmenu-login-dropdown " class = " userimg atoplogin dropdown user user-menu inline-block " >
2020-02-26 20:11:42 +01:00
< a href = " '.DOL_URL_ROOT.'/user/card.php?id='. $user->id .' " >
'.$userImage.'
< span class = " hidden-xs maxwidth200 atoploginusername hideonsmartphone " > '.dol_trunc($user->firstname ? $user->firstname : $user->login, 10).' </ span >
</ a >
</ div > ' ;
2020-10-27 19:46:07 +01:00
}
2019-03-12 11:49:56 +01:00
2021-02-23 20:26:57 +01:00
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
2020-10-27 19:46:07 +01:00
$btnUser .= '
2019-07-23 13:31:00 +02:00
<!-- Code to show / hide the user drop - down -->
< script >
2023-01-07 12:36:53 +01:00
function closeTopMenuLoginDropdown () {
//console.log("close login dropdown"); // This is call at each click on page, so we disable the log
// Hide the menus.
jQuery ( " #topmenu-login-dropdown " ) . removeClass ( " open " );
}
2022-12-24 15:32:20 +01:00
jQuery ( document ) . ready ( function () {
jQuery ( document ) . on ( " click " , function ( event ) {
2019-07-23 13:31:00 +02:00
if ( ! $ ( event . target ) . closest ( " #topmenu-login-dropdown " ) . length ) {
2023-01-07 12:36:53 +01:00
closeTopMenuLoginDropdown ();
2019-07-23 13:31:00 +02:00
}
});
2020-03-03 15:11:14 +01:00
' ;
2019-03-12 11:49:56 +01:00
2020-10-27 19:46:07 +01:00
if ( $conf -> theme != 'md' ) {
$btnUser .= '
2022-12-24 15:32:20 +01:00
jQuery ( " #topmenu-login-dropdown .dropdown-toggle " ) . on ( " click " , function ( event ) {
2020-03-04 02:14:40 +01:00
console . log ( " toggle login dropdown " );
event . preventDefault ();
2022-12-24 15:32:20 +01:00
jQuery ( " #topmenu-login-dropdown " ) . toggleClass ( " open " );
2020-03-04 02:14:40 +01:00
});
2022-12-24 15:32:20 +01:00
jQuery ( " #topmenulogincompanyinfo-btn " ) . on ( " click " , function () {
2022-03-26 11:44:36 +01:00
console . log ( " Clik on topmenulogincompanyinfo-btn " );
2022-12-24 15:32:20 +01:00
jQuery ( " #topmenulogincompanyinfo " ) . slideToggle ();
2021-03-21 22:58:21 +01:00
});
2022-12-24 15:32:20 +01:00
jQuery ( " #topmenuloginmoreinfo-btn " ) . on ( " click " , function () {
2022-03-26 11:44:36 +01:00
console . log ( " Clik on topmenuloginmoreinfo-btn " );
2022-12-24 15:32:20 +01:00
jQuery ( " #topmenuloginmoreinfo " ) . slideToggle ();
2020-03-04 02:14:40 +01:00
}); ' ;
2020-10-27 19:46:07 +01:00
}
2019-03-22 11:49:10 +01:00
2020-10-27 19:46:07 +01:00
$btnUser .= '
2019-07-23 13:31:00 +02:00
});
</ script >
' ;
2020-10-27 19:46:07 +01:00
}
2019-03-22 11:49:10 +01:00
2020-10-27 19:46:07 +01:00
return $btnUser ;
2019-03-11 18:03:39 +01:00
}
2020-05-05 21:35:03 +02:00
/**
* Build the tooltip on top menu quick add
*
* @ return string HTML content
*/
function top_menu_quickadd ()
{
2021-10-26 18:26:36 +02:00
global $langs ;
2021-05-17 08:30:30 +02:00
2020-05-05 21:35:03 +02:00
$html = '' ;
2020-09-07 10:18:17 +02:00
$html .= ' <!-- div for quick add link -->
2020-05-05 21:35:03 +02:00
< div id = " topmenu-quickadd-dropdown " class = " atoplogin dropdown inline-block " >
2022-04-15 18:04:58 +02:00
< 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 >
2021-10-26 18:26:36 +02:00
< div class = " dropdown-menu " > '.printDropdownQuickadd().' </ div >
2020-05-05 21:35:03 +02:00
</ div > ' ;
$html .= '
<!-- Code to show / hide the user drop - down -->
< script >
2022-12-24 15:32:20 +01:00
jQuery ( document ) . ready ( function () {
jQuery ( document ) . on ( " click " , function ( event ) {
2020-05-05 21:35:03 +02:00
if ( ! $ ( event . target ) . closest ( " #topmenu-quickadd-dropdown " ) . length ) {
// Hide the menus.
$ ( " #topmenu-quickadd-dropdown " ) . removeClass ( " open " );
}
});
$ ( " #topmenu-quickadd-dropdown .dropdown-toggle " ) . on ( " click " , function ( event ) {
openQuickAddDropDown ();
});
// Key map shortcut
$ ( document ) . keydown ( function ( e ){
if ( e . which === 76 && e . ctrlKey && e . shiftKey ){
console . log ( \ ' control + shift + l : trigger open quick add dropdown\ ' );
openQuickAddDropDown ();
}
});
var openQuickAddDropDown = function () {
event . preventDefault ();
$ ( " #topmenu-quickadd-dropdown " ) . toggleClass ( " open " );
//$("#top-quickadd-search-input").focus();
}
});
</ script >
' ;
return $html ;
}
2019-09-29 11:47:34 +02:00
2021-10-26 18:26:36 +02:00
/**
* Generate list of quickadd items
*
* @ return string HTML output
*/
function printDropdownQuickadd ()
{
global $conf , $user , $langs , $hookmanager ;
$items = array (
'items' => array (
2022-05-23 11:56:39 +02:00
array (
" url " => " /adherents/card.php?action=create&mainmenu=members " ,
" title " => " MenuNewMember@members " ,
" name " => " Adherent@members " ,
" picto " => " object_member " ,
2022-08-31 21:55:55 +02:00
" activation " => isModEnabled ( 'adherent' ) && $user -> hasRight ( " adherent " , " write " ), // vs hooking
2022-05-23 11:56:39 +02:00
" position " => 5 ,
),
2021-10-26 18:26:36 +02:00
array (
2022-04-18 07:18:02 +02:00
" url " => " /societe/card.php?action=create&mainmenu=companies " ,
2021-10-26 18:26:36 +02:00
" title " => " MenuNewThirdParty@companies " ,
" name " => " ThirdParty@companies " ,
" picto " => " object_company " ,
2022-08-23 20:01:34 +02:00
" activation " => isModEnabled ( " societe " ) && $user -> hasRight ( " societe " , " write " ), // vs hooking
2021-10-26 18:26:36 +02:00
" position " => 10 ,
),
array (
2022-04-18 07:18:02 +02:00
" url " => " /contact/card.php?action=create&mainmenu=companies " ,
2021-10-26 18:26:36 +02:00
" title " => " NewContactAddress@companies " ,
" name " => " Contact@companies " ,
" picto " => " object_contact " ,
2022-08-23 20:01:34 +02:00
" activation " => isModEnabled ( " societe " ) && $user -> hasRight ( " societe " , " contact " , " write " ), // vs hooking
2021-10-26 18:26:36 +02:00
" position " => 20 ,
),
array (
2022-04-18 07:18:02 +02:00
" url " => " /comm/propal/card.php?action=create&mainmenu=commercial " ,
2021-10-26 18:26:36 +02:00
" title " => " NewPropal@propal " ,
" name " => " Proposal@propal " ,
" picto " => " object_propal " ,
2022-10-16 16:50:11 +02:00
" activation " => isModEnabled ( " propal " ) && $user -> hasRight ( " propal " , " write " ), // vs hooking
2021-10-26 18:26:36 +02:00
" position " => 30 ,
),
array (
2022-04-18 07:18:02 +02:00
" url " => " /commande/card.php?action=create&mainmenu=commercial " ,
2021-10-26 18:26:36 +02:00
" title " => " NewOrder@orders " ,
" name " => " Order@orders " ,
" picto " => " object_order " ,
2022-08-31 21:55:55 +02:00
" activation " => isModEnabled ( 'commande' ) && $user -> hasRight ( " commande " , " write " ), // vs hooking
2021-10-26 18:26:36 +02:00
" position " => 40 ,
),
array (
2022-04-18 07:18:02 +02:00
" url " => " /compta/facture/card.php?action=create&mainmenu=billing " ,
2021-10-26 18:26:36 +02:00
" title " => " NewBill@bills " ,
" name " => " Bill@bills " ,
" picto " => " object_bill " ,
2022-07-29 15:46:13 +02:00
" activation " => isModEnabled ( 'facture' ) && $user -> hasRight ( " facture " , " write " ), // vs hooking
2021-10-26 18:26:36 +02:00
" position " => 50 ,
),
array (
2022-04-18 07:18:02 +02:00
" url " => " /contrat/card.php?action=create&mainmenu=commercial " ,
2021-10-26 18:26:36 +02:00
" title " => " NewContractSubscription@contracts " ,
" name " => " Contract@contracts " ,
" picto " => " object_contract " ,
2022-08-31 22:02:31 +02:00
" activation " => isModEnabled ( 'contrat' ) && $user -> hasRight ( " contrat " , " write " ), // vs hooking
2021-10-26 18:26:36 +02:00
" position " => 60 ,
),
array (
2022-04-18 07:18:02 +02:00
" url " => " /supplier_proposal/card.php?action=create&mainmenu=commercial " ,
2021-10-26 18:26:36 +02:00
" title " => " SupplierProposalNew@supplier_proposal " ,
" name " => " SupplierProposal@supplier_proposal " ,
2022-05-23 11:56:39 +02:00
" picto " => " supplier_proposal " ,
2022-08-31 22:02:31 +02:00
" activation " => isModEnabled ( 'supplier_proposal' ) && $user -> hasRight ( " supplier_invoice " , " write " ), // vs hooking
2021-10-26 18:26:36 +02:00
" position " => 70 ,
),
array (
2022-04-18 07:18:02 +02:00
" url " => " /fourn/commande/card.php?action=create&mainmenu=commercial " ,
2021-10-26 18:26:36 +02:00
" title " => " NewSupplierOrderShort@orders " ,
" name " => " SupplierOrder@orders " ,
2022-05-23 11:56:39 +02:00
" picto " => " supplier_order " ,
2022-08-23 20:05:09 +02:00
" activation " => ( isModEnabled ( " fournisseur " ) && empty ( $conf -> global -> MAIN_USE_NEW_SUPPLIERMOD ) && $user -> hasRight ( " fournisseur " , " commande " , " write " )) || ( isModEnabled ( " supplier_order " ) && $user -> hasRight ( " supplier_invoice " , " write " )), // vs hooking
2021-10-26 18:26:36 +02:00
" position " => 80 ,
),
array (
2022-04-18 07:18:02 +02:00
" url " => " /fourn/facture/card.php?action=create&mainmenu=billing " ,
2021-10-26 18:26:36 +02:00
" title " => " NewBill@bills " ,
" name " => " SupplierBill@bills " ,
2022-05-23 11:56:39 +02:00
" picto " => " supplier_invoice " ,
2022-08-23 20:05:09 +02:00
" activation " => ( isModEnabled ( " fournisseur " ) && empty ( $conf -> global -> MAIN_USE_NEW_SUPPLIERMOD ) && $user -> hasRight ( " fournisseur " , " facture " , " write " )) || ( isModEnabled ( " supplier_invoice " ) && $user -> hasRight ( " supplier_invoice " , " write " )), // vs hooking
2021-10-26 18:26:36 +02:00
" position " => 90 ,
),
2022-11-25 05:28:01 +01:00
array (
" url " => " /ticket/card.php?action=create&mainmenu=ticket " ,
" title " => " NewTicket@ticket " ,
" name " => " Ticket@ticket " ,
" picto " => " ticket " ,
" activation " => isModEnabled ( 'ticket' ) && $user -> hasRight ( " ticket " , " write " ), // vs hooking
" position " => 100 ,
),
array (
" url " => " /fichinter/card.php?action=create&mainmenu=commercial " ,
" title " => " NewIntervention@interventions " ,
" name " => " Intervention@interventions " ,
" picto " => " intervention " ,
" activation " => isModEnabled ( 'ficheinter' ) && $user -> hasRight ( " ficheinter " , " creer " ), // vs hooking
" position " => 110 ,
),
2021-10-26 18:26:36 +02:00
array (
2022-04-18 07:18:02 +02:00
" url " => " /product/card.php?action=create&type=0&mainmenu=products " ,
2021-10-26 18:26:36 +02:00
" title " => " NewProduct@products " ,
" name " => " Product@products " ,
" picto " => " object_product " ,
2022-08-23 20:01:34 +02:00
" activation " => isModEnabled ( " product " ) && $user -> hasRight ( " produit " , " write " ), // vs hooking
2022-11-25 05:28:01 +01:00
" position " => 400 ,
2021-10-26 18:26:36 +02:00
),
array (
2022-04-18 07:18:02 +02:00
" url " => " /product/card.php?action=create&type=1&mainmenu=products " ,
2021-10-26 18:26:36 +02:00
" title " => " NewService@products " ,
" name " => " Service@products " ,
" picto " => " object_service " ,
2022-08-23 20:02:37 +02:00
" activation " => isModEnabled ( " service " ) && $user -> hasRight ( " service " , " write " ), // vs hooking
2022-11-25 05:28:01 +01:00
" position " => 410 ,
2021-10-26 18:26:36 +02:00
),
2022-05-23 11:56:39 +02:00
array (
" url " => " /user/card.php?action=create&type=1&mainmenu=home " ,
" title " => " AddUser@users " ,
" name " => " User@users " ,
" picto " => " user " ,
2022-07-29 15:46:13 +02:00
" activation " => $user -> hasRight ( " user " , " user " , " write " ), // vs hooking
2022-05-23 11:56:39 +02:00
" position " => 500 ,
),
2021-10-26 18:26:36 +02:00
),
);
$dropDownQuickAddHtml = '' ;
// Define $dropDownQuickAddHtml
$dropDownQuickAddHtml .= '<div class="quickadd-body dropdown-body">' ;
$dropDownQuickAddHtml .= '<div class="dropdown-quickadd-list">' ;
// Allow the $items of the menu to be manipulated by modules
$parameters = array ();
$hook_items = $items ;
$reshook = $hookmanager -> executeHooks ( 'menuDropdownQuickaddItems' , $parameters , $hook_items ); // Note that $action and $object may have been modified by some hooks
2023-01-14 12:28:44 +01:00
if ( is_numeric ( $reshook ) && ! empty ( $hookmanager -> resArray ) && is_array ( $hookmanager -> resArray )) {
2021-10-26 18:26:36 +02:00
if ( $reshook == 0 ) {
2023-01-14 12:28:44 +01:00
$items [ 'items' ] = array_merge ( $items [ 'items' ], $hookmanager -> resArray ); // add
2021-10-26 18:26:36 +02:00
} else {
2023-01-14 12:28:44 +01:00
$items = $hookmanager -> resArray ; // replace
2021-10-26 18:26:36 +02:00
}
// Sort menu items by 'position' value
$position = array ();
foreach ( $items [ 'items' ] as $key => $row ) {
$position [ $key ] = $row [ 'position' ];
}
2022-06-03 14:14:53 +02:00
$array1_sort_order = SORT_ASC ;
array_multisort ( $position , $array1_sort_order , $items [ 'items' ]);
2021-10-26 18:26:36 +02:00
}
foreach ( $items [ 'items' ] as $item ) {
if ( ! $item [ 'activation' ]) {
continue ;
}
$langs -> load ( explode ( '@' , $item [ 'title' ])[ 1 ]);
$langs -> load ( explode ( '@' , $item [ 'name' ])[ 1 ]);
$dropDownQuickAddHtml .= '
< a class = " dropdown-item quickadd-item " href = " '.DOL_URL_ROOT. $item['url'] .' " title = " '. $langs->trans (explode('@', $item['title'] )[0]).' " >
'. img_picto(' ', $item[' picto '], ' style = " width:18px; " ') . ' ' . $langs->trans(explode(' @ ', $item[' name '])[0]) . ' </ a >
' ;
}
$dropDownQuickAddHtml .= '</div>' ;
$dropDownQuickAddHtml .= '</div>' ;
return $dropDownQuickAddHtml ;
}
2019-09-29 11:47:34 +02:00
/**
* Build the tooltip on top menu bookmark
*
* @ return string HTML content
*/
2019-10-17 20:59:42 +02:00
function top_menu_bookmark ()
2019-09-29 11:47:34 +02:00
{
2020-10-27 19:46:07 +01:00
global $langs , $conf , $db , $user ;
2019-10-17 20:59:42 +02:00
$html = '' ;
2019-09-29 11:47:34 +02:00
2020-10-27 19:46:07 +01:00
// Define $bookmarks
2022-09-25 15:31:07 +02:00
if ( ! isModEnabled ( 'bookmark' ) || empty ( $user -> rights -> bookmark -> lire )) {
2021-02-23 20:26:57 +01:00
return $html ;
}
2020-02-26 15:05:29 +01:00
2021-02-23 20:26:57 +01:00
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
2020-10-27 19:46:07 +01:00
include_once DOL_DOCUMENT_ROOT . '/bookmarks/bookmarks.lib.php' ;
$langs -> load ( " bookmarks " );
if ( ! empty ( $conf -> global -> MAIN_OPTIMIZEFORTEXTBROWSER )) {
$html .= '<div id="topmenu-bookmark-dropdown" class="dropdown inline-block">' ;
$html .= printDropdownBookmarksList ();
$html .= '</div>' ;
} else {
$html .= ' <!-- div for bookmark link -->
2020-03-25 15:40:02 +01:00
< div id = " topmenu-bookmark-dropdown " class = " dropdown inline-block " >
2022-04-15 18:04:58 +02:00
< 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 >
2020-03-25 15:40:02 +01:00
< div class = " dropdown-menu " >
'.printDropdownBookmarksList().'
</ div >
</ div > ' ;
2020-10-27 19:46:07 +01:00
$html .= '
2020-03-25 15:40:02 +01:00
<!-- Code to show / hide the bookmark drop - down -->
< script >
2022-12-24 15:32:20 +01:00
jQuery ( document ) . ready ( function () {
jQuery ( document ) . on ( " click " , function ( event ) {
2020-03-25 15:40:02 +01:00
if ( ! $ ( event . target ) . closest ( " #topmenu-bookmark-dropdown " ) . length ) {
//console.log("close bookmark dropdown - we click outside");
// Hide the menus.
$ ( " #topmenu-bookmark-dropdown " ) . removeClass ( " open " );
}
});
2019-09-29 18:56:28 +02:00
2022-12-24 15:32:20 +01:00
jQuery ( " #topmenu-bookmark-dropdown .dropdown-toggle " ) . on ( " click " , function ( event ) {
2020-03-25 15:40:02 +01:00
console . log ( " toggle bookmark dropdown " );
openBookMarkDropDown ();
});
2019-09-29 18:56:28 +02:00
2020-03-25 15:40:02 +01:00
// Key map shortcut
2022-12-24 15:32:20 +01:00
jQuery ( document ) . keydown ( function ( e ){
2020-03-25 15:40:02 +01:00
if ( e . which === 77 && e . ctrlKey && e . shiftKey ){
console . log ( \ ' control + shift + m : trigger open bookmark dropdown\ ' );
openBookMarkDropDown ();
}
});
2019-10-11 12:28:13 +02:00
2020-03-25 15:40:02 +01:00
var openBookMarkDropDown = function () {
event . preventDefault ();
2022-12-24 15:32:20 +01:00
jQuery ( " #topmenu-bookmark-dropdown " ) . toggleClass ( " open " );
jQuery ( " #top-bookmark-search-input " ) . focus ();
2020-03-25 15:40:02 +01:00
}
2019-09-29 18:56:28 +02:00
2020-03-25 15:40:02 +01:00
});
</ script >
' ;
2020-10-27 19:46:07 +01:00
}
}
return $html ;
2019-09-29 18:56:28 +02:00
}
/**
* Build the tooltip on top menu tsearch
*
* @ return string HTML content
*/
2019-10-17 20:59:42 +02:00
function top_menu_search ()
2019-09-29 18:56:28 +02:00
{
2020-10-27 19:46:07 +01:00
global $langs , $conf , $db , $user , $hookmanager ;
2019-10-17 20:59:42 +02:00
$html = '' ;
2019-09-29 18:56:28 +02:00
2020-10-27 19:46:07 +01:00
$usedbyinclude = 1 ;
$arrayresult = null ;
include DOL_DOCUMENT_ROOT . '/core/ajax/selectsearchbox.php' ; // This set $arrayresult
$defaultAction = '' ;
$buttonList = '<div class="dropdown-global-search-button-list" >' ;
// Menu with all searchable items
2021-02-23 20:26:57 +01:00
foreach ( $arrayresult as $keyItem => $item ) {
2020-10-27 19:46:07 +01:00
if ( empty ( $defaultAction )) {
$defaultAction = $item [ 'url' ];
}
$buttonList .= '<button class="dropdown-item global-search-item" data-target="' . dol_escape_htmltag ( $item [ 'url' ]) . '" >' ;
$buttonList .= $item [ 'text' ];
$buttonList .= '</button>' ;
}
$buttonList .= '</div>' ;
2019-09-29 18:56:28 +02:00
2020-10-27 19:46:07 +01:00
$searchInput = '<input name="sall" id="top-global-search-input" class="dropdown-search-input" placeholder="' . $langs -> trans ( 'Search' ) . '" autocomplete="off" >' ;
2019-09-29 18:56:28 +02:00
2020-10-27 19:46:07 +01:00
$dropDownHtml = '<form id="top-menu-action-search" name="actionsearch" method="GET" action="' . $defaultAction . '" >' ;
2019-09-29 18:56:28 +02:00
2020-10-27 19:46:07 +01:00
$dropDownHtml .= '
2019-09-29 18:56:28 +02:00
<!-- search input -->
< div class = " dropdown-header search-dropdown-header " >
2019-11-22 14:16:38 +01:00
' . $searchInput.'
2019-09-29 18:56:28 +02:00
</ div >
' ;
2020-10-27 19:46:07 +01:00
$dropDownHtml .= '
2019-09-29 18:56:28 +02:00
<!-- Menu Body -->
< div class = " dropdown-body search-dropdown-body " >
'.$buttonList.'
</ div >
' ;
2020-10-27 19:46:07 +01:00
$dropDownHtml .= '</form>' ;
2019-09-29 18:56:28 +02:00
2020-10-27 19:46:07 +01:00
$html .= ' <!-- div for Global Search -->
2019-09-29 18:56:28 +02:00
< div id = " topmenu-global-search-dropdown " class = " atoplogin dropdown inline-block " >
< a class = " dropdown-toggle login-dropdown-a " data - toggle = " dropdown " href = " # " title = " '. $langs->trans ('Search').' ('. $langs->trans ('SearchMenuShortCut').') " >
< i class = " fa fa-search " ></ i >
</ a >
2021-06-19 16:56:08 +02:00
< div class = " dropdown-menu dropdown-search " >
2019-09-29 18:56:28 +02:00
'.$dropDownHtml.'
</ div >
</ div > ' ;
2020-10-27 19:46:07 +01:00
$html .= '
2019-09-29 18:56:28 +02:00
<!-- Code to show / hide the user drop - down -->
< script >
2022-12-24 15:32:20 +01:00
jQuery ( document ) . ready ( function () {
2019-10-11 12:28:13 +02:00
2019-09-29 18:56:28 +02:00
// prevent submiting form on press ENTER
2022-12-24 15:32:20 +01:00
jQuery ( " #top-global-search-input " ) . keydown ( function ( e ) {
2019-09-29 18:56:28 +02:00
if ( e . keyCode == 13 ) {
var inputs = $ ( this ) . parents ( " form " ) . eq ( 0 ) . find ( " :button " );
2019-10-11 12:28:13 +02:00
if ( inputs [ inputs . index ( this ) + 1 ] != null ) {
2019-09-29 18:56:28 +02:00
inputs [ inputs . index ( this ) + 1 ] . focus ();
}
e . preventDefault ();
return false ;
}
});
2019-10-11 12:28:13 +02:00
2021-06-19 16:56:08 +02:00
// arrow key nav
2022-12-24 15:32:20 +01:00
jQuery ( document ) . keydown ( function ( e ) {
2021-06-19 16:56:08 +02:00
// Get the focused element:
var $focused = $ ( " :focus " );
if ( $focused . length && $focused . hasClass ( " global-search-item " )){
// UP - move to the previous line
if ( e . keyCode == 38 ) {
e . preventDefault ();
$focused . prev () . focus ();
}
// DOWN - move to the next line
if ( e . keyCode == 40 ) {
e . preventDefault ();
$focused . next () . focus ();
}
}
});
2019-10-11 12:28:13 +02:00
2019-09-29 18:56:28 +02:00
// submit form action
2022-12-24 15:32:20 +01:00
jQuery ( " .dropdown-global-search-button-list .global-search-item " ) . on ( " click " , function ( event ) {
jQuery ( " #top-menu-action-search " ) . attr ( " action " , $ ( this ) . data ( " target " ));
jQuery ( " #top-menu-action-search " ) . submit ();
2019-09-29 18:56:28 +02:00
});
2019-10-11 12:28:13 +02:00
2019-09-29 18:56:28 +02:00
// close drop down
2022-12-24 15:32:20 +01:00
jQuery ( document ) . on ( " click " , function ( event ) {
2020-02-20 15:25:32 +01:00
if ( ! $ ( event . target ) . closest ( " #topmenu-global-search-dropdown " ) . length ) {
2020-02-23 21:38:24 +01:00
console . log ( " click close search - we click outside " );
2019-09-29 18:56:28 +02:00
// Hide the menus.
2022-12-24 15:32:20 +01:00
jQuery ( " #topmenu-global-search-dropdown " ) . removeClass ( " open " );
2019-09-29 18:56:28 +02:00
}
});
// Open drop down
2022-12-24 15:32:20 +01:00
jQuery ( " #topmenu-global-search-dropdown .dropdown-toggle " ) . on ( " click " , function ( event ) {
2020-02-23 21:38:24 +01:00
console . log ( " toggle search dropdown " );
2019-09-29 18:56:28 +02:00
openGlobalSearchDropDown ();
});
// Key map shortcut
2022-12-24 15:32:20 +01:00
jQuery ( document ) . keydown ( function ( e ){
2019-09-29 18:56:28 +02:00
if ( e . which === 70 && e . ctrlKey && e . shiftKey ){
console . log ( \ ' control + shift + f : trigger open global - search dropdown\ ' );
openGlobalSearchDropDown ();
2019-10-11 12:28:13 +02:00
}
2019-09-29 18:56:28 +02:00
});
2019-10-11 12:28:13 +02:00
2019-09-29 18:56:28 +02:00
var openGlobalSearchDropDown = function () {
2022-12-24 15:32:20 +01:00
jQuery ( " #topmenu-global-search-dropdown " ) . toggleClass ( " open " );
jQuery ( " #top-global-search-input " ) . focus ();
2019-09-29 18:56:28 +02:00
}
});
</ script >
' ;
2020-10-27 19:46:07 +01:00
return $html ;
2019-09-29 11:47:34 +02:00
}
2005-01-01 20:48:22 +01:00
/**
2010-11-05 21:11:33 +01:00
* Show left menu bar
2011-09-25 00:43:52 +02:00
*
2016-02-04 17:55:30 +01:00
* @ param array $menu_array_before Table of menu entries to show before entries of menu handler . This param is deprectaed and must be provided to '' .
2011-09-25 00:43:52 +02:00
* @ param string $helppagename Name of wiki page for help ( '' by default ) .
* Syntax is : For a wiki page : EN : EnglishPage | FR : FrenchPage | ES : SpanishPage
2018-08-09 11:50:07 +02:00
* For other external page : http :// server / url
2015-10-30 09:36:57 +01:00
* @ param string $notused Deprecated . Used in past to add content into left menu . Hooks can be used now .
2011-09-25 00:43:52 +02:00
* @ param array $menu_array_after Table of menu entries to show after entries of menu handler
* @ param int $leftmenuwithoutmainarea Must be set to 1. 0 by default for backward compatibility with old modules .
* @ param string $title Title of web page
2015-11-07 15:13:51 +01:00
* @ param string $acceptdelayedhtml 1 if caller request to have html delayed content not returned but saved into global $delayedhtmlcontent ( so caller can show it at end of page to avoid flash FOUC effect )
2011-09-25 00:43:52 +02:00
* @ return void
2003-01-13 22:33:41 +01:00
*/
2019-01-27 15:20:16 +01:00
function left_menu ( $menu_array_before , $helppagename = '' , $notused = '' , $menu_array_after = '' , $leftmenuwithoutmainarea = 0 , $title = '' , $acceptdelayedhtml = 0 )
2003-01-13 22:33:41 +01:00
{
2017-10-16 08:47:05 +02:00
global $user , $conf , $langs , $db , $form ;
global $hookmanager , $menumanager ;
2002-05-09 16:57:48 +02:00
2019-11-22 14:16:38 +01:00
$searchform = '' ;
2009-02-24 03:41:21 +01:00
2021-02-23 20:26:57 +01:00
if ( ! empty ( $menu_array_before )) {
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 );
}
2016-03-18 10:56:55 +01:00
2021-02-23 20:26:57 +01:00
if ( empty ( $conf -> dol_hide_leftmenu ) && ( ! defined ( 'NOREQUIREMENU' ) || ! constant ( 'NOREQUIREMENU' ))) {
2020-12-08 22:16:38 +01:00
// Instantiate hooks for external modules
2019-11-22 14:16:38 +01:00
$hookmanager -> initHooks ( array ( 'searchform' , 'leftblock' ));
2013-06-19 00:11:42 +02:00
2017-02-24 21:13:40 +01:00
print " \n " . '<!-- Begin side-nav id-left -->' . " \n " . '<div class="side-nav"><div id="id-left">' . " \n " ;
2012-08-05 21:14:17 +02:00
2021-02-23 20:26:57 +01:00
if ( $conf -> browser -> layout == 'phone' ) {
$conf -> global -> MAIN_USE_OLD_SEARCH_FORM = 1 ; // Select into select2 is awfull on smartphone. TODO Is this still true with select2 v4 ?
}
2017-10-16 08:47:05 +02:00
2017-11-14 15:10:46 +01:00
print " \n " ;
2018-03-21 15:08:20 +01:00
2021-02-23 20:26:57 +01:00
if ( ! is_object ( $form )) {
$form = new Form ( $db );
}
2019-11-22 14:16:38 +01:00
$selected = - 1 ;
2020-10-27 19:46:07 +01:00
if ( empty ( $conf -> global -> MAIN_USE_TOP_MENU_SEARCH_DROPDOWN )) {
$usedbyinclude = 1 ;
2023-01-06 19:34:45 +01:00
$arrayresult = array ();
2020-10-27 19:46:07 +01:00
include DOL_DOCUMENT_ROOT . '/core/ajax/selectsearchbox.php' ; // This set $arrayresult
2015-11-12 12:22:21 +01:00
2020-10-27 19:46:07 +01:00
if ( $conf -> use_javascript_ajax && empty ( $conf -> global -> MAIN_USE_OLD_SEARCH_FORM )) {
$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 );
} else {
if ( is_array ( $arrayresult )) {
foreach ( $arrayresult as $key => $val ) {
2022-07-28 18:06:37 +02:00
$searchform .= printSearchForm ( $val [ 'url' ], $val [ 'url' ], $val [ 'label' ], 'maxwidth125' , 'sall' , ( empty ( $val [ 'shortcut' ]) ? '' : $val [ 'shortcut' ]), 'searchleft' . $key , $val [ 'img' ]);
2020-10-27 19:46:07 +01:00
}
}
}
// Execute hook printSearchForm
$parameters = array ( 'searchform' => $searchform );
$reshook = $hookmanager -> executeHooks ( 'printSearchForm' , $parameters ); // Note that $action and $object may have been modified by some hooks
if ( empty ( $reshook )) {
$searchform .= $hookmanager -> resPrint ;
2021-02-23 20:26:57 +01:00
} else {
$searchform = $hookmanager -> resPrint ;
}
2020-10-27 19:46:07 +01:00
// Force special value for $searchform
if ( ! empty ( $conf -> global -> MAIN_OPTIMIZEFORTEXTBROWSER ) || empty ( $conf -> use_javascript_ajax )) {
$urltosearch = DOL_URL_ROOT . '/core/search_page.php?showtitlebefore=1' ;
$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>' ;
} elseif ( $conf -> use_javascript_ajax && ! empty ( $conf -> global -> MAIN_USE_OLD_SEARCH_FORM )) {
$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>' ;
$searchform .= ' < script >
2016-01-03 19:34:19 +01:00
jQuery ( document ) . ready ( function () {
jQuery ( " #divsearchforms1 " ) . click ( function (){
jQuery ( " #divsearchforms2 " ) . toggle ();
});
});
</ script > ' . " \n " ;
2020-10-27 19:46:07 +01:00
$searchform .= '</div>' ;
}
}
2016-03-18 10:56:55 +01:00
2017-10-16 08:47:05 +02:00
// Left column
print '<!-- Begin left menu -->' . " \n " ;
2012-08-05 21:14:17 +02:00
2019-11-22 14:16:38 +01:00
print '<div class="vmenu"' . ( empty ( $conf -> global -> MAIN_OPTIMIZEFORTEXTBROWSER ) ? '' : ' title="Left menu"' ) . '>' . " \n \n " ;
2012-08-05 21:14:17 +02:00
2017-10-16 08:47:05 +02:00
// Show left menu with other forms
$menumanager -> menu_array = $menu_array_before ;
$menumanager -> menu_array_after = $menu_array_after ;
2021-10-25 12:09:17 +02:00
$menumanager -> showmenu ( 'left' , array ( 'searchform' => $searchform )); // output menu_array and menu found in database
2012-08-05 21:14:17 +02:00
2017-10-16 08:47:05 +02:00
// Dolibarr version + help + bug report link
2015-10-30 09:36:57 +01:00
print " \n " ;
2017-10-16 08:47:05 +02:00
print " <!-- Begin Help Block--> \n " ;
print '<div id="blockvmenuhelp" class="blockvmenuhelp">' . " \n " ;
2013-12-02 12:34:46 +01:00
2017-10-16 08:47:05 +02:00
// Version
2021-02-23 20:26:57 +01:00
if ( ! empty ( $conf -> global -> MAIN_SHOW_VERSION )) { // Version is already on help picto and on login page.
2019-11-13 19:37:08 +01:00
$doliurl = 'https://www.dolibarr.org' ;
2017-10-16 08:47:05 +02:00
//local communities
2021-02-23 20:26:57 +01:00
if ( preg_match ( '/fr/i' , $langs -> defaultlang )) {
$doliurl = 'https://www.dolibarr.fr' ;
}
if ( preg_match ( '/es/i' , $langs -> defaultlang )) {
$doliurl = 'https://www.dolibarr.es' ;
}
if ( preg_match ( '/de/i' , $langs -> defaultlang )) {
$doliurl = 'https://www.dolibarr.de' ;
}
if ( preg_match ( '/it/i' , $langs -> defaultlang )) {
$doliurl = 'https://www.dolibarr.it' ;
}
if ( preg_match ( '/gr/i' , $langs -> defaultlang )) {
$doliurl = 'https://www.dolibarr.gr' ;
}
2019-11-13 19:37:08 +01:00
$appli = constant ( 'DOL_APPLICATION_TITLE' );
2021-02-23 20:26:57 +01:00
if ( ! empty ( $conf -> global -> MAIN_APPLICATION_TITLE )) {
2019-11-13 19:37:08 +01:00
$appli = $conf -> global -> MAIN_APPLICATION_TITLE ; $doliurl = '' ;
2021-02-23 20:26:57 +01:00
if ( preg_match ( '/\d\.\d/' , $appli )) {
if ( ! preg_match ( '/' . preg_quote ( DOL_VERSION ) . '/' , $appli )) {
$appli .= " ( " . DOL_VERSION . " ) " ; // If new title contains a version that is different than core
}
} else {
$appli .= " " . DOL_VERSION ;
}
} else {
$appli .= " " . DOL_VERSION ;
}
2017-10-16 08:47:05 +02:00
print '<div id="blockvmenuhelpapp" class="blockvmenuhelp">' ;
2021-02-23 20:26:57 +01:00
if ( $doliurl ) {
2021-11-22 02:35:55 +01:00
print '<a class="help" target="_blank" rel="noopener noreferrer" href="' . $doliurl . '">' ;
2021-02-23 20:26:57 +01:00
} else {
print '<span class="help">' ;
}
2017-10-16 08:47:05 +02:00
print $appli ;
2021-02-23 20:26:57 +01:00
if ( $doliurl ) {
print '</a>' ;
} else {
print '</span>' ;
}
2017-10-16 08:47:05 +02:00
print '</div>' . " \n " ;
}
2013-06-05 16:24:32 +02:00
2015-04-28 21:14:17 +02:00
// Link to bugtrack
2021-02-23 20:26:57 +01:00
if ( ! empty ( $conf -> global -> MAIN_BUGTRACK_ENABLELINK )) {
2015-04-27 20:34:52 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/functions2.lib.php' ;
2021-04-14 23:16:30 +02:00
if ( $conf -> global -> MAIN_BUGTRACK_ENABLELINK == 'github' ) {
2021-04-12 22:01:46 +02:00
$bugbaseurl = 'https://github.com/Dolibarr/dolibarr/issues/new?labels=Bug' ;
$bugbaseurl .= '&title=' ;
$bugbaseurl .= urlencode ( " Bug: " );
$bugbaseurl .= '&body=' ;
$bugbaseurl .= urlencode ( " # Instructions \n " );
$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 " );
$bugbaseurl .= urlencode ( " *Please:* \n " );
$bugbaseurl .= urlencode ( " - *replace the bracket enclosed texts with meaningful information* \n " );
$bugbaseurl .= urlencode ( " - *remove any unused sub-section* \n " );
$bugbaseurl .= urlencode ( " \n " );
$bugbaseurl .= urlencode ( " \n " );
$bugbaseurl .= urlencode ( " # Bug \n " );
$bugbaseurl .= urlencode ( " [*Short description*] \n " );
$bugbaseurl .= urlencode ( " \n " );
$bugbaseurl .= urlencode ( " ## Environment \n " );
2021-10-23 22:22:10 +02:00
$bugbaseurl .= urlencode ( " - **Version**: " . DOL_VERSION . " \n " );
$bugbaseurl .= urlencode ( " - **OS**: " . php_uname ( 's' ) . " \n " );
$bugbaseurl .= urlencode ( " - **Web server**: " . $_SERVER [ " SERVER_SOFTWARE " ] . " \n " );
$bugbaseurl .= urlencode ( " - **PHP**: " . php_sapi_name () . ' ' . phpversion () . " \n " );
$bugbaseurl .= urlencode ( " - **Database**: " . $db :: LABEL . ' ' . $db -> getVersion () . " \n " );
$bugbaseurl .= urlencode ( " - **URL(s)**: " . $_SERVER [ " REQUEST_URI " ] . " \n " );
2021-04-12 22:01:46 +02:00
$bugbaseurl .= urlencode ( " \n " );
$bugbaseurl .= urlencode ( " ## Expected and actual behavior \n " );
$bugbaseurl .= urlencode ( " [*Verbose description*] \n " );
$bugbaseurl .= urlencode ( " \n " );
$bugbaseurl .= urlencode ( " ## Steps to reproduce the behavior \n " );
$bugbaseurl .= urlencode ( " [*Verbose description*] \n " );
$bugbaseurl .= urlencode ( " \n " );
$bugbaseurl .= urlencode ( " ## [Attached files](https://help.github.com/articles/issue-attachments) (Screenshots, screencasts, dolibarr.log, debugging informations…) \n " );
$bugbaseurl .= urlencode ( " [*Files*] \n " );
$bugbaseurl .= urlencode ( " \n " );
2021-04-14 23:16:30 +02:00
$bugbaseurl .= urlencode ( " \n " );
$bugbaseurl .= urlencode ( " ## Report \n " );
} elseif ( ! empty ( $conf -> global -> MAIN_BUGTRACK_ENABLELINK )) {
$bugbaseurl = $conf -> global -> MAIN_BUGTRACK_ENABLELINK ;
} else {
$bugbaseurl = " " ;
2021-04-12 22:01:46 +02:00
}
2019-09-10 17:50:55 +02:00
2019-05-10 12:24:02 +02:00
// Execute hook printBugtrackInfo
2021-04-14 23:16:30 +02:00
$parameters = array ( 'bugbaseurl' => $bugbaseurl );
2019-11-22 14:16:38 +01:00
$reshook = $hookmanager -> executeHooks ( 'printBugtrackInfo' , $parameters ); // Note that $action and $object may have been modified by some hooks
2021-02-23 20:26:57 +01:00
if ( empty ( $reshook )) {
2019-11-22 14:16:38 +01:00
$bugbaseurl .= $hookmanager -> resPrint ;
2021-02-23 20:26:57 +01:00
} else {
$bugbaseurl = $hookmanager -> resPrint ;
}
2019-05-10 12:24:02 +02:00
2015-12-04 12:12:12 +01:00
print '<div id="blockvmenuhelpbugreport" class="blockvmenuhelp">' ;
2022-10-06 13:51:40 +02:00
print '<a class="help" target="_blank" rel="noopener noreferrer" href="' . $bugbaseurl . '"><i class="fas fa-bug"></i> ' . $langs -> trans ( " FindBug " ) . '</a>' ;
2015-12-04 12:12:12 +01:00
print '</div>' ;
2015-04-27 20:34:52 +02:00
}
2012-08-05 21:14:17 +02:00
2017-10-16 08:47:05 +02:00
print " </div> \n " ;
print " <!-- End Help Block--> \n " ;
print " \n " ;
2012-08-05 21:14:17 +02:00
2017-10-16 08:47:05 +02:00
print " </div> \n " ;
print " <!-- End left menu --> \n " ;
print " \n " ;
2012-08-05 21:14:17 +02:00
2017-10-16 08:47:05 +02:00
// Execute hook printLeftBlock
2019-11-13 19:37:08 +01:00
$parameters = array ();
$reshook = $hookmanager -> executeHooks ( 'printLeftBlock' , $parameters ); // Note that $action and $object may have been modified by some hooks
2017-10-16 08:47:05 +02:00
print $hookmanager -> resPrint ;
2012-08-05 21:14:17 +02:00
2019-11-13 19:37:08 +01:00
print '</div></div> <!-- End side-nav id-left -->' ; // End div id="side-nav" div id="id-left"
2017-10-16 08:47:05 +02:00
}
2012-02-22 12:02:12 +01:00
2017-10-16 08:47:05 +02:00
print " \n " ;
print '<!-- Begin right area -->' . " \n " ;
2011-02-16 20:59:16 +01:00
2021-02-23 20:26:57 +01:00
if ( empty ( $leftmenuwithoutmainarea )) {
main_area ( $title );
}
2010-10-29 19:54:15 +02:00
}
2008-09-30 02:10:49 +02:00
2011-09-25 00:43:52 +02:00
2010-10-29 19:54:15 +02:00
/**
* Begin main area
2011-09-25 00:43:52 +02:00
*
* @ param string $title Title
* @ return void
2010-10-29 19:54:15 +02:00
*/
2019-01-27 15:20:16 +01:00
function main_area ( $title = '' )
2010-10-29 19:54:15 +02:00
{
2022-01-16 21:10:02 +01:00
global $conf , $langs , $hookmanager ;
2010-11-02 13:14:06 +01:00
2022-12-26 15:14:55 +01:00
if ( empty ( $conf -> dol_hide_leftmenu ) && ! GETPOST ( 'dol_openinpopup' )) {
2021-02-23 20:26:57 +01:00
print '<div id="id-right">' ;
}
2010-11-02 13:14:06 +01:00
2017-10-16 08:47:05 +02:00
print " \n " ;
2010-11-02 13:14:06 +01:00
2017-10-16 08:47:05 +02:00
print '<!-- Begin div class="fiche" -->' . " \n " . '<div class="fiche">' . " \n " ;
2017-06-10 16:29:25 +02:00
2022-01-16 21:10:02 +01:00
$hookmanager -> initHooks ( array ( 'main' ));
$parameters = array ();
$reshook = $hookmanager -> executeHooks ( 'printMainArea' , $parameters ); // Note that $action and $object may have been modified by some hooks
print $hookmanager -> resPrint ;
2021-02-23 20:26:57 +01:00
if ( ! empty ( $conf -> global -> MAIN_ONLY_LOGIN_ALLOWED )) {
print info_admin ( $langs -> trans ( " WarningYouAreInMaintenanceMode " , $conf -> global -> MAIN_ONLY_LOGIN_ALLOWED ), 0 , 0 , 1 , 'warning maintenancemode' );
}
2020-04-20 15:49:31 +02:00
2020-12-08 22:16:38 +01:00
// Permit to add user company information on each printed document by setting SHOW_SOCINFO_ON_PRINT
2021-02-23 20:26:57 +01:00
if ( ! empty ( $conf -> global -> SHOW_SOCINFO_ON_PRINT ) && GETPOST ( 'optioncss' , 'aZ09' ) == 'print' && empty ( GETPOST ( 'disable_show_socinfo_on_print' , 'az09' ))) {
2020-10-27 19:46:07 +01:00
$parameters = array ();
$reshook = $hookmanager -> executeHooks ( 'showSocinfoOnPrint' , $parameters );
2021-02-23 20:26:57 +01:00
if ( empty ( $reshook )) {
2020-10-27 19:46:07 +01:00
print '<!-- Begin show mysoc info header -->' . " \n " ;
print '<div id="mysoc-info-header">' . " \n " ;
print '<table class="centpercent div-table-responsive">' . " \n " ;
print '<tbody>' ;
print '<tr><td rowspan="0" class="width20p">' ;
if ( $conf -> global -> MAIN_SHOW_LOGO && empty ( $conf -> global -> MAIN_OPTIMIZEFORTEXTBROWSER ) && ! empty ( $conf -> global -> MAIN_INFO_SOCIETE_LOGO )) {
2022-12-13 18:40:30 +01:00
print '<img id="mysoc-info-header-logo" style="max-width:100%" alt="" src="' . DOL_URL_ROOT . '/viewimage.php?cache=1&modulepart=mycompany&file=' . urlencode ( 'logos/' . dol_escape_htmltag ( $conf -> global -> MAIN_INFO_SOCIETE_LOGO )) . '">' ;
2020-10-27 19:46:07 +01:00
}
print '</td><td rowspan="0" class="width50p"></td></tr>' . " \n " ;
print '<tr><td class="titre bold">' . dol_escape_htmltag ( $conf -> global -> MAIN_INFO_SOCIETE_NOM ) . '</td></tr>' . " \n " ;
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 " ;
2021-02-23 20:26:57 +01:00
if ( ! empty ( $conf -> global -> MAIN_INFO_SOCIETE_TEL )) {
print '<tr><td style="padding-left: 1em" class="small">' . $langs -> trans ( " Phone " ) . ' : ' . dol_escape_htmltag ( $conf -> global -> MAIN_INFO_SOCIETE_TEL ) . '</td></tr>' ;
}
if ( ! empty ( $conf -> global -> MAIN_INFO_SOCIETE_MAIL )) {
print '<tr><td style="padding-left: 1em" class="small">' . $langs -> trans ( " Email " ) . ' : ' . dol_escape_htmltag ( $conf -> global -> MAIN_INFO_SOCIETE_MAIL ) . '</td></tr>' ;
}
if ( ! empty ( $conf -> global -> MAIN_INFO_SOCIETE_WEB )) {
print '<tr><td style="padding-left: 1em" class="small">' . $langs -> trans ( " Web " ) . ' : ' . dol_escape_htmltag ( $conf -> global -> MAIN_INFO_SOCIETE_WEB ) . '</td></tr>' ;
}
2020-10-27 19:46:07 +01:00
print '</tbody>' ;
print '</table>' . " \n " ;
print '</div>' . " \n " ;
print '<!-- End show mysoc info header -->' . " \n " ;
}
}
2002-05-04 01:01:45 +02:00
}
2004-08-13 23:45:23 +02:00
2009-10-04 00:32:10 +02:00
/**
2011-02-20 14:04:53 +01:00
* Return helpbaseurl , helppage and mode
2011-09-25 00:43:52 +02:00
*
2012-11-10 16:24:20 +01:00
* @ param string $helppagename Page name ( 'EN:xxx,ES:eee,FR:fff...' or 'http://localpage' )
2011-09-25 00:43:52 +02:00
* @ param Translate $langs Language
* @ return array Array of help urls
2009-10-04 00:32:10 +02:00
*/
2019-01-27 15:20:16 +01:00
function getHelpParamFor ( $helppagename , $langs )
2009-10-04 00:32:10 +02:00
{
2019-11-13 19:37:08 +01:00
$helpbaseurl = '' ;
$helppage = '' ;
$mode = '' ;
2012-07-09 12:31:21 +02:00
2021-02-23 20:26:57 +01:00
if ( preg_match ( '/^http/i' , $helppagename )) {
2017-10-16 08:47:05 +02:00
// If complete URL
2019-11-13 19:37:08 +01:00
$helpbaseurl = '%s' ;
$helppage = $helppagename ;
$mode = 'local' ;
2020-05-21 01:03:03 +02:00
} else {
2017-10-16 08:47:05 +02:00
// If WIKI URL
2019-12-22 13:19:14 +01:00
$reg = array ();
2021-02-23 20:26:57 +01:00
if ( preg_match ( '/^es/i' , $langs -> defaultlang )) {
2019-11-13 19:37:08 +01:00
$helpbaseurl = 'http://wiki.dolibarr.org/index.php/%s' ;
2021-02-23 20:26:57 +01:00
if ( preg_match ( '/ES:([^|]+)/i' , $helppagename , $reg )) {
$helppage = $reg [ 1 ];
}
2017-10-16 08:47:05 +02:00
}
2021-02-23 20:26:57 +01:00
if ( preg_match ( '/^fr/i' , $langs -> defaultlang )) {
2019-11-13 19:37:08 +01:00
$helpbaseurl = 'http://wiki.dolibarr.org/index.php/%s' ;
2021-02-23 20:26:57 +01:00
if ( preg_match ( '/FR:([^|]+)/i' , $helppagename , $reg )) {
$helppage = $reg [ 1 ];
}
2017-10-16 08:47:05 +02:00
}
2021-02-23 20:26:57 +01:00
if ( empty ( $helppage )) { // If help page not already found
2019-11-13 19:37:08 +01:00
$helpbaseurl = 'http://wiki.dolibarr.org/index.php/%s' ;
2021-02-23 20:26:57 +01:00
if ( preg_match ( '/EN:([^|]+)/i' , $helppagename , $reg )) {
$helppage = $reg [ 1 ];
}
2017-10-16 08:47:05 +02:00
}
2019-11-13 19:37:08 +01:00
$mode = 'wiki' ;
2017-10-16 08:47:05 +02:00
}
2019-11-13 19:37:08 +01:00
return array ( 'helpbaseurl' => $helpbaseurl , 'helppage' => $helppage , 'mode' => $mode );
2009-10-04 00:32:10 +02:00
}
2004-08-13 23:45:23 +02:00
2005-01-01 20:48:22 +01:00
/**
2017-11-01 10:09:39 +01:00
* Show a search area .
* Used when the javascript quick search is not used .
2011-08-23 00:26:57 +02:00
*
2011-09-25 00:43:52 +02:00
* @ param string $urlaction Url post
* @ param string $urlobject Url of the link under the search box
* @ param string $title Title search area
2016-09-03 12:56:49 +02:00
* @ param string $htmlmorecss Add more css
2011-09-25 00:43:52 +02:00
* @ param string $htmlinputname Field Name input form
2014-07-29 22:04:53 +02:00
* @ param string $accesskey Accesskey
2015-10-16 22:21:26 +02:00
* @ param string $prefhtmlinputname Complement for id to avoid multiple same id in the page
2015-06-16 13:09:46 +02:00
* @ param string $img Image to use
2017-11-14 15:10:46 +01:00
* @ param string $showtitlebefore Show title before input text instead of into placeholder . This can be set when output is dedicated for text browsers .
2018-12-28 00:41:05 +01:00
* @ param string $autofocus Set autofocus on field
2014-04-23 18:07:47 +02:00
* @ return string
2004-08-13 23:45:23 +02:00
*/
2019-01-27 15:20:16 +01:00
function printSearchForm ( $urlaction , $urlobject , $title , $htmlmorecss , $htmlinputname , $accesskey = '' , $prefhtmlinputname = '' , $img = '' , $showtitlebefore = 0 , $autofocus = 0 )
2004-08-13 23:45:23 +02:00
{
2019-11-22 14:16:38 +01:00
global $conf , $langs , $user ;
$ret = '' ;
$ret .= '<form action="' . $urlaction . '" method="post" class="searchform nowraponall tagtr">' ;
2019-12-01 10:20:11 +01:00
$ret .= '<input type="hidden" name="token" value="' . newToken () . '">' ;
2019-11-22 14:16:38 +01:00
$ret .= '<input type="hidden" name="savelogin" value="' . dol_escape_htmltag ( $user -> login ) . '">' ;
2021-02-23 20:26:57 +01:00
if ( $showtitlebefore ) {
$ret .= '<div class="tagtd left">' . $title . '</div> ' ;
}
2019-11-22 14:16:38 +01:00
$ret .= '<div class="tagtd">' ;
2020-05-10 15:45:07 +02:00
$ret .= img_picto ( '' , $img , '' , false , 0 , 0 , '' , 'paddingright width20' );
2019-11-22 14:16:38 +01:00
$ret .= '<input type="text" class="flat ' . $htmlmorecss . '"' ;
2020-05-10 15:45:07 +02:00
$ret .= ' style="background-repeat: no-repeat; background-position: 3px;"' ;
2019-11-22 14:16:38 +01:00
$ret .= ( $accesskey ? ' accesskey="' . $accesskey . '"' : '' );
$ret .= ' placeholder="' . strip_tags ( $title ) . '"' ;
$ret .= ( $autofocus ? ' autofocus' : '' );
$ret .= ' name="' . $htmlinputname . '" id="' . $prefhtmlinputname . $htmlinputname . '" />' ;
2020-05-10 15:45:07 +02:00
$ret .= '<button type="submit" class="button bordertransp" style="padding-top: 4px; padding-bottom: 4px; padding-left: 6px; padding-right: 6px">' ;
2019-11-22 14:16:38 +01:00
$ret .= '<span class="fa fa-search"></span>' ;
$ret .= '</button>' ;
$ret .= '</div>' ;
$ret .= " </form> \n " ;
2017-10-16 08:47:05 +02:00
return $ret ;
2004-08-13 23:45:23 +02:00
}
2021-02-23 20:26:57 +01:00
if ( ! function_exists ( " llxFooter " )) {
2017-10-16 08:47:05 +02:00
/**
* Show HTML footer
* Close div / DIV class = fiche + / DIV id - right + / DIV id - container + / BODY + / HTML .
* If global var $delayedhtmlcontent was filled , we output it just before closing the body .
*
2017-10-28 13:36:23 +02:00
* @ param string $comment A text to add as HTML comment into HTML generated page
* @ param string $zone 'private' ( for private pages ) or 'public' ( for public pages )
* @ param int $disabledoutputofmessages Clear all messages stored into session without diplaying them
2017-10-16 08:47:05 +02:00
* @ return void
*/
2019-01-27 15:20:16 +01:00
function llxFooter ( $comment = '' , $zone = 'private' , $disabledoutputofmessages = 0 )
2017-10-16 08:47:05 +02:00
{
2021-10-05 10:41:11 +02:00
global $conf , $db , $langs , $user , $mysoc , $object , $hookmanager ;
2018-12-14 10:31:09 +01:00
global $delayedhtmlcontent ;
2022-02-09 15:21:25 +01:00
global $contextpage , $page , $limit , $mode ;
2020-10-30 12:44:29 +01:00
global $dolibarr_distrib ;
2016-03-18 10:56:55 +01:00
2023-01-02 01:53:05 +01:00
$ext = 'layout=' . urlencode ( $conf -> browser -> layout ) . '&version=' . urlencode ( DOL_VERSION );
2017-11-10 15:29:12 +01:00
2022-11-23 20:47:32 +01:00
// Hook to add more things on all pages within fiche DIV
$llxfooter = '' ;
$parameters = array ();
$reshook = $hookmanager -> executeHooks ( 'llxFooter' , $parameters , $object , $action ); // Note that $action and $object may have been modified by hook
if ( empty ( $reshook )) {
$llxfooter .= $hookmanager -> resPrint ;
} elseif ( $reshook > 0 ) {
$llxfooter = $hookmanager -> resPrint ;
}
2023-01-02 01:53:05 +01:00
if ( $llxfooter ) {
print $llxfooter ;
}
2022-11-23 20:47:32 +01:00
2017-10-16 08:47:05 +02:00
// Global html output events ($mesgs, $errors, $warnings)
2017-10-28 13:36:23 +02:00
dol_htmloutput_events ( $disabledoutputofmessages );
2012-07-29 08:26:33 +02:00
2017-10-16 08:47:05 +02:00
// Code for search criteria persistence.
2018-06-23 11:55:04 +02:00
// $user->lastsearch_values was set by the GETPOST when form field search_xxx exists
2021-02-23 20:26:57 +01:00
if ( is_object ( $user ) && ! empty ( $user -> lastsearch_values_tmp ) && is_array ( $user -> lastsearch_values_tmp )) {
2018-06-23 11:55:04 +02:00
// Clean and save data
2021-02-23 20:26:57 +01:00
foreach ( $user -> lastsearch_values_tmp as $key => $val ) {
2019-11-13 19:37:08 +01:00
unset ( $_SESSION [ 'lastsearch_values_tmp_' . $key ]); // Clean array to rebuild it just after
2022-07-07 17:15:50 +02:00
if ( count ( $val ) && empty ( $_POST [ 'button_removefilter' ]) && empty ( $_POST [ 'button_removefilter_x' ])) {
2021-02-23 20:26:57 +01:00
if ( empty ( $val [ 'sortfield' ])) {
unset ( $val [ 'sortfield' ]);
}
if ( empty ( $val [ 'sortorder' ])) {
unset ( $val [ 'sortorder' ]);
}
2018-06-23 11:55:04 +02:00
dol_syslog ( 'Save lastsearch_values_tmp_' . $key . '=' . json_encode ( $val , 0 ) . " (systematic recording of last search criterias) " );
2019-11-13 19:37:08 +01:00
$_SESSION [ 'lastsearch_values_tmp_' . $key ] = json_encode ( $val );
2017-10-16 08:47:05 +02:00
unset ( $_SESSION [ 'lastsearch_values_' . $key ]);
}
}
}
2017-05-16 23:38:23 +02:00
2018-06-23 11:55:04 +02:00
$relativepathstring = $_SERVER [ " PHP_SELF " ];
// Clean $relativepathstring
2021-02-23 20:26:57 +01:00
if ( constant ( 'DOL_URL_ROOT' )) {
$relativepathstring = preg_replace ( '/^' . preg_quote ( constant ( 'DOL_URL_ROOT' ), '/' ) . '/' , '' , $relativepathstring );
}
2018-06-23 11:55:04 +02:00
$relativepathstring = preg_replace ( '/^\//' , '' , $relativepathstring );
$relativepathstring = preg_replace ( '/^custom\//' , '' , $relativepathstring );
2021-02-23 20:26:57 +01:00
if ( preg_match ( '/list\.php$/' , $relativepathstring )) {
2018-06-23 11:55:04 +02:00
unset ( $_SESSION [ 'lastsearch_contextpage_tmp_' . $relativepathstring ]);
2018-12-14 10:31:09 +01:00
unset ( $_SESSION [ 'lastsearch_page_tmp_' . $relativepathstring ]);
unset ( $_SESSION [ 'lastsearch_limit_tmp_' . $relativepathstring ]);
2022-02-09 15:21:25 +01:00
unset ( $_SESSION [ 'lastsearch_mode_tmp_' . $relativepathstring ]);
2018-12-14 10:31:09 +01:00
2021-02-23 20:26:57 +01:00
if ( ! empty ( $contextpage )) {
$_SESSION [ 'lastsearch_contextpage_tmp_' . $relativepathstring ] = $contextpage ;
}
if ( ! empty ( $page ) && $page > 0 ) {
$_SESSION [ 'lastsearch_page_tmp_' . $relativepathstring ] = $page ;
}
if ( ! empty ( $limit ) && $limit != $conf -> liste_limit ) {
$_SESSION [ 'lastsearch_limit_tmp_' . $relativepathstring ] = $limit ;
}
2022-02-09 15:21:25 +01:00
if ( ! empty ( $mode )) {
$_SESSION [ 'lastsearch_mode_tmp_' . $relativepathstring ] = $mode ;
}
2018-12-14 10:31:09 +01:00
2018-06-23 11:55:04 +02:00
unset ( $_SESSION [ 'lastsearch_contextpage_' . $relativepathstring ]);
2018-12-14 10:31:09 +01:00
unset ( $_SESSION [ 'lastsearch_page_' . $relativepathstring ]);
unset ( $_SESSION [ 'lastsearch_limit_' . $relativepathstring ]);
2022-02-09 15:21:25 +01:00
unset ( $_SESSION [ 'lastsearch_mode_' . $relativepathstring ]);
2018-06-23 11:55:04 +02:00
}
2017-10-16 08:47:05 +02:00
// Core error message
2021-02-23 20:26:57 +01:00
if ( ! empty ( $conf -> global -> MAIN_CORE_ERROR )) {
2017-10-16 08:47:05 +02:00
// Ajax version
2021-02-23 20:26:57 +01:00
if ( $conf -> use_javascript_ajax ) {
2017-10-16 08:47:05 +02:00
$title = img_warning () . ' ' . $langs -> trans ( 'CoreErrorTitle' );
print ajax_dialog ( $title , $langs -> trans ( 'CoreErrorMessage' ));
2020-05-21 01:03:03 +02:00
} else {
// html version
2017-10-16 08:47:05 +02:00
$msg = img_warning () . ' ' . $langs -> trans ( 'CoreErrorMessage' );
print '<div class="error">' . $msg . '</div>' ;
}
2012-02-22 12:02:12 +01:00
2017-10-16 08:47:05 +02:00
//define("MAIN_CORE_ERROR",0); // Constant was defined and we can't change value of a constant
}
2008-09-30 02:10:49 +02:00
2017-10-16 08:47:05 +02:00
print " \n \n " ;
2017-06-10 16:29:25 +02:00
2017-10-16 08:47:05 +02:00
print '</div> <!-- End div class="fiche" -->' . " \n " ; // End div fiche
2008-06-19 00:56:02 +02:00
2022-12-26 15:14:55 +01:00
if ( empty ( $conf -> dol_hide_leftmenu ) && ! GETPOST ( 'dol_openinpopup' )) {
2021-02-23 20:26:57 +01:00
print '</div> <!-- End div id-right -->' . " \n " ; // End div id-right
}
2017-11-09 01:00:43 +01:00
2021-02-23 20:26:57 +01:00
if ( empty ( $conf -> dol_hide_leftmenu ) && empty ( $conf -> dol_use_jmobile )) {
print '</div> <!-- End div id-container -->' . " \n " ; // End div container
}
2008-09-30 02:10:49 +02:00
2017-10-16 08:47:05 +02:00
print " \n " ;
2021-02-23 20:26:57 +01:00
if ( $comment ) {
print '<!-- ' . $comment . ' -->' . " \n " ;
}
2011-02-16 20:59:16 +01:00
2017-10-16 08:47:05 +02:00
printCommonFooter ( $zone );
2011-02-16 20:59:16 +01:00
2021-02-23 20:26:57 +01:00
if ( ! empty ( $delayedhtmlcontent )) {
print $delayedhtmlcontent ;
}
2016-03-18 10:56:55 +01:00
2021-02-23 20:26:57 +01:00
if ( ! empty ( $conf -> use_javascript_ajax )) {
2017-11-09 01:00:43 +01:00
print " \n " . '<!-- Includes JS Footer of Dolibarr -->' . " \n " ;
2019-11-13 19:37:08 +01:00
print '<script src="' . DOL_URL_ROOT . '/core/js/lib_foot.js.php?lang=' . $langs -> defaultlang . ( $ext ? '&' . $ext : '' ) . '"></script>' . " \n " ;
2017-10-16 08:47:05 +02:00
}
2017-11-09 09:50:55 +01:00
2017-10-16 08:47:05 +02:00
// Wrapper to add log when clicking on download or preview
2022-09-25 15:31:07 +02:00
if ( isModEnabled ( 'blockedlog' ) && is_object ( $object ) && ! empty ( $object -> id ) && $object -> id > 0 && $object -> statut > 0 ) {
2021-02-23 20:26:57 +01:00
if ( in_array ( $object -> element , array ( 'facture' ))) { // Restrict for the moment to element 'facture'
2017-10-16 08:47:05 +02:00
print " \n <!-- JS CODE TO ENABLE log when making a download or a preview of a document --> \n " ;
?>
2021-02-23 20:26:57 +01:00
< script >
jQuery ( document ) . ready ( function () {
$ ( 'a.documentpreview' ) . click ( function () {
$ . post ( '<?php echo DOL_URL_ROOT."/blockedlog/ajax/block-add.php" ?>'
, {
id :< ? php echo $object -> id ; ?>
, element : '<?php echo $object->element ?>'
, action : 'DOC_PREVIEW'
2022-02-18 16:09:23 +01:00
, token : '<?php echo currentToken(); ?>'
2021-02-23 20:26:57 +01:00
}
);
});
$ ( 'a.documentdownload' ) . click ( function () {
$ . post ( '<?php echo DOL_URL_ROOT."/blockedlog/ajax/block-add.php" ?>'
, {
id :< ? php echo $object -> id ; ?>
, element : '<?php echo $object->element ?>'
, action : 'DOC_DOWNLOAD'
2022-02-18 16:09:23 +01:00
, token : '<?php echo currentToken(); ?>'
2021-02-23 20:26:57 +01:00
}
);
});
});
</ script >
2017-06-16 11:51:33 +02:00
< ? php
2017-10-16 08:47:05 +02:00
}
2021-02-23 20:26:57 +01:00
}
2017-06-16 11:51:33 +02:00
2016-01-02 00:27:14 +01:00
// A div for the address popup
2021-11-12 13:33:59 +01:00
print " \n <!-- A div to allow dialog popup by jQuery('#dialogforpopup').dialog() --> \n " ;
2016-01-02 00:27:14 +01:00
print '<div id="dialogforpopup" style="display: none;"></div>' . " \n " ;
2016-03-18 10:56:55 +01:00
2019-08-02 20:11:55 +02:00
// Add code for the asynchronous anonymous first ping (for telemetry)
2020-01-01 14:30:16 +01:00
// You can use &forceping=1 in parameters to force the ping if the ping was already sent.
2020-01-31 17:27:48 +01:00
$forceping = GETPOST ( 'forceping' , 'alpha' );
2021-02-23 20:26:57 +01:00
if (( $_SERVER [ " PHP_SELF " ] == DOL_URL_ROOT . '/index.php' ) || $forceping ) {
2019-08-23 16:23:31 +02:00
//print '<!-- instance_unique_id='.$conf->file->instance_unique_id.' MAIN_FIRST_PING_OK_ID='.$conf->global->MAIN_FIRST_PING_OK_ID.' -->';
2022-02-21 12:21:43 +01:00
$hash_unique_id = md5 ( 'dolibarr' . $conf -> file -> instance_unique_id ); // Do not use dol_hash(), must not change if salt changes.
2021-10-24 14:23:35 +02:00
2019-08-02 19:21:25 +02:00
if ( empty ( $conf -> global -> MAIN_FIRST_PING_OK_DATE )
2019-12-20 11:31:40 +01:00
|| ( ! empty ( $conf -> file -> instance_unique_id ) && ( $hash_unique_id != $conf -> global -> MAIN_FIRST_PING_OK_ID ) && ( $conf -> global -> MAIN_FIRST_PING_OK_ID != 'disabled' ))
2021-02-23 20:26:57 +01:00
|| $forceping ) {
2020-01-31 17:27:48 +01:00
// No ping done if we are into an alpha version
2020-04-10 10:59:32 +02:00
if ( strpos ( 'alpha' , DOL_VERSION ) > 0 && ! $forceping ) {
2020-01-01 14:30:16 +01:00
print " \n <!-- NO JS CODE TO ENABLE the anonymous Ping. It is an alpha version --> \n " ;
2021-02-23 20:26:57 +01:00
} elseif ( empty ( $_COOKIE [ 'DOLINSTALLNOPING_' . $hash_unique_id ]) || $forceping ) { // Cookie is set when we uncheck the checkbox in the installation wizard.
2021-02-26 11:29:16 +01:00
// MAIN_LAST_PING_KO_DATE
2021-10-24 14:01:23 +02:00
// Disable ping if MAIN_LAST_PING_KO_DATE is set and is recent (this month)
2020-04-10 10:59:32 +02:00
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 ) {
2020-01-31 17:27:48 +01:00
print " \n <!-- NO JS CODE TO ENABLE the anonymous Ping. An error already occured this month, we will try later. --> \n " ;
} else {
include_once DOL_DOCUMENT_ROOT . '/core/lib/functions2.lib.php' ;
2021-03-20 12:35:41 +01:00
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 " ;
2020-01-31 17:27:48 +01:00
print " \n <!-- JS CODE TO ENABLE the anonymous Ping --> \n " ;
$url_for_ping = ( empty ( $conf -> global -> MAIN_URL_FOR_PING ) ? " https://ping.dolibarr.org/ " : $conf -> global -> MAIN_URL_FOR_PING );
// Try to guess the distrib used
$distrib = 'standard' ;
2021-02-23 20:26:57 +01:00
if ( $_SERVER [ " SERVER_ADMIN " ] == 'doliwamp@localhost' ) {
$distrib = 'doliwamp' ;
}
if ( ! empty ( $dolibarr_distrib )) {
$distrib = $dolibarr_distrib ;
}
2020-01-31 17:27:48 +01:00
?>
2021-02-23 20:26:57 +01:00
< script >
jQuery ( document ) . ready ( function ( tmp ) {
2022-03-29 10:28:44 +02:00
console . log ( " Try Ping with hash_unique_id is md5('dolibarr'+instance_unique_id) " );
2021-02-23 20:26:57 +01:00
$ . ajax ({
method : " POST " ,
url : " <?php echo $url_for_ping ?> " ,
timeout : 500 , // timeout milliseconds
cache : false ,
data : {
hash_algo : 'md5' ,
hash_unique_id : '<?php echo dol_escape_js($hash_unique_id); ?>' ,
action : 'dolibarrping' ,
version : '<?php echo (float) DOL_VERSION; ?>' ,
entity : '<?php echo (int) $conf->entity; ?>' ,
dbtype : '<?php echo dol_escape_js($db->type); ?>' ,
country_code : '<?php echo $mysoc->country_code ? dol_escape_js($mysoc->country_code) : ' unknown '; ?>' ,
php_version : '<?php echo dol_escape_js(phpversion()); ?>' ,
os_version : '<?php echo dol_escape_js(version_os(' smr ')); ?>' ,
2021-06-17 03:37:52 +02:00
distrib : '<?php echo $distrib ? dol_escape_js($distrib) : ' unknown '; ?>' ,
token : 'notrequired'
2021-02-23 20:26:57 +01:00
},
success : function ( data , status , xhr ) { // success callback function (data contains body of response)
2021-06-17 03:37:52 +02:00
console . log ( " Ping ok " );
2021-02-23 20:26:57 +01:00
$ . ajax ({
method : 'GET' ,
url : '<?php echo DOL_URL_ROOT.' / core / ajax / pingresult . php '; ?>' ,
timeout : 500 , // timeout milliseconds
cache : false ,
2022-07-11 19:58:28 +02:00
data : { hash_algo : 'md5' , hash_unique_id : '<?php echo dol_escape_js($hash_unique_id); ?>' , action : 'firstpingok' , token : '<?php echo currentToken(); ?>' }, // for update
2021-02-23 20:26:57 +01:00
});
},
error : function ( data , status , xhr ) { // error callback function
console . log ( " Ping ko: " + data );
$ . ajax ({
method : 'GET' ,
url : '<?php echo DOL_URL_ROOT.' / core / ajax / pingresult . php '; ?>' ,
timeout : 500 , // timeout milliseconds
cache : false ,
2022-07-11 19:58:28 +02:00
data : { hash_algo : 'md5' , hash_unique_id : '<?php echo dol_escape_js($hash_unique_id); ?>' , action : 'firstpingko' , token : '<?php echo currentToken(); ?>' },
2021-02-23 20:26:57 +01:00
});
}
});
});
</ script >
2020-01-31 17:27:48 +01:00
< ? php
}
2020-05-21 01:03:03 +02:00
} else {
2019-08-23 16:23:31 +02:00
$now = dol_now ();
2020-01-01 14:30:16 +01:00
print " \n <!-- NO JS CODE TO ENABLE the anonymous Ping. It was disabled --> \n " ;
2019-08-23 16:23:31 +02:00
include_once DOL_DOCUMENT_ROOT . '/core/lib/admin.lib.php' ;
2021-03-20 12:49:44 +01:00
dolibarr_set_const ( $db , 'MAIN_FIRST_PING_OK_DATE' , dol_print_date ( $now , 'dayhourlog' , 'gmt' ), 'chaine' , 0 , '' , $conf -> entity );
dolibarr_set_const ( $db , 'MAIN_FIRST_PING_OK_ID' , 'disabled' , 'chaine' , 0 , '' , $conf -> entity );
2019-08-23 16:23:31 +02:00
}
2019-08-02 19:21:25 +02:00
}
}
2021-10-05 10:41:11 +02:00
$reshook = $hookmanager -> executeHooks ( 'beforeBodyClose' ); // Note that $action and $object may have been modified by some hooks
if ( $reshook > 0 ) {
print $hookmanager -> resPrint ;
}
2017-10-16 08:47:05 +02:00
print " </body> \n " ;
print " </html> \n " ;
2020-10-27 19:46:07 +01:00
}
2002-05-09 16:57:48 +02:00
}