diff --git a/admin/tokens.php b/admin/tokens.php index 331ec802b93..73a8b60e352 100644 --- a/admin/tokens.php +++ b/admin/tokens.php @@ -505,6 +505,8 @@ $query = db_rename_table(returnglobal('oldtable') , db_table_name_nq("tokens_$surveyid")); $result=$connect->Execute($query) or safe_die("Failed Rename!
".$query."
".$connect->ErrorMsg()); + LimeExpressionManager::SetDirtyFlag(); // so that knows that token tables have changed + $tokenoutput .= "\t
\n" ."
".$clang->gT("Import old tokens")."
" ."
".$clang->gT("A token table has been created for this survey and the old tokens were imported.")." (\"".$dbprefix."tokens_$surveyid\")

\n" @@ -1371,6 +1373,7 @@ } else { $deactivateresult = $connect->Execute($deactivatequery) or die ("Couldn't deactivate because:
\n".htmlspecialchars($connect->ErrorMsg())." - Query: ".htmlspecialchars($deactivatequery)."

\nAdmin\n"); } + LimeExpressionManager::SetDirtyFlag(); // so that knows that token tables have changed $tokenoutput .= '
'.$clang->gT("The tokens table has now been removed and tokens are no longer required to access this survey.")."
".$clang->gT("A backup of this table has been made and can be accessed by your system administrator.")."
\n" ."(\"{$dbprefix}old_tokens_{$surveyid}_$date\")"."

\n" @@ -2268,6 +2271,8 @@ ."\t\t
\n"; } $tokenoutput .= "\t
"; + + LimeExpressionManager::SetDirtyFlag(); // so that knows that token tables have changed } diff --git a/classes/expressions/LimeExpressionManager.php b/classes/expressions/LimeExpressionManager.php index 62ddc49669b..67b8d8ed9cd 100644 --- a/classes/expressions/LimeExpressionManager.php +++ b/classes/expressions/LimeExpressionManager.php @@ -2374,7 +2374,9 @@ private function setVariableAndTokenMappingsForExpressionManager($surveyid,$forc } else { - // Explicitly set all tokens to blank + // Read list of available tokens from the tokens table so that preview and error checking works correctly + $attrs = GetAttributeFieldNames($surveyid,false); + $blankVal = array( 'code'=>'', 'type'=>'', @@ -2382,14 +2384,13 @@ private function setVariableAndTokenMappingsForExpressionManager($surveyid,$forc 'jsName'=>'', 'readWrite'=>'N', ); - $this->knownVars['TOKEN:FIRSTNAME'] = $blankVal; - $this->knownVars['TOKEN:LASTNAME'] = $blankVal; - $this->knownVars['TOKEN:EMAIL'] = $blankVal; - $this->knownVars['TOKEN:USESLEFT'] = $blankVal; - $this->knownVars['TOKEN:TOKEN'] = $blankVal; - for ($i=1;$i<=100;++$i) // TODO - is there a way to know how many attributes are set? Looks like max is 100 - { - $this->knownVars['TOKEN:ATTRIBUTE_' . $i] = $blankVal; + + foreach ($attrs as $key) + { + if (preg_match('/^(firstname|lastname|email|usesleft|token|attribute_\d+)$/',$key)) + { + $this->knownVars['TOKEN:' . strtoupper($key)] = $blankVal; + } } } // set default value for reserved 'this' variable diff --git a/common_functions.php b/common_functions.php index 7382ad9fbb5..55b97517130 100644 --- a/common_functions.php +++ b/common_functions.php @@ -6514,7 +6514,7 @@ function filterforattributes ($fieldname) * @param mixed $surveyid The survey ID * @return array The fieldnames */ -function GetAttributeFieldNames($surveyid) +function GetAttributeFieldNames($surveyid,$filter=true) { global $dbprefix, $connect; if (tableExists('tokens_'.$surveyid) === false) @@ -6522,7 +6522,11 @@ function GetAttributeFieldNames($surveyid) return Array(); } $tokenfieldnames = array_values($connect->MetaColumnNames("{$dbprefix}tokens_$surveyid", true)); - return array_filter($tokenfieldnames,'filterforattributes'); + if ($filter) + { + return array_filter($tokenfieldnames,'filterforattributes'); + } + return $tokenfieldnames; } /**