Skip to content

Commit

Permalink
Change and Bug Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewPoppe committed Jun 27, 2024
1 parent 0c945bb commit d17fe42
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 6 deletions.
45 changes: 44 additions & 1 deletion REDCapPRO.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
*/
class REDCapPRO extends AbstractExternalModule
{
const DEFAULT_TIMEOUT_MINUTES = 5;

public $APPTITLE = "REDCapPRO";
public $AUTH;
Expand Down Expand Up @@ -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 "<style>
.swal2-timer-progress-bar {
background: #900000 !important;
}
button.swal2-confirm:focus {
box-shadow: 0 0 0 3px rgb(144 0 0 / 50%) !important;
}
body.swal2-shown > [aria-hidden='true'] {
filter: blur(10px);
}
body > * {
transition: 0.1s filter linear;
}
</style>";

// 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 "<script src='" . $this->getUrl("src/rcpro_base.js", true) . "'></script>";
echo "<script>
window.rcpro.module = " . $this->getJavascriptModuleObjectName() . ";
window.rcpro.logo = '" . $this->getUrl("images/RCPro_Favicon.svg") . "';
window.rcpro.logoutPage = '" . $this->getUrl("src/logout.php", true) . "';
window.rcpro.sessionCheckPage = '" . $this->getUrl("src/session_check.php", true) . "';
window.rcpro.timeout_minutes = " . $settings->getTimeoutMinutes() . ";
window.rcpro.warning_minutes = " . $settings->getTimeoutWarningMinutes() . ";
window.rcpro.initTimeout();
window.rcpro.initSessionCheck();
</script>";
return;
}

Expand Down Expand Up @@ -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 ) {
Expand Down
2 changes: 1 addition & 1 deletion src/classes/Auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions src/classes/ProjectSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
9 changes: 8 additions & 1 deletion src/login.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -21,7 +28,7 @@
}

$auth->deactivate_survey_link();
header("location: ${survey_url}");
header("location: " . $survey_url);
return;
}

Expand Down

0 comments on commit d17fe42

Please sign in to comment.