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

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}
......
......@@ -129,7 +129,7 @@ function createview1_cancel_submit() {
$SESSION->clear('create_' . $createid);
redirect(get_config('wwwroot') . 'view/');
redirect('/view/');
}
function createview1_submit(Pieform $form, $values) {
......@@ -149,7 +149,7 @@ function createview1_submit(Pieform $form, $values) {
$SESSION->set('create_' . $values['createid'], $data);
redirect(get_config('wwwroot') . 'view/create2.php?createid=' . $values['createid']);
redirect('/view/create2.php?createid=' . $values['createid']);
}
$smarty = smarty();
......
......@@ -35,12 +35,12 @@ $template = param_variable('template', null);
$action = param_variable('action', null);
if ($action == 'back' ) {
redirect(get_config('wwwroot') . 'view/create1.php?createid=' . $createid);
redirect('/view/create1.php?createid=' . $createid);
}
if ($action == 'cancel' ) {
$SESSION->clear('create_' . $createid);
redirect(get_config('wwwroot') . 'view/');
redirect('/view/');
}
if ( $template !== null ) {
......@@ -50,7 +50,7 @@ if ( $template !== null ) {
$SESSION->set('create_' . $createid, $data);
redirect(get_config('wwwroot') . 'view/create3.php?createid=' . $createid);
redirect('/view/create3.php?createid=' . $createid);
}
define('MENUITEM', 'myviews');
......
......@@ -77,7 +77,7 @@ if (param_boolean('submit')) {
log_debug($data);
$SESSION->set('create_' . $createid, $data);
redirect(get_config('wwwroot') . 'view/create4.php?createid=' . $createid);
redirect('/view/create4.php?createid=' . $createid);
}
if (param_boolean('back')) {
......@@ -87,11 +87,11 @@ if (param_boolean('back')) {
$SESSION->set('create_' . $createid, $data);
redirect(get_config('wwwroot') . 'view/create2.php?createid=' . $createid);
redirect('/view/create2.php?createid=' . $createid);
}
if (param_boolean('cancel')) {
redirect(get_config('wwwroot') . 'view/');
redirect('/view/');
}
// Get the list of root things for the tree
......
......@@ -50,7 +50,7 @@ $form = array(
);
function createview4_submit_cancel() {
redirect('view/');
redirect('/view/');
}
function createview4_submit(Pieform $form, $values) {
......@@ -60,7 +60,7 @@ function createview4_submit(Pieform $form, $values) {
$data['accesslist'] = array_values((array)$values['accesslist']);
log_debug($data);
$SESSION->set('create_' . $createid, $data);
redirect(get_config('wwwroot') . 'view/create3.php?createid=' . $createid);
redirect('/view/create3.php?createid=' . $createid);
}
db_begin();
......@@ -141,11 +141,11 @@ function createview4_submit(Pieform $form, $values) {
db_commit();
$SESSION->add_ok_msg(get_string('viewcreatedsuccessfully', 'view'));
redirect(get_config('wwwroot') . 'view/');
redirect('/view/');
}
function createview4_cancel() {
redirect(get_config('wwwroot') . 'view/');
redirect('/view/');
}
$smarty->assign('titlestr', get_string('createviewstep4', 'view'));
......
......@@ -37,7 +37,7 @@ $view_data = get_record( 'view', 'id', $view_id, 'owner', $USER->get('id'));
if(!$view_data) {
$SESSION->add_error_msg(get_string('canteditdontown', 'view'));
redirect(get_config('wwwroot') . 'view/');
redirect('/view/');
}
$data = array(
......@@ -153,11 +153,11 @@ if (param_boolean('submit')) {
$SESSION->add_ok_msg(get_string('viewinformationsaved', 'view'));
redirect(get_config('wwwroot') . 'view/');
redirect('/view/');
}
if (param_boolean('cancel')) {
redirect(get_config('wwwroot') . 'view/');
redirect('/view/');
}
// Get the list of root things for the tree
......
......@@ -42,7 +42,7 @@ $prefix = get_config('dbprefix');
if (!get_field('view', 'COUNT(*)', 'id', $viewid, 'owner', $USER->get('id'))) {
$SESSION->add_error_msg(get_string('canteditdontown', 'view'));
redirect('view/');
redirect('/view/');
}
$data = get_records_sql_array('SELECT va.accesstype AS type, va.startdate, va.stopdate
FROM ' . $prefix . 'view_access va
......@@ -99,7 +99,7 @@ $form = array(
);
function editviewaccess_cancel_submit() {
redirect('view/');
redirect('/view/');
}
function editviewaccess_submit(Pieform $form, $values) {
......@@ -203,7 +203,7 @@ function editviewaccess_submit(Pieform $form, $values) {
db_commit();
$SESSION->add_ok_msg(get_string('viewaccesseditedsuccessfully'));
redirect('view/');
redirect('/view/');
}
$smarty->assign('titlestr', get_string('editaccess', 'view'));
......
......@@ -61,7 +61,7 @@ $data = get_record(
if(!$data) {
$SESSION->add_error_msg(get_string('canteditdontown', 'view'));
redirect(get_config('wwwroot') . 'view/');
redirect('/view/');
}
$createview1 = pieform(array(
......@@ -124,7 +124,7 @@ $createview1 = pieform(array(
));
function createview1_cancel_submit() {
redirect('view/');
redirect('/view/');
}
function createview1_submit(Pieform $form, $values) {
......@@ -142,7 +142,7 @@ function createview1_submit(Pieform $form, $values) {
update_record('view', $data, (object)array( 'id' => $view_id ));
$SESSION->add_ok_msg(get_string('viewinformationsaved', 'view'));
redirect('view/');
redirect('/view/');
}
$smarty = smarty();
......
......@@ -47,7 +47,7 @@ $viewdata = get_record_sql('
INNER JOIN ' . $prefix . 'community c ON v.submittedto = c.id
WHERE v.id = ' . $viewid, '');
$page = get_config('wwwroot') . 'view/view.php?view=' . $viewid;
$page = '/view/view.php?view=' . $viewid;
require_once('uploadmanager.php');
$um = new upload_manager('attachment');
......@@ -104,6 +104,6 @@ require_once('activity.php');
activity_occurred('feedback', $data);
redirect(get_config('wwwroot') . 'view/view.php?view=' . $viewid);
redirect('/view/view.php?view=' . $viewid);
?>
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