diff --git a/application/helpers/SurveyRuntimeHelper.php b/application/helpers/SurveyRuntimeHelper.php
index ecb345bcb4a..7637280f06b 100644
--- a/application/helpers/SurveyRuntimeHelper.php
+++ b/application/helpers/SurveyRuntimeHelper.php
@@ -1269,10 +1269,6 @@ public static function getQuestionReplacement($aQuestionQanda)
$aReplacement['QUESTION']=$aQuestionQanda[0]['all'] ; // Deprecated : only used in old template (very old)
// Core value : user text
$aReplacement['QUESTION_TEXT'] = $aQuestionQanda[0]['text'];
- if ($sType == '*')
- {
- $aReplacement['QUESTION_TEXT'] = '
' .$aReplacement['QUESTION_TEXT']. '
';
- }
$aReplacement['QUESTIONHELP']=$lemQuestionInfo['info']['help'];// User help
// To be moved in a extra plugin : QUESTIONHELP img adding
$sTemplateDir=Template::model()->getTemplatePath($oSurveyId->template);
diff --git a/application/helpers/common_helper.php b/application/helpers/common_helper.php
index 1a60fbc5863..4d491fe3211 100644
--- a/application/helpers/common_helper.php
+++ b/application/helpers/common_helper.php
@@ -2809,6 +2809,15 @@ function questionAttributes($returnByName=false)
"help"=>gT('Enter a header text for the second scale'),
"caption"=>gT('Header for second scale'));
+ $qattributes["equation"]=array(
+ "types"=>"*",
+ 'category'=>gT('Logic'),
+ 'sortorder'=>100,
+ 'inputtype'=>'textarea',
+ "help"=>gT('Final equation to set in database, default to question text.'),
+ "caption"=>gT('Equation'),
+ "default"=>"");
+
$qattributes["equals_num_value"]=array(
"types"=>"K",
'category'=>gT('Input'),
diff --git a/application/helpers/expressions/em_manager_helper.php b/application/helpers/expressions/em_manager_helper.php
index a2ce05ea32f..69995b4a669 100644
--- a/application/helpers/expressions/em_manager_helper.php
+++ b/application/helpers/expressions/em_manager_helper.php
@@ -4038,7 +4038,7 @@ private function setVariableAndTokenMappingsForExpressionManager($surveyid,$forc
'hidden'=>$hidden,
'gid'=>$groupNum,
'mandatory'=>$mandatory,
- 'eqn'=>(($type == '*') ? $question : ''),
+ 'eqn'=>'',
'help'=>$help,
'qtext'=>$fielddata['question'], // $question,
'code'=>$varName,
@@ -6565,7 +6565,8 @@ function _ValidateQuestion($questionSeq,$force=false)
elseif ($qInfo['type'] == '*')
{
// Process relevant equations, even if hidden, and write the result to the database
- $result = flattenText($LEM->ProcessString($qInfo['eqn'], $qInfo['qid'],NULL,false,1,1,false,false));
+ $textToParse=(isset($LEM->qattr[$qid]['equation']) && trim($LEM->qattr[$qid]['equation'])!="") ? $LEM->qattr[$qid]['equation'] : $qInfo['qtext'];
+ $result = flattenText($LEM->ProcessString($textToParse, $qInfo['qid'],NULL,false,1,1,false,false,true));// More numRecursionLevels ?
$sgqa = $LEM->qid2code[$qid]; // there will be only one, since Equation
if($LEM->knownVars[$sgqa]['onlynum'])
{
@@ -7312,11 +7313,9 @@ static function GetRelevanceAndTailoringJavaScript()
{
$relParts[] = " // Write value from the question into the answer field\n";
$jsResultVar = $LEM->em->GetJsVarFor($arg['jsResultVar']);
- // Note, this will destroy embedded HTML in the equation (e.g. if it is a report)
- // Should be possible to use jQuery to remove just the LEMtailoring span, but not easy since done (the following doesn't work)
- // _tmpval = $('#question801 .em_equation').clone()
- // $(_tmpval).find('[id^=LEMtailor]').each(function(){ $(this).replaceWith(function(){ $(this).contents; }); })
- $relParts[] = " $('#" . substr($jsResultVar,1,-1) . "').val($.trim(LEMstrip_tags($('#question" . $arg['qid'] . " .em_equation').html())));\n";
+ // Note, this will destroy embedded HTML in the equation (e.g. if it is a report, can use {QCODE.question} for this purpose)
+ // This make same than flattenText to be same in JS and in PHP
+ $relParts[] = " $('#" . substr($jsResultVar,1,-1) . "').val($.trim($('#question" . $arg['qid'] . " .em_equation').text()));\n";
}
$relParts[] = " relChange" . $arg['qid'] . "=true;\n"; // any change to this value should trigger a propagation of changess
$relParts[] = " $('#relevance" . $arg['qid'] . "').val('1');\n";
diff --git a/application/helpers/qanda_helper.php b/application/helpers/qanda_helper.php
index 31d5bd10692..862687ec41b 100644
--- a/application/helpers/qanda_helper.php
+++ b/application/helpers/qanda_helper.php
@@ -857,7 +857,7 @@ function return_array_filter_strings($ia, $aQuestionAttributes, $thissurvey, $an
function do_boilerplate($ia)
{
- $aQuestionAttributes = getQuestionAttributeValues($ia[0], $ia[4]);
+
$answer='';
if (trim($aQuestionAttributes['time_limit'])!='')
@@ -873,16 +873,15 @@ function do_boilerplate($ia)
function do_equation($ia)
{
+ $aQuestionAttributes= getQuestionAttributeValues($ia[0], $ia[4]);
+ $sEquation=(trim($aQuestionAttributes['equation'])) ? $aQuestionAttributes['equation'] : $ia[3];
$answer='';
+ $answer .="