Skip to content

Commit 955d22b

Browse files
Merge pull request #7248 from christianbeeznest/GH-3201
Exercise: Fix quiz admin redirects, hotspot flow, and flash message translations - refs #3201
2 parents e0df5e0 + b693508 commit 955d22b

4 files changed

Lines changed: 44 additions & 20 deletions

File tree

public/main/exercise/admin.php

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -379,10 +379,16 @@
379379
$htmlHeadXtra[] = '<script src="'.api_get_path(WEB_PATH).'build/libs/select2/js/select2.min.js"></script>';
380380
$htmlHeadXtra[] = '<script>$(function(){ if ($.fn.select2){ $(".ch-select2").select2({width:"100%"}); } });</script>';
381381

382-
if (isset($_GET['message'])) {
383-
if (in_array($_GET['message'], ['ExerciseStored', 'ItemUpdated', 'ItemAdded'])) {
384-
Display::addFlash(Display::return_message(get_lang($_GET['message']), 'confirmation'));
385-
}
382+
$messageMap = [
383+
'ExerciseStored' => 'Exercise stored',
384+
'ItemUpdated' => 'Item updated',
385+
'ItemAdded' => 'Item added',
386+
];
387+
388+
if (isset($_GET['message']) && isset($messageMap[$_GET['message']])) {
389+
Display::addFlash(
390+
Display::return_message(get_lang($messageMap[$_GET['message']]), 'confirmation')
391+
);
386392
}
387393

388394
Display::display_header($nameTools, 'Exercise');
@@ -619,11 +625,16 @@
619625

620626
if (isset($_GET['hotspotadmin'])) {
621627
if (!is_object($objQuestion)) {
622-
$objQuestion = Question::read($_GET['hotspotadmin']);
628+
$objQuestion = Question::read((int) $_GET['hotspotadmin']);
623629
}
624630
if (!$objQuestion) {
625631
api_not_allowed();
626632
}
633+
634+
// If we already processed POST above, don't process it again here (avoid double-save).
635+
$hotspot_skip_processing = !empty($hotspotAlreadyProcessed);
636+
$hotspot_skip_display = false;
637+
627638
require 'hotspot_admin.inc.php';
628639
}
629640

public/main/exercise/hotspot_admin.inc.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
$answerType = $objQuestion->selectType();
2121

2222
$debug = 0;
23+
$hotspot_skip_processing = $hotspot_skip_processing ?? false;
24+
$hotspot_skip_display = $hotspot_skip_display ?? false;
25+
2326

2427
$reponse = $_REQUEST['reponse'] ?? null;
2528
$comment = $_REQUEST['comment'] ?? null;
@@ -76,7 +79,7 @@
7679
$buttonBack = isset($_POST['buttonBack']) ? true : false;
7780
$nbrAnswers = isset($_POST['nbrAnswers']) ? (int) $_POST['nbrAnswers'] : 0;
7881

79-
if ($submitAnswers || $buttonBack) {
82+
if (!$hotspot_skip_processing && ($submitAnswers || $buttonBack)) {
8083
if (in_array($answerType, [HOT_SPOT, HOT_SPOT_COMBINATION])) {
8184
if ($debug > 0) {
8285
echo '$submitAnswers or $buttonBack was set'."<br />\n";
@@ -181,8 +184,7 @@
181184
$editQuestion = $objQuestion->iid;
182185
unset($modifyAnswers);
183186
$redirect = $hotspot_admin_url.'&message=ItemUpdated';
184-
echo '<meta http-equiv="refresh" content="0;url='.htmlspecialchars($redirect, ENT_QUOTES).'">';
185-
echo '<script>top.location.replace("'.addslashes($redirect).'");</script>';
187+
api_location($redirect);
186188
exit;
187189
}
188190

@@ -382,13 +384,16 @@
382384
$editQuestion = $objQuestion->iid;
383385
unset($modifyAnswers);
384386
$redirect = $hotspot_admin_url.'&message=ItemUpdated';
385-
echo '<meta http-equiv="refresh" content="0;url='.htmlspecialchars($redirect, ENT_QUOTES).'">';
386-
echo '<script>top.location.replace("'.addslashes($redirect).'");</script>';
387+
api_location($redirect);
387388
exit;
388389
}
389390
}
390391
}
391392

393+
if ($hotspot_skip_display) {
394+
return;
395+
}
396+
392397
echo Display::page_header(get_lang('Question').': '.$objQuestion->selectTitle());
393398

394399
if (isset($modifyAnswers)) {

public/main/exercise/question_admin.inc.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,15 @@
8080
}
8181

8282
if (in_array($objQuestion->type, [HOT_SPOT, HOT_SPOT_COMBINATION, HOT_SPOT_DELINEATION])) {
83-
echo '<script>window.location.href="admin.php?exerciseId='.$exerciseId.'&page='.$page.'&hotspotadmin='.$objQuestion->id.'&'.api_get_cidreq().'"</script>';
83+
$qid = (int) ($objQuestion->iid ?? 0);
84+
85+
$url = api_get_path(WEB_CODE_PATH).'exercise/admin.php?'
86+
.api_get_cidreq()
87+
.'&exerciseId='.(int) $exerciseId
88+
.'&page='.(int) $page
89+
.'&hotspotadmin='.$qid;
90+
91+
api_location($url);
8492
exit;
8593
}
8694

public/main/inc/lib/exercise.lib.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1641,7 +1641,7 @@ class="window window_left_question window{$questionId}_question">
16411641
$hotspotColor = 0;
16421642
if (HOT_SPOT_DELINEATION != $answerType) {
16431643
$answerList = '
1644-
<div class="p-4 rounded-md border border-gray-25">
1644+
<div class="card p-4 rounded-md border border-gray-25">
16451645
<h5 class="font-bold text-lg mb-2 text-primary">'.get_lang('Image zones').'</h5>
16461646
<ol class="list-decimal ml-6 space-y-2 text-primary">
16471647
';
@@ -1667,13 +1667,13 @@ class="window window_left_question window{$questionId}_question">
16671667
if ($freeze) {
16681668
$relPath = api_get_path(WEB_CODE_PATH);
16691669
echo "
1670+
<div class=\"w-100\">
1671+
$answerList
1672+
</div>
16701673
<div class=\"flex space-x-4\">
1671-
<div class=\"w-3/4\">
1674+
<div class=\"w-100\">
16721675
<div id=\"hotspot-preview-$questionId\" class=\"bg-gray-10 w-full bg-center bg-no-repeat bg-contain border border-gray-25\"></div>
16731676
</div>
1674-
<div class=\"w-1/4\">
1675-
$answerList
1676-
</div>
16771677
</div>
16781678
<script>
16791679
new ".(in_array($answerType, [HOT_SPOT, HOT_SPOT_COMBINATION]) ? "HotspotQuestion" : "DelineationQuestion")."({
@@ -1702,12 +1702,15 @@ class="window window_left_question window{$questionId}_question">
17021702
<input type="hidden" name="hidden_hotspot_id" value="$questionId" />
17031703
<div class="exercise_questions">
17041704
$questionDescription
1705+
<div class="mb-4">
1706+
$answerList
1707+
</div>
17051708
<div class="flex space-x-4">
17061709
HOTSPOT;
17071710
}
17081711

17091712
$relPath = api_get_path(WEB_CODE_PATH);
1710-
$s .= "<div class=\"w-3/4\">
1713+
$s .= "<div>
17111714
<div class=\"hotspot-image bg-gray-10 border border-gray-25 bg-center bg-no-repeat bg-contain\"></div>
17121715
<script>
17131716
$(function() {
@@ -1722,9 +1725,6 @@ class="window window_left_question window{$questionId}_question">
17221725
});
17231726
</script>
17241727
</div>
1725-
<div class=\"w-1/4\">
1726-
$answerList
1727-
</div>
17281728
";
17291729

17301730
echo <<<HOTSPOT

0 commit comments

Comments
 (0)