From a655d930d014527f8bc05afdc75d3187b6b14117 Mon Sep 17 00:00:00 2001 From: Savetheinternet Date: Wed, 16 Feb 2011 19:59:13 +1100 Subject: [PATCH] Return to page if mod clicked on a link to a moderator page but was not logged in --- inc/display.php | 5 +++-- mod.php | 15 +++++++++------ templates/login.html | 3 ++- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/inc/display.php b/inc/display.php index acf77e39..9186b47a 100644 --- a/inc/display.php +++ b/inc/display.php @@ -37,7 +37,7 @@ ))); } - function loginForm($error=false, $username=false) { + function loginForm($error=false, $username=false, $redirect=false) { global $config; if(function_exists('sql_close')) sql_close(); @@ -47,7 +47,8 @@ 'body'=>Element('login.html', Array( 'index'=>$config['root'], 'error'=>$error, - 'username'=>$username + 'username'=>$username, + 'redirect'=>$redirect ) ) ))); diff --git a/mod.php b/mod.php index e465adec..23950f8c 100644 --- a/mod.php +++ b/mod.php @@ -25,6 +25,8 @@ $_POST = strip_array($_POST); } + $query = isset($_SERVER['QUERY_STRING']) ? $_SERVER['QUERY_STRING'] : ''; + // If not logged in if(!$mod) { if(isset($_POST['login'])) { @@ -33,11 +35,11 @@ !isset($_POST['password']) || empty($_POST['username']) || empty($_POST['password']) - ) loginForm($config['error']['invalid'], $_POST['username']); + ) loginForm($config['error']['invalid'], $_POST['username'], '?' . $query); if(!login($_POST['username'], $_POST['password'])) - loginForm($config['error']['invalid'], $_POST['username']); + loginForm($config['error']['invalid'], $_POST['username'], '?' . $query); modLog("Logged in."); @@ -46,16 +48,17 @@ setCookies(); // Redirect - header('Location: ?' . $config['mod']['default'], true, $config['redirect_http']); + if(isset($_POST['redirect'])) + header('Location: ' . $_POST['redirect'], true, $config['redirect_http']); + else + header('Location: ?' . $config['mod']['default'], true, $config['redirect_http']); // Close connection sql_close(); } else { - loginForm(); + loginForm(false, false, '?' . $query); } } else { - $query = isset($_SERVER['QUERY_STRING']) ? $_SERVER['QUERY_STRING'] : ''; - // A sort of "cache" // Stops calling preg_quote and str_replace when not needed; only does it once $regex = Array( diff --git a/templates/login.html b/templates/login.html index 312bd6e9..e9d559f7 100644 --- a/templates/login.html +++ b/templates/login.html @@ -1,6 +1,7 @@ -
+
{error?

{error}

}
+ {redirect?}