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 >
* Copyright ( C ) 2004 - 2015 Laurent Destailleur < eldy @ users . sourceforge . net >
* Copyright ( C ) 2004 Sebastien Di Cintio < sdicintio @ ressource - toi . org >
* Copyright ( C ) 2004 Benoit Mortier < benoit . mortier @ opensides . be >
2018-10-27 14:43:12 +02:00
* Copyright ( C ) 2005 - 2015 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 >
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
* along with this program . If not , see < http :// www . gnu . org / licenses />.
*/
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.
2008-01-10 18:12:07 +01:00
$micro_start_time = 0 ;
2015-06-06 14:21:18 +02:00
if ( ! empty ( $_SERVER [ 'MAIN_SHOW_TUNING_INFO' ]))
2008-01-10 18:12:07 +01:00
{
2017-10-16 08:47:05 +02:00
list ( $usec , $sec ) = explode ( " " , microtime ());
$micro_start_time = (( float ) $usec + ( float ) $sec );
// Add Xdebug code coverage
//define('XDEBUGCOVERAGE',1);
if ( defined ( 'XDEBUGCOVERAGE' )) {
xdebug_start_code_coverage ();
}
2008-01-10 18:12:07 +01:00
}
2011-03-07 23:35:35 +01:00
// Removed magic_quotes
2017-04-14 12:38:52 +02:00
if ( function_exists ( 'get_magic_quotes_gpc' )) // magic_quotes_* deprecated in PHP 5.0 and removed in PHP 5.5
2005-11-22 23:27:20 +01:00
{
2017-10-16 08:47:05 +02:00
if ( get_magic_quotes_gpc ())
{
// Forcing parameter setting magic_quotes_gpc and cleaning parameters
// (Otherwise he would have for each position, condition
// Reading stripslashes variable according to state get_magic_quotes_gpc).
// Off mode recommended (just do $db->escape for insert / update).
function stripslashes_deep ( $value )
{
return ( is_array ( $value ) ? array_map ( 'stripslashes_deep' , $value ) : stripslashes ( $value ));
}
$_GET = array_map ( 'stripslashes_deep' , $_GET );
$_POST = array_map ( 'stripslashes_deep' , $_POST );
$_FILES = array_map ( 'stripslashes_deep' , $_FILES );
//$_COOKIE = array_map('stripslashes_deep', $_COOKIE); // Useless because a cookie should never be outputed on screen nor used into sql
@ set_magic_quotes_runtime ( 0 );
}
2005-11-22 23:27:20 +01:00
}
2018-09-02 18:58:11 +02:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
/**
* Security : SQL Injection and XSS Injection ( scripts ) protection ( Filters on GET , POST , PHP_SELF ) .
*
* @ param string $val Value
* @ param string $type 1 = GET , 0 = POST , 2 = PHP_SELF , 3 = GET without sql reserved keywords ( the less tolerant test )
* @ return int > 0 if there is an injection , 0 if none
* @ deprecated use testSqlAndScriptInject
* @ see testSqlAndScriptInject ( $val , $type )
*/
function test_sql_and_script_inject ( $val , $type )
{
// phpcs:enable
2018-09-03 09:29:30 +02:00
return testSqlAndScriptInject ( $val , $type );
2018-09-02 18:58:11 +02:00
}
2011-09-12 19:08:02 +02:00
/**
2011-11-26 12:36:36 +01:00
* Security : SQL Injection and XSS Injection ( scripts ) protection ( Filters on GET , POST , PHP_SELF ) .
2011-09-12 19:08:02 +02:00
*
* @ param string $val Value
2018-06-25 14:06:09 +02:00
* @ param string $type 1 = GET , 0 = POST , 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
{
2017-10-16 08:47:05 +02:00
$inj = 0 ;
2017-12-01 17:22:32 +01:00
// For SQL Injection (only GET are used to be included into bad escaped SQL requests)
2018-06-25 14:06:09 +02:00
if ( $type == 1 || $type == 3 )
2017-10-16 08:47:05 +02: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 );
2017-12-01 17:22:32 +01:00
$inj += preg_match ( '/select\s+from/i' , $val );
2017-10-16 08:47:05 +02:00
$inj += preg_match ( '/into\s+(outfile|dumpfile)/i' , $val );
2018-06-25 14:06:09 +02:00
$inj += preg_match ( '/user\s*\(/i' , $val ); // avoid to use function user() that return current database login
$inj += preg_match ( '/information_schema/i' , $val ); // avoid to use request that read information_schema database
2017-12-01 17:22:32 +01:00
}
2018-06-25 14:06:09 +02:00
if ( $type == 3 )
2017-12-01 17:22:32 +01:00
{
2018-06-25 14:06:09 +02:00
$inj += preg_match ( '/select|update|delete|replace|group\s+by|concat|count|from/i' , $val );
}
if ( $type != 2 ) // Not common key strings, so we can check them both on GET and POST
{
$inj += preg_match ( '/updatexml\(/i' , $val );
2017-12-01 17:22:32 +01:00
$inj += preg_match ( '/update.+set.+=/i' , $val );
$inj += preg_match ( '/union.+select/i' , $val );
2017-10-16 08:47:05 +02:00
$inj += preg_match ( '/(\.\.%2f)+/i' , $val );
}
// 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
2017-10-16 08:47:05 +02:00
$inj += preg_match ( '/<script/i' , $val );
2017-09-07 13:50:16 +02:00
$inj += preg_match ( '/<iframe/i' , $val );
2018-04-06 19:12:13 +02:00
$inj += preg_match ( '/<audio/i' , $val );
2017-09-07 13:50:16 +02:00
$inj += preg_match ( '/Set\.constructor/i' , $val ); // ECMA script 6
2017-10-16 08:47:05 +02:00
if ( ! defined ( 'NOSTYLECHECK' )) $inj += preg_match ( '/<style/i' , $val );
$inj += preg_match ( '/base[\s]+href/si' , $val );
$inj += preg_match ( '/<.*onmouse/si' , $val ); // onmousexxx can be set on img or any html tag like <img title='...' onmouseover=alert(1)>
$inj += preg_match ( '/onerror\s*=/i' , $val ); // onerror can be set on img or any html tag like <img title='...' onerror = alert(1)>
$inj += preg_match ( '/onfocus\s*=/i' , $val ); // onfocus can be set on input text html tag like <input type='text' value='...' onfocus = alert(1)>
$inj += preg_match ( '/onload\s*=/i' , $val ); // onload can be set on svg tag <svg/onload=alert(1)> or other tag like body <body onload=alert(1)>
2018-04-06 19:12:13 +02:00
$inj += preg_match ( '/onloadstart\s*=/i' , $val ); // onload can be set on audio tag <audio onloadstart=alert(1)>
2018-01-04 19:30:25 +01:00
$inj += preg_match ( '/onclick\s*=/i' , $val ); // onclick can be set on img text html tag like <img onclick = alert(1)>
$inj += preg_match ( '/onscroll\s*=/i' , $val ); // onscroll can be on textarea
2017-10-16 08:47:05 +02:00
//$inj += preg_match('/on[A-Z][a-z]+\*=/', $val); // To lock event handlers onAbort(), ...
2017-09-07 13:50:16 +02:00
$inj += preg_match ( '/:|:|:/i' , $val ); // refused string ':' encoded (no reason to have it encoded) to lock 'javascript:...'
2017-10-16 08:47:05 +02:00
//if ($type == 1)
//{
$inj += preg_match ( '/javascript:/i' , $val );
$inj += preg_match ( '/vbscript:/i' , $val );
//}
// For XSS Injection done by adding javascript closing html tags like with onmousemove, etc... (closing a src or href tag with not cleaned param)
if ( $type == 1 ) $inj += preg_match ( '/"/i' , $val ); // We refused " in GET parameters value
if ( $type == 2 ) $inj += preg_match ( '/[;"]/' , $val ); // PHP_SELF is a file system path. It can contains spaces.
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
*
2015-04-06 12:22:52 +02:00
* @ param string $var Variable name
* @ 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
{
2017-10-16 08:47:05 +02:00
if ( is_array ( $var ))
{
2018-04-06 18:33:51 +02:00
foreach ( $var as $key => $value ) // Warning, $key may also be used for attacks
2017-10-16 08:47:05 +02:00
{
2018-04-06 18:33:51 +02:00
if ( analyseVarsForSqlAndScriptsInjection ( $key , $type ) && analyseVarsForSqlAndScriptsInjection ( $value , $type ))
2013-10-18 11:19:32 +02:00
{
2018-04-06 18:33:51 +02:00
//$var[$key] = $value; // This is useless
2017-10-16 08:47:05 +02:00
}
else
{
print 'Access refused by SQL/Script injection protection in main.inc.php (type=' . htmlentities ( $type ) . ' key=' . htmlentities ( $key ) . ' value=' . htmlentities ( $value ) . ' page=' . htmlentities ( $_SERVER [ " REQUEST_URI " ]) . ')' ;
exit ;
}
}
return true ;
}
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
2013-02-24 14:54:08 +01:00
2014-01-21 18:55:45 +01:00
// Check consistency of NOREQUIREXXX DEFINES
2017-12-19 00:15:22 +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 ;
}
2013-02-24 14:54:08 +01:00
2011-03-07 23:35:35 +01:00
// Sanity check on URL
2011-03-08 17:38:58 +01:00
if ( ! empty ( $_SERVER [ " PHP_SELF " ]))
{
2017-10-16 08:47:05 +02:00
$morevaltochecklikepost = array ( $_SERVER [ " PHP_SELF " ]);
analyseVarsForSqlAndScriptsInjection ( $morevaltochecklikepost , 2 );
2011-03-08 17:38:58 +01:00
}
2011-03-07 23:35:35 +01:00
// Sanity check on GET parameters
2015-05-19 22:08:51 +02:00
if ( ! defined ( 'NOSCANGETFORINJECTION' ) && ! empty ( $_SERVER [ " QUERY_STRING " ]))
2011-03-08 17:38:58 +01:00
{
2017-10-16 08:47:05 +02:00
$morevaltochecklikeget = array ( $_SERVER [ " QUERY_STRING " ]);
analyseVarsForSqlAndScriptsInjection ( $morevaltochecklikeget , 1 );
2011-03-08 17:38:58 +01:00
}
2011-03-07 23:35:35 +01:00
// Sanity check on POST
2015-05-19 22:08:51 +02:00
if ( ! defined ( 'NOSCANPOSTFORINJECTION' ))
{
analyseVarsForSqlAndScriptsInjection ( $_POST , 0 );
}
2011-03-06 21:42:36 +01:00
2010-12-15 00:27:17 +01:00
// This is to make Dolibarr working with Plesk
2016-03-18 10:56:55 +01:00
if ( ! empty ( $_SERVER [ 'DOCUMENT_ROOT' ]) && substr ( $_SERVER [ 'DOCUMENT_ROOT' ], - 6 ) !== 'htdocs' )
2015-10-05 09:02:03 +02:00
{
set_include_path ( $_SERVER [ 'DOCUMENT_ROOT' ] . '/htdocs' );
2015-09-17 19:26:52 +02:00
}
2008-01-20 22:53:43 +01:00
2010-12-29 13:13:36 +01:00
// Include the conf.php and functions.lib.php
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'=> , ))
2013-07-29 17:32:43 +02:00
if ( ! empty ( $_POST [ " DOL_AUTOSET_COOKIE " ]))
{
2013-09-21 12:30:44 +02:00
$tmpautoset = explode ( ':' , $_POST [ " DOL_AUTOSET_COOKIE " ], 2 );
$tmplist = explode ( ',' , $tmpautoset [ 1 ]);
2018-04-19 13:54:43 +02:00
$cookiearrayvalue = array ();
2013-09-21 12:30:44 +02:00
foreach ( $tmplist as $tmpkey )
2013-07-29 17:32:43 +02:00
{
2013-09-21 12:30:44 +02:00
$postkey = $tmpautoset [ 0 ] . '_' . $tmpkey ;
//var_dump('tmpkey='.$tmpkey.' postkey='.$postkey.' value='.$_POST[$postkey]);
if ( ! empty ( $_POST [ $postkey ])) $cookiearrayvalue [ $tmpkey ] = $_POST [ $postkey ];
2013-07-29 17:32:43 +02:00
}
2013-09-21 12:30:44 +02:00
$cookiename = $tmpautoset [ 0 ];
2014-07-30 15:47:19 +02:00
$cookievalue = json_encode ( $cookiearrayvalue );
2013-09-21 12:30:44 +02:00
//var_dump('setcookie cookiename='.$cookiename.' cookievalue='.$cookievalue);
2017-09-24 19:50:32 +02:00
setcookie ( $cookiename , empty ( $cookievalue ) ? '' : $cookievalue , empty ( $cookievalue ) ? 0 : ( time () + ( 86400 * 354 )), '/' , null , false , true ); // keep cookie 1 year and add tag httponly
2013-09-21 12:30:44 +02:00
if ( empty ( $cookievalue )) unset ( $_COOKIE [ $cookiename ]);
2013-07-29 17:32:43 +02:00
}
2013-04-28 18:46:34 +02:00
2018-01-14 20:11:38 +01:00
2009-05-22 00:28:05 +02:00
// Init session. Name of session is specific to Dolibarr instance.
2018-01-24 14:22:11 +01:00
// Note: the function dol_getprefix may have been redefined to return a different key to manage another area to protect.
2017-12-19 00:15:22 +01:00
$prefix = dol_getprefix ( '' );
2018-01-14 20:11:38 +01:00
2010-12-29 13:13:36 +01:00
$sessionname = 'DOLSESSID_' . $prefix ;
$sessiontimeout = 'DOLSESSTIMEOUT_' . $prefix ;
2009-06-14 18:25:23 +02:00
if ( ! empty ( $_COOKIE [ $sessiontimeout ])) ini_set ( 'session.gc_maxlifetime' , $_COOKIE [ $sessiontimeout ]);
2009-05-20 20:18:25 +02:00
session_name ( $sessionname );
2017-09-24 19:50:32 +02:00
session_set_cookie_params ( 0 , '/' , null , false , true ); // Add tag httponly on session cookie (same as setting session.cookie_httponly into php.ini). Must be called before the session_start.
2017-12-22 01:03:40 +01:00
// This create lock, released when session_write_close() or end of page.
// We need this lock as long as we read/write $_SESSION ['vars']. We can remove lock when finished.
2017-07-02 13:18:23 +02:00
if ( ! defined ( 'NOSESSION' ))
2012-04-20 20:38:49 +02:00
{
2017-10-16 08:47:05 +02:00
session_start ();
2018-03-16 01:52:07 +01:00
/* if ( ini_get ( 'register_globals' )) // Deprecated in 5.3 and removed in 5.4. To solve bug in using $_SESSION
2017-10-16 08:47:05 +02:00
{
foreach ( $_SESSION as $key => $value )
{
if ( isset ( $GLOBALS [ $key ])) unset ( $GLOBALS [ $key ]);
}
2018-03-16 01:52:07 +01:00
} */
2012-04-20 20:38:49 +02:00
}
2009-05-22 00:28:05 +02:00
2017-04-14 12:38:52 +02:00
// Init the 5 global objects, this include will make the new and set properties for: $conf, $db, $langs, $user, $mysoc
2012-08-22 23:11:24 +02:00
require_once 'master.inc.php' ;
2008-01-10 18:12:07 +01:00
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
2011-02-20 13:16:18 +01:00
// Detection browser
if ( isset ( $_SERVER [ " HTTP_USER_AGENT " ]))
{
2017-10-16 08:47:05 +02: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'
//var_dump($conf->browser);
if ( $conf -> browser -> layout == 'phone' ) $conf -> dol_no_mouse_hover = 1 ;
if ( $conf -> browser -> layout == 'phone' ) $conf -> global -> MAIN_TESTMENUHIDER = 1 ;
2016-06-17 16:28:16 +02:00
}
2011-02-20 13:16:18 +01:00
2010-02-20 12:40:36 +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'
if ( ! empty ( $conf -> file -> main_force_https ) && ( empty ( $_SERVER [ " HTTPS " ]) || $_SERVER [ " HTTPS " ] != 'on' ))
2008-04-06 22:17:11 +02:00
{
2017-10-16 08:47:05 +02:00
$newurl = '' ;
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
{
$newurl = preg_replace ( '/^http:/i' , 'https:' , $_SERVER [ " SCRIPT_URI " ]);
}
}
else // Check HTTPS environment variable (Apache/mod_ssl only)
{
$newurl = preg_replace ( '/^http:/i' , 'https:' , DOL_MAIN_URL_ROOT ) . $_SERVER [ " REQUEST_URI " ];
}
}
else
{
// Check HTTPS environment variable (Apache/mod_ssl only)
$newurl = $conf -> file -> main_force_https . $_SERVER [ " REQUEST_URI " ];
}
// Start redirect
if ( $newurl )
{
dol_syslog ( " main.inc: dolibarr_main_force_https is on, we make a redirect to " . $newurl );
header ( " Location: " . $newurl );
exit ;
}
else
{
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
2018-02-15 19:49:50 +01:00
if ( ! defined ( 'NOLOGIN' ) && ! defined ( 'NOIPCHECK' ) && ! empty ( $dolibarr_main_restrict_ip ))
{
$listofip = explode ( ',' , $dolibarr_main_restrict_ip );
$found = false ;
foreach ( $listofip as $ip )
{
$ip = trim ( $ip );
if ( $ip == $_SERVER [ 'REMOTE_ADDR' ])
{
$found = true ;
break ;
}
}
if ( ! $found )
{
print 'Access refused by IP protection' ;
exit ;
}
}
2009-02-02 19:33:44 +01:00
2014-02-26 16:51:38 +01:00
// Loading of additional presentation includes
2012-08-22 23:11:24 +02: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' ) && $conf -> use_javascript_ajax ) 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.
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.
2010-02-15 22:22:04 +01:00
if (( ! empty ( $conf -> global -> MAIN_VERSION_LAST_UPGRADE ) && ( $conf -> global -> MAIN_VERSION_LAST_UPGRADE != DOL_VERSION ))
|| ( empty ( $conf -> global -> MAIN_VERSION_LAST_UPGRADE ) && ! empty ( $conf -> global -> MAIN_VERSION_LAST_INSTALL ) && ( $conf -> global -> MAIN_VERSION_LAST_INSTALL != DOL_VERSION )))
2009-08-08 18:26:06 +02:00
{
2017-10-16 08:47:05 +02: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 );
if ( $rescomp > 0 ) // Programs have a version higher than database. 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 page. " , LOG_WARNING );
header ( " Location: " . DOL_URL_ROOT . " /install/index.php " );
exit ;
}
2009-08-08 18:26:06 +02:00
}
2019-01-15 15:04:15 +01:00
//var_dump(GETPOST('token').' '.$_SESSION['token'].' - '.$_SESSION['newtoken'].' '.$_SERVER['SCRIPT_FILENAME']);
2010-02-19 14:50:49 +01:00
// Creation of a token against CSRF vulnerabilities
2009-05-26 19:01:18 +02:00
if ( ! defined ( 'NOTOKENRENEWAL' ))
{
2018-12-22 17:30:22 +01:00
// Rolling token at each call ($_SESSION['token'] contains token of previous page)
2017-10-16 08:47:05 +02:00
if ( isset ( $_SESSION [ 'newtoken' ])) $_SESSION [ 'token' ] = $_SESSION [ 'newtoken' ];
2017-06-10 16:29:25 +02:00
2017-10-16 08:47:05 +02:00
// Save in $_SESSION['newtoken'] what will be next token. Into forms, we will add param token = $_SESSION['newtoken']
2018-04-16 13:51:16 +02:00
$token = dol_hash ( uniqid ( mt_rand (), true )); // Generates a hash of a random number
2017-10-16 08:47:05 +02:00
$_SESSION [ 'newtoken' ] = $token ;
2009-05-26 19:01:18 +02:00
}
2019-01-15 15:04:15 +01:00
//var_dump(GETPOST('token').' '.$_SESSION['token'].' - '.$_SESSION['newtoken'].' '.$_SERVER['SCRIPT_FILENAME']);
2018-12-22 18:09:26 +01:00
// Check token
2018-04-06 17:58:30 +02:00
if (( ! defined ( 'NOCSRFCHECK' ) && empty ( $dolibarr_nocsrfcheck ) && ! empty ( $conf -> global -> MAIN_SECURITY_CSRF_WITH_TOKEN ))
|| defined ( 'CSRFCHECK_WITH_TOKEN' )) // Check validity of token, only if option MAIN_SECURITY_CSRF_WITH_TOKEN enabled or if constant CSRFCHECK_WITH_TOKEN is set
2009-05-15 14:48:13 +02:00
{
2018-12-22 18:09:26 +01:00
if ( $_SERVER [ 'REQUEST_METHOD' ] == 'POST' && ! GETPOSTISSET ( 'token' )) // Note, offender can still send request by GET
2017-10-16 08:47:05 +02:00
{
2019-01-15 13:55:14 +01:00
print " Access by POST method refused by CSRF protection in main.inc.php. Token not provided. \n " ;
2019-01-15 14:07:05 +01:00
print " If you access your server behind a proxy using url rewriting, you might check that all HTTP header is propagated (or add the line \$ dolibarr_nocsrfcheck=1 into your conf.php file or MAIN_SECURITY_CSRF_WITH_TOKEN to 0 into setup). \n " ;
2017-10-16 08:47:05 +02:00
die ;
}
2018-12-22 18:09:26 +01:00
//if ($_SERVER['REQUEST_METHOD'] === 'POST') // This test must be after loading $_SESSION['token'].
//{
if ( GETPOSTISSET ( 'token' ) && GETPOST ( 'token' , 'alpha' ) != $_SESSION [ 'token' ])
2017-10-16 08:47:05 +02:00
{
2018-12-22 18:09:26 +01:00
dol_syslog ( " Invalid token, so we disable POST and some GET parameters - referer= " . $_SERVER [ 'HTTP_REFERER' ] . " , action= " . GETPOST ( 'action' , 'aZ09' ) . " , _GET|POST['token']= " . GETPOST ( 'token' , 'alpha' ) . " , _SESSION['token']= " . $_SESSION [ 'token' ], LOG_WARNING );
//print 'Unset POST by CSRF protection in main.inc.php.'; // Do not output anything because this create problems when using the BACK button on browsers.
unset ( $_POST );
unset ( $_GET [ 'confirm' ]);
2017-10-16 08:47:05 +02:00
}
2018-12-22 18:09:26 +01:00
//}
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)
2017-05-16 13:27:32 +02:00
if ( GETPOST ( 'disablemodules' , 'alpha' )) $_SESSION [ " disablemodules " ] = GETPOST ( 'disablemodules' , 'alpha' );
2009-01-21 14:06:34 +01:00
if ( ! empty ( $_SESSION [ " disablemodules " ]))
2008-11-28 00:24:50 +01:00
{
2017-10-16 08:47:05 +02:00
$disabled_modules = explode ( ',' , $_SESSION [ " disablemodules " ]);
foreach ( $disabled_modules as $module )
{
if ( $module )
{
if ( empty ( $conf -> $module )) $conf -> $module = new stdClass ();
$conf -> $module -> enabled = false ;
if ( $module == 'fournisseur' ) // Special case
{
$conf -> supplier_order -> enabled = 0 ;
$conf -> supplier_invoice -> enabled = 0 ;
}
}
}
2008-11-28 00:24:50 +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
*/
2006-07-02 02:43:40 +02:00
$login = '' ;
2009-12-29 19:10:48 +01:00
if ( ! defined ( 'NOLOGIN' ))
2005-11-01 18:48:46 +01:00
{
2017-10-16 08:47:05 +02:00
// $authmode lists the different means 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
2018-01-14 20:11:38 +01:00
if ( defined ( 'MAIN_AUTHENTICATION_MODE' ))
{
$dolibarr_main_authentication = constant ( 'MAIN_AUTHENTICATION_MODE' );
}
else
{
// Authentication mode
if ( empty ( $dolibarr_main_authentication )) $dolibarr_main_authentication = 'http,dolibarr' ;
// Authentication mode: forceuser
if ( $dolibarr_main_authentication == 'forceuser' && empty ( $dolibarr_auto_user )) $dolibarr_auto_user = 'auto' ;
}
2017-10-16 08:47:05 +02:00
// Set authmode
$authmode = explode ( ',' , $dolibarr_main_authentication );
// No authentication mode
if ( ! count ( $authmode ))
{
$langs -> load ( 'main' );
dol_print_error ( '' , $langs -> trans ( " ErrorConfigParameterNotDefined " , 'dolibarr_main_authentication' ));
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.
$resultFetchUser = '' ;
$test = true ;
if ( ! isset ( $_SESSION [ " dol_login " ]))
{
// It is not already authenticated and it requests the login / password
include_once DOL_DOCUMENT_ROOT . '/core/lib/security2.lib.php' ;
$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 );
//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
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' ]))
{
dol_syslog ( " Call index page from another url than demo page (call is done from page " . $_SERVER [ 'HTTP_REFERER' ] . " ) " );
$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 : '' );
header ( " Location: " . $url );
exit ;
}
}
2012-02-22 12:02:12 +01:00
2017-10-16 08:47:05 +02:00
// Verification security graphic code
if ( GETPOST ( " username " , " alpha " , 2 ) && ! empty ( $conf -> global -> MAIN_SECURITY_ENABLECAPTCHA ))
{
$sessionkey = 'dol_antispam_value' ;
2018-04-16 13:51:16 +02:00
$ok = ( array_key_exists ( $sessionkey , $_SESSION ) === true && ( strtolower ( $_SESSION [ $sessionkey ]) == strtolower ( $_POST [ 'code' ])));
2012-02-22 12:02:12 +01:00
2017-10-16 08:47:05 +02:00
// Check code
if ( ! $ok )
{
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
$_SESSION [ " dol_loginmesg " ] = $langs -> trans ( " ErrorBadValueForCode " );
$test = false ;
2018-12-10 11:19:52 +01:00
// Call trigger for the "security events" log
$user -> trigger_mesg = 'ErrorBadValueForCode - login=' . GETPOST ( " username " , " alpha " , 2 );
// Call of triggers
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php' ;
$interface = new Interfaces ( $db );
$result = $interface -> run_triggers ( 'USER_LOGIN_FAILED' , $user , $user , $langs , $conf );
if ( $result < 0 ) {
$error ++ ;
}
// End Call of triggers
2018-12-10 17:50:58 +01:00
2017-10-16 08:47:05 +02:00
// Hooks on failed login
$action = '' ;
$hookmanager -> initHooks ( array ( 'login' ));
$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
if ( $reshook < 0 ) $error ++ ;
// Note: exit is done later
}
}
2013-02-24 02:47:30 +01:00
2018-03-16 01:52:07 +01:00
$allowedmethodtopostusername = 2 ;
if ( defined ( 'MAIN_AUTHENTICATION_POST_METHOD' )) $allowedmethodtopostusername = constant ( 'MAIN_AUTHENTICATION_POST_METHOD' );
$usertotest = ( ! empty ( $_COOKIE [ 'login_dolibarr' ]) ? $_COOKIE [ 'login_dolibarr' ] : GETPOST ( " username " , " alpha " , $allowedmethodtopostusername ));
2018-03-16 19:29:22 +01:00
$passwordtotest = GETPOST ( 'password' , 'none' , $allowedmethodtopostusername );
2017-10-16 08:47:05 +02:00
$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.
$goontestloop = false ;
if ( isset ( $_SERVER [ " REMOTE_USER " ]) && in_array ( 'http' , $authmode )) $goontestloop = true ;
if ( $dolibarr_main_authentication == 'forceuser' && ! empty ( $dolibarr_auto_user )) $goontestloop = true ;
2018-03-16 01:52:07 +01:00
if ( GETPOST ( " username " , " alpha " , $allowedmethodtopostusername ) || ! empty ( $_COOKIE [ 'login_dolibarr' ]) || GETPOST ( 'openid_mode' , 'alpha' , 1 )) $goontestloop = true ;
2015-06-27 21:52:23 +02:00
2017-10-16 08:47:05 +02:00
if ( ! is_object ( $langs )) // This can occurs when calling page with NOREQUIRETRAN defined, however we need langs for error messages.
{
include_once DOL_DOCUMENT_ROOT . '/core/class/translate.class.php' ;
$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 ));
2017-12-19 00:15:22 +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
if ( $test && $goontestloop )
{
$login = checkLoginPassEntity ( $usertotest , $passwordtotest , $entitytotest , $authmode );
if ( $login )
{
$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 ;
if ( isset ( $_POST [ " dst_first " ]) && isset ( $_POST [ " dst_second " ]))
{
include_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php' ;
$datenow = dol_now ();
$datefirst = dol_stringtotime ( $_POST [ " dst_first " ]);
$datesecond = dol_stringtotime ( $_POST [ " dst_second " ]);
if ( $datenow >= $datefirst && $datenow < $datesecond ) $dol_dst = 1 ;
}
//print $datefirst.'-'.$datesecond.'-'.$datenow.'-'.$dol_tz.'-'.$dol_tzstring.'-'.$dol_dst; exit;
}
if ( ! $login )
{
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
if ( empty ( $_SESSION [ " dol_loginmesg " ])) $_SESSION [ " dol_loginmesg " ] = $langs -> trans ( " ErrorBadLoginPassword " );
2018-12-10 11:19:52 +01:00
// Call trigger for the "security events" log
$user -> trigger_mesg = $langs -> trans ( " ErrorBadLoginPassword " ) . ' - login=' . GETPOST ( " username " , " alpha " , 2 );
// Call of triggers
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php' ;
$interface = new Interfaces ( $db );
$result = $interface -> run_triggers ( 'USER_LOGIN_FAILED' , $user , $user , $langs , $conf , GETPOST ( " username " , " alpha " , 2 ));
if ( $result < 0 ) {
$error ++ ;
}
// End Call of triggers
2017-10-16 08:47:05 +02:00
// Hooks on failed login
$action = '' ;
$hookmanager -> initHooks ( array ( 'login' ));
$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
if ( $reshook < 0 ) $error ++ ;
// 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
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.
{
// No data to test login, so we show the login page
2015-03-21 01:22:05 +01:00
dol_syslog ( " --- Access to " . $_SERVER [ " PHP_SELF " ] . " showing the login form and exit " );
2017-07-22 23:43:40 +02:00
if ( defined ( 'NOREDIRECTBYMAINTOLOGIN' )) return 'ERROR_NOT_LOGGED' ;
2017-10-16 08:47:05 +02:00
else dol_loginfunction ( $langs , $conf ,( ! empty ( $mysoc ) ? $mysoc : '' ));
exit ;
}
2012-02-22 12:02:12 +01:00
2017-10-16 08:47:05 +02:00
$resultFetchUser = $user -> fetch ( '' , $login , '' , 1 , ( $entitytotest > 0 ? $entitytotest : - 1 ));
if ( $resultFetchUser <= 0 )
{
dol_syslog ( 'User not found, connexion refused' );
session_destroy ();
session_name ( $sessionname );
session_set_cookie_params ( 0 , '/' , null , false , true ); // Add tag httponly on session cookie
session_start (); // Fixing the bug of register_globals here is useless since session is empty
2016-03-18 10:56:55 +01:00
2017-10-16 08:47:05 +02: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
2017-10-16 08:47:05 +02:00
$_SESSION [ " dol_loginmesg " ] = $langs -> trans ( " ErrorCantLoadUserFromDolibarrDatabase " , $login );
2018-12-10 17:50:58 +01:00
2018-12-10 11:19:52 +01:00
$user -> trigger_mesg = 'ErrorCantLoadUserFromDolibarrDatabase - login=' . $login ;
2017-10-16 08:47:05 +02:00
}
if ( $resultFetchUser < 0 )
{
$_SESSION [ " dol_loginmesg " ] = $user -> error ;
2018-12-10 17:50:58 +01:00
2018-12-10 11:19:52 +01:00
$user -> trigger_mesg = $user -> error ;
2017-10-16 08:47:05 +02:00
}
2018-12-10 11:19:52 +01:00
// Call triggers for the "security events" log
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php' ;
$interface = new Interfaces ( $db );
$result = $interface -> run_triggers ( 'USER_LOGIN_FAILED' , $user , $user , $langs , $conf );
if ( $result < 0 ) {
$error ++ ;
}
// End call triggers
2018-12-10 17:50:58 +01:00
2017-10-16 08:47:05 +02:00
// Hooks on failed login
$action = '' ;
$hookmanager -> initHooks ( array ( 'login' ));
$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
if ( $reshook < 0 ) $error ++ ;
$paramsurl = array ();
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' );
header ( 'Location: ' . DOL_URL_ROOT . '/index.php' . ( count ( $paramsurl ) ? '?' . implode ( '&' , $paramsurl ) : '' ));
exit ;
}
}
else
{
// We are already into an authenticated session
$login = $_SESSION [ " dol_login " ];
$entity = $_SESSION [ " dol_entity " ];
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
2017-10-16 08:47:05 +02:00
$resultFetchUser = $user -> fetch ( '' , $login , '' , 1 , ( $entity > 0 ? $entity : - 1 ));
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 );
session_destroy ();
session_name ( $sessionname );
session_set_cookie_params ( 0 , '/' , null , false , true ); // Add tag httponly on session cookie
session_start (); // Fixing the bug of register_globals here is useless since session is empty
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
2017-10-16 08:47:05 +02:00
$_SESSION [ " dol_loginmesg " ] = $langs -> trans ( " ErrorCantLoadUserFromDolibarrDatabase " , $login );
2018-12-10 11:19:52 +01:00
$user -> trigger_mesg = 'ErrorCantLoadUserFromDolibarrDatabase - login=' . $login ;
2017-10-16 08:47:05 +02:00
}
if ( $resultFetchUser < 0 )
{
$_SESSION [ " dol_loginmesg " ] = $user -> error ;
2018-12-10 17:50:58 +01:00
2018-12-10 11:19:52 +01:00
$user -> trigger_mesg = $user -> error ;
2017-10-16 08:47:05 +02:00
}
2018-12-10 11:19:52 +01:00
// Call triggers for the "security events" log
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php' ;
$interface = new Interfaces ( $db );
$result = $interface -> run_triggers ( 'USER_LOGIN_FAILED' , $user , $user , $langs , $conf );
if ( $result < 0 ) {
$error ++ ;
}
// End call triggers
2018-12-10 17:50:58 +01:00
2017-10-16 08:47:05 +02:00
// Hooks on failed login
$action = '' ;
$hookmanager -> initHooks ( array ( 'login' ));
$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
if ( $reshook < 0 ) $error ++ ;
$paramsurl = array ();
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' );
header ( 'Location: ' . DOL_URL_ROOT . '/index.php' . ( count ( $paramsurl ) ? '?' . implode ( '&' , $paramsurl ) : '' ));
exit ;
}
else
2015-07-03 22:06:24 +02:00
{
2018-04-08 12:40:19 +02: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.
2018-06-23 11:55:04 +02:00
if ( ! empty ( $_GET [ 'save_lastsearch_values' ])) // We must use $_GET here
2018-04-08 12:40:19 +02:00
{
$relativepathstring = preg_replace ( '/\?.*$/' , '' , $_SERVER [ " HTTP_REFERER " ]);
$relativepathstring = preg_replace ( '/^https?:\/\/[^\/]*/' , '' , $relativepathstring ); // Get full path except host server
// Clean $relativepathstring
if ( constant ( 'DOL_URL_ROOT' )) $relativepathstring = preg_replace ( '/^' . preg_quote ( constant ( 'DOL_URL_ROOT' ), '/' ) . '/' , '' , $relativepathstring );
$relativepathstring = preg_replace ( '/^\//' , '' , $relativepathstring );
$relativepathstring = preg_replace ( '/^custom\//' , '' , $relativepathstring );
//var_dump($relativepathstring);
2018-12-14 10:31:09 +01:00
// We click on a link that leave a page we have to save search criteria, contextpage, limit and page. We save them from tmp to no tmp
2018-04-08 12:40:19 +02:00
if ( ! empty ( $_SESSION [ 'lastsearch_values_tmp_' . $relativepathstring ]))
{
2018-06-23 11:55:04 +02:00
$_SESSION [ 'lastsearch_values_' . $relativepathstring ] = $_SESSION [ 'lastsearch_values_tmp_' . $relativepathstring ];
2018-04-08 12:40:19 +02:00
unset ( $_SESSION [ 'lastsearch_values_tmp_' . $relativepathstring ]);
}
2018-06-23 11:55:04 +02:00
if ( ! empty ( $_SESSION [ 'lastsearch_contextpage_tmp_' . $relativepathstring ]))
{
$_SESSION [ 'lastsearch_contextpage_' . $relativepathstring ] = $_SESSION [ 'lastsearch_contextpage_tmp_' . $relativepathstring ];
unset ( $_SESSION [ 'lastsearch_contextpage_tmp_' . $relativepathstring ]);
}
2018-12-14 10:31:09 +01:00
if ( ! empty ( $_SESSION [ 'lastsearch_page_tmp_' . $relativepathstring ]) && $_SESSION [ 'lastsearch_page_tmp_' . $relativepathstring ] > 1 )
{
$_SESSION [ 'lastsearch_page_' . $relativepathstring ] = $_SESSION [ 'lastsearch_page_tmp_' . $relativepathstring ];
unset ( $_SESSION [ 'lastsearch_page_tmp_' . $relativepathstring ]);
}
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 ]);
}
2018-04-08 12:40:19 +02: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.
if ( ! isset ( $_SESSION [ " dol_login " ]))
{
// New session for this login has started.
$error = 0 ;
// Store value into session (values always stored)
$_SESSION [ " dol_login " ] = $user -> login ;
$_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 : '' ;
$_SESSION [ " dol_company " ] = $conf -> global -> MAIN_INFO_SOCIETE_NOM ;
$_SESSION [ " dol_entity " ] = $conf -> entity ;
// Store value into session (values stored only if defined)
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 ;
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 ;
// Call triggers
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php' ;
$interface = new Interfaces ( $db );
$result = $interface -> run_triggers ( 'USER_LOGIN' , $user , $user , $langs , $conf );
if ( $result < 0 ) {
$error ++ ;
}
// End call triggers
2018-12-10 17:50:58 +01:00
2017-10-16 08:47:05 +02:00
// Hooks on successfull login
$action = '' ;
$hookmanager -> initHooks ( array ( 'login' ));
$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
if ( $reshook < 0 ) $error ++ ;
2015-06-27 21:52:23 +02:00
2017-10-16 08:47:05 +02:00
if ( $error )
2015-06-27 21:52:23 +02:00
{
2017-10-16 08:47:05 +02:00
$db -> rollback ();
session_destroy ();
2018-12-10 11:19:52 +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 ;
}
else
{
$db -> commit ();
}
2016-01-24 17:40:07 +01:00
2017-10-16 08:47:05 +02:00
// Change landing page if defined.
$landingpage = ( empty ( $user -> conf -> MAIN_LANDING_PAGE ) ? ( empty ( $conf -> global -> MAIN_LANDING_PAGE ) ? '' : $conf -> global -> MAIN_LANDING_PAGE ) : $user -> conf -> MAIN_LANDING_PAGE );
if ( ! empty ( $landingpage )) // Example: /index.php
{
$newpath = dol_buildpath ( $landingpage , 1 );
if ( $_SERVER [ " PHP_SELF " ] != $newpath ) // not already on landing page (avoid infinite loop)
{
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
if ( $user -> admin )
{
$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 ;
}
2012-02-22 12:02:12 +01:00
2017-10-16 08:47:05 +02:00
/*
2017-04-14 12:52:32 +02: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
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
if ( empty ( $conf -> global -> MAIN_FORCETHEME ) && ! empty ( $user -> conf -> MAIN_THEME ))
{
$conf -> theme = $user -> conf -> MAIN_THEME ;
$conf -> css = " /theme/ " . $conf -> theme . " /style.css.php " ;
}
2013-04-03 15:20:56 +02:00
}
2012-02-22 12:02:12 +01:00
2013-04-03 15:20:56 +02:00
// Case forcing style from url
2017-05-16 13:27:32 +02:00
if ( GETPOST ( 'theme' , 'alpha' ))
2013-04-03 15:20:56 +02:00
{
$conf -> theme = GETPOST ( 'theme' , 'alpha' , 1 );
$conf -> css = " /theme/ " . $conf -> theme . " /style.css.php " ;
}
2013-06-24 17:36:33 +02:00
2013-04-03 15:20:56 +02:00
2013-06-05 16:24:32 +02:00
// Set javascript option
2017-05-16 13:27:32 +02:00
if ( ! GETPOST ( 'nojs' , 'int' )) // If javascript was not disabled on URL
2013-06-05 16:24:32 +02:00
{
if ( ! empty ( $user -> conf -> MAIN_DISABLE_JAVASCRIPT ))
{
$conf -> use_javascript_ajax =! $user -> conf -> MAIN_DISABLE_JAVASCRIPT ;
}
}
else $conf -> use_javascript_ajax = 0 ;
2016-05-09 14:59:59 +02:00
// Set MAIN_OPTIMIZEFORTEXTBROWSER
2017-05-16 13:27:32 +02:00
if ( GETPOST ( 'textbrowser' , 'int' ) || ( ! empty ( $conf -> browser -> name ) && $conf -> browser -> name == 'lynxlinks' ) || ! empty ( $user -> conf -> MAIN_OPTIMIZEFORTEXTBROWSER )) // If we must enable text browser
2016-05-09 14:59:59 +02:00
{
2017-10-16 08:47:05 +02:00
$conf -> global -> MAIN_OPTIMIZEFORTEXTBROWSER = 1 ;
2016-05-09 14:59:59 +02:00
}
2017-10-17 14:03:22 +02:00
elseif ( ! empty ( $user -> conf -> MAIN_OPTIMIZEFORTEXTBROWSER ))
{
$conf -> global -> MAIN_OPTIMIZEFORTEXTBROWSER = $user -> conf -> MAIN_OPTIMIZEFORTEXTBROWSER ;
}
2013-04-03 15:20:56 +02:00
2014-10-19 19:57:42 +02:00
// Set terminal output option according to conf->browser.
2017-05-16 13:27:32 +02: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 ;
2014-10-19 19:57:42 +02:00
if ( ! empty ( $conf -> browser -> layout ) && $conf -> browser -> layout != 'classic' ) $conf -> dol_no_mouse_hover = 1 ;
if (( ! empty ( $conf -> browser -> layout ) && $conf -> browser -> layout == 'phone' )
2014-07-27 20:31:11 +02:00
|| ( ! empty ( $_SESSION [ 'dol_screenwidth' ]) && $_SESSION [ 'dol_screenwidth' ] < 400 )
|| ( ! empty ( $_SESSION [ 'dol_screenheight' ]) && $_SESSION [ 'dol_screenheight' ] < 400 )
)
2013-04-03 15:20:56 +02:00
{
$conf -> dol_optimize_smallscreen = 1 ;
2007-10-02 15:54:34 +02:00
}
2014-08-08 14:37:51 +02:00
// If we force to use jmobile, then we reenable javascript
if ( ! empty ( $conf -> dol_use_jmobile )) $conf -> use_javascript_ajax = 1 ;
2014-10-19 19:57:42 +02:00
// Replace themes bugged with jmobile with eldy
2019-01-05 15:13:35 +01:00
if ( ! empty ( $conf -> dol_use_jmobile ) && in_array ( $conf -> theme , array ( 'bureau2crea' , 'cameleo' , 'amarok' )))
2013-06-24 17:36:33 +02:00
{
$conf -> theme = 'eldy' ;
$conf -> css = " /theme/ " . $conf -> theme . " /style.css.php " ;
2013-06-20 16:13:42 +02:00
}
2010-02-28 15:49:39 +01:00
if ( ! defined ( 'NOREQUIRETRAN' ))
2005-08-11 22:04:33 +02:00
{
2017-10-16 08:47:05 +02:00
if ( ! GETPOST ( 'lang' , 'aZ09' )) // If language was not forced on URL
{
// If user has chosen its own language
if ( ! empty ( $user -> conf -> MAIN_LANG_DEFAULT ))
{
// If different than current language
//print ">>>".$langs->getDefaultLang()."-".$user->conf->MAIN_LANG_DEFAULT;
if ( $langs -> getDefaultLang () != $user -> conf -> MAIN_LANG_DEFAULT )
{
$langs -> setDefaultLang ( $user -> conf -> MAIN_LANG_DEFAULT );
}
}
}
2005-08-11 22:04:33 +02:00
}
2005-10-02 22:38:46 +02:00
2009-12-29 19:10:48 +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?
if ( ! $user -> login ) accessforbidden ();
// Check if user is active
if ( $user -> statut < 1 )
{
// If not active, we refuse the user
$langs -> load ( " other " );
dol_syslog ( " Authentification ko as login is disabled " );
accessforbidden ( $langs -> trans ( " ErrorLoginDisabled " ));
exit ;
}
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
2011-02-16 20:59:16 +01:00
2017-05-23 00:13:07 +02:00
dol_syslog ( " --- Access to " . $_SERVER [ " PHP_SELF " ] . ' - action=' . GETPOST ( 'action' , 'az09' ) . ', massaction=' . GETPOST ( 'massaction' , 'az09' ));
2009-08-29 00:46:40 +02:00
//Another call for easy debugg
//dol_syslog("Access to ".$_SERVER["PHP_SELF"].' 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
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
2010-08-29 19:43:51 +02:00
$bc = array ( 0 => 'class="impair"' , 1 => 'class="pair"' );
2017-04-05 14:48:24 +02:00
$bcdd = array ( 0 => 'class="drag drop oddeven"' , 1 => 'class="drag drop oddeven"' );
2017-03-28 12:47:48 +02:00
$bcnd = array ( 0 => 'class="nodrag nodrop nohover"' , 1 => 'class="nodrag nodrop nohoverpair"' ); // Used for tr to add new lines
2017-04-17 13:02:40 +02:00
$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
2012-07-29 08:26:33 +02:00
$mesg = '' ; $warning = '' ; $error = 0 ;
2015-12-21 22:59:12 +01:00
// deprecated, see setEventMessages() and dol_htmloutput_events()
2012-07-29 08:26:33 +02: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
if ( empty ( $conf -> browser -> firefox ))
2005-09-29 21:30:59 +02:00
{
2017-10-16 08:47:05 +02: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 );
2005-09-29 21:30:59 +02:00
}
else
{
2017-10-16 08:47:05 +02: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
}
2018-09-17 17:39:58 +02:00
$heightforframes = 50 ;
2010-04-03 17:08:09 +02:00
2013-01-19 16:29:16 +01:00
// Init menu manager
2013-02-24 03:45:19 +01:00
if ( ! defined ( 'NOREQUIREMENU' ))
2013-01-19 16:29:16 +01:00
{
2013-02-24 03:45:19 +01:00
if ( empty ( $user -> societe_id )) // If internal user or not defined
2013-01-19 16:29:16 +01:00
{
2013-02-24 03:45:19 +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 );
2013-01-19 16:29:16 +01:00
}
2013-02-24 03:45:19 +01:00
else // If external user
2013-01-19 16:29:16 +01:00
{
2013-02-24 03:45:19 +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)
2013-04-03 15:20:56 +02:00
$file_menu = $conf -> standard_menu ;
2017-05-16 13:27:32 +02:00
if ( GETPOST ( 'menu' , 'alpha' )) $file_menu = GETPOST ( 'menu' , 'alpha' ); // example: menu=eldy_menu.php
2013-02-24 03:45:19 +01:00
if ( ! class_exists ( 'MenuManager' ))
{
$menufound = 0 ;
$dirmenus = array_merge ( array ( " /core/menus/ " ),( array ) $conf -> modules_parts [ 'menus' ]);
foreach ( $dirmenus as $dirmenu )
{
$menufound = dol_include_once ( $dirmenu . " standard/ " . $file_menu );
2013-05-12 15:25:12 +02:00
if ( class_exists ( 'MenuManager' )) break ;
2013-02-24 03:45:19 +01:00
}
2013-05-12 15:25:12 +02: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 );
$file_menu = 'eldy_menu.php' ;
include_once DOL_DOCUMENT_ROOT . " /core/menus/standard/ " . $file_menu ;
}
}
$menumanager = new MenuManager ( $db , empty ( $user -> societe_id ) ? 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
2010-02-28 05:32:18 +01:00
if ( ! function_exists ( " llxHeader " ))
{
2017-10-16 08:47:05 +02:00
/**
* Show HTML header HTML + BODY + Top menu + left menu + DIV
*
* @ 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 $arrayofjs Array of complementary js files
* @ param array $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 .
* @ param string $replacemainareaby Replace call to main_area () by a print of this string
* @ return void
*/
2017-10-13 13:22:24 +02:00
function llxHeader ( $head = '' , $title = '' , $help_url = '' , $target = '' , $disablejs = 0 , $disablehead = 0 , $arrayofjs = '' , $arrayofcss = '' , $morequerystring = '' , $morecssonbody = '' , $replacemainareaby = '' )
2012-05-07 17:05:15 +02:00
{
2017-10-16 08:47:05 +02:00
global $conf ;
2013-01-28 20:30:33 +01:00
2017-10-16 08:47:05 +02:00
// html header
2013-01-17 18:39:15 +01:00
top_htmlhead ( $head , $title , $disablejs , $disablehead , $arrayofjs , $arrayofcss );
2012-12-12 02:37:15 +01:00
2017-10-16 08:47:05 +02:00
print '<body id="mainbody"' . ( $morecssonbody ? ' class="' . $morecssonbody . '"' : '' ) . '>' . " \n " ;
2017-05-13 15:19:35 +02:00
2013-01-17 18:39:15 +01:00
// top menu and left menu area
2018-06-29 00:19:43 +02:00
if ( empty ( $conf -> dol_hide_topmenu ) || GETPOST ( 'dol_invisible_topmenu' , 'int' ))
2012-08-05 21:14:17 +02:00
{
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
2014-06-22 13:33:31 +02:00
if ( empty ( $conf -> dol_hide_leftmenu ))
2012-08-05 21:14:17 +02:00
{
2018-12-10 17:50:58 +01:00
left_menu ( '' , $help_url , '' , '' , 1 , $title , 1 ); // $menumanager is retreived 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
2017-10-13 13:22:24 +02:00
if ( $replacemainareaby )
{
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
/**
2011-03-08 12:32:52 +01:00
* Show HTTP header
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
*/
2018-01-24 13:40:39 +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
if ( $contenttype == 'text/html' ) header ( " Content-Type: text/html; charset= " . $conf -> file -> character_set_client );
else header ( " Content-Type: " . $contenttype );
// Security options
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)
2019-01-11 17:03:29 +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 " );
2018-04-30 15:31:05 +02:00
//header("X-XSS-Protection: 1"); // XSS protection of some browsers (note: use of Content-Security-Policy is more efficient). Disabled as deprecated.
2018-04-30 14:39:12 +02:00
if ( ! defined ( 'FORCECSP' ))
2017-10-16 08:47:05 +02:00
{
2018-04-30 14:39:12 +02:00
//if (! isset($conf->global->MAIN_HTTP_CONTENT_SECURITY_POLICY))
//{
// // A default security policy that keep usage of js external component like ckeditor, stripe, google, working
// $contentsecuritypolicy = "font-src *; img-src *; style-src * 'unsafe-inline' 'unsafe-eval'; default-src 'self' *.stripe.com 'unsafe-inline' 'unsafe-eval'; script-src 'self' *.stripe.com 'unsafe-inline' 'unsafe-eval'; frame-src 'self' *.stripe.com; connect-src 'self';";
//}
//else $contentsecuritypolicy = $conf->global->MAIN_HTTP_CONTENT_SECURITY_POLICY;
$contentsecuritypolicy = $conf -> global -> MAIN_HTTP_CONTENT_SECURITY_POLICY ;
if ( ! is_object ( $hookmanager )) $hookmanager = new HookManager ( $db );
$hookmanager -> initHooks ( " main " );
$parameters = array ( 'contentsecuritypolicy' => $contentsecuritypolicy );
$result = $hookmanager -> executeHooks ( 'setContentSecurityPolicy' , $parameters ); // Note that $action and $object may have been modified by some hooks
if ( $result > 0 ) $contentsecuritypolicy = $hookmanager -> resPrint ; // Replace CSP
else $contentsecuritypolicy .= $hookmanager -> resPrint ; // Concat CSP
if ( ! empty ( $contentsecuritypolicy ))
{
// For example, to restrict 'script', 'object', 'frames' or 'img' to some domains:
// 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
// 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 *;
// Pre-existing site that uses too much inline code to fix but wants to ensure resources are loaded only over https and disable plugins:
// default-src http: https: 'unsafe-eval' 'unsafe-inline'; object-src 'none'
header ( " Content-Security-Policy: " . $contentsecuritypolicy );
}
}
elseif ( constant ( 'FORCECSP' ))
{
header ( " Content-Security-Policy: " . constant ( 'FORCECSP' ));
2017-10-16 08:47:05 +02:00
}
2018-01-24 13:40:39 +01:00
if ( $forcenocache )
{
header ( " Cache-Control: no-cache, no-store, must-revalidate, max-age=0 " );
}
2010-08-30 20:31:59 +02:00
}
2005-01-01 20:48:22 +01:00
/**
2012-02-18 17:10:29 +01:00
* Ouput html header of a page .
* 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
* @ param int $disablejmobile Disable jmobile ( No more used )
2017-01-29 16:42:59 +01:00
* @ param int $disablenofollow Disable no follow tag
2011-09-12 19:43:31 +02:00
* @ return void
2002-12-31 15:10:59 +01:00
*/
2017-01-29 16:42:59 +01:00
function top_htmlhead ( $head , $title = '' , $disablejs = 0 , $disablehead = 0 , $arrayofjs = '' , $arrayofcss = '' , $disablejmobile = 0 , $disablenofollow = 0 )
2002-12-31 15:10:59 +01:00
{
2018-06-28 22:59:53 +02:00
global $db , $conf , $langs , $user , $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
2017-10-16 08:47:05 +02: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 " ;
2017-10-16 08:47:05 +02:00
if ( ! empty ( $conf -> global -> MAIN_USE_CACHE_MANIFEST )) print '<html lang="' . substr ( $langs -> defaultlang , 0 , 2 ) . '" manifest="' . DOL_URL_ROOT . '/cache.manifest">' . " \n " ;
else print '<html lang="' . substr ( $langs -> defaultlang , 0 , 2 ) . '">' . " \n " ;
//print '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr">'."\n";
if ( empty ( $disablehead ))
{
2019-01-12 14:35:51 +01:00
if ( ! is_object ( $hookmanager )) $hookmanager = new HookManager ( $db );
$hookmanager -> initHooks ( " main " );
$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
2017-05-16 13:27:32 +02: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
2018-05-26 12:05:39 +02:00
print '<meta charset="UTF-8">' . " \n " ;
2017-10-28 13:36:23 +02:00
print '<meta name="robots" content="noindex' . ( $disablenofollow ? '' : ',nofollow' ) . '">' . " \n " ; // Do not index
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 " ;
2018-08-16 14:47:12 +02:00
2017-10-16 08:47:05 +02:00
// Favicon
2015-09-27 14:15:09 +02:00
$favicon = dol_buildpath ( '/theme/' . $conf -> theme . '/img/favicon.ico' , 1 );
2017-10-16 08:47:05 +02:00
if ( ! empty ( $conf -> global -> MAIN_FAVICON_URL )) $favicon = $conf -> global -> MAIN_FAVICON_URL ;
if ( empty ( $conf -> dol_use_jmobile )) print '<link rel="shortcut icon" type="image/x-icon" href="' . $favicon . '"/>' . " \n " ; // Not required into an Android webview
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";
//if (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) print '<link rel="copyright" title="GNU General Public License" href="http://www.gnu.org/copyleft/gpl.html#SEC1">'."\n";
//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
2018-08-16 14:47:12 +02:00
// Auto refresh page
if ( GETPOST ( 'autorefresh' , 'int' ) > 0 ) print '<meta http-equiv="refresh" content="' . GETPOST ( 'autorefresh' , 'int' ) . '">' ;
2017-10-16 08:47:05 +02:00
// Displays title
$appli = constant ( 'DOL_APPLICATION_TITLE' );
if ( ! empty ( $conf -> global -> MAIN_APPLICATION_TITLE )) $appli = $conf -> global -> MAIN_APPLICATION_TITLE ;
2018-06-28 22:59:53 +02:00
print '<title>' ;
$titletoshow = '' ;
if ( $title && ! empty ( $conf -> global -> MAIN_HTML_TITLE ) && preg_match ( '/noapp/' , $conf -> global -> MAIN_HTML_TITLE )) $titletoshow = dol_htmlentities ( $title );
else if ( $title ) $titletoshow = dol_htmlentities ( $appli . ' - ' . $title );
else $titletoshow = dol_htmlentities ( $appli );
$parameters = array ( 'title' => $titletoshow );
$result = $hookmanager -> executeHooks ( 'setHtmlTitle' , $parameters ); // Note that $action and $object may have been modified by some hooks
if ( $result > 0 ) $titletoshow = $hookmanager -> resPrint ; // Replace Title to show
else $titletoshow .= $hookmanager -> resPrint ; // Concat to Title to show
print $titletoshow ;
print '</title>' ;
2017-10-16 08:47:05 +02:00
print " \n " ;
if ( GETPOST ( 'version' , 'int' )) $ext = 'version=' . GETPOST ( 'version' , 'int' ); // usefull to force no cache on css/js
if ( GETPOST ( 'testmenuhider' , 'int' ) || ! empty ( $conf -> global -> MAIN_TESTMENUHIDER )) $ext .= '&testmenuhider=' . ( GETPOST ( 'testmenuhider' , 'int' ) ? GETPOST ( 'testmenuhider' , 'int' ) : $conf -> global -> MAIN_TESTMENUHIDER );
$themeparam = '?lang=' . $langs -> defaultlang . '&theme=' . $conf -> theme . ( GETPOST ( 'optioncss' , 'aZ09' ) ? '&optioncss=' . GETPOST ( 'optioncss' , 'aZ09' , 1 ) : '' ) . '&userid=' . $user -> id . '&entity=' . $conf -> entity ;
$themeparam .= ( $ext ? '&' . $ext : '' );
if ( ! empty ( $_SESSION [ 'dol_resetcache' ])) $themeparam .= '&dol_resetcache=' . $_SESSION [ 'dol_resetcache' ];
if ( GETPOST ( 'dol_hide_topmenu' , 'int' )) { $themeparam .= '&dol_hide_topmenu=' . GETPOST ( 'dol_hide_topmenu' , 'int' ); }
if ( GETPOST ( 'dol_hide_leftmenu' , 'int' )) { $themeparam .= '&dol_hide_leftmenu=' . GETPOST ( 'dol_hide_leftmenu' , 'int' ); }
if ( GETPOST ( 'dol_optimize_smallscreen' , 'int' )) { $themeparam .= '&dol_optimize_smallscreen=' . GETPOST ( 'dol_optimize_smallscreen' , 'int' ); }
if ( GETPOST ( 'dol_no_mouse_hover' , 'int' )) { $themeparam .= '&dol_no_mouse_hover=' . GETPOST ( 'dol_no_mouse_hover' , 'int' ); }
if ( GETPOST ( 'dol_use_jmobile' , 'int' )) { $themeparam .= '&dol_use_jmobile=' . GETPOST ( 'dol_use_jmobile' , 'int' ); $conf -> dol_use_jmobile = GETPOST ( 'dol_use_jmobile' , 'int' ); }
if ( ! defined ( 'DISABLE_JQUERY' ) && ! $disablejs && $conf -> use_javascript_ajax )
{
print '<!-- Includes CSS for JQuery (Ajax library) -->' . " \n " ;
2017-12-20 20:18:41 +01:00
$jquerytheme = 'base' ;
2017-10-16 08:47:05 +02:00
if ( ! empty ( $conf -> global -> MAIN_USE_JQUERY_THEME )) $jquerytheme = $conf -> global -> MAIN_USE_JQUERY_THEME ;
2019-01-03 21:14:59 +01:00
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
2017-10-16 08:47:05 +02:00
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"...
{
$tmpplugin = empty ( $conf -> global -> MAIN_USE_JQUERY_MULTISELECT ) ? constant ( 'REQUIRE_JQUERY_MULTISELECT' ) : $conf -> global -> MAIN_USE_JQUERY_MULTISELECT ;
2017-10-21 19:05:24 +02:00
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
2017-10-16 08:47:05 +02:00
if ( ! defined ( 'DISABLE_FONT_AWSOME' ))
{
print '<!-- Includes CSS for font awesome -->' . " \n " ;
2019-01-03 21:14:59 +01:00
print '<link rel="stylesheet" type="text/css" href="' . DOL_URL_ROOT . '/theme/common/fontawesome/css/font-awesome.min.css' . ( $ext ? '?' . $ext : '' ) . '">' . " \n " ;
if ( ! empty ( $conf -> global -> MAIN_USE_FONT_AWESOME_5 ))
{
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'
$themepath = dol_buildpath ( $conf -> css , 1 );
$themesubdir = '' ;
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 )))
{
2013-01-08 15:21:56 +01:00
$themepath = dol_buildpath ( $reldir . $conf -> css , 1 );
2013-01-12 16:00:38 +01:00
$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 " ;
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 /)
if ( ! empty ( $conf -> modules_parts [ 'css' ]))
{
$arraycss = ( array ) $conf -> modules_parts [ 'css' ];
foreach ( $arraycss as $modcss => $filescss )
{
$filescss = ( array ) $filescss ; // To be sure filecss is an array
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 );
// cssfile is a relative path
print '<!-- Includes CSS added by module ' . $modcss . ' -->' . " \n " . '<link rel="stylesheet" type="text/css" href="' . dol_buildpath ( $cssfile , 1 );
// 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 " ;
}
}
}
// CSS forced by page in top_htmlhead call (relative url starting with /)
if ( is_array ( $arrayofcss ))
{
foreach ( $arrayofcss as $cssfile )
{
print '<!-- Includes CSS added by page -->' . " \n " . '<link rel="stylesheet" type="text/css" title="default" href="' . dol_buildpath ( $cssfile , 1 );
// 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.
if ( ! preg_match ( '/\.css$/i' , $cssfile )) print $themeparam ;
print '">' . " \n " ;
}
}
2012-02-22 12:02:12 +01:00
2017-10-16 08:47:05 +02:00
// Output standard javascript links
if ( ! defined ( 'DISABLE_JQUERY' ) && ! $disablejs && ! empty ( $conf -> use_javascript_ajax ))
{
// JQuery. Must be before other includes
print '<!-- Includes JS for JQuery -->' . " \n " ;
if ( defined ( 'JS_JQUERY' ) && constant ( 'JS_JQUERY' )) print '<script type="text/javascript" src="' . JS_JQUERY . 'jquery.min.js' . ( $ext ? '?' . $ext : '' ) . '"></script>' . " \n " ;
else print '<script type="text/javascript" src="' . DOL_URL_ROOT . '/includes/jquery/js/jquery.min.js' . ( $ext ? '?' . $ext : '' ) . '"></script>' . " \n " ;
if ( ! empty ( $conf -> global -> MAIN_FEATURES_LEVEL ) && ! defined ( 'JS_JQUERY_MIGRATE_DISABLED' ))
{
if ( defined ( 'JS_JQUERY_MIGRATE' ) && constant ( 'JS_JQUERY_MIGRATE' )) print '<script type="text/javascript" src="' . JS_JQUERY_MIGRATE . 'jquery-migrate.min.js' . ( $ext ? '?' . $ext : '' ) . '"></script>' . " \n " ;
else print '<script type="text/javascript" src="' . DOL_URL_ROOT . '/includes/jquery/js/jquery-migrate.min.js' . ( $ext ? '?' . $ext : '' ) . '"></script>' . " \n " ;
}
if ( defined ( 'JS_JQUERY_UI' ) && constant ( 'JS_JQUERY_UI' )) print '<script type="text/javascript" src="' . JS_JQUERY_UI . 'jquery-ui.min.js' . ( $ext ? '?' . $ext : '' ) . '"></script>' . " \n " ;
else print '<script type="text/javascript" src="' . DOL_URL_ROOT . '/includes/jquery/js/jquery-ui.min.js' . ( $ext ? '?' . $ext : '' ) . '"></script>' . " \n " ;
2017-11-07 16:15:59 +01:00
if ( ! defined ( 'DISABLE_JQUERY_TABLEDND' )) print '<script type="text/javascript" src="' . DOL_URL_ROOT . '/includes/jquery/plugins/tablednd/jquery.tablednd.min.js' . ( $ext ? '?' . $ext : '' ) . '"></script>' . " \n " ;
2017-10-16 08:47:05 +02:00
// jQuery jnotify
if ( empty ( $conf -> global -> MAIN_DISABLE_JQUERY_JNOTIFY ) && ! defined ( 'DISABLE_JQUERY_JNOTIFY' ))
{
print '<script type="text/javascript" src="' . DOL_URL_ROOT . '/includes/jquery/plugins/jnotify/jquery.jnotify.min.js' . ( $ext ? '?' . $ext : '' ) . '"></script>' . " \n " ;
}
// Flot
if ( empty ( $conf -> global -> MAIN_DISABLE_JQUERY_FLOT ) && ! defined ( 'DISABLE_JQUERY_FLOT' ))
{
if ( constant ( 'JS_JQUERY_FLOT' ))
{
print '<script type="text/javascript" src="' . JS_JQUERY_FLOT . 'jquery.flot.js' . ( $ext ? '?' . $ext : '' ) . '"></script>' . " \n " ;
print '<script type="text/javascript" src="' . JS_JQUERY_FLOT . 'jquery.flot.pie.js' . ( $ext ? '?' . $ext : '' ) . '"></script>' . " \n " ;
print '<script type="text/javascript" src="' . JS_JQUERY_FLOT . 'jquery.flot.stack.js' . ( $ext ? '?' . $ext : '' ) . '"></script>' . " \n " ;
}
else
{
print '<script type="text/javascript" src="' . DOL_URL_ROOT . '/includes/jquery/plugins/flot/jquery.flot.min.js' . ( $ext ? '?' . $ext : '' ) . '"></script>' . " \n " ;
print '<script type="text/javascript" src="' . DOL_URL_ROOT . '/includes/jquery/plugins/flot/jquery.flot.pie.min.js' . ( $ext ? '?' . $ext : '' ) . '"></script>' . " \n " ;
print '<script type="text/javascript" src="' . DOL_URL_ROOT . '/includes/jquery/plugins/flot/jquery.flot.stack.min.js' . ( $ext ? '?' . $ext : '' ) . '"></script>' . " \n " ;
}
}
// jQuery jeditable
if ( ! empty ( $conf -> global -> MAIN_USE_JQUERY_JEDITABLE ) && ! defined ( 'DISABLE_JQUERY_JEDITABLE' ))
{
print '<!-- JS to manage editInPlace feature -->' . " \n " ;
2017-12-20 13:28:41 +01:00
print '<script type="text/javascript" src="' . DOL_URL_ROOT . '/includes/jquery/plugins/jeditable/jquery.jeditable.js' . ( $ext ? '?' . $ext : '' ) . '"></script>' . " \n " ;
2017-10-16 08:47:05 +02:00
print '<script type="text/javascript" src="' . DOL_URL_ROOT . '/includes/jquery/plugins/jeditable/jquery.jeditable.ui-datepicker.js' . ( $ext ? '?' . $ext : '' ) . '"></script>' . " \n " ;
print '<script type="text/javascript" src="' . DOL_URL_ROOT . '/includes/jquery/plugins/jeditable/jquery.jeditable.ui-autocomplete.js' . ( $ext ? '?' . $ext : '' ) . '"></script>' . " \n " ;
print '<script type="text/javascript">' . " \n " ;
print 'var urlSaveInPlace = \'' . DOL_URL_ROOT . '/core/ajax/saveinplace.php\';' . " \n " ;
print 'var urlLoadInPlace = \'' . DOL_URL_ROOT . '/core/ajax/loadinplace.php\';' . " \n " ;
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 ?
print 'var cancelInPlace = \'' . $langs -> trans ( 'Cancel' ) . '\';' . " \n " ;
print 'var submitInPlace = \'' . $langs -> trans ( 'Ok' ) . '\';' . " \n " ;
print 'var indicatorInPlace = \'<img src="' . DOL_URL_ROOT . " /theme/ " . $conf -> theme . " /img/working.gif " . '">\';' . " \n " ;
print 'var withInPlace = 300;' ; // width in pixel for default string edit
print '</script>' . " \n " ;
print '<script type="text/javascript" src="' . DOL_URL_ROOT . '/core/js/editinplace.js' . ( $ext ? '?' . $ext : '' ) . '"></script>' . " \n " ;
print '<script type="text/javascript" src="' . DOL_URL_ROOT . '/includes/jquery/plugins/jeditable/jquery.jeditable.ckeditor.js' . ( $ext ? '?' . $ext : '' ) . '"></script>' . " \n " ;
}
2013-04-01 23:38:39 +02:00
// jQuery Timepicker
if ( ! empty ( $conf -> global -> MAIN_USE_JQUERY_TIMEPICKER ) || defined ( 'REQUIRE_JQUERY_TIMEPICKER' ))
{
2014-01-18 00:50:21 +01:00
print '<script type="text/javascript" src="' . DOL_URL_ROOT . '/includes/jquery/plugins/timepicker/jquery-ui-timepicker-addon.js' . ( $ext ? '?' . $ext : '' ) . '"></script>' . " \n " ;
print '<script type="text/javascript" src="' . DOL_URL_ROOT . '/core/js/timepicker.js.php?lang=' . $langs -> defaultlang . ( $ext ? '&' . $ext : '' ) . '"></script>' . " \n " ;
2013-04-01 23:38:39 +02:00
}
2017-02-23 00:45:27 +01:00
if ( ! defined ( 'DISABLE_SELECT2' ) && ( ! empty ( $conf -> global -> MAIN_USE_JQUERY_MULTISELECT ) || defined ( 'REQUIRE_JQUERY_MULTISELECT' ))) // jQuery plugin "mutiselect", "multiple-select", "select2", ...
2014-11-16 00:46:27 +01:00
{
$tmpplugin = empty ( $conf -> global -> MAIN_USE_JQUERY_MULTISELECT ) ? constant ( 'REQUIRE_JQUERY_MULTISELECT' ) : $conf -> global -> MAIN_USE_JQUERY_MULTISELECT ;
2017-10-26 14:06:23 +02:00
print '<script type="text/javascript" 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
2014-11-16 00:46:27 +01:00
}
2018-09-15 13:31:25 +02:00
if ( ! defined ( 'DISABLE_MULTISELECT' )) // jQuery plugin "mutiselect" to select with checkboxes
{
print '<script type="text/javascript" src="' . DOL_URL_ROOT . '/includes/jquery/plugins/multiselect/jquery.multi-select.js' . ( $ext ? '?' . $ext : '' ) . '"></script>' . " \n " ;
}
}
2013-04-01 23:38:39 +02:00
2013-06-05 16:24:32 +02:00
if ( ! $disablejs && ! empty ( $conf -> use_javascript_ajax ))
2013-04-01 23:38:39 +02:00
{
2012-02-18 17:30:58 +01:00
// CKEditor
2017-02-23 00:45:27 +01:00
if ( ! empty ( $conf -> fckeditor -> enabled ) && ( empty ( $conf -> global -> FCKEDITOR_EDITORNAME ) || $conf -> global -> FCKEDITOR_EDITORNAME == 'ckeditor' ) && ! defined ( 'DISABLE_CKEDITOR' ))
2012-02-18 17:30:58 +01:00
{
print '<!-- Includes JS for CKEditor -->' . " \n " ;
2015-08-06 16:29:05 +02:00
$pathckeditor = DOL_URL_ROOT . '/includes/ckeditor/ckeditor/' ;
2014-03-13 12:45:20 +01:00
$jsckeditor = 'ckeditor.js' ;
2014-03-08 14:06:01 +01:00
if ( constant ( 'JS_CKEDITOR' )) // To use external ckeditor 4 js lib
{
$pathckeditor = constant ( 'JS_CKEDITOR' );
}
2012-06-23 20:17:51 +02:00
print '<script type="text/javascript">' ;
print 'var CKEDITOR_BASEPATH = \'' . $pathckeditor . '\';' . " \n " ;
2016-07-14 11:46:32 +02:00
print 'var ckeditorConfig = \'' . dol_buildpath ( $themesubdir . '/theme/' . $conf -> theme . '/ckeditor/config.js' . ( $ext ? '?' . $ext : '' ), 1 ) . '\';' . " \n " ; // $themesubdir='' in standard usage
2012-06-23 20:17:51 +02: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 " ;
2014-03-08 14:17:49 +01:00
print '<script type="text/javascript" src="' . $pathckeditor . $jsckeditor . ( $ext ? '?' . $ext : '' ) . '"></script>' . " \n " ;
2012-02-18 17:30:58 +01:00
}
2017-06-10 16:29:25 +02:00
2017-01-20 18:41:18 +01:00
// Browser notifications
2017-02-23 00:45:27 +01:00
if ( ! defined ( 'DISABLE_BROWSER_NOTIF' ))
2017-01-20 18:41:18 +01:00
{
2017-02-23 00:45:27 +01:00
$enablebrowsernotif = false ;
2017-08-20 16:07:22 +02:00
if ( ! empty ( $conf -> agenda -> enabled ) && ! empty ( $conf -> global -> AGENDA_REMINDER_BROWSER )) $enablebrowsernotif = true ;
2017-04-30 23:39:35 +02:00
if ( $conf -> browser -> layout == 'phone' ) $enablebrowsernotif = false ;
2017-02-23 00:45:27 +01:00
if ( $enablebrowsernotif )
{
2017-04-30 23:39:35 +02:00
print '<!-- Includes JS of Dolibarr (brwoser layout = ' . $conf -> browser -> layout . ')-->' . " \n " ;
2017-05-10 10:06:44 +02:00
print '<script type="text/javascript" src="' . DOL_URL_ROOT . '/core/js/lib_notification.js.php' . ( $ext ? '?' . $ext : '' ) . '"></script>' . " \n " ;
2017-02-23 00:45:27 +01:00
}
2017-01-20 18:41:18 +01:00
}
2017-06-10 16:29:25 +02:00
2011-02-05 04:34:25 +01:00
// Global js function
print '<!-- Includes JS of Dolibarr -->' . " \n " ;
2017-11-18 12:35:25 +01:00
print '<script type="text/javascript" src="' . DOL_URL_ROOT . '/core/js/lib_head.js.php?lang=' . $langs -> defaultlang . ( $ext ? '&' . $ext : '' ) . '"></script>' . " \n " ;
2011-11-01 04:57:45 +01:00
2012-06-12 18:35:29 +02:00
// JS forced by modules (relative url starting with /)
2013-01-08 15:21:56 +01:00
if ( ! empty ( $conf -> modules_parts [ 'js' ])) // $conf->modules_parts['js'] is array('module'=>array('file1','file2'))
2012-08-08 20:43:23 +02:00
{
$arrayjs = ( array ) $conf -> modules_parts [ 'js' ];
foreach ( $arrayjs as $modjs => $filesjs )
{
$filesjs = ( array ) $filesjs ; // To be sure filejs is an array
foreach ( $filesjs as $jsfile )
{
// jsfile is a relative path
2013-02-24 21:16:36 +01:00
print '<!-- Include JS added by module ' . $modjs . '-->' . " \n " . '<script type="text/javascript" src="' . dol_buildpath ( $jsfile , 1 ) . '"></script>' . " \n " ;
2012-08-08 20:43:23 +02:00
}
}
}
2012-06-12 18:35:29 +02:00
// JS forced by page in top_htmlhead (relative url starting with /)
2011-10-31 11:01:26 +01:00
if ( is_array ( $arrayofjs ))
{
2013-02-24 21:16:36 +01:00
print '<!-- Includes JS added by page -->' . " \n " ;
2012-02-22 12:02:12 +01:00
foreach ( $arrayofjs as $jsfile )
{
if ( preg_match ( '/^http/i' , $jsfile ))
{
print '<script type="text/javascript" src="' . $jsfile . '"></script>' . " \n " ;
}
else
{
print '<script type="text/javascript" src="' . dol_buildpath ( $jsfile , 1 ) . '"></script>' . " \n " ;
}
}
2011-10-31 11:01:26 +01:00
}
2012-02-22 12:02:12 +01:00
}
2009-08-09 13:37:32 +02:00
2012-02-22 12:02:12 +01:00
if ( ! empty ( $head )) print $head . " \n " ;
if ( ! empty ( $conf -> global -> MAIN_HTML_HEADER )) print $conf -> global -> MAIN_HTML_HEADER . " \n " ;
2009-10-16 19:15:32 +02:00
2019-01-12 14:35:51 +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
2012-02-22 12:02:12 +01:00
print " </head> \n \n " ;
}
2010-04-06 23:56:03 +02:00
2012-02-22 12:02:12 +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
*/
2015-11-14 22:38:29 +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 ;
global $hookmanager , $menumanager ;
2012-02-29 19:41:12 +01:00
2017-10-16 08:47:05 +02:00
$searchform = '' ;
$bookmarks = '' ;
2016-07-07 09:47:12 +02:00
2017-10-16 08:47:05 +02:00
// Instantiate hooks of thirdparty module
$hookmanager -> initHooks ( array ( 'toprightmenu' ));
2010-04-05 20:41:34 +02:00
2017-10-16 08:47:05 +02:00
$toprightmenu = '' ;
2010-06-27 15:19:38 +02:00
2017-10-16 08:47:05 +02:00
// For backward compatibility with old modules
if ( empty ( $conf -> headerdone ))
{
top_htmlhead ( $head , $title , $disablejs , $disablehead , $arrayofjs , $arrayofcss );
print '<body id="mainbody">' ;
}
2010-11-02 13:14:06 +01:00
2017-10-16 08:47:05 +02:00
/*
2012-02-22 12:02:12 +01:00
* Top menu
2012-05-07 17:05:15 +02:00
*/
2018-06-29 00:19:43 +02:00
if (( empty ( $conf -> dol_hide_topmenu ) || GETPOST ( 'dol_invisible_topmenu' , 'int' )) && ( ! defined ( 'NOREQUIREMENU' ) || ! constant ( 'NOREQUIREMENU' )))
2017-10-16 08:47:05 +02:00
{
print " \n " . '<!-- Start top horizontal -->' . " \n " ;
2018-06-29 00:19:43 +02:00
print '<div class="side-nav-vert' . ( GETPOST ( 'dol_invisible_topmenu' , 'int' ) ? ' hidden' : '' ) . '"><div id="id-top">' ; // 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
print '<div id="tmenu_tooltip' . ( empty ( $conf -> global -> MAIN_MENU_INVERT ) ? '' : 'invert' ) . '" class="tmenu">' . " \n " ;
$menumanager -> atarget = $target ;
$menumanager -> showmenu ( 'top' , array ( 'searchform' => $searchform , 'bookmarks' => $bookmarks )); // This contains a \n
print " </div> \n " ;
// Define link to login card
$appli = constant ( 'DOL_APPLICATION_TITLE' );
if ( ! empty ( $conf -> global -> MAIN_APPLICATION_TITLE ))
{
$appli = $conf -> global -> MAIN_APPLICATION_TITLE ;
if ( preg_match ( '/\d\.\d/' , $appli ))
{
2014-01-15 02:04:44 +01:00
if ( ! preg_match ( '/' . preg_quote ( DOL_VERSION ) . '/' , $appli )) $appli .= " ( " . DOL_VERSION . " ) " ; // If new title contains a version that is different than core
2017-10-16 08:47:05 +02:00
}
else $appli .= " " . DOL_VERSION ;
}
else $appli .= " " . DOL_VERSION ;
if ( ! empty ( $conf -> global -> MAIN_FEATURES_LEVEL )) $appli .= " <br> " . $langs -> trans ( " LevelOfFeature " ) . ': ' . $conf -> global -> MAIN_FEATURES_LEVEL ;
$logouttext = '' ;
if ( empty ( $conf -> global -> MAIN_OPTIMIZEFORTEXTBROWSER ))
{
//$logouthtmltext=$appli.'<br>';
if ( $_SESSION [ " dol_authmode " ] != 'forceuser' && $_SESSION [ " dol_authmode " ] != 'http' )
{
$logouthtmltext .= $langs -> trans ( " Logout " ) . '<br>' ;
2018-12-15 16:20:36 +01:00
$logouttext .= '<a accesskey="l" href="' . DOL_URL_ROOT . '/user/logout.php">' ;
2017-10-16 08:47:05 +02:00
//$logouttext .= img_picto($langs->trans('Logout').":".$langs->trans('Logout'), 'logout_top.png', 'class="login"', 0, 0, 1);
$logouttext .= '<span class="fa fa-sign-out atoplogin"></span>' ;
$logouttext .= '</a>' ;
}
else
{
$logouthtmltext .= $langs -> trans ( " NoLogoutProcessWithAuthMode " , $_SESSION [ " dol_authmode " ]);
$logouttext .= img_picto ( $langs -> trans ( 'Logout' ) . " : " . $langs -> trans ( 'Logout' ), 'logout_top.png' , 'class="login"' , 0 , 0 , 1 );
}
}
print '<div class="login_block">' . " \n " ;
// Add login user link
$toprightmenu .= '<div class="login_block_user">' ;
// Login name with photo and tooltip
2015-10-24 13:52:35 +02:00
$mode =- 1 ;
2017-10-16 08:47:05 +02:00
$toprightmenu .= '<div class="inline-block nowrap"><div class="inline-block login_block_elem login_block_elem_name" style="padding: 0px;">' ;
2017-10-22 21:15:08 +02:00
$toprightmenu .= $user -> getNomUrl ( $mode , '' , 1 , 0 , 11 , 0 , ( $user -> firstname ? 'firstname' : - 1 ), 'atoplogin' );
2017-10-16 08:47:05 +02:00
$toprightmenu .= '</div></div>' ;
2015-05-30 19:50:07 +02:00
2017-10-22 21:15:08 +02:00
$toprightmenu .= '</div>' . " \n " ;
2012-08-05 21:14:17 +02:00
2017-10-16 08:47:05 +02: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>')
2017-10-16 08:47:05 +02:00
$parameters = array ();
$result = $hookmanager -> executeHooks ( 'printTopRightMenu' , $parameters ); // Note that $action and $object may have been modified by some hooks
2013-07-28 17:02:13 +02:00
if ( is_numeric ( $result ))
{
2018-04-13 10:37:40 +02:00
if ( $result == 0 )
2018-04-13 02:42:19 +02:00
$toprightmenu .= $hookmanager -> resPrint ; // add
else
$toprightmenu = $hookmanager -> resPrint ; // replace
2013-07-28 17:02:13 +02:00
}
2018-04-13 10:37:40 +02:00
else
{
2018-04-13 02:42:19 +02: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
if ( ! empty ( $conf -> modulebuilder -> enabled ))
{
$text = '<a href="' . DOL_URL_ROOT . '/modulebuilder/index.php?mainmenu=home&leftmenu=admintools" target="_modulebuilder">' ;
//$text.= img_picto(":".$langs->trans("ModuleBuilder"), 'printer_top.png', 'class="printer"');
$text .= '<span class="fa fa-bug atoplogin"></span>' ;
$text .= '</a>' ;
$toprightmenu .=@ Form :: textwithtooltip ( '' , $langs -> trans ( " ModuleBuilder " ), 2 , 1 , $text , 'login_block_elem' , 2 );
}
2017-03-29 21:36:50 +02:00
// Link to print main content area
2018-09-02 16:45:03 +02:00
if ( empty ( $conf -> global -> MAIN_PRINT_DISABLELINK ) && empty ( $conf -> global -> MAIN_OPTIMIZEFORTEXTBROWSER ) && $conf -> browser -> layout != 'phone' )
2017-10-16 08:47:05 +02:00
{
$qs = dol_escape_htmltag ( $_SERVER [ " QUERY_STRING " ]);
if ( is_array ( $_POST ))
{
foreach ( $_POST as $key => $value ) {
2017-11-27 15:29:19 +01:00
if ( $key !== 'action' && $key !== 'password' && ! is_array ( $value )) $qs .= '&' . $key . '=' . urlencode ( $value );
2017-10-16 08:47:05 +02:00
}
}
2016-07-06 10:36:58 +02:00
$qs .= (( $qs && $morequerystring ) ? '&' : '' ) . $morequerystring ;
2017-10-16 08:47:05 +02:00
$text = '<a href="' . dol_escape_htmltag ( $_SERVER [ " PHP_SELF " ]) . '?' . $qs . ( $qs ? '&' : '' ) . 'optioncss=print" target="_blank">' ;
//$text.= img_picto(":".$langs->trans("PrintContentArea"), 'printer_top.png', 'class="printer"');
2019-01-03 21:14:59 +01:00
$text .= '<span class="fa fa-print atoplogin"></span>' ;
2017-10-16 08:47:05 +02:00
$text .= '</a>' ;
$toprightmenu .=@ Form :: textwithtooltip ( '' , $langs -> trans ( " PrintContentArea " ), 2 , 1 , $text , 'login_block_elem' , 2 );
}
// Link to Dolibarr wiki pages
if ( empty ( $conf -> global -> MAIN_HELP_DISABLELINK ) && empty ( $conf -> global -> MAIN_OPTIMIZEFORTEXTBROWSER ))
{
$langs -> load ( " help " );
$helpbaseurl = '' ;
$helppage = '' ;
$mode = '' ;
if ( empty ( $helppagename )) $helppagename = 'EN:User_documentation|FR:Documentation_utilisateur|ES:Documentación_usuarios' ;
// Get helpbaseurl, helppage and mode from helppagename and langs
$arrayres = getHelpParamFor ( $helppagename , $langs );
$helpbaseurl = $arrayres [ 'helpbaseurl' ];
$helppage = $arrayres [ 'helppage' ];
$mode = $arrayres [ 'mode' ];
// Link to help pages
if ( $helpbaseurl && $helppage )
{
$text = '' ;
2018-05-02 09:10:58 +02: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
$title = $appli . '<br>' ;
$title .= $langs -> trans ( $mode == 'wiki' ? 'GoToWikiHelpPage' : 'GoToHelpPage' );
if ( $mode == 'wiki' ) $title .= ' - ' . $langs -> trans ( " PageWiki " ) . ' "' . dol_escape_htmltag ( strtr ( $helppage , '_' , ' ' )) . '"' ;
2017-12-02 01:13:32 +01:00
$text .= '<a class="help" target="_blank" rel="noopener" href="' ;
2017-10-16 08:47:05 +02:00
if ( $mode == 'wiki' ) $text .= sprintf ( $helpbaseurl , urlencode ( html_entity_decode ( $helppage )));
else $text .= sprintf ( $helpbaseurl , $helppage );
$text .= '">' ;
//$text.=img_picto('', 'helpdoc_top').' ';
$text .= '<span class="fa fa-question-circle atoplogin"></span>' ;
//$toprightmenu.=$langs->trans($mode == 'wiki' ? 'OnlineHelp': 'Help');
//if ($mode == 'wiki') $text.=' ('.dol_trunc(strtr($helppage,'_',' '),8).')';
$text .= '</a>' ;
//$toprightmenu.='</div>'."\n";
$toprightmenu .=@ Form :: textwithtooltip ( '' , $title , 2 , 1 , $text , 'login_block_elem' , 2 );
}
}
2016-03-18 10:56:55 +01:00
2015-05-30 20:07:44 +02:00
// Logout link
2017-10-16 08:47:05 +02:00
$toprightmenu .=@ Form :: textwithtooltip ( '' , $logouthtmltext , 2 , 1 , $logouttext , 'login_block_elem' , 2 );
2015-05-30 20:07:44 +02:00
2017-10-16 08:47:05 +02:00
$toprightmenu .= '</div>' ;
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
2018-03-29 11:34:01 +02:00
print " </div> \n " ; // end div class="login_block"
2015-03-24 22:24:15 +01:00
print '</div></div>' ;
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
2017-10-16 08:47:05 +02:00
if ( empty ( $conf -> dol_hide_leftmenu ) && empty ( $conf -> dol_use_jmobile )) print '<!-- Begin div id-container --><div id="id-container" class="id-container' . ( $morecss ? ' ' . $morecss : '' ) . '">' ;
2010-04-05 20:41: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
*/
2015-11-07 15:13:51 +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
2017-10-16 08:47:05 +02:00
$searchform = '' ;
$bookmarks = '' ;
2009-02-24 03:41:21 +01:00
2017-10-16 08:47:05 +02: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
2017-10-16 08:47:05 +02:00
if ( empty ( $conf -> dol_hide_leftmenu ) && ( ! defined ( 'NOREQUIREMENU' ) || ! constant ( 'NOREQUIREMENU' )))
{
// Instantiate hooks of thirdparty module
$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
2017-11-14 15:10:46 +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
if ( ! is_object ( $form )) $form = new Form ( $db );
$selected =- 1 ;
$usedbyinclude = 1 ;
2018-03-21 20:44:32 +01:00
include_once DOL_DOCUMENT_ROOT . '/core/ajax/selectsearchbox.php' ; // This set $arrayresult
2018-03-21 15:08:20 +01:00
2017-10-20 01:18:21 +02:00
if ( $conf -> use_javascript_ajax && empty ( $conf -> global -> MAIN_USE_OLD_SEARCH_FORM ))
2017-10-16 08:47:05 +02:00
{
2018-03-21 20:43:26 +01:00
//$searchform.=$form->selectArrayAjax('searchselectcombo', DOL_URL_ROOT.'/core/ajax/selectsearchbox.php', $selected, '', '', 0, 1, 'vmenusearchselectcombo', 1, $langs->trans("Search"), 1);
2018-04-17 10:01:14 +02:00
$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 );
2017-10-16 08:47:05 +02:00
}
else
{
2017-10-20 01:18:21 +02:00
foreach ( $arrayresult as $key => $val )
2017-10-16 08:47:05 +02:00
{
2017-12-02 01:13:32 +01:00
//$searchform.=printSearchForm($val['url'], $val['url'], $val['label'], 'maxwidth100', 'sall', $val['shortcut'], 'searchleft', img_picto('',$val['img']));
$searchform .= printSearchForm ( $val [ 'url' ], $val [ 'url' ], $val [ 'label' ], 'maxwidth125' , 'sall' , $val [ 'shortcut' ], 'searchleft' , img_picto ( '' , $val [ 'img' ], '' , false , 1 , 1 ));
2017-10-16 08:47:05 +02: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
2015-11-12 12:22:21 +01:00
if ( empty ( $reshook ))
{
$searchform .= $hookmanager -> resPrint ;
}
else $searchform = $hookmanager -> resPrint ;
2017-11-14 15:10:46 +01:00
// Force special value for $searchform
2017-11-14 15:17:10 +01:00
if ( ! empty ( $conf -> global -> MAIN_OPTIMIZEFORTEXTBROWSER ) || empty ( $conf -> use_javascript_ajax ))
2017-11-14 15:10:46 +01:00
{
$urltosearch = DOL_URL_ROOT . '/core/search_page.php?showtitlebefore=1' ;
2018-12-28 00:41:05 +01:00
$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>' ;
2017-11-14 15:10:46 +01:00
}
elseif ( $conf -> use_javascript_ajax && ! empty ( $conf -> global -> MAIN_USE_OLD_SEARCH_FORM ))
2017-10-16 08:47:05 +02:00
{
$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 type = " text/javascript " >
2016-01-03 19:34:19 +01:00
jQuery ( document ) . ready ( function () {
jQuery ( " #divsearchforms1 " ) . click ( function (){
jQuery ( " #divsearchforms2 " ) . toggle ();
});
});
</ script > ' . " \n " ;
2017-10-16 08:47:05 +02:00
$searchform .= '</div>' ;
}
2016-03-18 10:56:55 +01:00
2017-10-16 08:47:05 +02:00
// Define $bookmarks
if ( ! empty ( $conf -> bookmark -> enabled ) && $user -> rights -> bookmark -> lire )
{
2018-07-26 11:57:25 +02:00
include_once DOL_DOCUMENT_ROOT . '/bookmarks/bookmarks.lib.php' ;
2017-10-16 08:47:05 +02:00
$langs -> load ( " bookmarks " );
2012-08-05 21:14:17 +02:00
2017-10-16 08:47:05 +02:00
$bookmarks = printBookmarksList ( $db , $langs );
}
2012-08-05 21:14:17 +02:00
2017-10-16 08:47:05 +02:00
// Left column
print '<!-- Begin left menu -->' . " \n " ;
2012-08-05 21:14:17 +02:00
2017-10-16 08:47:05 +02: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 ;
$menumanager -> showmenu ( 'left' , array ( 'searchform' => $searchform , 'bookmarks' => $bookmarks )); // 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
if ( empty ( $conf -> global -> MAIN_HIDE_VERSION )) // Version is already on help picto and on login page.
{
$doliurl = 'https://www.dolibarr.org' ;
//local communities
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' ;
$appli = constant ( 'DOL_APPLICATION_TITLE' );
if ( ! empty ( $conf -> global -> MAIN_APPLICATION_TITLE ))
{
$appli = $conf -> global -> MAIN_APPLICATION_TITLE ; $doliurl = '' ;
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 ;
print '<div id="blockvmenuhelpapp" class="blockvmenuhelp">' ;
2017-12-02 01:13:32 +01:00
if ( $doliurl ) print '<a class="help" target="_blank" rel="noopener" href="' . $doliurl . '">' ;
2017-10-16 08:47:05 +02:00
else print '<span class="help">' ;
print $appli ;
if ( $doliurl ) print '</a>' ;
else print '</span>' ;
print '</div>' . " \n " ;
}
2013-06-05 16:24:32 +02:00
2015-04-28 21:14:17 +02:00
// Link to bugtrack
2015-04-27 20:34:52 +02:00
if ( ! empty ( $conf -> global -> MAIN_BUGTRACK_ENABLELINK ))
{
require_once DOL_DOCUMENT_ROOT . '/core/lib/functions2.lib.php' ;
$bugbaseurl = 'https://github.com/Dolibarr/dolibarr/issues/new' ;
$bugbaseurl .= '?title=' ;
$bugbaseurl .= urlencode ( " Bug: " );
$bugbaseurl .= '&body=' ;
2018-09-02 16:47:58 +02:00
$bugbaseurl .= urlencode ( " # Bug \n " );
$bugbaseurl .= urlencode ( " \n " );
2016-02-19 18:20:51 +01:00
$bugbaseurl .= urlencode ( " ## Environment \n " );
2015-04-27 20:34:52 +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**: " . $_SERVER [ " REQUEST_URI " ] . " \n " );
$bugbaseurl .= urlencode ( " \n " );
2016-02-19 18:20:51 +01:00
$bugbaseurl .= urlencode ( " ## Report \n " );
2015-12-04 12:12:12 +01:00
print '<div id="blockvmenuhelpbugreport" class="blockvmenuhelp">' ;
2017-12-02 01:13:32 +01:00
print '<a class="help" target="_blank" rel="noopener" href="' . $bugbaseurl . '">' . $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
$parameters = array ();
$reshook = $hookmanager -> executeHooks ( 'printLeftBlock' , $parameters ); // Note that $action and $object may have been modified by some hooks
print $hookmanager -> resPrint ;
2012-08-05 21:14:17 +02:00
2017-10-16 08:47:05 +02:00
print '</div></div> <!-- End side-nav id-left -->' ; // End div id="side-nav" div id="id-left"
}
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
2017-10-16 08:47:05 +02: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
*/
2011-02-16 20:59:16 +01:00
function main_area ( $title = '' )
2010-10-29 19:54:15 +02:00
{
2017-10-16 08:47:05 +02:00
global $conf , $langs ;
2010-11-02 13:14:06 +01:00
2013-04-25 20:27:45 +02:00
if ( empty ( $conf -> dol_hide_leftmenu )) 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
2017-10-16 08:47:05 +02:00
if ( ! empty ( $conf -> global -> MAIN_ONLY_LOGIN_ALLOWED )) print info_admin ( $langs -> trans ( " WarningYouAreInMaintenanceMode " , $conf -> global -> MAIN_ONLY_LOGIN_ALLOWED ));
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
*/
function getHelpParamFor ( $helppagename , $langs )
{
2012-07-09 12:31:21 +02:00
$helpbaseurl = '' ;
$helppage = '' ;
$mode = '' ;
2017-10-16 08:47:05 +02:00
if ( preg_match ( '/^http/i' , $helppagename ))
{
// If complete URL
$helpbaseurl = '%s' ;
$helppage = $helppagename ;
$mode = 'local' ;
}
else
{
// If WIKI URL
if ( preg_match ( '/^es/i' , $langs -> defaultlang ))
{
$helpbaseurl = 'http://wiki.dolibarr.org/index.php/%s' ;
if ( preg_match ( '/ES:([^|]+)/i' , $helppagename , $reg )) $helppage = $reg [ 1 ];
}
if ( preg_match ( '/^fr/i' , $langs -> defaultlang ))
{
$helpbaseurl = 'http://wiki.dolibarr.org/index.php/%s' ;
if ( preg_match ( '/FR:([^|]+)/i' , $helppagename , $reg )) $helppage = $reg [ 1 ];
}
if ( empty ( $helppage )) // If help page not already found
{
$helpbaseurl = 'http://wiki.dolibarr.org/index.php/%s' ;
if ( preg_match ( '/EN:([^|]+)/i' , $helppagename , $reg )) $helppage = $reg [ 1 ];
}
$mode = 'wiki' ;
}
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
*/
2018-12-28 00:41:05 +01:00
function printSearchForm ( $urlaction , $urlobject , $title , $htmlmorecss , $htmlinputname , $accesskey = '' , $prefhtmlinputname = '' , $img = '' , $showtitlebefore = 0 , $autofocus = 0 )
2004-08-13 23:45:23 +02:00
{
2017-11-01 10:09:39 +01:00
global $conf , $langs , $user ;
2012-02-22 12:02:12 +01:00
2017-10-16 08:47:05 +02:00
$ret = '' ;
$ret .= '<form action="' . $urlaction . '" method="post" class="searchform">' ;
$ret .= '<input type="hidden" name="token" value="' . $_SESSION [ 'newtoken' ] . '">' ;
$ret .= '<input type="hidden" name="mode" value="search">' ;
2017-11-01 10:09:39 +01:00
$ret .= '<input type="hidden" name="savelogin" value="' . dol_escape_htmltag ( $user -> login ) . '">' ;
2017-11-14 15:10:46 +01:00
if ( $showtitlebefore ) $ret .= $title . ' ' ;
2017-10-16 08:47:05 +02:00
$ret .= '<input type="text" class="flat ' . $htmlmorecss . '"' ;
2017-11-01 10:09:39 +01:00
$ret .= ' style="text-indent: 22px; background-image: url(\'' . $img . '\'); background-repeat: no-repeat; background-position: 3px;"' ;
2017-10-16 08:47:05 +02:00
$ret .= ( $accesskey ? ' accesskey="' . $accesskey . '"' : '' );
2017-11-01 10:09:39 +01:00
$ret .= ' placeholder="' . strip_tags ( $title ) . '"' ;
2018-12-28 00:41:05 +01:00
$ret .= ( $autofocus ? ' autofocus' : '' );
2017-10-16 08:47:05 +02:00
$ret .= ' name="' . $htmlinputname . '" id="' . $prefhtmlinputname . $htmlinputname . '" />' ;
2018-06-22 23:21:16 +02:00
//$ret.='<input type="submit" class="button" style="padding-top: 4px; padding-bottom: 4px; padding-left: 6px; padding-right: 6px" value="'.$langs->trans("Go").'">';
$ret .= '<button type="submit" class="button" style="padding-top: 4px; padding-bottom: 4px; padding-left: 6px; padding-right: 6px">' ;
$ret .= '<span class="fa fa-search"></span>' ;
$ret .= '</button>' ;
2017-10-16 08:47:05 +02:00
$ret .= " </form> \n " ;
return $ret ;
2004-08-13 23:45:23 +02:00
}
2010-03-16 02:18:25 +01:00
if ( ! function_exists ( " llxFooter " ))
2002-12-12 17:42:08 +01:00
{
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
*/
2017-10-28 13:36:23 +02:00
function llxFooter ( $comment = '' , $zone = 'private' , $disabledoutputofmessages = 0 )
2017-10-16 08:47:05 +02:00
{
global $conf , $langs , $user , $object ;
2018-12-14 10:31:09 +01:00
global $delayedhtmlcontent ;
global $contextpage , $page , $limit ;
2016-03-18 10:56:55 +01:00
2017-11-18 12:35:25 +01:00
$ext = 'layout=' . $conf -> browser -> layout . '&version=' . urlencode ( DOL_VERSION );
2017-11-10 15:29:12 +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
2017-10-16 08:47:05 +02: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
2017-10-16 08:47:05 +02:00
foreach ( $user -> lastsearch_values_tmp as $key => $val )
{
2018-06-23 11:55:04 +02:00
unset ( $_SESSION [ 'lastsearch_values_tmp_' . $key ]); // Clean array to rebuild it just after
2018-04-08 12:40:19 +02:00
if ( count ( $val ) && empty ( $_POST [ 'button_removefilter' ])) // If there is search criteria to save and we did not click on 'Clear filter' button
2017-10-16 08:47:05 +02: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) " );
2017-10-16 08:47:05 +02:00
$_SESSION [ 'lastsearch_values_tmp_' . $key ] = json_encode ( $val );
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
if ( constant ( 'DOL_URL_ROOT' )) $relativepathstring = preg_replace ( '/^' . preg_quote ( constant ( 'DOL_URL_ROOT' ), '/' ) . '/' , '' , $relativepathstring );
$relativepathstring = preg_replace ( '/^\//' , '' , $relativepathstring );
$relativepathstring = preg_replace ( '/^custom\//' , '' , $relativepathstring );
if ( preg_match ( '/list\.php$/' , $relativepathstring ))
{
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 ]);
if ( ! empty ( $contextpage )) $_SESSION [ 'lastsearch_contextpage_tmp_' . $relativepathstring ] = $contextpage ;
if ( ! empty ( $page ) && $page > 1 ) $_SESSION [ 'lastsearch_page_tmp_' . $relativepathstring ] = $page ;
if ( ! empty ( $limit ) && $limit != $conf -> limit ) $_SESSION [ 'lastsearch_limit_tmp_' . $relativepathstring ] = $limit ;
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 ]);
2018-06-23 11:55:04 +02:00
}
2017-10-16 08:47:05 +02:00
// Core error message
if ( ! empty ( $conf -> global -> MAIN_CORE_ERROR ))
{
// Ajax version
if ( $conf -> use_javascript_ajax )
{
$title = img_warning () . ' ' . $langs -> trans ( 'CoreErrorTitle' );
print ajax_dialog ( $title , $langs -> trans ( 'CoreErrorMessage' ));
}
// html version
else
{
$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
2017-11-09 01:00:43 +01:00
if ( empty ( $conf -> dol_hide_leftmenu )) print '</div> <!-- End div id-right -->' . " \n " ; // End div id-right
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 " ;
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
2017-10-16 08:47:05 +02:00
if ( ! empty ( $delayedhtmlcontent )) print $delayedhtmlcontent ;
2016-03-18 10:56:55 +01:00
2017-11-09 01:00:43 +01:00
if ( ! empty ( $conf -> use_javascript_ajax ))
2017-10-16 08:47:05 +02:00
{
2017-11-09 01:00:43 +01:00
print " \n " . '<!-- Includes JS Footer of Dolibarr -->' . " \n " ;
2017-11-18 12:35:25 +01:00
print '<script type="text/javascript" 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
if ( ! empty ( $conf -> blockedlog -> enabled ) && is_object ( $object ) && $object -> id > 0 && $object -> statut > 0 )
{
if ( in_array ( $object -> element , array ( 'facture' ))) // Restrict for the moment to element 'facture'
{
print " \n <!-- JS CODE TO ENABLE log when making a download or a preview of a document --> \n " ;
?>
2017-06-16 11:51:33 +02:00
< script type = " text/javascript " >
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'
}
);
});
$ ( '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'
}
);
});
});
</ script >
< ? php
2017-10-16 08:47:05 +02:00
}
}
2017-06-16 11:51:33 +02:00
2016-01-02 00:27:14 +01:00
// A div for the address popup
print " \n <!-- A div to allow dialog popup --> \n " ;
print '<div id="dialogforpopup" style="display: none;"></div>' . " \n " ;
2016-03-18 10:56:55 +01:00
2017-10-16 08:47:05 +02:00
print " </body> \n " ;
print " </html> \n " ;
}
2002-05-09 16:57:48 +02:00
}