Skip to content

Commit

Permalink
fix uncaught error in content element
Browse files Browse the repository at this point in the history
  • Loading branch information
MDevster committed Jul 18, 2024
1 parent cf29778 commit 1ae5753
Show file tree
Hide file tree
Showing 12 changed files with 48 additions and 41 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ Types of changes
Security in case of vulnerabilities.
)


## [3.6.1](https://github.com/pdir/contao-survey/tree/3.6.1) – 2024-07-18

- [Fixed] Error when starting TAN surveys fixed
- [Changed] Increase PHP version to minimum 8.0

## [3.6.0](https://github.com/pdir/contao-survey/tree/3.6.0) – 2024-07-04

- [Added] an **autostart** feature for an anonymous survey with TAN. To use this feature, the page with the corresponding
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
}
],
"require": {
"php": "^7.4 || ^8.0",
"php": "^8.0",
"contao/core-bundle": "^4.9",
"doctrine/dbal": "^2.5 || ^3.0",
"hschottm/contao-textwizard": "^3.2",
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/contao/classes/Survey.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function getSurveyStatus($id, $pin)
*
* @return string
*/
public function checkPINTAN($id, $pin = '', $tan = '')
public function checkPINTAN($id, $pin = '', $tan = ''): bool|string
{
if (\strlen($pin)) {
$pinTanModel = SurveyPinTanModel::findOneBy(['pid=?', 'pin=?'], [$id, $pin]);
Expand Down
10 changes: 5 additions & 5 deletions src/Resources/contao/classes/SurveyQuestionConstantsum.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public function exportDataToExcel(&$exporter, $sheet, &$row): void
$col = 2;

if (\is_array($this->statistics['cumulated'])) {
$arrChoices = deserialize($this->arrData['sumchoices'], true);
$arrChoices = StringUtil::deserialize($this->arrData['sumchoices'], true);
$counter = 1;

foreach ($arrChoices as $choice) {
Expand Down Expand Up @@ -171,7 +171,7 @@ public function exportDetailsToExcel(&$exporter, $sheet, &$row, &$col, $question

public function resultAsString($res)
{
$arrAnswer = deserialize($res, true);
$arrAnswer = StringUtil::deserialize($res, true);

if (\is_array($arrAnswer)) {
return implode(', ', $arrAnswer);
Expand Down Expand Up @@ -201,7 +201,7 @@ protected function calculateCumulated(): void
$cumulated['other'] = [];

foreach ($this->arrStatistics['answers'] as $answer) {
$arrAnswer = deserialize($answer, true);
$arrAnswer = StringUtil::deserialize($answer, true);

if (\is_array($arrAnswer)) {
foreach ($arrAnswer as $answerkey => $answervalue) {
Expand Down Expand Up @@ -242,7 +242,7 @@ protected function calculateCumulated(): void
*/
protected function exportQuestionHeadersToExcel(&$exporter, $sheet, &$row, &$col, $questionNumbers, &$rotateInfo)
{
$this->choices = deserialize($this->arrData['sumchoices'], true);
$this->choices = StringUtil::deserialize($this->arrData['sumchoices'], true);

foreach ($this->choices as $k => $v) {
$this->choices[$k] = StringUtil::decodeEntities($v);
Expand Down Expand Up @@ -404,7 +404,7 @@ protected function exportDetailResults(&$exporter, $sheet, &$row, &$col, $partic

if ($data) {
$col = $startCol;
$arrAnswers = deserialize($data, true);
$arrAnswers = StringUtil::deserialize($data, true);

foreach ($this->choices as $k => $choice) {
$strAnswer = '';
Expand Down
14 changes: 7 additions & 7 deletions src/Resources/contao/classes/SurveyQuestionMatrix.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ public function exportDataToExcel(&$exporter, $sheet, &$row): void
$col = 2;

if (\is_array($this->statistics['cumulated'])) {
$arrRows = deserialize($this->arrData['matrixrows'], true);
$arrChoices = deserialize($this->arrData['matrixcolumns'], true);
$arrRows = StringUtil::deserialize($this->arrData['matrixrows'], true);
$arrChoices = StringUtil::deserialize($this->arrData['matrixcolumns'], true);
$row_counter = 1;

foreach ($arrRows as $id => $rowdata) {
Expand Down Expand Up @@ -190,7 +190,7 @@ public function exportDetailsToExcel(&$exporter, $sheet, &$row, &$col, $question

public function resultAsString($res)
{
$arrAnswer = deserialize($res, true);
$arrAnswer = StringUtil::deserialize($res, true);

if (\is_array($arrAnswer)) {
// ToDo: fix the following workaround
Expand Down Expand Up @@ -221,7 +221,7 @@ protected function calculateCumulated(): void
$cumulated['other'] = [];

foreach ($this->arrStatistics['answers'] as $answer) {
$arrAnswer = deserialize($answer, true);
$arrAnswer = StringUtil::deserialize($answer, true);

if (\is_array($arrAnswer)) {
foreach ($arrAnswer as $row => $answervalue) {
Expand Down Expand Up @@ -256,14 +256,14 @@ protected function calculateCumulated(): void
*/
protected function exportQuestionHeadersToExcel(&$exporter, $sheet, &$row, &$col, $questionNumbers, &$rotateInfo)
{
$this->subquestions = deserialize($this->arrData['matrixrows'], true);
$this->subquestions = StringUtil::deserialize($this->arrData['matrixrows'], true);

foreach ($this->subquestions as $k => $v) {
$this->subquestions[$k] = StringUtil::decodeEntities($v);
}
$numcols = \count($this->subquestions);

$this->choices = deserialize($this->arrData['matrixcolumns'], true);
$this->choices = StringUtil::deserialize($this->arrData['matrixcolumns'], true);

if ($this->arrData['addneutralcolumn']) {
// TODO: i believe, the dash is better then the real text for the neutral column, make configurable?
Expand Down Expand Up @@ -437,7 +437,7 @@ protected function exportDetailResults(&$exporter, $sheet, &$row, &$col, $partic

if ($data) {
$col = $startCol;
$arrAnswers = deserialize($data, true);
$arrAnswers = StringUtil::deserialize($data, true);

if ('matrix_singleresponse' === $this->arrData['matrix_subtype']) {
$emptyAnswer = false;
Expand Down
6 changes: 3 additions & 3 deletions src/Resources/contao/classes/SurveyQuestionMultiplechoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ protected function exportDetailResults(&$exporter, $sheet, &$row, &$col, $partic

if ($data) {
$col = $startCol;
$arrAnswers = deserialize($data, true);
$arrAnswers = StringUtil::deserialize($data, true);

if ('mc_dichotomous' === $this->arrData['multiplechoice_subtype']) {
$exporter->setCellValue($sheet, $row, $col, [
Expand Down Expand Up @@ -592,14 +592,14 @@ protected function exportDetailResults(&$exporter, $sheet, &$row, &$col, $partic

/*public function resultAsString($res)
{
$arrAnswer = deserialize($res, true);
$arrAnswer = StringUtil::deserialize($res, true);
if (is_array($arrAnswer['value']))
{
return implode (", ", $arrAnswer['value']);
}
else
{
$arrChoices = (strcmp($this->arrData['multiplechoice_subtype'], 'mc_dichotomous') != 0) ? deserialize($this->arrData['choices'], true) : array(0 => $GLOBALS['TL_LANG']['tl_survey_question']['yes'], 1 => $GLOBALS['TL_LANG']['tl_survey_question']['no']);
$arrChoices = (strcmp($this->arrData['multiplechoice_subtype'], 'mc_dichotomous') != 0) ? StringUtil::deserialize($this->arrData['choices'], true) : array(0 => $GLOBALS['TL_LANG']['tl_survey_question']['yes'], 1 => $GLOBALS['TL_LANG']['tl_survey_question']['no']);
return $arrChoices[$arrAnswer['value']-1];
}
if (strlen($arrAnswer['other']))
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/contao/dca/tl_survey_question.php
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,7 @@ public function addScale(DataContainer $dc)
$arrScales = [];

while ($objScales->next()) {
$arrScales[$objScales->id] = ['title' => $objScales->title, 'scales' => deserialize($objScales->scale, true), 'folder' => $objScales->folder];
$arrScales[$objScales->id] = ['title' => $objScales->title, 'scales' => StringUtil::deserialize($objScales->scale, true), 'folder' => $objScales->folder];
}

// Add scale
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/contao/dca/tl_survey_scale.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public function compilePreview($row, $blnWriteToFile = false)
{
$result = '<p><strong>'.$row['title'].'</strong></p>';
$result .= '<ol>';
$answers = deserialize($row['scale'], true);
$answers = StringUtil::deserialize($row['scale'], true);

foreach ($answers as $answer) {
$result .= '<li>'.StringUtil::specialchars($answer).'</li>';
Expand Down
36 changes: 18 additions & 18 deletions src/Resources/contao/elements/ContentSurvey.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ protected function compile()

// add survey javascript
if (\is_array($GLOBALS['TL_JAVASCRIPT'])) {
array_insert($GLOBALS['TL_JAVASCRIPT'], 1, 'bundles/hschottmsurvey/js/survey.js');
\array_insert($GLOBALS['TL_JAVASCRIPT'], 1, 'bundles/hschottmsurvey/js/survey.js');
} else {
$GLOBALS['TL_JAVASCRIPT'] = ['bundles/hschottmsurvey/js/survey.js'];
}
Expand Down Expand Up @@ -146,7 +146,7 @@ protected function compile()
$pintan = $this->svy->generatePIN_TAN();

if ($this->objSurvey->usecookie) {
setcookie('TLsvy_'.$this->objSurvey->id, $pintan['PIN'], time() + 3600 * 24 * 365, '/');
\setcookie('TLsvy_'.$this->objSurvey->id, $pintan['PIN'], time() + 3600 * 24 * 365, '/');
}
$this->pin = $pintan['PIN'];
$this->insertPinTan($this->objSurvey->id, $pintan['PIN'], $pintan['TAN'], 1);
Expand All @@ -158,15 +158,15 @@ protected function compile()
case 'anoncode':
$tan = Input::post('tan');

if (0 === strcmp(Input::post('FORM_SUBMIT'), 'tl_survey_form') && (!empty($tan))) {
if (0 === \strcmp(Input::post('FORM_SUBMIT'), 'tl_survey_form') && (!empty($tan))) {
$result = $this->svy->checkPINTAN($this->objSurvey->id, '', $tan);

if (false === $result) {
$this->Template->tanMsg = $GLOBALS['TL_LANG']['ERR']['survey_wrong_tan'];
} else {
$this->pin = $this->svy->getPINforTAN($this->objSurvey->id, $tan);

if ('0' === $result) {
if (0 == $result) {
$res = SurveyPinTanModel::findOneBy(['tan=?', 'pid=?'], [$tan, $this->objSurvey->id]);

if (null !== $res) {
Expand All @@ -175,7 +175,7 @@ protected function compile()
}
// set pin
if ($this->objSurvey->usecookie) {
setcookie('TLsvy_'.$this->objSurvey->id, $this->pin, time() + 3600 * 24 * 365, '/');
\setcookie('TLsvy_'.$this->objSurvey->id, $this->pin, \time() + 3600 * 24 * 365, '/');
}
$this->insertParticipant($this->objSurvey->id, $this->pin);
$page = 1;
Expand Down Expand Up @@ -327,12 +327,12 @@ protected function compile()
$this->Template->pin = $this->pin;

// fix for /survey/code/xyz.html urls
if (isset($tan) && str_contains($formaction, '/code/')) {
$url = parse_url($formaction);
$formaction = str_replace('/code/'.$tan, '', $url['path']);
if (isset($tan) && \str_contains($formaction, '/code/')) {
$url = \parse_url($formaction);
$formaction = \str_replace('/code/'.$tan, '', $url['path']);
}

$this->Template->action = ampersand($formaction);
$this->Template->action = \ampersand($formaction);
}

protected function evaluateConditions($page)
Expand Down Expand Up @@ -387,7 +387,7 @@ protected function evaluateConditions($page)
}

if ($applies) {
$condition = array_shift($group);
$condition = \array_shift($group);

return $condition['pageid'];
}
Expand All @@ -403,7 +403,7 @@ protected function getResultForQuestion($question_id)
;

if ($objResult->numRows) {
return deserialize($objResult->result);
return \deserialize($objResult->result);
}

return null;
Expand Down Expand Up @@ -450,7 +450,7 @@ protected function createSurveyPage($pagerow, $pagenumber, $validate = true, $go
$objWidget->pageQuestionNumber = $pagequestioncounter;
$objWidget->pageNumber = $pagenumber;
$objWidget->cssClass = ('' !== $question['cssClass'] ? ' '.$question['cssClass'] : '').(0 === $objWidget->absoluteNumber % 2 ? ' odd' : ' even');
array_push($surveypage, $objWidget);
\array_push($surveypage, $objWidget);
++$pagequestioncounter;

if ($validate) {
Expand Down Expand Up @@ -533,7 +533,7 @@ protected function createSurveyPage($pagerow, $pagenumber, $validate = true, $go
$value = $question->value;

if (\is_array($question->value)) {
$value = serialize($question->value);
$value = \serialize($question->value);
}

if (!empty($value)) {
Expand Down Expand Up @@ -620,16 +620,16 @@ protected function createSurveyPage($pagerow, $pagenumber, $validate = true, $go

if (null !== $res) {
if (!empty($res->result)) {
$arrRecipient = trimsplit(',', $res->result);
$arrRecipient = \trimsplit(',', $res->result);
}
}
}

if (!empty($this->objSurvey->confirmationMailRecipient)) {
$varRecipient = $this->objSurvey->confirmationMailRecipient;
$arrRecipient = array_merge($arrRecipient, trimsplit(',', $varRecipient));
$arrRecipient = \array_merge($arrRecipient, \trimsplit(',', $varRecipient));
}
$arrRecipient = array_filter(array_unique($arrRecipient));
$arrRecipient = \array_filter(array_unique($arrRecipient));

if (!empty($arrRecipient)) {
foreach ($arrRecipient as $kR => $recipient) {
Expand All @@ -641,7 +641,7 @@ protected function createSurveyPage($pagerow, $pagenumber, $validate = true, $go
// Check if we want custom attachments... (Thanks to Torben Schwellnus)
if ($this->objSurvey->addConfirmationMailAttachments) {
if ($this->objSurvey->confirmationMailAttachments) {
$arrCustomAttachments = deserialize($this->objSurvey->confirmationMailAttachments, true);
$arrCustomAttachments = StringUtil::deserialize($this->objSurvey->confirmationMailAttachments, true);

if (!empty($arrCustomAttachments)) {
foreach ($arrCustomAttachments as $varFile) {
Expand Down Expand Up @@ -779,7 +779,7 @@ protected function createSurveyPage($pagerow, $pagenumber, $validate = true, $go
// Check if we want custom attachments... (Thanks to Torben Schwellnus)
if ($this->objSurvey->addConfirmationMailAlternateAttachments) {
if ($this->objSurvey->confirmationMailAlternateAttachments) {
$arrCustomAttachments = deserialize($this->objSurvey->confirmationMailAlternateAttachments, true);
$arrCustomAttachments = StringUtil::deserialize($this->objSurvey->confirmationMailAlternateAttachments, true);

if (!empty($arrCustomAttachments)) {
foreach ($arrCustomAttachments as $varFile) {
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/contao/forms/FormConstantSumQuestion.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function __set($strKey, $varValue): void
$this->strSumOption = $varValue['sumoption'];
$this->dblSum = (float)$varValue['sum'];
$this->blnInputFirst = $varValue['inputfirst'] ? true : false;
$this->arrChoices = deserialize($varValue['sumchoices']);
$this->arrChoices = StringUtil::deserialize($varValue['sumchoices']);

if (!\is_array($this->arrChoices)) {
$this->arrChoices = [];
Expand Down
4 changes: 2 additions & 2 deletions src/Resources/contao/forms/FormMatrixQuestion.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ public function __set($strKey, $varValue): void
case 'surveydata':
parent::__set($strKey, $varValue);
$this->strClass = 'matrix'.((\strlen($varValue['cssClass']) ? ' '.$varValue['cssClass'] : ''));
$this->arrRows = deserialize($varValue['matrixrows']);
$this->arrRows = StringUtil::deserialize($varValue['matrixrows']);

if (!\is_array($this->arrRows)) {
$this->arrRows = [];
}
$this->arrColumns = deserialize($varValue['matrixcolumns']);
$this->arrColumns = StringUtil::deserialize($varValue['matrixcolumns']);

if (!\is_array($this->arrColumns)) {
$this->arrColumns = [];
Expand Down
3 changes: 2 additions & 1 deletion src/Resources/contao/widgets/ConditionWizard.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
namespace Hschottm\SurveyBundle;

use Contao\BackendTemplate;
use Contao\StringUtil;
use Contao\Widget;

/**
Expand Down Expand Up @@ -58,7 +59,7 @@ public function __set($strKey, $varValue): void
break;

case 'value':
$this->varValue = deserialize($varValue);
$this->varValue = StringUtil::deserialize($varValue);
break;

case 'mandatory':
Expand Down

0 comments on commit 1ae5753

Please sign in to comment.