Skip to content

Commit

Permalink
Updated feature Enable token-based response persistence: silent save …
Browse files Browse the repository at this point in the history
…when "Resume later" is clicked

Dev If 'Enable token-based response persistence?' is 'Yes' there is no interaction required when clicking "Resume later". Responses are saved, an email is sent and respondent is returned to survey.
Dev saved response email has same URL as invitation/reminder email.


git-svn-id: file:///Users/Shitiz/Downloads/lssvn/source/limesurvey_dev@8913 b72ed6b6-b9f8-46b5-92b4-906544132732
  • Loading branch information
Evan Wills committed Jul 7, 2010
1 parent 4baa5a5 commit 1ccc68f
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 7 deletions.
23 changes: 18 additions & 5 deletions common.php
Expand Up @@ -2996,17 +2996,30 @@ function templatereplace($line, $replacements=array())

if ($thissurvey['format']=='A')
{
$saveall = "<input type='submit' name='loadall' value='".$clang->gT("Load Unfinished Survey")."' class='saveall' ". (($thissurvey['active'] != "Y")? "disabled='disabled'":"") ."/>"
."<input type='button' name='saveallbtn' value='".$clang->gT("Resume Later")."' class='saveall' onclick=\"javascript:document.limesurvey.move.value = this.value;addHiddenField(document.getElementById('limesurvey'),'saveall',this.value);document.getElementById('limesurvey').submit();\" ". (($thissurvey['active'] != "Y")? "disabled='disabled'":"") ."/>"; // Show Save So Far button

if($thissurvey['tokenanswerspersistence'] != 'Y')
{
$saveall = "<input type='submit' name='loadall' value='".$clang->gT("Load Unfinished Survey")."' class='saveall' ". (($thissurvey['active'] != "Y")? "disabled='disabled'":"") ."/>"
."<input type='button' name='saveallbtn' value='".$clang->gT("Resume Later")."' class='saveall' onclick=\"javascript:document.limesurvey.move.value = this.value;addHiddenField(document.getElementById('limesurvey'),'saveall',this.value);document.getElementById('limesurvey').submit();\" ". (($thissurvey['active'] != "Y")? "disabled='disabled'":"") ."/>"; // Show Save So Far button
}
else
{
$saveall= "<input type='button' name='saveallbtn' value='".$clang->gT("Resume Later")."' class='saveall' onclick=\"javascript:document.limesurvey.move.value = this.value;addHiddenField(document.getElementById('limesurvey'),'saveall',this.value);document.getElementById('limesurvey').submit();\" ". (($thissurvey['active'] != "Y")? "disabled='disabled'":"") ."/>"; // Show Save So Far button
};
}
elseif (!isset($_SESSION['step']) || !$_SESSION['step']) //First page, show LOAD
{
$saveall = "<input type='submit' name='loadall' value='".$clang->gT("Load Unfinished Survey")."' class='saveall' ". (($thissurvey['active'] != "Y")? "disabled='disabled'":"") ."/>";
if($thissurvey['tokenanswerspersistence'] != 'Y')
{
$saveall = "<input type='submit' name='loadall' value='".$clang->gT("Load Unfinished Survey")."' class='saveall' ". (($thissurvey['active'] != "Y")? "disabled='disabled'":"") ."/>";
}
else
{
$saveall = '';
};
}
elseif (isset($_SESSION['scid']) && (isset($move) && $move == "movelast")) //Already saved and on Submit Page, dont show Save So Far button
{
$saveall="";
$saveall='';
}
else
{
Expand Down
53 changes: 51 additions & 2 deletions save.php
Expand Up @@ -168,7 +168,6 @@

}
}

// CREATE SAVED CONTROL RECORD USING SAVE FORM INFORMATION
if (isset($_POST['saveprompt'])) //Value submitted when clicking on 'Save Now' button on SAVE FORM
{
Expand All @@ -191,7 +190,14 @@
// Show 'SAVE FORM' only when click the 'Save so far' button the first time
if ($thissurvey['allowsave'] == "Y" && isset($_POST['saveall']) && !isset($_SESSION['scid']))
{
showsaveform();
if($thissurvey['tokenanswerspersistence'] != 'Y')
{
showsaveform();
}
else
{
$flashmessage = savedsilent();
};
}
elseif ($thissurvey['allowsave'] == "Y" && isset($_POST['saveall']) && isset($_SESSION['scid']) ) //update the saved step only
{
Expand Down Expand Up @@ -372,6 +378,49 @@ 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($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.');
};


//FUNCTIONS USED WHEN SUBMITTING RESULTS:
function createinsertquery()
{
Expand Down

0 comments on commit 1ccc68f

Please sign in to comment.