From 602314757f5334c8126a5a1715e02977c7ae97f8 Mon Sep 17 00:00:00 2001 From: Denis Chenu Date: Mon, 8 May 2023 11:41:00 +0200 Subject: [PATCH] Fixed issue #18634: Export single selected response can export a empty 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 --- application/controllers/admin/export.php | 2 +- application/controllers/admin/responses.php | 19 -------------- .../admin/grid/MassiveActionsWidget/README.md | 5 +++- .../assets/listActions.js | 4 +-- .../exportresult_panels/_single-value.php | 11 +++----- .../views/admin/export/exportresults_view.php | 5 ++-- .../responses/massive_actions/_selector.php | 26 +++++++++---------- 7 files changed, 25 insertions(+), 47 deletions(-) diff --git a/application/controllers/admin/export.php b/application/controllers/admin/export.php index 2be26c9664b..e2f3dbe8284 100644 --- a/application/controllers/admin/export.php +++ b/application/controllers/admin/export.php @@ -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; diff --git a/application/controllers/admin/responses.php b/application/controllers/admin/responses.php index cad9ff1da8d..3cd806cebb6 100644 --- a/application/controllers/admin/responses.php +++ b/application/controllers/admin/responses.php @@ -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 * diff --git a/application/extensions/admin/grid/MassiveActionsWidget/README.md b/application/extensions/admin/grid/MassiveActionsWidget/README.md index 1049459f71b..10bc142c9d9 100644 --- a/application/extensions/admin/grid/MassiveActionsWidget/README.md +++ b/application/extensions/admin/grid/MassiveActionsWidget/README.md @@ -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. diff --git a/application/extensions/admin/grid/MassiveActionsWidget/assets/listActions.js b/application/extensions/admin/grid/MassiveActionsWidget/assets/listActions.js index 9d83436a802..0d4a66dda53 100644 --- a/application/extensions/admin/grid/MassiveActionsWidget/assets/listActions.js +++ b/application/extensions/admin/grid/MassiveActionsWidget/assets/listActions.js @@ -47,11 +47,11 @@ var onClickListAction = function () { $oCheckedItems = $gridid.yiiGridView('getChecked', $('.listActions').data('pk')); // So we can join var newForm = jQuery('
', { 'action': $actionUrl, - 'target': '_blank', + 'target': $that.data('target') ?? '_blank', 'method': 'POST' }).append(jQuery('', { 'name': $that.data('input-name'), - 'value': $oCheckedItems.join("|"), + 'value': $oCheckedItems.join($that.data('input-separator') ?? '|'), 'type': 'hidden' })).append(jQuery('', { 'name': LS.data.csrfTokenName, diff --git a/application/views/admin/export/exportresult_panels/_single-value.php b/application/views/admin/export/exportresult_panels/_single-value.php index f2fa12e9e70..f7ca74477e7 100644 --- a/application/views/admin/export/exportresult_panels/_single-value.php +++ b/application/views/admin/export/exportresult_panels/_single-value.php @@ -1,9 +1,5 @@ session['responsesid']); - foreach($aResponsesId as $aResponseId){ - $sResponsesId .= $aResponseId.', '; - } + $sResponsesId = App()->getRequest()->getParam('responseIds'); ?> diff --git a/application/views/admin/export/exportresults_view.php b/application/views/admin/export/exportresults_view.php index b0367e690f7..d4c11df8c02 100644 --- a/application/views/admin/export/exportresults_view.php +++ b/application/views/admin/export/exportresults_view.php @@ -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); } ?> @@ -32,8 +32,7 @@
renderPartial('/admin/export/exportresult_panels/_format', ['exports' => $exports,'defaultexport' => $defaultexport,'aCsvFieldSeparator' => $aCsvFieldSeparator ]); ?> renderPartial('/admin/export/exportresult_panels/_general', [ 'selecthide' => $selecthide, 'selectshow' => $selectshow, 'selectinc' => $selectinc, 'aLanguages' => $aLanguages]); ?> - - session['responsesid'])): // If called from massive action, it will be filled the selected answers ?> + getRequest()->getParam('responseIds'))): // If called from massive action, it will be filled the selected answers ?> renderPartial('/admin/export/exportresult_panels/_range', ['SingleResponse' => $SingleResponse, 'min_datasets' => $min_datasets, 'max_datasets' => $max_datasets]); ?> renderPartial('/admin/export/exportresult_panels/_single-value', ['SingleResponse' => $SingleResponse, 'surveyid' => $surveyid]); ?> diff --git a/application/views/admin/responses/massive_actions/_selector.php b/application/views/admin/responses/massive_actions/_selector.php index 07655f00224..9889ccd95db 100644 --- a/application/views/admin/responses/massive_actions/_selector.php +++ b/application/views/admin/responses/massive_actions/_selector.php @@ -9,13 +9,14 @@ 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', @@ -29,7 +30,7 @@ . '
' . 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), ), ); @@ -37,7 +38,7 @@ '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', @@ -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', @@ -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', ); }