Skip to content

Commit

Permalink
New Feature Import and Export from a new Excel format with one row ea…
Browse files Browse the repository at this point in the history
…ch per group, question, sub-question, and answer; and no dependence upon SGQA naming
  • Loading branch information
TMSWhite committed Mar 21, 2012
1 parent 3f50b5c commit 576c768
Show file tree
Hide file tree
Showing 8 changed files with 2,581 additions and 6 deletions.
47 changes: 47 additions & 0 deletions application/controllers/admin/export.php
Original file line number Diff line number Diff line change
Expand Up @@ -1305,12 +1305,59 @@ private function _surveyexport($action, $iSurveyID)
{
lsrccsv_export($iSurveyID);
}
elseif ($action == 'exportstructureexcel')
{
$this->_exportexcel($iSurveyID);
}
elseif ( $action == "exportarchive" )
{
$this->_exportarchive($iSurveyID);
}
}

/**
* Generate and Excel file for the survey structure
* @param type $surveyid
*/
private function _exportexcel($surveyid)
{
$fn = "limesurvey_survey_$surveyid.xls";
$this->_addHeaders($fn, "text/csv", 0);

$data =& LimeExpressionManager::ExcelSurveyExport($surveyid);

Yii::import('application.libraries.admin.pear.Spreadsheet.Excel.Xlswriter', true);

// actually generate an Excel workbook
$workbook = new xlswriter;
$workbook->setVersion(8);
$workbook->send($fn);

$sheet =& $workbook->addWorksheet(); // do not translate/change this - the library does not support any special chars in sheet name
$sheet->setInputEncoding('utf-8');

$rc = -1; // row counter
$cc = -1; // column counter
foreach($data as $row)
{
++$rc;
$cc=-1;
foreach ($row as $col)
{
// Enclose in \" if begins by =
++$cc;
if (substr($col,0,1) == "=")
{
$col = "\"".$col."\"";
}
$col = str_replace(array("\t","\n","\r"),array(" "," "," "),$col);
$sheet->write($rc, $cc, $col);
}
}
$workbook->close();
return;
}

private function _addHeaders($filename, $content_type, $expires, $pragma = "public")
{
header("Content-Type: {$content_type}; charset=UTF-8");
Expand Down
6 changes: 5 additions & 1 deletion application/controllers/admin/surveyadmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,7 @@ public function copy()
}
}

if (!$aData['bFailed'] && (strtolower($sExtension) != 'csv' && strtolower($sExtension) != 'lss' && strtolower($sExtension) != 'zip'))
if (!$aData['bFailed'] && (strtolower($sExtension) != 'csv' && strtolower($sExtension) != 'lss' && strtolower($sExtension) != 'xls' && strtolower($sExtension) != 'zip'))
{
$aData['sErrorMessage'] = $clang->gT("Import failed. You specified an invalid file type.");
$aData['bFailed'] = true;
Expand Down Expand Up @@ -848,6 +848,10 @@ public function copy()
{
$aImportResults = XMLImportSurvey($sFullFilepath, null, null, null, (isset($_POST['translinksfields'])));
}
elseif (isset($sExtension) && strtolower($sExtension) == 'xls')
{
$aImportResults = ExcelImportSurvey($sFullFilepath);
}
elseif (isset($sExtension) && strtolower($sExtension) == 'zip') // Import a survey archive
{
Yii::import("application.libraries.admin.pclzip.pclzip", true);
Expand Down

0 comments on commit 576c768

Please sign in to comment.