Skip to content

Commit

Permalink
Fixed issue #8321: Export of single response preselects only 255 columns
Browse files Browse the repository at this point in the history
  • Loading branch information
c-schmitz committed Oct 30, 2013
1 parent 1e324d2 commit c0ea64d
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 60 deletions.
12 changes: 11 additions & 1 deletion application/controllers/admin/export.php
Expand Up @@ -146,6 +146,9 @@ public function exportresults()

Yii::app()->loadHelper("admin/exportresults");

App()->getClientScript()->registerScriptFile(Yii::app()->getConfig('generalscripts')."expressions/em_javascript.js");
App()->getClientScript()->registerScriptFile(Yii::app()->getConfig('adminscripts') . '/exportresults.js');

$surveybaselang = Survey::model()->findByPk($iSurveyID)->language;
$exportoutput = "";

Expand Down Expand Up @@ -182,12 +185,19 @@ public function exportresults()
$selectshow = "selected='selected'";
}

$aFields=array();
foreach($aFieldMap as $sFieldName=>$fieldinfo)
{
$sCode=viewHelper::getFieldCode($fieldinfo);
$aFields[$sCode]=$sCode.' - '.htmlspecialchars(ellipsize(html_entity_decode(viewHelper::getFieldText($fieldinfo)),30,.6,'...'));
}

$data['SingleResponse']=(int)returnGlobal('id');
$data['selecthide'] = $selecthide;
$data['selectshow'] = $selectshow;
$data['selectinc'] = $selectinc;
$data['afieldcount'] = $iFieldCount;
$data['excesscols'] = $aFieldMap;
$data['aFields'] = $aFields;

//get max number of datasets
$iMaximum = SurveyDynamic::model($iSurveyID)->getMaxId();
Expand Down
1 change: 0 additions & 1 deletion application/controllers/admin/quotas.php
Expand Up @@ -558,7 +558,6 @@ function getQuotaAnswers($iQuestionId, $iSurveyId, $iQuotaId)
protected function _renderWrappedTemplate($sAction = 'quotas', $aViewUrls = array(), $aData = array())
{
App()->getClientScript()->registerPackage('jquery-superfish');
# App()->getClientScript()->registerPackage('jquery-tablesorter');
App()->getClientScript()->registerScriptFile(Yii::app()->getConfig('adminscripts') . '/quotas.js');
parent::_renderWrappedTemplate($sAction, $aViewUrls, $aData);
}
Expand Down
20 changes: 8 additions & 12 deletions application/core/plugins/Authdb/Authdb.php
Expand Up @@ -141,25 +141,21 @@ public function listExportOptions()
$type = $event->get('type');

switch ($type) {
case 'csv':
$event->set('label', gT("CSV File (All charsets)"));
if (!function_exists('iconv')) {
$event->set('default', true);
}
case 'csv':
$event->set('label', gT("CSV"));
$event->set('default', true);
break;

case 'xls':
$label = gT("Microsoft Excel (All charsets)");
if (function_exists('iconv')) {
$event->set('default', true);
} else {
$label = gT("Microsoft Excel");
if (!function_exists('iconv')) {
$label .= '<font class="warningtitle">'.$clang->gT("(Iconv Library not installed)").'</font>';
}
$event->set('label', $label);
break;

case 'doc':
$event->set('label', gT("Microsoft Word (UTF-8 charset)"));
$event->set('label', gT("Microsoft Word"));
$event->set('onclick', 'document.getElementById("ansfull").checked=true;document.getElementById("ansabbrev").disabled=true;');
break;

Expand Down Expand Up @@ -187,12 +183,12 @@ public function listExportPlugins()

// Yes we overwrite existing classes if available
$className = get_class();
$exports['doc'] = $className;
$exports['csv'] = $className;
$exports['xls'] = $className;
$exports['pdf'] = $className;
$exports['html'] = $className;
$exports['json'] = $className;
$exports['csv'] = $className;
$exports['doc'] = $className;

$event->set('exportplugins', $exports);
}
Expand Down
50 changes: 13 additions & 37 deletions application/views/admin/export/exportresults_view.php
@@ -1,3 +1,8 @@
<script type="text/javascript">
var sMsgMaximumExcelColumns = '<?php $clang->eT("You can only choose 255 colums at a maximum for Excel export.",'js'); ?>';
var sMsgExcelColumnsReduced = '<?php $clang->eT("The number of selected columns was reduced automatically.",'js'); ?>';
var sMsgColumnCount = '<?php $clang->eT("%s of %s columns selected",'js'); ?>';
</script>
<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) {
Expand Down Expand Up @@ -61,8 +66,8 @@
<?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>
<ul><li><label><?php $clang->eT("Range:");?></label><br> <?php $clang->eT("From");?> <input type='text' name='export_from' size='7' value='1' />
<?php $clang->eT("to");?> <input type='text' name='export_to' size='7' value='<?php echo $max_datasets;?>' /></li>

<li><br /><label for='completionstate'><?php $clang->eT("Completion state");?></label> <select id='completionstate' name='completionstate'>
<option value='complete' <?php echo $selecthide;?>><?php $clang->eT("Completed responses only");?></option>
Expand Down Expand Up @@ -113,41 +118,12 @@
<input type='hidden' name='response_id' value="<?php echo $SingleResponse;?>" />
<?php }
$clang->eT("Choose columns");?>:

<?php if ($afieldcount > 255) {
echo "\t<img src='$imageurl/help.gif' alt='".$clang->gT("Help")."' onclick='javascript:alert(\""
.$clang->gT("Your survey contains more than 255 columns of responses. Spreadsheet applications such as Excel are limited to loading no more than 255. Select the columns you wish to export in the list below.","js")
."\")' />";
}
else
{
echo "\t<img src='$imageurl/help.gif' alt='".$clang->gT("Help")."' onclick='javascript:alert(\""
.$clang->gT("Choose the columns you wish to export.","js")
."\")' />";
} ?>
<br /><select name='colselect[]' multiple size='20'>
<?php $i=1;
foreach($excesscols as $sFieldName=>$fieldinfo)
{
$questiontext=viewHelper::getFieldText($fieldinfo);
$questioncode=viewHelper::getFieldCode($fieldinfo);
echo "<option value='{$sFieldName}'";
if (isset($_POST['summary']))
{
if (in_array($ec, $_POST['summary']))
{
echo "selected";
}
}
elseif ($i<256)
{
echo " selected";
}
echo " title='{$sFieldName} : ".str_replace("'", "&#39;",$questiontext)."'>".ellipsize("{$i} : {$questioncode} - ".str_replace(array("\r\n", "\n", "\r"), " ", $questiontext),45)."</option>\n";
$i++;
} ?>
</select>
<br />&nbsp;</fieldset>
<br />
<?php
echo CHtml::listBox('colselect[]',array_keys($aFields),$aFields,array('multiple'=>'multiple','size'=>'20','style'=>'width:370px;'));
echo "\t<img src='$imageurl/help.gif' alt='".$clang->gT("Help")."' onclick='javascript:alert(\"".$clang->gT("Please note: The export to Excel is currently limited to loading no more than 255 columns.","js")."\")'>";?>
<span id='columncount'>&nbsp;</span>
</fieldset>
<?php if ($thissurvey['anonymized'] == "N" && tableExists("{{tokens_$surveyid}}") && Permission::model()->hasSurveyPermission($surveyid,'tokens','read')) { ?>
<fieldset><legend><?php $clang->eT("Token control");?></legend>
<?php $clang->eT("Choose token fields");?>:
Expand Down
39 changes: 39 additions & 0 deletions scripts/admin/exportresults.js
@@ -0,0 +1,39 @@
$(document).ready(function(){
updateColumnCountDisplay();
$('#colselect').change(function(){
if ($(this).val().length > 255 && $('#xls').prop('checked')) {
alert(sMsgMaximumExcelColumns);
$(this).val(last_valid_selection);
} else {
last_valid_selection = $(this).val();
}
updateColumnCountDisplay();
});
$('#xls').change(function(){
aOptions=$($("#colselect :selected").get().reverse());
selectedCount = $("#colselect :selected").length;
bLimited=false;
aOptions.each(function(){
if (selectedCount>255)
{
this.selected=false;
selectedCount--;
bLimited=true;
}
});
if (bLimited)
{
alert(sMsgMaximumExcelColumns+' '+"\n"+sMsgExcelColumnsReduced);
}
updateColumnCountDisplay();
});


});

function updateColumnCountDisplay()
{
selectedCount = $("#colselect :selected").length;
totalCount = $("#colselect option").length;
$('#columncount').html(sprintf(sMsgColumnCount,selectedCount,totalCount));
}
6 changes: 3 additions & 3 deletions styles/blobblueish/adminstyle.css
Expand Up @@ -1335,16 +1335,16 @@ thead tr .headerSortDown, thead tr .headerSortUp {
div.left
{
float:left;
width:300px;
width:400px;
}

div.right {
float:right;
width:300px;
width:400px;
}

.wrap2columns {
width:600px;
width:800px;
margin:0 auto;
}

Expand Down
6 changes: 3 additions & 3 deletions styles/darkblue/adminstyle.css
Expand Up @@ -1354,16 +1354,16 @@ thead tr .headerSortDown, thead tr .headerSortUp {
div.left
{
float:left;
width:300px;
width:400px;
}

div.right {
float:right;
width:300px;
width:400px;
}

.wrap2columns {
width:600px;
width:800px;
margin:0 auto;
}

Expand Down
6 changes: 3 additions & 3 deletions styles/gringegreen/adminstyle.css
Expand Up @@ -1355,16 +1355,16 @@ thead tr .headerSortDown, thead tr .headerSortUp {
div.left
{
float:left;
width:300px;
width:400px;
}

div.right {
float:right;
width:300px;
width:400px;
}

.wrap2columns {
width:600px;
width:800px;
margin:0 auto;
}

Expand Down

0 comments on commit c0ea64d

Please sign in to comment.