Commit 070eb9d7 authored by Chenu Denis's avatar Chenu Denis
Browse files

[fix] 5.0 fix, review clear all way for restart url

parent eb4ad40c
......@@ -99,7 +99,10 @@ class StartUrl
if (!$this->isAvailable()) {
return false;
}
if (empty($srid)) {
\Yii::log("Call of getUrl without srid.", \CLogger::LEVEL_ERROR, 'plugin.reloadAnyResponse.StartUrl.getUrl');
return;
}
$params = array(
'sid' => $this->surveyId,
'srid' => $srid,
......
......@@ -2,17 +2,18 @@ $(document).ajaxComplete(function() {
if($('#responses-grid table').data('reloadAnyResponse') == 'done') {
return;
}
$('#responses-grid table tbody').find('tr').each(function( index, element) {
var pencil = $(element).find('.button-column').find('a .fa-pencil');
var pencil = $(element).find('.button-column,.icon-btn-row').find('a .fa-pencil');
if($(pencil).length) {
var srid = $(element).find('input').eq(0).val();
var newLink = $('<a/>', {
'class': 'btn btn-default btn-xs',
'class': LS.reloadAnyResponse.lsVersion > 3 ? 'btn btn-default btn-sm' : 'btn btn-default btn-xs',
'href': LS.reloadAnyResponse.baseUrl + srid,
'target': '_blank',
'title': LS.reloadAnyResponse.lang.launch,
'data-toggle': 'tooltip'
}).html('<i class="fa fa-pencil-square-o text-success" aria-hidden="true"></i>');
}).html('<i class="fa fa-cog text-success" aria-hidden="true"></i>');
$(pencil).closest("a").after(newLink);
}
});
......
......@@ -4,11 +4,11 @@
<name>reloadAnyResponse</name>
<type>plugin</type>
<creationDate>2018-04-18</creationDate>
<lastUpdate>2021-06-29</lastUpdate>
<lastUpdate>2021-11-10</lastUpdate>
<author>Denis Chenu</author>
<authorUrl>https://extensions.sondages.pro/reloadanyresponse</authorUrl>
<supportUrl>https://support.sondages.pro/</supportUrl>
<version>4.4.4</version>
<version>5.0.0-beta1</version>
<license>GNU Affero General Public License v3.0</license>
<description><![CDATA[Allow to reload any response for admin user and respondant.]]></description>
</metadata>
......@@ -18,5 +18,4 @@
<version>4</version>
<version>5</version>
</compatibility>
</config>
......@@ -2,7 +2,7 @@
/**
* This file is part of reloadAnyResponse plugin
* @version 1.6.0
* @version 1.7.0
*/
namespace reloadAnyResponse\models;
......@@ -71,21 +71,18 @@ class surveySession extends CActiveRecord
public static function saveSessionTime($sid, $srid = null, $token = null)
{
if (!$srid) {
$srid = isset($_SESSION['survey_' . $sid]['srid']) ? $_SESSION['survey_' . $sid]['srid'] : null;
$srid = Utilities::getCurrentSrid($sid);
}
if (!$srid && !$token) {
return;
}
if (self::surveyHasTokenTable($sid)) {
if (!$token) {
$token = isset($_SESSION['survey_' . $sid]['token']) ? $_SESSION['survey_' . $sid]['token'] : null;
$token = Utilities::getCurrentToken($sid);
}
if (!$token) {
$token = Yii::app()->getRequest()->getParam('token');
}
if (!$token) {
if (!$token && Survey::model()->findByPk($sid)->anonymized != "N") {
$oResponse = Response::model($sid)->findByPk($srid);
if ($oResponse && Survey::model()->findByPk($sid)->anonymized != "N" && !empty($oResponse->token)) {
if ($oResponse && !empty($oResponse->token)) {
$token = $oResponse->token;
}
}
......@@ -116,7 +113,7 @@ class surveySession extends CActiveRecord
public static function getIsUsed($sid, $srid = null, $save = true)
{
if (!$srid) {
$srid = isset($_SESSION['survey_' . $sid]['srid']) ? $_SESSION['survey_' . $sid]['srid'] : null;
$srid = Utilities::getCurrentSrid($sid);
}
if (!$srid) {
return;
......
......@@ -6,7 +6,7 @@
* @author Denis Chenu <denis@sondages.pro>
* @copyright 2018-2021 Denis Chenu <http://www.sondages.pro>
* @license AGPL v3
* @version 4.4.4
* @version 5.0.0-beta1
*
* 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
......@@ -29,6 +29,8 @@ class reloadAnyResponse extends PluginBase
/* @var null|interger Keep reload srid during all events */
private $reloadedSrid = null;
/* @var null|interger Keep current srid during all events */
private $currentSrid = null;
/* @var null|string Keep reload token during all events */
private $reloadedToken = null;
......@@ -283,7 +285,7 @@ class reloadAnyResponse extends PluginBase
/* Save current session */
$this->subscribe('beforeSurveyPage');
/* Some needed action when srid is set */
$this->subscribe('getPluginTwigPath');
$this->subscribe('beforeTwigRenderTemplate');
/* Replace existing system if srid = new */
$this->subscribe('beforeLoadResponse');
/* Add a checker when multiple tab is open */
......@@ -683,15 +685,17 @@ class reloadAnyResponse extends PluginBase
if (!Permission::model()->hasSurveyPermission($surveyid, 'response', 'update')) {
return;
}
if (!\reloadAnyResponse\Utilities::SurveyIsValid($surveyid)) {
return;
}
if($this->get('addEditResponseOnBrowse',null, null, 1) && !$this->get('replaceEditResponse',null,null,0)) {
$reloadAnyResponseOptions = array(
$reloadAnyResponseOptions = array(
'baseUrl' => Yii::app()->createUrl("survey/index", array('sid' => $surveyid,'newtest'=>'Y','srid'=>"")),
'lang' => array(
'launch' => gT("Execute Survey"),
),
'lsVersion' => floatval(App()->getConfig('versionnumber'))
);
App()->clientScript->registerScript(
'reloadAnyResponseAdminScript',
......@@ -1027,7 +1031,6 @@ class reloadAnyResponse extends PluginBase
$this->endWithEditionMessage($since);
}
$token = \reloadAnyResponse\Utilities::getCurrentReloadedToken($surveyid);
tracevar($this->getCurrentSetting('reloadResetSubmitted', $surveyid));
\reloadAnyResponse\Utilities::resetLoadedReponse($surveyid, $currentSrid, $token, $this->getCurrentSetting('reloadResetSubmitted', $surveyid));
$this->surveyId = $surveyid;
$this->reloadedSrid = $currentSrid;
......@@ -1070,15 +1073,14 @@ class reloadAnyResponse extends PluginBase
}
/**
* @see getPluginTwigPath event
* @see beforeTwigRenderTemplate event
* Do some action when srid is potentially set
*/
public function getPluginTwigPath()
public function beforeTwigRenderTemplate()
{
if (!$this->getEvent()) {
throw new CHttpException(403);
}
$this->unsubscribe('getPluginTwigPath');
if (!$this->surveyId) {
return;
}
......@@ -1165,7 +1167,7 @@ class reloadAnyResponse extends PluginBase
$surveyId = Yii::app()->getRequest()->getParam('sid');
$responseId = Yii::app()->getRequest()->getParam('srid');
if (\reloadAnyResponse\Utilities::getCurrentReloadedSrid($surveyId) != $responseId && \reloadAnyResponse\Utilities::getCurrentSrid($surveyId) != $responseId) {
\Yii::log(sprintf("Try to reset session for %s in %s", $responseId, $surveyId), \CLogger::LEVEL_INFO, 'plugin.reloadAnyResponse.newDirectRequest');
$this->log(sprintf("Try to reset session for %s in %s", $responseId, $surveyId), \CLogger::LEVEL_INFO);
return;
}
if ($surveyId && $responseId) {
......@@ -1194,12 +1196,16 @@ class reloadAnyResponse extends PluginBase
}
if (empty($reloadedSrid)) {
$reloadedSrid = \reloadAnyResponse\Utilities::getCurrentReloadedSrid($surveyId);
if (empty($reloadedSrid)) {
if (!$this->getCurrentSetting('clearAllActionForced', $surveyId)) {
/* seems not reloaded : quit */
return;
}
}
}
if (!$reloadedSrid && $this->getCurrentSetting('clearAllActionForced', $surveyId)) {
/* seems not reloaded : quit */
return;
}
$this->reloadedSrid = $reloadedSrid;
$this->currentSrid = $srid;
$this->reloadedToken = \reloadAnyResponse\Utilities::getCurrentReloadedToken($surveyId);
;
/* Disable LS core system : only in case of no delete */
......@@ -1207,9 +1213,8 @@ class reloadAnyResponse extends PluginBase
$_POST['confirm-clearall'] = null;
}
$this->unsubscribe('getPluginTwigPath'); /* Other not needed */
$this->surveyId = $surveyId;
$this->subscribe('getPluginTwigPath', 'clearAllAction');
$this->subscribe('beforeTwigRenderTemplate', 'clearAllAction');
}
......@@ -1222,11 +1227,11 @@ class reloadAnyResponse extends PluginBase
if (!$this->getEvent()) {
throw new CHttpException(403);
}
$this->unsubscribe('getPluginTwigPath');
$this->unsubscribe('beforeTwigRenderTemplate');
$surveyId = $this->surveyId;
$action = $this->getCurrentSetting('clearAllAction', $surveyId);
/* Start by reset the session */
$currentSrid = $this->reloadedSrid;
$currentSrid = $this->currentSrid;
$currentToken = $this->reloadedToken;
/* what restart url to be used ? */
/* mimic core, but replace according information */
......@@ -1687,7 +1692,6 @@ class reloadAnyResponse extends PluginBase
if (!$logDetail && $this->getEvent()) {
$logDetail = $this->getEvent()->getEventName();
} // What to put if no event ?
parent::log($message, $level);
Yii::log($message, $level, 'application.plugins.reloadAnyResponse.' . $logDetail);
\Yii::log($message, $level, 'plugin.reloadAnyResponse.' . $logDetail);
}
}
Markdown is supported
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