Skip to content

Commit

Permalink
Dev Fixed notices if a survey is run in test mode and a question was …
Browse files Browse the repository at this point in the history
…deleted while taking the survey

git-svn-id: file:///Users/Shitiz/Downloads/lssvn/source/limesurvey@9518 b72ed6b6-b9f8-46b5-92b4-906544132732
  • Loading branch information
c-schmitz committed Nov 22, 2010
1 parent 4a1da57 commit ba4045d
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 49 deletions.
7 changes: 6 additions & 1 deletion common.php
Expand Up @@ -3389,7 +3389,7 @@ function buildLabelSetCheckSumArray()
* @author: c_schmitz
* @param $qid The question ID
* @param $type optional The question type - saves a DB query if you provide it
* @return array{attribute=>value , attribute=>value}
* @return array{attribute=>value , attribute=>value} or false if the question ID does not exist (anymore)
*/
function getQuestionAttributes($qid, $type='')
{
Expand All @@ -3404,6 +3404,11 @@ function getQuestionAttributes($qid, $type='')
$query = "SELECT type FROM ".db_table_name('questions')." WHERE qid=$qid and parent_qid=0 group by type";
$result = db_execute_assoc($query) or safe_die("Error finding question attributes"); //Checked
$row=$result->FetchRow();
if ($row===false) // Question was deleted while running the survey
{
$cache[$qid]=false;
return false;
}
$type=$row['type'];
}

Expand Down
2 changes: 1 addition & 1 deletion group.php
Expand Up @@ -334,7 +334,7 @@
if ($ia[5] == $gid)
{
$qidattributes=getQuestionAttributes($ia[0]);
if ($qidattributes['hidden']==1) {
if ($qidattributes===false || $qidattributes['hidden']==1) {
// Should we really skip the question here, maybe the result won't be stored if we do that
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion index.php
Expand Up @@ -1092,7 +1092,7 @@ function checkgroupfordisplay($gid)
{
// Check if this question is hidden
$qidattributes=getQuestionAttributes($ia[0]);
if ($qidattributes['hidden']==0)
if ($qidattributes!==false && $qidattributes['hidden']==0)
{
$countQuestionsInThisGroup++;
if ($ia[7] == "Y") //This question is conditional
Expand Down
94 changes: 49 additions & 45 deletions question.php
Expand Up @@ -90,64 +90,68 @@

// MANAGE CONDITIONAL QUESTIONS AND HIDDEN QUESTIONS
$qidattributes=getQuestionAttributes($ia[0]);
if ($qidattributes===false) // Question was deleted
{
$qidattributes['hidden']==1; //Workaround to skip the question if it was deleted while the survey is running in test mode
}
$conditionforthisquestion=$ia[7];
$questionsSkipped=0;

while ($conditionforthisquestion == "Y" || $qidattributes['hidden']==1) //IF CONDITIONAL, CHECK IF CONDITIONS ARE MET; IF HIDDEN MOVE TO NEXT
{ // this is a while, not an IF because if we skip the question we loop on the next question, see below
if (checkquestionfordisplay($ia[0]) === true && $qidattributes['hidden']==0)
{ // question will be displayed
// we set conditionforthisquestion to N here because it is used later to select style=display:'' for the question
$conditionforthisquestion="N";
}
else
{
$questionsSkipped++;
if (returnglobal('move') == "movenext")
if (checkquestionfordisplay($ia[0]) === true && $qidattributes['hidden']==0)
{ // question will be displayed
// we set conditionforthisquestion to N here because it is used later to select style=display:'' for the question
$conditionforthisquestion="N";
}
else
{
$currentquestion++;
if(isset($_SESSION['fieldarray'][$currentquestion]))
$questionsSkipped++;
if (returnglobal('move') == "movenext")
{
$ia=$_SESSION['fieldarray'][$currentquestion];
}
if ($_SESSION['step']>=$_SESSION['totalsteps'])
{
$move="movesubmit";
submitanswer(); // complete this answer (submitdate)
break;
}
$_SESSION['step']++;
foreach ($_SESSION['grouplist'] as $gl)
{
if ($gl[0] == $ia[5])
$currentquestion++;
if(isset($_SESSION['fieldarray'][$currentquestion]))
{
$gid=$gl[0];
$groupname=$gl[1];
$groupdescription=$gl[2];
if (auto_unescape($_POST['lastgroupname']) != strip_tags($groupname) && $groupdescription) {$newgroup = "Y";} else {$newgroup == "N";}
$ia=$_SESSION['fieldarray'][$currentquestion];
}
if ($_SESSION['step']>=$_SESSION['totalsteps'])
{
$move="movesubmit";
submitanswer(); // complete this answer (submitdate)
break;
}
$_SESSION['step']++;
foreach ($_SESSION['grouplist'] as $gl)
{
if ($gl[0] == $ia[5])
{
$gid=$gl[0];
$groupname=$gl[1];
$groupdescription=$gl[2];
if (auto_unescape($_POST['lastgroupname']) != strip_tags($groupname) && $groupdescription) {$newgroup = "Y";} else {$newgroup == "N";}
}
}
}
}
elseif (returnglobal('move') == "moveprev")
{
$currentquestion--; // if we reach -1, this means we must go back to first page
if ($currentquestion >= 0)
{
$ia=$_SESSION['fieldarray'][$currentquestion];
$_SESSION['step']--;
}
else
elseif (returnglobal('move') == "moveprev")
{
$_SESSION['step']=0;
display_first_page();
exit;
$currentquestion--; // if we reach -1, this means we must go back to first page
if ($currentquestion >= 0)
{
$ia=$_SESSION['fieldarray'][$currentquestion];
$_SESSION['step']--;
}
else
{
$_SESSION['step']=0;
display_first_page();
exit;
}
}
// because we skip this question, we need to loop on the same condition 'check-block'
// with the new question (we have overwritten $ia)
$conditionforthisquestion=$ia[7];
$qidattributes=getQuestionAttributes($ia[0]);
}
// because we skip this question, we need to loop on the same condition 'check-block'
// with the new question (we have overwritten $ia)
$conditionforthisquestion=$ia[7];
$qidattributes=getQuestionAttributes($ia[0]);
}
} // End of while conditionforthisquestion=="Y"

//SUBMIT
Expand Down
2 changes: 1 addition & 1 deletion survey.php
Expand Up @@ -257,7 +257,7 @@
if ($ia[5] == $gid)
{
$qidattributes=getQuestionAttributes($ia[0]);
if ($qidattributes['hidden']==1) {
if ($qidattributes===false || $qidattributes['hidden']==1) {
continue;
}
$qtypesarray[$ia[1]] = $ia[4];
Expand Down

0 comments on commit ba4045d

Please sign in to comment.