Skip to content

Commit

Permalink
Fixed issue #05877: Resume later doesn't work with a survey allowing …
Browse files Browse the repository at this point in the history
…public registration
  • Loading branch information
sachdeva-shubham committed Mar 23, 2012
1 parent 8dbb8e5 commit 3816326
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 1 deletion.
12 changes: 11 additions & 1 deletion group.php
Expand Up @@ -235,7 +235,16 @@
// must do this here to process the POSTed values
$moveResult = LimeExpressionManager::JumpTo($_SESSION['step'],false); // by jumping to current step, saves data so far

showsaveform(); // generates a form and exits, awaiting input
//showsaveform(); // generates a form and exits, awaiting input
if($thissurvey['tokenanswerspersistence'] != 'Y' || !tableExists('tokens_'.$surveyid))
{
showsaveform();
}
else
{
$flashmessage = savedsilent();

}
}

if ($thissurvey['active'] == "Y" && isset($_POST['saveprompt']))
Expand All @@ -253,6 +262,7 @@
$LEMskipReprocessing=true;

// TODO - does this work automatically for token answer persistence? Used to be savedsilent()

}

//Now, we check mandatory questions if necessary
Expand Down
86 changes: 86 additions & 0 deletions save.php
Expand Up @@ -189,6 +189,92 @@ function savedcontrol()
}
}

/**
* savesilent() saves survey responses when the "Resume later" button
* is press but has no interaction. i.e. it does not ask for email,
* username or password or capture.
*
* @return string confirming successful save.
*/
function savedsilent()
{
global $connect, $surveyid, $dbprefix, $thissurvey, $errormsg, $publicurl, $sitename, $timeadjust, $clang, $clienttoken, $thisstep, $modrewrite;
submitanswer();
// Prepare email
$tokenentryquery = 'SELECT * from '.$dbprefix.'tokens_'.$surveyid.' WHERE token=\''.sanitize_paranoid_string($clienttoken).'\';';
$tokenentryresult = db_execute_assoc($tokenentryquery);
$tokenentryarray = $tokenentryresult->FetchRow();

$from = $thissurvey['adminname'].' <'.$thissurvey['adminemail'].'>';
$to = $tokenentryarray['firstname'].' '.$tokenentryarray['lastname'].' <'.$tokenentryarray['email'].'>';
$subject = $clang->gT("Saved Survey Details") . " - " . $thissurvey['name'];
$message = $clang->gT("Thank you for saving your survey in progress. You can return to the survey at the same point you saved it at any time using the link from this or any previous email sent to regarding this survey.","unescaped")."\n\n";
$message .= $clang->gT("Reload your survey by clicking on the following link (or pasting it into your browser):","unescaped")."\n";
$language = $tokenentryarray['language'];

if($modrewrite)
{
$message .= "\n\n$publicurl/$surveyid/lang-$language/tk-$clienttoken";
}
else
{
$message .= "\n\n$publicurl/index.php?lang=$language&sid=$surveyid&token=$clienttoken";
}
if (SendEmailMessage(null, $message, $subject, $to, $from, $sitename, false, getBounceEmail($surveyid)))
{
$emailsent="Y";
}
else
{
echo "Error: Email failed, this may indicate a PHP Mail Setup problem on your server. Your survey details have still been saved, however you will not get an email with the details. You should note the \"name\" and \"password\" you just used for future reference.";
}
return $clang->gT('Your survey was successfully saved.');
}

// submitanswer sets the submitdate
// Only used by question.php and group.php if next pages
// should not display due to conditions and generally used by survey.php
// In this case all answers have already been updated by save.php
// but movesubmit status was only set after calling save.php
// ==> thus we need to update submitdate here.
function submitanswer()
{
global $thissurvey,$timeadjust;
global $surveyid, $connect, $clang, $move;

if ($thissurvey['anonymized'] =="Y" && $thissurvey['datestamp'] =="N")
{
// In case of anonymized responses survey with no datestamp
// then the the answer submitdate gets a conventional timestamp
// 1st Jan 1980
$mysubmitdate = date("Y-m-d H:i:s",mktime(0,0,0,1,1,1980));
}
else
{
$mysubmitdate = date_shift(date("Y-m-d H:i:s"), "Y-m-d H:i:s", $timeadjust);
}

$query = "";
if (isset($move) && ($move == "movesubmit") && ($thissurvey['active'] == "Y"))
{
if (!isset($_SESSION['srid']))
{ //due to conditions no answer was displayed and yet we must submit
$query=createinsertquery();
if ($result=$connect->Execute($query))
{
$tempID=$connect->Insert_ID($thissurvey['tablename'],"id");
$_SESSION['srid'] = $tempID;
}
}
$query = "UPDATE {$thissurvey['tablename']} SET ";
$query .= " submitdate = ".$connect->DBDate($mysubmitdate);
$query .= " WHERE id=" . $_SESSION['srid'];
}

$result=$connect->Execute($query); // Checked
return $result;
}

/**
* This functions saves the answer time for question/group and whole survey.
* [ It compares current time with the time in $_POST['start_time'] ]
Expand Down

1 comment on commit 3816326

@TMSWhite
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has a bug in submitanswer(). createinsertquery() doesn't exist any more, and isn' t needed, so submitanswer() is obsolete.

Take a look at LimeExpressionManager::_UpdateValuesInDatabase($updatedValues, $finished=true). This is called by the JumpTo() to statement to save the data prior to showsavedform() or savedsilent()

So, JumpTo will save the data (so you don't need savedanswer()). The only thing you want it to do is to set the submit date.

So, I recommend doing the following instead of this:
(1) change JumpTo to this:
static function JumpTo($seq,$preview=false,$processPOST=true,$force=false,$changeLang=false,$setSubmitDate=false)
(2) change _UpdateValuesInDataBase to:
private function _UpdateValuesInDatabase($updatedValues, $finished=false,$setSubmitDate=false)
(3) Have JumpTo pass the $setSubmitDate to _UpdateValuesInDatabase()
(4) Have _UpdateValuesInDatabase() set the submit date if either $finished (which it already does), or if $setSubmitDate.

That way you can completely delete submitanswer() again.

Please sign in to comment.