Skip to content

Commit eb52692

Browse files
Merge pull request #7246 from christianbeeznest/fixes-updates207
Learnpath: Fix LP add redirect: preserve isStudentView only when in URL
2 parents 4c72f3c + c1dc2aa commit eb52692

1 file changed

Lines changed: 22 additions & 9 deletions

File tree

public/main/lp/lp_add.php

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,22 +36,35 @@ function activate_end_date() {
3636

3737
/* Constants and variables */
3838

39-
$is_allowed_to_edit = api_is_allowed_to_create_course();
40-
$isStudentView = filter_var($_REQUEST['isStudentView'] ?? 'false', FILTER_VALIDATE_BOOLEAN);
4139
$lpId = (int)($_REQUEST['lp_id'] ?? 0);
40+
$is_allowed_to_edit = api_is_allowed_to_edit(false, true, false, false);
41+
42+
// Only treat student view as enabled if it was explicitly passed in the URL.
43+
// This avoids picking it up from cookies/$_REQUEST.
44+
$rawQuery = $_SERVER['QUERY_STRING'] ?? '';
45+
$hasStudentViewInUrl = preg_match('/(?:^|&)isStudentView=/i', $rawQuery) === 1;
46+
$isStudentView = $hasStudentViewInUrl
47+
? filter_var($_GET['isStudentView'] ?? 'false', FILTER_VALIDATE_BOOLEAN)
48+
: false;
4249

4350
if (!$is_allowed_to_edit || $isStudentView) {
4451
$course = api_get_course_entity(api_get_course_int_id());
45-
$nodeId = method_exists($course,'getResourceNode') && $course->getResourceNode()
46-
? (int)$course->getResourceNode()->getId()
52+
$nodeId = method_exists($course, 'getResourceNode') && $course->getResourceNode()
53+
? (int) $course->getResourceNode()->getId()
4754
: 0;
4855

49-
$cid = (int)($_REQUEST['cid'] ?? api_get_course_int_id());
50-
$sid = (int)($_REQUEST['sid'] ?? api_get_session_id());
51-
$qs = ['cid' => $cid, 'isStudentView' => 'true'];
56+
$cid = (int) ($_REQUEST['cid'] ?? api_get_course_int_id());
57+
$sid = (int) ($_REQUEST['sid'] ?? api_get_session_id());
58+
59+
$qs = ['cid' => $cid];
5260
if ($sid > 0) $qs['sid'] = $sid;
53-
if (isset($_REQUEST['gid'])) $qs['gid'] = (int)$_REQUEST['gid'];
54-
if (isset($_REQUEST['gradebook'])) $qs['gradebook'] = (int)$_REQUEST['gradebook'];
61+
if (isset($_REQUEST['gid'])) $qs['gid'] = (int) $_REQUEST['gid'];
62+
if (isset($_REQUEST['gradebook'])) $qs['gradebook'] = (int) $_REQUEST['gradebook'];
63+
64+
// Preserve student view only if it was explicitly requested.
65+
if ($isStudentView) {
66+
$qs['isStudentView'] = 'true';
67+
}
5568

5669
$listUrl = api_get_path(WEB_PATH).'resources/lp/'.$nodeId.'?'.http_build_query($qs);
5770
header('Location: '.$listUrl);

0 commit comments

Comments
 (0)