Skip to content

Commit

Permalink
Fixed issue #12697: SPSS Export - responses truncated for incomplete …
Browse files Browse the repository at this point in the history
…answers

Fixed issue #12734: SPSS : exporting complete or uncomplete make different syntax
Dev: Conflicts: application/helpers/export_helper.php
  • Loading branch information
Shnoulle committed Oct 31, 2017
1 parent 423263f commit 50f83de
Show file tree
Hide file tree
Showing 2 changed files with 377 additions and 250 deletions.
97 changes: 22 additions & 75 deletions application/controllers/admin/export.php
@@ -1,7 +1,7 @@
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/*
* LimeSurvey
* Copyright (C) 2007-2011 The LimeSurvey Project Team / Carsten Schmitz
* Copyright (C) 2007-2017 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
Expand Down Expand Up @@ -361,41 +361,32 @@ public function exportspss()
// $typeMap = $this->_getTypeMap();

$filterstate = incompleteAnsFilterState();
$spssver = returnGlobal('spssver');

if ( is_null($spssver) )
{
if ( ! Yii::app()->session['spssversion'] )
{
Yii::app()->session['spssversion'] = 2; //Set default to 2, version 16 or up
}

$spssver = Yii::app()->session['spssversion'];
}
else
{
Yii::app()->session['spssversion'] = $spssver;
if(!Yii::app()->session['spssversion']) { // Default to 2 (16 and up)
Yii::app()->session['spssversion'] = 2;
}
$spssver = Yii::app()->request->getParam('spssver',Yii::app()->session['spssversion']);
Yii::app()->session['spssversion'] = $spssver;

$length_varlabel = '231'; // Set the max text length of Variable Labels
$length_vallabel = '120'; // Set the max text length of Value Labels

switch ( $spssver )
{
switch ( $spssver ) {
case 1: //<16
$iLength = '255'; // Set the max text length of the Value
break;
case 2: //>=16
$iLength = '16384'; // Set the max text length of the Value
break;
default:
$iLength = '16384'; // Set the max text length of the Value
}

$headerComment = '*$Rev: 121017 $' . " $filterstate $spssver.\n";

if ( isset($_POST['dldata']) ) $subaction = "dldata";
if ( isset($_POST['dlstructure']) ) $subaction = "dlstructure";
if ( Yii::app()->request->getPost('dldata') ) {
$subaction = "dldata";
}
if ( Yii::app()->request->getPost('dlstructure') ) {
$subaction = "dlstructure";
}

if ( ! isset($subaction) )
{
Expand Down Expand Up @@ -454,8 +445,7 @@ public function exportspss()
Yii::app()->loadHelper("admin/exportresults");
viewHelper::disableHtmlLogging();

if ( $subaction == 'dldata' )
{
if ( $subaction == 'dldata' ) {
header("Content-Disposition: attachment; filename=survey_" . $iSurveyID . "_SPSS_data_file.dat");
header("Content-type: text/comma-separated-values; charset=UTF-8");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
Expand All @@ -469,60 +459,19 @@ public function exportspss()
$sNoAnswerValue = (isset($_POST['noanswervalue']) && $_POST['noanswervalue'] != '' )?'\''.$_POST['noanswervalue'].'\'':'';
SPSSExportData($iSurveyID, $iLength, $sNoAnswerValue,'\'',false, $sLanguage);

exit;
App()->end();
}

if ( $subaction == 'dlstructure' )
{
if ( $subaction == 'dlstructure' ) {
header("Content-Disposition: attachment; filename=survey_" . $iSurveyID . "_SPSS_syntax_file.sps");
header("Content-type: application/download; charset=UTF-8");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Pragma: public");

// Build array that has to be returned
$fields = SPSSFieldMap($iSurveyID, 'V', $sLanguage);

//Now get the query string with all fields to export
$query = SPSSGetQuery($iSurveyID, 500, 0); // Sample first 500 responses for adjusting fieldmap
$result = $query->queryAll();

$num_fields = 0;
//Now we check if we need to adjust the size of the field or the type of the field
foreach ( $result as $row )
{

foreach ( $fields as $iIndex=>$aField )
{
//Performance improvement, don't recheck fields that have valuelabels
if ( ! isset($aField['answers']) )
{
$strTmp = mb_substr(stripTagsFull($row[$aField['sql_name']]), 0, $iLength);
$len = mb_strlen($strTmp);

if ( $len > $fields[$iIndex]['size'] ) $fields[$iIndex]['size'] = $len;

if ( trim($strTmp) != '' )
{
if ( $fields[$iIndex]['SPSStype'] == 'F' && (isNumericExtended($strTmp) === FALSE || $fields[$iIndex]['size'] > 16) )
{
$fields[$iIndex]['SPSStype'] = 'A';
}
}
}
}
}

/**
* End of DATA print out
*
* Now $fields contains accurate length data, and the DATA LIST can be rendered -- then the contents of the temp file can
* be sent to the client.
*/
if ( $spssver == 2 )
{
if ( $spssver == 2 ) {
echo "\xEF\xBB\xBF";
}

echo $headerComment;

if ($spssver == 2 )
Expand All @@ -547,14 +496,12 @@ public function exportspss()

foreach ( $fields as $field )
{
if( $field['SPSStype'] == 'DATETIME23.2' ) $field['size'] = '';

if($field['SPSStype'] == 'F' && ($field['LStype'] == 'N' || $field['LStype'] == 'K'))
{
$field['size'] .= '.' . ($field['size']-1);
if( $field['SPSStype'] == 'DATETIME23.2' ) {
$field['size'] = '';
}
if ( !$field['hide'] ) {
echo "\n {$field['id']} {$field['SPSStype']}{$field['size']}";
}

if ( !$field['hide'] ) echo "\n {$field['id']} {$field['SPSStype']}{$field['size']}";
}

echo ".\nCACHE.\n"
Expand Down Expand Up @@ -655,7 +602,7 @@ public function exportspss()
}
}
echo "RESTORE LOCALE.\n";
exit;
App()->end();
}
}

Expand Down

0 comments on commit 50f83de

Please sign in to comment.