Skip to content

Commit

Permalink
- Deletion of groups works now again
Browse files Browse the repository at this point in the history
- Export of survey, groups, questions as CSV works and is tested
- Import of old survey, new CSV survey and CSV question works and is tested
Still to test: Import of groups/label sets, export of label sets
Remark: DBEdit.php is not used. It looks like a try to move database functions from database to functions in dbedit.php. We should put it to use sooner or later.

git-svn-id: file:///Users/Shitiz/Downloads/lssvn/source/phpsurveyor@2216 b72ed6b6-b9f8-46b5-92b4-906544132732
  • Loading branch information
c-schmitz committed Jan 29, 2007
1 parent 4cc3b8c commit e52d4b1
Show file tree
Hide file tree
Showing 15 changed files with 534 additions and 958 deletions.
6 changes: 5 additions & 1 deletion admin/admin.php
Expand Up @@ -53,7 +53,6 @@
$adminoutput=getAdminHeader(); // Alle future output is written into this and then outputted at the end of file

include_once("login_check.php");



if ($action == "activate")
Expand Down Expand Up @@ -99,6 +98,9 @@
include("access_denied.php");
}
}



if ($action == "importgroup")
{
/*$surquery = "SELECT define_questions FROM {$dbprefix}surveys_rights WHERE sid=$surveyid AND uid = ".$_SESSION['loginID']; //Getting rights for this survey
Expand Down Expand Up @@ -208,6 +210,8 @@
if (isset($editanswer)) {$adminoutput.= $editanswer;}
if (isset($assessmentsoutput)) {$adminoutput.= $assessmentsoutput;}
if (isset($importsurvey)) {$adminoutput.= $importsurvey;}
if (isset($importgroup)) {$adminoutput.= $importgroup;}
if (isset($importquestion)) {$adminoutput.= $importquestion;}


$adminoutput.= "\t\t</td>\n".helpscreen();;
Expand Down
2 changes: 1 addition & 1 deletion admin/browse.php
Expand Up @@ -240,7 +240,7 @@
."<img align='left' hspace='0' border='0' src='$imagefiles/delete.png' alt='' title='' onClick=\"return confirm('"._("Are you sure you want to delete this entry.")."')\" /></a>\n"
. "\t\t\t<a href='export.php?sid=$surveyid&id=$id'" .
"onmouseout=\"hideTooltip()\" onmouseover=\"showTooltip(event,'". _("Export this Response")."')\">" .
"<img name='Export' src='$imagefiles/exportsql.png' title='' alt='". _("Export this Response")."'align='left' /></a>\n"
"<img name='Export' src='$imagefiles/exportcsv.png' title='' alt='". _("Export this Response")."'align='left' /></a>\n"
."\t\t\t<img src='$imagefiles/seperator.gif' border='0' hspace='0' align='left' alt='' />\n"
."\t\t\t<img src='$imagefiles/blank.gif' width='20' height='20' border='0' hspace='0' align='left' alt='' />\n"
."\t\t\t<a href='browse.php?action=id&amp;id=$last&amp;sid=$surveyid&amp;surveytable=$surveytable'" .
Expand Down
2 changes: 1 addition & 1 deletion admin/database.php
Expand Up @@ -200,7 +200,7 @@ function get_max_order($gid)
if ($dresult=$connect->Execute($dquery)) {$total++;}
$dquery = "DELETE FROM ".db_table_name('answers')." WHERE qid={$row['qid']}";
if ($dresult=$connect->Execute($dquery)) {$total++;}
$dquery = "DELETE FROM ".db_table_name('qeustions')." WHERE qid={$row['qid']}";
$dquery = "DELETE FROM ".db_table_name('questions')." WHERE qid={$row['qid']}";
if ($dresult=$connect->Execute($dquery)) {$total++;}
}
if ($total != $qtodel*3)
Expand Down
53 changes: 13 additions & 40 deletions admin/dumpgroup.php
Expand Up @@ -63,39 +63,14 @@
exit;
}

$fn = "group_$gid.sql";
$fn = "phpsurveyor_group_$gid.csv";

$dumphead = "# SURVEYOR GROUP DUMP\n";
$dumphead .= "# Version $versionnumber\n# This is a dumped group from the PHPSurveyor Script\n";
$dumphead .= "# http://www.phpsurveyor.org/\n";
$dumphead = "# PHPSurveyor Group Dump\n"
. "# DBVersion $dbversionnumber\n"
. "# This is a dumped group from the PHPSurveyor Script\n"
. "# http://www.phpsurveyor.org/\n"
. "# Do not change this header!\n";

function BuildOutput($Query)
{
global $dbprefix, $connect;
$QueryResult = db_execute_assoc($Query) or die("ERROR:\n".$Query."\n".$connect->ErrorMsg()."\n\n");
preg_match('/FROM (\w+)( |,)/i', $Query, $MatchResults);
$TableName = $MatchResults[1];
if ($dbprefix)
{
$TableName = substr($TableName, strlen($dbprefix), strlen($TableName));
}
$Output = "\n# NEW TABLE\n# " . strtoupper($TableName) . " TABLE\n#\n";
while ($Row = $QueryResult->FetchRow())
{
$ColumnNames = "";
$ColumnValues = "";
foreach ($Row as $Key=>$Value)
{
$ColumnNames .= "`" . $Key . "`, "; //Add all the column names together
$ColumnValues .= $connect->qstr(str_replace("\r\n", "\n", $Value)) . ", ";
}
$ColumnNames = substr($ColumnNames, 0, -2); //strip off last comma space
$ColumnValues = substr($ColumnValues, 0, -2); //strip off last comma space

$Output .= "INSERT INTO $TableName ($ColumnNames) VALUES ($ColumnValues);\n";
}
return $Output;
}

header("Content-Type: application/download");
header("Content-Disposition: attachment; filename=$fn");
Expand All @@ -106,34 +81,32 @@ function BuildOutput($Query)

//0: Groups Table
$gquery = "SELECT * FROM {$dbprefix}groups WHERE gid=$gid";
$gdump = BuildOutput($gquery);
$gdump = BuildCSVFromQuery($gquery);

//1: Questions Table
$qquery = "SELECT * FROM {$dbprefix}questions WHERE gid=$gid";
$qdump = BuildOutput($qquery);
$qdump = BuildCSVFromQuery($qquery);

//2: Answers table
$aquery = "SELECT {$dbprefix}answers.* FROM {$dbprefix}answers, {$dbprefix}questions WHERE {$dbprefix}answers.qid={$dbprefix}questions.qid AND {$dbprefix}questions.gid=$gid";
$adump = BuildOutput($aquery);
$adump = BuildCSVFromQuery($aquery);

//3: Conditions table - THIS CAN ONLY EXPORT CONDITIONS THAT RELATE TO THE SAME GROUP
$cquery = "SELECT {$dbprefix}conditions.* FROM {$dbprefix}conditions, {$dbprefix}questions, {$dbprefix}questions b WHERE {$dbprefix}conditions.cqid={$dbprefix}questions.qid AND {$dbprefix}conditions.qid=b.qid AND {$dbprefix}questions.sid=$surveyid AND {$dbprefix}questions.gid=$gid AND b.gid=$gid";
$cdump = BuildOutput($cquery);
$cdump = BuildCSVFromQuery($cquery);

//4: Labelsets Table
$lsquery = "SELECT DISTINCT {$dbprefix}labelsets.lid, label_name FROM {$dbprefix}labelsets, {$dbprefix}questions WHERE {$dbprefix}labelsets.lid={$dbprefix}questions.lid AND type in ('F', 'H', 'W', 'Z') AND gid=$gid";
$lsdump = BuildOutput($lsquery);
$lsdump = BuildCSVFromQuery($lsquery);

//5: Labels Table
$lquery = "SELECT DISTINCT {$dbprefix}labels.lid, {$dbprefix}labels.code, {$dbprefix}labels.title, {$dbprefix}labels.sortorder FROM {$dbprefix}labels, {$dbprefix}questions WHERE {$dbprefix}labels.lid={$dbprefix}questions.lid AND type='F' AND gid=$gid";
$ldump = BuildOutput($lquery);
$ldump = BuildCSVFromQuery($lquery);

//8: Question Attributes
$query = "SELECT {$dbprefix}question_attributes.* FROM {$dbprefix}question_attributes, {$dbprefix}questions WHERE {$dbprefix}question_attributes.qid={$dbprefix}questions.qid AND {$dbprefix}questions.sid=$surveyid AND {$dbprefix}questions.gid=$gid";
$qadump = BuildOutput($query);
$qadump = BuildCSVFromQuery($query);
// HTTP/1.0
echo "#<pre>\n";
echo $dumphead, $gdump, $qdump, $adump, $cdump, $lsdump, $ldump, $qadump;
echo "#</pre>\n";

?>
44 changes: 9 additions & 35 deletions admin/dumplabel.php
Expand Up @@ -62,56 +62,30 @@
echo "</body></html>\n";
exit;
}
$dumphead = "# SURVEYOR LABEL SET DUMP\n";
$dumphead .= "#\n# This is a dumped label set from the PHPSurveyor Script\n";
$dumphead .= "# http://www.phpsurveyor.org/\n";

function BuildOutput($Query)
{
global $dbprefix, $connect;
$QueryResult = db_execute_assoc($Query);
preg_match('/FROM (\w+)( |,)/i', $Query, $MatchResults);
$TableName = $MatchResults[1];
if ($dbprefix)
{
$TableName = substr($TableName, strlen($dbprefix), strlen($TableName));
}
$Output = "\n# NEW TABLE\n# " . strtoupper($TableName) . " TABLE\n#\n";
while ($Row = $QueryResult->FetchRow())
{
$ColumnNames = "";
$ColumnValues = "";
foreach ($Row as $Key=>$Value)
{
$ColumnNames .= "`" . $Key . "`, "; //Add all the column names together
$ColumnValues .= $connect->qstr(str_replace("\r\n", "\n", $Value)) . ", ";
}
$ColumnNames = substr($ColumnNames, 0, -2); //strip off last comma space
$ColumnValues = substr($ColumnValues, 0, -2); //strip off last comma space

$Output .= "INSERT INTO $TableName ($ColumnNames) VALUES ($ColumnValues)\n";
}
return $Output;
}
$dumphead = "# PHPSurveyor Label Set Dump\n"
. "# DBVersion $dbversionnumber\n"
." # This is a dumped label set from the PHPSurveyor Script\n"
. "# http://www.phpsurveyor.org/\n"
. "# Do not change this header!\n";

//1: Questions Table
$qquery = "SELECT * FROM {$dbprefix}labelsets WHERE lid=$lid";
$qdump = BuildOutput($qquery);
$qdump = BuildCSVFromQuery($qquery);

//2: Answers table
$aquery = "SELECT lid, code, title, sortorder, language FROM {$dbprefix}labels WHERE lid=$lid";
$adump = BuildOutput($aquery);
$adump = BuildCSVFromQuery($aquery);

$fn = "labelset_$lid.sql";
$fn = "phpsurveyor_labelset_$lid.csv";

//header("Content-Type: application/msword"); //EXPORT INTO MSWORD
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: no-cache"); // HTTP/1.0
echo "#<pre>\n";

echo $dumphead, $qdump, $adump;
echo "#</pre>\n";

?>
52 changes: 31 additions & 21 deletions admin/dumpquestion.php
Expand Up @@ -62,67 +62,77 @@
echo "</body></html>\n";
exit;
}
$dumphead = "# SURVEYOR QUESTION DUMP\n";
$dumphead .= "# Version $versionnumber\n# This is a dumped question from the PHPSurveyor Script\n";
$dumphead .= "# http://www.phpsurveyor.org/\n";

$dumphead = "# PHPSurveyor Question Dump\n"
. "# DBVersion $dbversionnumber\n"
. "# This is a dumped question from the PHPSurveyor Script\n"
. "# http://www.phpsurveyor.org/\n"
. "# Do not change this header!\n";

function BuildOutput($Query)
{
global $dbprefix, $connect;
$QueryResult = db_execute_assoc($Query);
$QueryResult = db_execute_assoc($Query) or die ("ERROR: $QueryResult<br />".htmlspecialchars($connect->ErrorMsg()));
preg_match('/FROM (\w+)( |,)/i', $Query, $MatchResults);
$TableName = $MatchResults[1];
$TableName = $MatchResults[1];;
if ($dbprefix)
{
$TableName = substr($TableName, strlen($dbprefix), strlen($TableName));
}
$Output = "\n# NEW TABLE\n# " . strtoupper($TableName) . " TABLE\n#\n";
$Output = "\n#\n# " . strtoupper($TableName) . " TABLE\n#\n";
$HeaderDone = false; $ColumnNames = "";
while ($Row = $QueryResult->FetchRow())
{
$ColumnNames = "";

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)
{
$ColumnNames .= "`" . $Key . "`, "; //Add all the column names together
$ColumnValues .= $connect->qstr(str_replace("\r\n", "\n", $Value)) . ", ";
$ColumnValues .= CSVEscape(str_replace("\r\n", "\n", $Value)) . ",";
}
$ColumnNames = substr($ColumnNames, 0, -2); //strip off last comma space
$ColumnValues = substr($ColumnValues, 0, -2); //strip off last comma space

$Output .= "INSERT INTO $TableName ($ColumnNames) VALUES ($ColumnValues)\n";
$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 = BuildOutput($qquery);
$qdump = BuildCSVFromQuery($qquery);

//2: Answers table
$aquery = "SELECT {$dbprefix}answers.* FROM {$dbprefix}answers, {$dbprefix}questions WHERE {$dbprefix}answers.qid={$dbprefix}questions.qid AND {$dbprefix}questions.qid=$qid";
$adump = BuildOutput($aquery);
$adump = BuildCSVFromQuery($aquery);

//3: Labelsets Table
$lsquery = "SELECT DISTINCT {$dbprefix}labelsets.lid, label_name FROM {$dbprefix}labelsets, {$dbprefix}questions WHERE {$dbprefix}labelsets.lid={$dbprefix}questions.lid AND type='F' AND qid=$qid";
$lsdump = BuildOutput($lsquery);
$lsdump = BuildCSVFromQuery($lsquery);

//4: Labels Table
$lquery = "SELECT DISTINCT {$dbprefix}labels.lid, {$dbprefix}labels.code, {$dbprefix}labels.title, {$dbprefix}labels.sortorder FROM {$dbprefix}labels, {$dbprefix}questions WHERE {$dbprefix}labels.lid={$dbprefix}questions.lid AND type in ('F', 'H', 'Z', 'W') AND qid=$qid";
$ldump = BuildOutput($lquery);
$ldump = BuildCSVFromQuery($lquery);

//5: Question Attributes
$query = "SELECT {$dbprefix}question_attributes.* FROM {$dbprefix}question_attributes WHERE {$dbprefix}question_attributes.qid=$qid";
$qadump = BuildOutput($query);
$fn = "question_$qid.sql";
$qadump = BuildCSVFromQuery($query);
$fn = "phpsurveyor_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: no-cache"); // HTTP/1.0
echo "#<pre>\n";
echo $dumphead, $qdump, $adump, $lsdump, $ldump, $qadump;
echo "#</pre>\n";

?>

0 comments on commit e52d4b1

Please sign in to comment.