Skip to content

Commit

Permalink
Fixed Bug with multiple option questions, display issues and mandator…
Browse files Browse the repository at this point in the history
…y field checking

git-svn-id: file:///Users/Shitiz/Downloads/lssvn/trunk/unstable@312 b72ed6b6-b9f8-46b5-92b4-906544132732
  • Loading branch information
jcleeland committed May 28, 2003
1 parent 78ec90a commit 5a017e9
Show file tree
Hide file tree
Showing 4 changed files with 247 additions and 14 deletions.
95 changes: 91 additions & 4 deletions group.php
Expand Up @@ -58,36 +58,117 @@
$mi=0;
foreach ($chkmands as $cm)
{
if ($multiname != "MULTI$mfns[$mi]")
{
if ($multiname && $_POST[$multiname])
{
if ($$multiname == $$multiname2) //so far all multiple choice options are unanswered
{
//The number of questions not answered is equal to the number of questions
if ($_POST['move'] == " << prev ") {$_SESSION['step'] = $_POST['thisstep'];}
if ($_POST['move'] == " next >> ") {$_SESSION['step'] = $_POST['thisstep'];}
if ($_POST['move'] == " last ") {$_SESSION['step'] = $_POST['thisstep']; $_POST['move'] == " next >> ";}
$notanswered[]=substr($multiname, 5, strlen($multiname));
$$multiname=0;
$$multiname2=0;
}
}
$multiname="MULTI$mfns[$mi]";
$$multiname=0;
$$multiname2=0;
}
else {$multiname="MULTI$mfns[$mi]";}
if ($_SESSION[$cm] == "0" || $_SESSION[$cm])
{
}
else
elseif (!$_POST[$multiname])
{
//One of the mandatory questions hasn't been asnwered
if ($_POST['move'] == " << prev ") {$_SESSION['step'] = $_POST['thisstep'];}
if ($_POST['move'] == " next >> ") {$_SESSION['step'] = $_POST['thisstep'];}
if ($_POST['move'] == " last ") {$_SESSION['step'] = $_POST['thisstep']; $_POST['move'] == " next >> ";}
$notanswered[]=$mfns[$mi];
}
else
{
//One of the mandatory questions hasn't been asnwered
$$multiname++;
}
$$multiname2++;
$mi++;
}
if ($multiname && $_POST[$multiname]) // Catch the last multiple options question in the lot
{
if ($$multiname == $$multiname2) //so far all multiple choice options are unanswered
{
//The number of questions not answered is equal to the number of questions
if ($_POST['move'] == " << prev ") {$_SESSION['step'] = $_POST['thisstep'];}
if ($_POST['move'] == " next >> ") {$_SESSION['step'] = $_POST['thisstep'];}
if ($_POST['move'] == " last ") {$_SESSION['step'] = $_POST['thisstep']; $_POST['move'] == " next >> ";}
$notanswered[]=substr($multiname, 5, strlen($multiname));
$$multiname="";
$$multiname2="";
}
}
}

if ($_POST['conmandatory'])
{
$chkcmands=explode("|", $_POST['conmandatory']);
$cmfns=explode("|", $_POST['conmandatoryfn']);
$mi=0;
foreach ($chkcmands as $ccm)
{
$dccm="display$ccm";
if ($_POST[$dccm] == "on" && !$_SESSION[$ccm])
if ($multiname != "MULTI$cmfns[$mi]") //the last multipleanswerchecked is different to this one
{
if ($multiname && $_POST[$multiname])
{
if ($$multiname == $$multiname2) //For this lot all multiple choice options are unanswered
{
//The number of questions not answered is equal to the number of questions
if ($_POST['move'] == " << prev ") {$_SESSION['step'] = $_POST['thisstep'];}
if ($_POST['move'] == " next >> ") {$_SESSION['step'] = $_POST['thisstep'];}
if ($_POST['move'] == " last ") {$_SESSION['step'] = $_POST['thisstep']; $_POST['move'] == " next >> ";}
$notanswered[]=substr($multiname, 5, strlen($multiname));
$$multiname=0;
$$multiname2=0;
}
}
$multiname="MULTI$cmfns[$mi]";
$$multiname=0;
$$multiname2=0;
}
else{$multiname="MULTI$cmfns[$mi]";}
//$dccm="display$ccm";
$dccm="display$cmfns[$mi]";
if (($_SESSION[$ccm] == "0" || $_SESSION[$ccm]) && $_POST[$dccm] == "on")//There is an answer
{
}
elseif ($_POST[$dccm] == "on" && !$_POST[$multiname]) //Question is on, there is no answer, but it's a multiple
{
//One of the conditional mandatory questions was on, but hasn't been answered
if ($_POST['move'] == " << prev ") {$_SESSION['step'] = $_POST['thisstep'];}
if ($_POST['move'] == " next >> ") {$_SESSION['step'] = $_POST['thisstep'];}
if ($_POST['move'] == " last ") {$_SESSION['step'] = $_POST['thisstep']; $_POST['move'] == " next >> ";}
$notanswered[]=$cmfns[$mi];
}
elseif ($_POST[$dccm] == "on")
{
//One of the conditional mandatory questions was on, but hasn't been answered
$$multiname++;
}
$$multiname2++;
$mi++;
}
if ($multiname && $_POST[$multiname])
{
if ($$multiname == $$multiname2) //so far all multiple choice options are unanswered
{
//The number of questions not answered is equal to the number of questions
if ($_POST['move'] == " << prev ") {$_SESSION['step'] = $_POST['thisstep'];}
if ($_POST['move'] == " next >> ") {$_SESSION['step'] = $_POST['thisstep'];}
if ($_POST['move'] == " last ") {$_SESSION['step'] = $_POST['thisstep']; $_POST['move'] == " next >> ";}
$notanswered[]=substr($multiname, 5, strlen($multiname));
}
}
}
//DEBUG - FOLLOWING SECTION CAN GO ONCE SCRIPT IS OK
Expand Down Expand Up @@ -630,10 +711,16 @@
if ($cd[4] == "R") {$idname="fvalue".substr($cd[2], strlen($cd[5]), strlen($cd[2]-strlen($cd[5])));}
elseif ($cd[4] == "5" || $cd[4] == "A" || $cd[4] == "B" || $cd[4] == "C" || $cd[4] == "G" || $cd[4] == "Y" || ($cd[4] == "L" && $dropdowns == "R"))
{$idname="java$cd[2]";}
elseif($cd[4] == "M" || $cd[4] == "O")
{$idname="$cd[2]$cd[3]";}
else {$idname=$cd[2];}
if ($cqcount > 1 && $oldcq ==$cd[2]) {$java .= " || ";}
elseif ($cqcount >1 && $oldcq != $cd[2]) {$java .= ") && (";}
//if ($cd[4] == "M" || $cd[4] == "O")

if ($cd[3] == '') {$java .= "document.getElementById('$idname').value == ' ' || !document.getElementById('$idname').value";}
elseif ($cd[4] == "M" || $cd[4] == "O")
{$java .= "document.getElementById('$idname').checked";}
else {$java .= "document.getElementById('$idname').value == '$cd[3]'";}
if ($oldq != $cd[0])//Close if statement
{
Expand Down
13 changes: 11 additions & 2 deletions qanda.php
Expand Up @@ -380,6 +380,7 @@
$ansquery = "SELECT * FROM answers WHERE qid={$ia[0]} ORDER BY code";
$ansresult = mysql_query($ansquery);
$anscount = mysql_num_rows($ansresult);
$answer .= "\t\t\t\t\t<input type='hidden' name='MULTI$ia[1]' value='$anscount'>\n";
$fn = 1;
while ($ansrow = mysql_fetch_array($ansresult))
{
Expand Down Expand Up @@ -438,6 +439,7 @@
$ansquery = "SELECT * FROM answers WHERE qid={$ia[0]} ORDER BY code";
$ansresult = mysql_query($ansquery);
$anscount = mysql_num_rows($ansresult)*2;
$answer .= "\t\t\t\t\t<input type='hidden' name='MULTI$ia[1]' value='$anscount'>\n";
$fn = 1;
$answer .= "\t\t\t\t\t\t<table border='0'>\n";
while ($ansrow = mysql_fetch_array($ansresult))
Expand Down Expand Up @@ -694,16 +696,23 @@
$answer .= "\t\t\t</table>\n";
break;
}
$answer .= "\n\t\t\t<input type='hidden' name='display$ia[1]' id='display$ia[0]' value=''>\n"; //for conditional mandatory questions
$answer .= "\n\t\t\t<input type='hidden' name='display$ia[1]' id='display$ia[0]' value='";
if ($surveyformat == "S")
{
$answer .= "on"; //Ifthis is single format, then it must be showing. Needed for checking conditional mandatories
}
$answer .= "'>\n"; //for conditional mandatory questions

$qtitle=$ia[3];
if (is_array($notanswered))
{
if (in_array($ia[1], $notanswered))
{
$qtitle = "</b><font color='red' size='1'>This question is mandatory.";
if ($ia[4] == "A" || $ia[4] == "B" || $ia[4] == "C" || $ia[4] == "M" || $ia[4] == "O" )
if ($ia[4] == "A" || $ia[4] == "B" || $ia[4] == "C")
{ $qtitle .= "<br />\nPlease answer all parts."; }
if ($ia[4] == "M" || $ia[4] == "P")
{ $qtitle .= "<br />\nPlease check at least one item.";}
if ($ia[4] == "R")
{ $qtitle .= "<br />\nPlease rank every item."; }
$qtitle .= "</font><b><br />\n";
Expand Down
58 changes: 54 additions & 4 deletions question.php
Expand Up @@ -59,19 +59,34 @@
$mi=0;
foreach ($chkmands as $cm)
{
$multiname="MULTI$mfns[$mi]";
//echo "Checking Mandatory: $cm<br />";
//echo "Mandatory $cm is ".$_SESSION[$cm]."<br />\n";
if ($_SESSION[$cm] == "0" || $_SESSION[$cm])
{
}
else
elseif (!$_POST[$multiname])
{
//One of the mandatory questions hasn't been asnwered
if ($_POST['move'] == " << prev ") {$_SESSION['step'] = $_POST['thisstep'];}
if ($_POST['move'] == " next >> ") {$_SESSION['step'] = $_POST['thisstep'];}
if ($_POST['move'] == " last ") {$_SESSION['step'] = $_POST['thisstep']; $_POST['move'] == " next >> ";}
$notanswered[]=$mfns[$mi];
}
else
{
$notanswered[]=$mfns[$mi];
}
if ($_POST[$multiname])
{
if (count($notanswered) == count($chkmands)) //
{
//The number of questions not answered is equal to the number of questions
if ($_POST['move'] == " << prev ") {$_SESSION['step'] = $_POST['thisstep'];}
if ($_POST['move'] == " next >> ") {$_SESSION['step'] = $_POST['thisstep'];}
if ($_POST['move'] == " last ") {$_SESSION['step'] = $_POST['thisstep']; $_POST['move'] == " next >> ";}
}
}
$mi++;
}
}
Expand All @@ -82,15 +97,37 @@
$mi=0;
foreach ($chkcmands as $ccm)
{
$dccm="display$ccm";
if ($_POST[$dccm] == "on" && !$_SESSION[$ccm])
$multiname="MULTI$cmfns[$mi]";
if (!$_POST[$multiname])
{
$dccm="display$ccm";
}
else
{
$dccm="display".$cmfns[0];
}
if ($_POST[$dccm] == "on" && (!$_SESSION[$ccm] && $_SESSION[$ccm] != "0") && !$_POST[$multiname])
{
//One of the conditional mandatory questions was on, but hasn't been answered
if ($_POST['move'] == " << prev ") {$_SESSION['step'] = $_POST['thisstep'];}
if ($_POST['move'] == " next >> ") {$_SESSION['step'] = $_POST['thisstep'];}
if ($_POST['move'] == " last ") {$_SESSION['step'] = $_POST['thisstep']; $_POST['move'] == " next >> ";}
$notanswered[]=$cmfns[$mi];
}
elseif ($_POST[$dccm] == "on" && !$_SESSION[$ccm] && $_POST[$multiname])
{
$notanswered[]=$cmfns[$mi];
}
}
if ($_POST[$multiname])
{
if (count($notanswered) == count($chkcmands)) //
{
//The number of questions not answered is equal to the number of questions
if ($_POST['move'] == " << prev ") {$_SESSION['step'] = $_POST['thisstep'];}
if ($_POST['move'] == " next >> ") {$_SESSION['step'] = $_POST['thisstep'];}
if ($_POST['move'] == " last ") {$_SESSION['step'] = $_POST['thisstep']; $_POST['move'] == " next >> ";}
}
}
}
//DEBUG - FOLLOWING SECTION CAN GO ONCE SCRIPT IS OK
Expand Down Expand Up @@ -120,7 +157,7 @@
// }
// }
//echo "-->\n";

//
//echo "<!-- DEBUG: POST ARRAY\n";
//foreach (array_keys($_POST) as $Pak)
// {
Expand Down Expand Up @@ -573,6 +610,13 @@
$cqidmatches=0;
while ($crows=mysql_fetch_array($cresult))//Go through each condition for this current question
{
//Check if the condition is multiple type
$ccquery="SELECT type FROM questions WHERE qid={$crows['cqid']}";
$ccresult=mysql_query($ccquery) or die ("Coudn't get type from questions<br />$ccquery<br />".mysql_error());
while($ccrows=mysql_fetch_array($ccresult))
{
$thistype=$ccrows['type'];
}
$cqquery = "SELECT cfieldname, value, cqid FROM conditions WHERE qid={$ia[0]} AND cqid={$crows['cqid']}";
$cqresult = mysql_query($cqquery) or die("Couldn't get conditions for this question/cqid<br />$cquery<br />".mysql_error());
$amatchhasbeenfound="N";
Expand All @@ -581,8 +625,14 @@
$currentcqid=$cqrows['cqid'];
$conditionfieldname=$cqrows['cfieldname'];
if (!$cqrows['value']) {$conditionvalue="NULL";} else {$conditionvalue=$cqrows['value'];}
if ($thistype == "M" || $thistype == "O")
{
$conditionfieldname .= $conditionvalue;
$conditionvalue = "Y";
}
if (!$_SESSION[$conditionfieldname]) {$currentvalue="NULL";} else {$currentvalue=$_SESSION[$conditionfieldname];}
if ($currentvalue == $conditionvalue) {$amatchhasbeenfound="Y";}
echo "!- $conditionfieldname -- ". $currentvalue . "---". $conditionvalue."-- <br />";
}
if ($amatchhasbeenfound == "Y") {$cqidmatches++;}
}
Expand Down

0 comments on commit 5a017e9

Please sign in to comment.