Skip to content

Commit

Permalink
New feature: Response Excel format now exports xlsx files
Browse files Browse the repository at this point in the history
  • Loading branch information
c-schmitz committed May 25, 2016
1 parent f9fe819 commit ec2629c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion application/helpers/admin/export/ExcelWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function close()
$this->workbook->writeToFile($this->filename);
if ($this->forceDownload){
header("Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
header("Content-Disposition: attachment; filename=\"Excel.xlsx\"");
header("Content-Disposition: attachment; filename=\"{$this->webfilename}.xlsx\"");
header('Content-Length: ' . filesize($this->filename));
readfile($this->filename);
}
Expand Down
1 change: 1 addition & 0 deletions application/helpers/admin/export/Writer.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public function init(SurveyObj $oSurvey, $sLanguageCode, FormattingOptions $oOpt
$this->languageCode = $sLanguageCode;
$this->translator = new Translator();
$this->filename = Yii::app()->getConfig("tempdir") . DIRECTORY_SEPARATOR . randomChars(40);
$this->webfilename = 'results-survey'.$oSurvey->id;
}

/**
Expand Down
14 changes: 7 additions & 7 deletions application/helpers/admin/statistics_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -4112,7 +4112,7 @@ public function generate_html_chartjs_statistics($surveyid, $allfields, $q2show=
* @param mixed $browse Show browse buttons
* @return buffer
*/
public function generate_statistics($surveyid, $allfields, $q2show='all', $usegraph=0, $outputType='pdf', $pdfOutput='I',$sLanguageCode=null, $browse = true)
public function generate_statistics($surveyid, $allfields, $q2show='all', $usegraph=0, $outputType='pdf', $outputTarget='I',$sLanguageCode=null, $browse = true)
{

$aStatisticsData=array(); //astatdata generates data for the output page's javascript so it can rebuild graphs on the fly
Expand Down Expand Up @@ -4260,7 +4260,7 @@ public function generate_statistics($surveyid, $allfields, $q2show='all', $usegr
*/
require_once(APPPATH.'/third_party/pear/Spreadsheet/Excel/Xlswriter.php');

if($pdfOutput=='F')
if($outputTarget=='F')
{
$sFileName = $sTempDir.'/statistic-survey'.$surveyid.'.xls';
$this->workbook = new Xlswriter($sFileName);
Expand All @@ -4278,7 +4278,7 @@ public function generate_statistics($surveyid, $allfields, $q2show='all', $usegr
if (!empty($sTempDir)) {
$this->workbook->setTempDir($sTempDir);
}
if ($pdfOutput!='F')
if ($outputTarget!='F')
$this->workbook->send('statistic-survey'.$surveyid.'.xls');

// Creating the first worksheet
Expand Down Expand Up @@ -4460,7 +4460,7 @@ public function generate_statistics($surveyid, $allfields, $q2show='all', $usegr

$this->workbook->close();

if($pdfOutput=='F')
if($outputTarget=='F')
{
return $sFileName;
}
Expand All @@ -4473,14 +4473,14 @@ public function generate_statistics($surveyid, $allfields, $q2show='all', $usegr
case 'pdf':
$this->pdf->lastPage();

if($pdfOutput=='F')
if($outputTarget=='F')
{ // This is only used by lsrc to send an E-Mail attachment, so it gives back the filename to send and delete afterwards
$tempfilename = $sTempDir."/Survey_".$surveyid.".pdf";
$this->pdf->Output($tempfilename, $pdfOutput);
$this->pdf->Output($tempfilename, $outputTarget);
return $tempfilename;
}
else
return $this->pdf->Output(gT('Survey').'_'.$surveyid."_".$surveyInfo['surveyls_title'].'.pdf', $pdfOutput);
return $this->pdf->Output(gT('Survey').'_'.$surveyid."_".$surveyInfo['surveyls_title'].'.pdf', $outputTarget);

break;
case 'html':
Expand Down

0 comments on commit ec2629c

Please sign in to comment.