function checkconfield($value) { global $surveyid, $thissurvey, $qattributes; $fieldisdisplayed = true; if (!is_array($thissurvey)) { $local_thissurvey = getSurveyInfo($surveyid); } else { $local_thissurvey = $thissurvey; } // we know the true fieldname $value (for instance SGQA for each checkboxes) // and we want to compare it to the values stored in $_SESSION['fieldarray'] which are simple fieldnames // ==> We first translate $value to the simple fieldname (let's call it the masterFieldName) from // the $_SESSION['survey_X']['fieldnamesInfo'] translation table if (isset($_SESSION['survey_' . $surveyid]['fieldnamesInfo'][$value])) { $masterFieldName = $_SESSION['survey_' . $surveyid]['fieldnamesInfo'][$value]; } else { // for token refurl, ipaddr... $masterFieldName = 'token'; } $value_qid = 0; $value_type = ''; $value_isconditionnal = 'N'; //$value is the fieldname for the field we are checking for conditions foreach ($_SESSION['survey_' . $surveyid]['fieldarray'] as $sfa) { // record the qid and question type for future use if ($sfa[1] == $masterFieldName) { $value_qid = $sfa[0]; $value_type = $sfa[4]; $value_isconditionnal = $sfa[7]; break; } } // check if this question is conditionnal ($sfa[7]): if yes eval conditions if ($value_isconditionnal == "Y" && isset($_SESSION['survey_' . $surveyid][$value])) { $scenarioquery = "SELECT DISTINCT scenario FROM {{conditions}}" . " WHERE {{conditions}}.qid={$sfa['0']} ORDER BY scenario"; $scenarioresult = dbExecuteAssoc($scenarioquery); $matchfound = 0; //$scenario=1; //while ($scenario > 0) $evalNextScenario = true; foreach ($scenarioresult->readAll() as $scenariorow) { if ($evalNextScenario !== true) { break; } $aAllCondrows = array(); $cqval = array(); $container = array(); $scenario = $scenariorow['scenario']; $currentcfield = ""; $sConditionsQuery1 = "SELECT {{conditions}}.*, {{questions}}.type " . "FROM {{conditions}}, {{questions}} " . "WHERE {{conditions}}.cqid={{questions}}.qid " . "AND {{conditions}}.qid={$value_qid} " . "AND {{conditions}}.scenario={$scenario} " . "AND {{conditions}}.cfieldname NOT LIKE '{%' " . "ORDER BY {{conditions}}.qid,{{conditions}}.cfieldname"; $oResult1 = dbExecuteAssoc($sConditionsQuery1) or safeDie($query . "<br />"); //Checked $aConditionsResult1 = $oResult2->readAll(); //Checked $conditionsfound = count($aConditionsResult1); $sConditionsQuery2 = "SELECT {{conditions}}.*, '' as type " . "FROM {{conditions}} " . "WHERE " . " {{conditions}}.qid={$value_qid} " . "AND {{conditions}}.scenario={$scenario} " . "AND {{conditions}}.cfieldname LIKE '{%' " . "ORDER BY {{conditions}}.qid,{{conditions}}.cfieldname"; $oResult2 = dbExecuteAssoc($sConditionsQuery2) or safeDie($querytoken . "<br />"); $aConditionsResult2 = $oResult2->readAll(); //Checked $conditionsfoundtoken = count($aConditionsResult2); $conditionsfound = $conditionsfound + $conditionsfoundtoken; foreach ($aConditionsResult2 as $Condrow) { $aAllCondrows[] = $Condrow; } foreach ($aConditionsResult1 as $Condrow) { $aAllCondrows[] = $Condrow; } foreach ($aAllCondrows as $rows) { if (preg_match("/^\\+(.*)\$/", $rows['cfieldname'], $cfieldnamematch)) { // this condition uses a single checkbox as source $rows['type'] = "+" . $rows['type']; $rows['cfieldname'] = $cfieldnamematch[1]; } if ($rows['type'] == "M" || $rows['type'] == "P") { $matchfield = $rows['cfieldname'] . $rows['value']; $matchmethod = $rows['method']; $matchvalue = "Y"; } else { $matchfield = $rows['cfieldname']; $matchmethod = $rows['method']; $matchvalue = $rows['value']; } $cqval[] = array("cfieldname" => $rows['cfieldname'], "value" => $rows['value'], "type" => $rows['type'], "matchfield" => $matchfield, "matchvalue" => $matchvalue, "matchmethod" => $matchmethod); if ($rows['cfieldname'] != $currentcfield) { $container[] = $rows['cfieldname']; } $currentcfield = $rows['cfieldname']; } if ($conditionsfound > 0) { //At least one match must be found for each "$container" $total = 0; foreach ($container as $con) { $conditionCanBeEvaluated = true; $addon = 0; foreach ($cqval as $cqv) { //Go through each condition // Replace @SGQA@ condition values // By corresponding value if (preg_match('/^@([0-9]+X[0-9]+X[^@]+)@/', $cqv["matchvalue"], $targetconditionfieldname)) { if (isset($_SESSION['survey_' . $surveyid][$targetconditionfieldname[1]])) { $cqv["matchvalue"] = $_SESSION['survey_' . $surveyid][$targetconditionfieldname[1]]; } else { $conditionCanBeEvaluated = false; } } // Replace {TOKEN:XXX} condition values // By corresponding value if ($local_thissurvey['anonymized'] == 'N' && preg_match('/^{TOKEN:([^}]*)}$/', $cqv["matchvalue"], $targetconditiontokenattr)) { if (isset($_SESSION['survey_' . $surveyid]['token']) && in_array(strtolower($targetconditiontokenattr[1]), getTokenConditionsFieldNames($surveyid))) { $cqv["matchvalue"] = getAttributeValue($surveyid, strtolower($targetconditiontokenattr[1]), $_SESSION['survey_' . $surveyid]['token']); } else { $conditionCanBeEvaluated = false; } } // Use == as default operator if (trim($cqv['matchmethod']) == '') { $cqv['matchmethod'] = '=='; } if ($cqv['cfieldname'] == $con && $conditionCanBeEvaluated === true) { if (!preg_match("/^{/", $cqv['cfieldname'])) { if (isset($_SESSION['survey_' . $surveyid][$cqv['matchfield']])) { $comparisonLeftOperand = $_SESSION['survey_' . $surveyid][$cqv['matchfield']]; } else { $comparisonLeftOperand = null; } } elseif ($local_thissurvey['anonymized'] == "N" && preg_match('/^{TOKEN:([^}]*)}$/', $cqv['cfieldname'], $sourceconditiontokenattr)) { if (isset($_SESSION['survey_' . $surveyid]['token']) && in_array(strtolower($sourceconditiontokenattr[1]), getTokenConditionsFieldNames($surveyid))) { $comparisonLeftOperand = getAttributeValue($surveyid, strtolower($sourceconditiontokenattr[1]), $_SESSION['survey_' . $surveyid]['token']); } else { $comparisonLeftOperand = null; } } else { $comparisonLeftOperand = null; } if ($cqv['matchmethod'] != "RX") { if (preg_match("/^a(.*)b\$/", $cqv['matchmethod'], $matchmethods)) { // strings comparizon operator in PHP are the same as numerical operators $matchOperator = $matchmethods[1]; } else { $matchOperator = $cqv['matchmethod']; } if (isset($comparisonLeftOperand) && !is_null($comparisonLeftOperand) && eval('if (trim($comparisonLeftOperand) ' . $matchOperator . ' trim($cqv["matchvalue"]) ) {return true;} else {return false;}')) { //plug successful matches into appropriate container $addon = 1; } } elseif (isset($comparisonLeftOperand) && !is_null($comparisonLeftOperand) && preg_match('/' . $cqv["matchvalue"] . '/', $comparisonLeftOperand)) { $addon = 1; } } } if ($addon == 1) { $total++; } } if ($total == count($container)) { $matchfound = 1; $evalNextScenario = false; // Don't look for other scenario's. } unset($cqval); unset($container); } else { //Curious there is no condition for this question in this scenario // this is not a normal behaviour, but I propose to defaults to a // condition-matched state in this case $matchfound = 1; $evalNextScenario = false; } } // while ($scenario) if ($matchfound == 0) { //If this is not a "moveprev" then // Reset the value in SESSION //if(isset($move) && $move != "moveprev") //{ $_SESSION['survey_' . $surveyid][$value] = ""; $fieldisdisplayed = false; //} } } if ($value_qid != 0) { // not token masterFieldname $value_qa = getQuestionAttributeValues($value_qid, $value_type); } if ($fieldisdisplayed === true && isset($value_qa) && (isset($value_qa['array_filter']) && trim($value_qa['array_filter']) != '' || isset($value_qa['array_filter_exclude']) && trim($value_qa['array_filter_exclude']) != '')) { // check if array_filter//array_filter_exclude have hidden the field $value_code = preg_replace("/{$masterFieldName}(.*)/", "\$1", $value); //If this question is a multi-flexible, the value_code will be both the array_filter value // (at the beginning) and then a labelset value after an underscore // ie: 2_1 for answer code=2 and labelset code=1 then 2_2 for answer_code=2 and // labelset code=2. So for these question types we need to split it again at the underscore! // 1. Find out if this is question type ":" or ";" if ($value_type == ";" || $value_type == ":") { list($value_code, $value_label) = explode("_", $value_code); } if (isset($value_qa['array_filter_exclude'])) { $arrayfilterXcludes_selected_codes = getArrayFilterExcludesForQuestion($value_qid); if ($arrayfilterXcludes_selected_codes !== false && in_array($value_code, $arrayfilterXcludes_selected_codes)) { $fieldisdisplayed = false; } } elseif (isset($value_qa['array_filter'])) { $arrayfilter_selected_codes = getArrayFiltersForQuestion($value_qid); if ($arrayfilter_selected_codes !== false && !in_array($value_code, $arrayfilter_selected_codes)) { $fieldisdisplayed = false; } } } return $fieldisdisplayed; }
function return_array_filter_exclude_strings($ia, $qidattributes, $thissurvey, $ansrow, $rowname, $trbc='', $valuename, $method="tbody", $class=null) { /* DO ARRAY_FILTER_EXCLUDE ATTRIBUTE We set the $hiddenfield for each answer, and the value of this is available to java to let javascripts know whether each answer is currently being displayed. $htmltbody2 determines whether the answer row should be displayed initially. If no answers for the source question have been selected then the whole answer row should start in the display-on position. */ $htmltbody2 = ''; $hiddenfield= ''; if ( (trim($qidattributes['array_filter_exclude'])!='' && // the array_filter attribute is set $thissurvey['format'] == 'G' && // and the survey is being presented group by group getArrayFiltersExcludesOutGroup($ia[0]) == false // and this question _is_ in the current group for the array filter (ie it's on the same page) ) || // OR (trim($qidattributes['array_filter_exclude'])!='' && // the array_filter attribute is set $thissurvey['format'] == 'A' // and the survey is being presented all on one page ) ) { $htmltbody2 = "\n\n\t<$method id='javatbd$rowname'>\n"; if($ia[4]=="1") { //This is an array dual scale question and we have to massage the tbidpslay rowname $hiddenfield = "<input type='hidden' name='tbdisp$rowname#0' id='tbdisp$rowname#0' value='on' />\n"; $hiddenfield .= "<input type='hidden' name='tbdisp$rowname#1' id='tbdisp$rowname#1' value='on' />\n"; } else { $hiddenfield = "<input type='hidden' name='tbdisp$rowname' id='tbdisp$rowname' value='on' />\n"; } } else if ( (trim($qidattributes['array_filter_exclude'])!='' && $thissurvey['format'] == 'S' ) || (trim($qidattributes['array_filter_exclude'])!='' && $thissurvey['format'] == 'G' && getArrayFiltersExcludesOutGroup($ia[0]) == true ) ) { $selected = getArrayFilterExcludesForQuestion($ia[0]); if (isset($ansrow['code'])) $ansrow['title'] = $ansrow['code']; if (!empty($selected) && !in_array($ansrow['title'],$selected)) { $htmltbody2 = "\n\n\t<$method id='javatbd$rowname'>\n"; if($ia[4]=="1") { //This is an array dual scale question and we have to massage the tbidpslay rowname $hiddenfield = "<input type='hidden' name='tbdisp$rowname#0' id='tbdisp$rowname#0' value='on' />\n"; $hiddenfield .= "<input type='hidden' name='tbdisp$rowname#1' id='tbdisp$rowname#1' value='on' />\n"; } else { $hiddenfield="<input type='hidden' name='tbdisp$rowname' id='tbdisp$rowname' value='on' />"; } } else { $htmltbody2 = "\n\n\t<$method id='javatbd$rowname' style='display: none'>"; if($ia[4]=="1") { //This is an array dual scale question and we have to massage the tbidpslay rowname $hiddenfield = "<input type='hidden' name='tbdisp$rowname#0' id='tbdisp$rowname#0' value='off' />\n"; $hiddenfield .= "<input type='hidden' name='tbdisp$rowname#1' id='tbdisp$rowname#1' value='off' />\n"; } else { $hiddenfield="\n<input type='hidden' name='tbdisp$rowname' id='tbdisp$rowname' value='off' />"; } $_SESSION[$valuename]=''; //Remove any saved results for this since it is no longer being displayed } } else { $htmltbody2 = "\n\n\t<$method id='javatbd$rowname' style='display: none'>\n"; if($ia[4]=="1") { //This is an array dual scale question and we have to massage the tbidpslay rowname $hiddenfield = "<input type='hidden' name='tbdisp$rowname#0' id='tbdisp$rowname#0' value='off' />\n"; $hiddenfield .= "<input type='hidden' name='tbdisp$rowname#1' id='tbdisp$rowname#1' value='off' />\n"; } else { $hiddenfield = "<input type='hidden' name='tbdisp$rowname' id='tbdisp$rowname' value='off' />"; } } //End of array_filter attribute return array($htmltbody2, $hiddenfield); }