diff --git a/README.md b/README.md index d493690..17f034f 100644 --- a/README.md +++ b/README.md @@ -112,13 +112,13 @@ When a value for _success_ is defined, the field with the action tag will be set ### Combining **@SURVEY-AUTH** with **@IF** -The **@SURVEY-AUTH** action tag can be used inside **@IF** (since v1.4.0), but only on non-public surveys. -For public surveys, as long as **@SURVEY-AUTH** is present _anywhere_ (even when inside the _false part_ of an @IF), the survey taker will need to log in before being able to proceed. +The **@SURVEY-AUTH** action tag can be used inside **@IF** action tags. Note that in public surveys, the record does not exist yet, and does any logic should be restricted to record-independent elements, such as e.g. the [arm-number], [arm-label] or the aggregate smart variables. ## [Changelog](#changelog) Release | Description ------- | --------------------- +v1.4.1 | Bugfix: @SURVEY-AUTH with @IF works now in public surveys. v1.4.0 | Compatiblity fix: @SURVEY-AUTH can now be used inside @IF; Bugfix: Some JavaScript was missing from the login page; Minimum REDCap version is 12.0.7. v1.3.1 | Changed the way the url for login form submission is generated. v1.3.0 | New feature: Login for non-public surveys. Simply add the @SURVEY-AUTH action tag (this must first be enabled in the system settings of the module). Enhancement: The token is not required any longer, but instead replaced by a setting that controls whether the module may write data to a record (during an upgrade, tokens are deleted and write mode set to ON). diff --git a/SurveyAuthExternalModule.php b/SurveyAuthExternalModule.php index 21df13f..2a05c70 100644 --- a/SurveyAuthExternalModule.php +++ b/SurveyAuthExternalModule.php @@ -41,10 +41,14 @@ function redcap_survey_page_top($project_id, $record, $instrument, $event_id, $g $record = \Survey::getRecordFromPartId([$participant_id])[$participant_id]; if ($record != null) { // We can be sure that the record exists! So we can safely do this: - // We must set this to something other than 0 in order to get @IF action tag parsing to work. Duh. + // We must set this to something other than 0 in order to get @IF action tag parsing to work (Form::evaluateIfActionTag() relies on this global). $GLOBALS["hidden_edit"] = 1; } } + if (\Survey::isPublicSurvey() && $record == null) { + // This is a hack to work around a bug in Form::evaluateIfActionTag() /REDCap::evaluateLogic() + $record = "__some_record_id_that_should_definitely_NOT_exist___" . \Crypto::getGuid(); + } $this->settings = new SurveyAuthSettings($this); @@ -208,7 +212,7 @@ private function getTaggedFields($dataDictionary, $project_id, $record, $event_i { $fields = array(); foreach ($dataDictionary as $fieldInfo) { - $evaluatedFieldAnnotation = \Survey::isPublicSurvey() ? $fieldInfo->field_annotation : \Form::replaceIfActionTag($fieldInfo->field_annotation, $project_id, $record, $event_id, $instrument, $repeat_instance); + $evaluatedFieldAnnotation = \Form::replaceIfActionTag($fieldInfo->field_annotation, $project_id, $record, $event_id, $instrument, $repeat_instance); if (strpos($evaluatedFieldAnnotation, "@".SurveyAuthExternalModule::$ACTIONTAG)) { array_push($fields, new SurveyAuthInfo($fieldInfo, $dataDictionary)); } @@ -292,6 +296,10 @@ function authenticate($username, $password, $project_id, $instrument, $event_id, else { // Use first, any further are ignored $tf = $taggedFields[0]; + // If this is a public survey, we need to set $record to null + if (\Survey::isPublicSurvey()) { + $record = null; + } // If this is a nonpublic survey, $record will be set so // just update that record. Otherwise, create new record. $record = $record ?? $this->addAutoNumberedRecord();