From d7fc05fa93b8098a8a8e522a5f50951cf7c0e553 Mon Sep 17 00:00:00 2001 From: Sam Mousa Date: Sun, 26 Jan 2014 15:32:33 +0100 Subject: [PATCH] Fixed issue #8506 --- .../helpers/expressions/em_manager_helper.php | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/application/helpers/expressions/em_manager_helper.php b/application/helpers/expressions/em_manager_helper.php index 3595e6df548..a3213e0e758 100644 --- a/application/helpers/expressions/em_manager_helper.php +++ b/application/helpers/expressions/em_manager_helper.php @@ -9836,6 +9836,78 @@ public static function getLEMsurveyId() { return $LEM->sid; } + /** + * This function loads the relevant data about tokens for a survey. + * If specific token is not given it loads empty values, this is used for + * question previewing and the like. + * + * @param int $iSurveyId + * @param string $sToken + * @param boolean $bAnonymize + * @return void + */ + public function loadTokenInformation($iSurveyId, $sToken = null, $bAnonymize = false) + { + if (!Survey::model()->hasTokens($iSurveyId)) + { + return; + } + if ($sToken == null && isset($_SESSION[$this->sessid]['token'])) + { + $sToken = $_SESSION[$this->sessid]['token']; + } + else + { + $sToken = null; + } + + $aToken = getTokenData($iSurveyId, $sToken); + + $this->knownVars['TOKEN:TOKEN'] = array( + 'code'=> $sToken, + 'jsName_on'=>'', + 'jsName'=>'', + 'readWrite'=>'N', + ); + + if (isset($aToken)) + { + foreach ($aToken as $key => $val) + { + if ($bAnonymize) + { + $val = ""; + } + $key = "TOKEN:" . strtoupper($key); + $this->knownVars[$key] = array( + 'code'=>$val, + 'jsName_on'=>'', + 'jsName'=>'', + 'readWrite'=>'N', + ); + } + } + else + { + // Read list of available tokens from the tokens table so that preview and error checking works correctly + + $blankVal = array( + 'code'=>'', + 'jsName_on'=>'', + 'jsName'=>'', + 'readWrite'=>'N', + ); + + foreach (getTokenFieldsAndNames($surveyId) as $field => $details) + { + if (preg_match('/^(firstname|lastname|email|usesleft|token|attribute_\d+)$/', $field)) + { + $this->knownVars['TOKEN:' . strtoupper($field)] = $blankVal; + } + } + } + } + } /**