Skip to content

Commit

Permalink
Fixed issue #18634: Export single selected response can export a empt…
Browse files Browse the repository at this point in the history
…y line (#2909)

* Fixed issue #18634: Export single selected response can export a empty line
Dev: id set in url, resonseId in POST (by session)
Dev: remove session usage
Dev: can move to window-location-href, but ready for POST

* Dev: separator to ,

* Dev: oups, lost the allow separator in widget

* Dev: Fixed new tab opens
  • Loading branch information
Shnoulle committed May 8, 2023
1 parent ebb447a commit 6023147
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 47 deletions.
2 changes: 1 addition & 1 deletion application/controllers/admin/export.php
Expand Up @@ -199,7 +199,7 @@ public function exportresults()
$aFieldsOptions[$sFieldName] = array('title'=>viewHelper::getFieldText($fieldinfo), 'data-fieldname'=>$fieldinfo['fieldname'], 'data-emcode'=>viewHelper::getFieldCode($fieldinfo, array('LEMcompat'=>true))); // No need to filter title : Yii do it (remove all tag)
}

$data['SingleResponse'] = (int) returnGlobal('id');
$data['SingleResponse'] = intval(App()->getRequest()->getParam('id'));
$data['selecthide'] = $selecthide;
$data['selectshow'] = $selectshow;
$data['selectinc'] = $selectinc;
Expand Down
19 changes: 0 additions & 19 deletions application/controllers/admin/responses.php
Expand Up @@ -1067,25 +1067,6 @@ private function _zipFiles($iSurveyID, $responseIds, $zipfilename)
$this->getController()->redirect(array("admin/responses", "sa" => "browse", "surveyid" => $iSurveyID));
}



/**
* Responsible for setting the session variables for attribute map page redirect
* @todo Use user session?
* @todo Used?
*/
public function setSession($unset = false, $sid = null)
{
if (!$unset) {
unset(Yii::app()->session['responsesid']);
Yii::app()->session['responsesid'] = Yii::app()->request->getPost('itemsid');
} else {
unset(Yii::app()->session['responsesid']);
$this->getController()->redirect(array("admin/export", "sa"=>"exportresults", "surveyid"=>$sid));
}

}

/**
* Renders template(s) wrapped in header and footer
*
Expand Down
Expand Up @@ -85,7 +85,10 @@ The link, to be defined, need:

There is currently 3 action types (they are the result of the refactorisation of the old jQgrid massive actions) :

- **redirect** : when clicking on the action link, user will be redirected to the wanted url in a blank windows. The list of the checked items will be posted in a string separated by |. This is used only for tokens right now (send email...).
- **redirect** : when clicking on the action link, user will be redirected to the wanted url in a blank windows. The list of the checked items will be posted in a string separated by `|` (by default). This is used only for tokens right now (send email...), extra parameters in data of the link :
- `input-name` : name of the input created
- `input-separator` : separator used to separate checked item (defult to `|`)
- `target` : target set of the action : default `_blanck`, use `_self` to use current windows
- **fill-session-and-redirect** : basically the same than redirect, but calling first an action on a controller to fill the session with the checked items before redirecting. This is used only for tokens "add participant to CPDB" for now.
- **modal** : This is the most used case. It raises a modal to first confirm the action, then submit an ajax request to the defined url, and closes it OR shows an array of results.

Expand Down
Expand Up @@ -47,11 +47,11 @@ var onClickListAction = function () {
$oCheckedItems = $gridid.yiiGridView('getChecked', $('.listActions').data('pk')); // So we can join
var newForm = jQuery('<form>', {
'action': $actionUrl,
'target': '_blank',
'target': $that.data('target') ?? '_blank',
'method': 'POST'
}).append(jQuery('<input>', {
'name': $that.data('input-name'),
'value': $oCheckedItems.join("|"),
'value': $oCheckedItems.join($that.data('input-separator') ?? '|'),
'type': 'hidden'
})).append(jQuery('<input>', {
'name': LS.data.csrfTokenName,
Expand Down
@@ -1,9 +1,5 @@
<?php
$sResponsesId = '';
$aResponsesId = json_decode(Yii::app()->session['responsesid']);
foreach($aResponsesId as $aResponseId){
$sResponsesId .= $aResponseId.', ';
}
$sResponsesId = App()->getRequest()->getParam('responseIds');
?>

<div class="panel panel-primary" id="panel-2" <?php if ($SingleResponse) { echo 'style="display:none"';} ?> >
Expand All @@ -20,14 +16,13 @@
</label>

<div class="col-sm-6">
<input type="text" readonly value="<?php echo $sResponsesId; ?>" class="form-control" name="responses_id" id="responses_id" />
<input type="text" readonly value="<?php echo Chtml::encode($sResponsesId); ?>" class="form-control" name="responses_id" id="responses_id" />
</div>
<div class="col-sm-2">
<a class="btn btn-default" href="<?php echo Yii::app()->getController()->createUrl("admin/responses/sa/setSession/", array('unset'=>'true', 'sid'=>$surveyid)); ?>" role="button">
<a class="btn btn-default" href="<?php echo Yii::app()->getController()->createUrl("admin/export/sa/exportresults", array('surveyid'=>$surveyid)); ?>" role="button">
<?php eT("Reset");?>
</a>
</div>
<input type="hidden" value='<?php echo json_encode($aResponsesId); ?>' name="export_ids" id="export_ids" />
</div>
</div>
</div>
5 changes: 2 additions & 3 deletions application/views/admin/export/exportresults_view.php
Expand Up @@ -20,7 +20,7 @@
if (isset($_POST['sql'])) {echo" - ".gT("Filtered from statistics script");}
if ($SingleResponse)
{
echo " - ".sprintf(gT("Single response: ID %s"),$SingleResponse);
echo " - ".sprintf(gT("Single response: ID %s"), $SingleResponse);
}
?>
</h3>
Expand All @@ -32,8 +32,7 @@
<div class="col-sm-12 col-md-6">
<?php $this->renderPartial('/admin/export/exportresult_panels/_format', ['exports' => $exports,'defaultexport' => $defaultexport,'aCsvFieldSeparator' => $aCsvFieldSeparator ]); ?>
<?php $this->renderPartial('/admin/export/exportresult_panels/_general', [ 'selecthide' => $selecthide, 'selectshow' => $selectshow, 'selectinc' => $selectinc, 'aLanguages' => $aLanguages]); ?>

<?php if (empty(Yii::app()->session['responsesid'])): // If called from massive action, it will be filled the selected answers ?>
<?php if (empty(App()->getRequest()->getParam('responseIds'))): // If called from massive action, it will be filled the selected answers ?>
<?php $this->renderPartial('/admin/export/exportresult_panels/_range', ['SingleResponse' => $SingleResponse, 'min_datasets' => $min_datasets, 'max_datasets' => $max_datasets]); ?>
<?php else: ?>
<?php $this->renderPartial('/admin/export/exportresult_panels/_single-value', ['SingleResponse' => $SingleResponse, 'surveyid' => $surveyid]); ?>
Expand Down
26 changes: 13 additions & 13 deletions application/views/admin/responses/massive_actions/_selector.php
Expand Up @@ -9,13 +9,14 @@
<!-- Rendering massive action widget -->
<?php
$buttons = array();
if (Permission::model()->hasSurveyPermission($_GET['surveyid'], 'responses','delete')) {
$surveyId = intval(App()->getRequest()->getQuery('surveyid'));
if (Permission::model()->hasSurveyPermission($surveyId, 'responses','delete')) {
// Delete
$buttons[] = array(
// li element
'type' => 'action',
'action' => 'delete',
'url' => App()->createUrl('/admin/responses/sa/actionDelete/surveyid/'.$_GET['surveyid']),
'url' => App()->createUrl('/admin/responses/sa/actionDelete/surveyid/'.$surveyId),
'iconClasses' => 'text-danger fa fa-trash',
'text' => gT('Delete'),
'grid-reload' => 'yes',
Expand All @@ -29,15 +30,15 @@
. '<br/>'
. gT('Please note that if you delete an incomplete response during a running survey, the participant will not be able to complete it.'),
'aCustomDatas' => array(
array( 'name'=>'sid', 'value'=> $_GET['surveyid']),
array( 'name'=>'sid', 'value'=> $surveyId),
),
);

$buttons[] = array(
'type' => 'action',
'action' => 'deleteAttachments',
//'url' => App()->createUrl("admin/responses", array("sa"=>"actionDeleteAttachments")),
'url' => App()->createUrl("/admin/responses/sa/actionDeleteAttachments/", array("surveyid" => $_GET['surveyid'] )),
'url' => App()->createUrl("/admin/responses/sa/actionDeleteAttachments/", array("surveyid" => $surveyId )),
'iconClasses' => 'text-danger fa fa-paperclip',
'text' => gT('Delete attachments'),
'grid-reload' => 'yes',
Expand All @@ -49,17 +50,17 @@
'sModalTitle' => gT('Delete attachments'),
'htmlModalBody' => gT('Are you sure you want to delete all uploaded files from the selected responses?'),
'aCustomDatas' => array(
array( 'name'=>'sid', 'value'=> $_GET['surveyid']),
array( 'name'=>'sid', 'value'=> $surveyId),
),
);
}

if (Permission::model()->hasSurveyPermission($_GET['surveyid'], 'responses', 'read')) {
if (Permission::model()->hasSurveyPermission($surveyId, 'responses', 'read')) {
// Download ZIP archive of file upload question types
$buttons[] = array(
'type' => 'action',
'action' => 'downloadZip',
'url' => App()->createUrl('/admin/responses/sa/actionDownloadfiles/iSurveyId/' . $_GET['surveyid']) . '/sResponseId/',
'url' => App()->createUrl('/admin/responses/sa/actionDownloadfiles/iSurveyId/' . $surveyId) . '/sResponseId/',
'iconClasses' => 'fa fa-download',
'text' => gT('Download files'),
'grid-reload' => 'no',
Expand All @@ -73,16 +74,15 @@
// li element
'type' => 'action',
'action' => 'export',
'url' => App()->createUrl('admin/export/sa/exportresults/surveyid/'.$_GET['surveyid']),
'url' => App()->createUrl('admin/export/sa/exportresults/surveyid/'.$surveyId),
'iconClasses' => 'fa fa-upload',
'text' => gT('Export'),

'aLinkSpecificDatas' => array(
'input-name' => 'tokenids',
'input-name' => 'responseIds',
'input-separator' => ',',
'target' => '_self',
),

// modal
'actionType' => 'fill-session-and-redirect',
'actionType' => 'redirect',
);

}
Expand Down

0 comments on commit 6023147

Please sign in to comment.