Skip to content

Commit

Permalink
MDL-30811 core: Replace use of continue_button with redirect
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewnicols committed Feb 29, 2016
1 parent d954b54 commit 372d6b9
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 60 deletions.
20 changes: 2 additions & 18 deletions admin/tool/task/scheduledtasks.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,9 @@

try {
\core\task\manager::configure_scheduled_task($task);
$url = $PAGE->url;
$url->params(array('success'=>get_string('changessaved')));
redirect($url);
redirect($PAGE->url, get_string('changessaved'), null, \core\output\notification::NOTIFY_SUCCESS);
} catch (Exception $e) {
$url = $PAGE->url;
$url->params(array('error'=>$e->getMessage()));
redirect($url);
redirect($PAGE->url, $e->getMessage(), null, \core\output\notification::NOTIFY_ERROR);
}
} else {
echo $OUTPUT->header();
Expand All @@ -104,19 +100,7 @@

} else {
echo $OUTPUT->header();
$error = optional_param('error', '', PARAM_NOTAGS);
if ($error) {
echo $OUTPUT->notification($error, 'notifyerror');
}
$success = optional_param('success', '', PARAM_NOTAGS);
if ($success) {
echo $OUTPUT->notification($success, 'notifysuccess');
}
$tasks = core\task\manager::get_all_scheduled_tasks();
echo $renderer->scheduled_tasks_table($tasks);
echo $OUTPUT->footer();
}




7 changes: 1 addition & 6 deletions admin/user/user_bulk_cohortadd.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,7 @@
unset($allcohorts);

if (count($cohorts) < 2) {
echo $OUTPUT->header();
echo $OUTPUT->heading(get_string('bulkadd', 'core_cohort'));
echo $OUTPUT->notification(get_string('bulknocohort', 'core_cohort'));
echo $OUTPUT->continue_button(new moodle_url('/admin/user/user_bulk.php'));
echo $OUTPUT->footer();
die;
redirect(new moodle_url('/admin/user/user_bulk.php'), get_string('bulknocohort', 'core_cohort'));
}

$countries = get_string_manager()->get_list_of_countries(true);
Expand Down
3 changes: 1 addition & 2 deletions badges/action.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,7 @@
$url = new moodle_url('/badges/action.php', $params);

if (!$badge->has_criteria()) {
echo $OUTPUT->notification(get_string('error:cannotact', 'badges') . get_string('nocriteria', 'badges'));
echo $OUTPUT->continue_button($returnurl);
redirect($returnurl, get_string('error:cannotact', 'badges') . get_string('nocriteria', 'badges'), null, \core\output\notification::NOTIFY_ERROR);
} else {
$message = get_string('reviewconfirm', 'badges', $badge->name);
echo $OUTPUT->confirm($message, $url, $returnurl);
Expand Down
6 changes: 5 additions & 1 deletion lib/weblib.php
Original file line number Diff line number Diff line change
Expand Up @@ -2599,14 +2599,18 @@ function notice ($message, $link='', $course=null) {
* @param string $messagetype The type of notification to show the message in. See constants on \core\output\notification.
* @throws moodle_exception
*/
function redirect($url, $message='', $delay=-1, $messagetype = \core\output\notification::NOTIFY_INFO) {
function redirect($url, $message='', $delay=null, $messagetype = \core\output\notification::NOTIFY_INFO) {
global $OUTPUT, $PAGE, $CFG;

if (CLI_SCRIPT or AJAX_SCRIPT) {
// This is wrong - developers should not use redirect in these scripts but it should not be very likely.
throw new moodle_exception('redirecterrordetected', 'error');
}

if ($delay === null) {
$delay = -1;
}

// Prevent debug errors - make sure context is properly initialised.
if ($PAGE) {
$PAGE->set_context(null);
Expand Down
10 changes: 4 additions & 6 deletions mod/imscp/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,15 @@
$PAGE->set_title($course->shortname.': '.$imscp->name);
$PAGE->set_heading($course->fullname);
$PAGE->set_activity_record($imscp);
echo $OUTPUT->header();
echo $OUTPUT->heading(format_string($imscp->name));

// Verify imsmanifest was parsed properly.
if (!$imscp->structure) {
echo $OUTPUT->notification(get_string('deploymenterror', 'imscp'), 'notifyproblem');
echo $OUTPUT->continue_button(course_get_url($course->id, $cm->section));
echo $OUTPUT->footer();
die;
redirect(course_get_url($course->id, $cm->section), get_string('deploymenterror', 'imscp'));
}

echo $OUTPUT->header();
echo $OUTPUT->heading(format_string($imscp->name));

imscp_print_content($imscp, $cm, $course);

echo $OUTPUT->footer();
6 changes: 1 addition & 5 deletions mod/quiz/report/overview/report.php
Original file line number Diff line number Diff line change
Expand Up @@ -302,11 +302,7 @@ protected function start_regrade($quiz, $cm) {
* @uses exit. This method never returns.
*/
protected function finish_regrade($nexturl) {
global $OUTPUT, $PAGE;
echo $OUTPUT->heading(get_string('regradecomplete', 'quiz_overview'), 3);
echo $OUTPUT->continue_button($nexturl);
echo $OUTPUT->footer();
die();
redirect($nexturl, get_string('regradecomplete', 'quiz_overview'), null, \core\output\notification::NOTIFY_SUCCESS);
}

/**
Expand Down
27 changes: 13 additions & 14 deletions user/emailupdate.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,42 +45,41 @@
$PAGE->set_title(format_string($SITE->fullname) . ": $stremailupdate");
$PAGE->set_heading(format_string($SITE->fullname) . ": $stremailupdate");

echo $OUTPUT->header();

if (empty($preferences['newemailattemptsleft'])) {
redirect("$CFG->wwwroot/user/view.php?id=$user->id");

} else if ($preferences['newemailattemptsleft'] < 1) {
cancel_email_update($user->id);
$stroutofattempts = get_string('auth_outofnewemailupdateattempts', 'auth');
echo $OUTPUT->box($stroutofattempts, 'center');

echo $OUTPUT->header();
echo $OUTPUT->box(get_string('auth_outofnewemailupdateattempts', 'auth'), 'center');
echo $OUTPUT->footer();
} else if ($key == $preferences['newemailkey']) {
$olduser = clone($user);
cancel_email_update($user->id);
$user->email = $preferences['newemail'];

// Detect duplicate before saving.
if ($DB->get_record('user', array('email' => $user->email))) {
$stremailnowexists = get_string('emailnowexists', 'auth');
echo $OUTPUT->box($stremailnowexists, 'center');
echo $OUTPUT->continue_button("$CFG->wwwroot/user/view.php?id=$user->id");
redirect(new moodle_url('/user/view.php', ['id' => $user->id]), get_string('emailnowexists', 'auth'));
} else {
// Update user email.
$authplugin = get_auth_plugin($user->auth);
$authplugin->user_update($olduser, $user);
user_update_user($user, false);
$a->email = $user->email;
$stremailupdatesuccess = get_string('emailupdatesuccess', 'auth', $a);
echo $OUTPUT->box($stremailupdatesuccess, 'center');
echo $OUTPUT->continue_button("$CFG->wwwroot/user/view.php?id=$user->id");
redirect(
new moodle_url('/user/view.php', ['id' => $user->id]),
get_string('emailupdatesuccess', 'auth', $a),
null,
\core\output\notification::NOTIFY_SUCCESS
);
}

} else {
$preferences['newemailattemptsleft']--;
set_user_preference('newemailattemptsleft', $preferences['newemailattemptsleft'], $user->id);
$strinvalidkey = get_string('auth_invalidnewemailkey', 'auth');
echo $OUTPUT->box($strinvalidkey, 'center');
echo $OUTPUT->header();
echo $OUTPUT->box(get_string('auth_invalidnewemailkey', 'auth'), 'center');
echo $OUTPUT->footer();
}

echo $OUTPUT->footer();
16 changes: 8 additions & 8 deletions user/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,12 @@
if ($currentuser) {
if (!is_viewing($coursecontext) && !is_enrolled($coursecontext)) {
// Need to have full access to a course to see the rest of own info.
echo $OUTPUT->header();
echo $OUTPUT->heading(get_string('notenrolled', '', $fullname));
$referer = get_local_referer(false);
if (!empty($referer)) {
echo $OUTPUT->continue_button($referer);
redirect($referer, get_string('notenrolled', '', $fullname));
}
echo $OUTPUT->header();
echo $OUTPUT->heading(get_string('notenrolled', '', $fullname));
echo $OUTPUT->footer();
die;
}
Expand All @@ -136,17 +136,17 @@
// or test for course:inspect capability.
if (has_capability('moodle/role:assign', $coursecontext)) {
$PAGE->navbar->add($fullname);
echo $OUTPUT->header();
echo $OUTPUT->heading(get_string('notenrolled', '', $fullname));
$notice = get_string('notenrolled', '', $fullname);
} else {
echo $OUTPUT->header();
$PAGE->navbar->add($struser);
echo $OUTPUT->heading(get_string('notenrolledprofile'));
$notice = get_string('notenrolledprofile', '', $fullname);
}
$referer = get_local_referer(false);
if (!empty($referer)) {
echo $OUTPUT->continue_button($referer);
redirect($referer, $notice);
}
echo $OUTPUT->header();
echo $OUTPUT->heading($notice);
echo $OUTPUT->footer();
exit;
}
Expand Down

0 comments on commit 372d6b9

Please sign in to comment.