Skip to content

Commit

Permalink
Fixed issue #18129 : Check of json data for upload question (#2433)
Browse files Browse the repository at this point in the history
  • Loading branch information
Shnoulle committed May 31, 2022
1 parent efca172 commit 464762e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 20 deletions.
7 changes: 3 additions & 4 deletions application/helpers/expressions/em_manager_helper.php
Expand Up @@ -8450,13 +8450,12 @@ public static function ProcessCurrentResponses()
if (!preg_match('/_filecount$/', $sq)) {
$json = $value;
$aFiles = json_decode($json);
$iSize = (is_null($aFiles)) ? 0 : @count($aFiles);
// if the files have not been saved already,
// move the files from tmp to the files folder

$tmp = $LEM->surveyOptions['tempdir'] . 'upload' . DIRECTORY_SEPARATOR;
if (!is_null($aFiles) && $iSize > 0) {
if (!empty($aFiles) && is_array($aFiles)) {
$iSize = count($aFiles);
// Move the (unmoved, temp) files from temp to files directory.
$tmp = $LEM->surveyOptions['tempdir'] . 'upload' . DIRECTORY_SEPARATOR;
// Check all possible file uploads
for ($i = 0; $i < $iSize; $i++) {
$aFiles[$i]->name = sanitize_filename($aFiles[$i]->name, false, false, true);
Expand Down
29 changes: 13 additions & 16 deletions application/helpers/frontend_helper.php
Expand Up @@ -260,12 +260,10 @@ function checkUploadedFileValidity($surveyid, $move, $backok = null)
global $thisstep;

$survey = Survey::model()->findByPk($surveyid);


if (!isset($backok) || $backok != "Y") {
$fieldmap = createFieldMap($survey, 'full', false, false, $_SESSION['survey_' . $surveyid]['s_lang']);

if (isset($_POST['fieldnames']) && $_POST['fieldnames'] != "") {
if (!empty(App()->getRequest()->getPost('fieldnames'))) {
$fields = explode("|", $_POST['fieldnames']);

foreach ($fields as $field) {
Expand All @@ -274,20 +272,19 @@ function checkUploadedFileValidity($surveyid, $move, $backok = null)

$filecount = 0;

$json = $_POST[$field];
$json = App()->getRequest()->getPost($field);
$phparray = json_decode(urldecode($json));
// if name is blank, its basic, hence check
// else, its ajax, don't check, bypass it.

if ($json != "" && $json != "[]") {
$phparray = json_decode(urldecode($json));
if ($phparray[0]->size != "") {
// ajax
if (!empty($phparray)) {
if (!empty($phparray[0]->size)) {
// ajax
$filecount = count($phparray);
} else {
// basic
// basic
for ($i = 1; $i <= $validation['max_num_of_files']; $i++) {
if (!isset($_FILES[$field . "_file_" . $i]) || $_FILES[$field . "_file_" . $i]['name'] == '') {
continue;
continue;
}

$filecount++;
Expand Down Expand Up @@ -318,7 +315,7 @@ function checkUploadedFileValidity($surveyid, $move, $backok = null)
}
}
} else {
$filecount = 0;
$filecount = 0;
}

if (isset($validation['min_num_of_files']) && $filecount < $validation['min_num_of_files'] && LimeExpressionManager::QuestionIsRelevant($fieldmap[$field]['qid'])) {
Expand All @@ -330,18 +327,18 @@ function checkUploadedFileValidity($surveyid, $move, $backok = null)
}
if (isset($filenotvalidated)) {
if (isset($move) && $move == "moveprev") {
$_SESSION['survey_' . $surveyid]['step'] = $thisstep;
$_SESSION['survey_' . $surveyid]['step'] = $thisstep;
}
if (isset($move) && $move == "movenext") {
$_SESSION['survey_' . $surveyid]['step'] = $thisstep;
$_SESSION['survey_' . $surveyid]['step'] = $thisstep;
}
return $filenotvalidated;
}
}
if (!isset($filenotvalidated)) {
return false;
return false;
} else {
return $filenotvalidated;
return $filenotvalidated;
}
}

Expand Down

0 comments on commit 464762e

Please sign in to comment.