diff --git a/htdocs/main.inc.php b/htdocs/main.inc.php index 93f445b83d1..740323a644b 100644 --- a/htdocs/main.inc.php +++ b/htdocs/main.inc.php @@ -38,8 +38,7 @@ // For optional tuning. Enabled if environment variable MAIN_SHOW_TUNING_INFO is defined. $micro_start_time = 0; -if (!empty($_SERVER['MAIN_SHOW_TUNING_INFO'])) -{ +if (!empty($_SERVER['MAIN_SHOW_TUNING_INFO'])) { list($usec, $sec) = explode(" ", microtime()); $micro_start_time = ((float) $usec + (float) $sec); // Add Xdebug code coverage @@ -75,8 +74,7 @@ function testSqlAndScriptInject($val, $type) $inj = 0; // For SQL Injection (only GET are used to be included into bad escaped SQL requests) - if ($type == 1 || $type == 3) - { + if ($type == 1 || $type == 3) { $inj += preg_match('/delete\s+from/i', $val); $inj += preg_match('/create\s+table/i', $val); $inj += preg_match('/insert\s+into/i', $val); @@ -86,12 +84,10 @@ function testSqlAndScriptInject($val, $type) $inj += preg_match('/information_schema/i', $val); // avoid to use request that read information_schema database $inj += preg_match('/ $value) // Warning, $key may also be used for attacks - { - if (analyseVarsForSqlAndScriptsInjection($key, $type) && analyseVarsForSqlAndScriptsInjection($value, $type)) - { + if (is_array($var)) { + foreach ($var as $key => $value) { // Warning, $key may also be used for attacks + if (analyseVarsForSqlAndScriptsInjection($key, $type) && analyseVarsForSqlAndScriptsInjection($value, $type)) { //$var[$key] = $value; // This is useless } else { // Get remote IP: PS: We do not use getRemoteIP(), function is not yet loaded and we need a value that can't be spoofed @@ -195,14 +192,12 @@ if (defined('NOREQUIREUSER') && !defined('NOREQUIREMENU')) { } // Sanity check on URL -if (!empty($_SERVER["PHP_SELF"])) -{ +if (!empty($_SERVER["PHP_SELF"])) { $morevaltochecklikepost = array($_SERVER["PHP_SELF"]); analyseVarsForSqlAndScriptsInjection($morevaltochecklikepost, 2); } // Sanity check on GET parameters -if (!defined('NOSCANGETFORINJECTION') && !empty($_SERVER["QUERY_STRING"])) -{ +if (!defined('NOSCANGETFORINJECTION') && !empty($_SERVER["QUERY_STRING"])) { // Note: QUERY_STRING is url encoded, but $_GET and $_POST are already decoded // Because the analyseVarsForSqlAndScriptsInjection is designed for already url decoded value, we must decode QUERY_STRING // Another solution is to provide $_GET as parameter @@ -210,14 +205,12 @@ if (!defined('NOSCANGETFORINJECTION') && !empty($_SERVER["QUERY_STRING"])) analyseVarsForSqlAndScriptsInjection($morevaltochecklikeget, 1); } // Sanity check on POST -if (!defined('NOSCANPOSTFORINJECTION')) -{ +if (!defined('NOSCANPOSTFORINJECTION')) { analyseVarsForSqlAndScriptsInjection($_POST, 0); } // This is to make Dolibarr working with Plesk -if (!empty($_SERVER['DOCUMENT_ROOT']) && substr($_SERVER['DOCUMENT_ROOT'], -6) !== 'htdocs') -{ +if (!empty($_SERVER['DOCUMENT_ROOT']) && substr($_SERVER['DOCUMENT_ROOT'], -6) !== 'htdocs') { set_include_path($_SERVER['DOCUMENT_ROOT'].'/htdocs'); } @@ -227,22 +220,24 @@ require_once 'filefunc.inc.php'; // 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'=> , )) -if (!empty($_POST["DOL_AUTOSET_COOKIE"])) -{ +if (!empty($_POST["DOL_AUTOSET_COOKIE"])) { $tmpautoset = explode(':', $_POST["DOL_AUTOSET_COOKIE"], 2); $tmplist = explode(',', $tmpautoset[1]); $cookiearrayvalue = array(); - foreach ($tmplist as $tmpkey) - { + foreach ($tmplist as $tmpkey) { $postkey = $tmpautoset[0].'_'.$tmpkey; //var_dump('tmpkey='.$tmpkey.' postkey='.$postkey.' value='.$_POST[$postkey]); - if (!empty($_POST[$postkey])) $cookiearrayvalue[$tmpkey] = $_POST[$postkey]; + if (!empty($_POST[$postkey])) { + $cookiearrayvalue[$tmpkey] = $_POST[$postkey]; + } } $cookiename = $tmpautoset[0]; $cookievalue = json_encode($cookiearrayvalue); //var_dump('setcookie cookiename='.$cookiename.' cookievalue='.$cookievalue); setcookie($cookiename, empty($cookievalue) ? '' : $cookievalue, empty($cookievalue) ? 0 : (time() + (86400 * 354)), '/', null, false, true); // keep cookie 1 year and add tag httponly - if (empty($cookievalue)) unset($_COOKIE[$cookiename]); + if (empty($cookievalue)) { + unset($_COOKIE[$cookiename]); + } } @@ -257,11 +252,12 @@ if (ini_get('session.save_handler') == 'user') { $prefix = dol_getprefix(''); $sessionname = 'DOLSESSID_'.$prefix; $sessiontimeout = 'DOLSESSTIMEOUT_'.$prefix; -if (!empty($_COOKIE[$sessiontimeout])) ini_set('session.gc_maxlifetime', $_COOKIE[$sessiontimeout]); +if (!empty($_COOKIE[$sessiontimeout])) { + ini_set('session.gc_maxlifetime', $_COOKIE[$sessiontimeout]); +} // This create lock, released by 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. -if (!defined('NOSESSION')) -{ +if (!defined('NOSESSION')) { session_set_cookie_params(0, '/', null, (empty($dolibarr_main_force_https) ? false : true), true); // Add tag secure and httponly on session cookie (same as setting session.cookie_httponly into php.ini). Must be called before the session_start. session_name($sessionname); session_start(); @@ -273,18 +269,21 @@ require_once 'master.inc.php'; // If software has been locked. Only login $conf->global->MAIN_ONLY_LOGIN_ALLOWED is allowed. -if (!empty($conf->global->MAIN_ONLY_LOGIN_ALLOWED)) -{ +if (!empty($conf->global->MAIN_ONLY_LOGIN_ALLOWED)) { $ok = 0; - if ((!session_id() || !isset($_SESSION["dol_login"])) && !isset($_POST["username"]) && !empty($_SERVER["GATEWAY_INTERFACE"])) $ok = 1; // We let working pages if not logged and inside a web browser (login form, to allow login by admin) - elseif (isset($_POST["username"]) && $_POST["username"] == $conf->global->MAIN_ONLY_LOGIN_ALLOWED) $ok = 1; // We let working pages that is a login submission (login submit, to allow login by admin) - elseif (defined('NOREQUIREDB')) $ok = 1; // We let working pages that don't need database access (xxx.css.php) - elseif (defined('EVEN_IF_ONLY_LOGIN_ALLOWED')) $ok = 1; // We let working pages that ask to work even if only login enabled (logout.php) - elseif (session_id() && isset($_SESSION["dol_login"]) && $_SESSION["dol_login"] == $conf->global->MAIN_ONLY_LOGIN_ALLOWED) $ok = 1; // We let working if user is allowed admin - if (!$ok) - { - if (session_id() && isset($_SESSION["dol_login"]) && $_SESSION["dol_login"] != $conf->global->MAIN_ONLY_LOGIN_ALLOWED) - { + if ((!session_id() || !isset($_SESSION["dol_login"])) && !isset($_POST["username"]) && !empty($_SERVER["GATEWAY_INTERFACE"])) { + $ok = 1; // We let working pages if not logged and inside a web browser (login form, to allow login by admin) + } elseif (isset($_POST["username"]) && $_POST["username"] == $conf->global->MAIN_ONLY_LOGIN_ALLOWED) { + $ok = 1; // We let working pages that is a login submission (login submit, to allow login by admin) + } elseif (defined('NOREQUIREDB')) { + $ok = 1; // We let working pages that don't need database access (xxx.css.php) + } elseif (defined('EVEN_IF_ONLY_LOGIN_ALLOWED')) { + $ok = 1; // We let working pages that ask to work even if only login enabled (logout.php) + } elseif (session_id() && isset($_SESSION["dol_login"]) && $_SESSION["dol_login"] == $conf->global->MAIN_ONLY_LOGIN_ALLOWED) { + $ok = 1; // We let working if user is allowed admin + } + if (!$ok) { + if (session_id() && isset($_SESSION["dol_login"]) && $_SESSION["dol_login"] != $conf->global->MAIN_ONLY_LOGIN_ALLOWED) { print 'Sorry, your application is offline.'."\n"; print 'You are logged with user "'.$_SESSION["dol_login"].'" and only administrator user "'.$conf->global->MAIN_ONLY_LOGIN_ALLOWED.'" is allowed to connect for the moment.'."\n"; $nexturl = DOL_URL_ROOT.'/user/logout.php'; @@ -303,21 +302,21 @@ if (!empty($conf->global->MAIN_ONLY_LOGIN_ALLOWED)) register_shutdown_function('dol_shutdown'); // Load debugbar -if (!empty($conf->debugbar->enabled) && !GETPOST('dol_use_jmobile') && empty($_SESSION['dol_use_jmobile'])) -{ +if (!empty($conf->debugbar->enabled) && !GETPOST('dol_use_jmobile') && empty($_SESSION['dol_use_jmobile'])) { global $debugbar; include_once DOL_DOCUMENT_ROOT.'/debugbar/class/DebugBar.php'; $debugbar = new DolibarrDebugBar(); $renderer = $debugbar->getRenderer(); - if (empty($conf->global->MAIN_HTML_HEADER)) $conf->global->MAIN_HTML_HEADER = ''; + if (empty($conf->global->MAIN_HTML_HEADER)) { + $conf->global->MAIN_HTML_HEADER = ''; + } $conf->global->MAIN_HTML_HEADER .= $renderer->renderHead(); $debugbar['time']->startMeasure('pageaftermaster', 'Page generation (after environment init)'); } // Detection browser -if (isset($_SERVER["HTTP_USER_AGENT"])) -{ +if (isset($_SERVER["HTTP_USER_AGENT"])) { $tmp = getBrowserInfo($_SERVER["HTTP_USER_AGENT"]); $conf->browser->name = $tmp['browsername']; $conf->browser->os = $tmp['browseros']; @@ -325,26 +324,23 @@ if (isset($_SERVER["HTTP_USER_AGENT"])) $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->dol_no_mouse_hover = 1; + } } // Set global MAIN_OPTIMIZEFORTEXTBROWSER (must be before login part) -if (GETPOST('textbrowser', 'int') || (!empty($conf->browser->name) && $conf->browser->name == 'lynxlinks')) // If we must enable text browser -{ +if (GETPOST('textbrowser', 'int') || (!empty($conf->browser->name) && $conf->browser->name == 'lynxlinks')) { // If we must enable text browser $conf->global->MAIN_OPTIMIZEFORTEXTBROWSER = 1; } // Force HTTPS if required ($conf->file->main_force_https is 0/1 or 'https dolibarr root url') // $_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')) -{ +if (!empty($conf->file->main_force_https) && (empty($_SERVER["HTTPS"]) || $_SERVER["HTTPS"] != 'on')) { $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 - { + 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 { @@ -356,8 +352,7 @@ if (!empty($conf->file->main_force_https) && (empty($_SERVER["HTTPS"]) || $_SERV $newurl = $conf->file->main_force_https.$_SERVER["REQUEST_URI"]; } // Start redirect - if ($newurl) - { + if ($newurl) { header_remove(); // Clean header already set to be sure to remove any header like "Set-Cookie: DOLSESSID_..." from non HTTPS answers dol_syslog("main.inc: dolibarr_main_force_https is on, we make a redirect to ".$newurl); header("Location: ".$newurl); @@ -367,48 +362,45 @@ if (!empty($conf->file->main_force_https) && (empty($_SERVER["HTTPS"]) || $_SERV } } -if (!defined('NOLOGIN') && !defined('NOIPCHECK') && !empty($dolibarr_main_restrict_ip)) -{ +if (!defined('NOLOGIN') && !defined('NOIPCHECK') && !empty($dolibarr_main_restrict_ip)) { $listofip = explode(',', $dolibarr_main_restrict_ip); $found = false; - foreach ($listofip as $ip) - { + foreach ($listofip as $ip) { $ip = trim($ip); - if ($ip == $_SERVER['REMOTE_ADDR']) - { + if ($ip == $_SERVER['REMOTE_ADDR']) { $found = true; break; } } - if (!$found) - { + if (!$found) { print 'Access refused by IP protection. Your detected IP is '.$_SERVER['REMOTE_ADDR']; exit; } } // Loading of additional presentation includes -if (!defined('NOREQUIREHTML')) require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php'; // Need 660ko memory (800ko in 2.2) -if (!defined('NOREQUIREAJAX')) require_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php'; // Need 22ko memory +if (!defined('NOREQUIREHTML')) { + require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php'; // Need 660ko memory (800ko in 2.2) +} +if (!defined('NOREQUIREAJAX')) { + require_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php'; // Need 22ko memory +} // 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)) -{ +if (!empty($conf->global->MAIN_NOT_INSTALLED) || !empty($conf->global->MAIN_NOT_UPGRADED)) { 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; } // If an upgrade process is required, we call the install page. 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))) -{ +|| (empty($conf->global->MAIN_VERSION_LAST_UPGRADE) && !empty($conf->global->MAIN_VERSION_LAST_INSTALL) && ($conf->global->MAIN_VERSION_LAST_INSTALL != DOL_VERSION))) { $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 - { + 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; @@ -432,13 +424,11 @@ if (!defined('NOTOKENRENEWAL')) { //$dolibarr_nocsrfcheck=1; // Check token 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 into page -{ - // Check all cases that need a token (all POST actions, all actions and mass actions on pages with CSRFCHECK_WITH_TOKEN set, all sensitive GET actions) + || 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 into page +// Check all cases that need a token (all POST actions, all actions and mass actions on pages with CSRFCHECK_WITH_TOKEN set, all sensitive GET actions) if ($_SERVER['REQUEST_METHOD'] == 'POST' || ((GETPOSTISSET('action') || GETPOSTISSET('massaction')) && defined('CSRFCHECK_WITH_TOKEN')) || - in_array(GETPOST('action', 'aZ09'), array('add', 'addtimespent', 'update', 'install', 'delete', 'deletefilter', 'deleteoperation', 'deleteprof', 'deletepayment', 'confirm_create_user', 'confirm_create_thirdparty', 'confirm_reject_check'))) - { + in_array(GETPOST('action', 'aZ09'), array('add', 'addtimespent', 'update', 'install', 'delete', 'deletefilter', 'deleteoperation', 'deleteprof', 'deletepayment', 'confirm_create_user', 'confirm_create_thirdparty', 'confirm_reject_check'))) { if (!GETPOSTISSET('token')) { if (GETPOST('uploadform', 'int')) { dol_syslog("--- Access to ".$_SERVER["PHP_SELF"]." refused. File size too large."); @@ -477,24 +467,23 @@ if ((!defined('NOCSRFCHECK') && empty($dolibarr_nocsrfcheck) && !empty($conf->gl } // Disable modules (this must be after session_start and after conf has been loaded) -if (GETPOSTISSET('disablemodules')) $_SESSION["disablemodules"] = GETPOST('disablemodules', 'alpha'); -if (!empty($_SESSION["disablemodules"])) -{ +if (GETPOSTISSET('disablemodules')) { + $_SESSION["disablemodules"] = GETPOST('disablemodules', 'alpha'); +} +if (!empty($_SESSION["disablemodules"])) { $modulepartkeys = array('css', 'js', 'tabs', 'triggers', 'login', 'substitutions', 'menus', 'theme', 'sms', 'tpl', 'barcode', 'models', 'societe', 'hooks', 'dir', 'syslog', 'tpllinkable', 'contactelement', 'moduleforexternal'); $disabled_modules = explode(',', $_SESSION["disablemodules"]); - foreach ($disabled_modules as $module) - { - if ($module) - { - if (empty($conf->$module)) $conf->$module = new stdClass(); // To avoid warnings + foreach ($disabled_modules as $module) { + if ($module) { + if (empty($conf->$module)) { + $conf->$module = new stdClass(); // To avoid warnings + } $conf->$module->enabled = false; - foreach ($modulepartkeys as $modulepartkey) - { + foreach ($modulepartkeys as $modulepartkey) { unset($conf->modules_parts[$modulepartkey][$module]); } - if ($module == 'fournisseur') // Special case - { + if ($module == 'fournisseur') { // Special case $conf->supplier_order->enabled = 0; $conf->supplier_invoice->enabled = 0; } @@ -504,12 +493,9 @@ if (!empty($_SESSION["disablemodules"])) // Set current modulepart $modulepart = explode("/", $_SERVER["PHP_SELF"]); -if (is_array($modulepart) && count($modulepart) > 0) -{ - foreach ($conf->modules as $module) - { - if (in_array($module, $modulepart)) - { +if (is_array($modulepart) && count($modulepart) > 0) { + foreach ($conf->modules as $module) { + if (in_array($module, $modulepart)) { $conf->modulepart = $module; break; } @@ -520,26 +506,27 @@ if (is_array($modulepart) && count($modulepart) > 0) * Phase authentication / login */ $login = ''; -if (!defined('NOLOGIN')) -{ +if (!defined('NOLOGIN')) { // $authmode lists the different method of identification to be tested in order of preference. // Example: 'http', 'dolibarr', 'ldap', 'http,forceuser', '...' - if (defined('MAIN_AUTHENTICATION_MODE')) - { + 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'; + 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'; + if ($dolibarr_main_authentication == 'forceuser' && empty($dolibarr_auto_user)) { + $dolibarr_auto_user = 'auto'; + } } // Set authmode $authmode = explode(',', $dolibarr_main_authentication); // No authentication mode - if (!count($authmode)) - { + if (!count($authmode)) { $langs->load('main'); dol_print_error('', $langs->trans("ErrorConfigParameterNotDefined", 'dolibarr_main_authentication')); exit; @@ -550,8 +537,7 @@ if (!defined('NOLOGIN')) // At the end of this phase, the variable $login is defined. $resultFetchUser = ''; $test = true; - if (!isset($_SESSION["dol_login"])) - { + 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'; @@ -568,10 +554,8 @@ if (!defined('NOLOGIN')) //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'])) - { + 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 : ''); @@ -591,19 +575,17 @@ if (!defined('NOLOGIN')) $parameters = array(); $reshook = $hookmanager->executeHooks('beforeLoginAuthentication', $parameters, $user, $action); // Note that $action and $object may have been modified by some hooks if ($reshook < 0) { - $test = false; - $error++; + $test = false; + $error++; } // Verification security graphic code - if ($test && GETPOST("username", "alpha", 2) && !empty($conf->global->MAIN_SECURITY_ENABLECAPTCHA) && !isset($_SESSION['dol_bypass_antispam'])) - { + if ($test && GETPOST("username", "alpha", 2) && !empty($conf->global->MAIN_SECURITY_ENABLECAPTCHA) && !isset($_SESSION['dol_bypass_antispam'])) { $sessionkey = 'dol_antispam_value'; $ok = (array_key_exists($sessionkey, $_SESSION) === true && (strtolower($_SESSION[$sessionkey]) === strtolower(GETPOST('code', 'none')))); // Check code - if (!$ok) - { + if (!$ok) { dol_syslog('Bad value for code, connexion refused'); // Load translation files required by page $langs->loadLangs(array('main', 'errors')); @@ -616,7 +598,9 @@ if (!defined('NOLOGIN')) // Call trigger $result = $user->call_trigger('USER_LOGIN_FAILED', $user); - if ($result < 0) $error++; + if ($result < 0) { + $error++; + } // End call triggers // Hooks on failed login @@ -624,45 +608,54 @@ if (!defined('NOLOGIN')) $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++; + if ($reshook < 0) { + $error++; + } // Note: exit is done later } } $allowedmethodtopostusername = 2; - if (defined('MAIN_AUTHENTICATION_POST_METHOD')) $allowedmethodtopostusername = constant('MAIN_AUTHENTICATION_POST_METHOD'); + if (defined('MAIN_AUTHENTICATION_POST_METHOD')) { + $allowedmethodtopostusername = constant('MAIN_AUTHENTICATION_POST_METHOD'); + } $usertotest = (!empty($_COOKIE['login_dolibarr']) ? preg_replace('/[^a-zA-Z0-9_\-]/', '', $_COOKIE['login_dolibarr']) : GETPOST("username", "alpha", $allowedmethodtopostusername)); $passwordtotest = GETPOST('password', 'none', $allowedmethodtopostusername); $entitytotest = (GETPOST('entity', 'int') ? GETPOST('entity', 'int') : (!empty($conf->entity) ? $conf->entity : 1)); // 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; - if (GETPOST("username", "alpha", $allowedmethodtopostusername) || !empty($_COOKIE['login_dolibarr']) || GETPOST('openid_mode', 'alpha', 1)) $goontestloop = true; + if (isset($_SERVER["REMOTE_USER"]) && in_array('http', $authmode)) { + $goontestloop = true; + } + if ($dolibarr_main_authentication == 'forceuser' && !empty($dolibarr_auto_user)) { + $goontestloop = true; + } + if (GETPOST("username", "alpha", $allowedmethodtopostusername) || !empty($_COOKIE['login_dolibarr']) || GETPOST('openid_mode', 'alpha', 1)) { + $goontestloop = true; + } - if (!is_object($langs)) // This can occurs when calling page with NOREQUIRETRAN defined, however we need langs for error messages. - { + 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)); - if (defined('MAIN_LANG_DEFAULT')) $langcode = constant('MAIN_LANG_DEFAULT'); + if (defined('MAIN_LANG_DEFAULT')) { + $langcode = constant('MAIN_LANG_DEFAULT'); + } $langs->setDefaultLang($langcode); } // 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 && (GETPOST('actionlogin', 'aZ09') == 'login' || $dolibarr_main_authentication != 'dolibarr')) - { + if ($test && $goontestloop && (GETPOST('actionlogin', 'aZ09') == 'login' || $dolibarr_main_authentication != 'dolibarr')) { $login = checkLoginPassEntity($usertotest, $passwordtotest, $entitytotest, $authmode); if ($login === '--bad-login-validity--') { $login = ''; } - if ($login) - { + 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"]; @@ -671,33 +664,37 @@ if (!defined('NOLOGIN')) $dol_tz_string = preg_replace('/\s/', '_', $dol_tz_string); $dol_dst = 0; // Keep $_POST here. Do not use GETPOSTISSET - if (isset($_POST["dst_first"]) && isset($_POST["dst_second"])) - { + 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; + if ($datenow >= $datefirst && $datenow < $datesecond) { + $dol_dst = 1; + } } //print $datefirst.'-'.$datesecond.'-'.$datenow.'-'.$dol_tz.'-'.$dol_tzstring.'-'.$dol_dst; exit; } - if (!$login) - { + if (!$login) { dol_syslog('Bad password, connexion refused', LOG_DEBUG); // Load translation files required by page $langs->loadLangs(array('main', 'errors')); // 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"); + if (empty($_SESSION["dol_loginmesg"])) { + $_SESSION["dol_loginmesg"] = $langs->trans("ErrorBadLoginPassword"); + } // Call trigger for the "security events" log $user->trigger_mesg = $langs->trans("ErrorBadLoginPassword").' - login='.GETPOST("username", "alpha", 2); // Call trigger $result = $user->call_trigger('USER_LOGIN_FAILED', $user); - if ($result < 0) $error++; + if ($result < 0) { + $error++; + } // End call triggers // Hooks on failed login @@ -705,19 +702,21 @@ if (!defined('NOLOGIN')) $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++; + if ($reshook < 0) { + $error++; + } // Note: exit is done in next chapter } } // 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. + 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. dol_syslog("--- Access to ".$_SERVER["PHP_SELF"]." - action=".GETPOST('action', 'aZ09')." - actionlogin=".GETPOST('actionlogin', 'aZ09')." - showing the login form and exit"); - if (defined('NOREDIRECTBYMAINTOLOGIN')) return 'ERROR_NOT_LOGGED'; - else { + if (defined('NOREDIRECTBYMAINTOLOGIN')) { + return 'ERROR_NOT_LOGGED'; + } else { if ($_SERVER["HTTP_USER_AGENT"] == 'securitytest') { http_response_code(401); // It makes easier to understand if session was broken during security tests } @@ -727,16 +726,14 @@ if (!defined('NOLOGIN')) } $resultFetchUser = $user->fetch('', $login, '', 1, ($entitytotest > 0 ? $entitytotest : -1)); // login was retrieved previously when checking password. - if ($resultFetchUser <= 0) - { + if ($resultFetchUser <= 0) { dol_syslog('User not found, connexion refused'); session_destroy(); session_set_cookie_params(0, '/', null, (empty($dolibarr_main_force_https) ? false : true), true); // Add tag secure and httponly on session cookie session_name($sessionname); session_start(); - if ($resultFetchUser == 0) - { + if ($resultFetchUser == 0) { // Load translation files required by page $langs->loadLangs(array('main', 'errors')); @@ -744,8 +741,7 @@ if (!defined('NOLOGIN')) $user->trigger_mesg = 'ErrorCantLoadUserFromDolibarrDatabase - login='.$login; } - if ($resultFetchUser < 0) - { + if ($resultFetchUser < 0) { $_SESSION["dol_loginmesg"] = $user->error; $user->trigger_mesg = $user->error; @@ -753,7 +749,9 @@ if (!defined('NOLOGIN')) // Call trigger $result = $user->call_trigger('USER_LOGIN_FAILED', $user); - if ($result < 0) $error++; + if ($result < 0) { + $error++; + } // End call triggers @@ -762,12 +760,20 @@ if (!defined('NOLOGIN')) $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++; + 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'); + 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 { @@ -783,8 +789,7 @@ if (!defined('NOLOGIN')) dol_syslog("- This is an already logged session. _SESSION['dol_login']=".$login." _SESSION['dol_entity']=".$entity, LOG_DEBUG); $resultFetchUser = $user->fetch('', $login, '', 1, ($entity > 0 ? $entity : -1)); - if ($resultFetchUser <= 0) - { + 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(); @@ -792,8 +797,7 @@ if (!defined('NOLOGIN')) session_name($sessionname); session_start(); - if ($resultFetchUser == 0) - { + if ($resultFetchUser == 0) { // Load translation files required by page $langs->loadLangs(array('main', 'errors')); @@ -801,8 +805,7 @@ if (!defined('NOLOGIN')) $user->trigger_mesg = 'ErrorCantLoadUserFromDolibarrDatabase - login='.$login; } - if ($resultFetchUser < 0) - { + if ($resultFetchUser < 0) { $_SESSION["dol_loginmesg"] = $user->error; $user->trigger_mesg = $user->error; @@ -810,7 +813,9 @@ if (!defined('NOLOGIN')) // Call trigger $result = $user->call_trigger('USER_LOGIN_FAILED', $user); - if ($result < 0) $error++; + if ($result < 0) { + $error++; + } // End call triggers // Hooks on failed login @@ -818,12 +823,20 @@ if (!defined('NOLOGIN')) $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++; + 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'); + 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 { @@ -831,34 +844,31 @@ if (!defined('NOLOGIN')) $hookmanager->initHooks(array('main')); // Code for search criteria persistence. - if (!empty($_GET['save_lastsearch_values'])) // We must use $_GET here - { + if (!empty($_GET['save_lastsearch_values'])) { // We must use $_GET here $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); + 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); // 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 - if (!empty($_SESSION['lastsearch_values_tmp_'.$relativepathstring])) - { + if (!empty($_SESSION['lastsearch_values_tmp_'.$relativepathstring])) { $_SESSION['lastsearch_values_'.$relativepathstring] = $_SESSION['lastsearch_values_tmp_'.$relativepathstring]; unset($_SESSION['lastsearch_values_tmp_'.$relativepathstring]); } - if (!empty($_SESSION['lastsearch_contextpage_tmp_'.$relativepathstring])) - { + if (!empty($_SESSION['lastsearch_contextpage_tmp_'.$relativepathstring])) { $_SESSION['lastsearch_contextpage_'.$relativepathstring] = $_SESSION['lastsearch_contextpage_tmp_'.$relativepathstring]; unset($_SESSION['lastsearch_contextpage_tmp_'.$relativepathstring]); } - if (!empty($_SESSION['lastsearch_page_tmp_'.$relativepathstring]) && $_SESSION['lastsearch_page_tmp_'.$relativepathstring] > 0) - { + if (!empty($_SESSION['lastsearch_page_tmp_'.$relativepathstring]) && $_SESSION['lastsearch_page_tmp_'.$relativepathstring] > 0) { $_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) - { + 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]); } @@ -874,8 +884,7 @@ if (!defined('NOLOGIN')) // Is it a new session that has started ? // If we are here, this means authentication was successfull. - if (!isset($_SESSION["dol_login"])) - { + if (!isset($_SESSION["dol_login"])) { // New session for this login has started. $error = 0; @@ -893,11 +902,21 @@ if (!defined('NOLOGIN')) $_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; + 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()); @@ -912,7 +931,9 @@ if (!defined('NOLOGIN')) // Call trigger $result = $user->call_trigger('USER_LOGIN', $user); - if ($result < 0) $error++; + if ($result < 0) { + $error++; + } // End call triggers // Hooks on successfull login @@ -920,10 +941,11 @@ if (!defined('NOLOGIN')) $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++; + if ($reshook < 0) { + $error++; + } - if ($error) - { + if ($error) { $db->rollback(); session_destroy(); dol_print_error($db, 'Error in some triggers USER_LOGIN or in some hooks afterLogin'); @@ -934,11 +956,9 @@ if (!defined('NOLOGIN')) // 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 - { + if (!empty($landingpage)) { // Example: /index.php $newpath = dol_buildpath($landingpage, 1); - if ($_SERVER["PHP_SELF"] != $newpath) // not already on landing page (avoid infinite loop) - { + if ($_SERVER["PHP_SELF"] != $newpath) { // not already on landing page (avoid infinite loop) header('Location: '.$newpath); exit; } @@ -947,8 +967,7 @@ if (!defined('NOLOGIN')) // If user admin, we force the rights-based modules - if ($user->admin) - { + if ($user->admin) { $user->rights->user->user->lire = 1; $user->rights->user->user->creer = 1; $user->rights->user->user->password = 1; @@ -958,24 +977,26 @@ if (!defined('NOLOGIN')) } /* - * Overwrite some configs globals (try to avoid this and have code to use instead $user->conf->xxx) - */ + * Overwrite some configs globals (try to avoid this and have code to use instead $user->conf->xxx) + */ // 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 + 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 + } // Replace conf->css by personalized value if theme not forced - if (empty($conf->global->MAIN_FORCETHEME) && !empty($user->conf->MAIN_THEME)) - { + 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"; } } // Case forcing style from url -if (GETPOST('theme', 'alpha')) -{ +if (GETPOST('theme', 'alpha')) { $conf->theme = GETPOST('theme', 'alpha', 1); $conf->css = "/theme/".$conf->theme."/style.css.php"; } @@ -998,52 +1019,58 @@ if (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER) && !empty($user->conf->MAI $conf->global->MAIN_OPTIMIZEFORCOLORBLIND = empty($user->conf->MAIN_OPTIMIZEFORCOLORBLIND) ? '' : $user->conf->MAIN_OPTIMIZEFORCOLORBLIND; // Set terminal output option according to conf->browser. -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; -if (!empty($conf->browser->layout) && $conf->browser->layout != 'classic') $conf->dol_no_mouse_hover = 1; +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; +} +if (!empty($conf->browser->layout) && $conf->browser->layout != 'classic') { + $conf->dol_no_mouse_hover = 1; +} if ((!empty($conf->browser->layout) && $conf->browser->layout == 'phone') || (!empty($_SESSION['dol_screenwidth']) && $_SESSION['dol_screenwidth'] < 400) || (!empty($_SESSION['dol_screenheight']) && $_SESSION['dol_screenheight'] < 400) -) -{ +) { $conf->dol_optimize_smallscreen = 1; } // Replace themes bugged with jmobile with eldy -if (!empty($conf->dol_use_jmobile) && in_array($conf->theme, array('bureau2crea', 'cameleo', 'amarok'))) -{ +if (!empty($conf->dol_use_jmobile) && in_array($conf->theme, array('bureau2crea', 'cameleo', 'amarok'))) { $conf->theme = 'eldy'; $conf->css = "/theme/".$conf->theme."/style.css.php"; } -if (!defined('NOREQUIRETRAN')) -{ - 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 (!defined('NOREQUIRETRAN')) { + 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) - { + if ($langs->getDefaultLang() != $user->conf->MAIN_LANG_DEFAULT) { $langs->setDefaultLang($user->conf->MAIN_LANG_DEFAULT); } } } } -if (!defined('NOLOGIN')) -{ +if (!defined('NOLOGIN')) { // If the login is not recovered, it is identified with an account that does not exist. // Hacking attempt? - if (!$user->login) accessforbidden(); + if (!$user->login) { + accessforbidden(); + } // Check if user is active - if ($user->statut < 1) - { + if ($user->statut < 1) { // If not active, we refuse the user $langs->load("other"); dol_syslog("Authentication KO as login is disabled", LOG_NOTICE); @@ -1060,8 +1087,7 @@ dol_syslog("--- Access to ".(empty($_SERVER["REQUEST_METHOD"])?'':$_SERVER["REQU //dol_syslog("Access to ".$_SERVER["PHP_SELF"].' GET='.join(',',array_keys($_GET)).'->'.join(',',$_GET).' POST:'.join(',',array_keys($_POST)).'->'.join(',',$_POST)); // Load main languages files -if (!defined('NOREQUIRETRAN')) -{ +if (!defined('NOREQUIRETRAN')) { // Load translation files required by page $langs->loadLangs(array('main', 'dict')); } @@ -1078,8 +1104,7 @@ $mesg = ''; $warning = ''; $error = 0; $mesgs = array(); $warnings = array(); $errors = array(); // Constants used to defined number of lines in textarea -if (empty($conf->browser->firefox)) -{ +if (empty($conf->browser->firefox)) { define('ROWS_1', 1); define('ROWS_2', 2); define('ROWS_3', 3); @@ -1104,10 +1129,8 @@ if (empty($conf->browser->firefox)) $heightforframes = 50; // Init menu manager -if (!defined('NOREQUIREMENU')) -{ - if (empty($user->socid)) // If internal user or not defined - { +if (!defined('NOREQUIREMENU')) { + if (empty($user->socid)) { // If internal user or not defined $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); } else { // If external user @@ -1116,18 +1139,19 @@ if (!defined('NOREQUIREMENU')) // Load the menu manager (only if not already done) $file_menu = $conf->standard_menu; - if (GETPOST('menu', 'alpha')) $file_menu = GETPOST('menu', 'alpha'); // example: menu=eldy_menu.php - if (!class_exists('MenuManager')) - { + if (GETPOST('menu', 'alpha')) { + $file_menu = GETPOST('menu', 'alpha'); // example: menu=eldy_menu.php + } + if (!class_exists('MenuManager')) { $menufound = 0; $dirmenus = array_merge(array("/core/menus/"), (array) $conf->modules_parts['menus']); - foreach ($dirmenus as $dirmenu) - { + foreach ($dirmenus as $dirmenu) { $menufound = dol_include_once($dirmenu."standard/".$file_menu); - if (class_exists('MenuManager')) break; + if (class_exists('MenuManager')) { + break; + } } - if (!class_exists('MenuManager')) // If failed to include, we try with standard eldy_menu.php - { + if (!class_exists('MenuManager')) { // If failed to include, we try with standard eldy_menu.php 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; @@ -1141,8 +1165,7 @@ if (!defined('NOREQUIREMENU')) // Functions -if (!function_exists("llxHeader")) -{ +if (!function_exists("llxHeader")) { /** * Show HTML header HTML + BODY + Top menu + left menu + DIV * @@ -1171,10 +1194,11 @@ if (!function_exists("llxHeader")) $tmpcsstouse = 'sidebar-collapse'.($morecssonbody ? ' '.$morecssonbody : ''); // If theme MD and classic layer, we open the menulayer by default. - if ($conf->theme == 'md' && !in_array($conf->browser->layout, array('phone', 'tablet')) && empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) - { + if ($conf->theme == 'md' && !in_array($conf->browser->layout, array('phone', 'tablet')) && empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) { global $mainmenu; - if ($mainmenu != 'website') $tmpcsstouse = $morecssonbody; // We do not use sidebar-collpase by default to have menuhider open by default. + if ($mainmenu != 'website') { + $tmpcsstouse = $morecssonbody; // We do not use sidebar-collpase by default to have menuhider open by default. + } } if (!empty($conf->global->MAIN_OPTIMIZEFORCOLORBLIND)) { @@ -1184,19 +1208,16 @@ if (!function_exists("llxHeader")) print ''."\n"; // top menu and left menu area - if (empty($conf->dol_hide_topmenu) || GETPOST('dol_invisible_topmenu', 'int')) - { + if (empty($conf->dol_hide_topmenu) || GETPOST('dol_invisible_topmenu', 'int')) { top_menu($head, $title, $target, $disablejs, $disablehead, $arrayofjs, $arrayofcss, $morequerystring, $help_url); } - if (empty($conf->dol_hide_leftmenu)) - { + if (empty($conf->dol_hide_leftmenu)) { left_menu('', $help_url, '', '', 1, $title, 1); // $menumanager is retrieved with a global $menumanager inside this function } // main area - if ($replacemainareaby) - { + if ($replacemainareaby) { print $replacemainareaby; return; } @@ -1216,16 +1237,21 @@ function top_httphead($contenttype = 'text/html', $forcenocache = 0) { global $db, $conf, $hookmanager; - if ($contenttype == 'text/html') header("Content-Type: text/html; charset=".$conf->file->character_set_client); - else header("Content-Type: ".$contenttype); + 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) - 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"); + 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"); + } //header("X-XSS-Protection: 1"); // XSS filtering protection of some browsers (note: use of Content-Security-Policy is more efficient). Disabled as deprecated. - if (!defined('FORCECSP')) - { + if (!defined('FORCECSP')) { //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 @@ -1234,16 +1260,20 @@ function top_httphead($contenttype = 'text/html', $forcenocache = 0) //else $contentsecuritypolicy = empty($conf->global->MAIN_HTTP_CONTENT_SECURITY_POLICY) ? '' : $conf->global->MAIN_HTTP_CONTENT_SECURITY_POLICY; - if (!is_object($hookmanager)) $hookmanager = new HookManager($db); + if (!is_object($hookmanager)) { + $hookmanager = new HookManager($db); + } $hookmanager->initHooks(array("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 ($result > 0) { + $contentsecuritypolicy = $hookmanager->resPrint; // Replace CSP + } else { + $contentsecuritypolicy .= $hookmanager->resPrint; // Concat CSP + } - if (!empty($contentsecuritypolicy)) - { + 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', ...: @@ -1254,12 +1284,10 @@ function top_httphead($contenttype = 'text/html', $forcenocache = 0) // default-src http: https: 'unsafe-eval' 'unsafe-inline'; object-src 'none' header("Content-Security-Policy: ".$contentsecuritypolicy); } - } elseif (constant('FORCECSP')) - { + } elseif (constant('FORCECSP')) { header("Content-Security-Policy: ".constant('FORCECSP')); } - if ($forcenocache) - { + if ($forcenocache) { header("Cache-Control: no-cache, no-store, must-revalidate, max-age=0"); } } @@ -1284,23 +1312,31 @@ function top_htmlhead($head, $title = '', $disablejs = 0, $disablehead = 0, $arr top_httphead(); - if (empty($conf->css)) $conf->css = '/theme/eldy/style.css.php'; // If not defined, eldy by default + if (empty($conf->css)) { + $conf->css = '/theme/eldy/style.css.php'; // If not defined, eldy by default + } print ''."\n"; - if (!empty($conf->global->MAIN_USE_CACHE_MANIFEST)) print ''."\n"; - else print ''."\n"; + if (!empty($conf->global->MAIN_USE_CACHE_MANIFEST)) { + print ''."\n"; + } else { + print ''."\n"; + } //print ''."\n"; - if (empty($disablehead)) - { - if (!is_object($hookmanager)) $hookmanager = new HookManager($db); + if (empty($disablehead)) { + if (!is_object($hookmanager)) { + $hookmanager = new HookManager($db); + } $hookmanager->initHooks(array("main")); $ext = 'layout='.$conf->browser->layout.'&version='.urlencode(DOL_VERSION); print "\n"; - if (GETPOST('dol_basehref', 'alpha')) print ''."\n"; + if (GETPOST('dol_basehref', 'alpha')) { + print ''."\n"; + } // Displays meta print ''."\n"; @@ -1310,9 +1346,15 @@ function top_htmlhead($head, $title = '', $disablejs = 0, $disablehead = 0, $arr // Favicon $favicon = DOL_URL_ROOT.'/theme/dolibarr_256x256_color.png'; - if (!empty($mysoc->logo_squarred_mini)) $favicon = DOL_URL_ROOT.'/viewimage.php?cache=1&modulepart=mycompany&file='.urlencode('logos/thumbs/'.$mysoc->logo_squarred_mini); - if (!empty($conf->global->MAIN_FAVICON_URL)) $favicon = $conf->global->MAIN_FAVICON_URL; - if (empty($conf->dol_use_jmobile)) print ''."\n"; // Not required into an Android webview + if (!empty($mysoc->logo_squarred_mini)) { + $favicon = DOL_URL_ROOT.'/viewimage.php?cache=1&modulepart=mycompany&file='.urlencode('logos/thumbs/'.$mysoc->logo_squarred_mini); + } + if (!empty($conf->global->MAIN_FAVICON_URL)) { + $favicon = $conf->global->MAIN_FAVICON_URL; + } + if (empty($conf->dol_use_jmobile)) { + print ''."\n"; // Not required into an Android webview + } //if (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) print ''."\n"; //if (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) print ''."\n"; @@ -1330,63 +1372,96 @@ function top_htmlhead($head, $title = '', $disablejs = 0, $disablehead = 0, $arr } // Auto refresh page - if (GETPOST('autorefresh', 'int') > 0) print ''; + if (GETPOST('autorefresh', 'int') > 0) { + print ''; + } // Displays title $appli = constant('DOL_APPLICATION_TITLE'); - if (!empty($conf->global->MAIN_APPLICATION_TITLE)) $appli = $conf->global->MAIN_APPLICATION_TITLE; + if (!empty($conf->global->MAIN_APPLICATION_TITLE)) { + $appli = $conf->global->MAIN_APPLICATION_TITLE; + } print ''; $titletoshow = ''; - if ($title && !empty($conf->global->MAIN_HTML_TITLE) && preg_match('/noapp/', $conf->global->MAIN_HTML_TITLE)) $titletoshow = dol_htmlentities($title); - elseif ($title) $titletoshow = dol_htmlentities($appli.' - '.$title); - else $titletoshow = dol_htmlentities($appli); + if ($title && !empty($conf->global->MAIN_HTML_TITLE) && preg_match('/noapp/', $conf->global->MAIN_HTML_TITLE)) { + $titletoshow = dol_htmlentities($title); + } elseif ($title) { + $titletoshow = dol_htmlentities($appli.' - '.$title); + } else { + $titletoshow = dol_htmlentities($appli); + } $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 + if ($result > 0) { + $titletoshow = $hookmanager->resPrint; // Replace Title to show + } else { + $titletoshow .= $hookmanager->resPrint; // Concat to Title to show + } print $titletoshow; print ''; print "\n"; - if (GETPOST('version', 'int')) $ext = 'version='.GETPOST('version', 'int'); // usefull to force no cache on css/js + if (GETPOST('version', 'int')) { + $ext = 'version='.GETPOST('version', 'int'); // usefull to force no cache on css/js + } $themeparam = '?lang='.$langs->defaultlang.'&theme='.$conf->theme.(GETPOST('optioncss', 'aZ09') ? '&optioncss='.GETPOST('optioncss', 'aZ09', 1) : '').'&userid='.$user->id.'&entity='.$conf->entity; $themeparam .= ($ext ? '&'.$ext : '').'&revision='.$conf->global->MAIN_IHM_PARAMS_REV; - if (!empty($_SESSION['dol_resetcache'])) $themeparam .= '&dol_resetcache='.$_SESSION['dol_resetcache']; - if (GETPOSTISSET('dol_hide_topmenu')) { $themeparam .= '&dol_hide_topmenu='.GETPOST('dol_hide_topmenu', 'int'); } - if (GETPOSTISSET('dol_hide_leftmenu')) { $themeparam .= '&dol_hide_leftmenu='.GETPOST('dol_hide_leftmenu', 'int'); } - if (GETPOSTISSET('dol_optimize_smallscreen')) { $themeparam .= '&dol_optimize_smallscreen='.GETPOST('dol_optimize_smallscreen', 'int'); } - if (GETPOSTISSET('dol_no_mouse_hover')) { $themeparam .= '&dol_no_mouse_hover='.GETPOST('dol_no_mouse_hover', 'int'); } - if (GETPOSTISSET('dol_use_jmobile')) { $themeparam .= '&dol_use_jmobile='.GETPOST('dol_use_jmobile', 'int'); $conf->dol_use_jmobile = GETPOST('dol_use_jmobile', 'int'); } - if (GETPOSTISSET('THEME_DARKMODEENABLED')) { $themeparam .= '&THEME_DARKMODEENABLED='.GETPOST('THEME_DARKMODEENABLED', 'int'); } - if (GETPOSTISSET('THEME_SATURATE_RATIO')) { $themeparam .= '&THEME_SATURATE_RATIO='.GETPOST('THEME_SATURATE_RATIO', 'int'); } + if (!empty($_SESSION['dol_resetcache'])) { + $themeparam .= '&dol_resetcache='.$_SESSION['dol_resetcache']; + } + if (GETPOSTISSET('dol_hide_topmenu')) { + $themeparam .= '&dol_hide_topmenu='.GETPOST('dol_hide_topmenu', 'int'); + } + if (GETPOSTISSET('dol_hide_leftmenu')) { + $themeparam .= '&dol_hide_leftmenu='.GETPOST('dol_hide_leftmenu', 'int'); + } + if (GETPOSTISSET('dol_optimize_smallscreen')) { + $themeparam .= '&dol_optimize_smallscreen='.GETPOST('dol_optimize_smallscreen', 'int'); + } + if (GETPOSTISSET('dol_no_mouse_hover')) { + $themeparam .= '&dol_no_mouse_hover='.GETPOST('dol_no_mouse_hover', 'int'); + } + if (GETPOSTISSET('dol_use_jmobile')) { + $themeparam .= '&dol_use_jmobile='.GETPOST('dol_use_jmobile', 'int'); $conf->dol_use_jmobile = GETPOST('dol_use_jmobile', 'int'); + } + if (GETPOSTISSET('THEME_DARKMODEENABLED')) { + $themeparam .= '&THEME_DARKMODEENABLED='.GETPOST('THEME_DARKMODEENABLED', 'int'); + } + if (GETPOSTISSET('THEME_SATURATE_RATIO')) { + $themeparam .= '&THEME_SATURATE_RATIO='.GETPOST('THEME_SATURATE_RATIO', 'int'); + } if (!empty($conf->global->MAIN_ENABLE_FONT_ROBOTO)) { print ''."\n"; print ''."\n"; } - if (!defined('DISABLE_JQUERY') && !$disablejs && $conf->use_javascript_ajax) - { + if (!defined('DISABLE_JQUERY') && !$disablejs && $conf->use_javascript_ajax) { print ''."\n"; $jquerytheme = 'base'; - if (!empty($conf->global->MAIN_USE_JQUERY_THEME)) $jquerytheme = $conf->global->MAIN_USE_JQUERY_THEME; - if (constant('JS_JQUERY_UI')) print ''."\n"; // Forced JQuery - else print ''."\n"; // JQuery - if (!defined('DISABLE_JQUERY_JNOTIFY')) print ''."\n"; // JNotify - if (!defined('DISABLE_SELECT2') && (!empty($conf->global->MAIN_USE_JQUERY_MULTISELECT) || defined('REQUIRE_JQUERY_MULTISELECT'))) // jQuery plugin "mutiselect", "multiple-select", "select2"... - { + if (!empty($conf->global->MAIN_USE_JQUERY_THEME)) { + $jquerytheme = $conf->global->MAIN_USE_JQUERY_THEME; + } + if (constant('JS_JQUERY_UI')) { + print ''."\n"; // Forced JQuery + } else { + print ''."\n"; // JQuery + } + if (!defined('DISABLE_JQUERY_JNOTIFY')) { + print ''."\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; print ''."\n"; } } - if (!defined('DISABLE_FONT_AWSOME')) - { + if (!defined('DISABLE_FONT_AWSOME')) { print ''."\n"; print ''."\n"; print ''."\n"; @@ -1396,12 +1471,9 @@ function top_htmlhead($head, $title = '', $disablejs = 0, $disablehead = 0, $arr // 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))) - { + 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))) { $themepath = dol_buildpath($reldir.$conf->css, 1); $themesubdir = $reldir; break; @@ -1411,59 +1483,68 @@ function top_htmlhead($head, $title = '', $disablejs = 0, $disablehead = 0, $arr //print 'themepath='.$themepath.' themeparam='.$themeparam;exit; print ''."\n"; - if (!empty($conf->global->MAIN_FIX_FLASH_ON_CHROME)) print ''."\n".''."\n"; + if (!empty($conf->global->MAIN_FIX_FLASH_ON_CHROME)) { + print ''."\n".''."\n"; + } // CSS forced by modules (relative url starting with /) - if (!empty($conf->modules_parts['css'])) - { + if (!empty($conf->modules_parts['css'])) { $arraycss = (array) $conf->modules_parts['css']; - foreach ($arraycss as $modcss => $filescss) - { + 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); + 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 ''."\n".''."\n"; } } } // CSS forced by page in top_htmlhead call (relative url starting with /) - if (is_array($arrayofcss)) - { - foreach ($arrayofcss as $cssfile) - { - if (preg_match('/^(http|\/\/)/i', $cssfile)) - { + if (is_array($arrayofcss)) { + foreach ($arrayofcss as $cssfile) { + if (preg_match('/^(http|\/\/)/i', $cssfile)) { $urltofile = $cssfile; } else { $urltofile = dol_buildpath($cssfile, 1); } print ''."\n".''."\n"; } } // Output standard javascript links - if (!defined('DISABLE_JQUERY') && !$disablejs && !empty($conf->use_javascript_ajax)) - { + if (!defined('DISABLE_JQUERY') && !$disablejs && !empty($conf->use_javascript_ajax)) { // JQuery. Must be before other includes print ''."\n"; - if (defined('JS_JQUERY') && constant('JS_JQUERY')) print ''."\n"; - else print ''."\n"; + if (defined('JS_JQUERY') && constant('JS_JQUERY')) { + print ''."\n"; + } else { + print ''."\n"; + } /*if (! empty($conf->global->MAIN_FEATURES_LEVEL) && ! defined('JS_JQUERY_MIGRATE_DISABLED')) { if (defined('JS_JQUERY_MIGRATE') && constant('JS_JQUERY_MIGRATE')) print ''."\n"; else print ''."\n"; }*/ - if (defined('JS_JQUERY_UI') && constant('JS_JQUERY_UI')) print ''."\n"; - else print ''."\n"; - if (!defined('DISABLE_JQUERY_TABLEDND')) print ''."\n"; + if (defined('JS_JQUERY_UI') && constant('JS_JQUERY_UI')) { + print ''."\n"; + } else { + print ''."\n"; + } + if (!defined('DISABLE_JQUERY_TABLEDND')) { + print ''."\n"; + } // jQuery jnotify if (empty($conf->global->MAIN_DISABLE_JQUERY_JNOTIFY) && !defined('DISABLE_JQUERY_JNOTIFY')) { print ''."\n"; @@ -1502,16 +1583,14 @@ function top_htmlhead($head, $title = '', $disablejs = 0, $disablehead = 0, $arr $tmpplugin = empty($conf->global->MAIN_USE_JQUERY_MULTISELECT) ?constant('REQUIRE_JQUERY_MULTISELECT') : $conf->global->MAIN_USE_JQUERY_MULTISELECT; print ''."\n"; // We include full because we need the support of containerCssClass } - if (!defined('DISABLE_MULTISELECT')) // jQuery plugin "mutiselect" to select with checkboxes. Can be removed once we have an enhanced search tool - { + if (!defined('DISABLE_MULTISELECT')) { // jQuery plugin "mutiselect" to select with checkboxes. Can be removed once we have an enhanced search tool print ''."\n"; } } if (!$disablejs && !empty($conf->use_javascript_ajax)) { // CKEditor - if ((!empty($conf->fckeditor->enabled) && (empty($conf->global->FCKEDITOR_EDITORNAME) || $conf->global->FCKEDITOR_EDITORNAME == 'ckeditor') && !defined('DISABLE_CKEDITOR')) || defined('FORCE_CKEDITOR')) - { + if ((!empty($conf->fckeditor->enabled) && (empty($conf->global->FCKEDITOR_EDITORNAME) || $conf->global->FCKEDITOR_EDITORNAME == 'ckeditor') && !defined('DISABLE_CKEDITOR')) || defined('FORCE_CKEDITOR')) { print ''."\n"; $pathckeditor = DOL_URL_ROOT.'/includes/ckeditor/ckeditor/'; $jsckeditor = 'ckeditor.js'; @@ -1520,7 +1599,7 @@ function top_htmlhead($head, $title = '', $disablejs = 0, $disablehead = 0, $arr $pathckeditor = constant('JS_CKEDITOR'); } print ''."\n"; } @@ -1554,27 +1635,21 @@ function top_htmlhead($head, $title = '', $disablejs = 0, $disablehead = 0, $arr print ''."\n"; // JS forced by modules (relative url starting with /) - if (!empty($conf->modules_parts['js'])) // $conf->modules_parts['js'] is array('module'=>array('file1','file2')) - { + if (!empty($conf->modules_parts['js'])) { // $conf->modules_parts['js'] is array('module'=>array('file1','file2')) $arrayjs = (array) $conf->modules_parts['js']; - foreach ($arrayjs as $modjs => $filesjs) - { + foreach ($arrayjs as $modjs => $filesjs) { $filesjs = (array) $filesjs; // To be sure filejs is an array - foreach ($filesjs as $jsfile) - { + foreach ($filesjs as $jsfile) { // jsfile is a relative path print ''."\n".''."\n"; } } } // JS forced by page in top_htmlhead (relative url starting with /) - if (is_array($arrayofjs)) - { + if (is_array($arrayofjs)) { print ''."\n"; - foreach ($arrayofjs as $jsfile) - { - if (preg_match('/^(http|\/\/)/i', $jsfile)) - { + foreach ($arrayofjs as $jsfile) { + if (preg_match('/^(http|\/\/)/i', $jsfile)) { print ''."\n"; } else { print ''."\n"; @@ -1583,8 +1658,12 @@ function top_htmlhead($head, $title = '', $disablejs = 0, $disablehead = 0, $arr } } - if (!empty($head)) print $head."\n"; - if (!empty($conf->global->MAIN_HTML_HEADER)) print $conf->global->MAIN_HTML_HEADER."\n"; + if (!empty($head)) { + print $head."\n"; + } + if (!empty($conf->global->MAIN_HTML_HEADER)) { + print $conf->global->MAIN_HTML_HEADER."\n"; + } $parameters = array(); $result = $hookmanager->executeHooks('addHtmlHeader', $parameters); // Note that $action and $object may have been modified by some hooks @@ -1628,18 +1707,16 @@ function top_menu($head, $title = '', $target = '', $disablejs = 0, $disablehead $toprightmenu = ''; // For backward compatibility with old modules - if (empty($conf->headerdone)) - { + if (empty($conf->headerdone)) { $disablenofollow = 0; top_htmlhead($head, $title, $disablejs, $disablehead, $arrayofjs, $arrayofcss, 0, $disablenofollow); print ''; } /* - * Top menu - */ - if ((empty($conf->dol_hide_topmenu) || GETPOST('dol_invisible_topmenu', 'int')) && (!defined('NOREQUIREMENU') || !constant('NOREQUIREMENU'))) - { + * Top menu + */ + if ((empty($conf->dol_hide_topmenu) || GETPOST('dol_invisible_topmenu', 'int')) && (!defined('NOREQUIREMENU') || !constant('NOREQUIREMENU'))) { if (!isset($form) || !is_object($form)) { include_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php'; $form = new Form($db); @@ -1657,24 +1734,28 @@ function top_menu($head, $title = '', $target = '', $disablejs = 0, $disablehead // Define link to login card $appli = constant('DOL_APPLICATION_TITLE'); - if (!empty($conf->global->MAIN_APPLICATION_TITLE)) - { + if (!empty($conf->global->MAIN_APPLICATION_TITLE)) { $appli = $conf->global->MAIN_APPLICATION_TITLE; - 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; + 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; + } - if (!empty($conf->global->MAIN_FEATURES_LEVEL)) $appli .= "
".$langs->trans("LevelOfFeature").': '.$conf->global->MAIN_FEATURES_LEVEL; + if (!empty($conf->global->MAIN_FEATURES_LEVEL)) { + $appli .= "
".$langs->trans("LevelOfFeature").': '.$conf->global->MAIN_FEATURES_LEVEL; + } $logouttext = ''; $logouthtmltext = ''; - if (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) - { + if (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) { //$logouthtmltext=$appli.'
'; - if ($_SESSION["dol_authmode"] != 'forceuser' && $_SESSION["dol_authmode"] != 'http') - { + if ($_SESSION["dol_authmode"] != 'forceuser' && $_SESSION["dol_authmode"] != 'http') { $logouthtmltext .= $langs->trans("Logout").'
'; $logouttext .= ''; @@ -1693,11 +1774,10 @@ function top_menu($head, $title = '', $target = '', $disablejs = 0, $disablehead // Execute hook printTopRightMenu (hooks should output string like '
mylink
') $parameters = array(); $result = $hookmanager->executeHooks('printTopRightMenu', $parameters); // Note that $action and $object may have been modified by some hooks - if (is_numeric($result)) - { - if ($result == 0) + if (is_numeric($result)) { + if ($result == 0) { $toprightmenu .= $hookmanager->resPrint; // add - else { + } else { $toprightmenu = $hookmanager->resPrint; // replace } } else { @@ -1705,8 +1785,7 @@ function top_menu($head, $title = '', $target = '', $disablejs = 0, $disablehead } // Link to module builder - if (!empty($conf->modulebuilder->enabled)) - { + if (!empty($conf->modulebuilder->enabled)) { $text = ''; //$text.= img_picto(":".$langs->trans("ModuleBuilder"), 'printer_top.png', 'class="printer"'); $text .= ''; @@ -1715,14 +1794,14 @@ function top_menu($head, $title = '', $target = '', $disablejs = 0, $disablehead } // Link to print main content area - if (empty($conf->global->MAIN_PRINT_DISABLELINK) && empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER) && $conf->browser->layout != 'phone') - { + if (empty($conf->global->MAIN_PRINT_DISABLELINK) && empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER) && $conf->browser->layout != 'phone') { $qs = dol_escape_htmltag($_SERVER["QUERY_STRING"]); - if (is_array($_POST)) - { - foreach ($_POST as $key=>$value) { - if ($key !== 'action' && $key !== 'password' && !is_array($value)) $qs .= '&'.$key.'='.urlencode($value); + if (is_array($_POST)) { + foreach ($_POST as $key => $value) { + if ($key !== 'action' && $key !== 'password' && !is_array($value)) { + $qs .= '&'.$key.'='.urlencode($value); + } } } $qs .= (($qs && $morequerystring) ? '&' : '').$morequerystring; @@ -1734,8 +1813,7 @@ function top_menu($head, $title = '', $target = '', $disablejs = 0, $disablehead } // Link to Dolibarr wiki pages - if (empty($conf->global->MAIN_HELP_DISABLELINK) && empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) - { + if (empty($conf->global->MAIN_HELP_DISABLELINK) && empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) { $langs->load("help"); $helpbaseurl = ''; @@ -1756,21 +1834,28 @@ function top_menu($head, $title = '', $target = '', $disablejs = 0, $disablehead $mode = $arrayres['mode']; // Link to help pages - if ($helpbaseurl && $helppage) - { + if ($helpbaseurl && $helppage) { $text = ''; $title = $langs->trans($mode == 'wiki' ? 'GoToWikiHelpPage' : 'GoToHelpPage').'...'; if ($mode == 'wiki') { $title .= '
'.$langs->trans("PageWiki").' '.dol_escape_htmltag('"'.strtr($helppage, '_', ' ').'"'); - if ($helppresent) $title .= ' ('.$langs->trans("DedicatedPageAvailable").')'; - else $title .= ' ('.$langs->trans("HomePage").')'; + if ($helppresent) { + $title .= ' ('.$langs->trans("DedicatedPageAvailable").')'; + } else { + $title .= ' ('.$langs->trans("HomePage").')'; + } } $text .= '
'; $text .= ''; - if ($helppresent) $text .= ''; + if ($helppresent) { + $text .= ''; + } $text .= ''; $toprightmenu .= $form->textwithtooltip('', $title, 2, 1, $text, 'login_block_elem', 2); } @@ -1831,7 +1916,9 @@ function top_menu($head, $title = '', $target = '', $disablejs = 0, $disablehead print "\n\n"; } - if (empty($conf->dol_hide_leftmenu) && empty($conf->dol_use_jmobile)) print '
'; + if (empty($conf->dol_hide_leftmenu) && empty($conf->dol_use_jmobile)) { + print '
'; + } } @@ -1849,14 +1936,17 @@ function top_menu_user($hideloginname = 0, $urllogout = '') global $menumanager; $userImage = $userDropDownImage = ''; - if (!empty($user->photo)) - { + if (!empty($user->photo)) { $userImage = Form::showphoto('userphoto', $user, 0, 0, 0, 'photouserphoto userphoto', 'small', 0, 1); $userDropDownImage = Form::showphoto('userphoto', $user, 0, 0, 0, 'dropdown-user-image', 'small', 0, 1); } else { $nophoto = '/public/theme/common/user_anonymous.png'; - if ($user->gender == 'man') $nophoto = '/public/theme/common/user_man.png'; - if ($user->gender == 'woman') $nophoto = '/public/theme/common/user_woman.png'; + if ($user->gender == 'man') { + $nophoto = '/public/theme/common/user_man.png'; + } + if ($user->gender == 'woman') { + $nophoto = '/public/theme/common/user_woman.png'; + } $userImage = 'No photo'; $userDropDownImage = 'No photo'; @@ -1870,8 +1960,7 @@ function top_menu_user($hideloginname = 0, $urllogout = '') if (!empty($user->admin)) { $dropdownBody .= '
'.$langs->trans("Administrator").': '.yn($user->admin); } - if (!empty($user->socid)) // Add thirdparty for external users - { + if (!empty($user->socid)) { // Add thirdparty for external users $thirdpartystatic = new Societe($db); $thirdpartystatic->fetch($user->socid); $companylink = ' '.$thirdpartystatic->getNomUrl(2); // picto only of company @@ -1884,7 +1973,9 @@ function top_menu_user($hideloginname = 0, $urllogout = '') $dropdownBody .= '
'.$langs->trans("Session").''; $dropdownBody .= '
'.$langs->trans("IPAddress").': '.dol_escape_htmltag($_SERVER["REMOTE_ADDR"]); - if (!empty($conf->global->MAIN_MODULE_MULTICOMPANY)) $dropdownBody .= '
'.$langs->trans("ConnectedOnMultiCompany").': '.$conf->entity.' (user entity '.$user->entity.')'; + if (!empty($conf->global->MAIN_MODULE_MULTICOMPANY)) { + $dropdownBody .= '
'.$langs->trans("ConnectedOnMultiCompany").': '.$conf->entity.' (user entity '.$user->entity.')'; + } $dropdownBody .= '
'.$langs->trans("AuthenticationMode").': '.$_SESSION["dol_authmode"].(empty($dolibarr_main_demo) ? '' : ' (demo)'); $dropdownBody .= '
'.$langs->trans("ConnectedSince").': '.dol_print_date($user->datelastlogin, "dayhour", 'tzuser'); $dropdownBody .= '
'.$langs->trans("PreviousConnexion").': '.dol_print_date($user->datepreviouslogin, "dayhour", 'tzuser'); @@ -1903,15 +1994,18 @@ function top_menu_user($hideloginname = 0, $urllogout = '') $dropdownBody .= '
'.$langs->trans("Browser").': '.$conf->browser->name.($conf->browser->version ? ' '.$conf->browser->version : '').' ('.dol_escape_htmltag($_SERVER['HTTP_USER_AGENT']).')'; $dropdownBody .= '
'.$langs->trans("Layout").': '.$conf->browser->layout; $dropdownBody .= '
'.$langs->trans("Screen").': '.$_SESSION['dol_screenwidth'].' x '.$_SESSION['dol_screenheight']; - if ($conf->browser->layout == 'phone') $dropdownBody .= '
'.$langs->trans("Phone").': '.$langs->trans("Yes"); - if (!empty($_SESSION["disablemodules"])) $dropdownBody .= '
'.$langs->trans("DisabledModules").':
'.join(', ', explode(',', $_SESSION["disablemodules"])); + if ($conf->browser->layout == 'phone') { + $dropdownBody .= '
'.$langs->trans("Phone").': '.$langs->trans("Yes"); + } + if (!empty($_SESSION["disablemodules"])) { + $dropdownBody .= '
'.$langs->trans("DisabledModules").':
'.join(', ', explode(',', $_SESSION["disablemodules"])); + } $dropdownBody .= '
'; // Execute hook $parameters = array('user'=>$user, 'langs' => $langs); $result = $hookmanager->executeHooks('printTopRightMenuLoginDropdownBody', $parameters); // Note that $action and $object may have been modified by some hooks - if (is_numeric($result)) - { + if (is_numeric($result)) { if ($result == 0) { $dropdownBody .= $hookmanager->resPrint; // add } else { @@ -1934,14 +2028,18 @@ function top_menu_user($hideloginname = 0, $urllogout = '') // Define version to show $appli = constant('DOL_APPLICATION_TITLE'); - if (!empty($conf->global->MAIN_APPLICATION_TITLE)) - { + if (!empty($conf->global->MAIN_APPLICATION_TITLE)) { $appli = $conf->global->MAIN_APPLICATION_TITLE; - 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; + 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; + } if (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) { $btnUser = ' @@ -1990,8 +2088,7 @@ function top_menu_user($hideloginname = 0, $urllogout = '')
'; } - if (!defined('JS_JQUERY_DISABLE_DROPDOWN') && !empty($conf->use_javascript_ajax)) // This may be set by some pages that use different jquery version to avoid errors - { + if (!defined('JS_JQUERY_DISABLE_DROPDOWN') && !empty($conf->use_javascript_ajax)) { // This may be set by some pages that use different jquery version to avoid errors $btnUser .= ' '."\n"; } // 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' - { + 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\n"; ?> - + \n"; @@ -2916,20 +3063,17 @@ if (!function_exists("llxFooter")) // Add code for the asynchronous anonymous first ping (for telemetry) // You can use &forceping=1 in parameters to force the ping if the ping was already sent. $forceping = GETPOST('forceping', 'alpha'); - if (($_SERVER["PHP_SELF"] == DOL_URL_ROOT.'/index.php') || $forceping) - { + if (($_SERVER["PHP_SELF"] == DOL_URL_ROOT.'/index.php') || $forceping) { //print ''; $hash_unique_id = md5('dolibarr'.$conf->file->instance_unique_id); if (empty($conf->global->MAIN_FIRST_PING_OK_DATE) || (!empty($conf->file->instance_unique_id) && ($hash_unique_id != $conf->global->MAIN_FIRST_PING_OK_ID) && ($conf->global->MAIN_FIRST_PING_OK_ID != 'disabled')) - || $forceping) - { + || $forceping) { // No ping done if we are into an alpha version if (strpos('alpha', DOL_VERSION) > 0 && !$forceping) { print "\n\n"; - } elseif (empty($_COOKIE['DOLINSTALLNOPING_'.$hash_unique_id]) || $forceping) // Cookie is set when we uncheck the checkbox in the installation wizard. - { - // MAIN_LAST_PING_KO_DATE + } elseif (empty($_COOKIE['DOLINSTALLNOPING_'.$hash_unique_id]) || $forceping) { // Cookie is set when we uncheck the checkbox in the installation wizard. + // MAIN_LAST_PING_KO_DATE // Disable ping if MAIN_LAST_PING_KO_DATE is set and is recent if (!empty($conf->global->MAIN_LAST_PING_KO_DATE) && substr($conf->global->MAIN_LAST_PING_KO_DATE, 0, 6) == dol_print_date(dol_now(), '%Y%m') && !$forceping) { print "\n\n"; @@ -2941,51 +3085,55 @@ if (!function_exists("llxFooter")) $url_for_ping = (empty($conf->global->MAIN_URL_FOR_PING) ? "https://ping.dolibarr.org/" : $conf->global->MAIN_URL_FOR_PING); // Try to guess the distrib used $distrib = 'standard'; - if ($_SERVER["SERVER_ADMIN"] == 'doliwamp@localhost') $distrib = 'doliwamp'; - if (!empty($dolibarr_distrib)) $distrib = $dolibarr_distrib; + if ($_SERVER["SERVER_ADMIN"] == 'doliwamp@localhost') { + $distrib = 'doliwamp'; + } + if (!empty($dolibarr_distrib)) { + $distrib = $dolibarr_distrib; + } ?> - +