Commit 0fe7f6df authored by Chenu Denis's avatar Chenu Denis
Browse files

[fix] sessionSurvey deleted when just reload current page

- sendbeacon happen after loading page.
parent fdd2220a
......@@ -8,7 +8,7 @@
<author>Denis Chenu</author>
<authorUrl>https://extensions.sondages.pro/reloadanyresponse</authorUrl>
<supportUrl>https://support.sondages.pro/</supportUrl>
<version>5.8.2</version>
<version>5.8.4</version>
<license>GNU Affero General Public License v3.0</license>
<description><![CDATA[Allow to reload any response for admin user and respondant.]]></description>
</metadata>
......
......@@ -6,7 +6,7 @@
* @author Denis Chenu <denis@sondages.pro>
* @copyright 2018-2023 Denis Chenu <http://www.sondages.pro>
* @license AGPL v3
* @version 5.8.3
* @version 5.8.4
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......@@ -883,7 +883,6 @@ class reloadAnyResponse extends PluginBase
if (empty($oSurvey)) {
return;
}
$this->surveyId = $surveyid;
/* Multiple access to same survey checking */
$multiAccessTime = $this->getCurrentSetting('multiAccessTime', $surveyid);
if ($multiAccessTime !== '') {
......@@ -1001,14 +1000,12 @@ class reloadAnyResponse extends PluginBase
array('plugin' => get_class($this), 'function' => 'close','sid' => $this->surveyId,'srid' => $srid)
);
$onBeforeUnload = "$(window).on('unload', function() { \n";
$onBeforeUnload .= " closeReloadAnyResponse();\n";
$onBeforeUnload .= " jQuery.ajax({ async: false, url:'{$ajaxUrl}' });\n";
$onBeforeUnload .= "})\n";
$onBeforeUnload .= "function closeReloadAnyResponse() { \n";
$onBeforeUnload .= " let beaconData = new FormData();\n";
$onBeforeUnload .= " beaconData.append('" . Yii::app()->request->csrfTokenName . "', '" . Yii::app()->request->csrfToken . "');;\n";
$onBeforeUnload .= " navigator.sendBeacon('{$ajaxUrl}', beaconData);\n";
$onBeforeUnload .= " jQuery.ajax({ async: false, url:'{$ajaxUrl}' });\n";
$onBeforeUnload .= "}\n";
Yii::app()->getClientScript()->registerScript("reloadAnyResponseBeforeUnload", $onBeforeUnload, CClientScript::POS_HEAD);
Yii::app()->getClientScript()->registerScript("reloadAnyResponseBeforeUnload", $onBeforeUnload, CClientScript::POS_READY);
}
}
......@@ -1764,10 +1761,8 @@ class reloadAnyResponse extends PluginBase
*/
private function endWithEditionMessage($since)
{
$messageString = sprintf($this->translate("She last action was made less than %s minutes ago. Please try again in some minutes."), ceil($since));
$titleString = $this->translate("Sorry, someone update this response to the questionnaire a short time ago.");
$this->ThrowHttpException("409", $messageString, $titleString);
$messageString = sprintf($this->translate("Sorry, someone update this response to the questionnaire a short time ago. The last action was made less than %s minutes ago."), ceil($since));
$this->ThrowHttpException("409", $messageString);
}
/**
......@@ -1855,12 +1850,11 @@ class reloadAnyResponse extends PluginBase
/**
* Throw specific error
* @param string|integer errorCode (404/401/403 totally supported)
* @param string errorMessage
* @param string titleString
* @param @errorCode (404/401/403 totally supported)
* @param @errorMessage
* @throw CHttpException
*/
private function ThrowHttpException($errorCode, $errorMessage, $titleString = "")
private function ThrowHttpException($errorCode, $errorMessage)
{
$errorCodeHeader = array(
'401' => "401 Unauthorized",
......@@ -1874,18 +1868,12 @@ class reloadAnyResponse extends PluginBase
}
$limesurveyVersion = Yii::app()->getConfig("versionnumber");
if (version_compare($limesurveyVersion, "3.14.0", '>=')) {
$aSurveyInfo = array();
if ($this->surveyId) {
Template::model()->getInstance('', $this->surveyId);
$aSurveyInfo = array();
$oSurvey = Survey::model()->findByPk($this->surveyId);
if ($oSurvey) {
$aSurveyInfo = getSurveyInfo($this->surveyId, App()->getLanguage());
}
}
Template::model()->getInstance('', $this->surveyId);
$oSurvey = Survey::model()->findByPk($this->surveyId);
$aSurveyInfo = $oSurvey->attributes;
$aSurveyInfo['aError'] = array(
'error' => $errorCodeHeader[$errorCode],
'title' => $titleString,
'title' => $errorCodeHeader[$errorCode],
'message' => $errorMessage,
);
header($_SERVER["SERVER_PROTOCOL"] . " " . $errorCodeHeader[$errorCode], true, $errorCode);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment