Skip to content

Commit

Permalink
Fixed issue #09541: Unable to delete or download files from browse re…
Browse files Browse the repository at this point in the history
…sponse

Fixed issue : Response table don't take the selected language
Dev: Fixed whole : one responses and some responses
Dev: Use jqgrid editurl for some
Dev: actionDelete is public and allow param for response id, maybe fix it ?
  • Loading branch information
Shnoulle committed Mar 3, 2015
1 parent 8010262 commit 0f48238
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 192 deletions.
141 changes: 74 additions & 67 deletions application/controllers/admin/responses.php
Expand Up @@ -34,6 +34,11 @@
class responses extends Survey_Common_Action
{

/**
* @var string : Default layout is bare : temporary to real layout
*/
public $layout = 'bare';

function __construct($controller, $id)
{
parent::__construct($controller, $id);
Expand Down Expand Up @@ -105,7 +110,7 @@ public function view($iSurveyID, $iId, $sBrowseLang = '')
if(Permission::model()->hasSurveyPermission($iSurveyID,'responses','read'))
{
$aData = $this->_getData(array('iId' => $iId, 'iSurveyId' => $iSurveyID, 'browselang' => $sBrowseLang));
$oBrowseLanguage = $aData['language'];
$sBrowseLanguage = $aData['language'];

extract($aData);

Expand Down Expand Up @@ -253,7 +258,7 @@ public function view($iSurveyID, $iId, $sBrowseLang = '')
}
else
{
$answervalue = htmlspecialchars(strip_tags(stripJavaScript(getExtendedAnswer($iSurveyID, $fnames[$i][0], $iIdrow[$fnames[$i][0]], $oBrowseLanguage))), ENT_QUOTES);
$answervalue = htmlspecialchars(strip_tags(stripJavaScript(getExtendedAnswer($iSurveyID, $fnames[$i][0], $iIdrow[$fnames[$i][0]], $sBrowseLanguage))), ENT_QUOTES);
}
}
$aData['answervalue'] = $answervalue;
Expand Down Expand Up @@ -289,7 +294,7 @@ public function index($iSurveyID)
$aData = $this->_getData($iSurveyID);
extract($aData);
$aViewUrls = array();
$oBrowseLanguage = $aData['language'];
$sBrowseLanguage = $aData['language'];

/**
* fnames is used as informational array
Expand Down Expand Up @@ -333,7 +338,7 @@ function browse($iSurveyID)
$aData = $this->_getData($iSurveyID);
extract($aData);
$aViewUrls = array();
$oBrowseLanguage = $aData['language'];
$sBrowseLanguage = $aData['language'];
// Some specific column
$aSpecificColumns=array(
'submitdate', // Replaced by completed : TODO : add it if is a real date
Expand All @@ -350,6 +355,7 @@ function browse($iSurveyID)
'sorttype' => 'string',
'sortable' => false,
'width' => '100',
'resizable' => true,
'align' => 'left',
'label' => gt("Actions"),
'search' => false,
Expand All @@ -363,15 +369,18 @@ function browse($iSurveyID)
'sorttype'=>'integer',
'sortable'=>true,
'width'=>'100',
'resizable' => true,
'align'=>'center',
'title'=>viewHelper::getFieldText($fields['id']),
'hidedlg'=>true,
);
$column_model[] = array(
'name'=>'lastpage',
'index'=>'id',
'index'=>'lastpage',
'sorttype'=>'integer',
'sortable'=>true, 'width'=>'100',
'sortable'=>true,
'width'=>'100',
'resizable' => true,// Strangely : don't work
'align'=>'center',
'title'=>viewHelper::getFieldText($fields['lastpage']),
);
Expand Down Expand Up @@ -536,7 +545,8 @@ function browse($iSurveyID)
* Returns survey responses in json format for a given survey
*
* @access public
* @return void
* @param $iSurveyID : survey id
* @return json
*/
public function getResponses_json($iSurveyID)
{
Expand All @@ -548,8 +558,7 @@ public function getResponses_json($iSurveyID)
$bHaveToken=$aData['surveyinfo']['anonymized'] == "N" && tableExists('tokens_' . $iSurveyID) && Permission::model()->hasSurveyPermission($iSurveyID,'tokens','read');
extract($aData);
$aViewUrls = array();
$oBrowseLanguage = $aData['language'];

$sBrowseLanguage = $aData['language'];
$sImageURL = Yii::app()->getConfig('adminimageurl');

$fnames = array();
Expand Down Expand Up @@ -661,14 +670,13 @@ public function getResponses_json($iSurveyID)
if (hasFileUploadQuestion($surveyid)) {
$action_html .= "<a href='".Yii::app()->createUrl("admin/responses",array("sa"=>"downloadfiles","surveyid"=>$surveyid,"responseid"=>$row['id']))."'><img src='" . $sImageURL . "/down.png' alt='" . gT('Download all files in this response as a zip file') . "' class='downloadfile'/></a>";
}

if (Permission::model()->hasSurveyPermission($iSurveyID,'responses','delete')) {
$action_html .= "<a><img id='deleteresponse_" . $row['id'] . "' src='" . $sImageURL . "/token_delete.png' alt='" . gT('Delete this response') . "' class='deleteresponse'/></a>";
$action_html .= "<a href='".Yii::app()->createUrl("admin/responses",array("sa"=>"actionDelete","surveyid"=>$surveyid,"sResponseId"=>$row['id']))."' data-delete='".$row['id']."'><img src='" . $sImageURL . "/token_delete.png' alt='" . sprintf(gT('Delete response %s'),$row['id']) . "' class='deleteresponse'/></a>";
}

$aSurveyEntry = array();

$aSurveyEntry[] = '<!--a-->' . $action_html;
$aSurveyEntry[] = $action_html;

$aSurveyEntry[] = $row['id'];
$aSurveyEntry[] = $row['lastpage'];
Expand Down Expand Up @@ -696,7 +704,7 @@ public function getResponses_json($iSurveyID)
if(in_array($row_index,$aSpecificColumns))
continue;
// Alternative to striptag : use CHtmlPurifier : but CHtmlPurifier use a lot of memory
$aSurveyEntry[] = strip_tags(getExtendedAnswer($iSurveyID, $row_index, $row_value, $oBrowseLanguage)); // This fix XSS and get the value
$aSurveyEntry[] = strip_tags(getExtendedAnswer($iSurveyID, $row_index, $row_value, $sBrowseLanguage)); // This fix XSS and get the value
}
$all_rows[] = array('id' => $row['id'], 'cell' => $aSurveyEntry);
}
Expand All @@ -708,7 +716,14 @@ public function getResponses_json($iSurveyID)
Yii::app()->end();
}

function downloadfiles($iSurveyID)
/**
* Construct a zip files from a list of response
*
* @access public
* @param $iSurveyID : survey id
* @return application/zip
*/
public function downloadfiles($iSurveyID)
{
if(Permission::model()->hasSurveyPermission($iSurveyID,'responses','read'))
{
Expand Down Expand Up @@ -740,64 +755,56 @@ function downloadfiles($iSurveyID)
}
}

/**
* Do an actions on response
*
* @access public
* @param $iSurveyId : survey id
* @return void
*/
public function actionResponses($iSurveyId)
{
$action=Yii::app()->request->getPost('oper');
$sResponseId=Yii::app()->request->getPost('id');
switch ($action)
{
case 'del':
$this->actionDelete($iSurveyId,$sResponseId);
break;
default:
break;
}
}

/**
* Delete response
* Allow to delete directly : leave it ? Can take $sResponseId by POST
* @access public
* @param $iSurveyId : survey id
* @param $sResponseId : list of response
* @return void
*/
public function actionDelete($iSurveyId,$sResponseId)
{
if(Permission::model()->hasSurveyPermission($iSurveyId,'responses','delete'))
{
$oSurvey=Survey::model()->findByPk($iSurveyId);
//SurveyDynamic::model($iSurveyId)->deleteByPk($sResponseId);
Response::model($iSurveyId)->findByPk($sResponseId)->delete(true);
if($oSurvey->savetimings == "Y"){// TODO : add it to response delete (maybe test if timing table exist)
SurveyTimingDynamic::model($iSurveyID)->deleteByPk($iResponseID);
}
}
}
function oldbrowse($iSurveyID)
{
$aData = $this->_getData($iSurveyID);
extract($aData);
$aViewUrls = array();
$oBrowseLanguage = $aData['language'];
$sBrowseLanguage = $aData['language'];
$tokenRequest = Yii::app()->request->getParam('token', null);

//Delete Individual answer using inrow delete buttons/links - checked
if (Yii::app()->request->getPost('deleteanswer') && Yii::app()->request->getPost('deleteanswer') != '' && Yii::app()->request->getPost('deleteanswer') != 'marked')
{
if(Permission::model()->hasSurveyPermission($iSurveyID,'responses','delete'))
{
$iResponseID = (int) Yii::app()->request->getPost('deleteanswer'); // sanitize the value
Response::model($iSurveyID)->findByPk($iResponseID)->delete(true);
// delete timings if savetimings is set
if($aData['surveyinfo']['savetimings'] == "Y"){
SurveyTimingDynamic::model($iSurveyID)->deleteByPk($iResponseID);
}
Yii::app()->session['flashmessage'] = sprintf(gT("Response ID %s was successfully deleted."),$iResponseID);
}
else
{
Yii::app()->session['flashmessage'] = gT("Access denied!",'js');
}
}
// Marked responses -> deal with the whole batch of marked responses
if (Yii::app()->request->getPost('markedresponses') && count(Yii::app()->request->getPost('markedresponses')) > 0)
{
// Delete the marked responses - checked
if (Yii::app()->request->getPost('deleteanswer') && Yii::app()->request->getPost('deleteanswer') === 'marked')
{
if(Permission::model()->hasSurveyPermission($iSurveyID,'responses','delete'))
{
foreach (Response::model($iSurveyID)->findAllByPk(Yii::app()->request->getPost('markedresponses')) as $response)
{
$response->deleteFiles();
// delete timings if savetimings is set
/**
* @todo Move this to the Response model.
*/
if($aData['surveyinfo']['savetimings'] == "Y"){
SurveyTimingDynamic::model($iSurveyID)->deleteByPk($iResponseID);
}
}

Response::model($iSurveyID)->deleteByPk(Yii::app()->request->getPost('markedresponses'));


Yii::app()->session['flashmessage'] = sprintf(ngT("%s response was successfully deleted.|%s responses were successfully deleted.",count(Yii::app()->request->getPost('markedresponses'))),count(Yii::app()->request->getPost('markedresponses')),'js');
}
else
{
Yii::app()->session['flashmessage'] = gT("Access denied!",'js');
}
}
}
elseif (Yii::app()->request->getParam('downloadindividualfile') != '')
if (Yii::app()->request->getParam('downloadindividualfile') != '')
{
if(Permission::model()->hasSurveyPermission($iSurveyID,'responses','read'))
{
Expand All @@ -818,7 +825,7 @@ function oldbrowse($iSurveyID)
{
@ob_clean();
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Type: application/zip');
header('Content-Disposition: attachment; filename="' . rawurldecode($phparray[$i]['name']) . '"');
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
Expand Down Expand Up @@ -1002,7 +1009,7 @@ function oldbrowse($iSurveyID)
}
$aData['dtrow'] = $dtrow;
$aData['bgcc'] = $bgcc;
$aData['oBrowseLanguage']=$oBrowseLanguage;
$aData['sBrowseLanguage']=$sBrowseLanguage;
$aViewUrls['browseallrow_view'][] = $aData;
}

Expand Down
9 changes: 4 additions & 5 deletions application/views/admin/responses/listResponses_view.php
Expand Up @@ -7,9 +7,6 @@

<br />
<script type='text/javascript'>
var getuserurl = '<?php echo $this->createUrl('admin/survey/ajaxgetusers'); ?>';
var ownerediturl = '<?php echo $this->createUrl('admin/survey/ajaxowneredit'); ?>';
var delmsg ='<?php eT("Are you sure you want to delete these surveys?",'js');?>';
var sCaption ='<?php eT("Survey Respones",'js');?>';
var sSelectColumns ='<?php eT("Select columns",'js');?>';
var sRecordText = '<?php eT("View {0} - {1} of {2}",'js');?>';
Expand Down Expand Up @@ -40,9 +37,11 @@
var sCancel = '<?php eT("Cancel",'js');?>';
var sSearchTitle ='<?php eT("Filter responses",'js');?>';
var sRefreshTitle ='<?php eT("Reload responses list",'js');?>';
var delBtnCaption ='<?php eT("Save",'js');?>';
var delBtnCaption ='<?php eT("Delete",'js');?>';
var sEmptyRecords ='<?php eT("There are currently no responses.",'js');?>';
var jsonUrl = "<?php echo App()->createUrl('/admin/responses', array('sa'=> 'getResponses_json', 'surveyid' => $surveyid)); ?>";
var jsonUrl = "<?php echo App()->createUrl('/admin/responses', array('sa'=> 'getResponses_json', 'surveyid' => $surveyid,'browselang'=>$language)); ?>";
var jsonActionUrl = "<?php echo App()->createUrl('/admin/responses', array('sa'=> 'actionResponses', 'surveyid' => $surveyid,'browselang'=>$language)); ?>";

//var sConfirmationExpireMessage='<?php eT("Are you sure you want to expire these surveys?",'js');?>';
// var editUrl = "<?php echo $this->createUrl('/admin/survey/editSurvey_json'); ?>";
var colNames = <?php echo $column_names_txt; ?>;
Expand Down
2 changes: 2 additions & 0 deletions scripts/admin/admin_core.js
Expand Up @@ -698,6 +698,8 @@ function linksInDialog()
event.preventDefault();
var src = $(this).attr("href");
var title = $(this).attr("title");
if(!title && $(this).children("img[alt]"))
title = $(this).children("img[alt]").attr("alt");
iframe.attr({
src: src,
});
Expand Down

0 comments on commit 0f48238

Please sign in to comment.