Skip to content

Commit

Permalink
Fixed issue #06281: hidden variables used in equations have wrong nam…
Browse files Browse the repository at this point in the history
…e so don't POST properly

Dev Also got variable assignment working, so can use expressions to set values of other variables
  • Loading branch information
TMSWhite committed Jun 26, 2012
1 parent 7b1517e commit b4a81e8
Showing 1 changed file with 62 additions and 19 deletions.
81 changes: 62 additions & 19 deletions application/helpers/expressions/em_manager_helper.php
Expand Up @@ -630,6 +630,11 @@ class LimeExpressionManager {
* @var type
*/
private $qid2exclusiveAuto = array();
/**
* Array of values to be updated
* @var type
*/
private $updatedValues = array();

/**
* A private constructor; prevents direct creation of object
Expand Down Expand Up @@ -2911,7 +2916,7 @@ private function setVariableAndTokenMappingsForExpressionManager($surveyid,$forc
}
$this->qid2code[$questionNum] = $codeList;

$readWrite = 'N';
$readWrite = 'Y';

// Set $ansArray
switch($type)
Expand Down Expand Up @@ -3945,6 +3950,7 @@ static function NavigateBackwards()
$LEM =& LimeExpressionManager::singleton();

$LEM->ParseResultCache=array(); // to avoid running same test more than once for a given group
$LEM->updatedValues = array();

switch ($LEM->surveyMode)
{
Expand Down Expand Up @@ -4077,6 +4083,7 @@ static function NavigateForwards($force=false) {
$LEM =& LimeExpressionManager::singleton();

$LEM->ParseResultCache=array(); // to avoid running same test more than once for a given group
$LEM->updatedValues = array();

switch ($LEM->surveyMode)
{
Expand Down Expand Up @@ -4294,6 +4301,9 @@ static function NavigateForwards($force=false) {
*/
private function _UpdateValuesInDatabase($updatedValues, $finished=false)
{
// TODO - now that using $this->updatedValues, may be able to remove local copies of it (unless needed by other sub-systems)
$updatedValues = $this->updatedValues;

$message = '';
$_SESSION[$this->sessid]['datestamp']=dateShift(date("Y-m-d H:i:s"), "Y-m-d H:i:s", $this->surveyOptions['timeadjust']);
if ($this->surveyOptions['active'] && !isset($_SESSION[$this->sessid]['srid']))
Expand Down Expand Up @@ -4524,6 +4534,7 @@ static function JumpTo($seq,$preview=false,$processPOST=true,$force=false,$chang
}

$LEM->ParseResultCache=array(); // to avoid running same test more than once for a given group
$LEM->updatedValues = array();
--$seq; // convert to 0-based numbering

switch ($LEM->surveyMode)
Expand Down Expand Up @@ -5616,6 +5627,7 @@ function _ValidateQuestion($questionSeq)
{
$_SESSION[$LEM->sessid][$sgqa] = NULL;
$updatedValues[$sgqa] = NULL;
$LEM->updatedValues[$sgqa] = NULL;
}
}
else if ($qInfo['type'] == '*')
Expand All @@ -5625,10 +5637,13 @@ function _ValidateQuestion($questionSeq)
$sgqa = $LEM->qid2code[$qid]; // there will be only one, since Equation
// Store the result of the Equation in the SESSION
$_SESSION[$LEM->sessid][$sgqa] = $result;
$updatedValues[$sgqa] = array(
$_update = array(
'type'=>'*',
'value'=>$result,
);
$updatedValues[$sgqa] = $_update;
$LEM->updatedValues[$sgqa] = $_update;

if (($LEM->debugLevel & LEM_DEBUG_VALIDATION_DETAIL) == LEM_DEBUG_VALIDATION_DETAIL)
{
$prettyPrintEqn = $LEM->em->GetPrettyPrintString();
Expand All @@ -5640,6 +5655,7 @@ function _ValidateQuestion($questionSeq)
// NULL irrelevant sub-questions
$_SESSION[$LEM->sessid][$sq] = NULL;
$updatedValues[$sq] = NULL;
$LEM->updatedValues[$sq]= NULL;
}

// Regardless of whether relevant or hidden, if there is a default value and $_SESSION[$LEM->sessid][$sgqa] is NULL, then use the default value in $_SESSION, but don't write to database
Expand Down Expand Up @@ -6612,7 +6628,7 @@ static function GetRelevanceAndTailoringJavaScript()
{
// TODO - is different type needed for text? Or process value to striphtml?
if ($jsVar == '') continue;
$jsParts[] = "<input type='hidden' id='" . $jsVar . "' name='" . $jsVar . "' value='" . htmlspecialchars($undeclaredVal[$jsVar],ENT_QUOTES) . "'/>\n";
$jsParts[] = "<input type='hidden' id='" . $jsVar . "' name='" . substr($jsVar,4) . "' value='" . htmlspecialchars($undeclaredVal[$jsVar],ENT_QUOTES) . "'/>\n";
}
}
else
Expand Down Expand Up @@ -7335,7 +7351,7 @@ static function ProcessCurrentResponses()
$type = $qinfo['info']['type'];
if ($relevant && $grelevant && $sqrelevant)
{
if ($qinfo['info']['hidden'])
if ($qinfo['info']['hidden'] && !isset($_POST[$sq]))
{
$value = (isset($_SESSION['survey_'.$LEM->sessid][$sq]) ? $_SESSION['survey_'.$LEM->sessid][$sq] : ''); // if always hidden, use the default value, if any
}
Expand Down Expand Up @@ -7407,18 +7423,22 @@ static function ProcessCurrentResponses()
break;
}
$_SESSION[$LEM->sessid][$sq] = $value;
$updatedValues[$sq] = array (
$_update = array (
'type'=>$type,
'value'=>$value,
);
$updatedValues[$sq] = $_update;
$LEM->updatedValues[$sq] = $_update;
}
else { // irrelevant, so database will be NULLed separately
// Must unset the value, rather than setting to '', so that EM can re-use the default value as needed.
unset($_SESSION[$LEM->sessid][$sq]);
$updatedValues[$sq] = array (
$_update = array (
'type'=>$type,
'value'=>NULL,
);
$updatedValues[$sq] = $_update;
$LEM->updatedValues[$sq] = $_update;
}
}
}
Expand Down Expand Up @@ -7743,38 +7763,61 @@ public static function SetVariableValue($op,$name,$value)
$LEM->tempVars[$name]['code'] -= $value;
break;
}
return $LEM->tempVars[$name]['code'];
$_result = $LEM->tempVars[$name]['code'];
$_SESSION[$LEM->sessid][$name] = $_result;
$LEM->updatedValues[$name] = array(
'type'=>'*',
'value'=>$_result,
);
return $_result;
}
else
{
if (isset($LEM->knownVars[$name]))
if (!isset($LEM->knownVars[$name]))
{
$vname = $name;
}
else if (isset($LEM->qcode2sgqa[$name]))
if (isset($LEM->qcode2sgqa[$name]))
{
$name = $LEM->qcode2sgqa[$name];
}
else
{
$vname = $LEM->qcode2sgqa[$name];
return ''; // shouldn't happen
}
}
if (isset($_SESSION[$LEM->sessid][$name]))
{
$_result = $_SESSION[$LEM->sessid][$name];
}
else
{
$_result = (isset($LEM->knownVars[$name]['default']) ? $LEM->knownVars[$name]['default'] : 0);
}

switch($op)
switch($op)
{
case '=':
$LEM->knownVars[$name]['code'] = $value;
$_result = $value;
break;
case '*=':
$LEM->knownVars[$name]['code'] *= $value;
$_result *= $value;
break;
case '/=':
$LEM->knownVars[$name]['code'] /= $value;
$_result /= $value;
break;
case '+=':
$LEM->knownVars[$name]['code'] += $value;
$_result += $value;
break;
case '-=':
$LEM->knownVars[$name]['code'] -= $value;
$_result -= $value;
break;
}
return $LEM->knownVars[$name]['code'];
$_SESSION[$LEM->sessid][$name] = $_result;
$_type = $LEM->knownVars[$name]['type'];
$LEM->updatedValues[$name] = array(
'type'=>$_type,
'value'=>$_result,
);
return $_result;
}
}

Expand Down

0 comments on commit b4a81e8

Please sign in to comment.