Skip to content

Commit

Permalink
Fixed issue #16122: Encryption of "email" field in participants datab…
Browse files Browse the repository at this point in the history
…ase: Limesurvey does not mark participant as invited

Dev: decrypt when load, encrypt when save
Dev: Add the validation error in tokenoutput in case
Dev: Remove some unused var
  • Loading branch information
Shnoulle committed Apr 24, 2020
1 parent 0e47d3f commit 69c8914
Showing 1 changed file with 14 additions and 16 deletions.
30 changes: 14 additions & 16 deletions application/controllers/admin/tokens.php
Expand Up @@ -1385,13 +1385,6 @@ public function email($iSurveyId)
initKcfinder();
Yii::app()->loadHelper('replacements');

$oToken = Token::model($iSurveyId)->find();
$token = null;
if ($oToken !== null) {
$token = Token::model($iSurveyId)->find()->decrypt();
}

$aExampleRow = isset($token) ? $token->attributes : array();
$aSurveyLangs = Survey::model()->findByPk($iSurveyId)->additionalLanguages;
$sBaseLanguage = Survey::model()->findByPk($iSurveyId)->language;
array_unshift($aSurveyLangs, $sBaseLanguage);
Expand All @@ -1410,12 +1403,10 @@ public function email($iSurveyId)
$aData['baselang'] = $sBaseLanguage;
$aData['tokenfields'] = array_keys($aTokenFields);
$aData['nrofattributes'] = $iAttributes;
$aData['examplerow'] = $aExampleRow;
$aData['tokenids'] = $aTokenIds;
$aData['ishtml'] = $bHtml;
$aData['reminderbutton'] = (Yii::app()->request->getParam('action') == "remind");


$iMaxEmails = Yii::app()->getConfig('maxemails');

// TODO: Rename 'ok' to something meaningful.
Expand Down Expand Up @@ -1476,18 +1467,24 @@ public function email($iSurveyId)
$success = $mail->sendMessage();
$stringInfo = CHtml::encode("{$emrow['tid']}: {$emrow['firstname']} {$emrow['lastname']} ({$emrow['email']}).");
if ($success) {
// Put date into sent
$token = Token::model($iSurveyId)->findByPk($emrow['tid']);
// Load token to set as sent, no need to check existence ? we just send the email
$oToken = Token::model($iSurveyId)->findByPk($emrow['tid'])->decrypt();
if ($bIsInvitation) {
$tokenoutput .= gT("Invitation sent to:");
$token->sent = dateShift(date("Y-m-d H:i:s"), "Y-m-d H:i", Yii::app()->getConfig("timeadjust"));
$oToken->sent = dateShift(date("Y-m-d H:i:s"), "Y-m-d H:i", Yii::app()->getConfig("timeadjust"));
} else {
$tokenoutput .= gT("Reminder sent to:");
$token->remindersent = dateShift(date("Y-m-d H:i:s"), "Y-m-d H:i", Yii::app()->getConfig("timeadjust"));
$token->remindercount++;
$oToken->remindersent = dateShift(date("Y-m-d H:i:s"), "Y-m-d H:i", Yii::app()->getConfig("timeadjust"));
$oToken->remindercount++;
}
$tokenSaveError = "";
if(!$oToken->encryptSave(true)) {
// Add the error when try to save token
$tokenSaveError = CHtml::errorSummary(
$oToken,
CHtml::tag("div",array('class'=>'text-warning'),sprintf(gT("An error happen when save this survey participant email sent date (id:%s)"),$emrow['tid']))
);
}
$token->save();

// Mark token email as send this session.
// NB: This cache is cleared on form page for invitation/reminder.
$sType = $bIsInvitation?'i':'r';
Expand All @@ -1505,6 +1502,7 @@ public function email($iSurveyId)
if (Yii::app()->getConfig("emailsmtpdebug") > 1) {
$tokenoutput .= $mail->getDebug('html');
}
$tokenoutput .= $tokenSaveError;
} else {
$maildebug = $mail->getDebug('html');
$tokenoutput .= $stringInfo.CHtml::tag("span",array('class'=>"text-warning"),sprintf(gT("Error message: %s"), $mail->getError()))."<br>\n";
Expand Down

0 comments on commit 69c8914

Please sign in to comment.