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 fe1ea45 commit 1296664
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 97 deletions.
18 changes: 9 additions & 9 deletions classes/expressions/LimeExpressionManager.php
Expand Up @@ -3209,7 +3209,7 @@ static function NavigateForwards($force=false) {
* @param <type> $updatedValues
* @param <boolean> $finished - true if the survey needs to be finalized
*/
private function _UpdateValuesInDatabase($updatedValues, $finished=false)
private function _UpdateValuesInDatabase($updatedValues, $finished=false,$setSubmitDate=false)
{
// Update these values in the database
global $connect;
Expand Down Expand Up @@ -3404,7 +3404,7 @@ static function GetLastMoveResult($clearSubstitutionInfo=false)
* @param <type> $preview - if true, then treat this group/question as relevant, even if it is not, so that it can be displayed
* @return <type>
*/
static function JumpTo($seq,$preview=false,$processPOST=true,$force=false,$changeLang=false) {
static function JumpTo($seq,$preview=false,$processPOST=true,$force=false,$changeLang=false,$setSubmitDate=false) {
$now = microtime(true);
$LEM =& LimeExpressionManager::singleton();

Expand Down Expand Up @@ -3435,7 +3435,7 @@ static function JumpTo($seq,$preview=false,$processPOST=true,$force=false,$chang
$message .= $result['message'];
$updatedValues = array_merge($updatedValues,$result['updatedValues']);
$finished=false;
$message .= $LEM->_UpdateValuesInDatabase($updatedValues,$finished);
$message .= $LEM->_UpdateValuesInDatabase($updatedValues,$finished,$setSubmitDate);
$LEM->runtimeTimings[] = array(__METHOD__,(microtime(true) - $now));
$LEM->lastMoveResult = array(
'finished'=>$finished,
Expand Down Expand Up @@ -3467,7 +3467,7 @@ static function JumpTo($seq,$preview=false,$processPOST=true,$force=false,$chang
if (!is_null($result) && ($result['mandViolation'] || !$result['valid']))
{
// redisplay the current group
$message .= $LEM->_UpdateValuesInDatabase($updatedValues,false);
$message .= $LEM->_UpdateValuesInDatabase($updatedValues,false,$setSubmitDate);
$LEM->runtimeTimings[] = array(__METHOD__,(microtime(true) - $now));
$LEM->lastMoveResult = array(
'finished'=>false,
Expand All @@ -3490,7 +3490,7 @@ static function JumpTo($seq,$preview=false,$processPOST=true,$force=false,$chang
$LEM->currentQset = array(); // reset active list of questions
if (++$LEM->currentGroupSeq >= $LEM->numGroups)
{
$message .= $LEM->_UpdateValuesInDatabase($updatedValues,true);
$message .= $LEM->_UpdateValuesInDatabase($updatedValues,true,$setSubmitDate);
$LEM->runtimeTimings[] = array(__METHOD__,(microtime(true) - $now));
$LEM->lastMoveResult = array(
'finished'=>true,
Expand Down Expand Up @@ -3524,7 +3524,7 @@ static function JumpTo($seq,$preview=false,$processPOST=true,$force=false,$chang
else
{
// display new group
$message .= $LEM->_UpdateValuesInDatabase($updatedValues,false);
$message .= $LEM->_UpdateValuesInDatabase($updatedValues,false,$setSubmitDate);
$LEM->runtimeTimings[] = array(__METHOD__,(microtime(true) - $now));
$LEM->lastMoveResult = array(
'finished'=>false,
Expand Down Expand Up @@ -3559,7 +3559,7 @@ static function JumpTo($seq,$preview=false,$processPOST=true,$force=false,$chang
if ($grel && ($result['mandViolation'] || !$result['valid']))
{
// redisplay the current question
$message .= $LEM->_UpdateValuesInDatabase($updatedValues,false);
$message .= $LEM->_UpdateValuesInDatabase($updatedValues,false,$setSubmitDate);
$LEM->runtimeTimings[] = array(__METHOD__,(microtime(true) - $now));
$LEM->lastMoveResult = array(
'finished'=>false,
Expand All @@ -3583,7 +3583,7 @@ static function JumpTo($seq,$preview=false,$processPOST=true,$force=false,$chang
$LEM->currentQset = array(); // reset active list of questions
if (++$LEM->currentQuestionSeq >= $LEM->numQuestions)
{
$message .= $LEM->_UpdateValuesInDatabase($updatedValues,true);
$message .= $LEM->_UpdateValuesInDatabase($updatedValues,true,$setSubmitDate);
$LEM->runtimeTimings[] = array(__METHOD__,(microtime(true) - $now));
$LEM->lastMoveResult = array(
'finished'=>true,
Expand Down Expand Up @@ -3637,7 +3637,7 @@ static function JumpTo($seq,$preview=false,$processPOST=true,$force=false,$chang
else
{
// display new question
$message .= $LEM->_UpdateValuesInDatabase($updatedValues,false);
$message .= $LEM->_UpdateValuesInDatabase($updatedValues,false,$setSubmitDate);
$LEM->runtimeTimings[] = array(__METHOD__,(microtime(true) - $now));
$LEM->lastMoveResult = array(
'finished'=>false,
Expand Down
10 changes: 7 additions & 3 deletions group.php
Expand Up @@ -233,17 +233,21 @@
if ($thissurvey['active'] == "Y" && isset($_POST['saveall']))
{
// must do this here to process the POSTed values
$moveResult = LimeExpressionManager::JumpTo($_SESSION['step'],false); // by jumping to current step, saves data so far
//$moveResult = LimeExpressionManager::JumpTo($_SESSION['step'],false); // by jumping to current step, saves data so far

//showsaveform(); // generates a form and exits, awaiting input
if($thissurvey['tokenanswerspersistence'] != 'Y' || !tableExists('tokens_'.$surveyid))
{
$moveResult = LimeExpressionManager::JumpTo($_SESSION['step'],false); // by jumping to current step, saves data so far
showsaveform();
}
else
{
$flashmessage = savedsilent();

$moveResult = LimeExpressionManager::JumpTo($_SESSION['step'],false,true,false,false,true); // by jumping to current step, saves data so far
if (!is_null($moveResult))
{
$flashmessage = $clang->gT('Your survey was successfully saved.');

This comment has been minimized.

Copy link
@TMSWhite

TMSWhite Mar 23, 2012

Contributor

I think you want this for this line instead:

    $flashmessage = savedcontrol();

This comment has been minimized.

Copy link
@sachdeva-shubham

sachdeva-shubham Mar 23, 2012

Author Contributor

I think we don't need this at all.
$flashmessage = savedcontrol();
is after this if block!(look few lines below this line.) isn't it?

This comment has been minimized.

Copy link
@TMSWhite

TMSWhite Mar 23, 2012

Contributor

$flashmessage = savedcontrol();
is in a different if block that isn't active unless $_POST['saveprompt'] is set too.
If it isn't, then we should explicitly add that savedcontrol line.

This comment has been minimized.

Copy link
@sachdeva-shubham

sachdeva-shubham Mar 23, 2012

Author Contributor

ok. here it is http://git.io/8GgM5Q .

This comment has been minimized.

Copy link
@TMSWhite

TMSWhite Mar 23, 2012

Contributor

sadly, that doesn't quite do it. When I tested, I got these errors:

( ! ) Notice: Undefined index: savepass in C:\xampp\htdocs\git\ls192\save.php on line 84
Call Stack

Time Memory Function Location

1 0.0100 1360552 {main}( ) ..\index.php:0
2 0.1621 11299944 require_once( 'C:\xampp\htdocs\git\ls192\group.php' ) ..\index.php:888
3 0.2010 12066304 savedcontrol( ) ..\group.php:249

( ! ) Notice: Undefined index: savepass2 in C:\xampp\htdocs\git\ls192\save.php on line 84
Call Stack

Time Memory Function Location

1 0.0100 1360552 {main}( ) ..\index.php:0
2 0.1621 11299944 require_once( 'C:\xampp\htdocs\git\ls192\group.php' ) ..\index.php:888
3 0.2010 12066304 savedcontrol( ) ..\group.php:249

( ! ) Notice: Undefined index: saveemail in C:\xampp\htdocs\git\ls192\save.php on line 97
Call Stack

Time Memory Function Location

1 0.0100 1360552 {main}( ) ..\index.php:0
2 0.1621 11299944 require_once( 'C:\xampp\htdocs\git\ls192\group.php' ) ..\index.php:888
3 0.2010 12066304 savedcontrol( ) ..\group.php:249

This comment has been minimized.

Copy link
@sachdeva-shubham

sachdeva-shubham Mar 24, 2012

Author Contributor

Hmm, i compared the old code and this one and i think i don't need

if (!is_null($moveResult))
{
$flashmessage = abc-xyz;
}

at all. :-)
when $_POST['saveprompt'] is set, we have savedcontrol() called already and savedcontrol() shouldn't be called when $_POST['saveall'] is set!

Initially the answers were being saved by savedsilent() and it was returning a happy message setting $flashmessage as well as $_POST['saveall'].
Now EM function takes care of it and $_POST'saveall'] is already set and hence the desired behaviour we want :-)

TMSWhite : Can you please comment this line out and check? I just want to be double/triple sure on this one before commiting. I checked at my system without any error/warning.

This comment has been minimized.

Copy link
@TMSWhite

TMSWhite Mar 24, 2012

Contributor

I can check late tonight (e.g. 6 hours from now)

This comment has been minimized.

Copy link
@TMSWhite

TMSWhite Mar 25, 2012

Contributor

I'm not able to review this for another day. As long as you have tested all of the possibilities with debug level = 3 and there are no errors, you should be fine.

This comment has been minimized.

Copy link
@TMSWhite

TMSWhite Mar 26, 2012

Contributor

magiclko - You are correct, we don't need

        if (!is_null($moveResult))
        {
            $flashmessage = savedcontrol();
        }    

When I remove it, it saves newly entered data just fine.

}
}
}

Expand Down
85 changes: 0 additions & 85 deletions save.php
Expand Up @@ -189,91 +189,6 @@ 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.
Expand Down

6 comments on commit 1296664

@TMSWhite
Copy link
Contributor

Choose a reason for hiding this comment

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

magicklo - looks good except for line 249 of group.php

@TMSWhite
Copy link
Contributor

Choose a reason for hiding this comment

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

The final fix hasn't been committed to master
(see last note about removing
if (!is_null($moveResult))
{
$flashmessage = savedcontrol();
}

@TMSWhite
Copy link
Contributor

Choose a reason for hiding this comment

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

Needs to be ported to Yii?

@c-schmitz
Copy link
Contributor

Choose a reason for hiding this comment

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

Issue does not exist in Yii.

@c-schmitz
Copy link
Contributor

Choose a reason for hiding this comment

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

Did the last missing fix on master.

@TMSWhite
Copy link
Contributor

Choose a reason for hiding this comment

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

magicklo-

Looking at this code, the function _UpdateValuesInDatabase() has a new argument, $setSubmitDate, but it isn't used anywhere in the function.

What is it supposed to do?

I vaguely recollect it is supposed to set the submit date even if the survey is not finished, but I can't find reference to it elsewhere in the code or prior commits.

Please sign in to comment.