From 6ef50d65d9b83b4891fc46ebf9bd88da062ade1d Mon Sep 17 00:00:00 2001 From: Patrick Teichmann Date: Fri, 26 Mar 2021 10:01:02 +0100 Subject: [PATCH 01/13] Fixed issue #16673: afterFindSurvey fired to many times --- application/models/QuestionAttribute.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/application/models/QuestionAttribute.php b/application/models/QuestionAttribute.php index a705c9059e1..16f2a037627 100644 --- a/application/models/QuestionAttribute.php +++ b/application/models/QuestionAttribute.php @@ -209,7 +209,8 @@ public function setMultiple($iSid, $aQids, $aAttributesToUpdate, $aValidQuestion */ public function getQuestionAttributes($iQuestionID, $sLanguage = null) { - $iQuestionID = (int) $iQuestionID; + static $survey = ''; + $iQuestionID = (int)$iQuestionID; // Limit the size of the attribute cache due to memory usage $cacheKey = 'getQuestionAttributes_' . $iQuestionID . '_' . json_encode($sLanguage); if (EmCacheHelper::useCache()) { @@ -218,12 +219,16 @@ public function getQuestionAttributes($iQuestionID, $sLanguage = null) return $value; } } - $oQuestion = Question::model()->with('survey')->find("qid=:qid", array('qid' => $iQuestionID)); + + $oQuestion = Question::model()->find("qid=:qid", ['qid' => $iQuestionID]); if ($oQuestion) { + if (!$survey) { + $survey = Survey::model()->findByPk($oQuestion->sid); + } if ($sLanguage) { - $aLanguages = array($sLanguage); + $aLanguages = [$sLanguage]; } else { - $aLanguages = $oQuestion->survey->allLanguages; + $aLanguages = $survey->allLanguages; } // For some reason this happened in bug #10684 if ($oQuestion->type == null) { From 0556d2268c3b86f77ec3a6db26a022f90133d6ae Mon Sep 17 00:00:00 2001 From: Carsten Schmitz Date: Fri, 26 Mar 2021 16:37:26 +0100 Subject: [PATCH 02/13] Dev Renamed lastLogin field --- application/config/version.php | 2 +- application/core/LSUserIdentity.php | 2 +- application/helpers/update/updatedb_helper.php | 5 +++++ application/models/User.php | 4 ++-- installer/create-database.php | 2 +- 5 files changed, 10 insertions(+), 5 deletions(-) diff --git a/application/config/version.php b/application/config/version.php index 464599d6a82..ec164ab17cd 100644 --- a/application/config/version.php +++ b/application/config/version.php @@ -12,7 +12,7 @@ */ $config['versionnumber'] = '4.4.14'; -$config['dbversionnumber'] = 442; +$config['dbversionnumber'] = 443; $config['buildnumber'] = ''; $config['updatable'] = true; $config['templateapiversion'] = 3; diff --git a/application/core/LSUserIdentity.php b/application/core/LSUserIdentity.php index df561c056e8..9662647fb1c 100644 --- a/application/core/LSUserIdentity.php +++ b/application/core/LSUserIdentity.php @@ -179,7 +179,7 @@ protected function postLogin() } //At last store the login time in the user table - $user->lastLogin = date('Y-m-d H:i:s'); + $user->last_login = date('Y-m-d H:i:s'); $user->save(); } diff --git a/application/helpers/update/updatedb_helper.php b/application/helpers/update/updatedb_helper.php index de4b09af278..3a6ab79e9c0 100644 --- a/application/helpers/update/updatedb_helper.php +++ b/application/helpers/update/updatedb_helper.php @@ -3783,6 +3783,11 @@ function ($v) { $oDB->createCommand()->update('{{settings_global}}', array('stg_value' => 442), "stg_name='DBVersion'"); $oTransaction->commit(); } + if ($iOldDBVersion < 443) { + $oDB->createCommand()->renameColumn('{{users}}', 'lastLogin', 'last_login'); + $oDB->createCommand()->update('{{settings_global}}', array('stg_value' => 443), "stg_name='DBVersion'"); + $oTransaction->commit(); + } } catch (Exception $e) { Yii::app()->setConfig('Updating', false); $oTransaction->rollback(); diff --git a/application/models/User.php b/application/models/User.php index e8ba6541981..0d4b6968f2a 100644 --- a/application/models/User.php +++ b/application/models/User.php @@ -122,7 +122,7 @@ public function attributeLabels() 'dateformat' => gT('Date format'), 'created' => gT('Created at'), 'modified' => gT('Modified at'), - 'lastLogin' => gT('Last recorded login'), + 'last_login' => gT('Last recorded login'), ]; } @@ -741,7 +741,7 @@ function ($oRoleMapping) { public function getLastloginFormatted() { - $lastLogin = $this->lastLogin; + $lastLogin = $this->last_login; if ($lastLogin == null) { return '---'; } diff --git a/installer/create-database.php b/installer/create-database.php index 83a6d9ea0a6..ea4f6b53d99 100755 --- a/installer/create-database.php +++ b/installer/create-database.php @@ -1061,7 +1061,7 @@ function populateDatabase($oDB) 'questionselectormode' => "string(7) NOT NULL default 'default'", 'one_time_pw' => "text", 'dateformat' => "integer NOT NULL DEFAULT 1", - 'lastLogin' => "datetime NULL", + 'last_login' => "datetime NULL", 'created' => "datetime", 'modified' => "datetime", ), $options); From 1c97b9834eae95c7e13c7541365ad74585e5399c Mon Sep 17 00:00:00 2001 From: Carsten Schmitz Date: Fri, 26 Mar 2021 16:38:16 +0100 Subject: [PATCH 03/13] Dev Renamed lastLogin field --- application/helpers/update/updatedb_helper.php | 1 + 1 file changed, 1 insertion(+) diff --git a/application/helpers/update/updatedb_helper.php b/application/helpers/update/updatedb_helper.php index 3a6ab79e9c0..737150e9d8b 100644 --- a/application/helpers/update/updatedb_helper.php +++ b/application/helpers/update/updatedb_helper.php @@ -3784,6 +3784,7 @@ function ($v) { $oTransaction->commit(); } if ($iOldDBVersion < 443) { + $oTransaction = $oDB->beginTransaction(); $oDB->createCommand()->renameColumn('{{users}}', 'lastLogin', 'last_login'); $oDB->createCommand()->update('{{settings_global}}', array('stg_value' => 443), "stg_name='DBVersion'"); $oTransaction->commit(); From de62b7fb4d75c04a6d4495e3a017566b3e7fbf3e Mon Sep 17 00:00:00 2001 From: arnaudbore Date: Sat, 27 Mar 2021 03:58:24 -0400 Subject: [PATCH 04/13] Fixed issue: RemoteControl add_participants did not return anything --- .../helpers/remotecontrol/remotecontrol_handle.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/application/helpers/remotecontrol/remotecontrol_handle.php b/application/helpers/remotecontrol/remotecontrol_handle.php index a8638be619a..61955e1c23d 100644 --- a/application/helpers/remotecontrol/remotecontrol_handle.php +++ b/application/helpers/remotecontrol/remotecontrol_handle.php @@ -1823,13 +1823,13 @@ public function add_participants($sSessionKey, $iSurveyID, $aParticipantData, $b if ($bCreateToken) { $token->generateToken(); } - if ($token->encryptSave(true)) { - $aParticipant = $token->getAttributes(); + if ($token->encryptSave(true)) { + $return = $token->getAttributes(); } else { - $aParticipant["errors"] = $token->errors; + $return["status"] = 'Error: '.$token->errors; } } - return $aParticipantData; + return $return; } else { return array('status' => 'No permission'); } From ed935997fc70d5d21761bfe7fd446d3a8f0845a8 Mon Sep 17 00:00:00 2001 From: Carsten Schmitz Date: Sat, 27 Mar 2021 09:28:20 +0100 Subject: [PATCH 05/13] Dev Revert "Fixed issue: RemoteControl add_participants did not return anything" Dev Unnecessary fix --- .../helpers/remotecontrol/remotecontrol_handle.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/application/helpers/remotecontrol/remotecontrol_handle.php b/application/helpers/remotecontrol/remotecontrol_handle.php index 61955e1c23d..a8638be619a 100644 --- a/application/helpers/remotecontrol/remotecontrol_handle.php +++ b/application/helpers/remotecontrol/remotecontrol_handle.php @@ -1823,13 +1823,13 @@ public function add_participants($sSessionKey, $iSurveyID, $aParticipantData, $b if ($bCreateToken) { $token->generateToken(); } - if ($token->encryptSave(true)) { - $return = $token->getAttributes(); + if ($token->encryptSave(true)) { + $aParticipant = $token->getAttributes(); } else { - $return["status"] = 'Error: '.$token->errors; + $aParticipant["errors"] = $token->errors; } } - return $return; + return $aParticipantData; } else { return array('status' => 'No permission'); } From a7e9d311ae378eba9115728ec21a6f9605f6a948 Mon Sep 17 00:00:00 2001 From: Carsten Schmitz Date: Sat, 27 Mar 2021 09:42:37 +0100 Subject: [PATCH 06/13] Fixed issue: RemoteControl add_participants did not return the actual saved values or errors --- application/helpers/remotecontrol/remotecontrol_handle.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/application/helpers/remotecontrol/remotecontrol_handle.php b/application/helpers/remotecontrol/remotecontrol_handle.php index a8638be619a..52f71538c29 100644 --- a/application/helpers/remotecontrol/remotecontrol_handle.php +++ b/application/helpers/remotecontrol/remotecontrol_handle.php @@ -1817,6 +1817,7 @@ public function add_participants($sSessionKey, $iSurveyID, $aParticipantData, $b return array('status' => 'No survey participants table'); } $aDestinationFields = array_flip(Token::model($iSurveyID)->getMetaData()->tableSchema->columnNames); + $aReturn = []; foreach ($aParticipantData as &$aParticipant) { $token = Token::create($iSurveyID); $token->setAttributes(array_intersect_key($aParticipant, $aDestinationFields)); @@ -1824,12 +1825,12 @@ public function add_participants($sSessionKey, $iSurveyID, $aParticipantData, $b $token->generateToken(); } if ($token->encryptSave(true)) { - $aParticipant = $token->getAttributes(); + $aReturn[] = $token->getAttributes(); } else { - $aParticipant["errors"] = $token->errors; + $aReturn["errors"][] = $token->errors; } } - return $aParticipantData; + return $aReturn; } else { return array('status' => 'No permission'); } From 0ba1b7605926b0c08c7ac9f06df2d5bdd16a8004 Mon Sep 17 00:00:00 2001 From: Carsten Schmitz Date: Sun, 28 Mar 2021 10:16:14 +0200 Subject: [PATCH 07/13] Dev Revert "Fixed issue: RemoteControl add_participants did not return the actual saved values or errors" --- application/helpers/remotecontrol/remotecontrol_handle.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/application/helpers/remotecontrol/remotecontrol_handle.php b/application/helpers/remotecontrol/remotecontrol_handle.php index 52f71538c29..a8638be619a 100644 --- a/application/helpers/remotecontrol/remotecontrol_handle.php +++ b/application/helpers/remotecontrol/remotecontrol_handle.php @@ -1817,7 +1817,6 @@ public function add_participants($sSessionKey, $iSurveyID, $aParticipantData, $b return array('status' => 'No survey participants table'); } $aDestinationFields = array_flip(Token::model($iSurveyID)->getMetaData()->tableSchema->columnNames); - $aReturn = []; foreach ($aParticipantData as &$aParticipant) { $token = Token::create($iSurveyID); $token->setAttributes(array_intersect_key($aParticipant, $aDestinationFields)); @@ -1825,12 +1824,12 @@ public function add_participants($sSessionKey, $iSurveyID, $aParticipantData, $b $token->generateToken(); } if ($token->encryptSave(true)) { - $aReturn[] = $token->getAttributes(); + $aParticipant = $token->getAttributes(); } else { - $aReturn["errors"][] = $token->errors; + $aParticipant["errors"] = $token->errors; } } - return $aReturn; + return $aParticipantData; } else { return array('status' => 'No permission'); } From 1048d4256dfd753a1b8acc9bd8e0126659fc8874 Mon Sep 17 00:00:00 2001 From: Carsten Schmitz Date: Mon, 29 Mar 2021 08:37:35 +0200 Subject: [PATCH 08/13] Fixed issue: Google Maps being loaded even though no API key is set --- .../helpers/admin/statistics_helper.php | 30 ++++++------------- application/helpers/qanda_helper.php | 10 ++----- application/helpers/userstatistics_helper.php | 11 ++----- 3 files changed, 14 insertions(+), 37 deletions(-) diff --git a/application/helpers/admin/statistics_helper.php b/application/helpers/admin/statistics_helper.php index 0e37680711b..3c646c53dd3 100644 --- a/application/helpers/admin/statistics_helper.php +++ b/application/helpers/admin/statistics_helper.php @@ -3524,15 +3524,11 @@ public function generate_simple_statistics($surveyid, $allfields, $q2show = 'all $sOutputHTML .= ''; $sGoogleMapsAPIKey = trim(Yii::app()->getConfig("googleMapsAPIKey")); - if ($sGoogleMapsAPIKey != '') { - $sGoogleMapsAPIKey = '&key=' . $sGoogleMapsAPIKey; + if (!empty($sGoogleMapsAPIKey != '')) { + $sOutputHTML .= "\n"; } - $sSSL = ''; - if (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != "off") { - $sSSL = 's'; - } - $sOutputHTML .= "\n" - . ""; + + $sOutputHTML .= ""; return $sOutputHTML; @@ -3748,11 +3744,7 @@ public function generate_html_chartjs_statistics($surveyid, $allfields, $q2show if ($sGoogleMapsAPIKey != '') { $sGoogleMapsAPIKey = '&key=' . $sGoogleMapsAPIKey; } - $sSSL = ''; - if (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != "off") { - $sSSL = 's'; - } - $sOutputHTML .= "\n" + $sOutputHTML .= "\n" . ""; @@ -4087,15 +4079,11 @@ public function generate_statistics($surveyid, $allfields, $q2show = 'all', $use break; case 'html': $sGoogleMapsAPIKey = trim(Yii::app()->getConfig("googleMapsAPIKey")); - if ($sGoogleMapsAPIKey != '') { - $sGoogleMapsAPIKey = '&key=' . $sGoogleMapsAPIKey; + if (!empty($sGoogleMapsAPIKey)) { + $sOutputHTML .= "\n"; } - $sSSL = ''; - if (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != "off") { - $sSSL = 's'; - } - $sOutputHTML .= "\n" - . ""; + + $sOutputHTML .= ""; return $sOutputHTML; break; diff --git a/application/helpers/qanda_helper.php b/application/helpers/qanda_helper.php index dc5064abb64..16c4ab54de7 100644 --- a/application/helpers/qanda_helper.php +++ b/application/helpers/qanda_helper.php @@ -2383,10 +2383,6 @@ function do_shortfreetext($ia) $sGoogleMapsAPIKey = trim(Yii::app()->getConfig("googleMapsAPIKey")); $coreClass = "ls-answers answer-item text-item"; - if ($sGoogleMapsAPIKey != '') { - $sGoogleMapsAPIKey = '&key=' . $sGoogleMapsAPIKey; - } - $extraclass = ""; $aQuestionAttributes = QuestionAttribute::model()->getQuestionAttributes($ia[0]); @@ -2525,10 +2521,8 @@ function do_shortfreetext($ia) $currentLocation = $currentLatLong[0] . " " . $currentLatLong[1]; Yii::app()->getClientScript()->registerScriptFile(Yii::app()->getConfig('generalscripts') . "map.js", LSYii_ClientScript::POS_END); - if ($aQuestionAttributes['location_mapservice'] == 1 && !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != "off") { - Yii::app()->getClientScript()->registerScriptFile("https://maps.googleapis.com/maps/api/js?sensor=false$sGoogleMapsAPIKey", LSYii_ClientScript::POS_BEGIN); - } elseif ($aQuestionAttributes['location_mapservice'] == 1) { - Yii::app()->getClientScript()->registerScriptFile("http://maps.googleapis.com/maps/api/js?sensor=false$sGoogleMapsAPIKey", LSYii_ClientScript::POS_BEGIN); + if ($aQuestionAttributes['location_mapservice'] == 1 && !empty($sGoogleMapsAPIKey)) { + Yii::app()->getClientScript()->registerScriptFile("//maps.googleapis.com/maps/api/js?sensor=false&key={$sGoogleMapsAPIKey}", LSYii_ClientScript::POS_BEGIN); } elseif ($aQuestionAttributes['location_mapservice'] == 2) { /* 2019-04-01 : openlayers auto redirect to https (on firefox) , but always good to use automatic protocol */ Yii::app()->getClientScript()->registerScriptFile("//www.openlayers.org/api/OpenLayers.js", LSYii_ClientScript::POS_BEGIN); diff --git a/application/helpers/userstatistics_helper.php b/application/helpers/userstatistics_helper.php index 92336e3a197..de45c3fe4f3 100644 --- a/application/helpers/userstatistics_helper.php +++ b/application/helpers/userstatistics_helper.php @@ -2804,15 +2804,10 @@ public function generate_statistics($surveyid, $allfields, $q2show = 'all', $use break; case 'html': $sGoogleMapsAPIKey = trim(Yii::app()->getConfig("googleMapsAPIKey")); - if ($sGoogleMapsAPIKey != '') { - $sGoogleMapsAPIKey = '&key=' . $sGoogleMapsAPIKey; + if (!empty($sGoogleMapsAPIKey)) { + $sOutputHTML .= "\n"; } - $sSSL = ''; - if (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != "off") { - $sSSL = 's'; - } - $sOutputHTML .= "\n" - . ""; + $sOutputHTML .= ""; return $sOutputHTML; break; From 5040c5861e472a8623355bf34e24b5ad97a3bc92 Mon Sep 17 00:00:00 2001 From: Carsten Schmitz Date: Mon, 29 Mar 2021 08:40:46 +0200 Subject: [PATCH 09/13] Fixed issue: Google Maps being loaded even though no API key is set --- application/helpers/admin/statistics_helper.php | 7 +++---- application/helpers/qanda_helper.php | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/application/helpers/admin/statistics_helper.php b/application/helpers/admin/statistics_helper.php index 3c646c53dd3..64c85bf2554 100644 --- a/application/helpers/admin/statistics_helper.php +++ b/application/helpers/admin/statistics_helper.php @@ -3741,11 +3741,10 @@ public function generate_html_chartjs_statistics($surveyid, $allfields, $q2show } //end if -> show summary results $sGoogleMapsAPIKey = trim(Yii::app()->getConfig("googleMapsAPIKey")); - if ($sGoogleMapsAPIKey != '') { - $sGoogleMapsAPIKey = '&key=' . $sGoogleMapsAPIKey; + if (!empty($sGoogleMapsAPIKey)) { + $sOutputHTML .= "\n"; } - $sOutputHTML .= "\n" - . ""; + $sOutputHTML .= ""; return $sOutputHTML; diff --git a/application/helpers/qanda_helper.php b/application/helpers/qanda_helper.php index 16c4ab54de7..1a17cf619e4 100644 --- a/application/helpers/qanda_helper.php +++ b/application/helpers/qanda_helper.php @@ -2381,7 +2381,6 @@ function do_shortfreetext($ia) { global $thissurvey; - $sGoogleMapsAPIKey = trim(Yii::app()->getConfig("googleMapsAPIKey")); $coreClass = "ls-answers answer-item text-item"; $extraclass = ""; $aQuestionAttributes = QuestionAttribute::model()->getQuestionAttributes($ia[0]); @@ -2521,6 +2520,7 @@ function do_shortfreetext($ia) $currentLocation = $currentLatLong[0] . " " . $currentLatLong[1]; Yii::app()->getClientScript()->registerScriptFile(Yii::app()->getConfig('generalscripts') . "map.js", LSYii_ClientScript::POS_END); + $sGoogleMapsAPIKey = trim(Yii::app()->getConfig("googleMapsAPIKey")); if ($aQuestionAttributes['location_mapservice'] == 1 && !empty($sGoogleMapsAPIKey)) { Yii::app()->getClientScript()->registerScriptFile("//maps.googleapis.com/maps/api/js?sensor=false&key={$sGoogleMapsAPIKey}", LSYii_ClientScript::POS_BEGIN); } elseif ($aQuestionAttributes['location_mapservice'] == 2) { From 0e7d342188482f29d14bf84b9320565f86382d7b Mon Sep 17 00:00:00 2001 From: Carsten Schmitz Date: Mon, 29 Mar 2021 08:41:38 +0200 Subject: [PATCH 10/13] Fixed issue: Google Maps being loaded even though no API key is set --- application/helpers/admin/statistics_helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/helpers/admin/statistics_helper.php b/application/helpers/admin/statistics_helper.php index 64c85bf2554..f14a6a45b5f 100644 --- a/application/helpers/admin/statistics_helper.php +++ b/application/helpers/admin/statistics_helper.php @@ -3524,7 +3524,7 @@ public function generate_simple_statistics($surveyid, $allfields, $q2show = 'all $sOutputHTML .= ''; $sGoogleMapsAPIKey = trim(Yii::app()->getConfig("googleMapsAPIKey")); - if (!empty($sGoogleMapsAPIKey != '')) { + if (!empty($sGoogleMapsAPIKey)) { $sOutputHTML .= "\n"; } From 0eb34617a312bb6006057c5cbd89f109c43cc7ce Mon Sep 17 00:00:00 2001 From: Patrick Teichmann Date: Fri, 12 Mar 2021 12:40:41 +0100 Subject: [PATCH 11/13] Fixed issue #16575: Token not marked as answered if email encryption is turned on --- application/helpers/frontend_helper.php | 3 +- .../views/admin/super/layout_insurvey.php | 106 +++++++++--------- 2 files changed, 55 insertions(+), 54 deletions(-) diff --git a/application/helpers/frontend_helper.php b/application/helpers/frontend_helper.php index 3b9c5ed4a3b..7084ff7bcfb 100644 --- a/application/helpers/frontend_helper.php +++ b/application/helpers/frontend_helper.php @@ -422,7 +422,8 @@ function submittokens($quotaexit = false) } $token->usesleft--; } - $token->save(); + $token->decrypt(); + $token->encryptSave(); if ($quotaexit == false) { if ($token && trim(strip_tags($thissurvey['email_confirm'])) != "" && $thissurvey['sendconfirmation'] == "Y") { diff --git a/application/views/admin/super/layout_insurvey.php b/application/views/admin/super/layout_insurvey.php index 9e3daaa92f1..e4263d939d4 100644 --- a/application/views/admin/super/layout_insurvey.php +++ b/application/views/admin/super/layout_insurvey.php @@ -7,67 +7,67 @@ //headers will be generated with the template file /admin/super/header.php $this->_showHeaders($aData, false); - //The adminmenu bar will be generated from /admin/super/adminmenu.php - $this->_showadminmenu($aData); +//The adminmenu bar will be generated from /admin/super/adminmenu.php +$this->_showadminmenu($aData); + +// Generated through /admin/usergroup/usergroupbar_view +$this->_userGroupBar($aData); + +echo ""; +// Needed to evaluate EM expressions in question summary +// See bug #11845 +LimeExpressionManager::StartProcessingPage(false, true); +$aData['debug'] = $aData; +$this->_titlebar($aData); + +//The load indicator for pjax +echo '
'; + +// echo "
".print_r($aData, true)."
"; + +//The container to hold the vuejs application +echo ' +
'; + //Rendered through /admin/super/sidemenu + $this->_surveysidemenu($aData); + echo '
'; - // Generated through /admin/usergroup/usergroupbar_view - $this->_userGroupBar($aData); + echo '
'; + echo LayoutHelper::renderTopbar($aData); - echo ""; - // Needed to evaluate EM expressions in question summary - // See bug #11845 - LimeExpressionManager::StartProcessingPage(false, true); - $aData['debug'] = $aData; - $this->_titlebar($aData); + //Rendered through /admin/responses/browsemenubar_view + //$this->_browsemenubar($aData); + //Rendered through /admin/survey/Question/questionbar_view + $this->_organizequestionbar($aData); - //The load indicator for pjax - echo '
'; + echo '
'; - // echo "
".print_r($aData, true)."
"; + //Rendered through /admin/update/_update_notification + $this->_updatenotification(); + //Rendered through /notifications/notifications + $this->_notifications(); + + //// Here the main content views. + //Rendered through /admin/survey/QuestionGroups/listquestiongroups + $this->_listquestiongroups($aData); + //Rendered through /admin/survey/Question/listquestions + $this->_listquestions($aData); + //Rendered through /admin/super/sidebody + //With content of /admin/survey/surveySummary_view + $this->_nsurveysummary($aData); + + echo $content; - //The container to hold the vuejs application - echo ' -
'; - //Rendered through /admin/super/sidemenu - $this->_surveysidemenu($aData); - echo '
'; - - echo '
'; - echo LayoutHelper::renderTopbar($aData); - - //Rendered through /admin/responses/browsemenubar_view - //$this->_browsemenubar($aData); - //Rendered through /admin/survey/Question/questionbar_view - $this->_organizequestionbar($aData); - - echo '
'; - - //Rendered through /admin/update/_update_notification - $this->_updatenotification(); - //Rendered through /notifications/notifications - $this->_notifications(); - - //// Here the main content views. - //Rendered through /admin/survey/QuestionGroups/listquestiongroups - $this->_listquestiongroups($aData); - //Rendered through /admin/survey/Question/listquestions - $this->_listquestions($aData); - //Rendered through /admin/super/sidebody - //With content of /admin/survey/surveySummary_view - $this->_nsurveysummary($aData); - - echo $content; - - echo "
\n"; echo "
\n"; echo "
\n"; echo "
\n"; +echo "
\n"; echo ""; // Footer From d97b9c942c9f0781f537bead588d2876be41eb76 Mon Sep 17 00:00:00 2001 From: Patrick Teichmann Date: Wed, 17 Mar 2021 09:55:14 +0100 Subject: [PATCH 12/13] Fixed issue: CPDB Participant cannot be copied to survey if attributes are encrypted --- .../controllers/admin/participantsaction.php | 13 ++------ application/models/LSActiveRecord.php | 3 +- application/models/Participant.php | 31 ++++++++++--------- 3 files changed, 20 insertions(+), 27 deletions(-) diff --git a/application/controllers/admin/participantsaction.php b/application/controllers/admin/participantsaction.php index e23f4114452..c0b99d4ea19 100644 --- a/application/controllers/admin/participantsaction.php +++ b/application/controllers/admin/participantsaction.php @@ -2486,13 +2486,13 @@ public function addToTokenattmap() * mapped[attribute_38] = 39 * meaning that an attribute is mapped onto another. */ - $mappedAttributes = Yii::app()->request->getPost('mapped'); + $mappedAttributes = Yii::app()->request->getPost('mapped', []); /** * newarr takes values like * newarr[] = 39 */ - $newAttributes = Yii::app()->request->getPost('newarr'); + $newAttributes = Yii::app()->request->getPost('newarr', []); $options = array(); $options['overwriteauto'] = Yii::app()->request->getPost('overwrite') === 'true'; @@ -2500,15 +2500,6 @@ public function addToTokenattmap() $options['overwritest'] = Yii::app()->request->getPost('overwritest') === 'true'; $options['createautomap'] = Yii::app()->request->getPost('createautomap') === 'true'; - // TODO: Why? - if (empty($newAttributes[0])) { - $newAttributes = array(); - } - - if (empty($mappedAttributes)) { - $mappedAttributes = array(); - } - try { $response = Participant::model()->copyCPDBAttributesToTokens($surveyId, $participantIds, $mappedAttributes, $newAttributes, $options); } diff --git a/application/models/LSActiveRecord.php b/application/models/LSActiveRecord.php index f7a1132b89f..82ab0697312 100644 --- a/application/models/LSActiveRecord.php +++ b/application/models/LSActiveRecord.php @@ -244,6 +244,7 @@ public function findAllByAttributes($attributes, $condition = '', $params = arra * @param int $iSurveyId * @param string $sClassName * @return array + * TODO: Should be split into seperate functions in the appropiate model or helper class */ public function getAllEncryptedAttributes($iSurveyId = 0, $sClassName) { @@ -357,7 +358,7 @@ public static function decryptSingle($value = '') /** * Enrypt single value - * @param string $value String value which needs to be decrypted + * @param string $value String value which needs to be encrypted */ public static function encryptSingle($value = '') { diff --git a/application/models/Participant.php b/application/models/Participant.php index 2800faa120c..5da1e90265c 100755 --- a/application/models/Participant.php +++ b/application/models/Participant.php @@ -1675,6 +1675,7 @@ private function writeParticipantsToTokenTable( $blacklistSkipped++; continue; } + $oParticipant->decrypt(); $isDuplicate = array_reduce($oTokens, function ($carry, $oToken) use ($oParticipant) { return $carry ? $carry : ($oToken->participant_id == $oParticipant->participant_id); }, false); @@ -1723,7 +1724,7 @@ private function writeParticipantsToTokenTable( $oToken->lastname = $oParticipant->lastname; $oToken->email = $oParticipant->email; $oToken->language = $oParticipant->language; - if (!$oToken->save()) { + if (!$oToken->encryptSave(true)) { throw new Exception(CHtml::errorSummary($oToken)); } $insertedtokenid = $oToken->tid; @@ -1809,10 +1810,10 @@ public function copyCPDBAttributesToTokens($surveyId, array $participantIds, arr $this->checkColumnDuplicates($surveyId, $newAttributes); // TODO: Why use two variables for this? - list($addedAttributes, $addedAttributeIds) = $this->createColumnsInTokenTable($surveyId, $newAttributes); + [$addedAttributes, $addedAttributeIds] = $this->createColumnsInTokenTable($surveyId, $newAttributes); //Write each participant to the survey survey participants table - list($successful, $duplicate, $blacklistSkipped) = $this->writeParticipantsToTokenTable( + [$successful, $duplicate, $blacklistSkipped] = $this->writeParticipantsToTokenTable( $surveyId, $participantIds, $mappedAttributes, @@ -1822,13 +1823,13 @@ public function copyCPDBAttributesToTokens($surveyId, array $participantIds, arr $options ); - $returndata = array( - 'success' => $successful, - 'duplicate' => $duplicate, + $returndata = [ + 'success' => $successful, + 'duplicate' => $duplicate, 'blacklistskipped' => $blacklistSkipped, - 'overwriteauto' => $options['overwriteauto'], - 'overwriteman' => $options['overwriteman'] - ); + 'overwriteauto' => $options['overwriteauto'], + 'overwriteman' => $options['overwriteman'] + ]; return $returndata; } @@ -2230,13 +2231,13 @@ public static function getParticipantsEncryptionOptions() if (empty($aOptions)) { $aOptions = Participant::getDefaultEncryptionOptions(); return $aOptions; - } else { - $aOptionReturn['enabled'] = 'Y'; - foreach ($aOptions as $key => $value) { - $aOptionReturn['columns'][$value['defaultname']] = $value['encrypted']; - } - return $aOptionReturn; } + + $aOptionReturn['enabled'] = 'Y'; + foreach ($aOptions as $key => $value) { + $aOptionReturn['columns'][$value['defaultname']] = $value['encrypted']; + } + return $aOptionReturn; } public static function getDefaultEncryptionOptions() From be5981ca805f4ea431999da2f6107ab57c4cc216 Mon Sep 17 00:00:00 2001 From: Patrick Teichmann Date: Wed, 17 Mar 2021 10:25:32 +0100 Subject: [PATCH 13/13] Fixed issue #16499: CPDB table not accessible after copying unencrypted Participant to CPDB --- application/models/Participant.php | 74 +++++++++++++++--------------- 1 file changed, 38 insertions(+), 36 deletions(-) diff --git a/application/models/Participant.php b/application/models/Participant.php index 5da1e90265c..3bceb280c0a 100755 --- a/application/models/Participant.php +++ b/application/models/Participant.php @@ -1941,7 +1941,7 @@ public function copyToCentral($surveyid, $aAttributesToBeCreated, $aMapped, $ove $tokenids = json_decode($tokenid_string, true); $duplicate = 0; $sucessfull = 0; - $attid = array(); //Will store the CPDB attribute_id of new or existing attributes keyed by CPDB at + $attid = []; //Will store the CPDB attribute_id of new or existing attributes keyed by CPDB at $aTokenAttributes = decodeTokenAttributes($survey->attributedescriptions); $aAutoMapped=$survey->getCPDBMappings(); @@ -1953,22 +1953,22 @@ public function copyToCentral($surveyid, $aAttributesToBeCreated, $aMapped, $ove /* $key is the fieldname from the survey participants table (ie "attribute_1") * $value is the 'friendly name' for the attribute (ie "Gender") */ - $insertnames = array( + $insertnames = [ 'attribute_type' => 'TB', - 'visible' => 'Y', - 'encrypted' => $aTokenAttributes[$key]['encrypted'], - 'defaultname' => $value - ); + 'visible' => 'Y', + 'encrypted' => $aTokenAttributes[$key]['encrypted'], + 'defaultname' => $value + ]; $oParticipantAttributeNames = new ParticipantAttributeName(); $oParticipantAttributeNames->setAttributes($insertnames, false); $oParticipantAttributeNames->save(false); $attid[$key] = $oParticipantAttributeNames->getPrimaryKey(); - $insertnameslang = array( - 'attribute_id' => $attid[$key], + $insertnameslang = [ + 'attribute_id' => $attid[$key], 'attribute_name' => urldecode($value), - 'lang' => Yii::app()->session['adminlang'] - ); + 'lang' => Yii::app()->session['adminlang'] + ]; $oParticipantAttributeNamesLang = new ParticipantAttributeNameLang(); $oParticipantAttributeNamesLang->setAttributes($insertnameslang, false); $oParticipantAttributeNamesLang->save(false); @@ -1977,12 +1977,15 @@ public function copyToCentral($surveyid, $aAttributesToBeCreated, $aMapped, $ove /* Add the participants to the CPDB = Iterate through each $tokenid and create the new CPDB id*/ if (!is_array($tokenids)) { - $tokenids = (array) $tokenids; + $tokenids = (array)$tokenids; } foreach ($tokenids as $tid) { if (is_numeric($tid) && $tid != "") { /* Get the data for this participant from the tokens table */ $oTokenDynamic = TokenDynamic::model($survey->sid)->findByPk($tid); + if (isset($oTokenDynamic) && $oTokenDynamic) { + $oTokenDynamic->decrypt(); + } /* See if there are any existing CPDB entries that match on firstname,lastname and email */ $participantCriteria = new CDbCriteria(); @@ -1991,8 +1994,8 @@ public function copyToCentral($surveyid, $aAttributesToBeCreated, $aMapped, $ove $participantCriteria->addCondition('email = :email'); $participantCriteria->params = [ ":firstname" => $oTokenDynamic->firstname, - ":lastname" => $oTokenDynamic->lastname, - ":email" => $oTokenDynamic->email, + ":lastname" => $oTokenDynamic->lastname, + ":email" => $oTokenDynamic->email, ]; $existing = Participant::model()->find($participantCriteria); /* If there is already an existing entry, add to the duplicate count */ @@ -2007,31 +2010,30 @@ public function copyToCentral($surveyid, $aAttributesToBeCreated, $aMapped, $ove foreach ($aAutoMapped as $cpdbatt => $tatt) { Participant::model()->updateAttributeValueToken($surveyid, $existing->participant_id, $cpdbatt, $tatt); } - } - } - /* If there isn't an existing entry, create one! */ else { + } + } /* If there isn't an existing entry, create one! */ else { /* Create entry in participants table */ $black = !empty($oTokenDynamic->blacklisted) ? $oTokenDynamic->blacklisted : 'N'; $pid = !empty($oTokenDynamic->participant_id) ? $oTokenDynamic->participant_id : $this->gen_uuid(); - $writearray = array( + $writearray = [ 'participant_id' => $pid, - 'firstname' => $oTokenDynamic->firstname, - 'lastname' => $oTokenDynamic->lastname, - 'email' => $oTokenDynamic->email, - 'language' => $oTokenDynamic->language, - 'blacklisted' => $black, - 'owner_uid' => Yii::app()->session['loginID'], - 'created_by' => Yii::app()->session['loginID'], - 'created' => date('Y-m-d H:i:s', time()) - ); + 'firstname' => $oTokenDynamic->firstname, + 'lastname' => $oTokenDynamic->lastname, + 'email' => $oTokenDynamic->email, + 'language' => $oTokenDynamic->language, + 'blacklisted' => $black, + 'owner_uid' => Yii::app()->session['loginID'], + 'created_by' => Yii::app()->session['loginID'], + 'created' => date('Y-m-d H:i:s', time()) + ]; $oParticipant = new Participant(); $oParticipant->setAttributes($writearray, false); - $oParticipant->save(false); + $oParticipant->encryptSave(); //Update survey participants table and insert the new UUID $oTokenDynamic->participant_id = $pid; - $oTokenDynamic->save(false); + $oTokenDynamic->encryptSave(); /* Now add any new attribute values */ if (!empty($aAttributesToBeCreated)) { @@ -2049,12 +2051,12 @@ public function copyToCentral($surveyid, $aAttributesToBeCreated, $aMapped, $ove /* Create a survey_link */ $oSurveyLink = new SurveyLink(); - $data = array( + $data = [ 'participant_id' => $pid, - 'token_id' => $tid, - 'survey_id' => $surveyid, - 'date_created' => date('Y-m-d H:i:s', time()) - ); + 'token_id' => $tid, + 'survey_id' => $surveyid, + 'date_created' => date('Y-m-d H:i:s', time()) + ]; $oSurveyLink->setAttributes($data, false); $oSurveyLink->save(false); } @@ -2070,7 +2072,7 @@ public function copyToCentral($surveyid, $aAttributesToBeCreated, $aMapped, $ove } Yii::app()->db ->createCommand() - ->update('{{surveys}}', array("attributedescriptions" => json_encode($aAttributes)), 'sid = ' . $surveyid); + ->update('{{surveys}}', ["attributedescriptions" => json_encode($aAttributes)], 'sid = ' . $surveyid); } if (!empty($aMapped)) { foreach ($aMapped as $cpdbatt => $tatt) { @@ -2079,10 +2081,10 @@ public function copyToCentral($surveyid, $aAttributesToBeCreated, $aMapped, $ove } Yii::app()->db ->createCommand() - ->update('{{surveys}}', array("attributedescriptions" => json_encode($aAttributes)), 'sid = ' . $surveyid); + ->update('{{surveys}}', ["attributedescriptions" => json_encode($aAttributes)], 'sid = ' . $surveyid); } } - $returndata = array('success' => $sucessfull, 'duplicate' => $duplicate, 'overwriteauto' => $overwriteauto, 'overwriteman' => $overwriteman); + $returndata = ['success' => $sucessfull, 'duplicate' => $duplicate, 'overwriteauto' => $overwriteauto, 'overwriteman' => $overwriteman]; return $returndata; }