Skip to content

Commit

Permalink
Fixed issue #6562: Export token attribute fields not working
Browse files Browse the repository at this point in the history
  • Loading branch information
c-schmitz committed Sep 21, 2012
1 parent cc66894 commit 64ab931
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 50 deletions.
16 changes: 16 additions & 0 deletions admin/admin.php
@@ -0,0 +1,16 @@
<?php
/*
* LimeSurvey
* Copyright (C) 2007-2011 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
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*/

// Simple redirect to still have the old /admin URL
header( 'Location: ../index.php/admin' ) ;
?>
27 changes: 13 additions & 14 deletions admin/index.php
@@ -1,17 +1,16 @@
<?php
/*
* LimeSurvey
* Copyright (C) 2007-2011 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
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*
* $Id$
*/
/*
* LimeSurvey
* Copyright (C) 2007-2011 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
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*/

// Simple redirect to still have the old /admin URL
header( 'Location: ../index.php/admin' ) ;
header( 'Location: ../index.php/admin' ) ;
?>
17 changes: 5 additions & 12 deletions application/controllers/admin/export.php
Expand Up @@ -230,34 +230,27 @@ public function exportresults()
$options->responseCompletionState = incompleteAnsFilterState();

//If we have no data for the filter state then default to show all.
if ( empty($options->responseCompletionState) )
if ( $options->responseCompletionState =='all' )
{
if ( ! isset($_POST['attribute_select']) )
{
$_POST['attribute_select'] = array();
}

$options->responseCompletionState = 'all';

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

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

if ( in_array('email_address', Yii::app()->request->getPost('attribute_select')) )
{
$dquery .= ", {{tokens_$iSurveyID}}.email";
}

if ( in_array('token', Yii::app()->request->getPost('attribute_select')) )
{
$dquery .= ", {{tokens_$iSurveyID}}.token";
$options->selectedColumns[]="email";
}

$attributeFields = getTokenFieldsAndNames($iSurveyID, TRUE);
Expand All @@ -266,7 +259,7 @@ public function exportresults()
{
if ( in_array($attr_name, Yii::app()->request->getPost('attribute_select')) )
{
$dquery .= ", {{tokens_$iSurveyID}}.$attr_name";
$options->selectedColumns[]=$attr_name;
}
}
}
Expand Down
16 changes: 6 additions & 10 deletions application/controllers/admin/tokens.php
Expand Up @@ -10,16 +10,16 @@
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*
* $Id$
* $Id$
*/

/**
* Tokens Controller
*
* This controller performs token actions
*
* @package LimeSurvey
* @subpackage Backend
* @package LimeSurvey
* @subpackage Backend
*/
class tokens extends Survey_Common_Action
{
Expand Down Expand Up @@ -1154,15 +1154,11 @@ function updatetokenattributes($iSurveyId)
$fields['attribute_' . $i] = array('type' => 'VARCHAR', 'constraint' => '255');
}

$aData['thissurvey'] = getSurveyInfo($iSurveyId);
$aData['surveyid'] = $iSurveyId;
LimeExpressionManager::SetDirtyFlag(); // so that knows that token tables have changed

$this->_renderWrappedTemplate('token', array('tokenbar', 'message' => array(
'title' => sprintf($clang->gT("%s field(s) were successfully added."), $number2add),
'message' => "<br /><input type='button' value='" . $clang->gT("Back to attribute field management.") . "' onclick=\"window.open('" . $this->getController()->createUrl("/admin/tokens/managetokenattributes/surveyid/$iSurveyId") . "', '_top')\" />"
)), $aData);
Yii::app()->session['flashmessage'] = sprintf($clang->gT("%s field(s) were successfully added."), $number2add);
Yii::app()->getController()->redirect(Yii::app()->getController()->createUrl("/admin/tokens/managetokenattributes/surveyid/$iSurveyId"));

LimeExpressionManager::SetDirtyFlag(); // so that knows that token tables have changed
}

/**
Expand Down
32 changes: 19 additions & 13 deletions application/helpers/admin/exportresults_helper.php
Expand Up @@ -262,31 +262,31 @@ public function loadSurveyById($id)


//Load groups
$sql = 'SELECT g.* FROM {{groups}} AS g '.
$sQuery = 'SELECT g.* FROM {{groups}} AS g '.
'WHERE g.sid = '.$intId.' '.
'ORDER BY g.group_order;';
$recordSet = Yii::app()->db->createCommand($sql)->query()->readAll();
$recordSet = Yii::app()->db->createCommand($sQuery)->query()->readAll();
$survey->groups = $recordSet;

//Load questions
$sql = 'SELECT q.* FROM {{questions}} AS q '.
$sQuery = 'SELECT q.* FROM {{questions}} AS q '.
'JOIN {{groups}} AS g ON q.gid = g.gid '.
'WHERE q.sid = '.$intId.' AND q.language = \''.$lang.'\' '.
'ORDER BY g.group_order, q.question_order;';
$survey->questions = Yii::app()->db->createCommand($sql)->query()->readAll();
$survey->questions = Yii::app()->db->createCommand($sQuery)->query()->readAll();

//Load answers
$sql = 'SELECT DISTINCT a.* FROM {{answers}} AS a '.
$sQuery = 'SELECT DISTINCT a.* FROM {{answers}} AS a '.
'JOIN {{questions}} AS q ON a.qid = q.qid '.
'WHERE q.sid = '.$intId.' AND a.language = \''.$lang.'\' '.
'ORDER BY a.qid, a.sortorder;';
$survey->answers = Yii::app()->db->createCommand($sql)->query()->readAll();
$survey->answers = Yii::app()->db->createCommand($sQuery)->query()->readAll();

//Load tokens
if (Yii::app()->db->schema->getTable('{{tokens_' . $intId . '}}'))
{
$sql = 'SELECT t.* FROM {{tokens_' . $intId . '}} AS t;';
$recordSet = Yii::app()->db->createCommand($sql)->query()->readAll();
$sQuery = 'SELECT t.* FROM {{tokens_' . $intId . '}} AS t;';
$recordSet = Yii::app()->db->createCommand($sQuery)->query()->readAll();
$survey->tokens = $recordSet;
}
else
Expand All @@ -295,8 +295,8 @@ public function loadSurveyById($id)
}

//Load language settings
$sql = 'SELECT * FROM {{surveys_languagesettings}} WHERE surveyls_survey_id = '.$intId.';';
$recordSet = Yii::app()->db->createCommand($sql)->query()->readAll();
$sQuery = 'SELECT * FROM {{surveys_languagesettings}} WHERE surveyls_survey_id = '.$intId.';';
$recordSet = Yii::app()->db->createCommand($sQuery)->query()->readAll();
$survey->languageSettings = $recordSet;

return $survey;
Expand All @@ -316,11 +316,16 @@ public function loadSurveyResults(SurveyObj $survey, $minRecord = null, $maxReco
{

/* @var $recordSet ADORecordSet */
$sql = 'SELECT * FROM {{survey_' . $survey->id . '}} order by id';
$sQuery = 'SELECT * FROM {{survey_' . $survey->id . '}}';
if (tableExists('tokens_'.$survey->id))
{
$sQuery.=' left join {{tokens_' . $survey->id . '}} on {{tokens_' . $survey->id . '}}.token={{survey_' . $survey->id . '}}.token ';
}
$sQuery.=' order by id';
if (!isset($minRecord) && !isset($maxRecord))
{
//Neither min or max is set, load it all.
$recordSet = Yii::app()->db->createCommand($sql)->query()->readAll();
$recordSet = Yii::app()->db->createCommand($sQuery)->query()->readAll();
}
elseif (!isset($minRecord) xor !isset($maxRecord))
{
Expand All @@ -330,7 +335,7 @@ public function loadSurveyResults(SurveyObj $survey, $minRecord = null, $maxReco
else
{
//Both min and max are set.
$recordSet = Yii::app()->db->createCommand($sql)->limit($maxRecord - $minRecord + 1, $minRecord)->query()->readAll();
$recordSet = Yii::app()->db->createCommand($sQuery)->limit($maxRecord - $minRecord + 1, $minRecord)->query()->readAll();
}
//Convert the data in the recordSet to a 2D array and stuff it in $responses.
$survey->responses = $recordSet;
Expand Down Expand Up @@ -874,6 +879,7 @@ protected function translate($key, $sLanguageCode)

protected function translateHeading($column, $sLanguageCode)
{
if (substr($column,0,10)=='attribute_') return $column;
return $this->translator->translateHeading($column, $sLanguageCode);
}

Expand Down
1 change: 0 additions & 1 deletion application/views/admin/export/exportresults_view.php
Expand Up @@ -119,7 +119,6 @@
<option value='first_name' id='first_name' /><?php $clang->eT("First name");?></option>
<option value='last_name' id='last_name' /><?php $clang->eT("Last name");?></option>
<option value='email_address' id='email_address' /><?php $clang->eT("Email address");?></option>
<option value='token' id='token' /><?php $clang->eT("Token");?></option>

<?php $attrfieldnames=getTokenFieldsAndNames($surveyid,true);
foreach ($attrfieldnames as $attr_name=>$attr_desc)
Expand Down

0 comments on commit 64ab931

Please sign in to comment.