View Issue Details

IDProjectCategoryView StatusLast Update
04660User patchesSurvey designpublic2010-12-14 13:02
Reporterroom2web Assigned Toc_schmitz  
PrioritynormalSeverityminor 
Status closedResolutionfixed 
Product Version1.90 
Target VersionFixed in Version1.91 
Summary04660: possibility to edit survey answers after completion of survey
Description

It should be possible to allow for editing survey answers after a participant has completed his or her survey. This patch adds a select box "Allow edit after completion" to the survey settings and allows users to change their answers if he or she logs in again.

If the flag "Allow edit after completion" is set, users who login will always start the survey at page 1.

Tokenbased answer persistence needs to be set for this to work as expected.

TagsNo tags attached.
Complete LimeSurvey version number (& build)9180

Activities

room2web

room2web

2010-10-07 11:10

reporter   ~13022

Last edited: 2010-10-07 11:15

View 2 revisions

The feature was implemented on LS1.90 so the svn patches are patched 1.90 files against svn. Give me a shout if this doesn't work out.

edit: The Patches without svn-numbers were patched against LS1.90

c_schmitz

c_schmitz

2010-10-12 00:18

administrator   ~13103

Hello!

Thank you for providing this patch.
The patches need to be created with Subversion (svn diff) against our development branch at:
https://limesurvey.svn.sourceforge.net/svnroot/limesurvey/source/limesurvey_dev

If you need help let us know.

room2web

room2web

2010-12-10 12:35

reporter  

ls1.r9619.patch (11,073 bytes)
Index: admin/database.php
===================================================================
--- admin/database.php	(Revision 9619)
+++ admin/database.php	(Arbeitskopie)
@@ -1072,6 +1072,7 @@
                             'listpublic'=>$_POST['public'],
                             'htmlemail'=>$_POST['htmlemail'],
                             'tokenanswerspersistence'=>$_POST['tokenanswerspersistence'],
+                            'alloweditaftercompletion'=>$_POST['alloweditaftercompletion'],
                             'usecaptcha'=>$_POST['usecaptcha'],
                             'emailresponseto'=>trim($_POST['emailresponseto']),
                             'emailnotificationto'=>trim($_POST['emailnotificationto']),
@@ -1373,6 +1374,7 @@
                             'public'=>$_POST['public'],
                             'htmlemail'=>$_POST['htmlemail'],
                             'tokenanswerspersistence'=>$_POST['tokenanswerspersistence'],
+                            'alloweditaftercompletion'=>$_POST['alloweditaftercompletion'],
                             'usecaptcha'=>$_POST['usecaptcha'],
                             'publicstatistics'=>$_POST['publicstatistics'],
                             'publicgraphs'=>$_POST['publicgraphs'],
Index: admin/install/create-mysql.sql
===================================================================
--- admin/install/create-mysql.sql	(Revision 9619)
+++ admin/install/create-mysql.sql	(Arbeitskopie)
@@ -257,6 +257,7 @@
   `listpublic` char(1) default 'N',
   `htmlemail` char(1) default 'N',
   `tokenanswerspersistence` char(1) default 'N',
+  `alloweditaftercompletion` char(1) default 'N',
   `assessments` char(1) default 'N', 
   `usecaptcha` char(1) default 'N',
   `usetokens` char(1) default 'N',
Index: admin/install/create-mssqlnative.sql
===================================================================
--- admin/install/create-mssqlnative.sql	(Revision 9619)
+++ admin/install/create-mssqlnative.sql	(Arbeitskopie)
@@ -282,6 +282,7 @@
   [publicgraphs] char(1) default 'N',
   [htmlemail] char(1) default 'N',
   [tokenanswerspersistence] char(1) default 'N',
+  [alloweditaftercompletion] char(1) default 'N',
   [assessments] char(1) default 'N',
   [usecaptcha] char(1) default 'N',
   [usetokens] char(1) default 'N',
Index: admin/install/create-postgres.sql
===================================================================
--- admin/install/create-postgres.sql	(Revision 9619)
+++ admin/install/create-postgres.sql	(Arbeitskopie)
@@ -287,6 +287,7 @@
     publicgraphs character(1) DEFAULT 'N'::bpchar,
     htmlemail character(1) DEFAULT 'N'::bpchar,
     tokenanswerspersistence character(1) DEFAULT 'N'::bpchar,
+    alloweditaftercompletion character(1) DEFAULT 'N'::bpchar,
     assessments character(1) DEFAULT 'N'::bpchar,
     usecaptcha character(1) DEFAULT 'N'::bpchar,
     bouncetime bigint,
Index: admin/install/create-mssql.sql
===================================================================
--- admin/install/create-mssql.sql	(Revision 9619)
+++ admin/install/create-mssql.sql	(Arbeitskopie)
@@ -273,6 +273,7 @@
   [publicgraphs] char(1) default 'N',
   [htmlemail] char(1) default 'N',
   [tokenanswerspersistence] char(1) default 'N',
+  [alloweditaftercompletion] char(1) default 'N',
   [assessments] char(1) default 'N',
   [usecaptcha] char(1) default 'N',
   [usetokens] char(1) default 'N',
Index: admin/editsurveysettings.php
===================================================================
--- admin/editsurveysettings.php	(Revision 9619)
+++ admin/editsurveysettings.php	(Arbeitskopie)
@@ -866,6 +866,16 @@
         $editsurvey .= ">".$clang->gT("No")."</option>\n"
         . "</select></li>\n";
 
+            // Allow editing answers after completion 
+            $editsurvey .= "<li><label for=''>".$clang->gT("Allow editing answers after completion?")."</label>\n"
+            . "<select id='alloweditaftercompletion' name='alloweditaftercompletion' onchange=\"javascript: if (document.getElementById('private').value == 'Y') {alert('".$clang->gT("This option can't be set if Anonymous answers are used","js")."'); this.value='N';}\">\n"
+            . "<option value='Y'";
+            if ($esrow['alloweditaftercompletion'] == "Y") {$editsurvey .= " selected='selected'";}
+            $editsurvey .= ">".$clang->gT("Yes")."</option>\n"
+            . "<option value='N'";
+            if ($esrow['alloweditaftercompletion'] == "N") {$editsurvey .= " selected='selected'";}
+            $editsurvey .= ">".$clang->gT("No")."</option>\n"
+            . "</select></li>\n";
 
         // Save timings
         $editsurvey .= "<li><label for='savetimings'>".$clang->gT("Save timings?")."</label>\n";
Index: config.php
===================================================================
--- config.php	(Revision 9619)
+++ config.php	(Arbeitskopie)
@@ -25,18 +25,17 @@
 // Basic Setup
 
 $databasetype       =   'mysql';       // ADOdb database driver - valid values are mysql, mysqli, odbc_mssql, mssql_n, odbtp or postgres
-// mysql: Recommended driver for mysql
-// mysqli: Slightly faster driver for mysql - not on all server systems available
-// odbc_mssql: MSSQL driver using ODBC with MS SQL Server
-// mssqlnative: Native SQL Server driver for SQL Server 2005+
-// mssql_n: Experimental driver for MS SQL Server which handles UTF-8 charsets
-// odbtp: ODBTP driver to access MSSQL-Server is needed for this one - we also recommend to activate $databasepersistent for decent speed
-// postgres: Standard postgres driver
+                                       // mysql: Recommended driver for mysql
+                                       // mysqli: Slightly faster driver for mysql - not on all server systems available 
+                                       // odbc_mssql: MSSQL driver using ODBC with MS SQL Server
+                                       // mssql_n: Experimental driver for MS SQL Server which handles UTF-8 charsets
+                                       // odbtp: ODBTP driver to access MSSQL-Server is needed for this one - we also recommend to activate $databasepersistent for decent speed
+                                       // postgres: Standard postgres driver
 
-$databaselocation   =   'localhost';   // Network location of your Database - for odbc_mssql or mssqlnative use the mssql servername, not localhost or IP
+$databaselocation   =   'localhost';   // Network location of your Database - for odbc_mssql use the mssql servername, not localhost or IP
 $databasename       =   'limesurvey_dev';  // The name of the database that we will create
-$databaseuser       =   'root';        // The name of a user with rights to create db (or if db already exists, then rights within that db)
-$databasepass       =   '';            // Password of db user
+$databaseuser       =   'limesurvey';        // The name of a user with rights to create db (or if db already exists, then rights within that db)
+$databasepass       =   'BWq4V8hsfM8rcNeH';            // Password of db user
 $dbprefix           =   'lime_';       // A global prefix that can be added to all LimeSurvey tables. Use this if you are sharing
 // a database with other applications. Suggested prefix is 'lime_'
 
Index: index.php
===================================================================
--- index.php	(Revision 9619)
+++ index.php	(Arbeitskopie)
@@ -655,8 +655,12 @@
 {
 	//check if tokens actually haven't been already used
 	$areTokensUsed = usedTokens(db_quote(trim(strip_tags(returnglobal('token')))));
-    
-    $tkquery = "SELECT * FROM ".db_table_name('tokens_'.$surveyid)." WHERE token='".db_quote($token)."' AND (completed = 'N' or completed='')";
+	// check if token actually does exist
+	// check also if it is allowed to change survey after completion
+	if ($thissurvey['alloweditaftercompletion'] == 'Y' ) {
+    	$tkquery = "SELECT * FROM ".db_table_name('tokens_'.$surveyid)." WHERE token='".db_quote($token)."' ";
+		} else {
+    	$tkquery = "SELECT * FROM ".db_table_name('tokens_'.$surveyid)." WHERE token='".db_quote($token)."' AND (completed = 'N' or completed='')";
     $tkresult = db_execute_num($tkquery); //Checked
     $tokendata = $tkresult->FetchRow();
     if ($tkresult->RecordCount()==0 || $areTokensUsed)
@@ -681,7 +685,13 @@
 }
 if ($tokensexist == 1 && isset($token) && $token && db_tables_exist($dbprefix.'tokens_'.$surveyid)) //check if token is in a valid time frame
 {
-    $tkquery = "SELECT * FROM ".db_table_name('tokens_'.$surveyid)." WHERE token='".db_quote($token)."' AND (completed = 'N' or completed='')";
+
+		// check also if it is allowed to change survey after completion
+		if ($thissurvey['alloweditaftercompletion'] == 'Y' ) {
+    	$tkquery = "SELECT * FROM ".db_table_name('tokens_'.$surveyid)." WHERE token='".db_quote($token)."' ";
+		} else {
+    	$tkquery = "SELECT * FROM ".db_table_name('tokens_'.$surveyid)." WHERE token='".db_quote($token)."' AND (completed = 'N' or completed='')";
+		}
     $tkresult = db_execute_assoc($tkquery); //Checked
     $tokendata = $tkresult->FetchRow();
     if ((trim($tokendata['validfrom'])!='' && $tokendata['validfrom']>date_shift(date("Y-m-d H:i:s"), "Y-m-d H:i:s", $timeadjust)) ||
@@ -922,12 +932,12 @@
                 $clienttoken=$value;
                 $token=$value;
             }
-            elseif ($column == "saved_thisstep")
+            elseif ($column == "saved_thisstep" && $thissurvey['alloweditaftercompletion'] != 'Y' )
             {
                 $_SESSION['step']=$value;
                 $thisstep=$value-1;
             }
-            elseif ($column =='lastpage' && isset($_GET['token']))
+            elseif ($column =='lastpage' && isset($_GET['token']) && $thissurvey['alloweditaftercompletion'] != 'Y' )
             {
                 if ($value<1) $value=1;
                 $_SESSION['step']=$value;
@@ -2409,7 +2419,14 @@
         //check if tokens actually haven't been already used
 		$areTokensUsed = usedTokens(db_quote(trim(strip_tags(returnglobal('token')))));
         //check if token actually does exist
-        $tkquery = "SELECT COUNT(*) FROM ".db_table_name('tokens_'.$surveyid)." WHERE token='".db_quote(trim(strip_tags(returnglobal('token'))))."' AND (completed = 'N' or completed='')";
+				// check also if it is allowed to change survey after completion (patch by johannes.klug@silverage.de)
+				if ($thissurvey['alloweditaftercompletion'] == 'Y' ) {
+          $tkquery = "SELECT COUNT(*) FROM ".db_table_name('tokens_'.$surveyid)." WHERE token='".db_quote(trim(strip_tags(returnglobal('token'))))."' ";
+				} else {
+        	$tkquery = "SELECT COUNT(*) FROM ".db_table_name('tokens_'.$surveyid)." WHERE token='".db_quote(trim(strip_tags(returnglobal('token'))))."' AND (completed = 'N' or completed='')";
+				}
+
+//				print_r($thissurvey);
         $tkresult = db_execute_num($tkquery);    //Checked
         list($tkexist) = $tkresult->FetchRow();
         if (!$tkexist || $areTokensUsed)
ls1.r9619.patch (11,073 bytes)
room2web

room2web

2010-12-10 12:36

reporter   ~13744

added a patch against the latest svn checkout from dev branch.

c_schmitz

c_schmitz

2010-12-11 13:57

administrator   ~13756

Thank you very much!
Looks good. You forgot the upgrade procedure but I fixed that for you.
This feature will be in 1.91b.

Issue History

Date Modified Username Field Change
2010-10-07 11:07 room2web New Issue
2010-10-07 11:07 room2web File Added: index.php.diff
2010-10-07 11:07 room2web File Added: html.php.diff
2010-10-07 11:08 room2web File Added: html.php.svn9180.diff
2010-10-07 11:08 room2web File Added: index.php.svn9180.diff
2010-10-07 11:10 room2web Note Added: 13022
2010-10-07 11:15 room2web Note Edited: 13022 View Revisions
2010-10-12 00:18 c_schmitz Note Added: 13103
2010-10-12 00:18 c_schmitz Assigned To => c_schmitz
2010-10-12 00:18 c_schmitz Status new => feedback
2010-12-10 12:35 room2web File Added: ls1.r9619.patch
2010-12-10 12:36 room2web Note Added: 13744
2010-12-10 12:36 room2web Status feedback => assigned
2010-12-11 13:37 c_schmitz File Deleted: index.php.diff
2010-12-11 13:37 c_schmitz File Deleted: html.php.diff
2010-12-11 13:38 c_schmitz File Deleted: html.php.svn9180.diff
2010-12-11 13:38 c_schmitz File Deleted: index.php.svn9180.diff
2010-12-11 13:57 c_schmitz Note Added: 13756
2010-12-11 13:57 c_schmitz Status assigned => resolved
2010-12-11 13:57 c_schmitz Fixed in Version => 1.91
2010-12-11 13:57 c_schmitz Resolution open => fixed
2010-12-14 13:02 c_schmitz Status resolved => closed