...
 
Commits (2)
<?php
/**
* Some Utilities
*
* @author Denis Chenu <[email protected]>
* @copyright 2020 Denis Chenu <http://www.sondages.pro>
* @license AGPL v3
* @version 0.0.0
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
namespace reloadAnyResponse;
use App;
use Yii;
use CHttpException;
class Utilities
{
CONST DefaultSettings = array(
'allowAdminUser' => 1,
'allowTokenUser' => 1,
'allowTokenGroupUser' => 1,
'uniqueCodeAccess' => 1,
);
/**
* Create Survey and add current response in $_SESSION
* @param integer $surveydi
* @param integer $srid
* @param string $token
* @param string $accesscode
* @throws Errors
* @return void|true;
*/
public static function loadReponse($surveyid, $srid, $token = null, $accesscode = null)
{
if(self::getCurrentSrid($surveyid) == $srid) {
return;
}
$oResponse = \SurveyDynamic::model($surveyid)->find("id = :srid",array(':srid'=>$srid));
$language = App()->getLanguage();
$oSurvey = \Survey::model()->findByPk($surveyid);
/* @var boolean, did edition is allowed with current params and settings */
$editAllowed = false;
/* we check usage by usage : accesscode , token, admin */
if ($accesscode
&& self::getReloadAnyResponseSetting($surveyid, 'uniqueCodeAccess')
) {
$responseLink = \reloadAnyResponse\models\responseLink::model()->findByPk(array('sid'=>$surveyid,'srid'=>$srid));
if(!$responseLink) {
return self::returnOrThrowException($surveyid, 401 , self::translate('Sorry, this access code is not valid.'));
}
if($responseLink && $responseLink->accesscode != $accesscode) {
return self::returnOrThrowException($surveyid,401, self::translate('Sorry, this access code is not valid.'));
}
if(!$oResponse) {
return self::returnOrThrowException($surveyid,404, self::translate('Response not found.'));
}
$editAllowed = true;
}
if (!$editAllowed
&& $token
&& !empty($oResponse->token)
&& self::getReloadAnyResponseSetting($surveyid, 'allowTokenUser')
) {
if(!$oResponse) {
return self::returnOrThrowException($surveyid,404, self::translate('Response not found.'));
}
/* Check the list of token with reponseListAndManage */
if(self::getReloadAnyResponseSetting($surveyid, 'allowTokenGroupUser')) {
if(!self::checkIsValidToken($surveyid, $token, $oResponse->token)) {
return self::returnOrThrowException($surveyid,403, self::translate('Sorry, this token is not valid.'));
}
} elseif($token != $oResponse->token) {
return self::returnOrThrowException($surveyid,403, self::translate('Sorry, this token is not valid.'));
}
$editAllowed = true;
}
if (!$editAllowed) {
$havePermission = self::getReloadAnyResponseSetting($surveyid, 'allowAdminUser') && \Permission::model()->hasSurveyPermission($surveyid,'response','update');
if (!$havePermission) {
return self::returnOrThrowException($surveyid, 401, self::translate('Sorry, you don‘t have access to this response.'));
}
if(!$oResponse) {
return self::returnOrThrowException($surveyid, 404, self::translate('Response not found.'));
}
}
killSurveySession($surveyid);
\LimeExpressionManager::SetDirtyFlag();
$_SESSION['survey_'.$surveyid]['srid'] = $oResponse->id;
if (!empty($oResponse->lastpage)) {
$_SESSION['survey_'.$surveyid]['LEMtokenResume'] = true;
// If the response was completed start at the beginning and not at the last page - just makes more sense
if (empty($oResponse->submitdate)) {
$_SESSION['survey_'.$surveyid]['step'] = $oResponse->lastpage;
}
/*
Move it to beforeSurveyPage only if POST value
*/
}
$_SESSION['survey_'.$surveyid]['s_lang'] = $language; /* buildsurveysession use session lang … , send a notic if not set */
buildsurveysession($surveyid);
if (!empty($oResponse->submitdate)) {
$_SESSION['survey_'.$surveyid]['maxstep'] = $_SESSION['survey_'.$surveyid]['totalsteps'];
}
if (tableExists('tokens_'.$surveyid) && !empty($oResponse->token)) {
$_SESSION['survey_'.$surveyid]['token'] = $oResponse->token;
}
randomizationGroupsAndQuestions($surveyid);
initFieldArray($surveyid, $_SESSION['survey_'.$surveyid]['fieldmap']);
loadanswers();
if(self::getReloadAnyResponseSetting($surveyid, 'replaceDefaultSave') ) {
$_SESSION['survey_'.$surveyid]['scid'] = self::getCurrentSrid($surveyid);
}
self::setCurrentReloadedToken($surveyid, $token);
self::setCurrentReloadedSrid($surveyid, self::getCurrentSrid($surveyid));
models\surveySession::saveSessionTime($surveyid,$oResponse->id);
return true;
}
/**
* get current srid for a survey
* @param $surveyid integer
* @return integer|null
*/
public static function getCurrentSrid($surveyid)
{
if (empty($_SESSION['survey_'.$surveyid]['srid']) ) {
return null;
}
return $_SESSION['survey_'.$surveyid]['srid'];
}
/**
* get current srid for a survey
* @param $surveyid integer
* @return integer|null
*/
public static function getCurrentReloadedSrid($surveyid)
{
if (empty($_SESSION['survey_'.$surveyid]['reloadAnyResponseSrid']) ) {
return null;
}
return $_SESSION['survey_'.$surveyid]['reloadAnyResponseSrid'];
}
/**
* get current token for a survey
* @param $surveyid integer
* @return string|null
*/
public static function getCurrentReloadedToken($surveyid)
{
if (empty($_SESSION['survey_'.$surveyid]['reloadAnyResponseToken']) ) {
return null;
}
return $_SESSION['survey_'.$surveyid]['reloadAnyResponseToken'];
}
/**
* set current srid for a survey
* @param integer $surveyid
* @param integer $srid
* @return integer|null
*/
public static function setCurrentReloadedSrid($surveyid, $srid)
{
$_SESSION['survey_'.$surveyid]['reloadAnyResponseSrid'] = $srid;
}
/**
* gset current token for a survey
* @param $surveyid integer
* @return integer|null
*/
public static function setCurrentReloadedToken($surveyid, $token)
{
if(empty($token)) {
return;
}
if(isset($_SESSION['survey_'.$surveyid]['token']) && $_SESSION['survey_'.$surveyid]['token'] == $token) {
return;
}
$_SESSION['survey_'.$surveyid]['reloadAnyResponseToken'] = $token;
}
/**
* Translate by this plugin
* @see reloadAnyResponse->_setConfig
* @param string $string to translate
* @param string $language for translation
* @return string
*/
public static function translate($string, $language = null)
{
return Yii::t('', $string, array(), 'ReloadAnyResponseMessages', $language);
}
/**
* Get a DB setting from a plugin
* @param integer survey id
* @param string setting name
* @return mixed
*/
public static function getReloadAnyResponseSetting($surveyId, $sSetting) {
$oPlugin = \Plugin::model()->find(
"name = :name",
array(":name" => 'reloadAnyResponse')
);
if(!$oPlugin || !$oPlugin->active) {
return $default;
}
$oSetting = \PluginSetting::model()->find(
'plugin_id = :pluginid AND '.App()->getDb()->quoteColumnName('key').' = :key AND model = :model AND model_id = :surveyid',
array(
':pluginid' => $oPlugin->id,
':key' => $sSetting,
':model' => 'Survey',
':surveyid' => $surveyId,
)
);
if(!empty($oSetting)) {
$value = json_decode($oSetting->value);
if($value !== '') {
return $value;
}
}
$oSetting = \PluginSetting::model()->find(
'plugin_id = :pluginid AND '.App()->getDb()->quoteColumnName('key').' = :key AND model = :model AND model_id = :surveyid',
array(
':pluginid' => $oPlugin->id,
':key' => $sSetting,
':model' => null,
':surveyid' => null,
)
);
if(!empty($oSetting)) {
$value = json_decode($oSetting->value);
if($value !== '') {
return $value;
}
}
if (isset(self::DefaultSettings[$sSetting])) {
return self::DefaultSettings[$sSetting];
}
return null;
}
/**
* Reset a survey
* @param integer $surveydi
* @param integer $srid
* @param string $token
* @param boolean $forced
* @return void
*/
public static function resetLoadedReponse($surveyid, $srid, $token = null, $forced = false)
{
if(self::getCurrentReloadedSrid($surveyid) == $srid) {
if($forced || \Survey::model()->findByPk($surveyid)->alloweditaftercompletion != 'Y') {
$oResponse = \SurveyDynamic::model($surveyid)->updateByPk($srid, array('submitdate'=>null));
}
if($token && \Survey::model()->findByPk($surveyid)->anonymized != 'Y') {
$oResponse = \SurveyDynamic::model($surveyid)->updateByPk($srid, array('token'=>$token));
}
}
}
/**
* Check if a token is valid with another one
* @param integer $surveyd
* @param string $token to be validated
* @param string $token for control
* @return boolean
*/
public static function checkIsValidToken($surveyid, $token, $validtoken)
{
if(empty($validtoken)) {
return true;
}
if(empty($token)) {
return false;
}
if($token == $validtoken) {
return true;
}
if(Yii::getPathOfAlias('responseListAndManage')) {
if(in_array($token, \responseListAndManage\helpers\tokensList::getTokensList($surveyid,$validtoken))) {
return true;
}
}
return false;
}
/**
* Get a start url for any survey/srid
* @param integer $surveyd
* @param integer $srid
* @param integer $token, if is set use it, else use the current one of response
* @return string
*/
public static function getStartUrl($surveyid, $srid, $token = null, $extraParams, $forced = false)
{
$oSurvey = \Survey::model()->findByPk($surveyid);
/* @var boolean, did edition is allowed with current params and settings */
$editAllowed = false;
}
/**
* Check if need to throw exception,
* return if not
* @param integer $surveyid
* @params integer error code
* @param string text for error
* @throw exception
* return null;
*/
private static function returnOrThrowException($surveyid, $code, $text)
{
$ThrowException = self::getReloadAnyResponseSetting($surveyid, 'throwErrorRight');
if($ThrowException) {
throw new CHttpException($code, $text);
}
return;
}
}
......@@ -5,7 +5,7 @@
* @author Denis Chenu <[email protected]>
* @copyright 2018-2020 Denis Chenu <http://www.sondages.pro>
* @license AGPL v3
* @version 2.1.1
* @version 3.0.0-alpha-1
*
* 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
......@@ -26,6 +26,9 @@ class reloadAnyResponse extends PluginBase {
static protected $dbVersion = 2;
/* @var null|interger Keep reload srid in POST value, to compare with current session value */
private $reloadedSrid = null;
/**
* @var array[] the settings
*/
......@@ -54,13 +57,23 @@ class reloadAnyResponse extends PluginBase {
'default'=>0,
),
'allowTokenUser' => array(
'type'=>'checkbox',
'htmlOptions'=>array(
'value'=>1,
'uncheckValue'=>0,
'type'=>'select',
'options'=>array(
1 => "Yes",
0 => "No",
),
'label'=>"Allow user with a valid token.",
'default'=>1,
'default' => 1,
),
'allowTokenGroupUser' => array(
'type'=>'select',
'options'=>array(
1 => "Yes",
0 => "No",
),
'label'=>"Allow user with a token in same group.",
'help' => "Group is related to User group management from responseListAndManage plugin",
'default' => 1,
),
'uniqueCodeCreate' => array(
'type'=>'checkbox',
......@@ -137,6 +150,16 @@ class reloadAnyResponse extends PluginBase {
'help' => 'Send an http 401 error when srid is in url, but user did ,not have right. Else create a new response (according to survey settings).',
'default' => 0,
),
'replaceDefaultSave'=>array(
'type'=>'checkbox',
'htmlOptions'=>array(
'value'=>1,
'uncheckValue'=>0,
),
'label' => 'Replace the default LimeSurvey system',
'help' => 'When participant trye to save a reloaded reponse : it was directly saved without showing the save form.',
'default' => 1,
),
'noHttpUserAgent'=>array(
'type'=>'select',
'options' => array(
......@@ -172,24 +195,6 @@ class reloadAnyResponse extends PluginBase {
'help' => 'By default : show the page but don\'t disable other access. You can choose to send a http 403 error (Forbidden).',
'default' => 'noaction',
),
//~ '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.',
//~ 'htmlOptions'=>array(
//~ 'min'=>1,
//~ ),
//~ 'default' => 18,
//~ ),
//~ 'uniqueCodeCode' => array(
//~ 'type'=>'string',
//~ 'label'=>"Code in GET params to test.",
......@@ -219,6 +224,8 @@ class reloadAnyResponse extends PluginBase {
$this->subscribe('beforeSurveyPage');
/* Replace existing system if srid = new */
$this->subscribe('beforeLoadResponse');
/* Add a checker when multiple tabe is open */
$this->subscribe('beforeQuestionRender');
/* Survey settings */
$this->subscribe('beforeSurveySettings');
$this->subscribe('newSurveySettings');
......@@ -260,10 +267,11 @@ class reloadAnyResponse extends PluginBase {
/* currentDefault translation */
$allowAdminUserDefault = $this->get('allowAdminUser',null,null,$this->settings['allowAdminUser']['default']) ? gT('Yes') : gT('No');
$allowTokenDefault = $this->get('allowTokenUser',null,null,$this->settings['allowTokenUser']['default']) ? gT('Yes') : gT('No');
$allowTokenGroupUserDefault = $this->get('allowTokenGroupUser',null,null,$this->settings['allowTokenGroupUser']['default']) ? gT('Yes') : gT('No');
$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');
$throwErrorRightDefault = $this->get('throwErrorRight',null,null,$this->settings['throwErrorRight']['default']) ? gT('Yes') : gT('No');
$replaceDefaultSaveDefault = $this->get('replaceDefaultSave',null,null,$this->settings['replaceDefaultSave']['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');
$oEvent->set("surveysettings.{$this->id}", array(
......@@ -286,14 +294,27 @@ class reloadAnyResponse extends PluginBase {
'label' => $this->_translate("Allow participant with token to create or reload responses."),
'help' => $this->_translate("Related to “Enable token-based response persistence” and “Allow multiple responses or update responses” survey settings."),
'options'=>array(
1 =>gT("Yes"),
0 =>gT("No"),
1 => gT("Yes"),
0 => gT("No"),
),
'htmlOptions'=>array(
'empty' => CHtml::encode(sprintf($this->_translate("Use default (%s)"),$allowTokenDefault)),
),
'current'=>$this->get('allowTokenUser','Survey',$oEvent->get('survey'),"")
),
'allowTokenGroupUser'=>array(
'type' => 'select',
'label' => $this->_translate("Allow participant with token in same group to create or reload responses."),
'help' => $this->_translate("Related to responseListAndManage user. This need allowing token user to reload reponse."),
'options'=>array(
1 => gT("Yes"),
0 => gT("No"),
),
'htmlOptions'=>array(
'empty' => CHtml::encode(sprintf($this->_translate("Use default (%s)"),$allowTokenGroupUserDefault)),
),
'current'=>$this->get('allowTokenGroupUser','Survey',$oEvent->get('survey'),"")
),
'uniqueCodeCreate'=>array(
'type'=>'select',
'label'=>$this->_translate("Create unique code automatically."),
......@@ -341,6 +362,20 @@ class reloadAnyResponse extends PluginBase {
'help' => $this->_translate("Send an http 401 error when srid is in url, but user did ,not have right. Else create a new response (according to survey settings)"),
'current'=>$this->get('throwErrorRight','Survey',$oEvent->get('survey'),"")
),
/* Replacing save */
'replaceDefaultSave' => array(
'type'=>'select',
'options'=>array(
1 =>gT("Yes"),
0 =>gT("No"),
),
'htmlOptions'=>array(
'empty' => CHtml::encode(sprintf($this->_translate("Use default (%s)"),$replaceDefaultSaveDefault)),
),
'label' => $this->_translate("Save reloaded response transparently."),
'help' => $this->_translate("Replace the LimeSurvey save form : directly save the current reponse when user click on save all"),
'current'=>$this->get('replaceDefaultSave','Survey',$oEvent->get('survey'),"")
),
/* Reset to not submitted when open */
'reloadResetSubmitted' => array(
'type'=>'boolean',
......@@ -524,6 +559,7 @@ class reloadAnyResponse extends PluginBase {
\reloadAnyResponse\models\surveySession::saveSessionTime($surveyId,$oResponse->id);
}
}
/* @todo : control what happen with useleft > 1 and tokenanswerspersistence != "Y" */
}
......@@ -534,8 +570,9 @@ class reloadAnyResponse extends PluginBase {
/* Save current session Id to allow same user to reload survey in same browser */
/* resetAllSessionVariables regenerate session id */
/* Keep previous session id, if user reload start url it reset the sessionId, need to leav access */
$surveyid = $this->getEvent()->get('surveyId');
/* Multiple access to same survey checking */
$multiAccessTime = $this->_getCurrentSetting('multiAccessTime',$surveyid);
if($multiAccessTime !== '') {
Yii::app()->setConfig('surveysessiontime_limit',$multiAccessTime);
......@@ -548,7 +585,7 @@ class reloadAnyResponse extends PluginBase {
$this->checkAccessByUserAgent();
$disableMultiAccess = !$this->noactionByUserAgent();
}
$this->_fixLanguage($surveyid);
/* For token : @todo in beforeReloadReponse */
/* @todo : delete surveySession is save or clearall action */
if($disableMultiAccess && ($since = \reloadAnyResponse\models\surveySession::getIsUsed($surveyid))) {
......@@ -560,63 +597,53 @@ class reloadAnyResponse extends PluginBase {
'class'=>'alert alert-info',
));
}
/* Check POST and current session : throw error if needed */
if(App()->getRequest()->getPost('reloadAnyResponseSrid')) {
$currentSrid = isset($_SESSION['survey_'.$surveyid ]['srid']) ? $_SESSION['survey_'.$surveyid ]['srid'] : null;
if($currentSrid != App()->getRequest()->getPost('reloadAnyResponseSrid')) {
throw new CHttpException(400, $this->_translate("Your current session seems invalid with current data."));
}
$token = \reloadAnyResponse\Utilities::getCurrentReloadedToken($surveyid);
/* It's a POST : potential issue with edit response already submitted */
\reloadAnyResponse\Utilities::resetLoadedReponse($surveyid, $currentSrid, $token);
$this->reloadedSrid = $currentSrid;
return;
}
/* Check srid */
$srid = App()->getRequest()->getQuery('srid');
if(!$srid && $disableMultiAccess) {
/* Always save current srid if needed , only reload can disable this */
\reloadAnyResponse\models\surveySession::saveSessionTime($surveyid);
if(isset($_SESSION['survey_'.$surveyid]['srid'])) {
$this->_addUnloadScript($surveyid,$_SESSION['survey_'.$surveyid]['srid']);
if(!$srid) {
$this->reloadedSrid = \reloadAnyResponse\Utilities::getCurrentReloadedSrid($surveyid);
if($disableMultiAccess) {
/* Always save current srid if needed , only reload can disable this */
\reloadAnyResponse\models\surveySession::saveSessionTime($surveyid);
}
return;
}
$oSurvey = Survey::model()->findByPk($surveyid);
$token = App()->getRequest()->getParam('token');
if($srid == "new") {
// Done in beforeLoadResponse
return;
}
if(!$srid) {
$srid = $this->getCurrentSrid($surveyid);
}
if(!$srid) {
return;
}
//~ $accesscode = App()->getRequest()->getQuery($this->get('uniqueCodeCode'),null,null,$this->settings['uniqueCodeCode']['default']);
$accesscode = App()->getRequest()->getQuery('code');
$editAllowed = false;
if($accesscode && $this->_getIsActivated('uniqueCodeAccess',$surveyid)) {
$responseLink = \reloadAnyResponse\models\responseLink::model()->findByPk(array('sid'=>$surveyid,'srid'=>$srid));
if($responseLink && $responseLink->accesscode == $accesscode) {
$editAllowed = true;
}
if(!$responseLink) {
$this->_HttpException(404,$this->_translate("Sorry, this response didn‘t exist."),$surveyid);
}
if($responseLink && $responseLink->accesscode != $accesscode) {
$this->_HttpException(401,$this->_translate("Sorry, this access code is invalid."),$surveyid);
}
}
if(!$editAllowed && $this->_getIsActivated('allowTokenUser',$surveyid) && $this->_accessibleWithToken($oSurvey)) {
$editAllowed = true;
// Done in beforeLoadResponse, needed only with token related survey
return;
}
if(!$editAllowed && $this->_getIsActivated('allowAdminUser',$surveyid) && Permission::model()->hasSurveyPermission($surveyid,'responses','update')) {
$editAllowed = true;
if ($this->loadReponse($surveyid, $srid, App()->getRequest()->getParam('token'),App()->getRequest()->getParam('code')) ) {
$this->reloadedSrid = $srid;
}
if(!$editAllowed) {
if($this->_getIsActivated('throwErrorRight',$surveyid)) {
$this->_HttpException(401,$this->_translate("No right on this response"),$surveyid);
}
$this->log("srid used in url without right to reload");
return;
}
if($disableMultiAccess && $since = \reloadAnyResponse\models\surveySession::getIsUsed($surveyid,$srid)) {
$this->_endWithEditionMessage($since);
}
$this->_loadReponse($surveyid,$srid,App()->getRequest()->getParam('token'));
$this->_addUnloadScript($surveyid,$srid);
}
/**
* @see beforeQuestionRender event
* Adding a POST value with current reloaded Srid
* @return void
*/
public function beforeQuestionRender()
{
if($this->reloadedSrid) {
$hiddenInput = CHtml::hiddenField('reloadAnyResponseSrid',$this->reloadedSrid);
$this->getEvent()->set("answers",$this->getEvent()->get("answers").$hiddenInput);
}
$this->reloadedSrid = null;
}
/**
* Delete SurveySession for this event srid
*/
......@@ -648,7 +675,7 @@ class reloadAnyResponse extends PluginBase {
* @param $responseId
* @return @void
*/
private function _addUnloadScript($surveyId,$responseId)
private function addUnloadScript($surveyId,$responseId)
{
$ajaxUrl = Yii::app()->getController()->createUrl('plugins/direct', array('plugin' => get_class($this), 'function' => 'close','sid'=>$surveyId,'srid'=>$responseId));
$onBeforeUnload = "window.onbeforeunload = function(e) {\n";
......@@ -755,73 +782,28 @@ class reloadAnyResponse extends PluginBase {
}
$messageSource=array(
'class' => 'CGettextMessageSource',
'cacheID' => get_class($this).'Lang',
'cachingDuration'=>0,
'forceTranslation' => true,
'cachingDuration' => 3600, // 1 hour, Must reset only when needed
'useMoFile' => true,
'basePath' => __DIR__ . DIRECTORY_SEPARATOR.'locale',
'catalog'=>'messages',// default from Yii
);
Yii::app()->setComponent(get_class($this).'Messages',$messageSource);
Yii::app()->setComponent('ReloadAnyResponseMessages',$messageSource);
}
/**
* Create Survey and add current response in $_SESSION
* @param integer $surveydi
* @param integer $srid
* @throws Error 404
* @todo : use the new helper
* @return void
*/
private function _loadReponse($surveyid,$srid,$token = null)
{
if(isset($_SESSION['survey_'.$surveyid]['srid']) && $_SESSION['survey_'.$surveyid]['srid'] == $srid) {
return;
}
$oResponse = SurveyDynamic::model($surveyid)->find("id = :srid",array(':srid'=>$srid));
$language = Yii::app()->getLanguage();
if(!$oResponse) {
$this->_HttpException(404, $this->_translate('Response not found.'),$surveyid);
}
$oSurvey = Survey::model()->findByPk($surveyid);
// Validate token : @todo review for admin user
if(!Permission::model()->hasSurveyPermission($surveyid,'response','update') && tableExists('tokens_'.$surveyid) && !empty($oResponse->token)) {
if($oResponse->token != $token) {
$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;
// If the response was completed start at the beginning and not at the last page - just makes more sense
if (empty($oResponse->submitdate)) {
$_SESSION['survey_'.$surveyid]['step'] = $oResponse->lastpage;
}
if(!empty($oResponse->submitdate) && $oSurvey->alloweditaftercompletion != 'Y') {
$oResponse->submitdate = null;
$oResponse->save();
// Better to set Survey to alloweditaftercompletion == 'Y', but unable at this time on afterFindSurvey event
}
}
$_SESSION['survey_'.$surveyid]['s_lang'] = $language; /* buildsurveysession use session lang … , send a notic if not set */
buildsurveysession($surveyid);
if (!empty($oResponse->submitdate)) {
$_SESSION['survey_'.$surveyid]['maxstep'] = $_SESSION['survey_'.$surveyid]['totalsteps'];
}
if (tableExists('tokens_'.$surveyid) && !empty($oResponse->token)) {
$_SESSION['survey_'.$surveyid]['token'] = $oResponse->token;
}
if(version_compare(Yii::app()->getConfig('versionnumber'),"3",">=")) {
randomizationGroupsAndQuestions($surveyid);
initFieldArray($surveyid, $_SESSION['survey_'.$surveyid]['fieldmap']);
/**
* Create Survey and add current response in $_SESSION
* @param integer $surveyid
* @param integer $srid
* @param string $token
* @param string $accesscode
* @throws Error
* @return void|true
*/
private function loadReponse($surveyid,$srid,$token = null, $accesscode = null)
{
/* Utilities check access */
return \reloadAnyResponse\Utilities::loadReponse($surveyid,$srid,$token,$accesscode);
}
loadanswers();
$_SESSION['survey_'.$surveyid]['reloadAnyResponse'] = $oResponse->id;
\reloadAnyResponse\models\surveySession::saveSessionTime($surveyid,$oResponse->id);
}
/**
* Create a new response for token
......@@ -886,6 +868,7 @@ class reloadAnyResponse extends PluginBase {
/**
* Save current srid if exist in specific session
* @todo : unused, remove it
* @return void
*/
public function saveCurrentSrid($surveyId)
......@@ -904,6 +887,7 @@ class reloadAnyResponse extends PluginBase {
/**
* Get current srid if exist in specific session
* @todo : unused, remove it
* @return integer|null
*/
public function getCurrentSrid($surveyId)
......