\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', 'W', 'H', 'Z', '1', ':', ';') 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', 'W', 'H', 'Z', '1', ':', ';') AND qid=$qid"; $ldump = BuildCSVFromQuery($lquery); //4: Labelsets1 Table //This exists specifically to deal with dual-scale questions (or any future question that may have 2 labelsets) $lsquery = "SELECT DISTINCT {$dbprefix}labelsets.* FROM {$dbprefix}labelsets, {$dbprefix}questions WHERE {$dbprefix}labelsets.lid={$dbprefix}questions.lid1 AND type in ('1') AND qid=$qid"; $ls1dump = BuildCSVFromQuery($lsquery); $ls1=explode("\n", trim($ls1dump)); if(count($ls1)>3) { //If there is actually some data here, then add just the data (not the headers) into // $ls1dump - which will be outputted directly after $lsdump $ls1dump=$ls1[4]; $ls1dump .= "\n"; } else { //If there is no data then make it an empty string. $ls1dump = ""; } //4a: Labels1 Table // See explanation for Labelsets1 Table!! These are the actual labels $lquery = "SELECT DISTINCT {$dbprefix}labels.* FROM {$dbprefix}labels, {$dbprefix}questions WHERE {$dbprefix}labels.lid={$dbprefix}questions.lid1 AND type in ('1') AND qid=$qid"; $l1dump = BuildCSVFromQuery($lquery); $ld1=explode("\n", trim($l1dump)); if(count($ld1)>3) { //If there is actually some data here, then add just the data (not the headers) into // $l1dump - which will be outputted directly after $ldump $l1dump=array(); foreach($ld1 as $key=>$ld) { //Put every line, other than the first three into this string if($key > 3) { $l1dump[]=$ld; } } $l1dump = implode("\n", $l1dump); $l1dump .= "\n"; } else { //If there is no data then make it an empty string. $l1dump = ""; } //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, $ls1dump, $ldump, $l1dump, $qadump; exit; ?>