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 (#815)

Fixed issue #12697: SPSS Export - responses truncated for incomplete answers
Dev: force_refresh before exporting (like export by plugins)
Dev: unsure it fix THIS issue, but clearly : force_refresh seem needed
Fixed issue #12734: SPSS : exporting complete or uncomplete make different syntax
Dev: get the real size for string/text in the DB
Dev: Must review numeric (N/K) part ?
Dev: What for float ?
Dev: Fix invalid var without minus
Dev: MAX for max …
Dev: Fix export Array text and multi text as string (get size)
Dev: default is to export as string
Dev: Fix other/comment issue …
Dev: Fix badly set array number as dropdown for text input
Dev: fix controller part
Dev: Fix width of numeric is total width
Dev: readding $length_vallabel = 120;
Dev: constant for all SPSS version ?
Dev: Fixed issue other and comment must be string
  • Loading branch information
Shnoulle committed Oct 30, 2017
1 parent d57b146 commit aaaf845
Show file tree
Hide file tree
Showing 2 changed files with 340 additions and 226 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 @@ -357,41 +357,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 @@ -453,8 +444,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 @@ -468,60 +458,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 @@ -546,14 +495,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 @@ -654,7 +601,7 @@ public function exportspss()
}
}
echo "RESTORE LOCALE.\n";
exit;
App()->end();
}
}

Expand Down

3 comments on commit aaaf845

@c-schmitz
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sure to push this patch to develop branch, too.
As mentioned in one of the latest meetings there will ne no further automatic merges.

@Shnoulle
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, i know , but currentky have issue to import lsa file … (broken)

@Shnoulle
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Please sign in to comment.