View Issue Details

This bug affects 1 person(s).
 6
IDProjectCategoryView StatusLast Update
09904Feature requestsRemoteControlpublic2016-04-12 10:48
Reporteroenie Assigned ToDenisChenu  
PrioritynormalSeverityfeature 
Status closedResolutionfixed 
Summary09904: Variable EXPIRY of the survey can not be used in Expression when sending an email
Description

When trying to send an email through the Remote Control API, it seems that the Expression manager variable Expiry (as defined for a survey) is viewed as 'unknown'.

Sending the same email through the website (via Token > Send Invitations/Reminders) does not have this problem

Steps To Reproduce
  • Create a survey with tokens
  • Use the variable EXPIRY in one of the emails for the token users.
  • Send one of the emails through Remote Control API using invite_participants or remind_participants

EXPIRY is not replaced in the sent email, listed as 'unknown' by Expression Manager.
Other attributes of the tokens (e.g. firstname) are replaced correctly.

TagsNo tags attached.
Attached Files
issue_9904_expiry_token_remote_control.diff (1,180 bytes)   
diff --git a/application/helpers/admin/token_helper.php b/application/helpers/admin/token_helper.php
index ce4ac27..863dcb5 100644
--- a/application/helpers/admin/token_helper.php
+++ b/application/helpers/admin/token_helper.php
@@ -78,6 +78,7 @@ function emailTokens($iSurveyID,$aResultTokens,$sType)
 
 		$fieldsarray["{ADMINNAME}"] = $oSurvey['admin'];
 		$fieldsarray["{ADMINEMAIL}"] = $oSurvey['adminemail'];
+		$fieldsarray["{EXPIRY}"] = $oSurvey['expires'];
 		$from = $fieldsarray["{ADMINNAME}"] . ' <' . $fieldsarray["{ADMINEMAIL}"] . '>';
 		if($from ==  '')
 			$from = Yii::app()->getConfig('siteadminemail');
@@ -128,8 +129,10 @@ function emailTokens($iSurveyID,$aResultTokens,$sType)
 			$sMessage = $aSurveyLocaleData[$sTokenLanguage]['surveyls_email_remind'];
 		}
 
-		$modsubject = Replacefields($sSubject, $fieldsarray);
-		$modmessage = Replacefields($sMessage, $fieldsarray);
+		$modsubject = Replacefields($sSubject, $fieldsarray, false);
+		$modsubject = Replacefields($modsubject, $fieldsarray);
+		$modmessage = Replacefields($sMessage, $fieldsarray, false);
+		$modmessage = Replacefields($modmessage, $fieldsarray);
 
 		if (isset($barebone_link))
 		{
Bug heat6
Story point estimate
Users affected %

Users monitoring this issue

There are no users monitoring this issue.

Activities

c_schmitz

c_schmitz

2015-09-30 13:16

administrator   ~33249

Do you still have the problem in the latest version?

oenie

oenie

2015-09-30 15:23

reporter   ~33260

I will have to check it later this month, am currently out of the office.
I'll post back ASAP.

oenie

oenie

2015-09-30 18:32

reporter   ~33267

I have installed the recent (2.06) version of limesurvey on my local computer, and it seems to have the same problem still. It works when I send the email from the web interface, but no EXPIRY date when sending through RemoteControl.

oenie

oenie

2015-10-20 16:28

reporter   ~33401

I've been looking into the problem myself and have found the following solution:

The EXPIRY field was not included in the $fieldsarray in the emailTokens function (application/helpers/admin/token_helper.php)

The global options, including EXPIRY, are already parsed through ReplaceFields in the views when going through the Webinterface (e.g. see the code in application/views/admin/token/invite.php), before passing to the same emailTokens function later.

What is interesting to note here (a second problem for me) is that the function call to ReplaceFields in the views is used with the parameter bReplaceInsertans set to FALSE.

In my own example, the EXPIRY variable was wrapped inside a function to format it according to a specific pattern ({strftime('%e %B %Y', strtotime('{EXPIRY}'))}). EXPIRY here needs to be replaced first by calling ReplaceFields with $bReplaceInsertans to FALSE, or it will be lost.

To solve both problems i have added a diff to the most recent code (checked out 2.06 build 151018 with git):

  • Added the field 'expiry' to the fieldarray from the Global survey data

  • Run the subject & message of the mail to send through an extra call of ReplaceFields with bReplaceInsertans to FALSE
    (That way, wrapped insertans fields like my EXPIRY above will be parsed correctly too)
    This does not seem to interfere with the extra call to ReplaceFields when going through the WebInterface.

Hope that helps !

oenie

oenie

2015-10-29 00:06

reporter   ~33462

Reminder sent to: c_schmitz

Hi

Just wondering if you have had the time to look at my suggested fix.

Kind regards,

Jeroen

DenisChenu

DenisChenu

2015-12-09 11:14

developer   ~33793

Why doing Replacefields(Replacefields($sSubject)) ?

You don't have to Replacefields 2 times.

oenie

oenie

2015-12-09 11:18

reporter   ~33794

It was mentioned in my previous note, and the reason of the whole problem:

It is called 2 times, but once with the bReplaceInsertans to FALSE and then with it set to TRUE. Doing this allows the INSERTANS fields to be parsed to.

Quote:

In my own example, the EXPIRY variable was wrapped inside a function to format it according to a specific pattern ({strftime('%e %B %Y', strtotime('{EXPIRY}'))}). EXPIRY here needs to be replaced first by calling ReplaceFields with $bReplaceInsertans to FALSE, or it will be lost.

DenisChenu

DenisChenu

2015-12-09 11:29

developer   ~33798

You don't have to add the { inside an expression ....

{strftime('%e %B %Y', strtotime(EXPIRY))})

Musty work (and if not : must be fixed)

oenie

oenie

2015-12-09 11:37

reporter   ~33800

I'm afraid that does not work, and i wasn't expecting it to.
If you leave out the {...} around the EXPIRY string, how would the ExpressionManager be able to tell apart an ordinary string from an INSERTANS field ? it would need to read the whole string and see if it detects any fields that might be an INSERTANS ?

What if i wanted to use a function to concatenate a piece of text with the string 'EXPIRY' (or any other existing INSERTANS field for that matter) ? Then it would always replace the strings with their value counterparts, no ?

DenisChenu

DenisChenu

2015-12-09 16:51

developer   ~33820

1st : strftime don't exist.

2nd : IN GUI too : EXPIRY is not replaced with EM.
(same for other var : SURVEYDESCITION, ADMINNAME etc ...)

DenisChenu

DenisChenu

2015-12-09 17:27

developer   ~33826

Fix committed to master branch: http://bugs.limesurvey.org/plugin.php?page=Source/view&amp;id=16446

DenisChenu

DenisChenu

2015-12-09 17:27

developer   ~33827

2.06

c_schmitz

c_schmitz

2016-04-12 10:48

administrator   ~37245

Version 2.50+ Build 140413 released

Related Changesets

LimeSurvey: master e30ac928

2015-12-09 16:26:56

DenisChenu

Details Diff
New feature 09904 : allow to use EXPIRY in expression when sending email
Dev: Think SURVEYNAME/ADMINNAM etc ... don't have to be used
Dev: maybe adding it when have same function for GUI and for RC
Affected Issues
09904
mod - application/controllers/admin/tokens.php Diff File
mod - application/helpers/admin/token_helper.php Diff File

Issue History

Date Modified Username Field Change
2015-09-20 23:46 oenie New Issue
2015-09-30 13:16 c_schmitz Assigned To => c_schmitz
2015-09-30 13:16 c_schmitz Status new => assigned
2015-09-30 13:16 c_schmitz Note Added: 33249
2015-09-30 13:16 c_schmitz Status assigned => feedback
2015-09-30 15:23 oenie Note Added: 33260
2015-09-30 15:23 oenie Status feedback => assigned
2015-09-30 18:32 oenie Note Added: 33267
2015-10-20 16:27 oenie File Added: issue_9904_expiry_token_remote_control.diff
2015-10-20 16:28 oenie Note Added: 33401
2015-10-29 00:06 oenie Note Added: 33462
2015-12-09 10:04 c_schmitz Assigned To c_schmitz => DenisChenu
2015-12-09 11:14 DenisChenu Note Added: 33793
2015-12-09 11:18 oenie Note Added: 33794
2015-12-09 11:29 DenisChenu Note Added: 33798
2015-12-09 11:37 oenie Note Added: 33800
2015-12-09 16:51 DenisChenu Note Added: 33820
2015-12-09 16:51 DenisChenu Project Bug reports => Feature requests
2015-12-09 16:58 DenisChenu Severity @50@ => feature
2015-12-09 16:58 DenisChenu Summary Variable EXPIRY of the survey is not found when used in an e-mail template that is sent through the Remote Control API => Variable EXPIRY of the survey can not be used in Expression when sending an email
2015-12-09 17:27 DenisChenu Changeset attached => LimeSurvey master e30ac928
2015-12-09 17:27 DenisChenu Note Added: 33826
2015-12-09 17:27 DenisChenu Resolution open => fixed
2015-12-09 17:27 DenisChenu Note Added: 33827
2015-12-09 17:27 DenisChenu Status assigned => resolved
2016-04-12 10:48 c_schmitz Note Added: 37245
2016-04-12 10:48 c_schmitz Status resolved => closed