\n"; echo "\n"; echo "\t\n"; echo "\t\n"; echo "
".$clang->gT("Export Question")."
\n"; echo "
".$clang->gT("Error")."
\n".$clang->gT("No QID has been provided. Cannot dump question.")."
\n"; echo "
\n"; echo "\t
\n"; echo "\n"; exit; } $dumphead = "# LimeSurvey Question Dump\n" . "# DBVersion $dbversionnumber\n" . "# This is a dumped question from the LimeSurvey Script\n" . "# http://www.limesurvey.org/\n" . "# Do not change this header!\n"; function BuildOutput($Query) { global $dbprefix, $connect; $QueryResult = db_execute_assoc($Query) or safe_die ("ERROR: $QueryResult
".$connect->ErrorMsg()); preg_match('/FROM (\w+)( |,)/i', $Query, $MatchResults); $TableName = $MatchResults[1];; if ($dbprefix) { $TableName = substr($TableName, strlen($dbprefix), strlen($TableName)); } $Output = "\n#\n# " . strtoupper($TableName) . " TABLE\n#\n"; $HeaderDone = false; $ColumnNames = ""; while ($Row = $QueryResult->FetchRow()) { if (!$HeaderDone) { foreach ($Row as $Key=>$Value) { $ColumnNames .= CSVEscape($Key).","; //Add all the column names together } $ColumnNames = substr($ColumnNames, 0, -1); //strip off last comma space $Output .= "$ColumnNames\n"; $HeaderDone=true; } $ColumnValues = ""; foreach ($Row as $Key=>$Value) { $ColumnValues .= CSVEscape(str_replace("\r\n", "\n", $Value)) . ","; } $ColumnValues = substr($ColumnValues, 0, -1); //strip off last comma space $Output .= "$ColumnValues\n"; } return $Output; } //1: Questions Table $qquery = "SELECT * FROM {$dbprefix}questions WHERE qid=$qid"; $qdump = BuildCSVFromQuery($qquery); //2: Answers table $aquery = "SELECT {$dbprefix}answers.* FROM {$dbprefix}answers WHERE {$dbprefix}answers.qid = $qid"; $adump = BuildCSVFromQuery($aquery); //3: Labelsets Table //$lsquery = "SELECT DISTINCT {$dbprefix}labelsets.* FROM {$dbprefix}labelsets, {$dbprefix}questions WHERE {$dbprefix}labelsets.lid={$dbprefix}questions.lid AND type='F' AND qid=$qid"; $lsquery = "SELECT DISTINCT {$dbprefix}labelsets.* FROM {$dbprefix}labelsets, {$dbprefix}questions WHERE {$dbprefix}labelsets.lid={$dbprefix}questions.lid AND type in ('F', 'H', 'Z', 'W') AND qid=$qid"; $lsdump = BuildCSVFromQuery($lsquery); //4: Labels Table $lquery = "SELECT DISTINCT {$dbprefix}labels.* FROM {$dbprefix}labels, {$dbprefix}questions WHERE {$dbprefix}labels.lid={$dbprefix}questions.lid AND type in ('F', 'H', 'Z', 'W') AND qid=$qid"; $ldump = BuildCSVFromQuery($lquery); //5: Question Attributes $query = "SELECT {$dbprefix}question_attributes.* FROM {$dbprefix}question_attributes WHERE {$dbprefix}question_attributes.qid=$qid"; $qadump = BuildCSVFromQuery($query); $fn = "limesurvey_question_$qid.csv"; header("Content-Type: application/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 echo $dumphead, $qdump, $adump, $lsdump, $ldump, $qadump; exit; ?>