Skip to content

Commit

Permalink
MOD: Allows exporting and importing of new question_attributes featur…
Browse files Browse the repository at this point in the history
…e with normal import/export controls

git-svn-id: file:///Users/Shitiz/Downloads/lssvn/trunk/unstable@1192 b72ed6b6-b9f8-46b5-92b4-906544132732
  • Loading branch information
jcleeland committed Sep 17, 2004
1 parent 6537a71 commit e9f29f2
Show file tree
Hide file tree
Showing 6 changed files with 176 additions and 17 deletions.
5 changes: 4 additions & 1 deletion admin/dumpgroup.php
Expand Up @@ -133,9 +133,12 @@ function BuildOutput($Query)
$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);

//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=$sid AND {$dbprefix}.questions.gid=$gid";
$qadump = BuildOutput($query);
// HTTP/1.0
echo "#<pre>\n";
echo $dumphead, $gdump, $qdump, $adump, $cdump, $lsdump, $ldump;
echo $dumphead, $gdump, $qdump, $adump, $cdump, $lsdump, $ldump, $qadump;
echo "#</pre>\n";

?>
5 changes: 4 additions & 1 deletion admin/dumpquestion.php
Expand Up @@ -114,6 +114,9 @@ function BuildOutput($Query)
$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 qid=$qid";
$ldump = BuildOutput($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";

header("Content-Type: application/download");
Expand All @@ -124,7 +127,7 @@ function BuildOutput($Query)
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache"); // HTTP/1.0
echo "#<pre>\n";
echo $dumphead, $qdump, $adump, $lsdump, $ldump;
echo $dumphead, $qdump, $adump, $lsdump, $ldump, $qadump;
echo "#</pre>\n";

?>
6 changes: 5 additions & 1 deletion admin/dumpsurvey.php
Expand Up @@ -134,6 +134,10 @@ function BuildOutput($Query)
$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 sid=$sid";
$ldump = BuildOutput($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=$sid";
$qadump = BuildOutput($query);

$fn = "survey_$sid.sql";

header("Content-Type: application/download");
Expand All @@ -145,6 +149,6 @@ function BuildOutput($Query)
header("Pragma: no-cache"); // HTTP/1.0

echo "#<pre>\n"
.$dumphead, $sdump, $gdump, $qdump, $adump, $cdump, $lsdump, $ldump
.$dumphead, $sdump, $gdump, $qdump, $adump, $cdump, $lsdump, $ldump, $qadump
."#</pre>\n";
?>
50 changes: 48 additions & 2 deletions admin/importgroup.php
Expand Up @@ -184,22 +184,44 @@
$bigarray = array_values($bigarray);

//LABELS
if (array_search("# QUESTION_ATTRIBUTES TABLE\n", $bigarray))
{
$stoppoint = array_search("# QUESTION_ATTRIBUTES TABLE\n", $bigarray);
}
elseif (array_search("# QUESTION_ATTRIBUTES TABLE\r\n", $bigarray))
{
$stoppoint = array_search("# QUESTION_ATTRIBUTES TABLE\r\n", $bigarray);
}
else
{
$stoppoint = count($bigarray)-1;
}
for ($i=0; $i<=$stoppoint+1; $i++)
{
if ($i<$stoppoint-2) {$labelsarray[] = $bigarray[$i];}
unset($bigarray[$i]);
}
$bigarray = array_values($bigarray);

//LAST LOT (now question_attributes)
if (!isset($noconditions) || $noconditions != "Y")
{
$stoppoint = count($bigarray)-1;
for ($i=0; $i<=$stoppoint+1; $i++)
{
if ($i<$stoppoint-1) {$labelsarray[] = $bigarray[$i];}
if ($i<$stoppoint-1) {$question_attributesarray[] = $bigarray[$i];}
unset($bigarray[$i]);
}
}
$bigarray = array_values($bigarray);

if (isset($grouparray)) {$countgroups = count($grouparray);}
if (isset($questionarray)) {$countquestions = count($questionarray);}
if (isset($answerarray)) {$countanswers = count($answerarray);}
if (isset($conditionsarray)) {$countconditions = count($conditionsarray);}
if (isset($labelsetsarray)) {$countlabelsets = count($labelsetsarray);}
if (isset($labelsarray)) {$countlabels = count($labelsarray);}
if (isset($question_attributesarray)) {$countquestion_attributes = count($question_attributesarray);} else {$countquestion_attributes=0;}

$newsid = $_POST["sid"];

Expand Down Expand Up @@ -423,6 +445,28 @@
//We've built two arrays along the way - one containing the old SID, GID and QIDs - and their NEW equivalents
//and one containing the old 'extended fieldname' and its new equivalent. These are needed to import conditions.

if (isset($question_attributesarray) && $question_attributesarray) {//ONLY DO THIS IF THERE ARE QUESTION_ATTRIBUES
foreach ($question_attributesarray as $qar) {
$fieldorders=convertToArray($qar, "`, `", "(`", "`)");
$fieldcontents=convertToArray($qar, "', '", "('", "')");
$newfieldcontents=$fieldcontents;
$oldqid=$fieldcontents[array_search("qid", $fieldorders)];
foreach ($substitutions as $subs) {
if ($oldqid==$subs[2]) {$newqid=$subs[5];}
}

$newfieldcontents[array_search("qid", $fieldorders)]=$newqid;
$newfieldcontents[array_search("qaid", $fieldorders)]="";

$newvalues="('".implode("', '", $newfieldcontents)."')";
$insert=str_replace("('".implode("', '", $fieldcontents)."')", $newvalues, $qar);
$insert=str_replace("INTO question_attributes", "INTO {$dbprefix}question_attributes", $insert);
$result=mysql_query($insert) or die ("Couldn't insert question_attribute<br />$insert<br />".mysql_error());

unset($newcqid);
}
}

if (isset($conditionsarray) && $conditionsarray) {//ONLY DO THIS IF THERE ARE CONDITIONS!
foreach ($conditionsarray as $car) {
$fieldorders=convertToArray($car, "`, `", "(`", "`)");
Expand Down Expand Up @@ -469,8 +513,10 @@
if (isset($countlabelsets)) {echo $countlabelsets;}
echo " ("._LABELANS.": ";
if (isset($countlabels)) {echo $countlabels;}
echo ")</li>\n";
echo "\t<li>"._QL_QUESTIONATTRIBUTES;
if (isset($countquestion_attributes)) {echo " $countquestion_attributes";}
echo ")</li>\n</ul>\n";

echo "<b>"._IG_SUCCESS."</b><br />\n"
."<input $btstyle type='submit' value='"._GO_ADMIN."' onClick=\"window.open('$scriptname?sid=$newsid', '_top')\">\n"
."</td></tr></table>\n"
Expand Down
74 changes: 65 additions & 9 deletions admin/importquestion.php
Expand Up @@ -163,32 +163,64 @@
}
$bigarray = array_values($bigarray);

//ANSWERS
if (array_search("#</pre>\n", $bigarray))
//LABELS
if (array_search("# QUESTION_ATTRIBUTES TABLE\n", $bigarray))
{
$stoppoint = array_search("#</pre>\n", $bigarray);
$stoppoint = array_search("# QUESTION_ATTRIBUTES TABLE\n", $bigarray);
}
if (array_search("#</pre>\r\n", $bigarray))
elseif (array_search("# QUESTION_ATTRIBUTES TABLE\r\n", $bigarray))
{
$stoppoint = array_search("#</pre>\r\n", $bigarray);
$stoppoint = array_search("# QUESTION_ATTRIBUTES TABLE\r\n", $bigarray);
}
else
{
$stoppoint = count($bigarray)-1;
}
for ($i=0; $i<$stoppoint; $i++)
for ($i=0; $i<=$stoppoint+1; $i++)
{
$labelsarray[] = $bigarray[$i];
//echo "($i)[$stoppoint]An Answer! - {$bigarray[$i]}<br />";
if ($i<$stoppoint-2) {$labelsarray[] = $bigarray[$i];}
unset($bigarray[$i]);
}
$bigarray = array_values($bigarray);

//LAST LOT (now question_attributes)
if (!isset($noconditions) || $noconditions != "Y")
{
$stoppoint = count($bigarray)-1;
for ($i=0; $i<=$stoppoint+1; $i++)
{
if ($i<$stoppoint-1) {$question_attributesarray[] = $bigarray[$i];}
unset($bigarray[$i]);
}
}
$bigarray = array_values($bigarray);
////ANSWERS
//if (array_search("#</pre>\n", $bigarray))
// {
// $stoppoint = array_search("#</pre>\n", $bigarray);
// }
//if (array_search("#</pre>\r\n", $bigarray))
// {
// $stoppoint = array_search("#</pre>\r\n", $bigarray);
// }
//else
// {
// $stoppoint = count($bigarray)-1;
// }
//for ($i=0; $i<$stoppoint; $i++)
// {
// $labelsarray[] = $bigarray[$i];
// //echo "($i)[$stoppoint]An Answer! - {$bigarray[$i]}<br />";
// unset($bigarray[$i]);
// }
//$bigarray = array_values($bigarray);


if (isset($questionarray)) {$countquestions = count($questionarray);}
if (isset($answerarray)) {$countanswers = count($answerarray);}
if (isset($labelsetsarray)) {$countlabelsets = count($labelsetsarray);}
if (isset($labelsarray)) {$countlabels = count($labelsarray);}
if (isset($question_attributesarray)) {$countquestion_attributes = count($question_attributesarray);} else {$countquestion_attributes=0;}

// GET SURVEY AND GROUP DETAILS
$sid=$_POST['sid'];
Expand Down Expand Up @@ -369,6 +401,27 @@
}
$substitutions[]=array($oldsid, $oldgid, $oldqid, $newsid, $newgid, $newqid);
}
//NOW DO question_attributes if there are any
if (isset($question_attributesarray) && $question_attributesarray)
{//ONLY DO THIS IF THERE ARE QUESTION_ATTRIBUES
foreach ($question_attributesarray as $qar)
{
$fieldorders=convertToArray($qar, "`, `", "(`", "`)");
$fieldcontents=convertToArray($qar, "', '", "('", "')");
$newfieldcontents=$fieldcontents;
$oldqid=$fieldcontents[array_search("qid", $fieldorders)];

$newfieldcontents[array_search("qid", $fieldorders)]=$newqid;
$newfieldcontents[array_search("qaid", $fieldorders)]="";

$newvalues="('".implode("', '", $newfieldcontents)."')";
$insert=str_replace("('".implode("', '", $fieldcontents)."')", $newvalues, $qar);
$insert=str_replace("INTO question_attributes", "INTO {$dbprefix}question_attributes", $insert);
$result=mysql_query($insert) or die ("Couldn't insert question_attribute<br />$insert<br />".mysql_error());

unset($newcqid);
}
}
}
}

Expand All @@ -389,7 +442,10 @@
if (isset($countlabelsets)) {echo $countlabelsets;}
echo " (";
if (isset($countlabels)) {echo $countlabels;}
echo ")</li></ul><br />\n";
echo ")</li><br />\n";
echo "\t<li>"._QL_QUESTIONATTRIBUTES;
if (isset($countquestion_attributes)) {echo $countquestion_attributes;}
echo "</li></ul><br />\n";

echo "<b>"._IS_SUCCESS."</b><br />\n"
."<input $btstyle type='submit' value='"
Expand Down
53 changes: 50 additions & 3 deletions admin/importsurvey.php
Expand Up @@ -207,15 +207,38 @@
$bigarray = array_values($bigarray);

//LABELS
if (array_search("# QUESTION_ATTRIBUTES TABLE\n", $bigarray))
{
$stoppoint = array_search("# QUESTION_ATTRIBUTES TABLE\n", $bigarray);
}
elseif (array_search("# QUESTION_ATTRIBUTES TABLE\r\n", $bigarray))
{
$stoppoint = array_search("# QUESTION_ATTRIBUTES TABLE\r\n", $bigarray);
}
else
{
$stoppoint = count($bigarray)-1;
}
for ($i=0; $i<=$stoppoint+1; $i++)
{
if ($i<$stoppoint-2) {$labelsarray[] = $bigarray[$i];}
unset($bigarray[$i]);
}
$bigarray = array_values($bigarray);

//LAST LOT (now question_attributes)
if (!isset($noconditions) || $noconditions != "Y")
{
$stoppoint = count($bigarray)-1;
for ($i=0; $i<=$stoppoint+1; $i++)
{
if ($i<$stoppoint-1) {$labelsarray[] = $bigarray[$i];}
if ($i<$stoppoint-1) {$question_attributesarray[] = $bigarray[$i];}
unset($bigarray[$i]);
}
}
$bigarray = array_values($bigarray);

//QUESTION_ATTRIBUTES



Expand All @@ -227,6 +250,7 @@
if (isset($conditionsarray)) {$countconditions = count($conditionsarray);} else {$countconditions=0;}
if (isset($labelsetsarray)) {$countlabelsets = count($labelsetsarray);} else {$countlabelsets=0;}
if (isset($labelsarray)) {$countlabels = count($labelsarray);} else {$countlabels=0;}
if (isset($question_attributesarray)) {$countquestion_attributes = count($question_attributesarray);} else {$countquestion_attributes=0;}

// CREATE SURVEY
$sfieldorders=convertToArray($tablearray[0], "`, `", "(`", "`)");
Expand Down Expand Up @@ -482,7 +506,29 @@
}
}
//We've built two arrays along the way - one containing the old SID, GID and QIDs - and their NEW equivalents
//and one containing the old 'extended fieldname' and its new equivalent. These are needed to import conditions.
//and one containing the old 'extended fieldname' and its new equivalent. These are needed to import conditions and question_attributes.
if (isset($question_attributesarray) && $question_attributesarray) {//ONLY DO THIS IF THERE ARE QUESTION_ATTRIBUES
foreach ($question_attributesarray as $qar) {
$fieldorders=convertToArray($qar, "`, `", "(`", "`)");
$fieldcontents=convertToArray($qar, "', '", "('", "')");
$newfieldcontents=$fieldcontents;
$oldqid=$fieldcontents[array_search("qid", $fieldorders)];
foreach ($substitutions as $subs) {
if ($oldqid==$subs[2]) {$newqid=$subs[5];}
}

$newfieldcontents[array_search("qid", $fieldorders)]=$newqid;
$newfieldcontents[array_search("qaid", $fieldorders)]="";

$newvalues="('".implode("', '", $newfieldcontents)."')";
$insert=str_replace("('".implode("', '", $fieldcontents)."')", $newvalues, $qar);
$insert=str_replace("INTO question_attributes", "INTO {$dbprefix}question_attributes", $insert);
$result=mysql_query($insert) or die ("Couldn't insert question_attribute<br />$insert<br />".mysql_error());

unset($newcqid);
}
}

if (isset($conditionsarray) && $conditionsarray) {//ONLY DO THIS IF THERE ARE CONDITIONS!
foreach ($conditionsarray as $car) {
$fieldorders=convertToArray($car, "`, `", "(`", "`)");
Expand Down Expand Up @@ -533,7 +579,8 @@
echo "\t<li>"._QUESTIONS.": $countquestions</li>\n";
echo "\t<li>"._ANSWERS.": $countanswers</li>\n";
echo "\t<li>"._CONDITIONS.": $countconditions</li>\n";
echo "\t<li>"._LABELSET.": $countlabelsets ("._LABELANS.": $countlabels)</li>\n</ul>\n";
echo "\t<li>"._LABELSET.": $countlabelsets ("._LABELANS.": $countlabels)</li>\n";
echo "\t<li>"._QL_QUESTIONATTRIBUTES." $countquestion_attributes</li>\n</ul>\n";

echo "<b>"._IS_SUCCESS."</b><br />\n";
echo "<input $btstyle type='submit' value='"._GO_ADMIN."' onClick=\"window.open('$scriptname?sid=$newsid', '_top')\">\n";
Expand Down

0 comments on commit e9f29f2

Please sign in to comment.