From b74235619d7377ff01521ae6a753dc89e6f6da64 Mon Sep 17 00:00:00 2001 From: Rohan Sharma Sitoula Date: Mon, 28 Oct 2024 13:38:00 +0530 Subject: [PATCH] Refactor back button hiding logic for SB exams and update plugin version --- classes/local/api/tracker.php | 34 ++++++++++++++++++++++++++++++---- templates/tracker.mustache | 14 -------------- version.php | 4 ++-- 3 files changed, 32 insertions(+), 20 deletions(-) diff --git a/classes/local/api/tracker.php b/classes/local/api/tracker.php index e531bca..e9d40ea 100644 --- a/classes/local/api/tracker.php +++ b/classes/local/api/tracker.php @@ -195,10 +195,36 @@ public static function insert_tracking() if (strpos($PAGE->url, ('mod/quiz/attempt')) && $quizaccess_proctor_setting && $quizaccess_proctor_setting->proctortype == 'noproctor' && - $quizaccess_proctor_setting->tsbenabled && - strpos($_SERVER ['HTTP_USER_AGENT'], "Proview-SB") === FALSE) { - self::redirect_to_wrapper($template, $quiz); - return; + $quizaccess_proctor_setting->tsbenabled + ) { + if(strpos($_SERVER ['HTTP_USER_AGENT'], "Proview-SB") === FALSE){ + self::redirect_to_wrapper($template, $quiz); + return; + } + else{ + $PAGE->requires->js_amd_inline(' + require(["jquery"], function($) { + $(document).ready(function() { + console.log("Document is ready. Checking links..."); + + document.querySelectorAll('a').forEach(link => { + const urlContainsIndex = link.href.includes('mod/quiz/view.php'); + const textContainsBack = link.textContent.trim().toLowerCase().includes('back'); + + if (urlContainsIndex && textContainsBack) { + console.log(`Hiding link: ${link.href} with text: ${link.textContent}`); + // Hide the element by setting its display style to none + link.style.display = 'none'; + } else { + console.log(`Link not hidden: ${link.href} with text: ${link.textContent}`); + } + }); + + console.log("Link checking complete."); + }); + }); + '); + } } if (strpos($PAGE->url, ('mod/quiz/report'))) { diff --git a/templates/tracker.mustache b/templates/tracker.mustache index 542ecf3..61ca94a 100644 --- a/templates/tracker.mustache +++ b/templates/tracker.mustache @@ -97,20 +97,6 @@ }); window.location.href = '{{root_dir}}local/proview/frame.php?'+params.toString(); } - // Hide back Button from quiz if exam is launched in SB Starts - // NOTE: This will only work for English Language due to string matching - if (window.navigator.userAgent.match(/Proview-SB/)) { - console.log("User Agent: ", window.navigator.userAgent); - document.querySelectorAll('a').forEach(link => { - const urlContainsIndex = link.href.includes('moodle/mod/quiz/view.php'); - const textContainsBack = link.textContent.trim().toLowerCase().includes('back'); - if (urlContainsIndex && textContainsBack) { - // Hide the element by setting its display style to none - link.style.display = 'none'; - } - }); - } - // Hide back Button from quiz if exam is launched in SB Starts } if(current.match('mod/quiz/view') ) { if(window.self != window.top && window.parent.previousUrl) { //checking if the request is coming from summary diff --git a/version.php b/version.php index 3b6d79d..a37a61b 100644 --- a/version.php +++ b/version.php @@ -28,9 +28,9 @@ defined('MOODLE_INTERNAL') || die; -$plugin->version = 2024102601; +$plugin->version = 2024102805; $plugin->requires = 2020061500; -$plugin->release = '3.3.7 (Build: 2024102601)'; +$plugin->release = '3.3.7 (Build: 2024102805)'; $plugin->maturity = MATURITY_STABLE; $plugin->component = 'local_proview';