Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed issue #18635: Export single response can goes to a white page #2923

Merged
merged 3 commits into from May 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 0 additions & 15 deletions application/controllers/ResponsesController.php
Expand Up @@ -912,21 +912,6 @@ public function actionTime(int $surveyId): void
]);
}

/**
* Responsible for setting the session variables for attribute map page redirect
* @param bool $unset
* @param int|null $surveyId
*/
public function actionSetSession(bool $unset = false, int $surveyId = null): void
{
unset(App()->session['responsesid']);
if (!$unset) {
App()->session['responsesid'] = App()->request->getPost('itemsid');
} else {
$this->redirect(["admin/export", "sa" => "exportresults", "surveyid" => $surveyId]);
}
}

/**
* Change the value of the max characters to elipsize headers/questions in response grid.
* It's called via ajax request
Expand Down
5 changes: 2 additions & 3 deletions application/controllers/admin/Export.php
Expand Up @@ -136,7 +136,7 @@ public function question()
*/
public function exportresults()
{
$iSurveyID = sanitize_int(Yii::app()->request->getParam('surveyid')) ??
$iSurveyID = sanitize_int(App()->request->getParam('surveyid')) ??
sanitize_int(Yii::app()->request->getParam('surveyId'));
$survey = Survey::model()->findByPk($iSurveyID);

Expand Down Expand Up @@ -217,7 +217,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 Expand Up @@ -347,7 +347,6 @@ public function exportresults()
} else {
$sFilter = '';
}

viewHelper::disableHtmlLogging();
$resultsService->exportResponses($iSurveyID, $explang, $sExportType, $options, $sFilter);

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 @@ -28,7 +28,6 @@ var onClickListAction = function () {
$oCheckedItems = JSON.stringify($oCheckedItems);
var actionType = $that.data('actionType');
var selectedList = $(".selected-items-list");

if ($oCheckedItems == '[]') {
//If no item selected, the error modal "please select first an item" is shown
// TODO: add a variable in the widget to replace "item" by the item type (e.g: survey, question, token, etc.)
Expand All @@ -48,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,20 @@
</label>

<div class="col-sm-6">
<input type="text" readonly value="<?php echo $sResponsesId; ?>" class="form-control" name="responses_id" id="responses_id" />
<input
name="responses_id" id="responses_id"
type="text" readonly class="form-control"
value="<?= Chtml::encode($sResponsesId); ?>"
/>
</div>
<div class="col-sm-2">
<a class="btn btn-default" href="<?php echo Yii::app()->getController()->createUrl("responses/setSession/", ['unset' => 'true', 'surveyId' => $surveyid]); ?>" role="button">
<a
href="<?php echo Yii::app()->getController()->createUrl("admin/export/sa/exportresults", array('surveyid'=>$surveyid)); ?>"
class="btn btn-default" 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>
7 changes: 3 additions & 4 deletions application/views/admin/export/exportresults_view.php
Expand Up @@ -22,7 +22,7 @@
<h4>
<?php eT("Export results"); ?>
<?php
if (isset($_POST['sql'])) {
if (App()->getRequest()->getPost('sql')) {
echo " - " . gT("Filtered from statistics script");
}
if ($SingleResponse) {
Expand All @@ -42,10 +42,9 @@
<?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'))) : ?>
<?php $this->renderPartial('/admin/export/exportresult_panels/_range', ['SingleResponse' => $SingleResponse, 'min_datasets' => $min_datasets, 'max_datasets' => $max_datasets]); ?>
<?php else : ?>
<?php else : // call by massive action (for example) ?>
<?php $this->renderPartial('/admin/export/exportresult_panels/_single-value', ['SingleResponse' => $SingleResponse, 'surveyid' => $surveyid]); ?>
<?php endif; ?>

Expand Down
26 changes: 13 additions & 13 deletions application/views/responses/massive_actions/_selector.php
Expand Up @@ -9,13 +9,14 @@
<!-- Rendering massive action widget -->
<?php
$buttons = [];
if (Permission::model()->hasSurveyPermission($_GET['surveyId'], 'responses', 'delete')) {
$surveyId = intval(App()->getRequest()->getQuery('surveyId'));
if (Permission::model()->hasSurveyPermission($surveyId, 'responses', 'delete')) {
// Delete
$buttons[] = [
// li element
'type' => 'action',
'action' => 'delete',
'url' => App()->createUrl("responses/delete/", ['surveyId' => $_GET['surveyId']]),
'url' => App()->createUrl("responses/delete/", ['surveyId' => $surveyId]),
'iconClasses' => 'fa fa-trash text-danger',
'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' => [
['name' =>'sid', 'value' => $_GET['surveyId']],
['name' =>'sid', 'value' => $surveyId],
],
];

$buttons[] = [
'type' => 'action',
'action' => 'deleteAttachments',
//'url' => App()->createUrl("admin/responses", array("sa"=>"actionDeleteAttachments")),
'url' => App()->createUrl("responses/deleteAttachments/", ["surveyId" => $_GET['surveyId']]),
'url' => App()->createUrl("responses/deleteAttachments/", ["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' => [
['name' =>'sid', 'value' => $_GET['surveyId']],
['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[] = [
'type' => 'action',
'action' => 'downloadZip',
'url' => App()->createUrl('responses/downloadfiles/', ['surveyId' => $_GET['surveyId'], 'responseIds' => '']),
'url' => App()->createUrl('responses/downloadfiles/', ['surveyId' => $surveyId, 'responseIds' => '']),
'iconClasses' => 'fa fa-download test',
'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' => [
'input-name' => 'tokenids',
'input-name' => 'responseIds',
'input-separator' => ',',
'target' => '_self',
],

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

Expand Down