Commit 83dc2995 authored by Chenu Denis's avatar Chenu Denis

[fix] Unable to disable globally

[wip] Alert and close survey after a time
[fix] Remove untested and unused helper
parent e5e18371
<?php
/**
* This file is part of reloadAnyResponse plugin
* Helpers for other plugin : reload or create responses
* @version 0.1.0
*/
namespace reloadAnyResponse\helpers;
use Yii;
use LimeExpressionManager;
use Survey;
use SurveyLanguageSetting;
use SurveyDynamic;
class reloadResponse
{
/** @var null|integer $surveyId **/
public $surveyId = null;
/** @var null|integer $srid **/
public $srid = null;
/** @var null|string $language **/
public $language = null;
/** @var boolean **/
private $surveyStarted = false;
/**
* @param integer $surveyId
* @param integer $srid
* @param string|null $language
*/
public function __construct($surveyId , $srid, $language = null)
{
$this->surveyId = $surveyId;
$this->srid = $srid;
$oSurvey = Survey::model()->findByPk($surveyId);
if(!$language) {
$language = Yii::app()->getLanguage();
}
if(!$language || !in_array($language,$oSurvey->getAllLanguages())) {
$language = $oSurvey->language;
}
$this->language = $language;
}
/**
* Start and load a Survey
* No control is done for rights or token in this function
* @param null|true|integer $step , null : 1st page, true : get current step or response , integer : to this step
* @param boolean|null $resetSubmit, if null : reset if needed (submitted and alloweditaftercompletion disable)
* @return void
*/
public function startSurvey($step = true, $resetSubmit = null)
{
$surveyId = $this->surveyId;
$reset = (LimeExpressionManager::getLEMsurveyId() != $surveyId); // Unsure needed
LimeExpressionManager::SetSurveyId($surveyId);
if(empty($_SESSION['survey_'.$surveyId]['fieldmap'])) {
/* Warning can be deprecated , updated and removed*/
buildsurveysession($surveyId);
if(version_compare(Yii::app()->getConfig('versionnumber'),"3",">=")) {
randomizationGroupsAndQuestions($surveyId);
initFieldArray($surveyId, $_SESSION['survey_'.$surveyId]['fieldmap']);
}
}
$oResponse = SurveyDynamic::model($surveyId)->findByPk($this->srid);
if(empty($oResponse)) {
/* Not available currently, no need */
throw new \Exception('Reponse not found.');
}
$token = '';
if(!empty($oResponse->token)) {
$token = $_SESSION['survey_'.$surveyId]['token'] = $oResponse->token;
}
$_SESSION['survey_'.$surveyId]['srid'] = $oResponse->id;
/* Warning can be deprecated , updated and removed*/
loadanswers();
unset($_SESSION['survey_'.$surveyId]['LEMtokenResume']);
$oSurvey = Survey::model()->findByPk($surveyId);
switch($oSurvey->format) {
case "A":
$surveyMode = "survey";
break;
case "Q":
$surveyMode = "question";
break;
case "G":
default:
$surveyMode = "group";
break;
}
$oLanguageSettings = SurveyLanguageSetting::model()->findByPk(array('surveyls_survey_id'=>$surveyId,'surveyls_language'=>App()->getLanguage()));
$radix = getRadixPointData($oLanguageSettings->surveyls_numberformat);
$radix = $radix['separator'];
$aSurveyOtions = array(
'active' => $oSurvey->active == 'Y',
'allowsave' => $oSurvey->allowsave == 'Y',
'anonymized' => $oSurvey->anonymized != 'N',
'assessments' => $oSurvey->assessments == 'Y',
'datestamp' => $oSurvey->datestamp == 'Y',
'deletenonvalues' => Yii::app()->getConfig('deletenonvalues'),
'hyperlinkSyntaxHighlighting' => false,
'ipaddr' => $oSurvey->ipaddr == 'Y',
'radix' => $radix,
'refurl' => ($oSurvey->refurl == "Y" && isset($_SESSION["survey_$surveyId"]['refurl']) ) ? $_SESSION["survey_$surveyId"]['refurl'] : null,
'savetimings' => $oSurvey->savetimings == "Y",
'surveyls_dateformat' => $oLanguageSettings->surveyls_dateformat,
'startlanguage' => Yii::app()->getLanguage(),
'target' => Yii::app()->getConfig('uploaddir').DIRECTORY_SEPARATOR.'surveys'.DIRECTORY_SEPARATOR.$surveyId.DIRECTORY_SEPARATOR.'files'.DIRECTORY_SEPARATOR,
'tempdir' => Yii::app()->getConfig('tempdir').DIRECTORY_SEPARATOR,
'timeadjust' => Yii::app()->getConfig("timeadjust"),
'token' => $token,
);
LimeExpressionManager::StartSurvey($surveyId,$surveyMode,$aSurveyOtions,false);
$this->surveyStarted = true;
if(!empty($oResponse->submitdate)) {
if($resetSubmit || $oSurvey->alloweditaftercompletion != 'Y') {
$oResponse->submitdate = null;
$oResponse->save();
}
}
if(is_null($step)) {
if ($oSurvey->format == 'A') { /* All in one */
LimeExpressionManager::JumpTo(1, false, false, true);
} elseif ($oSurvey->showwelcome != 'Y') { // !$oSurvey->getIsShowWelcome if LS >= 3
$this->aMoveResult = LimeExpressionManager::NavigateForwards();
}
return;
}
if($step === true && empty($oResponse->submitdate)) {
$step = $oResponse->lastpage; // +1 ?
}
LimeExpressionManager::JumpTo($step, false, false, true);
}
}
......@@ -5,7 +5,7 @@
* @author Denis Chenu <denis@sondages.pro>
* @copyright 2018-2019 Denis Chenu <http://www.sondages.pro>
* @license AGPL v3
* @version 1.3.2
* @version 1.3.3.beta
*
* 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
......@@ -125,25 +125,36 @@ class reloadAnyResponse extends PluginBase {
'min'=>1,
'placeholder'=>'Disable',
),
'default' => 30,
'default' => "",
),
//~ 'multiAccessTimeOptOut'=>array(
//~ 'type'=>'int',
//~ 'label' => 'Auto save and close current responses (with a javascript solution) in minutes.',
//~ 'help' => 'If user didn‘t do any action on his browser during access time, save and close the windows. Set to an empty disable this feature.',
//~ 'htmlOptions'=>array(
//~ 'min'=>1,
//~ ),
//~ 'default' => 20,
//~ ),
//~ 'multiAccessTimeAlert'=>array(
//~ 'type'=>'int',
//~ 'label' => 'Time for alert shown for optout of survey',
//~ 'help' => 'Set to empty to disable. This alert is shown after X minutes, where X is the number here.',
'multiAccessTimeOptOut'=>array(
'type'=>'int',
'label' => 'Auto save and close current responses (with a javascript solution) in minutes.',
'help' => 'If user didn‘t do any action on his browser during access time, save and show information. Set to an empty disable this feature.',
'htmlOptions'=>array(
'min'=>1,
'placeholder'=>'Disable',
),
'default' => "",
),
'multiAccessTimeAlert'=>array(
'type'=>'int',
'label' => 'Time for alert shown for optout of survey (before survey is saved)',
'help' => 'Set to empty to disable. This alert is shown after X minutes, where X is the number here.',
'htmlOptions'=>array(
'min'=>1,
'placeholder'=>'Disable',
),
'default' => "",
),
//~ 'multiAccessSaveNotcomplete'=>array(
//~ 'type'=>'select',
//~ 'label' => 'Reset completed survey as not completed when save',
//~ 'htmlOptions'=>array(
//~ 'min'=>1,
//~ 1=>"Yes",
//~ 0=>"No",
//~ ),
//~ 'default' => 18,
//~ 'default' => 1,
//~ ),
//~ 'uniqueCodeCode' => array(
//~ 'type'=>'string',
......@@ -205,6 +216,7 @@ class reloadAnyResponse extends PluginBase {
public function getPluginSettings($getValues=true)
{
/* @todo translation of label and help */
/* @todo Set disable multi access related to session gc */
return parent::getPluginSettings($getValues);
}
......@@ -218,6 +230,8 @@ class reloadAnyResponse extends PluginBase {
$uniqueCodeCreateDefault = $this->get('uniqueCodeCreate',null,null,$this->settings['uniqueCodeCreate']['default']) ? gT('Yes') : gT('No');
$uniqueCodeAccessDefault = $this->get('uniqueCodeAccess',null,null,$this->settings['uniqueCodeAccess']['default']) ? gT('Yes') : gT('No');
$multiAccessTimeDefault = $this->get('multiAccessTime',null,null,$this->settings['multiAccessTime']['default']) ? $this->get('multiAccessTime',null,null,$this->settings['multiAccessTime']['default']) : gT('Disable');
$multiAccessTimeOptOutDefault = $this->get('multiAccessTimeOptOut',null,null,$this->settings['multiAccessTimeOptOut']['default']) ? $this->get('multiAccessTimeOptOut',null,null,$this->settings['multiAccessTimeOptOut']['default']) : gT('Disable');
$multiAccessTimeAlertDefault = $this->get('multiAccessTimeAlert',null,null,$this->settings['multiAccessTimeAlert']['default']) ? $this->get('multiAccessTimeAlert',null,null,$this->settings['multiAccessTime']['default']) : gT('Disable');
$oEvent->set("surveysettings.{$this->id}", array(
'name' => get_class($this),
......@@ -280,6 +294,26 @@ class reloadAnyResponse extends PluginBase {
),
'current'=>$this->get('multiAccessTime','Survey',$oEvent->get('survey'),"")
),
'multiAccessTimeOptOut'=>array(
'type'=>'int',
'label'=> $this->_translate("Auto save and close current responses (with a javascript solution) in minutes."),
'help' => $this->_translate("Use 0 to disable. This show a static page to user after save."),
'htmlOptions'=>array(
'min'=>0,
'placeholder' => CHtml::encode(sprintf($this->_translate("Use default (%s)"),$multiAccessTimeOptOutDefault)),
),
'current'=>$this->get('multiAccessTimeOptOut','Survey',$oEvent->get('survey'),"")
),
'multiAccessTimeAlert'=>array(
'type'=>'int',
'label'=>$this->_translate("Time for alert shown for optout of survey (before survey is saved)"),
'help' => $this->_translate("Use 0 to disable."),
'htmlOptions'=>array(
'min'=>0,
'placeholder' => CHtml::encode(sprintf($this->_translate("Use default (%s)"),$multiAccessTimeAlertDefault)),
),
'current'=>$this->get('multiAccessTimeAlert','Survey',$oEvent->get('survey'),"")
),
),
));
}
......@@ -470,7 +504,7 @@ class reloadAnyResponse extends PluginBase {
Yii::app()->setConfig('surveysessiontime_limit',$multiAccessTime);
}
$disableMultiAccess = true;
if($multiAccessTime === '0') {
if($multiAccessTime === '0' /* disable by survey */|| $multiAccessTime === ''/* disable globally */) {
$disableMultiAccess = false;
}
$this->_fixLanguage($surveyid);
......@@ -695,7 +729,6 @@ class reloadAnyResponse extends PluginBase {
*/
private function _loadReponse($surveyid,$srid,$token = null)
{
if(isset($_SESSION['survey_'.$surveyid]['srid']) && $_SESSION['survey_'.$surveyid]['srid'] == $srid) {
return;
}
......@@ -711,8 +744,7 @@ class reloadAnyResponse extends PluginBase {
$this->_HttpException(401, $this->_translate('Access to this response need a valid token.'),$surveyid);
}
}
killSurveySession($surveyid); // Is this needed ?
LimeExpressionManager::SetDirtyFlag();
$_SESSION['survey_'.$surveyid]['srid'] = $oResponse->id;
if (!empty($oResponse->lastpage)) {
$_SESSION['survey_'.$surveyid]['LEMtokenResume'] = true;
......
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