Skip to content

Commit

Permalink
Fixed issue #12101: Placeholder "TOKEN" does not work in Equation que…
Browse files Browse the repository at this point in the history
…stion

Dev: Add it in LimeExpressionManager->setVariableAndTokenMappingsForExpressionManager function
Dev: Add SID too (see #12468)
  • Loading branch information
Shnoulle committed Jun 17, 2017
1 parent 9f8e5e3 commit fadb0cc
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
26 changes: 19 additions & 7 deletions application/helpers/expressions/em_manager_helper.php
Expand Up @@ -3635,7 +3635,13 @@ private function setVariableAndTokenMappingsForExpressionManager($surveyid,$forc
$this->qid2validationEqn = array();
$this->groupSeqInfo = array();
$this->gseq2relevanceStatus = array();

/* Fill some static know vars , the used is always $this->knownVars (even if set in templatereplace function) */
$this->knownVars['SID'] = array(
'code'=>$this->sid,
'jsName_on'=>'',
'jsName'=>'',
'readWrite'=>'N',
);
/* Add the core replacement before question code : needed if use it in equation , use SID to never send error */
templatereplace("{SID}");

Expand Down Expand Up @@ -4228,6 +4234,12 @@ private function setVariableAndTokenMappingsForExpressionManager($surveyid,$forc
'jsName'=>'',
'readWrite'=>'N',
);
$this->knownVars['TOKEN'] = array(
'code'=>$_SESSION[$this->sessid]['token'],
'jsName_on'=>'',
'jsName'=>'',
'readWrite'=>'N',
);

$token = Token::model($surveyid)->findByToken($_SESSION[$this->sessid]['token']);
if($token) {
Expand All @@ -4248,13 +4260,13 @@ private function setVariableAndTokenMappingsForExpressionManager($surveyid,$forc
$attrs = array_keys(getTokenFieldsAndNames($surveyid));

$blankVal = array(
'code'=>'',
'type'=>'',
'jsName_on'=>'',
'jsName'=>'',
'readWrite'=>'N',
'code'=>'',
'type'=>'',
'jsName_on'=>'',
'jsName'=>'',
'readWrite'=>'N',
);

// DON'T set $this->knownVars['TOKEN'] = $blankVal; becuase optout/optin can need it, then don't replace this from templatereplace
foreach ($attrs as $key)
{
if (preg_match('/^(firstname|lastname|email|usesleft|token|attribute_\d+)$/',$key))
Expand Down
2 changes: 1 addition & 1 deletion application/helpers/replacements_helper.php
Expand Up @@ -715,7 +715,7 @@ function templatereplace($line, $replacements = array(), &$redata = array(), $de
$coreReplacements['SAVEFORM'] = $_saveform;
$coreReplacements['SAVEHEADING'] = gT("Save your unfinished survey");
$coreReplacements['SAVEMESSAGE'] = gT("Enter a name and password for this survey and click save below.")."<br />\n".gT("Your survey will be saved using that name and password, and can be completed later by logging in with the same name and password.")."<br /><br />\n<span class='emailoptional'>".gT("If you give an email address, an email containing the details will be sent to you.")."</span><br /><br />\n".gT("After having clicked the save button you can either close this browser window or continue filling out the survey.");
$coreReplacements['SID'] = Yii::app()->getConfig('surveyID','');// Allways use surveyID from config
$coreReplacements['SID'] = Yii::app()->getConfig('surveyID','');// Allways use surveyID from config, leave it to be sure to have something (EM setVariableAndTokenMappingsForExpressionManager replace it)
$coreReplacements['SITENAME'] = Yii::app()->getConfig('sitename');
$coreReplacements['SITELOGO'] = $sitelogo;
$coreReplacements['SUBMITBUTTON'] = $_submitbutton;
Expand Down

0 comments on commit fadb0cc

Please sign in to comment.