Skip to content

Commit

Permalink
Fixed issue #11490: Wrong language when session time out
Browse files Browse the repository at this point in the history
  • Loading branch information
frederikprijck committed Jul 26, 2016
1 parent 4d75617 commit 0f17fbe
Showing 1 changed file with 33 additions and 39 deletions.
72 changes: 33 additions & 39 deletions application/controllers/survey/index.php
Expand Up @@ -88,8 +88,18 @@ function action()
// collect all data in this method to pass on later
$redata = compact(array_keys(get_defined_vars()));

$this->_loadLimesurveyLang($surveyid);

// Set the language of the survey, either from POST, GET parameter of session var
$sOldLang = isset($_SESSION['survey_'.$surveyid]['s_lang'])?$_SESSION['survey_'.$surveyid]['s_lang']:"";// Keep the old value, because SetSurveyLanguage update $_SESSION
$sDisplayLanguage = $this->_getLanguage($surveyid, $param);
if ($surveyid && $surveyExists)
{
SetSurveyLanguage( $surveyid, $sDisplayLanguage);
}
else
{
SetSurveyLanguage( 0, $sDisplayLanguage);
}

if ( $this->_isClientTokenDifferentFromSessionToken($clienttoken,$surveyid) )
{
$sReloadUrl=$this->getController()->createUrl("/survey/index/sid/{$surveyid}",array('token'=>$clienttoken,'lang'=>App()->language,'newtest'=>'Y'));
Expand Down Expand Up @@ -171,25 +181,7 @@ function action()
$this->_niceExit($redata, __LINE__, null, $asMessage);
};

// Set the language of the survey, either from POST, GET parameter of session var
// Keep the old value, because SetSurveyLanguage update $_SESSION
$sOldLang=isset($_SESSION['survey_'.$surveyid]['s_lang'])?$_SESSION['survey_'.$surveyid]['s_lang']:"";// Keep the old value, because SetSurveyLanguage update $_SESSION
if (!empty($param['lang']))
{
$sDisplayLanguage = $param['lang'];// $param take lang from returnGlobal and returnGlobal sanitize langagecode
}
elseif (isset($_SESSION['survey_'.$surveyid]['s_lang']))
{
$sDisplayLanguage = $_SESSION['survey_'.$surveyid]['s_lang'];
}
elseif(Survey::model()->findByPk($surveyid))
{
$sDisplayLanguage=Survey::model()->findByPk($surveyid)->language;
}
else
{
$sDisplayLanguage=Yii::app()->getConfig('defaultlang');
}

//CHECK FOR REQUIRED INFORMATION (sid)
if ($surveyid && $surveyExists)
{
Expand Down Expand Up @@ -613,23 +605,6 @@ function _loadRequiredHelpersAndLibraries()
Yii::app()->loadHelper("surveytranslator");
}

function _loadLimesurveyLang($mvSurveyIdOrBaseLang)
{
if ( is_numeric($mvSurveyIdOrBaseLang) && Survey::model()->findByPk($mvSurveyIdOrBaseLang))
{
$baselang = Survey::model()->findByPk($mvSurveyIdOrBaseLang)->language;
}
elseif (!empty($mvSurveyIdOrBaseLang))
{
$baselang = $mvSurveyIdOrBaseLang;
}
else
{
$baselang = Yii::app()->getConfig('defaultlang');
}
App()->setLanguage($baselang);
}

function _isClientTokenDifferentFromSessionToken($clientToken, $surveyid)
{
return $clientToken != '' && isset($_SESSION['survey_'.$surveyid]['token']) && $clientToken != $_SESSION['survey_'.$surveyid]['token'];
Expand All @@ -648,7 +623,7 @@ function _surveyCantBeViewedWithCurrentPreviewAccess($surveyid, $bIsSurveyActive

function _didSessionTimeout($surveyid)
{
return !isset($_SESSION['survey_'.$surveyid]['s_lang']) && isset($_POST['thisstep']);
return !isset($_SESSION['survey_'.$surveyid]['step']) && isset($_POST['thisstep']);
}

function _canUserPreviewSurvey($iSurveyID)
Expand Down Expand Up @@ -731,6 +706,25 @@ function _printTemplateContent($sTemplateFile, &$redata, $iDebugLine = -1)
echo templatereplace(file_get_contents($sTemplateFile),array(),$redata,'survey['.$iDebugLine.']');
}

function _getLanguage($surveyid, $param)
{
if (!empty($param['lang']))
{
return $param['lang'];// $param take lang from returnGlobal and returnGlobal sanitize langagecode
}
elseif (isset($_SESSION['survey_'.$surveyid]['s_lang']))
{
return $_SESSION['survey_'.$surveyid]['s_lang'];
}
elseif(Survey::model()->findByPk($surveyid))
{
return Survey::model()->findByPk($surveyid)->language;
}
else
{
return Yii::app()->getConfig('defaultlang');
}
}

}

Expand Down

0 comments on commit 0f17fbe

Please sign in to comment.