Skip to content

Commit

Permalink
Remote Control: process Survey files on add_response()
Browse files Browse the repository at this point in the history
If the response data has fields for file attachments, move those files
to the final upload folder.
  • Loading branch information
pardo-bsso committed Jul 25, 2017
1 parent 8a45bd9 commit 57b626c
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions application/helpers/remotecontrol/remotecontrol_handle.php
Expand Up @@ -2491,7 +2491,29 @@ public function add_response($sSessionKey, $iSurveyID, $aResponseData)
$result_id = $survey_dynamic->insertRecords($aResponseData);

if ($result_id)
{
$oResponse = Response::model($iSurveyID)->findByAttributes(array('token' => $sToken, 'id' => $result_id));
foreach ($oResponse->getFiles() as $aFile)
{
$sUploadPath = Yii::app()->getConfig('uploaddir') . "/surveys/" . $iSurveyID . "/files/";
$sFileRealName = Yii::app()->getConfig('uploaddir') . "/surveys/" . $iSurveyID . "/files/" . $aFile['filename'];
$sFileTempName = Yii::app()->getConfig('tempdir') . "/upload/" . $aFile['filename'];

if (!file_exists($sFileRealName))
{
if (!is_dir($sUploadPath))
{
mkdir($sUploadPath, 0777, true);
}
if (!rename($sFileTempName, $sFileRealName))
{
return array('status' => 'Unable to move files ' . $sFileTmpName . ' ' . $sFileRealName);
}
}

}
return $result_id;
}
else
return array('status' => 'Unable to add response');
}
Expand Down

0 comments on commit 57b626c

Please sign in to comment.