diff --git a/application/controllers/admin/saved.php b/application/controllers/admin/saved.php index 554d2c7da21..948ad6decdf 100644 --- a/application/controllers/admin/saved.php +++ b/application/controllers/admin/saved.php @@ -3,7 +3,7 @@ } /* * LimeSurvey - * Copyright (C) 2007-2011 The LimeSurvey Project Team / Carsten Schmitz + * Copyright (C) 2007-2019 The LimeSurvey Project Team / Carsten Schmitz * All rights reserved. * License: GNU/GPL License v2 or later, see LICENSE.php * LimeSurvey is free software. This version may have been modified pursuant @@ -24,41 +24,79 @@ class saved extends Survey_Common_Action { + /** + * Show the list of save response + * @param int $surveyid + * @return void + * @throw Exception + */ public function view($iSurveyId) { $iSurveyId = sanitize_int($iSurveyId); $aViewUrls = array(); if (!Permission::model()->hasSurveyPermission($iSurveyId, 'responses', 'read')) { - die(); + throw new CHttpException(403, gT("You do not have permission to access this page.")); } $aThisSurvey = getSurveyInfo($iSurveyId); $aData['sSurveyName'] = $aThisSurvey['name']; $aData['iSurveyId'] = $iSurveyId; - $aViewUrls[] = 'savedbar_view'; - $aViewUrls['savedlist_view'][] = $this->_showSavedList($iSurveyId); - - // saved.js bugs if table is empty - if (count($aViewUrls['savedlist_view'][0]['aResults'])) { - App()->getClientScript()->registerPackage('jquery-tablesorter'); - App()->getClientScript()->registerScriptFile(App()->getConfig('adminscripts').'saved.js'); - } - - + $aData['dataProvider'] = new CActiveDataProvider('SavedControl', array( + 'criteria'=>array( + 'condition'=>'sid=:sid', + 'params'=>[':sid'=>$iSurveyId], + ), + 'countCriteria'=>array( + 'condition'=>'sid=:sid', + 'params'=>[':sid'=>$iSurveyId], + ), + )); + $aData['SavedControlModel'] = SavedControl::model(); + $aViewUrls[] = 'savedlist_view'; $this->_renderWrappedTemplate('saved', $aViewUrls, $aData); } /** * Function responsible to delete saved responses. + * @param int $surveyid + * @return void + * @throw Exception */ - public function delete($iSurveyId, $iSurveyResponseId, $iSavedControlId) + public function actionDelete($surveyid) { - $survey = Survey::model()->findByPk($iSurveyId); - SavedControl::model()->deleteAllByAttributes(array('scid' => $iSavedControlId, 'sid' => $iSurveyId)) or die(gT("Couldn't delete")); - Yii::app()->db->createCommand()->delete($survey->responsesTableName, 'id=:id', array('id' => $iSurveyResponseId)) or die(gT("Couldn't delete")); + if(!Permission::model()->hasSurveyPermission($surveyid, 'responses', 'delete')) { + throw new CHttpException(403, gT("You do not have permission to access this page.")); + } + if(!Yii::app()->getRequest()->isPostRequest) { + throw new CHttpException(405, gT("Invalid action")); + } + Yii::import('application.helpers.admin.ajax_helper', true); - $this->getController()->redirect(array("admin/saved/sa/view/surveyid/{$iSurveyId}")); + $iScid = App()->getRequest()->getParam('scid'); + $oSavedControl = SavedControl::model()->find('scid = :scid',array(':scid'=>$iScid)); + if(empty($oSavedControl)) { + throw new CHttpException(401, gT("Saved response not found")); + } + if($oSavedControl->delete()) { + $oReponse = Response::model($surveyid)->findByPk($oSavedControl->srid); + if($oReponse) { + $oReponse->delete(); + } + } else { + if(Yii::app()->getRequest()->isAjaxRequest) { + ls\ajax\AjaxHelper::outputError(gT('Unable to delete saved response.')); + Yii::app()->end(); + } + Yii::app()->setFlashMessage(gT('Unable to delete saved response.'),'danger'); + $this->getController()->redirect(array("admin/saved/sa/view/surveyid/{$surveyid}")); + } + if(Yii::app()->getRequest()->isAjaxRequest) { + ls\ajax\AjaxHelper::outputSuccess(gT('Saved response deleted.')); + Yii::app()->end(); + } + Yii::app()->setFlashMessage(gT('Saved response deleted.'),'success'); + $this->getController()->redirect(array("admin/saved/sa/view/surveyid/{$surveyid}")); } /** @@ -79,25 +117,4 @@ protected function _renderWrappedTemplate($sAction = 'saved', $aViewUrls = array $aData['menu']['edition'] = false; parent::_renderWrappedTemplate($sAction, $aViewUrls, $aData, $sRenderFile); } - - /** - * Load saved list. - * @param mixed $iSurveyId Survey id - * @return array - */ - private function _showSavedList($iSurveyId) - { - $aResults = SavedControl::model()->findAll(array( - 'select' => array('scid', 'srid', 'identifier', 'ip', 'saved_date', 'email', 'access_code'), - 'condition' => 'sid=:sid', - 'order' => 'saved_date desc', - 'params' => array(':sid' => $iSurveyId), - )); - - if (!empty($aResults)) { - return compact('aResults'); - } else - {return array('aResults'=>array()); } - } - } diff --git a/application/models/SavedControl.php b/application/models/SavedControl.php index 4cf985cd7c6..93cc96f7f14 100644 --- a/application/models/SavedControl.php +++ b/application/models/SavedControl.php @@ -102,4 +102,33 @@ public function insertRecords($data) return $this->db->insert('saved_control', $data); } + public function getGridButtons($surveyid) + { + $gridButtons = array(); + $gridButtons['editresponse'] = array( + 'label'=>''.gT("Edit").'', + 'imageUrl'=>false, + 'url' => 'App()->createUrl("admin/dataentry/sa/editdata/subaction/edit",array("surveyid"=>$data->sid,"id"=>$data->srid));', + 'options' => array( + 'class'=>"btn btn-default btn-xs btn-edit", + 'data-toggle'=>"tooltip", + 'title'=>gT("Edit response") + ), + 'visible'=> 'boolval('.Permission::model()->hasSurveyPermission($surveyid, 'responses', 'update').')', + ); + $gridButtons['delete'] = array( + 'label'=>''.gT("Delete").'', + 'imageUrl'=>false, + 'icon'=>false, + 'url' => 'App()->createUrl("admin/saved/sa/actionDelete",array("surveyid"=>$data->sid,"scid"=>$data->scid,"srid"=>$data->srid));', + 'options' => array( + 'class'=>"btn btn-default btn-xs btn-delete", + 'data-toggle'=>"tooltip", + 'title'=>gT("Delete this entry and related response") + ), + 'visible'=> 'boolval('.Permission::model()->hasSurveyPermission($surveyid, 'responses', 'delete').')', + 'click' => 'function(event){ window.LS.gridButton.confirmGridAction(event,$(this)); }', + ); + return $gridButtons; + } } diff --git a/application/views/admin/saved/savedlist_view.php b/application/views/admin/saved/savedlist_view.php index 9a2581e7563..c8509b0c10c 100644 --- a/application/views/admin/saved/savedlist_view.php +++ b/application/views/admin/saved/savedlist_view.php @@ -1,54 +1,49 @@

- - + +

- - -

- - - - - - - - - - - - - - - - - - - - - - - - - - -
scid; ?> - - hasSurveyPermission($iSurveyId,'responses','update')) - { ?> - srid}"); ?>', '_top')" title='' class="fa fa-pencil text-success"> - hasSurveyPermission($iSurveyId,'responses','delete')) - { ?> - ' onclick="if (confirm('')) { window.open('createUrl("admin/saved/delete/surveyid/{$iSurveyId}/srid/{$oResult->srid}/scid/{$oResult->scid}"); ?>', '_top'); }" > - - identifier); ?>ip; ?>saved_date; ?>email),'mailto:'.htmlspecialchars($oResult->email)); ?>
-
  -

-
+widget('ext.LimeGridView.LimeGridView', array( + 'id' => 'saved-grid', + 'ajaxUpdate' => 'saved-grid', + 'dataProvider' => $dataProvider, + 'ajaxType' => 'POST', + 'template' => "{items}\n
{pager}
{summary}
", + 'columns' => array( + array( + 'header' => gT("ID"), + 'name' => 'scid', + ), + array( + 'class'=>'bootstrap.widgets.TbButtonColumn', + 'template'=>'{editresponse}{delete}', + //~ 'htmlOptions' => array('class' => 'text-left response-buttons'), + 'buttons'=> $SavedControlModel->getGridButtons($iSurveyId), + ), + array( + 'header' => gT("Identifier"), + 'name' => 'identifier', + ), + array( + 'header' => gT("IP address"), + 'name' => 'ip', + ), + array( + 'header' => gT("Date saved"), + 'name' => 'saved_date', + ), + array( + 'header' => gT("Email address"), + 'name' => 'email', + ), + ), + ), + ); +?> + + + diff --git a/assets/scripts/admin/saved.js b/assets/scripts/admin/saved.js deleted file mode 100644 index ca3c41843e6..00000000000 --- a/assets/scripts/admin/saved.js +++ /dev/null @@ -1,10 +0,0 @@ -// $Id: saved.js 9330 2010-10-24 22:23:56Z c_schmitz $ -var LS = LS || { - onDocumentReady: {} -}; - -$(document).on('ready pjax:scriptcomplete', function(){ - $(".browsetable").tablesorter({ - widgets: ['zebra'], - sortList: [[0,0]] }); -});