Skip to content

Commit

Permalink
Dev Added a new export format for survey structures with file extensi…
Browse files Browse the repository at this point in the history
…ons .lss (LimeSurvey survey) which contains XML

git-svn-id: file:///Users/Shitiz/Downloads/lssvn/source/limesurvey@8596 b72ed6b6-b9f8-46b5-92b4-906544132732
  • Loading branch information
c-schmitz committed Apr 14, 2010
1 parent 56e1b8b commit 924ce35
Show file tree
Hide file tree
Showing 5 changed files with 232 additions and 8 deletions.
5 changes: 5 additions & 0 deletions admin/admin.php
Expand Up @@ -197,6 +197,11 @@
if(hasRight($surveyid,'export')) {include('export_structure_quexml.php');}
else { include('access_denied.php');}
}
elseif ($action == 'exportstructurexml')
{
if(hasRight($surveyid,'export')) {include('export_structure_xml.php');}
else { include('access_denied.php');}
}
elseif ($action == 'exportstructurecsvGroup')
{
if(hasRight($surveyid,'export')) {include('dumpgroup.php');}
Expand Down
38 changes: 37 additions & 1 deletion admin/export_data_functions.php
Expand Up @@ -456,4 +456,40 @@ function spss_getquery() {
}
return $query;
}
?>

function BuildXMLFromQuery($xmlwriter, $Query)
{
global $dbprefix, $connect;
$QueryResult = db_execute_assoc($Query) or safe_die ("ERROR: $QueryResult<br />".$connect->ErrorMsg()); //safe
preg_match('/FROM (\w+)( |,)/', $Query, $MatchResults);
$TableName = $MatchResults[1];;
if ($dbprefix)
{
$TableName = substr($TableName, strlen($dbprefix), strlen($TableName));
}
if ($QueryResult->RecordCount()>0)
{
$xmlwriter->startElement($TableName);
$xmlwriter->startElement('fields');
$Columninfo = $QueryResult->fields;
foreach ($Columninfo as $fieldname=>$value)
{
$xmlwriter->writeElement('fieldname',$fieldname);
}
$xmlwriter->endElement(); // close columns
$xmlwriter->startElement('rows');
while ($Row = $QueryResult->FetchRow())
{
$xmlwriter->startElement('row');
foreach ($Row as $Key=>$Value)
{
$xmlwriter->startElement('data');
$xmlwriter->writeCData($Value);
$xmlwriter->endElement();
}
$xmlwriter->endElement(); // close row
}
$xmlwriter->endElement(); // close rows
$xmlwriter->endElement(); // close tablename
}
}
179 changes: 179 additions & 0 deletions admin/export_structure_xml.php
@@ -0,0 +1,179 @@
<?php
/*
* LimeSurvey
* Copyright (C) 2007 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: export_structure_csv.php 8592 2010-04-14 12:23:25Z machaven $
*/



// DUMP THE RELATED DATA FOR A SINGLE SURVEY INTO A SQL FILE FOR IMPORTING LATER ON OR ON ANOTHER SURVEY SETUP
// DUMP ALL DATA WITH RELATED SID FROM THE FOLLOWING TABLES
// 1. Surveys
// 2. Surveys Language Table
// 3. Groups
// 4. Questions
// 5. Answers
// 6. Conditions
// 7. Label Sets
// 8. Labels
// 9. Question Attributes
// 10. Assessments
// 11. Quota
// 12. Quota Members

include_once("login_check.php");
require_once ("export_data_functions.php");

if (!isset($surveyid))
{
$surveyid=returnglobal('sid');
}


if (!$surveyid)
{
echo $htmlheader
."<br />\n"
."<table width='350' align='center' style='border: 1px solid #555555' cellpadding='1' cellspacing='0'>\n"
."\t<tr bgcolor='#555555'><td colspan='2' height='4'><font size='1' face='verdana' color='white'><strong>"
.$clang->gT("Export Survey")."</strong></td></tr>\n"
."\t<tr><td align='center'>\n"
."<br /><strong><font color='red'>"
.$clang->gT("Error")."</font></strong><br />\n"
.$clang->gT("No SID has been provided. Cannot dump survey")."<br />\n"
."<br /><input type='submit' value='"
.$clang->gT("Main Admin Screen")."' onclick=\"window.open('$scriptname', '_top')\">\n"
."\t</td></tr>\n"
."</table>\n"
."</body></html>\n";
exit;
}

function getXMLStructure($xmlwriter, $exclude=array())
{
global $dbprefix, $surveyid;

$sdump = "";

if ((!empty($exclude) && $exclude['answers'] !== true) || empty($exclude))
{
//Answers table
$aquery = "SELECT {$dbprefix}answers.*
FROM {$dbprefix}answers, {$dbprefix}questions
WHERE {$dbprefix}answers.language={$dbprefix}questions.language
AND {$dbprefix}answers.qid={$dbprefix}questions.qid
AND {$dbprefix}questions.sid=$surveyid";
BuildXMLFromQuery($xmlwriter,$aquery);
}

// Assessments
$query = "SELECT {$dbprefix}assessments.*
FROM {$dbprefix}assessments
WHERE {$dbprefix}assessments.sid=$surveyid";
BuildXMLFromQuery($xmlwriter,$query);

if ((!empty($exclude) && $exclude['conditions'] !== true) || empty($exclude))
{
//Conditions table
$cquery = "SELECT DISTINCT {$dbprefix}conditions.*
FROM {$dbprefix}conditions, {$dbprefix}questions
WHERE {$dbprefix}conditions.qid={$dbprefix}questions.qid
AND {$dbprefix}questions.sid=$surveyid";
BuildXMLFromQuery($xmlwriter,$cquery);
}

//Default values
$query = "SELECT {$dbprefix}defaultvalues.*
FROM {$dbprefix}defaultvalues
WHERE qid in (select qid from {$dbprefix}questions where sid=$surveyid group by qid)";
BuildXMLFromQuery($xmlwriter,$query);

// Groups
$gquery = "SELECT *
FROM {$dbprefix}groups
WHERE sid=$surveyid
ORDER BY gid";
BuildXMLFromQuery($xmlwriter,$gquery);

//Questions
$qquery = "SELECT *
FROM {$dbprefix}questions
WHERE sid=$surveyid
ORDER BY qid";
BuildXMLFromQuery($xmlwriter,$qquery);

//Question attributes
$query = "SELECT {$dbprefix}question_attributes.qaid, {$dbprefix}question_attributes.qid, {$dbprefix}question_attributes.attribute, {$dbprefix}question_attributes.value
FROM {$dbprefix}question_attributes
WHERE {$dbprefix}question_attributes.qid in (select qid from {$dbprefix}questions where sid=$surveyid group by qid)";
BuildXMLFromQuery($xmlwriter,$query);

if ((!empty($exclude) && $exclude['quotas'] !== true) || empty($exclude))
{
//Quota
$query = "SELECT {$dbprefix}quota.*
FROM {$dbprefix}quota
WHERE {$dbprefix}quota.sid=$surveyid";
BuildXMLFromQuery($xmlwriter,$query);

//1Quota members
$query = "SELECT {$dbprefix}quota_members.*
FROM {$dbprefix}quota_members
WHERE {$dbprefix}quota_members.sid=$surveyid";
BuildXMLFromQuery($xmlwriter,$query);

//Quota languagesettings
$query = "SELECT {$dbprefix}quota_languagesettings.*
FROM {$dbprefix}quota_languagesettings, {$dbprefix}quota
WHERE {$dbprefix}quota.id = {$dbprefix}quota_languagesettings.quotals_quota_id
AND {$dbprefix}quota.sid=$surveyid";
BuildXMLFromQuery($xmlwriter,$query);
}

// Surveys
$squery = "SELECT *
FROM {$dbprefix}surveys
WHERE sid=$surveyid";
BuildXMLFromQuery($xmlwriter,$squery);

// Survey language settings
$slsquery = "SELECT *
FROM {$dbprefix}surveys_languagesettings
WHERE surveyls_survey_id=$surveyid";
BuildXMLFromQuery($xmlwriter,$slsquery);

}

if (!isset($copyfunction))
{
$fn = "limesurvey_survey_$surveyid.lss";
header("Content-Type: text/html/force-download");
header("Content-Disposition: attachment; filename=$fn");
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Pragma: cache"); // HTTP/1.0
$xml =new XMLWriter();
$xml->openURI('php://output');
$xml->setIndent(true);
$xml->startDocument('1.0', 'UTF-8');
$xml->startElement('document');
$xml->writeElement('LimeSurveyDocType','Survey');
$xml->writeElement('DBVersion',$dbversionnumber);

getXMLStructure($xml);
$xml->endElement(); // close columns
$xml->endDocument();
}

exit;
?>
14 changes: 7 additions & 7 deletions admin/html.php
Expand Up @@ -2100,13 +2100,14 @@
."<div class='header'>"
.$clang->gT("Export Survey Structure")."\n</div><br />\n"
."<ul style='margin-left:35%;'>\n"
."<li><input type='radio' class='radiobtn' name='type' value='structurecsv' checked='checked' id='surveycsv'
onclick=\"this.form.action.value='exportstructurecsv'\" />"
."<li><input type='radio' class='radiobtn' name='action' value='exportstructurecsv' checked='checked' id='surveycsv'"
."<label for='surveycsv'>"
.$clang->gT("LimeSurvey Survey File (*.csv)")."</label></li>\n";
.$clang->gT("LimeSurvey Survey File (*.csv)")."</label></li>\n"
."<li><input type='radio' class='radiobtn' name='action' value='exportstructurexml' checked='checked' id='surveyxml'"
."<label for='surveycsv'>"
.$clang->gT("LimeSurvey XML survey file (*.lss)")."</label></li>\n";

$exportstructure.="<li><input type='radio' class='radiobtn' name='type' value='structurequeXML' id='queXML'
onclick=\"this.form.action.value='exportstructurequexml'\" />"
$exportstructure.="<li><input type='radio' class='radiobtn' name='action' value='exportstructurequeXML' id='queXML'"
."<label for='queXML'>"
.str_replace('queXML','<a href="http://quexml.sourceforge.net/" target="_blank">queXML</a>',$clang->gT("queXML Survey XML Format (*.xml)"))." "
."</label></li>\n";
Expand All @@ -2128,8 +2129,7 @@
$exportstructure.="<p>\n"
."<input type='submit' value='"
.$clang->gT("Export To File")."' />\n"
."<input type='hidden' name='sid' value='$surveyid' />\n"
."<input type='hidden' name='action' value='exportstructurecsv' />\n";
."<input type='hidden' name='sid' value='$surveyid' />\n";
$exportstructure.="</form>\n";
}
}
Expand Down
4 changes: 4 additions & 0 deletions admin/statistics.php
Expand Up @@ -109,6 +109,10 @@
{
$chartfontfile='KacstFarsi.ttf';
}
elseif ($language=='el' )
{
$chartfontfile='DejaVuLGCSans.ttf';
}
elseif ($language=='zh-Hant-HK' || $language=='zh-Hant-TW' || $language=='zh-Hans')
{
$chartfontfile='fireflysung.ttf';
Expand Down

0 comments on commit 924ce35

Please sign in to comment.