View Issue Details

This bug affects 1 person(s).
 10
IDProjectCategoryView StatusLast Update
03799Bug reportsSurvey takingpublic2010-10-19 21:12
Reporterronvdburg Assigned Toc_schmitz  
PrioritynormalSeverityminor 
Status closedResolutionfixed 
Product Version1.85+ 
Fixed in Version1.90+ 
Summary03799: Assure that the submit button appears if the last group has no questions
Description

Suppose:
= The survey is in group mode.
= The last group has only conditional questions.
= None of the last group's conditions are satisfied.

In other words: the last group of the survey should be skipped.

Then the "submit" button does not show anywhere, leaving the user questioning if the survey was submitted or not.
The effect is that the "next" button on the previous group's screen is actually not only a "next", but also a "submit" without the user seeing it.

Additional Information

I included a "diff -u" to solve this issue.

The solution I chose is to change the function checkgroupfordisplay in index.php with a leading statement:

if (this is the last group) then return true;

The reasons for this solution:
a) You may try to put the "submit" button on the last ACTUAL group (one that has at least one question). This would mean to "look forward" if this group will be the last one.
One option would be to change the variable totalsteps. This is deemed impossible. Currently the variable is determined by counting the number of defined groups. What we need is the number of non-empty-groups (groups that have at least one question after condition evaluation). This would mean that you have to evaluate a lot: a lot of inefficiency.
Also, you can not know whether to put the "submit" button on a previous group if a next group depends on answers in the current group. This would mean that javascript should be used to "toggle" between a "next" button and a "submit" button based on conditions. This is undoable.

b) A survey admin could create a boilerplate question in the last group with a condition that holds true if all the other questions in the last group evaluate to false.
I regard this an impractical work-around, because this depends on the admin's ability to negate compound conditions properly.

c) You may also change code after the false return of the function:

If "checkgroupfordisplay" returns false AND it is the last group then show an empty page with the "prev" + "save" + "submit" button.

This appeared to me to be much more work to code.

d) The solution I posted is also capable of handling an explicit "submit" button if the last n (> 1) groups all evaluate to 0 questions.

TagsNo tags attached.
Attached Files
ShowSubmitOnLastEmptyGroup.txt (739 bytes)   
--- index-185plus-build7593-20090907.php        2009-08-24 00:37:55.000000000 +0200
+++ index.php   2009-10-28 13:46:12.000000000 +0100
@@ -936,6 +936,10 @@
        //the function will return false, to indicate that the whole group
        //should not display at all.
        global $dbprefix, $connect;
+       if (isset($_SESSION['step']) && ($_SESSION['step'] == $_SESSION['totalsteps']))
+       {
+               return true; // If this is the last group then show it, even if there are no questions. Otherwise you won't get a <Submit> button.
+       }
        $countQuestionsInThisGroup=0;
        $countConditionalQuestionsInThisGroup=0;
        foreach ($_SESSION['fieldarray'] as $ia) //Run through all the questions
feature03799-v1.diff (4,435 bytes)   
Index: group.php
===================================================================
--- group.php	(revision 7789)
+++ group.php	(working copy)
@@ -59,6 +59,9 @@
 }
 
 //SEE IF THIS GROUP SHOULD DISPLAY
+global $show_empty_group_if_the_last_group_is_hidden;
+my $show_empty_group = false;
+
 if (isset($move) && $_SESSION['step'] != 0 && $move != "movesubmit")
 {
 	while(checkgroupfordisplay($_SESSION['grouplist'][$_SESSION['step']-1][0]) === false)
@@ -73,9 +76,19 @@
         }
         if ($_SESSION['step']>$_SESSION['totalsteps']) 
         {
-            $move = "movesubmit";
-		submitanswer(); // complete this answer (submitdate)
-            break;
+			// We are skipping groups, but we moved 'off' the last group.
+			// Now choose to implement an implicit submit (old behaviour),
+			// or create an empty page giving the user the explicit option to submit.
+			if (isset($show_empty_group_if_the_last_group_is_hidden) && $show_empty_group_if_the_last_group_is_hidden == true)
+			{
+				$show_empty_group = true;
+				break;
+			} else
+			{
+            	$move = "movesubmit";
+				submitanswer(); // complete this answer (submitdate)
+            	break;
+			}
         } 
 	}
 }
@@ -297,10 +310,17 @@
 //******************************************************************************************************
 
 //GET GROUP DETAILS
-$grouparrayno=$_SESSION['step']-1;
-$gid=$_SESSION['grouplist'][$grouparrayno][0];
-$groupname=$_SESSION['grouplist'][$grouparrayno][1];
-$groupdescription=$_SESSION['grouplist'][$grouparrayno][2];
+if ($show_empty_group) {
+	$gid=-1; // Make sure the gid is unused. This will assure that the foreach (fieldarray as ia) has no effect.
+	$groupname=$clang->gT("Finalising your survey");
+	$groupdescription=$clang->gT("There are no more questions. If you are satisfied, press the <submit> button");
+} else
+{
+	$grouparrayno=$_SESSION['step']-1;
+	$gid=$_SESSION['grouplist'][$grouparrayno][0];
+	$groupname=$_SESSION['grouplist'][$grouparrayno][1];
+	$groupdescription=$_SESSION['grouplist'][$grouparrayno][2];
+}
 
 require_once("qanda.php"); //This should be qanda.php when finished
 
@@ -376,7 +396,12 @@
 } //end iteration
 
 
-$percentcomplete = makegraph($_SESSION['step'], $_SESSION['totalsteps']);
+if ($show_empty_group) {
+	$percentcomplete = makegraph($_SESSION['totalsteps'], $_SESSION['totalsteps']);
+} else
+{
+	$percentcomplete = makegraph($_SESSION['step'], $_SESSION['totalsteps']);
+}
 $languagechanger = makelanguagechanger();
 
 //READ TEMPLATES, INSERT DATA AND PRESENT PAGE
@@ -409,7 +434,12 @@
     <!--\n";
     
 // Find out if there are any array_filter questions in this group
-$array_filterqs = getArrayFiltersForGroup($surveyid,$gid);
+if ($show_empty_group) {
+	unset($array_filterqs);
+} else
+{
+	$array_filterqs = getArrayFiltersForGroup($surveyid,$gid);
+}
 
 print <<<END
 	function noop_checkconditions(value, name, type)
Index: config-defaults.php
===================================================================
--- config-defaults.php	(revision 7789)
+++ config-defaults.php	(working copy)
@@ -345,6 +345,31 @@
  */
 $hide_groupdescr_allinone=true;
 
+/**
+ * Before 1.87, the user may not see a <submit> button.
+ * The variable show_empty_group_if_the_last_group_is_hidden can change this behaviour.
+ * The default is true; to get the old behaviour, change the variable to false.
+ *
+ * DETAILS OF THE OLD BEHAVIOUR (set variable to false)
+ * Suppose:
+ * = The survey is in group mode.
+ * = The last group has only conditional questions.
+ * = None of the last group's conditions are satisfied.
+ *
+ * In other words: the last group of the survey should be skipped.
+ *
+ * Then the <submit> button does not show anywhere, leaving the user questioning
+ * if the survey was submitted or not.
+ * The effect is that the <next> button on the previous group's screen is actually
+ * not only a <next>, but also a <submit> without the user seeing it.
+ *
+ * DETAILS OF THE NEW BEHAVIOUR (set variable to true)
+ * If the user of a group survey presses <next> and the last group has no questions
+ * (due to unsatisfied conditions), present an "empty" group, with a <submit> button.
+ * The group title is something descriptive, the <prev> and other buttons are also
+ * available (if appropriate).
+ */
+$show_empty_group_if_the_last_group_is_hidden=true;
 
 /**
  * Use FireBug Lite for JavaScript and template development and testing.
feature03799-v1.diff (4,435 bytes)   
index.php.diff (820 bytes)   
Index: index.php
===================================================================
--- index.php	(revision 9091)
+++ index.php	(working copy)
@@ -2571,7 +2571,7 @@
         $surveymover .=  "\t<input class='submit' type='submit' onclick=\"javascript:document.limesurvey.move.value = 'movenext';\" value=' "
         . $clang->gT("Next")." &gt;&gt; ' name='move2' />\n";
     }
-    if ($_SESSION['step'] && ($_SESSION['step'] == $_SESSION['totalsteps']) && !$presentinggroupdescription)
+    if ($_SESSION['step'] && ($_SESSION['step'] >= $_SESSION['totalsteps']) && !$presentinggroupdescription)
     {
         $surveymover .= "\t<input class='submit' type='submit' accesskey='l' onclick=\"javascript:document.limesurvey.move.value = 'movesubmit';\" value=' "
         . $clang->gT("Submit")." ' name='move2' />\n";
index.php.diff (820 bytes)   
Bug heat10
Complete LimeSurvey version number (& build)7593
I will donate to the project if issue is resolved
Browser
Database type & versionMysql
Server OS (if known)Linux
Webserver software & version (if known)Apache
PHP Version5.1.6

Users monitoring this issue

ronvdburg

Activities

user372

2009-10-28 16:26

  ~09893

@ Lemeur: can you please have a look at this patch?

lemeur

lemeur

2009-10-28 17:25

developer   ~09898

Last edited: 2009-10-28 17:27

I'm not sure this is the correct fix for 2 reasons:
1- some LS administrators may want to decide if they really want this last empty page top be displayed
==> this means that we must, at least, make it possible to switch this new behaviour ON/OFF in the config.php file

2- the last 'empty' group page will be shown with the true title of last group (which is not relevant and even should be hidden to the participant).
==> We must find a way to display an empty page with another group title in this case

So to sum up: I think the best solution would be to:

  • add a config-defaults.php option to switch on/off this feature
  • implement this test not in the checkgroupfordisplay() function, but directly in group.php, so that:
    • if checkgroupfordisplay returns false and if we are on latest group, then display an empty page with a "You've reached the end of the survey, please submit your answers now" message instead of an irrelevant group title.

What do you think ?

@ronvdburg, do you think you could submit such a patch ?

Thanks in advance,
Thibault

ronvdburg

ronvdburg

2009-10-28 18:01

reporter   ~09901

Hi Thibault,

You are right. With my patch, I wanted to cut some corners: I thought I could do with only 4 lines of extra code... ;-)

1- Good idea.
2- Much better. I have to see what code I need for that.

I will see whether I can submit a patch. This may take a little while, because:

  • I need to move from svn to git.
  • I need to get the latest version.
  • Coding now needs to be at config.php + group.php.

Regards,
Ron

lemeur

lemeur

2009-10-28 18:07

developer   ~09902

Hi Ron,

I know this fix won't be difficult for you (knowing what you've already done in the past ;-) ).

Why move from SVN to Git ??

Yes, a fix applied to latest SVN would be better.

Fix in config.php is nothing more that to declare a new "$myoption = true;" line and to add a litle comment ;-)

Fix in group.php might be nothing more that your 4 lines + something to overwrite the text displayed as Group Title... I'm just saying this, but I haven't openned group.php to check ;-)

ronvdburg

ronvdburg

2009-10-29 15:18

reporter   ~09916

Hi Thibault,

I implemented the feature as you suggested.

The SVN to GIT: sorry my fault, I was thinking about another great project RT (request tracker), who moved to using GIT.

I uploaded the "svn di" file (w.r.t. rev 7789).

Please note that I haven't tested it, I have just been typing code in one go. I am currently running a very important rev 7593 survey that I do not want to disturb.

Furthermore, I used two texts (groupname + groupdescription) using the clang->gT construct. However, I did not add both texts to all the language files because I want to be sure that the default version of the texts are confirmed.
I did not consider alternatives for the texts: an extra option in the survey definition; or a template .pstpl file.

lemeur

lemeur

2009-11-07 14:33

developer   ~09991

Fixed in 7847.
Thanks for the patch.

Thibault

ronvdburg

ronvdburg

2010-08-26 14:59

reporter   ~12714

I have had the time to check the official patch (in 7847) for solving this issue.
There is indeed a separate "Submit your answers" page. However, the submit button does not show.

In my opinion, there needs to be a change from '==' to '>=', because 'step' is now 1 larger than 'totalsteps'.

I cannot attach the svn diff file, so here it is.

Index: index.php

--- index.php (revision 9091)
+++ index.php (working copy)
@@ -2571,7 +2571,7 @@
$surveymover .= "\t<input class='submit' type='submit' onclick=\"javascript:document.limesurvey.move.value = 'movenext';\" value=' "
. $clang->gT("Next")." >> ' name='move2' />\n";
}

  • if ($_SESSION['step'] && ($_SESSION['step'] == $_SESSION['totalsteps']) && !$presentinggroupdescription)
  • if ($_SESSION['step'] && ($_SESSION['step'] >= $_SESSION['totalsteps']) && !$presentinggroupdescription)
    {
    $surveymover .= "\t<input class='submit' type='submit' accesskey='l' onclick=\"javascript:document.limesurvey.move.value = 'movesubmit';\" value=' "
    . $clang->gT("Submit")." ' name='move2' />\n";
c_schmitz

c_schmitz

2010-10-13 20:45

administrator   ~13150

Thank you! Fixed in rev 9232

c_schmitz

c_schmitz

2010-10-19 21:12

administrator   ~13281

Released in 1.90 plus release.

Issue History

Date Modified Username Field Change
2009-10-28 14:35 ronvdburg New Issue
2009-10-28 14:35 ronvdburg Status new => assigned
2009-10-28 14:35 ronvdburg Assigned To => user372
2009-10-28 14:35 ronvdburg File Added: ShowSubmitOnLastEmptyGroup.txt
2009-10-28 14:35 ronvdburg LimeSurvey build number => 7593
2009-10-28 14:35 ronvdburg Database & DB-Version => Mysql
2009-10-28 14:35 ronvdburg Operating System (Server) => Linux
2009-10-28 14:35 ronvdburg Webserver => Apache
2009-10-28 14:35 ronvdburg PHP Version => 5.1.6
2009-10-28 16:26 user372 Note Added: 09893
2009-10-28 16:26 user372 Assigned To user372 => lemeur
2009-10-28 17:25 lemeur Note Added: 09898
2009-10-28 17:25 lemeur Status assigned => feedback
2009-10-28 17:25 lemeur Note Edited: 09898
2009-10-28 17:27 lemeur Note Edited: 09898
2009-10-28 18:01 ronvdburg Note Added: 09901
2009-10-28 18:07 lemeur Note Added: 09902
2009-10-29 15:10 ronvdburg File Added: feature03799-v1.diff
2009-10-29 15:18 ronvdburg Note Added: 09916
2009-11-07 14:12 lemeur Status feedback => acknowledged
2009-11-07 14:33 lemeur Note Added: 09991
2009-11-07 14:33 lemeur Status acknowledged => resolved
2009-11-07 14:33 lemeur Fixed in Version => 1.87RC1
2009-11-07 14:33 lemeur Resolution open => fixed
2009-11-13 16:40 c_schmitz Status resolved => closed
2010-08-26 14:52 ronvdburg Issue Monitored: ronvdburg
2010-08-26 14:59 ronvdburg Note Added: 12714
2010-08-26 14:59 ronvdburg Status closed => feedback
2010-08-26 14:59 ronvdburg Resolution fixed => reopened
2010-08-26 15:00 ronvdburg File Added: index.php.diff
2010-09-09 13:21 Mazi Status feedback => assigned
2010-10-13 20:43 c_schmitz Assigned To lemeur => c_schmitz
2010-10-13 20:45 c_schmitz Note Added: 13150
2010-10-13 20:45 c_schmitz Status assigned => resolved
2010-10-13 20:45 c_schmitz Fixed in Version 1.87RC1 => 1.90+
2010-10-13 20:45 c_schmitz Resolution reopened => fixed
2010-10-19 21:12 c_schmitz Note Added: 13281
2010-10-19 21:12 c_schmitz Status resolved => closed
2010-10-25 00:18 c_schmitz Category Survey at Runtime => Survey taking
2021-08-03 18:57 guest Bug heat 8 => 10