Skip to content

Commit

Permalink
Fixed issue #07114: {TEMPLATEURL} not parsed correctly at survey's en…
Browse files Browse the repository at this point in the history
…d message

Fixed issue: error public page don't use survey template
Dev: $redata is really a pity
  • Loading branch information
Shnoulle committed Dec 21, 2012
1 parent f3069d1 commit 2cd136f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 41 deletions.
60 changes: 25 additions & 35 deletions application/controllers/survey/index.php
Expand Up @@ -48,9 +48,8 @@ function action()
{
killSurveySession($surveyid);
}


list($surveyExists, $isSurveyActive) = $this->_surveyExistsAndIsActive($surveyid);
$surveyExists=($surveyid && Survey::model()->findByPk($surveyid));
$isSurveyActive=($surveyExists && Survey::model()->findByPk($surveyid)->active=="Y");

// collect all data in this method to pass on later
$redata = compact(array_keys(get_defined_vars()));
Expand Down Expand Up @@ -737,28 +736,6 @@ function _loadLimesurveyLang($mvSurveyIdOrBaseLang)
return new Limesurvey_lang($baselang);
}

function _surveyExistsAndIsActive($surveyId)
{
$isSurveyActive = false;
$surveyExists = false;

if ($surveyId)
{
$aRow = dbExecuteAssoc("SELECT active FROM {{surveys}} WHERE sid='".$surveyId."'")->read();
if (isset($aRow['active']))
{
$surveyExists = true;
if($aRow['active'] == 'Y')
{
$isSurveyActive = true;
}
}
}

return array($surveyExists, $isSurveyActive);
}


function _isClientTokenDifferentFromSessionToken($clientToken, $surveyid)
{
return $clientToken != '' && isset($_SESSION['survey_'.$surveyid]['token']) && $clientToken != $_SESSION['survey_'.$surveyid]['token'];
Expand Down Expand Up @@ -808,28 +785,41 @@ function _userHasPreviewAccessSession($iSurveyID){

function _niceExit(&$redata, $iDebugLine, $sTemplateDir = null, $asMessage = array())
{
if ( $sTemplateDir === null )
$sTemplateDir = Yii::app()->getConfig("standardtemplaterootdir").DIRECTORY_SEPARATOR.'default';

if(isset($redata['surveyid']) && $redata['surveyid'] && !isset($thisurvey))
{
$thissurvey=getSurveyInfo($redata['surveyid']);
$sTemplateDir= getTemplatePath($thissurvey['template']);
}
else
{
$sTemplateDir= getTemplatePath($sTemplateDir);
}
sendCacheHeaders();

doHeader();

$this->_printTemplateContent($sTemplateDir.DIRECTORY_SEPARATOR.'startpage.pstpl', $redata, $iDebugLine);
$this->_printTemplateContent($sTemplateDir.'/startpage.pstpl', $redata, $iDebugLine);
$this->_printMessage($asMessage);
$this->_printTemplateContent($sTemplateDir.DIRECTORY_SEPARATOR.'endpage.pstpl', $redata, $iDebugLine);
$this->_printTemplateContent($sTemplateDir.'/endpage.pstpl', $redata, $iDebugLine);

doFooter();

exit;
}

function _createNewUserSessionAndRedirect($surveyId, &$redata, $iDebugLine, $asMessage = array())
function _createNewUserSessionAndRedirect($surveyid, &$redata, $iDebugLine, $asMessage = array())
{
$clang = Yii::app()->lang;
killSurveySession($surveyId);
killSurveySession($surveyid);
$thissurvey=getSurveyInfo($surveyid);
if($thissurvey)
{
$templatename=$thissurvey['template'];
}
else
{
$templatename=Yii::app()->getConfig('defaulttemplate');;
}
// Let's redirect the client to the same URL after having reset the session
$this->_niceExit($redata, $iDebugLine, null, $asMessage);
$this->_niceExit($redata, $iDebugLine, $templatename, $asMessage);
}


Expand Down
11 changes: 5 additions & 6 deletions application/helpers/SurveyRuntimeHelper.php
Expand Up @@ -361,7 +361,7 @@ function run($surveyid,$args) {
//Before doing the "templatereplace()" function, check the $thissurvey['url']
//field for limereplace stuff, and do transformations!
$thissurvey['surveyls_url'] = passthruReplace($thissurvey['surveyls_url'], $thissurvey);
$thissurvey['surveyls_url'] = templatereplace($thissurvey['surveyls_url'], $thissurvey); // to do INSERTANS substitutions
$thissurvey['surveyls_url'] = templatereplace($thissurvey['surveyls_url'], array(), $redata); // to do INSERTANS substitutions

//END PAGE - COMMIT CHANGES TO DATABASE
if ($thissurvey['active'] != "Y") //If survey is not active, don't really commit
Expand Down Expand Up @@ -390,7 +390,7 @@ function run($surveyid,$args) {
}
*/
// can't kill session before end message, otherwise INSERTANS doesn't work.
$completed = templatereplace($thissurvey['surveyls_endtext']);
$completed = templatereplace($thissurvey['surveyls_endtext'], array(), $redata);
$completed .= "<br /><strong><font size='2' color='red'>" . $clang->gT("Did Not Save") . "</font></strong><br /><br />\n\n";
$completed .= $clang->gT("Your survey responses have not been recorded. This survey is not yet active.") . "<br /><br />\n";
if ($thissurvey['printanswers'] == 'Y')
Expand All @@ -399,8 +399,7 @@ function run($surveyid,$args) {
// in other cases the session is cleared at submit time
$completed .= "<a href='" . Yii::app()->getController()->createUrl("survey/index/sid/{$surveyid}/move/clearall") . "'>" . $clang->gT("Clear Responses") . "</a><br /><br />\n";
}


killSurveySession($surveyid);
}
else //THE FOLLOWING DEALS WITH SUBMITTING ANSWERS AND COMPLETING AN ACTIVE SURVEY
{
Expand Down Expand Up @@ -457,7 +456,7 @@ function run($surveyid,$args) {
}
else
{
$completed = templatereplace($thissurvey['surveyls_endtext']);
$completed = templatereplace($thissurvey['surveyls_endtext'], array(), $redata);
}

// Link to Print Answer Preview **********
Expand Down Expand Up @@ -511,7 +510,7 @@ function run($surveyid,$args) {
{
echo "<table><tr><td align='left'><b>Group/Question Validation Results:</b>" . $moveResult['message'] . "</td></tr></table>\n";
}
echo templatereplace(file_get_contents($sTemplatePath."endpage.pstpl"));
echo templatereplace(file_get_contents($sTemplatePath."endpage.pstpl"), array(), $redata);
doFooter();

// The session cannot be killed until the page is completely rendered
Expand Down

0 comments on commit 2cd136f

Please sign in to comment.