Skip to content

Commit

Permalink
Fixed bug #4176 - Array filter does not know how to handle 'other' field
Browse files Browse the repository at this point in the history
git-svn-id: file:///Users/Shitiz/Downloads/lssvn/source/limesurvey@8523 b72ed6b6-b9f8-46b5-92b4-906544132732
  • Loading branch information
jcleeland committed Mar 27, 2010
1 parent 8bd384f commit 01015bd
Show file tree
Hide file tree
Showing 4 changed files with 182 additions and 40 deletions.
25 changes: 21 additions & 4 deletions common.php
Expand Up @@ -4773,6 +4773,7 @@ function getArrayFiltersForQuestion($qid)
$qid=sanitize_int($qid);
$query = "SELECT value FROM ".db_table_name('question_attributes')." WHERE attribute='array_filter' AND qid='".$qid."'";
$result = db_execute_assoc($query); //Checked

if ($result->RecordCount() == 1) // We Found a array_filter attribute
{
$val = $result->FetchRow(); // Get the Value of the Attribute ( should be a previous question's title in same group )
Expand All @@ -4790,6 +4791,14 @@ function getArrayFiltersForQuestion($qid)
if ((isset($_SESSION[$fields[1].$code['code']]) && $_SESSION[$fields[1].$code['code']] == "Y")
|| $_SESSION[$fields[1]] == $code['code']) array_push($selected,$code['code']);
}
//Now we also need to find out if (a) the question had "other" enabled, and (b) if that was selected
$query = "SELECT other FROM ".db_table_name('questions')." where qid='{$fields[0]}'";
$qresult = db_execute_assoc($query);
while ($row=$qresult->fetchRow()) {$other=$row['other'];}
if($other == "Y")
{
if($_SESSION[$fields[1].'other'] != "") {array_push($selected, "other");}
}
return $selected;
}
}
Expand Down Expand Up @@ -4831,7 +4840,7 @@ function getArrayFilterExcludesForQuestion($qid)
$query = "SELECT value FROM ".db_table_name('question_attributes')." WHERE attribute='array_filter_exclude' AND qid='".$qid."'";
$result = db_execute_assoc($query); //Checked
$excludevals=array();
if ($result->RecordCount() == 1) // We Found a array_filter attribute
if ($result->RecordCount() == 1) // We Found a array_filter_exclude attribute
{
$selected=array();
$excludevals[] = $result->FetchRow(); // Get the Value of the Attribute ( should be a previous question's title in same group )
Expand All @@ -4848,11 +4857,11 @@ function getArrayFilterExcludesForQuestion($qid)
/* For each $val (question title) that applies to this, check what values exist and add them to the $selected array */
foreach ($excludevals as $val)
{
foreach ($_SESSION['fieldarray'] as $fields)
foreach ($_SESSION['fieldarray'] as $fields) //iterate through every question in the survey
{
if ($fields[2] == $val['value'])
{
// we found the target question, now we need to know what the answers where, we know its a multi!
{
// we found the target question, now we need to know what the answers were!
$fields[0]=sanitize_int($fields[0]);
$query = "SELECT code FROM ".db_table_name('answers')." where qid='{$fields[0]}' AND language='".$_SESSION['s_lang']."' order by sortorder";
$qresult = db_execute_assoc($query); //Checked
Expand All @@ -4861,6 +4870,14 @@ function getArrayFilterExcludesForQuestion($qid)
if ((isset($_SESSION[$fields[1].$code['code']]) && $_SESSION[$fields[1].$code['code']] == "Y")
|| $_SESSION[$fields[1]] == $code['code']) array_push($selected,$code['code']);
}
//Now we also need to find out if (a) the question had "other" enabled, and (b) if that was selected
$query = "SELECT other FROM ".db_table_name('questions')." where qid='{$fields[0]}'";
$qresult = db_execute_assoc($query);
while ($row=$qresult->fetchRow()) {$other=$row['other'];}
if($other == "Y")
{
if($_SESSION[$fields[1].'other'] != "") {array_push($selected, "other");}
}
}
}
}
Expand Down
54 changes: 51 additions & 3 deletions group.php
Expand Up @@ -473,7 +473,7 @@ function checkconditions(value, name, type)
if (type == 'checkbox')
{
var hiddenformname='java'+name;
var chkname='answer'+name;
var chkname='answer'+name;
if (document.getElementById(chkname).checked)
{
document.getElementById(hiddenformname).value='Y';
Expand Down Expand Up @@ -895,10 +895,12 @@ function checkconditions(value, name, type)
$qfbase = $surveyid."X".$gid."X".$attralist['fid'];
if ($attralist['type'] == "M")
{
$qquery = "SELECT {$dbprefix}answers.code, {$dbprefix}questions.type FROM {$dbprefix}answers, {$dbprefix}questions WHERE {$dbprefix}answers.qid={$dbprefix}questions.qid AND {$dbprefix}answers.qid='".$attralist['qid']."' AND {$dbprefix}answers.language='".$_SESSION['s_lang']."' order by code;";
$qquery = "SELECT {$dbprefix}answers.code, {$dbprefix}questions.type, {$dbprefix}questions.other FROM {$dbprefix}answers, {$dbprefix}questions WHERE {$dbprefix}answers.qid={$dbprefix}questions.qid AND {$dbprefix}answers.qid='".$attralist['qid']."' AND {$dbprefix}answers.language='".$_SESSION['s_lang']."' order by code;";
$qresult = db_execute_assoc($qquery); //Checked
$other=null;
while ($fansrows = $qresult->FetchRow())
{
if($fansrows['other']== "Y") $other="Y";
if(strpos($array_filter_types, $fansrows['type']) === false) {} else
{
$fquestans = "java".$qfbase.$fansrows['code'];
Expand All @@ -922,6 +924,28 @@ function checkconditions(value, name, type)
$appendj .= "\t}\n";
}
}

if($other=="Y") {
$fquestans = "answer".$qfbase."other";
$tbody = "javatbd".$qbase."other";
$dtbody = "tbdisp".$qbase."other";
$tbodyae = $qbase."other";
$appendj .= "\n";
$appendj .= "\tif (document.getElementById('$fquestans').value !== '')\n";
$appendj .= "\t{\n";
$appendj .= "\t\tdocument.getElementById('$tbody').style.display='';\n";
$appendj .= "\t\t$('#$dtbody').val('on');\n";
$appendj .= "\t}\n";
$appendj .= "\telse\n";
$appendj .= "\t{\n";
$appendj .= "\t\tdocument.getElementById('$tbody').style.display='none';\n";
$appendj .= "\t\t$('#$dtbody').val('off');\n";
// This line resets the text fields in the hidden row
$appendj .= "\t\t$('#$tbody input[type=text]').val('');";
// This line resets any radio group in the hidden row
$appendj .= "\t\t$('#$tbody input[type=radio]').attr('checked', false); ";
$appendj .= "\t}\n";
}
}
}
$java .= $appendj;
Expand All @@ -931,15 +955,17 @@ function checkconditions(value, name, type)
$qfbase = $surveyid."X".$gid."X".$attralist['fid'];
if ($attralist['type'] == "M")
{
$qquery = "SELECT {$dbprefix}answers.code, {$dbprefix}questions.type
$qquery = "SELECT {$dbprefix}answers.code, {$dbprefix}questions.type, {$dbprefix}questions.other
FROM {$dbprefix}answers, {$dbprefix}questions
WHERE {$dbprefix}answers.qid={$dbprefix}questions.qid
AND {$dbprefix}answers.qid='".$attralist['qid']."'
AND {$dbprefix}answers.language='".$_SESSION['s_lang']."'
ORDER BY code;";
$qresult = db_execute_assoc($qquery); //Checked
$other=null;
while ($fansrows = $qresult->FetchRow())
{
if($fansrows['other']== "Y") $other="Y";
if(strpos($array_filter_exclude_types, $fansrows['type']) === false) {} else
{
$fquestans = "java".$qfbase.$fansrows['code'];
Expand All @@ -953,6 +979,7 @@ function checkconditions(value, name, type)
/* If this question is a cascading question, then it also needs to check the status of the question that this one relies on */
if(isset($array_filterXqs_cascades[$attralist['qid']]))
{

foreach($array_filterXqs_cascades[$attralist['qid']] as $cascader)
{
$cascadefqa ="java".$surveyid."X".$gid."X".$cascader.$fansrows['code'];
Expand All @@ -977,6 +1004,27 @@ function checkconditions(value, name, type)
$appendj .= "\t}\n";
}
}
if($other=="Y") {
$fquestans = "answer".$qfbase."other";
$tbody = "javatbd".$qbase."other";
$dtbody = "tbdisp".$qbase."other";
$tbodyae = $qbase."other";
$appendj .= "\n";
$appendj .= "\tif (document.getElementById('$fquestans').value !== '')\n";
$appendj .= "\t{\n";
$appendj .= "\t\tdocument.getElementById('$tbody').style.display='none';\n";
$appendj .= "\t\t$('#$dtbody').val('on');\n";
$appendj .= "\t}\n";
$appendj .= "\telse\n";
$appendj .= "\t{\n";
$appendj .= "\t\tdocument.getElementById('$tbody').style.display='';\n";
$appendj .= "\t\t$('#$dtbody').val('off');\n";
// This line resets the text fields in the hidden row
$appendj .= "\t\t$('#$tbody input[type=text]').val('');";
// This line resets any radio group in the hidden row
$appendj .= "\t\t$('#$tbody input[type=radio]').attr('checked', false); ";
$appendj .= "\t}\n";
}
}
}
$java .= $appendj;
Expand Down

0 comments on commit 01015bd

Please sign in to comment.