diff --git a/REDCapPRO.php b/REDCapPRO.php index 131346e..b1b0372 100644 --- a/REDCapPRO.php +++ b/REDCapPRO.php @@ -4,19 +4,17 @@ use ExternalModules\AbstractExternalModule; use ExternalModules\Framework; -use IU\AutoNotifyModule\Settings; - -require_once("src/classes/AjaxHandler.php"); -require_once("src/classes/Auth.php"); -require_once("src/classes/DAG.php"); -require_once("src/classes/Instrument.php"); -require_once("src/classes/ParticipantHelper.php"); -require_once("src/classes/Project.php"); -require_once("src/classes/ProjectHelper.php"); -require_once("src/classes/ProjectSettings.php"); -require_once("src/classes/REDCapProException.php"); -require_once("src/classes/UI.php"); +require_once "src/classes/AjaxHandler.php"; +require_once "src/classes/Auth.php"; +require_once "src/classes/DAG.php"; +require_once "src/classes/Instrument.php"; +require_once "src/classes/ParticipantHelper.php"; +require_once "src/classes/Project.php"; +require_once "src/classes/ProjectHelper.php"; +require_once "src/classes/ProjectSettings.php"; +require_once "src/classes/REDCapProException.php"; +require_once "src/classes/UI.php"; /** * @property Framework $framework * @see Framework @@ -143,7 +141,7 @@ class REDCapPRO extends AbstractExternalModule static $LOGO_URL = "https://i.imgur.com/5Xq2Vqt.png"; static $LOGO_ALTERNATE_URL = "https://i.imgur.com/fu0t8V1.png"; - function __construct() + public function __construct() { parent::__construct(); $this->AUTH = new Auth($this->APPTITLE); @@ -184,14 +182,16 @@ public function redcap_survey_page_top( ) { // Initialize Authentication - if ( isset($record) ) \Session::savecookie("record", $record, 0, TRUE); + if ( isset($record) ) { + \Session::savecookie("record", $record, 0, true); + } $this->AUTH->init(); // Participant is logged in to their account if ( $this->AUTH->is_logged_in() ) { // Get RCPRO project ID - $rcpro_project_id = $this->PARTICIPANT->getProjectIdFromPID($project_id); + $rcpro_project_id = $this->PROJECT->getProjectIdFromPID($project_id); // Settings $settings = new ProjectSettings($this); @@ -223,7 +223,7 @@ public function redcap_survey_page_top( // Determine whether participant is in the appropriate DAG if ( isset($group_id) ) { - $rcpro_link_id = $this->PARTICIPANT->getLinkId($rcpro_participant_id, $rcpro_project_id); + $rcpro_link_id = $this->PROJECT->getLinkId($rcpro_participant_id, $rcpro_project_id); $rcpro_dag = $this->DAG->getParticipantDag($rcpro_link_id); if ( $group_id !== $rcpro_dag ) { @@ -328,14 +328,14 @@ public function redcap_survey_page_top( public function redcap_data_entry_form($project_id, $record, $instrument, $event_id, $group_id, $repeat_instance = 1) { - $role = SUPER_USER ? 3 : $this->getUserRole(USERID); // 3=admin/manager, 2=user, 1=monitor, 0=not found + $role = $this->getUserRole($this->framework->getUser()->getUsername()); // 3=admin/manager, 2=user, 1=monitor, 0=not found if ( $role < 2 ) { return; } echo ' '; - $rcpro_dag = $this->DAG->getCurrentDag(USERID, $project_id); + $rcpro_dag = $this->DAG->getCurrentDag($this->framework->getUser()->getUsername(), $project_id); $instrument = new Instrument($this, $instrument, $rcpro_dag); $instrument->update_form(); } @@ -353,14 +353,14 @@ public function redcap_data_entry_form($project_id, $record, $instrument, $event */ public function redcap_module_project_enable($version, $pid) { - if ( !$this->PARTICIPANT->checkProject($pid) ) { - $this->PARTICIPANT->addProject($pid); + if ( !$this->PROJECT->checkProject($pid) ) { + $this->PROJECT->addProject($pid); } else { - $this->PARTICIPANT->setProjectActive($pid, 1); + $this->PROJECT->setProjectActive($pid, 1); } - $this->changeUserRole(USERID, NULL, 3); + $this->changeUserRole($this->framework->getUser()->getUsername(), NULL, 3); $this->logEvent("Module Enabled", [ - "redcap_user" => USERID, + "redcap_user" => $this->framework->getUser()->getUsername(), "version" => $version ]); } @@ -375,9 +375,9 @@ public function redcap_module_project_enable($version, $pid) */ public function redcap_module_project_disable($version, $project_id) { - $this->PARTICIPANT->setProjectActive($project_id, 0); + $this->PROJECT->setProjectActive($project_id, 0); $this->logEvent("Module Disabled", [ - "redcap_user" => USERID, + "redcap_user" => $this->framework->getUser()->getUsername(), "version" => $version ]); } @@ -392,7 +392,7 @@ public function redcap_module_project_disable($version, $project_id) public function redcap_module_system_enable($version) { $this->logEvent("Module Enabled - System", [ - "redcap_user" => USERID, + "redcap_user" => $this->framework->getUser()->getUsername(), "version" => $version ]); } @@ -407,7 +407,7 @@ public function redcap_module_system_enable($version) public function redcap_module_system_disable($version) { $this->logEvent("Module Disabled - System", [ - "redcap_user" => USERID, + "redcap_user" => $this->framework->getUser()->getUsername(), "version" => $version ]); } @@ -422,15 +422,16 @@ public function redcap_module_system_disable($version) * @return bool */ - public function redcap_module_configure_button_display() + public function redcap_module_configure_button_display() { // Hide module configuration button in project context. return $this->getProjectId() === null; } - public function redcap_module_link_check_display($project_id, $link) { - $role = SUPER_USER ? 3 : $this->getUserRole(USERID); // 3=admin/manager, 2=user, 1=monitor, 0=not found + public function redcap_module_link_check_display($project_id, $link) + { + $role = $this->getUserRole($this->framework->getUser()->getUsername()); // 3=admin/manager, 2=user, 1=monitor, 0=not found if ( $role > 0 ) { return $link; } @@ -442,7 +443,7 @@ public function redcap_module_system_change_version($version, $old_version) $this->logEvent("Module Version Changed", [ "version" => $version, "old_version" => $old_version, - "redcap_user" => USERID + "redcap_user" => $this->framework->getUser()->getUsername() ]); $new_version_number = explode('v', $version)[1]; @@ -482,8 +483,8 @@ public function createEmailLink(string $email, ?string $subject) $username = $this->AUTH->get_username(); $body .= $this->tt("email_inquiry_username", $username) . "\n"; } - if ( PROJECT_ID ) { - $body .= $this->tt("email_inquiry_project_id", PROJECT_ID) . "\n"; + if ( $this->framework->getProjectId() ) { + $body .= $this->tt("email_inquiry_project_id", $this->framework->getProjectId()) . "\n"; $body .= $this->tt("email_inquiry_project_title", \REDCap::getProjectTitle()); } $link = "mailto:${email}?subject=" . rawurlencode($subject) . "&body=" . rawurlencode($body); @@ -534,7 +535,7 @@ public function sendEmailUpdateEmail(string $username, string $new_email, string
"; $body .= "" . $this->tt("email_update_message2") . "";
- if ( defined("PROJECT_ID") ) {
+ if ( $this->framework->getProjectId() ) {
$study_contact = $this->getContactPerson($this->tt("email_update_subject"));
if ( isset($study_contact["info"]) ) {
$body .= "
" . $study_contact["info"];
@@ -588,7 +589,7 @@ public function sendNewParticipantEmail(string $username, string $email, string
" . $this->tt("email_new_participant_message6", $hours_valid) . "
" . $this->tt("email_new_participant_message7");
- if ( defined("PROJECT_ID") ) {
+ if ( $this->framework->getProjectId() ) {
$study_contact = $this->getContactPerson($subject);
if ( isset($study_contact["info"]) ) {
$body .= "
" . $study_contact["info"];
@@ -607,7 +608,7 @@ public function sendNewParticipantEmail(string $username, string $email, string
*
* @param mixed $rcpro_participant_id
*
- * @return void
+ * @return mixed
*/
public function sendPasswordResetEmail($rcpro_participant_id)
{
@@ -635,7 +636,7 @@ public function sendPasswordResetEmail($rcpro_participant_id)
" . $this->tt("email_password_reset_message5") . "" . $this->tt("email_password_reset_link_text") . "
" . $this->tt("email_password_reset_message6");
- if ( defined("PROJECT_ID") ) {
+ if ( $this->framework->getProjectId() ) {
$study_contact = $this->getContactPerson($subject);
if ( isset($study_contact["info"]) ) {
$body .= "
" . $study_contact["info"];
@@ -656,7 +657,7 @@ public function sendPasswordResetEmail($rcpro_participant_id)
"rcpro_participant_id" => $rcpro_participant_id,
"rcpro_username" => $username_clean,
"rcpro_email" => $to,
- "redcap_user" => USERID,
+ "redcap_user" => $this->framework->getUser()->getUsername(),
"project_id" => $project_id,
"initiating_project_id" => $current_pid
]);
@@ -665,7 +666,7 @@ public function sendPasswordResetEmail($rcpro_participant_id)
} catch ( \Exception $e ) {
$this->logEvent("Password Reset Failed", [
"rcpro_participant_id" => $rcpro_participant_id,
- "redcap_user" => USERID
+ "redcap_user" => $this->framework->getUser()->getUsername()
]);
$this->logError("Error sending password reset email", $e);
}
@@ -695,7 +696,7 @@ public function sendUsernameEmail(string $email, string $username)
" . $this->tt("email_username_message3") . "
";
$body .= $this->tt("email_username_message4");
- if ( defined("PROJECT_ID") ) {
+ if ( $this->framework->getProjectId() ) {
$study_contact = $this->getContactPerson($subject);
if ( isset($study_contact["info"]) ) {
$body .= "
" . $study_contact["info"];
@@ -752,7 +753,7 @@ public function changeUserRole(string $username, ?string $oldRole, string $newRo
$this->setProjectSetting("monitors", $roles["1"]);
$this->logEvent("Changed user role", [
- "redcap_user" => USERID,
+ "redcap_user" => $this->framework->getUser()->getUsername(),
"redcap_user_acted_upon" => $username,
"old_role" => $oldRole,
"new_role" => $newRole
@@ -788,6 +789,10 @@ public function getUserFullname(string $username)
*/
public function getUserRole(string $username)
{
+
+ if ( $this->framework->getUser($username)->isSuperUser() ) {
+ return 3;
+ }
// FIX: PHP 8 fix
$managers = $this->getProjectSetting("managers") ?? array( '' );
$users = $this->getProjectSetting("users") ?? array( '' );
@@ -797,9 +802,9 @@ public function getUserRole(string $username)
if ( in_array($username, $managers) ) {
$result = 3;
- } else if ( in_array($username, $users) ) {
+ } elseif ( in_array($username, $users) ) {
$result = 2;
- } else if ( in_array($username, $monitors) ) {
+ } elseif ( in_array($username, $monitors) ) {
$result = 1;
}
@@ -816,7 +821,7 @@ public function getUserRole(string $username)
*
* @return [array]
*/
- function getAllUsers()
+ public function getAllUsers()
{
global $module;
$projects = $module->getProjectsWithModuleEnabled();
@@ -859,7 +864,7 @@ public function logError(string $message, \Throwable $e)
"error_file" => $e->getFile(),
"error_line" => $e->getLine(),
"error_string" => $e->__toString(),
- "redcap_user" => USERID,
+ "redcap_user" => $this->framework->getUser()->getUsername(),
"module_token" => $this->getModuleToken()
];
if ( isset($e->rcpro) ) {
@@ -885,7 +890,7 @@ public function logForm(string $message, $parameters)
$logParametersString = json_encode($logParameters);
$this->logEvent($message, [
"parameters" => $logParametersString,
- "redcap_user" => USERID,
+ "redcap_user" => $this->framework->getUser()->getUsername(),
"module_token" => $this->getModuleToken()
]);
}
@@ -1025,7 +1030,7 @@ function validateSettings($settings)
$logParameters = json_encode($settings);
$this->logEvent("Configuration Saved", [
"parameters" => $logParameters,
- "redcap_user" => USERID,
+ "redcap_user" => $this->framework->getUser()->getUsername(),
"message" => $message,
"success" => is_null($message)
]);
diff --git a/src/classes/Instrument.php b/src/classes/Instrument.php
index e795669..a595032 100644
--- a/src/classes/Instrument.php
+++ b/src/classes/Instrument.php
@@ -4,7 +4,7 @@
class Instrument
{
- public $module;
+ public REDCapPRO $module;
public $instrument_name;
public $rcpro_dag;
public $dd;
@@ -15,12 +15,12 @@ class Instrument
function __construct($module, $instrument_name, $rcpro_dag)
{
- $this->module = $module;
+ $this->module = $module;
$this->instrument_name = $instrument_name;
- $this->rcpro_dag = $rcpro_dag;
- $this->dd = $this->getDD();
- $this->username = $this->getUsernameField();
- if (isset($this->username)) {
+ $this->rcpro_dag = $rcpro_dag;
+ $this->dd = $this->getDD();
+ $this->username = $this->getUsernameField();
+ if ( isset($this->username) ) {
$this->email = $this->getEmailField();
$this->fname = $this->getFirstNameField();
$this->lname = $this->getLastNameField();
@@ -29,13 +29,13 @@ function __construct($module, $instrument_name, $rcpro_dag)
function getDD()
{
- $json = \REDCap::getDataDictionary("json", false, null, [$this->instrument_name], false);
+ $json = \REDCap::getDataDictionary("json", false, null, [ $this->instrument_name ], false);
return json_decode($json, true);
}
function getUsernameField()
{
- foreach ($this->dd as $field) {
+ foreach ( $this->dd as $field ) {
if (
strpos($field["field_annotation"], "@RCPRO-USERNAME") !== FALSE
&& $field["field_type"] === "text"
@@ -47,7 +47,7 @@ function getUsernameField()
function getEmailField()
{
- foreach ($this->dd as $field) {
+ foreach ( $this->dd as $field ) {
if (
strpos($field["field_annotation"], "@RCPRO-EMAIL") !== FALSE
&& $field["field_type"] === "text"
@@ -60,7 +60,7 @@ function getEmailField()
function getFirstNameField()
{
- foreach ($this->dd as $field) {
+ foreach ( $this->dd as $field ) {
if (
strpos($field["field_annotation"], "@RCPRO-FNAME") !== FALSE
&& $field["field_type"] === "text"
@@ -72,7 +72,7 @@ function getFirstNameField()
function getLastNameField()
{
- foreach ($this->dd as $field) {
+ foreach ( $this->dd as $field ) {
if (
strpos($field["field_annotation"], "@RCPRO-LNAME") !== FALSE
&& $field["field_type"] === "text"
@@ -84,23 +84,23 @@ function getLastNameField()
function update_form()
{
- if (isset($this->username)) {
- $rcpro_project_id = $this->module->PARTICIPANT->getProjectIdFromPID(PROJECT_ID);
- $participants = $this->module->PARTICIPANT->getProjectParticipants($rcpro_project_id, $this->rcpro_dag);
- $options = "";
+ if ( isset($this->username) ) {
+ $rcpro_project_id = $this->module->PARTICIPANT->getProjectIdFromPID($this->framework->getProjectId());
+ $participants = $this->module->PARTICIPANT->getProjectParticipants($rcpro_project_id, $this->rcpro_dag);
+ $options = "";
$participants_json = json_encode($participants);
- foreach ($participants as $participant) {
+ foreach ( $participants as $participant ) {
$inst_username = \REDCap::escapeHtml($participant["rcpro_username"]);
$inst_email = \REDCap::escapeHtml($participant["email"]);
$inst_fname = \REDCap::escapeHtml($participant["fname"]);
$inst_lname = \REDCap::escapeHtml($participant["lname"]);
- $options .= "";
+ $options .= "";
}
- $replacement = "";
+ $replacement = "";
$this->module->initializeJavascriptModuleObject();
-?>
+ ?>
-getEmail($rcpro_participant_id);
- $SQL = "UPDATE redcap_external_modules_log_parameters SET value = ? WHERE log_id = ? AND name = 'email'";
+ $SQL = "UPDATE redcap_external_modules_log_parameters SET value = ? WHERE log_id = ? AND name = 'email'";
try {
- $result = $this->module->query($SQL, [$new_email, $rcpro_participant_id]);
- if ($result) {
+ $result = $this->module->query($SQL, [ $new_email, $rcpro_participant_id ]);
+ if ( $result ) {
$username = $this->getUserName($rcpro_participant_id);
@@ -39,41 +39,41 @@ public function changeEmailAddress(int $rcpro_participant_id, string $new_email)
// Get all projects to which participant is currently enrolled
$project_ids = $this->getEnrolledProjects($rcpro_participant_id);
- foreach ($project_ids as $project_id) {
+ foreach ( $project_ids as $project_id ) {
$this->module->logEvent("Changed Email Address", [
- "rcpro_participant_id" => $rcpro_participant_id,
- "rcpro_username" => $username,
- "old_email" => $current_email,
- "new_email" => $new_email,
- "redcap_user" => USERID,
- "project_id" => $project_id,
+ "rcpro_participant_id" => $rcpro_participant_id,
+ "rcpro_username" => $username,
+ "old_email" => $current_email,
+ "new_email" => $new_email,
+ "redcap_user" => $this->module->framework->getUser()->getUsername(),
+ "project_id" => $project_id,
"initiating_project_id" => $current_pid
]);
}
return $this->module->sendEmailUpdateEmail($username, $new_email, $current_email);
} else {
- throw new REDCapProException(["rcpro_participant_id" => $rcpro_participant_id]);
+ throw new REDCapProException([ "rcpro_participant_id" => $rcpro_participant_id ]);
}
- } catch (\Exception $e) {
+ } catch ( \Exception $e ) {
$this->module->logError("Error changing email address", $e);
}
}
public function changeName(int $rcpro_participant_id, $fname, $lname)
{
- $SQL1 = "UPDATE redcap_external_modules_log_parameters SET value = ? WHERE log_id = ? AND name = 'fname'";
- $SQL2 = "UPDATE redcap_external_modules_log_parameters SET value = ? WHERE log_id = ? AND name = 'lname'";
+ $SQL1 = "UPDATE redcap_external_modules_log_parameters SET value = ? WHERE log_id = ? AND name = 'fname'";
+ $SQL2 = "UPDATE redcap_external_modules_log_parameters SET value = ? WHERE log_id = ? AND name = 'lname'";
$participant = $this->getParticipant($this->getUserName($rcpro_participant_id));
try {
- $result1 = $this->module->query($SQL1, [$fname, $rcpro_participant_id]);
- if (!$result1) {
- throw new REDCapProException(["rcpro_participant_id" => $rcpro_participant_id]);
+ $result1 = $this->module->query($SQL1, [ $fname, $rcpro_participant_id ]);
+ if ( !$result1 ) {
+ throw new REDCapProException([ "rcpro_participant_id" => $rcpro_participant_id ]);
}
- $result2 = $this->module->query($SQL2, [$lname, $rcpro_participant_id]);
- if (!$result2) {
- throw new REDCapProException(["rcpro_participant_id" => $rcpro_participant_id]);
+ $result2 = $this->module->query($SQL2, [ $lname, $rcpro_participant_id ]);
+ if ( !$result2 ) {
+ throw new REDCapProException([ "rcpro_participant_id" => $rcpro_participant_id ]);
}
// Get current project (or "system" if initiated in the control center)
@@ -81,19 +81,19 @@ public function changeName(int $rcpro_participant_id, $fname, $lname)
// Get all projects to which participant is currently enrolled
$project_ids = $this->getEnrolledProjects($rcpro_participant_id);
- foreach ($project_ids as $project_id) {
+ foreach ( $project_ids as $project_id ) {
$this->module->logEvent("Updated Participant Name", [
"rcpro_participant_id" => $rcpro_participant_id,
"rcpro_username" => $participant["rcpro_username"],
"old_name" => $participant["fname"] . " " . $participant["lname"],
"new_name" => $fname . " " . $lname,
- "redcap_user" => USERID,
+ "redcap_user" => $this->module->framework->getUser()->getUsername(),
"project_id" => $project_id,
"initiating_project_id" => $current_pid
]);
}
return $result1 && $result2;
- } catch (\Exception $e) {
+ } catch ( \Exception $e ) {
$this->module->logError("Error updating participant's name", $e);
}
}
@@ -109,9 +109,9 @@ public function checkEmailExists(string $email)
{
$SQL = "message = 'PARTICIPANT' AND email = ? AND (project_id IS NULL OR project_id IS NOT NULL)";
try {
- $result = $this->module->countLogsValidated($SQL, [$email]);
+ $result = $this->module->countLogsValidated($SQL, [ $email ]);
return $result > 0;
- } catch (\Exception $e) {
+ } catch ( \Exception $e ) {
$this->module->logError("Error checking if email exists", $e);
}
}
@@ -129,9 +129,9 @@ public function checkParticipantExists($rcpro_participant_id)
{
$SQL = "log_id = ? AND message = 'PARTICIPANT' AND (project_id IS NULL OR project_id IS NOT NULL)";
try {
- $res = $this->module->countLogsValidated($SQL, [$rcpro_participant_id]);
+ $res = $this->module->countLogsValidated($SQL, [ $rcpro_participant_id ]);
return $res > 0;
- } catch (\Exception $e) {
+ } catch ( \Exception $e ) {
$this->module->logError("Error checking whether participant exists", $e);
}
}
@@ -155,11 +155,11 @@ public function createParticipant(string $email, string $fname, string $lname)
$lname_clean = \REDCap::escapeHtml($lname);
$counter = 0;
$counterLimit = 90000000;
- while ($this->usernameIsTaken($username) && $counter < $counterLimit) {
+ while ( $this->usernameIsTaken($username) && $counter < $counterLimit ) {
$username = $this->createUsername();
$counter++;
}
- if ($counter >= $counterLimit) {
+ if ( $counter >= $counterLimit ) {
echo "Please contact your REDCap administrator.";
return NULL;
}
@@ -176,19 +176,19 @@ public function createParticipant(string $email, string $fname, string $lname)
"token" => "",
"token_ts" => time(),
"token_valid" => 0,
- "redcap_user" => USERID,
+ "redcap_user" => $this->module->framework->getUser()->getUsername(),
"active" => 1
]);
- if (!$id) {
- throw new REDCapProException(["rcpro_username" => $username]);
+ if ( !$id ) {
+ throw new REDCapProException([ "rcpro_username" => $username ]);
}
$this->module->logEvent("Participant Created", [
"rcpro_user_id" => $id,
"rcpro_username" => $username,
- "redcap_user" => USERID
+ "redcap_user" => $this->module->framework->getUser()->getUsername()
]);
return $username;
- } catch (\Exception $e) {
+ } catch ( \Exception $e ) {
$this->module->logError("Participant Creation Failed", $e);
}
}
@@ -203,20 +203,20 @@ public function createParticipant(string $email, string $fname, string $lname)
*/
public function createResetToken($rcpro_participant_id, int $hours_valid = 1)
{
- $token = bin2hex(random_bytes(32));
+ $token = bin2hex(random_bytes(32));
$token_ts = time() + ($hours_valid * 60 * 60);
- $SQL1 = "UPDATE redcap_external_modules_log_parameters SET value = ? WHERE log_id = ? AND name = 'token'";
- $SQL2 = "UPDATE redcap_external_modules_log_parameters SET value = ? WHERE log_id = ? AND name = 'token_ts'";
- $SQL3 = "UPDATE redcap_external_modules_log_parameters SET value = 1 WHERE log_id = ? AND name = 'token_valid'";
+ $SQL1 = "UPDATE redcap_external_modules_log_parameters SET value = ? WHERE log_id = ? AND name = 'token'";
+ $SQL2 = "UPDATE redcap_external_modules_log_parameters SET value = ? WHERE log_id = ? AND name = 'token_ts'";
+ $SQL3 = "UPDATE redcap_external_modules_log_parameters SET value = 1 WHERE log_id = ? AND name = 'token_valid'";
try {
- $result1 = $this->module->query($SQL1, [$token, $rcpro_participant_id]);
- $result2 = $this->module->query($SQL2, [$token_ts, $rcpro_participant_id]);
- $result3 = $this->module->query($SQL3, [$rcpro_participant_id]);
- if (!$result1 || !$result2 || !$result3) {
- throw new REDCapProException(["rcpro_participant_id" => $rcpro_participant_id]);
+ $result1 = $this->module->query($SQL1, [ $token, $rcpro_participant_id ]);
+ $result2 = $this->module->query($SQL2, [ $token_ts, $rcpro_participant_id ]);
+ $result3 = $this->module->query($SQL3, [ $rcpro_participant_id ]);
+ if ( !$result1 || !$result2 || !$result3 ) {
+ throw new REDCapProException([ "rcpro_participant_id" => $rcpro_participant_id ]);
}
return $token;
- } catch (\Exception $e) {
+ } catch ( \Exception $e ) {
$this->module->logError("Error creating reset token", $e);
}
}
@@ -271,9 +271,9 @@ public function enrolledInProject(int $rcpro_participant_id, int $rcpro_project_
{
$SQL = "message = 'LINK' AND rcpro_project_id = ? AND rcpro_participant_id = ? AND active = 1 AND (project_id IS NULL OR project_id IS NOT NULL)";
try {
- $result = $this->module->countLogsValidated($SQL, [$rcpro_project_id, $rcpro_participant_id]);
+ $result = $this->module->countLogsValidated($SQL, [ $rcpro_project_id, $rcpro_participant_id ]);
return $result > 0;
- } catch (\Exception $e) {
+ } catch ( \Exception $e ) {
$this->module->logError("Error checking that participant is enrolled", $e);
}
}
@@ -289,8 +289,8 @@ public function expirePasswordResetToken($rcpro_participant_id)
{
$SQL = "UPDATE redcap_external_modules_log_parameters SET value = 0 WHERE log_id = ? AND name = 'token_valid'";
try {
- return $this->module->query($SQL, [$rcpro_participant_id]);
- } catch (\Exception $e) {
+ return $this->module->query($SQL, [ $rcpro_participant_id ]);
+ } catch ( \Exception $e ) {
$this->module->logError("Error expiring password reset token.", $e);
}
}
@@ -304,17 +304,17 @@ public function getAllParticipants()
{
$SQL = "SELECT log_id, rcpro_username, email, fname, lname, lockout_ts, pw, active WHERE message = 'PARTICIPANT' AND rcpro_username IS NOT NULL AND (project_id IS NULL OR project_id IS NOT NULL)";
try {
- $result = $this->module->selectLogs($SQL, []);
- $participants = array();
+ $result = $this->module->selectLogs($SQL, []);
+ $participants = array();
// grab participant details
- while ($row = $result->fetch_assoc()) {
+ while ( $row = $result->fetch_assoc() ) {
$row["pw_set"] = (!isset($row["pw"]) || $row["pw"] === "") ? "False" : "True";
unset($row["pw"]);
$participants[$row["log_id"]] = $row;
}
return $participants;
- } catch (\Exception $e) {
+ } catch ( \Exception $e ) {
$this->module->logError("Error fetching participants", $e);
}
}
@@ -330,9 +330,9 @@ public function getEmail(int $rcpro_participant_id)
{
$SQL = "SELECT email WHERE message = 'PARTICIPANT' AND log_id = ? AND (project_id IS NULL OR project_id IS NOT NULL)";
try {
- $result = $this->module->selectLogs($SQL, [$rcpro_participant_id]);
+ $result = $this->module->selectLogs($SQL, [ $rcpro_participant_id ]);
return $result->fetch_assoc()["email"];
- } catch (\Exception $e) {
+ } catch ( \Exception $e ) {
$this->module->logError("Error fetching email address", $e);
}
}
@@ -350,16 +350,16 @@ public function getEnrolledProjects(int $rcpro_participant_id)
{
$SQL = "SELECT project_id WHERE message = 'LINK' AND rcpro_participant_id = ? AND (project_id IS NULL OR project_id IS NOT NULL)";
try {
- $result = $this->module->selectLogs($SQL, [$rcpro_participant_id]);
+ $result = $this->module->selectLogs($SQL, [ $rcpro_participant_id ]);
$project_ids = array();
- while ($row = $result->fetch_assoc()) {
+ while ( $row = $result->fetch_assoc() ) {
array_push($project_ids, $row["project_id"]);
}
- if (count($project_ids) === 0) {
+ if ( count($project_ids) === 0 ) {
array_push($project_ids, NULL);
}
return $project_ids;
- } catch (\Exception $e) {
+ } catch ( \Exception $e ) {
$this->module->logError("Error fetching enrolled projects", $e);
}
}
@@ -373,14 +373,14 @@ public function getEnrolledProjects(int $rcpro_participant_id)
*/
public function getParticipant(string $username)
{
- if ($username === NULL) {
+ if ( $username === NULL ) {
return NULL;
}
$SQL = "SELECT log_id, rcpro_username, email, fname, lname, active WHERE message = 'PARTICIPANT' AND rcpro_username = ? AND (project_id IS NULL OR project_id IS NOT NULL)";
try {
- $result = $this->module->selectLogs($SQL, [$username]);
+ $result = $this->module->selectLogs($SQL, [ $username ]);
return $result->fetch_assoc();
- } catch (\Exception $e) {
+ } catch ( \Exception $e ) {
$this->module->logError("Error fetching participant information", $e);
}
}
@@ -394,14 +394,14 @@ public function getParticipant(string $username)
*/
public function getParticipantFromEmail(string $email)
{
- if ($email === NULL) {
+ if ( $email === NULL ) {
return NULL;
}
$SQL = "SELECT log_id, rcpro_username, email, fname, lname, active WHERE message = 'PARTICIPANT' AND email = ? AND (project_id IS NULL OR project_id IS NOT NULL)";
try {
- $result = $this->module->selectLogs($SQL, [$email]);
+ $result = $this->module->selectLogs($SQL, [ $email ]);
return $result->fetch_assoc();
- } catch (\Exception $e) {
+ } catch ( \Exception $e ) {
$this->module->logError("Error fetching participant information", $e);
}
}
@@ -417,9 +417,9 @@ public function getParticipantIdFromEmail(string $email)
{
$SQL = "SELECT log_id WHERE message = 'PARTICIPANT' AND email = ? AND (project_id IS NULL OR project_id IS NOT NULL)";
try {
- $result = $this->module->selectLogs($SQL, [$email]);
+ $result = $this->module->selectLogs($SQL, [ $email ]);
return $result->fetch_assoc()["log_id"];
- } catch (\Exception $e) {
+ } catch ( \Exception $e ) {
$this->module->logError("Error fetching id from email", $e);
}
}
@@ -435,9 +435,9 @@ public function getParticipantIdFromUsername(string $username)
{
$SQL = "SELECT log_id WHERE message = 'PARTICIPANT' AND rcpro_username = ? AND (project_id IS NULL OR project_id IS NOT NULL)";
try {
- $result = $this->module->selectLogs($SQL, [$username]);
+ $result = $this->module->selectLogs($SQL, [ $username ]);
return $result->fetch_assoc()["log_id"];
- } catch (\Exception $e) {
+ } catch ( \Exception $e ) {
$this->module->logError("Error fetching id from username", $e);
}
}
@@ -453,9 +453,9 @@ public function getParticipantInfo(int $rcpro_participant_id)
{
$SQL = "SELECT log_id AS 'User_ID', rcpro_username AS Username, timestamp AS 'Registered At', redcap_user AS 'Registered By' WHERE log_id = ? AND (project_id IS NULL OR project_id IS NOT NULL)";
try {
- $result_obj = $this->module->selectLogs($SQL, [$rcpro_participant_id]);
+ $result_obj = $this->module->selectLogs($SQL, [ $rcpro_participant_id ]);
return $result_obj->fetch_assoc();
- } catch (\Exception $e) {
+ } catch ( \Exception $e ) {
$this->module->logError("Error getting participant info", $e);
}
}
@@ -471,18 +471,18 @@ public function getParticipantInfo(int $rcpro_participant_id)
*/
public function getParticipantProjects(int $rcpro_participant_id)
{
- $SQL1 = "SELECT rcpro_project_id, active WHERE rcpro_participant_id = ? AND message = 'LINK' AND (project_id IS NULL OR project_id IS NOT NULL)";
- $SQL2 = "SELECT pid WHERE log_id = ? AND message = 'PROJECT' AND (project_id IS NULL OR project_id IS NOT NULL)";
+ $SQL1 = "SELECT rcpro_project_id, active WHERE rcpro_participant_id = ? AND message = 'LINK' AND (project_id IS NULL OR project_id IS NOT NULL)";
+ $SQL2 = "SELECT pid WHERE log_id = ? AND message = 'PROJECT' AND (project_id IS NULL OR project_id IS NOT NULL)";
$projects = array();
try {
- $result1 = $this->module->selectLogs($SQL1, [$rcpro_participant_id]);
- if (!$result1) {
- throw new REDCapProException(["rcpro_participant_id" => $rcpro_participant_id]);
+ $result1 = $this->module->selectLogs($SQL1, [ $rcpro_participant_id ]);
+ if ( !$result1 ) {
+ throw new REDCapProException([ "rcpro_participant_id" => $rcpro_participant_id ]);
}
- while ($row = $result1->fetch_assoc()) {
+ while ( $row = $result1->fetch_assoc() ) {
$rcpro_project_id = $row["rcpro_project_id"];
- $result2 = $this->module->selectLogs($SQL2, [$rcpro_project_id]);
- $redcap_pid = $result2->fetch_assoc()["pid"];
+ $result2 = $this->module->selectLogs($SQL2, [ $rcpro_project_id ]);
+ $redcap_pid = $result2->fetch_assoc()["pid"];
array_push($projects, [
"rcpro_project_id" => $rcpro_project_id,
"active" => $row["active"],
@@ -490,7 +490,7 @@ public function getParticipantProjects(int $rcpro_participant_id)
]);
}
return $projects;
- } catch (\Exception $e) {
+ } catch ( \Exception $e ) {
$this->module->logError("Error fetching participant's projects", $e);
}
}
@@ -505,26 +505,26 @@ public function getParticipantProjects(int $rcpro_participant_id)
*/
public function getProjectParticipants(string $rcpro_project_id, ?int $dag = NULL)
{
- $SQL = "SELECT rcpro_participant_id WHERE message = 'LINK' AND rcpro_project_id = ? AND active = 1 AND (project_id IS NULL OR project_id IS NOT NULL)";
- $PARAMS = [$rcpro_project_id];
- if (isset($dag)) {
+ $SQL = "SELECT rcpro_participant_id WHERE message = 'LINK' AND rcpro_project_id = ? AND active = 1 AND (project_id IS NULL OR project_id IS NOT NULL)";
+ $PARAMS = [ $rcpro_project_id ];
+ if ( isset($dag) ) {
$SQL .= " AND project_dag IS NOT NULL AND project_dag = ?";
array_push($PARAMS, strval($dag));
}
try {
- $result = $this->module->selectLogs($SQL, $PARAMS);
- $participants = array();
+ $result = $this->module->selectLogs($SQL, $PARAMS);
+ $participants = array();
- while ($row = $result->fetch_assoc()) {
- $participantSQL = "SELECT log_id, rcpro_username, email, fname, lname, lockout_ts, pw WHERE message = 'PARTICIPANT' AND log_id = ? AND (project_id IS NULL OR project_id IS NOT NULL)";
- $participantResult = $this->module->selectLogs($participantSQL, [$row["rcpro_participant_id"]]);
- $participant = $participantResult->fetch_assoc();
+ while ( $row = $result->fetch_assoc() ) {
+ $participantSQL = "SELECT log_id, rcpro_username, email, fname, lname, lockout_ts, pw WHERE message = 'PARTICIPANT' AND log_id = ? AND (project_id IS NULL OR project_id IS NOT NULL)";
+ $participantResult = $this->module->selectLogs($participantSQL, [ $row["rcpro_participant_id"] ]);
+ $participant = $participantResult->fetch_assoc();
$participant["pw_set"] = (!isset($participant["pw"]) || $participant["pw"] === "") ? "False" : "True";
unset($participant["pw"]);
$participants[$row["rcpro_participant_id"]] = $participant;
}
return $participants;
- } catch (\Exception $e) {
+ } catch ( \Exception $e ) {
$this->module->logError("Error fetching project participants", $e);
}
}
@@ -540,9 +540,9 @@ public function getUserName(int $rcpro_participant_id)
{
$SQL = "SELECT rcpro_username WHERE message = 'PARTICIPANT' AND log_id = ? AND (project_id IS NULL OR project_id IS NOT NULL)";
try {
- $result = $this->module->selectLogs($SQL, [$rcpro_participant_id]);
+ $result = $this->module->selectLogs($SQL, [ $rcpro_participant_id ]);
return $result->fetch_assoc()["rcpro_username"];
- } catch (\Exception $e) {
+ } catch ( \Exception $e ) {
$this->module->logError("Error fetching username", $e);
}
}
@@ -558,10 +558,10 @@ public function isParticipantActive($rcpro_participant_id)
{
$SQL = "SELECT active WHERE log_id = ? AND (project_id IS NULL OR project_id IS NOT NULL)";
try {
- $res = $this->module->selectLogs($SQL, [$rcpro_participant_id]);
+ $res = $this->module->selectLogs($SQL, [ $rcpro_participant_id ]);
$status_arr = $res->fetch_assoc();
return !isset($status_arr["active"]) || $status_arr["active"] == 1;
- } catch (\Exception $e) {
+ } catch ( \Exception $e ) {
$this->module->logError("Error getting active status", $e);
}
}
@@ -577,15 +577,15 @@ public function searchParticipants(string $search_term)
{
$this->module->logEvent("Searched on Enroll Tab", [
"search" => \REDCap::escapeHtml($search_term),
- "redcap_user" => USERID
+ "redcap_user" => $this->module->framework->getUser()->getUsername()
]);
$SQL = "SELECT fname, lname, email, log_id, rcpro_username, active
WHERE message = 'PARTICIPANT'
AND (project_id IS NULL OR project_id IS NOT NULL)
AND (email = ?)";
try {
- return $this->module->selectLogs($SQL, [$search_term]);
- } catch (\Exception $e) {
+ return $this->module->selectLogs($SQL, [ $search_term ]);
+ } catch ( \Exception $e ) {
$this->module->logError("Error performing livesearch", $e);
}
}
@@ -600,30 +600,30 @@ public function searchParticipants(string $search_term)
*/
private function setActiveStatus($rcpro_participant_id, int $value)
{
- if ($this->module->countLogsValidated("log_id = ? AND active is not null", [$rcpro_participant_id]) > 0) {
+ if ( $this->module->countLogsValidated("log_id = ? AND active is not null", [ $rcpro_participant_id ]) > 0 ) {
$SQL = "UPDATE redcap_external_modules_log_parameters SET value = ? WHERE log_id = ? AND name = 'active'";
} else {
$SQL = "INSERT INTO redcap_external_modules_log_parameters (value, name, log_id) VALUES (?, 'active', ?)";
}
try {
- $res = $this->module->query($SQL, [$value, $rcpro_participant_id]);
- if ($res) {
+ $res = $this->module->query($SQL, [ $value, $rcpro_participant_id ]);
+ if ( $res ) {
$this->module->logEvent("Set participant active status", [
"rcpro_participant_id" => $rcpro_participant_id,
- "rcpro_username" => $this->getUserName($rcpro_participant_id),
- "active" => $value,
- "redcap_user" => USERID
+ "rcpro_username" => $this->getUserName($rcpro_participant_id),
+ "active" => $value,
+ "redcap_user" => $this->module->framework->getUser()->getUsername()
]);
} else {
$this->module->logEvent("Failed to set participant active status", [
"rcpro_participant_id" => $rcpro_participant_id,
- "rcpro_username" => $this->getUserName($rcpro_participant_id),
- "active" => $value,
- "redcap_user" => USERID
+ "rcpro_username" => $this->getUserName($rcpro_participant_id),
+ "active" => $value,
+ "redcap_user" => $this->module->framework->getUser()->getUsername()
]);
}
return $res;
- } catch (\Exception $e) {
+ } catch ( \Exception $e ) {
$this->module->logError("Error setting participant active status", $e);
}
}
@@ -640,13 +640,13 @@ public function storeHash(string $hash, int $rcpro_participant_id)
{
try {
$SQL = "UPDATE redcap_external_modules_log_parameters SET value = ? WHERE log_id = ? AND name = 'pw';";
- $res = $this->module->query($SQL, [$hash, $rcpro_participant_id]);
+ $res = $this->module->query($SQL, [ $hash, $rcpro_participant_id ]);
$this->module->logEvent("Password Hash Stored", [
"rcpro_participant_id" => $rcpro_participant_id,
"rcpro_username" => $this->getUserName($rcpro_participant_id)
]);
return $res;
- } catch (\Exception $e) {
+ } catch ( \Exception $e ) {
$this->module->logError("Error storing password hash", $e);
}
}
@@ -662,9 +662,9 @@ public function usernameIsTaken(string $username)
{
$SQL = "message = 'PARTICIPANT' AND rcpro_username = ? AND (project_id IS NULL OR project_id IS NOT NULL)";
try {
- $result = $this->module->countLogsValidated($SQL, [$username]);
+ $result = $this->module->countLogsValidated($SQL, [ $username ]);
return $result > 0;
- } catch (\Exception $e) {
+ } catch ( \Exception $e ) {
$this->module->logError("Error checking if username is taken", $e);
}
}
@@ -680,8 +680,8 @@ public function verifyPasswordResetToken(string $token)
{
$SQL = "SELECT log_id, rcpro_username WHERE message = 'PARTICIPANT' AND token = ? AND token_ts > ? AND token_valid = 1 AND (project_id IS NULL OR project_id IS NOT NULL)";
try {
- $result = $this->module->selectLogs($SQL, [$token, time()]);
- if ($result->num_rows > 0) {
+ $result = $this->module->selectLogs($SQL, [ $token, time() ]);
+ if ( $result->num_rows > 0 ) {
$result_array = $result->fetch_assoc();
$this->module->logEvent("Password Token Verified", [
'rcpro_participant_id' => $result_array['log_id'],
@@ -689,8 +689,8 @@ public function verifyPasswordResetToken(string $token)
]);
return $result_array;
}
- } catch (\Exception $e) {
+ } catch ( \Exception $e ) {
$this->module->logError("Error verifying password reset token", $e);
}
}
-}
+}
\ No newline at end of file
diff --git a/src/classes/ProjectHelper.php b/src/classes/ProjectHelper.php
index 27d501e..75a8a81 100644
--- a/src/classes/ProjectHelper.php
+++ b/src/classes/ProjectHelper.php
@@ -2,12 +2,11 @@
namespace YaleREDCap\REDCapPRO;
-require_once("src/classes/ParticipantHelper.php");
-
+require_once "src/classes/ParticipantHelper.php";
class ProjectHelper
{
- public $module;
+ public REDCapPRO $module;
function __construct(REDCapPRO $module)
{
@@ -27,9 +26,9 @@ public function addProject(int $pid)
return $this->module->logEvent("PROJECT", [
"pid" => $pid,
"active" => 1,
- "redcap_user" => USERID
+ "redcap_user" => $this->module->framework->getUser()->getUsername()
]);
- } catch (\Exception $e) {
+ } catch ( \Exception $e ) {
$this->module->logError("Error creating project entry", $e);
}
}
@@ -48,13 +47,13 @@ public function checkProject(int $pid, bool $check_active = FALSE)
{
$SQL = "SELECT active WHERE pid = ? and message = 'PROJECT' and (project_id IS NULL OR project_id IS NOT NULL)";
try {
- $result = $this->module->selectLogs($SQL, [$pid]);
- if ($result->num_rows == 0) {
+ $result = $this->module->selectLogs($SQL, [ $pid ]);
+ if ( $result->num_rows == 0 ) {
return FALSE;
}
$row = $result->fetch_assoc();
return $check_active ? $row["active"] == "1" : TRUE;
- } catch (\Exception $e) {
+ } catch ( \Exception $e ) {
$this->module->logError("Error checking project", $e);
}
}
@@ -76,18 +75,18 @@ private function createLink(int $rcpro_participant_id, int $rcpro_project_id, ?i
"rcpro_project_id" => $rcpro_project_id,
"rcpro_participant_id" => $rcpro_participant_id,
"active" => 1,
- "redcap_user" => USERID,
- "project_dag" => $dag
+ "redcap_user" => $this->module->framework->getUser()->getUsername(),
+ "project_dag" => $dag
]);
$this->module->logEvent("Enrolled Participant", [
"rcpro_participant_id" => $rcpro_participant_id,
"rcpro_username" => $rcpro_username,
"rcpro_project_id" => $rcpro_project_id,
- "redcap_user" => USERID,
- "project_dag" => $dag
+ "redcap_user" => $this->module->framework->getUser()->getUsername(),
+ "project_dag" => $dag
]);
return TRUE;
- } catch (\Exception $e) {
+ } catch ( \Exception $e ) {
$this->module->logError("Error enrolling participant", $e);
return FALSE;
}
@@ -105,16 +104,16 @@ public function disenrollParticipant(int $rcpro_participant_id, int $rcpro_proje
{
try {
$result = $this->setLinkActiveStatus($rcpro_participant_id, $rcpro_project_id, 0);
- if ($result) {
+ if ( $result ) {
$this->module->logEvent("Disenrolled Participant", [
"rcpro_participant_id" => $rcpro_participant_id,
"rcpro_username" => $rcpro_username,
"rcpro_project_id" => $rcpro_project_id,
- "redcap_user" => USERID
+ "redcap_user" => $this->module->framework->getUser()->getUsername()
]);
}
return $result;
- } catch (\Exception $e) {
+ } catch ( \Exception $e ) {
$this->module->logError("Error Disenrolling Participant", $e);
}
}
@@ -131,26 +130,26 @@ public function disenrollParticipant(int $rcpro_participant_id, int $rcpro_proje
public function enrollParticipant(int $rcpro_participant_id, int $pid, ?int $dag, ?string $rcpro_username)
{
// If project does not exist, create it.
- if (!$this->checkProject($pid)) {
+ if ( !$this->checkProject($pid) ) {
$this->addProject($pid);
}
$rcpro_project_id = $this->getProjectIdFromPID($pid);
// Check that user is not already enrolled in this project
- if ($this->participantEnrolled($rcpro_participant_id, $rcpro_project_id)) {
+ if ( $this->participantEnrolled($rcpro_participant_id, $rcpro_project_id) ) {
return -1;
}
// If there is already a link between this participant and project,
// then activate it, otherwise create the link
- if ($this->linkAlreadyExists($rcpro_participant_id, $rcpro_project_id)) {
+ if ( $this->linkAlreadyExists($rcpro_participant_id, $rcpro_project_id) ) {
$result = $this->setLinkActiveStatus($rcpro_participant_id, $rcpro_project_id, 1, $dag);
- if ($result) {
+ if ( $result ) {
$this->module->logEvent("Enrolled Participant", [
"rcpro_participant_id" => $rcpro_participant_id,
"rcpro_username" => $rcpro_username,
"rcpro_project_id" => $rcpro_project_id,
- "redcap_user" => USERID,
+ "redcap_user" => $this->module->framework->getUser()->getUsername(),
"project_dag" => $dag
]);
}
@@ -172,9 +171,9 @@ public function getLinkId(int $rcpro_participant_id, int $rcpro_project_id)
{
$SQL = "SELECT log_id WHERE message = 'LINK' AND rcpro_participant_id = ? AND rcpro_project_id = ? AND (project_id IS NULL OR project_id IS NOT NULL)";
try {
- $result = $this->module->selectLogs($SQL, [$rcpro_participant_id, $rcpro_project_id]);
+ $result = $this->module->selectLogs($SQL, [ $rcpro_participant_id, $rcpro_project_id ]);
return $result->fetch_assoc()["log_id"];
- } catch (\Exception $e) {
+ } catch ( \Exception $e ) {
$this->module->logError("Error fetching link id", $e);
}
}
@@ -190,9 +189,9 @@ public function getPidFromProjectId(int $rcpro_project_id)
{
$SQL = "SELECT pid WHERE message = 'PROJECT' AND log_id = ? AND (project_id IS NULL OR project_id IS NOT NULL)";
try {
- $result = $this->module->selectLogs($SQL, [$rcpro_project_id]);
+ $result = $this->module->selectLogs($SQL, [ $rcpro_project_id ]);
return $result->fetch_assoc()["pid"];
- } catch (\Exception $e) {
+ } catch ( \Exception $e ) {
$this->module->logError("Error fetching pid from project id", $e);
}
}
@@ -209,9 +208,9 @@ public function getProjectIdFromPID(int $pid)
{
$SQL = "SELECT log_id WHERE message = 'PROJECT' AND pid = ? AND (project_id IS NULL OR project_id IS NOT NULL)";
try {
- $result = $this->module->selectLogs($SQL, [$pid]);
+ $result = $this->module->selectLogs($SQL, [ $pid ]);
return $result->fetch_assoc()["log_id"];
- } catch (\Exception $e) {
+ } catch ( \Exception $e ) {
$this->module->logError("Error fetching project id from pid", $e);
}
}
@@ -229,9 +228,9 @@ private function linkAlreadyExists(int $rcpro_participant_id, int $rcpro_project
{
$SQL = "message = 'LINK' AND rcpro_participant_id = ? AND rcpro_project_id = ? AND (project_id IS NULL OR project_id IS NOT NULL)";
try {
- $result = $this->module->countLogsValidated($SQL, [$rcpro_participant_id, $rcpro_project_id]);
+ $result = $this->module->countLogsValidated($SQL, [ $rcpro_participant_id, $rcpro_project_id ]);
return $result > 0;
- } catch (\Exception $e) {
+ } catch ( \Exception $e ) {
$this->module->logError("Error checking if link exists", $e);
}
}
@@ -248,9 +247,9 @@ public function participantEnrolled(int $rcpro_participant_id, int $rcpro_projec
{
$SQL = "message = 'LINK' AND rcpro_participant_id = ? AND rcpro_project_id = ? AND active = 1 AND (project_id IS NULL OR project_id IS NOT NULL)";
try {
- $result = $this->module->countLogsValidated($SQL, [$rcpro_participant_id, $rcpro_project_id]);
+ $result = $this->module->countLogsValidated($SQL, [ $rcpro_participant_id, $rcpro_project_id ]);
return $result > 0;
- } catch (\Exception $e) {
+ } catch ( \Exception $e ) {
$this->module->logError("Error checking participant enrollment", $e);
}
}
@@ -268,15 +267,15 @@ public function participantEnrolled(int $rcpro_participant_id, int $rcpro_projec
private function setLinkActiveStatus(int $rcpro_participant_id, int $rcpro_project_id, int $active, int $dag = NULL)
{
$link_id = $this->getLinkId($rcpro_participant_id, $rcpro_project_id);
- $SQL1 = "UPDATE redcap_external_modules_log_parameters SET value = ? WHERE log_id = ? AND name = 'active'";
- $SQL2 = "UPDATE redcap_external_modules_log_parameters SET value = ? WHERE log_id = ? AND name = 'project_dag'";
+ $SQL1 = "UPDATE redcap_external_modules_log_parameters SET value = ? WHERE log_id = ? AND name = 'active'";
+ $SQL2 = "UPDATE redcap_external_modules_log_parameters SET value = ? WHERE log_id = ? AND name = 'project_dag'";
try {
- $result1 = $this->module->query($SQL1, [$active, $link_id]);
- if ($result1 && isset($dag)) {
- $result2 = $this->module->query($SQL2, [$dag, $link_id]);
+ $result1 = $this->module->query($SQL1, [ $active, $link_id ]);
+ if ( $result1 && isset($dag) ) {
+ $result2 = $this->module->query($SQL2, [ $dag, $link_id ]);
}
return $result1;
- } catch (\Exception $e) {
+ } catch ( \Exception $e ) {
$this->module->logError("Error setting link activity", $e);
}
}
@@ -292,18 +291,18 @@ private function setLinkActiveStatus(int $rcpro_participant_id, int $rcpro_proje
public function setProjectActive(int $pid, int $active)
{
$rcpro_project_id = $this->getProjectIdFromPID($pid);
- $SQL = "UPDATE redcap_external_modules_log_parameters SET value = ? WHERE log_id = ? AND name = 'active'";
+ $SQL = "UPDATE redcap_external_modules_log_parameters SET value = ? WHERE log_id = ? AND name = 'active'";
try {
- $result = $this->module->query($SQL, [$active, $rcpro_project_id]);
- if ($result) {
+ $result = $this->module->query($SQL, [ $active, $rcpro_project_id ]);
+ if ( $result ) {
$this->module->logEvent("Project Status Set", [
"rcpro_project_id" => $rcpro_project_id,
"active_status" => $active,
- "redcap_user" => USERID
+ "redcap_user" => $this->module->framework->getUser()->getUsername()
]);
}
- } catch (\Exception $e) {
+ } catch ( \Exception $e ) {
$this->module->logError("Error setting project active status", $e);
}
}
-}
+}
\ No newline at end of file
diff --git a/src/classes/UI.php b/src/classes/UI.php
index ebdfa66..bfb561d 100644
--- a/src/classes/UI.php
+++ b/src/classes/UI.php
@@ -5,7 +5,7 @@
class UI
{
- public $module;
+ public REDCapPRO $module;
function __construct($module)
{
$this->module = $module;
@@ -46,7 +46,7 @@ public function EndParticipantPage()
public function ShowHeader(string $page)
{
- $role = SUPER_USER ? 3 : $this->module->getUserRole(USERID); // 3=admin/manager, 2=user, 1=monitor, 0=not found
+ $role = $this->module->getUserRole($this->module->framework->getUser()->getUsername()); // 3=admin/manager, 2=user, 1=monitor, 0=not found
$header = "