dolibarr/htdocs/user/logout.php

111 lines
3.6 KiB
PHP
Raw Normal View History

2004-10-20 23:06:45 +02:00
<?php
/* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2003 Xavier Dutoit <doli@sydesy.com>
* Copyright (C) 2004-2009 Laurent Destailleur <eldy@users.sourceforge.net>
2018-10-27 14:43:12 +02:00
* Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
2003-08-30 14:17:08 +02: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
* the Free Software Foundation; either version 3 of the License, or
2003-08-30 14:17:08 +02:00
* (at your option) any later version.
*
* 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.
*
* You should have received a copy of the GNU General Public License
2019-09-23 21:55:30 +02:00
* along with this program. If not, see <https://www.gnu.org/licenses/>.
2003-08-30 14:17:08 +02:00
*/
/**
2009-05-18 00:40:53 +02:00
* \file htdocs/user/logout.php
* \brief Page called to disconnect a user
*/
//if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL','1'); // Uncomment creates pb to relogon after a disconnect
2021-02-26 13:18:40 +01:00
if (!defined('NOREQUIREMENU')) {
define('NOREQUIREMENU', '1');
}
if (!defined('NOREQUIREHTML')) {
define('NOREQUIREHTML', '1');
}
if (!defined('NOREQUIREAJAX')) {
define('NOREQUIREAJAX', '1');
}
2013-04-27 21:35:30 +02:00
//if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC','1'); // We need company to get correct logo onto home page
2021-02-26 13:18:40 +01:00
if (!defined('EVEN_IF_ONLY_LOGIN_ALLOWED')) {
define('EVEN_IF_ONLY_LOGIN_ALLOWED', '1');
}
require_once '../main.inc.php';
// This can happen only with a bookmark or forged url call.
2021-02-26 13:18:40 +01:00
if (!empty($_SESSION["dol_authmode"]) && ($_SESSION["dol_authmode"] == 'forceuser' || $_SESSION["dol_authmode"] == 'http')) {
unset($_SESSION["dol_login"]);
die("Applicative disconnection should be useless when connection was made in mode ".$_SESSION["dol_authmode"]);
}
2004-07-27 16:56:03 +02:00
2014-08-20 19:03:58 +02:00
global $conf, $langs, $user;
2020-04-02 12:03:29 +02:00
// Call trigger
$result = $user->call_trigger('USER_LOGOUT', $user);
2021-02-26 13:18:40 +01:00
if ($result < 0) {
$error++;
}
// End call triggers
2018-05-05 13:36:20 +02:00
// Hooks on logout
$action = '';
2018-05-05 13:36:20 +02:00
$hookmanager->initHooks(array('logout'));
$parameters = array();
$reshook = $hookmanager->executeHooks('afterLogout', $parameters, $user, $action); // Note that $action and $object may have been modified by some hooks
2021-02-26 13:18:40 +01:00
if ($reshook < 0) {
$error++;
}
2018-05-05 13:36:20 +02:00
2008-12-10 15:56:05 +01:00
// Define url to go after disconnect
$urlfrom = empty($_SESSION["urlfrom"]) ? '' : $_SESSION["urlfrom"];
2008-12-10 15:56:05 +01:00
// Define url to go
$url = DOL_URL_ROOT."/index.php"; // By default go to login page
2021-02-26 13:18:40 +01:00
if ($urlfrom) {
$url = DOL_URL_ROOT.$urlfrom;
}
if (!empty($conf->global->MAIN_LOGOUT_GOTO_URL)) {
$url = $conf->global->MAIN_LOGOUT_GOTO_URL;
}
2021-02-26 13:18:40 +01:00
if (GETPOST('dol_hide_topmenu')) {
$url .= (preg_match('/\?/', $url) ? '&' : '?').'dol_hide_topmenu=1';
}
if (GETPOST('dol_hide_leftmenu')) {
$url .= (preg_match('/\?/', $url) ? '&' : '?').'dol_hide_leftmenu=1';
}
if (GETPOST('dol_optimize_smallscreen')) {
$url .= (preg_match('/\?/', $url) ? '&' : '?').'dol_optimize_smallscreen=1';
}
if (GETPOST('dol_no_mouse_hover')) {
$url .= (preg_match('/\?/', $url) ? '&' : '?').'dol_no_mouse_hover=1';
}
if (GETPOST('dol_use_jmobile')) {
$url .= (preg_match('/\?/', $url) ? '&' : '?').'dol_use_jmobile=1';
}
// Destroy session
2018-09-01 11:57:18 +02:00
dol_syslog("End of session ".session_id());
2021-02-26 13:18:40 +01:00
if (session_status() === PHP_SESSION_ACTIVE) {
2018-09-01 11:57:18 +02:00
session_destroy();
}
2008-10-12 13:41:13 +02:00
// Not sure this is required
2013-06-05 16:12:07 +02:00
unset($_SESSION['dol_login']);
unset($_SESSION['dol_entity']);
2019-08-28 19:48:45 +02:00
unset($_SESSION['urlfrom']);
2021-02-26 13:18:40 +01:00
if (GETPOST('noredirect')) {
return;
}
header("Location: ".$url); // Default behaviour is redirect to index.php page