Skip to content

Commit

Permalink
some more file upload problems
Browse files Browse the repository at this point in the history
  • Loading branch information
mennodekker committed Aug 21, 2012
1 parent b835771 commit 5614cbb
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
11 changes: 6 additions & 5 deletions application/controllers/admin/responses.php
Expand Up @@ -246,7 +246,8 @@ public function view($iSurveyID, $iId, $sBrowseLang = '')
{
$index = $fnames[$i]['index'];
$metadata = $fnames[$i]['metadata'];
$phparray = json_decode($iIdrow[$fnames[$i][0]], true);
$phparray = json_decode_ls($iIdrow[$fnames[$i][0]]);

if (isset($phparray[$index]))
{
if ($metadata === "size")
Expand Down Expand Up @@ -341,7 +342,7 @@ function browse($iSurveyID)
{
foreach ($fuqtquestions as $fieldname)
{
$phparray = json_decode($json[$fieldname]);
$phparray = json_decode_ls($json[$fieldname]);
foreach ($phparray as $metadata)
{
$path = Yii::app()->getConfig('uploaddir') . "/surveys/" . $iSurveyID . "/files/";
Expand Down Expand Up @@ -384,7 +385,7 @@ function browse($iSurveyID)
{
foreach ($fuqtquestions as $fieldname)
{
$phparray = json_decode($json[$fieldname]);
$phparray = json_decode_ls($json[$fieldname]);
foreach ($phparray as $metadata)
{
$path = $this->getController()->getConfig('uploaddir') . "/surveys/{$iSurveyID}/files/";
Expand Down Expand Up @@ -421,7 +422,7 @@ function browse($iSurveyID)
$fieldname = Yii::app()->request->getPost('fieldname');

$row = Survey_dynamic::model($iSurveyID)->findByAttributes(array('id' => $iId));
$phparray = json_decode(reset($row));
$phparray = json_decode_ls(reset($row));

for ($i = 0; $i < count($phparray); $i++)
{
Expand Down Expand Up @@ -864,7 +865,7 @@ private function _zipFiles($iSurveyID, $responseIds, $zipfilename)
{
foreach ($metadata as $aData)
{
$phparray = json_decode($aData, true);
$phparray = json_decode_ls($aData);
if (is_array($phparray))
{
foreach ($phparray as $file)
Expand Down
18 changes: 18 additions & 0 deletions application/helpers/common_helper.php
Expand Up @@ -7633,6 +7633,24 @@ function ls_json_encode($content)
return $ans;
}

/**
* Decode a json string, sometimes needs stripslashes
*
* @param type $jsonString
* @return type
*/
function json_decode_ls($jsonString)
{
$decoded = json_decode($jsonString, true);

if (json_last_error() === JSON_ERROR_SYNTAX) {
// probably we need stipslahes
$decoded = json_decode(stripslashes($jsonString), true);
}

return $decoded;
}

/**
* Swaps two positions in an array
*
Expand Down
2 changes: 1 addition & 1 deletion application/views/admin/responses/browseallrow_view.php
Expand Up @@ -44,7 +44,7 @@
{
$index = $fnames[$i]['index'];
$metadata = $fnames[$i]['metadata'];
$phparray = json_decode($dtrow[$fnames[$i][0]], true);
$phparray = json_decode_ls($dtrow[$fnames[$i][0]], true);
if (isset($phparray[$index]))
{
if ($metadata === "size")
Expand Down

0 comments on commit 5614cbb

Please sign in to comment.