Skip to content

Commit

Permalink
Fixed issue #6643: Can not export one response from survey to an appl…
Browse files Browse the repository at this point in the history
…ication and translate problem
  • Loading branch information
c-schmitz committed Oct 5, 2012
1 parent 60cbe3b commit c0031f6
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 35 deletions.
20 changes: 10 additions & 10 deletions application/controllers/admin/export.php
Expand Up @@ -136,7 +136,6 @@ public function exportresults()
if ( ! isset($convertyto1) ) { $convertyto1 = returnGlobal('convertyto1'); }
if ( ! isset($convertnto2) ) { $convertnto2 = returnGlobal('convertnto2'); }
if ( ! isset($convertspacetous) ) { $convertspacetous = returnGlobal('convertspacetous'); }

$clang = Yii::app()->lang;

if ( ! hasSurveyPermission($iSurveyID, 'responses', 'export') )
Expand Down Expand Up @@ -174,6 +173,7 @@ public function exportresults()
$selectshow = "selected='selected'";
}

$data['SingleResponse']=(int)returnGlobal('id');
$data['selecthide'] = $selecthide;
$data['selectshow'] = $selectshow;
$data['selectinc'] = $selectinc;
Expand Down Expand Up @@ -232,23 +232,19 @@ public function exportresults()
//If we have no data for the filter state then default to show all.
if ( $options->responseCompletionState =='all' )
{
if ( ! isset($_POST['attribute_select']) )
{
$_POST['attribute_select'] = array();
}

$dquery = '';
if ( in_array('first_name', Yii::app()->request->getPost('attribute_select')) )
if ( in_array('first_name', Yii::app()->request->getPost('attribute_select', array())) )
{
$options->selectedColumns[]="firstname";
}

if ( in_array('last_name', Yii::app()->request->getPost('attribute_select')) )
if ( in_array('last_name', Yii::app()->request->getPost('attribute_select', array())) )
{
$options->selectedColumns[]="lastname";
}

if ( in_array('email_address', Yii::app()->request->getPost('attribute_select')) )
if ( in_array('email_address', Yii::app()->request->getPost('attribute_select', array())) )
{
$options->selectedColumns[]="email";
}
Expand All @@ -257,15 +253,19 @@ public function exportresults()

foreach ($attributeFields as $attr_name => $attr_desc)
{
if ( in_array($attr_name, Yii::app()->request->getPost('attribute_select')) )
if ( in_array($attr_name, Yii::app()->request->getPost('attribute_select',array())) )
{
$options->selectedColumns[]=$attr_name;
}
}
}
if (Yii::app()->request->getPost('response_id'))
{
$sFilter='id='.(int)Yii::app()->request->getPost('response_id');
}

$resultsService = new ExportSurveyResultsService();
$resultsService->exportSurvey($iSurveyID, $explang, $type, $options);
$resultsService->exportSurvey($iSurveyID, $explang, $type, $options, $sFilter);

exit;
}
Expand Down
30 changes: 15 additions & 15 deletions application/helpers/admin/exportresults_helper.php
Expand Up @@ -49,9 +49,10 @@ class ExportSurveyResultsService
* @param mixed $iSurveyId
* @param mixed $sLanguageCode
* @param FormattingOptions $oOptions
* @param string $sFilter
* @param mixed $sOutputStyle 'display' or 'file' Default: display (send to browser)
*/
function exportSurvey($iSurveyId, $sLanguageCode, $sExportPlugin, FormattingOptions $oOptions)
function exportSurvey($iSurveyId, $sLanguageCode, $sExportPlugin, FormattingOptions $oOptions, $sFilter)
{
//Do some input validation.
if (empty($iSurveyId))
Expand Down Expand Up @@ -113,15 +114,12 @@ function exportSurvey($iSurveyId, $sLanguageCode, $sExportPlugin, FormattingOpti
$bMoreRecords=true; $first=true;
while ($bMoreRecords)
{
if($iBatchSize > (int)$oOptions->responseMaxRecord-$iCurrentRecord)
{
$iBatchSize=(int)$oOptions->responseMaxRecord-$iCurrentRecord;
}
$iExported= $surveyDao->loadSurveyResults($survey, $iBatchSize, $iCurrentRecord);

$iExported= $surveyDao->loadSurveyResults($survey, $iBatchSize, $iCurrentRecord, $sFilter);
$iCurrentRecord+=$iExported;
$writer->write($survey, $sLanguageCode, $oOptions,$first);
$first=false;
$bMoreRecords=($iCurrentRecord < (int)$oOptions->responseMaxRecord);
$bMoreRecords= ($iExported == $iBatchSize);
}

$writer->close();
Expand Down Expand Up @@ -303,14 +301,16 @@ public function loadSurveyById($id)
* @param int $iOffset
* @param int $iLimit
*/
public function loadSurveyResults(SurveyObj $survey, $iLimit, $iOffset )
public function loadSurveyResults(SurveyObj $survey, $iLimit, $iOffset, $sFilter='' )
{

$oRecordSet = Yii::app()->db->createCommand()->select()->from('{{survey_' . $survey->id . '}}');
if (tableExists('tokens_'.$survey->id))
{
$oRecordSet->join('{{tokens_' . $survey->id . '}}','{{tokens_' . $survey->id . '}}.token={{survey_' . $survey->id . '}}.token');
}
if ($sFilter!='')
$oRecordSet->where($sFilter);
$survey->responses=$oRecordSet->order('id')->limit($iLimit, $iOffset)->query()->readAll();

return count($survey->responses);
Expand Down Expand Up @@ -712,17 +712,17 @@ class Translator
//internationalization layer. <fieldname> => <internationalization key>
private $headerTranslationKeys = array(
'id' => 'id',
'lastname' => 'Last Name',
'firstname' => 'First Name',
'email' => 'Email Address',
'lastname' => 'Last name',
'firstname' => 'First name',
'email' => 'Email address',
'token' => 'Token',
'datestamp' => 'Date Last Action',
'startdate' => 'Date Started',
'datestamp' => 'Date last action',
'startdate' => 'Date started',
'submitdate' => 'Completed',
//'completed' => 'Completed',
'ipaddr' => 'IP-Address',
'ipaddr' => 'IP address',
'refurl' => 'Referring URL',
'lastpage' => 'Last page seen',
'lastpage' => 'Last page',
'startlanguage' => 'Start language'//,
//'tid' => 'Token ID'
);
Expand Down
26 changes: 16 additions & 10 deletions application/views/admin/export/exportresults_view.php
@@ -1,11 +1,17 @@
<div class='header ui-widget-header'><?php $clang->eT("Export results");?></div>
<div class='header ui-widget-header'><?php $clang->eT("Export results");?>
<?php if (isset($_POST['sql'])) {echo" - ".$clang->gT("Filtered from statistics script");}
if ($SingleResponse) {
echo " - ".sprintf($clang->gT("Single response: ID %s"),$SingleResponse);}
?>
</div>
<div class='wrap2columns'>
<form id='resultexport' action='<?php echo $this->createUrl("admin/export/exportresults/surveyid/$surveyid");?>' method='post'><div class='left'>

<?php if (isset($_POST['sql'])) {echo" - ".$clang->gT("Filtered from statistics script");}
if (returnGlobal('id')<>'') {echo " - ".$clang->gT("Single response");} ?>

<fieldset><legend><?php $clang->eT("General");?></legend>

<fieldset <?php if ($SingleResponse) {?>
style='display:none';
<?php } ?>
><legend><?php $clang->eT("General");?></legend>

<ul><li><label><?php $clang->eT("Range:");?></label> <?php $clang->eT("From");?> <input type='text' name='export_from' size='8' value='1' />
<?php $clang->eT("to");?> <input type='text' name='export_to' size='8' value='<?php echo $max_datasets;?>' /></li>
Expand Down Expand Up @@ -51,11 +57,11 @@
<fieldset><legend><?php $clang->eT("Format");?></legend>
<ul>
<li><input type='radio' class='radiobtn' name='type' value='csv' id='csvdoc' <?php if (!function_exists('iconv'))
{ echo 'checked="checked" ';} ?> onclick='document.getElementById("ansabbrev").disabled=false;' />
{ echo 'checked="checked" ';} ?> onclick='document.getElementById("ansabbrev").disabled=false;' />
<label for='csvdoc'><?php $clang->eT("CSV File (All charsets)");?></label></li>
<li><input type='radio' class='radiobtn' name='type' value='xls' checked id='exceldoc' <?php if (!function_exists('iconv')) echo ' disabled="disabled" ';?> onclick='document.getElementById("ansabbrev").disabled=false;' />
<label for='exceldoc'><?php $clang->eT("Microsoft Excel (All charsets)");?><?php if (!function_exists('iconv'))
{ echo '<font class="warningtitle">'.$clang->gT("(Iconv Library not installed)").'</font>'; } ?>
{ echo '<font class="warningtitle">'.$clang->gT("(Iconv Library not installed)").'</font>'; } ?>
</label></li>
<li>
<input type='radio' class='radiobtn' name='type' value='doc' id='worddoc' onclick='document.getElementById("ansfull").checked=true;document.getElementById("ansabbrev").disabled=true;' />
Expand All @@ -74,8 +80,8 @@
<?php if (isset($_POST['sql'])) { ?>
<input type='hidden' name='sql' value="<?php echo stripcslashes($_POST['sql']);?>" />
<?php }
if (returnGlobal('id')<>'') { ?>
<input type='hidden' name='answerid' value="<?php echo stripcslashes(returnGlobal('id'));?>" />
if ($SingleResponse) { ?>
<input type='hidden' name='response_id' value="<?php echo $SingleResponse;?>" />
<?php }
$clang->eT("Choose columns");?>:

Expand Down Expand Up @@ -111,7 +117,7 @@
} ?>
</select>
<br />&nbsp;</fieldset>
<?php if ($thissurvey['anonymized'] == "N" && Yii::app()->db->schema->getTable("{{tokens_$surveyid}}")) { ?>
<?php if ($thissurvey['anonymized'] == "N" && tableExists("{{tokens_$surveyid}}")) { ?>
<fieldset><legend><?php $clang->eT("Token control");?></legend>
<?php $clang->eT("Choose token fields");?>:
<img src='<?php echo $imageurl;?>/help.gif' alt='<?php $clang->eT("Help");?>' onclick='javascript:alert("<?php $clang->gT("Your survey can export associated token data with each response. Select any additional fields you would like to export.","js");?>")' /><br />
Expand Down

0 comments on commit c0031f6

Please sign in to comment.