Skip to content

Commit b40d352

Browse files
author
erika
committed
Fix: Delete a course with a post request
Redirecting after deleting the course do not persist the flashes so they're not displayed. Passing a post request keep the flash messages
1 parent a020533 commit b40d352

File tree

1 file changed

+26
-30
lines changed

1 file changed

+26
-30
lines changed

public/main/admin/course_list.php

Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -240,25 +240,24 @@ function get_course_data(
240240
),
241241
$path.'course_copy/create_backup.php?'.api_get_cidreq_params($courseId)
242242
);
243-
$actions[] = Display::url(
244-
Display::getMdiIcon(
245-
ActionIcon::DELETE,
246-
'ch-tool-icon',
247-
null,
248-
ICON_SIZE_SMALL,
249-
get_lang('Delete')
250-
),
251-
$path.'admin/course_list.php?'
252-
.http_build_query([
253-
'delete_course' => $course['col0'],
254-
'sec_token' => Security::getTokenFromSession(),
255-
]),
256-
[
257-
'onclick' => "javascript: if (!confirm('"
258-
.addslashes(api_htmlentities(get_lang('Please confirm your choice'), \ENT_QUOTES))
259-
."')) return false;",
260-
]
261-
);
243+
// Delete course action
244+
$actions[] = '
245+
<form method="post" style="display:inline;" onsubmit="return confirm(\'' .
246+
addslashes(api_htmlentities(get_lang('Please confirm your choice'), \ENT_QUOTES)) .
247+
'\');">
248+
<input type="hidden" name="action" value="delete_course">
249+
<input type="hidden" name="course_code" value="' . $course['col0'] . '">
250+
<input type="hidden" name="sec_token" value="' . Security::getTokenFromSession() . '">
251+
<button type="submit" class="btn btn-link p-0 text-decoration-none cursor-pointer" title="' . get_lang('Delete') . '">
252+
' . Display::getMdiIcon(
253+
ActionIcon::DELETE,
254+
'ch-tool-icon',
255+
null,
256+
ICON_SIZE_SMALL,
257+
get_lang('Delete')
258+
) . '
259+
</button>
260+
</form>';
262261

263262
$em = Database::getManager();
264263
/** @var CatalogueCourseRelAccessUrlRelUsergroupRepository $repo */
@@ -356,7 +355,7 @@ function get_course_visibility_icon(int $visibility): string
356355
};
357356
}
358357

359-
if (isset($_POST['action']) && Security::check_token('get')) {
358+
if (isset($_POST['action']) && Security::check_token('post')) {
360359
// Delete selected courses
361360
if ('delete_courses' == $_POST['action']) {
362361
if (!empty($_POST['course'])) {
@@ -369,7 +368,13 @@ function get_course_visibility_icon(int $visibility): string
369368

370369
Display::addFlash(Display::return_message(get_lang('Deleted')));
371370
}
372-
api_location(api_get_self());
371+
}
372+
373+
if ('delete_course' == $_POST['action']) {
374+
$result = CourseManager::delete_course($_POST['course_code']);
375+
if ($result) {
376+
Display::addFlash(Display::return_message(get_lang('Deleted')));
377+
}
373378
}
374379
}
375380

@@ -463,15 +468,6 @@ function get_course_visibility_icon(int $visibility): string
463468
$content .= $form->returnForm();
464469
} else {
465470
$tool_name = get_lang('Course list');
466-
if (isset($_GET['delete_course']) && Security::check_token('get')) {
467-
$result = CourseManager::delete_course($_GET['delete_course']);
468-
if ($result) {
469-
Display::addFlash(Display::return_message(get_lang('Deleted')));
470-
}
471-
472-
api_location(api_get_self());
473-
}
474-
475471
if (isset($_GET['new_course_id'])) {
476472
$courseId = (int) $_GET['new_course_id'];
477473
$course = api_get_course_entity($courseId);

0 commit comments

Comments
 (0)