Skip to content

Commit

Permalink
Dev: fixed #14226 second part (#1192)
Browse files Browse the repository at this point in the history
Dev: move to use extends "./subviews/content/submit.twig"
Dev: add a lot of block to allow updating
Dev: do the job 2 times : one in SurveyRunTime : didn't broke current extended template
Dev: 2 times too for automatic translation
Dev: add information about url (print and stats) and disable url
  • Loading branch information
Shnoulle committed Dec 17, 2018
1 parent 93a5cf4 commit 3af1dea
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 92 deletions.
151 changes: 66 additions & 85 deletions application/helpers/SurveyRuntimeHelper.php
Expand Up @@ -1085,7 +1085,9 @@ private function setNotAnsweredAndNotValidated()
private function moveSubmitIfNeeded()
{
if ($this->sMove == "movesubmit") {

/* Put active in var for next part */
$surveyActive = ($this->aSurveyInfo['active'] == "Y");
$oSurvey = Survey::model()->findByPk($this->iSurveyid);
// Parts needed for active and unactive
//Check for assessments
$this->aSurveyInfo['aAssessments']['show'] = false;
Expand All @@ -1102,77 +1104,55 @@ private function moveSubmitIfNeeded()
$this->aSurveyInfo['aCompleted']['sEndText'] = $this->processString($this->aSurveyInfo['surveyls_endtext'], 2);
}

if ($this->aSurveyInfo['active'] != "Y") {

sendCacheHeaders();

$redata = compact(array_keys(get_defined_vars()));
// can't kill session before end message, otherwise INSERTANS doesn't work.
$completed = templatereplace($this->aSurveyInfo['surveyls_endtext'], array(), $redata, 'SubmitEndtextI', false, null, array(), true);
$this->completed = $completed;

$this->aSurveyInfo['include_content'] = 'submit_preview';
Yii::app()->twigRenderer->renderTemplateFromFile("layout_global.twig", array('oSurvey'=> Survey::model()->findByPk($this->iSurveyid), 'aSurveyInfo'=>$this->aSurveyInfo), false);
} else {

//Update the token if needed and send a confirmation email
if (isset($_SESSION['survey_'.$this->iSurveyid]['token'])) {
submittokens();
}

//Send notifications
//Update the token if needed and send a confirmation email
if ($surveyActive && $oSurvey->getHasTokensTable()) {
submittokens();
}
//Send notifications
if($surveyActive) {
sendSubmitNotifications($this->iSurveyid);
}
// Link to Print Answer Preview **********
$this->aSurveyInfo['aCompleted']['aPrintAnswers']['show'] = false;
if ($this->aSurveyInfo['printanswers'] == 'Y') {
$this->aSurveyInfo['aCompleted']['aPrintAnswers']['show'] = true;
$this->aSurveyInfo['aCompleted']['aPrintAnswers']['sUrl'] = $surveyActive ? Yii::app()->getController()->createUrl("/printanswers/view", array('surveyid'=>$this->iSurveyid)) : "#";
$this->aSurveyInfo['aCompleted']['aPrintAnswers']['sText'] = $surveyActive ? gT("Print your answers.") : gT("Print your answers is disable when survey not activated.");
}
// Link to Public statistics
$this->aSurveyInfo['aCompleted']['aPublicStatistics']['show'] = false;
if ($this->aSurveyInfo['publicstatistics'] == 'Y') {
$this->aSurveyInfo['aCompleted']['aPublicStatistics']['show'] = true;
$this->aSurveyInfo['aCompleted']['aPublicStatistics']['sUrl'] = $surveyActive ? Yii::app()->getController()->createUrl("/statistics_user/action/", array('surveyid'=>$this->iSurveyid, 'language'=>App()->getLanguage())) : "#";
$this->aSurveyInfo['aCompleted']['aPublicStatistics']['sText'] = $surveyActive ? gT("View the statistics for this survey.") : gT("View the statistics for this survey is disable when survey not activated.");
}

// Link to Print Answer Preview **********
$this->aSurveyInfo['aCompleted']['aPrintAnswers']['show'] = false;
if ($this->aSurveyInfo['printanswers'] == 'Y') {
$this->aSurveyInfo['aCompleted']['aPrintAnswers']['show'] = true;
$this->aSurveyInfo['aCompleted']['aPrintAnswers']['sUrl'] = Yii::app()->getController()->createUrl("/printanswers/view", array('surveyid'=>$this->iSurveyid));
$this->aSurveyInfo['aCompleted']['aPrintAnswers']['sText'] = gT("Print your answers.");

}

// Link to Public statistics **********
$this->aSurveyInfo['aCompleted']['aPublicStatistics']['show'] = false;
if ($this->aSurveyInfo['publicstatistics'] == 'Y') {
$this->aSurveyInfo['aCompleted']['aPublicStatistics']['show'] = true;
$this->aSurveyInfo['aCompleted']['aPublicStatistics']['sUrl'] = Yii::app()->getController()->createUrl("/statistics_user/action/", array('surveyid'=>$this->iSurveyid, 'language'=>App()->getLanguage()));

}

$this->completed = true;

//*****************************************
$this->completed = true;

$_SESSION[$this->LEMsessid]['finished'] = true;
$_SESSION[$this->LEMsessid]['sid'] = $this->iSurveyid;
$_SESSION[$this->LEMsessid]['finished'] = true;
$_SESSION[$this->LEMsessid]['sid'] = $this->iSurveyid;

//THE FOLLOWING DEALS WITH SUBMITTING ANSWERS AND COMPLETING AN ACTIVE SURVEY
//don't use cookies if tokens are being used
if (!empty($this->aSurveyInfo['active']) && $this->aSurveyInfo['active'] == "Y") {
global $tokensexist;
if ($this->aSurveyInfo['usecookie'] == "Y" && $tokensexist != 1 && $this->aMoveResult['finished'] == true ) {
setcookie("LS_".$this->iSurveyid."_STATUS", "COMPLETE", time() + 31536000); //Cookie will expire in 365 days
}
// cookies
if($surveyActive && $this->aSurveyInfo['usecookie'] == "Y") {
if(!$oSurvey->getHasTokensTable()) {
setcookie("LS_".$this->iSurveyid."_STATUS", "COMPLETE", time() + 31536000); //Cookie will expire in 365 days
}
}

$redata['completed'] = $this->completed;

// @todo Remove direct session access.
$event = new PluginEvent('afterSurveyComplete');

if (isset($_SESSION[$this->LEMsessid]['srid'])) {
$event->set('responseId', $_SESSION[$this->LEMsessid]['srid']);
}

$event->set('surveyId', $this->iSurveyid);
App()->getPluginManager()->dispatchEvent($event);
// event afterSurveyComplete
$blocks = array();

foreach ($event->getAllContent() as $blockData) {
/* @var $blockData PluginEventContent */
$blocks[] = CHtml::tag('div', array('id' => $blockData->getCssId(), 'class' => $blockData->getCssClass()), $blockData->getContent());
if($surveyActive) { // @todo : enable event even when survey is not active, but broke API

This comment has been minimized.

Copy link
@olleharstedt

olleharstedt Sep 28, 2022

Contributor

but broke API

Broke how?

This comment has been minimized.

Copy link
@Shnoulle

Shnoulle Sep 28, 2022

Author Collaborator

Because event didn't happen before, the line testing is at 1105 before
3af1dea#diff-f2c0610f506dc0397d2efd8d8203a78dc44f2825e26eb0ac70efd87205d2e36eL1105

$event = new PluginEvent('afterSurveyComplete');
if ($surveyActive && isset($_SESSION[$this->LEMsessid]['srid'])) {
$event->set('responseId', $_SESSION[$this->LEMsessid]['srid']);
}
$event->set('surveyId', $this->iSurveyid);
App()->getPluginManager()->dispatchEvent($event);
foreach ($event->getAllContent() as $blockData) {
/* @var $blockData PluginEventContent */
$blocks[] = CHtml::tag('div', array('id' => $blockData->getCssId(), 'class' => $blockData->getCssClass()), $blockData->getContent());
}
}

$this->aSurveyInfo['aCompleted']['sPluginHTML'] = implode("\n", $blocks)."\n";
Expand All @@ -1182,29 +1162,12 @@ private function moveSubmitIfNeeded()
$this->aSurveyInfo['surveyls_url'] = templatereplace($this->aSurveyInfo['surveyls_url'], array(), $redata, 'URLReplace', false, null, array(), true); // to do INSERTANS substitutions
$this->aSurveyInfo['aCompleted']['sSurveylsUrl'] = $this->aSurveyInfo['surveyls_url'];

// TODO: Process string in url description?
if ($this->aSurveyInfo['surveyls_urldescription'] != "") {
$this->aSurveyInfo['aCompleted']['sSurveylsUrlDescription'] = $this->aSurveyInfo['surveyls_urldescription'];
} else {
$this->aSurveyInfo['aCompleted']['sSurveylsUrlDescription'] = $this->aSurveyInfo['surveyls_urldescription'];
if ($this->aSurveyInfo['aCompleted']['sSurveylsUrlDescription'] == "") {
$this->aSurveyInfo['aCompleted']['sSurveylsUrlDescription'] = $this->aSurveyInfo['surveyls_url'];
}


if (isset($this->aSurveyInfo['autoredirect']) && $this->aSurveyInfo['autoredirect'] == "Y" && $this->aSurveyInfo['surveyls_url']) {
//Automatically redirect the page to the "url" setting for the survey
$headToSurveyUrl = htmlspecialchars_decode ($this->aSurveyInfo['surveyls_url']);

$actualRedirect = $headToSurveyUrl;
header("Access-Control-Allow-Origin: *");

if(Yii::app()->request->getParam('ajax') == 'on'){
header("X-Redirect: ".$headToSurveyUrl, false, 302);
} else {
header("Location: ".$actualRedirect, false, 302);
}

}

// LEM debug (???? what is this usage …)
$this->aSurveyInfo['aLEM']['debugvalidation']['show'] = false;
if (($this->LEMdebugLevel & LEM_DEBUG_VALIDATION_SUMMARY) == LEM_DEBUG_VALIDATION_SUMMARY) {
$this->aSurveyInfo['aLEM']['debugvalidation']['show'] = true;
Expand All @@ -1221,13 +1184,31 @@ private function moveSubmitIfNeeded()
$this->aSurveyInfo['aLEM']['debugvalidation']['message'] .= "<table><tr><td align='left'><b>Group/Question Validation Results:</b>".$this->aMoveResult['message']."</td></tr></table>\n";
}

// The session cannot be killed until the page is completely rendered
// kill survey session before redirecting
if ($this->aSurveyInfo['printanswers'] != 'Y') {
killSurveySession($this->iSurveyid);
}

if (isset($this->aSurveyInfo['autoredirect']) && $this->aSurveyInfo['autoredirect'] == "Y" && $this->aSurveyInfo['surveyls_url']) {
//Automatically redirect the page to the "url" setting for the survey
$headToSurveyUrl = htmlspecialchars_decode ($this->aSurveyInfo['surveyls_url']);
$actualRedirect = $headToSurveyUrl;
if($surveyActive) {
header("Access-Control-Allow-Origin: *");
if(Yii::app()->request->getParam('ajax') == 'on'){
header("X-Redirect: ".$headToSurveyUrl, false, 302);
} else {
header("Location: ".$actualRedirect, false, 302);
}
}
$this->aSurveyInfo['aCompleted']['sSurveylsUrlDescriptionExta'] = gT("Automatically load URL when survey complete deactivated disable when survey is not activated.");
}

$this->aSurveyInfo['include_content'] = 'submit';
Yii::app()->twigRenderer->renderTemplateFromFile("layout_global.twig", array('oSurvey'=> Survey::model()->findByPk($this->iSurveyid), 'aSurveyInfo'=>$this->aSurveyInfo), false);
if(!$surveyActive) {
$this->aSurveyInfo['include_content'] = 'submit_preview';
}
Yii::app()->twigRenderer->renderTemplateFromFile("layout_global.twig", array('oSurvey'=> $oSurvey, 'aSurveyInfo'=>$this->aSurveyInfo), false);
}
}

Expand Down
14 changes: 12 additions & 2 deletions themes/survey/vanilla/views/subviews/content/submit.twig
Expand Up @@ -31,18 +31,23 @@
{{ aSurveyInfo.EM.ScriptsAndHiddenInputs }}
<div class="{{ aSurveyInfo.class.submitwrapper }}" {{ aSurveyInfo.attr.submitwrapper }}>
<div class='{{ aSurveyInfo.class.submitwrappertext }}' {{ aSurveyInfo.attr.submitwrappertext }}>
{% block endtext %}
{% if (aSurveyInfo.aCompleted.showDefault == true) %}
<p {{ aSurveyInfo.attr.submitwrappertextpa }}>{{ gT("Thank you!") }}</p>
<p {{ aSurveyInfo.attr.submitwrappertextpb }}>{{ gT("Your survey responses have been recorded.") }}</p>
{% else %}
{{ aSurveyInfo.aCompleted.sEndText }}
{% endif %}
{% endblock %}

{% block assessments %}
{# Assessments #}
{% if (aSurveyInfo.aAssessments.show) %}
{{ include('./subviews/messages/assessments.twig') }}
{% endif %}
{% endblock %}

{% block printanswer %}
{# Link to Print Answer Preview #}
{% if (aSurveyInfo.aCompleted.aPrintAnswers.show == true) %}
<!-- Link to Print Answer Preview -->
Expand All @@ -52,7 +57,9 @@
</a>
</div>
{% endif %}
{% endblock %}

{% block publicstatistics %}
{# Link to Public statistics #}
{% if (aSurveyInfo.aCompleted.aPublicStatistics.show == true) %}
<!-- Link to Public statistics -->
Expand All @@ -62,14 +69,17 @@
</a>
</div>
{% endif %}
{% endblock %}

{# Before LS3 Master, this should be replace by a Twig block logic #}
{{ aSurveyInfo.aCompleted.sPluginHTML }}

{% block endurl %}
{# NOTE: not very clear what the old replacement keyword {URL} was doing #}
{% if (aSurveyInfo.surveyls_url) %}
<a href="{{ aSurveyInfo.surveyls_url }}">{{ aSurveyInfo.surveyls_urldescription ?: aSurveyInfo.surveyls_url }}</a>
{% if (aSurveyInfo.aCompleted.sSurveylsUrl) %}
<a href="{{ aSurveyInfo.aCompleted.sSurveylsUrl }}">{{ aSurveyInfo.aCompleted.sSurveylsUrlDescription }}</a>
{% endif %}
{% endblock %}
</div>
</div>
</form> <!-- main form -->
43 changes: 38 additions & 5 deletions themes/survey/vanilla/views/subviews/content/submit_preview.twig
Expand Up @@ -17,9 +17,42 @@
NOTE: This content is included inside mainrow.twig
NOTE: see layout_global.twig for more infos
#}
<!-- main form -->
<div class="alert alert-warning"><strong class="h4 text-danger">{{ gT("Did Not Save") }} </strong>
{{ gT("Your survey responses have not been recorded. This survey is not yet active.") }}
</div>
{{ include('./subviews/content/submit.twig') }}
{% extends "./subviews/content/submit.twig" %}
{% block endtext %}
<div class="alert alert-warning"><strong class="h4 text-danger">{{ gT("Did Not Save") }} </strong>
{{ gT("Your survey responses have not been recorded. This survey is not yet active.") }}
</div>
{{ parent() }}
{% endblock %}
{% block printanswer %}
{# Link to Print Answer Preview #}
{% if (aSurveyInfo.aCompleted.aPrintAnswers.show == true) %}
<!-- Link to Print Answer Preview -->
<div class="{{ aSurveyInfo.class.submitwrapperdiva }} disabled" {{ aSurveyInfo.attr.submitwrapperdiv }}>
<a href="#" class="{{ aSurveyInfo.class.submitwrapperdivaa }}" {{ aSurveyInfo.attr.submitwrapperdivaa }}>
{{ gT("Print your answers is disable when survey not activated.") }}
</a>
</div>
{% endif %}
{% endblock %}
{% block publicstatistics %}
{# Link to Public statistics #}
{% if (aSurveyInfo.aCompleted.aPublicStatistics.show == true) %}
<!-- Link to Public statistics -->
<div class="{{ aSurveyInfo.class.submitwrapperdivb }}" {{ aSurveyInfo.attr.submitwrapperdivb }}>
<a href="#" class="{{ aSurveyInfo.class.submitwrapperdivba }}" {{ aSurveyInfo.attr.submitwrapperdivba }}>
{{ gT("View the statistics for this survey is disable when survey not activated.") }}
</a>
</div>
{% endif %}
{% endblock %}
{% block endurl %}
{% if (aSurveyInfo.aCompleted.sSurveylsUrl) %}
<a href="{{ aSurveyInfo.aCompleted.sSurveylsUrl }}">{{ aSurveyInfo.aCompleted.sSurveylsUrlDescription }}
{% if(aSurveyInfo.autoredirect == "Y") %}
<small class="text-info">{{ gT("Automatically load URL when survey complete deactivated disable when survey is not activated.") }}</small>
{% endif %}
</a>
{% endif %}
{% endblock %}

0 comments on commit 3af1dea

Please sign in to comment.