Commit 960549da authored by Nigel McNie's avatar Nigel McNie Committed by Nigel McNie
Browse files

Fix up redirect() as part of fixing bug 432. Now mahara works in a

subdirectory properly.
parent cd61deef
......@@ -73,7 +73,7 @@ function adminusers_submit(Pieform $form, $values) {
WHERE id IN (' . join(',', $values['users']) . ')');
db_commit();
$SESSION->add_ok_msg(get_string('adminusersupdated', 'admin'));
redirect(get_config('wwwroot') . 'admin/users/admins.php');
redirect('/admin/users/admins.php');
}
$smarty->assign('adminusersform', pieform($form));
......
......@@ -48,7 +48,7 @@ if ($institution || $add) {
}
function delete_cancel_submit() {
redirect(get_config('wwwroot') . 'admin/users/institutions.php');
redirect('/admin/users/institutions.php');
}
function delete_submit(Pieform $form, $values) {
......@@ -60,7 +60,7 @@ if ($institution || $add) {
db_commit();
$SESSION->add_ok_msg(get_string('institutiondeletedsuccessfully', 'admin'));
redirect('admin/users/institutions.php');
redirect('/admin/users/institutions.php');
}
$form = array(
'name' => 'delete',
......@@ -233,11 +233,11 @@ function institution_submit(Pieform $form, $values) {
$message = ($add) ? 'institutionaddedsuccessfully' : 'institutionupdatedsuccessfully';
$SESSION->add_ok_msg(get_string($message, 'admin'));
redirect(get_config('wwwroot') . 'admin/users/institutions.php');
redirect('/admin/users/institutions.php');
}
function institution_cancel_submit() {
redirect('admin/users/institutions.php');
redirect('/admin/users/institutions.php');
}
$smarty->display('admin/users/institutions.tpl');
......
......@@ -71,7 +71,7 @@ function staffusers_submit(Pieform $form, $values) {
}
db_commit();
$SESSION->add_ok_msg(get_string('staffusersupdated', 'admin'));
redirect(get_config('wwwroot') . 'admin/users/staff.php');
redirect('/admin/users/staff.php');
}
$smarty->assign('staffusersform', pieform($form));
......
......@@ -88,14 +88,14 @@ function buttons_submit_unsuspend(Pieform $form, $values) {
}
$SESSION->add_ok_msg(get_string('usersunsuspendedsuccessfully', 'admin'));
redirect('admin/users/suspended.php');
redirect('/admin/users/suspended.php');
}
function buttons_submit_export(Pieform $form, $values) {
global $SESSION;
$ids = get_user_ids_from_post();
$SESSION->add_info_msg(get_string('exportingnotsupportedyet', 'admin'));
redirect('admin/users/suspended.php');
redirect('/admin/users/suspended.php');
}
function buttons_submit_delete(Pieform $form, $values) {
......@@ -107,7 +107,7 @@ function buttons_submit_delete(Pieform $form, $values) {
}
$SESSION->add_ok_msg(get_string('usersdeletedsuccessfully', 'admin'));
redirect('admin/users/suspended.php');
redirect('/admin/users/suspended.php');
}
function get_user_ids_from_post() {
......@@ -121,7 +121,7 @@ function get_user_ids_from_post() {
if (!$ids) {
global $SESSION;
$SESSION->add_info_msg(get_string('nousersselected', 'admin'));
redirect('admin/users/suspended.php');
redirect('/admin/users/suspended.php');
}
return $ids;
......
......@@ -178,7 +178,7 @@ function uploadcsv_submit(Pieform $form, $values) {
log_info('Inserted ' . count($CSVDATA) . ' records');
$SESSION->add_ok_msg(get_string('uploadcsvusersaddedsuccessfully', 'admin'));
redirect('admin/users/uploadcsv.php');
redirect('/admin/users/uploadcsv.php');
}
$smarty = smarty();
......
......@@ -96,14 +96,14 @@ function newblog_submit(Pieform $form, $values) {
global $USER;
ArtefactTypeBlog::new_blog($USER, $values);
redirect('artefact/blog/');
redirect('/artefact/blog/');
}
/**
* This function gets called to cancel a submission.
*/
function newblog_cancel_submit() {
redirect('artefact/blog/');
redirect('/artefact/blog/');
}
?>
......@@ -669,10 +669,10 @@ function editpost_submit(Pieform $form, array $values) {
if ((!empty($values['id']) && ArtefactTypeBlogPost::edit_post($USER, $values))
|| (empty($values['id']) && ArtefactTypeBlogPost::new_post($USER, $values))) {
// Redirect to the blog page.
redirect('artefact/blog/view/?id=' . $values['parent']);
redirect('/artefact/blog/view/?id=' . $values['parent']);
}
redirect('artefact/blog/');
redirect('/artefact/blog/');
}
......@@ -683,7 +683,7 @@ function editpost_submit(Pieform $form, array $values) {
*/
function editpost_cancel_submit() {
$blog = param_integer('parent');
redirect('artefact/blog/view/?id=' . $blog);
redirect('/artefact/blog/view/?id=' . $blog);
}
?>
......@@ -109,7 +109,7 @@ function editblog_submit(Pieform $form, $values) {
ArtefactTypeBlog::edit_blog($USER, $values);
redirect(get_config('wwwroot') . 'artefact/blog/view/?id=' . $values['id']);
redirect('/artefact/blog/view/?id=' . $values['id']);
}
/**
......@@ -118,7 +118,7 @@ function editblog_submit(Pieform $form, $values) {
*/
function editblog_cancel_submit() {
$id = param_integer('id');
redirect(get_config('wwwroot') . 'artefact/blog/view/?id=' . $id);
redirect('/artefact/blog/view/?id=' . $id);
}
?>
......@@ -201,7 +201,7 @@ function settings_submit_default(Pieform $form, $values) {
$USER->set('profileicon', $default);
set_field('usr', 'profileicon', $default, 'id', $USER->get('id'));
$SESSION->add_ok_msg(get_string('profileiconsdefaultsetsuccessfully', 'artefact.internal'));
redirect('artefact/internal/profileicons.php');
redirect('/artefact/internal/profileicons.php');
}
function settings_submit_delete(Pieform $form, $values) {
......@@ -228,7 +228,7 @@ function settings_submit_delete(Pieform $form, $values) {
$SESSION->add_info_msg(get_string('profileiconsnoneselected', 'artefact.internal'));
}
redirect('artefact/internal/profileicons.php');
redirect('/artefact/internal/profileicons.php');
}
$smarty->assign('uploadform', $uploadform);
......
......@@ -128,7 +128,7 @@ function auth_setup () {
if ($sessionlogouttime && isset($_GET['logout'])) {
$USER->logout();
$SESSION->add_ok_msg(get_string('loggedoutok'));
redirect(get_config('wwwroot'));
redirect();
}
if ($sessionlogouttime > time()) {
// The session is still active, so continue it.
......@@ -144,12 +144,12 @@ function auth_setup () {
// The user's admin rights have been taken away
$USER->set('admin', 0);
$SESSION->add_error_msg(get_string('accessforbiddentoadminsection'));
redirect(get_config('wwwroot'));
redirect();
}
elseif (!$USER->get('admin')) {
// The user never was an admin
$SESSION->add_error_msg(get_string('accessforbiddentoadminsection'));
redirect(get_config('wwwroot'));
redirect();
}
}
$USER->renew();
......@@ -561,7 +561,7 @@ function login_submit(Pieform $form, $values) {
// Only admins in the admin section!
if (defined('ADMIN') && !$userdata->admin) {
$SESSION->add_error_msg(get_string('accessforbiddentoadminsection'));
redirect(get_config('wwwroot'));
redirect();
}
// Check if the user's account has been deleted
......
......@@ -82,7 +82,7 @@ function createcommunity_validate(Pieform $form, $values) {
}
function createcommunity_cancel_submit() {
redirect(get_config('wwwroot') . 'contacts/communities/owned.php');
redirect('/contacts/communities/owned.php');
}
function createcommunity_submit(Pieform $form, $values) {
......@@ -111,7 +111,7 @@ function createcommunity_submit(Pieform $form, $values) {
db_commit();
redirect(get_config('wwwroot') . 'contacts/communities/owned.php');
redirect('/contacts/communities/owned.php');
}
$smarty = smarty();
......
......@@ -38,7 +38,7 @@ $community_data = get_record('community', 'id', $id, 'owner', $USER->get('id'));
if (!$community_data) {
$SESSION->add_error_msg(get_string('canteditdontown'));
redirect(get_config('wwwroot') . 'contacts/communities/owned.php');
redirect('/contacts/communities/owned.php');
}
$joinoptions = array(
......@@ -96,7 +96,7 @@ function editcommunity_validate(Pieform $form, $values) {
}
function editcommunity_cancel_submit() {
redirect(get_config('wwwroot') . 'contacts/communities/owned.php');
redirect('/contacts/communities/owned.php');
}
function editcommunity_submit(Pieform $form, $values) {
......@@ -125,7 +125,7 @@ function editcommunity_submit(Pieform $form, $values) {
db_commit();
redirect(get_config('wwwroot') . 'contacts/communities/owned.php');
redirect('/contacts/communities/owned.php');
}
$smarty = smarty();
......
......@@ -111,7 +111,7 @@ if (!empty($joincontrol)) {
break;
}
// redirect, stuff will have changed
redirect(get_config('wwwroot') . 'contacts/communities/view.php?id=' . $id);
redirect('/contacts/communities/view.php?id=' . $id);
exit;
}
......
......@@ -70,7 +70,7 @@ function creategroup_validate(Pieform $form, $values) {
}
function creategroup_cancel_submit() {
redirect('contacts/groups/');
redirect('/contacts/groups/');
}
function creategroup_submit(Pieform $form, $values) {
......@@ -109,7 +109,7 @@ function creategroup_submit(Pieform $form, $values) {
db_commit();
redirect('contacts/groups/');
redirect('/contacts/groups/');
}
$smarty = smarty();
......
......@@ -36,7 +36,7 @@ $id = param_integer('id',null);
$group_data = get_record('usr_group', 'id', $id, 'owner', $USER->get('id'));
if (!$group_data) {
$SESSION->add_error_msg(get_string('canteditdontown'));
redirect('contacts/groups/');
redirect('/contacts/groups/');
}
$group_members = get_column('usr_group_member', 'member', 'grp', $group_data->id);
......@@ -90,12 +90,12 @@ function editgroup_validate(Pieform $form, $values) {
if (!$id) {
$SESSION->add_error_msg(get_string('canteditdontown'));
redirect('contacts/groups/');
redirect('/contacts/groups/');
}
}
function editgroup_cancel_submit() {
redirect('contacts/groups/');
redirect('/contacts/groups/');
}
function editgroup_submit(Pieform $form, $values) {
......@@ -135,7 +135,7 @@ function editgroup_submit(Pieform $form, $values) {
db_commit();
redirect('contacts/groups/');
redirect('/contacts/groups/');
}
$smarty = smarty();
......
......@@ -153,7 +153,7 @@ function forgotpass_submit(Pieform $form, $values) {
// Add a marker in the session to say that the user has registered
$_SESSION['pwchangerequested'] = true;
redirect('forgotpass.php');
redirect('/forgotpass.php');
}
function forgotpasschange_validate(Pieform $form, $values) {
......@@ -194,7 +194,7 @@ function forgotpasschange_submit(Pieform $form, $values) {
$USER->login($user);
$SESSION->add_ok_msg(get_string('passwordchangedok'));
redirect(get_config('wwwroot'));
redirect();
exit;
}
......
......@@ -172,7 +172,7 @@ if (!get_config('installed')
&& false === strpos($_SERVER['SCRIPT_FILENAME'], 'admin/index.php')
&& false === strpos($_SERVER['SCRIPT_FILENAME'], 'admin/upgrade.php')
&& false === strpos($_SERVER['SCRIPT_FILENAME'], 'admin/upgrade.json.php')) {
redirect('admin/');
redirect('/admin/');
}
?>
......@@ -1166,24 +1166,32 @@ function get_site_page_content($pagename) {
}
function redirect($location='') {
/**
* Redirects the browser to a new location. The path to redirect to can take
* two forms:
*
* - http[something]: will redirect the user to that exact URL
* - /[something]: will redirect to WWWROOT/[something]
*
* Any other form is illegal and will cause an error.
*
* @param string $location The location to redirect the user to. Defaults to
* the application home page.
*/
function redirect($location='/') {
if (headers_sent()) {
throw new Exception('Headers already sent when redirect() was called');
}
$wwwroot = get_config('wwwroot');
if ($location == '') {
$path = $_SERVER['SCRIPT_NAME'];
if (substr($path, -9) == 'index.php') {
$path = substr($path, 0, -9);
if (substr($location, 0, 4) != 'http') {
if (substr($location, 0, 1) != '/') {
throw new SystemException('redirect() should be called with either'
. ' /[something] for local redirects or http[something] for'
. ' absolute redirects');
}
$location = substr($wwwroot, 0, -1) . $path;
}
else if (substr($location, 0, 4) != 'http') {
if (substr($location, 0, 1) == '/') {
$location = substr($location, 1);
}
$location = $wwwroot . $location;
$location = get_config('wwwroot') . substr($location, 1);
}
header('HTTP/1.1 303 See Other');
......
......@@ -43,7 +43,7 @@ if (!session_id()) {
// Logged in people can't register
if (is_logged_in()) {
redirect('/');
redirect();
}
// Step two of registration (first as it's the easiest): the user has
......@@ -119,7 +119,7 @@ if (isset($_REQUEST['key'])) {
// Log the user in and send them to the homepage
$USER->login($registration);
redirect('/');
redirect();
}
function profileform_validate(Pieform $form, $values) {
......@@ -420,7 +420,7 @@ function register_submit(Pieform $form, $values) {
// Add a marker in the session to say that the user has registered
$_SESSION['registered'] = true;
redirect('register.php');
redirect('/register.php');
}
function register_cancel_submit() {
......
......@@ -17,7 +17,7 @@
{$INLINEJAVASCRIPT}
</script>
{/if}
<script type="text/javascript" src="/js/pieforms.js"></script>
<script type="text/javascript" src="{$WWWROOT}js/pieforms.js"></script>
{foreach from=$STYLESHEETLIST item=cssurl}
<link rel="stylesheet" type="text/css" href="{$cssurl}">
{/foreach}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment