diff --git a/common.php b/common.php index f0832b86aed..23d60ccceea 100644 --- a/common.php +++ b/common.php @@ -2996,17 +2996,30 @@ function templatereplace($line, $replacements=array()) if ($thissurvey['format']=='A') { - $saveall = "" - .""; // Show Save So Far button - + if($thissurvey['tokenanswerspersistence'] != 'Y') + { + $saveall = "" + .""; // Show Save So Far button + } + else + { + $saveall= ""; // Show Save So Far button + }; } elseif (!isset($_SESSION['step']) || !$_SESSION['step']) //First page, show LOAD { - $saveall = ""; + if($thissurvey['tokenanswerspersistence'] != 'Y') + { + $saveall = ""; + } + 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 { diff --git a/save.php b/save.php index b87aed44b17..ebddf2a4fda 100644 --- a/save.php +++ b/save.php @@ -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 { @@ -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 { @@ -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() {