Skip to content

Commit

Permalink
Fixed issue #6742: File upload question: individual download of uploa…
Browse files Browse the repository at this point in the history
…ded files not working
  • Loading branch information
c-schmitz committed Oct 22, 2012
1 parent 0e416bb commit 8b833c6
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 30 deletions.
10 changes: 5 additions & 5 deletions application/controllers/admin/responses.php
Expand Up @@ -371,20 +371,20 @@ function browse($iSurveyID)
$downloadindividualfile = Yii::app()->request->getPost('downloadindividualfile');
$fieldname = Yii::app()->request->getPost('fieldname');

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

for ($i = 0; $i < count($phparray); $i++)
{
if ($phparray[$i]->name == $downloadindividualfile)
if ($phparray[$i]['name'] == $downloadindividualfile)
{
$file = Yii::app()->getConfig('uploaddir') . "/surveys/" . $iSurveyID . "/files/" . $phparray[$i]->filename;
$file = Yii::app()->getConfig('uploaddir') . "/surveys/" . $iSurveyID . "/files/" . $phparray[$i]['filename'];

if (file_exists($file))
{
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="' . rawurldecode($phparray[$i]->name) . '"');
header('Content-Disposition: attachment; filename="' . rawurldecode($phparray[$i]['name']) . '"');
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
Expand Down
59 changes: 34 additions & 25 deletions scripts/admin/browse.js
Expand Up @@ -32,7 +32,7 @@ $(document).ready(function(){
color: '#EADF95'}
},
position: { adjust: {
screen: true, scroll:true },
screen: true, scroll:true },
corner: {
target: 'bottomMiddle',
tooltip: 'topMiddle'}
Expand Down Expand Up @@ -89,7 +89,7 @@ $(document).ready(function(){
thisid=removechars($(this).attr('id'));
answer = confirm(strdeleteconfirm);
if (answer==true)
{
{
$('#deleteanswer').val(thisid);
$('.cbResponseMarker').attr('checked',false);
$('#resulttableform').submit();
Expand All @@ -98,11 +98,11 @@ $(document).ready(function(){
// Delete all marked responses
$("#imgDeleteMarkedResponses").click(function(){
if ($('.cbResponseMarker:checked').size()>0)
{
{
thisid=removechars($(this).attr('id'));
answer = confirm(strDeleteAllConfirm);
if (answer==true)
{
{
$('#deleteanswer').val('marked');
$('#resulttableform').submit();
}
Expand All @@ -122,7 +122,7 @@ $(document).ready(function(){
// Download all marked files
$("#imgDownloadMarkedFiles").click(function() {
if ($('.cbResponseMarker:checked').size() > 0)
{
{
$('#downloadfile').val('marked');
$('#resulttableform').submit();
}
Expand Down Expand Up @@ -201,25 +201,23 @@ Send a post request to the server to download a file
@param data parameters for $_POST
*/
function sendPost(myaction, data)
function sendPost(myaction, checkcode, arrayparam, arrayval)
{
var myform = document.createElement('form');
document.body.appendChild(myform);
myform.action = myaction;
myform.action =myaction;
myform.method = 'POST';

for (var key in data) {
var myel = document.createElement('input');
myel.type = 'hidden';
myel.name = key;
myform.appendChild(myel);
myel.value = data[key];
for (i=0;i<arrayparam.length;i++)
{
addHiddenElement(myform,arrayparam[i],arrayval[i])
}

addHiddenElement(myform,'checksessionbypost',checkcode)
myform.submit();
}




/**
Dowload a file from a response
@param id ID of the response
Expand All @@ -228,12 +226,19 @@ Dowload a file from a response
*/
function getFile(id, field, filename)
{
sendPost(siteURL + "/admin/responses/" + surveyID + "/grid", {
'id': id,
'fieldname': field,
'oper': 'downloadfile',
'filename': filename
});
sendPost(siteURL + "/admin/responses/" + surveyID + "/grid",
new Array(
'id',
'fieldname',
'oper',
'filename'
),
new Array(
id,
field,
'downloadfile',
filename
));
}


Expand All @@ -243,9 +248,13 @@ Get an archive containing all the file from a response
*/
function getArchive(id)
{
sendPost(siteURL + "/admin/responses/" + surveyID + "/grid", {
'oper': 'downloadarchive',
'id': id
});
sendPost(siteURL + "/admin/responses/" + surveyID + "/grid",
new Array(
'oper',
'id'),
new Array(
'downloadarchive',
id)
);
}

0 comments on commit 8b833c6

Please sign in to comment.