diff --git a/admin/admin.php b/admin/admin.php index 7dfe3f134a3..fa7ff90d3dc 100644 --- a/admin/admin.php +++ b/admin/admin.php @@ -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');} diff --git a/admin/export_data_functions.php b/admin/export_data_functions.php index 490e63cddc6..0b2e7ae4280 100644 --- a/admin/export_data_functions.php +++ b/admin/export_data_functions.php @@ -456,4 +456,40 @@ function spss_getquery() { } return $query; } -?> \ No newline at end of file + +function BuildXMLFromQuery($xmlwriter, $Query) +{ + global $dbprefix, $connect; + $QueryResult = db_execute_assoc($Query) or safe_die ("ERROR: $QueryResult
".$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 + } +} diff --git a/admin/export_structure_xml.php b/admin/export_structure_xml.php new file mode 100644 index 00000000000..e2d37a86c45 --- /dev/null +++ b/admin/export_structure_xml.php @@ -0,0 +1,179 @@ +\n" + ."\n" + ."\t\n" + ."\t\n" + ."
" + .$clang->gT("Export Survey")."
\n" + ."
" + .$clang->gT("Error")."
\n" + .$clang->gT("No SID has been provided. Cannot dump survey")."
\n" + ."
\n" + ."\t
\n" + ."\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; +?> diff --git a/admin/html.php b/admin/html.php index f170d914d86..12a3b017348 100644 --- a/admin/html.php +++ b/admin/html.php @@ -2100,13 +2100,14 @@ ."
" .$clang->gT("Export Survey Structure")."\n

\n" ."