diff --git a/question.php b/question.php index d949f559982..ab563da7a8a 100644 --- a/question.php +++ b/question.php @@ -643,34 +643,11 @@ else {$currentquestion=$_SESSION['step']-1;} $ia=$_SESSION['fieldarray'][$currentquestion]; -foreach ($_SESSION['grouplist'] as $gl) - { - if ($gl[0] == $ia[5]) - { - $gid=$gl[0]; - $groupname=$gl[1]; - $groupdescription=$gl[2]; - if (isset($_POST['lastgroupname']) && $_POST['lastgroupname'] != $groupname && $groupdescription) - { - $newgroup = "Y"; - } - else - { - $newgroup = "N"; - } - if (!isset($_POST['lastgroupname'])) {$newgroup="Y";} - } - } - -if ($newgroup == "Y" && $_POST['move'] == " << "._PREV." " && (isset($_POST['grpdesc']) && $_POST['grpdesc']=="Y")) //a small trick to manage moving backwards from a group description - { - $currentquestion++; - $ia=$_SESSION['fieldarray'][$currentquestion]; - $_SESSION['step']++; - } +list($newgroup, $gid, $groupname, $groupdescription, $gl)=checkIfNewGroup($ia); // MANAGE CONDITIONAL QUESTIONS $conditionforthisquestion=$ia[7]; +$questionsSkipped=0; while ($conditionforthisquestion == "Y") //IF CONDITIONAL, CHECK IF CONDITIONS ARE MET { $cquery="SELECT distinct cqid FROM {$dbprefix}conditions WHERE qid={$ia[0]}"; @@ -712,10 +689,14 @@ else { //matches have not been found in ALL distinct cqids. The question WILL NOT be displayed + $questionsSkipped++; if (returnglobal('move') == " "._NEXT." >> ") { $currentquestion++; - $ia=$_SESSION['fieldarray'][$currentquestion]; + if(isset($_SESSION['fieldarray'][$currentquestion])) + { + $ia=$_SESSION['fieldarray'][$currentquestion]; + } $_SESSION['step']++; foreach ($_SESSION['grouplist'] as $gl) { @@ -746,6 +727,16 @@ } } +if ($questionsSkipped == 0 && $newgroup == "Y" && $_POST['move'] == " << "._PREV." " && (isset($_POST['grpdesc']) && $_POST['grpdesc']=="Y")) //a small trick to manage moving backwards from a group description + { + //This does not work properly in all instances. + $currentquestion++; + $ia=$_SESSION['fieldarray'][$currentquestion]; + $_SESSION['step']++; + } + +list($newgroup, $gid, $groupname, $groupdescription, $gl)=checkIfNewGroup($ia); + include("qanda.php"); $percentcomplete = makegraph($_SESSION['step'], $_SESSION['totalsteps']); @@ -983,4 +974,27 @@ function last() echo "\n\n"; echo "\n\n"; } + +function checkIfNewGroup($ia) + { + foreach ($_SESSION['grouplist'] as $gl) + { + if ($gl[0] == $ia[5]) + { + $gid=$gl[0]; + $groupname=$gl[1]; + $groupdescription=$gl[2]; + if (isset($_POST['lastgroupname']) && $_POST['lastgroupname'] != $groupname && $groupdescription) + { + $newgroup = "Y"; + } + else + { + $newgroup = "N"; + } + if (!isset($_POST['lastgroupname'])) {$newgroup="Y";} + } + } + return array($newgroup, $gid, $groupname, $groupdescription, $gl); + } ?>