From d17fe42d0e3797195c9b12f0456e431c358bf4b8 Mon Sep 17 00:00:00 2001 From: AndrewPoppe Date: Thu, 27 Jun 2024 14:11:58 -0400 Subject: [PATCH] Change and Bug Fix --- REDCapPRO.php | 45 ++++++++++++++++++++++++++++++++- src/classes/Auth.php | 2 +- src/classes/ProjectSettings.php | 5 ++-- src/login.php | 9 ++++++- 4 files changed, 55 insertions(+), 6 deletions(-) diff --git a/REDCapPRO.php b/REDCapPRO.php index d164624..877b18d 100644 --- a/REDCapPRO.php +++ b/REDCapPRO.php @@ -27,6 +27,7 @@ */ class REDCapPRO extends AbstractExternalModule { + const DEFAULT_TIMEOUT_MINUTES = 5; public $APPTITLE = "REDCapPRO"; public $AUTH; @@ -197,6 +198,47 @@ public function redcap_every_page_top($project_id) // Participant is logged in to their account if ( $auth->is_logged_in() ) { + // Settings + $settings = new ProjectSettings($this); + + // Add inline style + echo ""; + + // Initialize Javascript module object + $this->initializeJavascriptModuleObject(); + + // Transfer language translation keys to Javascript object + $this->tt_transferToJavascriptModuleObject([ + "timeout_message1", + "timeout_message2", + "timeout_button_text" + ]); + + // Add script to control logout of form + echo ""; + echo ""; return; } @@ -1187,7 +1229,8 @@ function validateSettings($settings) if ( isset($settings["timeout-time"]) && $settings["timeout-time"] <= 0 ) { $message = "The timeout time must be a positive number."; } - if ( isset($settings['timeout-time-maximum']) && ($settings['timeout-time-maximum'] < $settings["timeout-time"])) { + $timeoutTime = $settings["timeout-time"] ?? REDCapPRO::DEFAULT_TIMEOUT_MINUTES; + if ( isset($settings['timeout-time-maximum']) && ($settings['timeout-time-maximum'] < $timeoutTime)) { $message = "The timeout time maximum must be greater than or equal to the timeout time."; } if ( isset($settings["password-length"]) && $settings["password-length"] < 8 ) { diff --git a/src/classes/Auth.php b/src/classes/Auth.php index 3fd0f0b..1077b26 100644 --- a/src/classes/Auth.php +++ b/src/classes/Auth.php @@ -91,7 +91,7 @@ public function is_survey_url_set() public function is_survey_link_active() { - return $_SESSION[$this->APPTITLE . "_survey_link_active"]; + return isset($_SESSION[$this->APPTITLE . "_survey_link_active"]); } // GETS diff --git a/src/classes/ProjectSettings.php b/src/classes/ProjectSettings.php index 0339f0f..9326abc 100644 --- a/src/classes/ProjectSettings.php +++ b/src/classes/ProjectSettings.php @@ -34,9 +34,8 @@ public function getMaximumTimeoutMinutes() { } public function getSystemTimeoutMinutes() { - $default = 5; - $setting = (float) $this->module->framework->getSystemSetting("timeout-time"); - return $setting > 0 ? $setting : $default; + $setting = (float) $this->module->framework->getSystemSetting("timeout-time"); + return $setting > 0 ? $setting : REDCapPRO::DEFAULT_TIMEOUT_MINUTES; } public function getProjectTimeoutMinutes($project_id) { diff --git a/src/login.php b/src/login.php index ff2fe24..66a36c7 100644 --- a/src/login.php +++ b/src/login.php @@ -11,6 +11,13 @@ // Login Helper $Login = new LoginHelper($module); +// Make sure survey url is set +if ( !$auth->is_survey_url_set() && isset($_GET['s']) ) { + $url = APP_PATH_SURVEY_FULL . "?s=" . filter_input(INPUT_GET, 's', FILTER_SANITIZE_FULL_SPECIAL_CHARS); + $auth->set_survey_url($url); + $auth->set_survey_active_state(TRUE); +} + // Check if the user is already logged in, if yes then redirect then to the survey if ( $auth->is_logged_in() ) { $survey_url = $auth->get_survey_url(); @@ -21,7 +28,7 @@ } $auth->deactivate_survey_link(); - header("location: ${survey_url}"); + header("location: " . $survey_url); return; }