Skip to content

Commit

Permalink
Changed database column references from numeric to associative.
Browse files Browse the repository at this point in the history
Cleaned up HTML tags.-JAR


git-svn-id: file:///Users/Shitiz/Downloads/lssvn/trunk/unstable@26 b72ed6b6-b9f8-46b5-92b4-906544132732
  • Loading branch information
Miguel E. Guajardo committed Mar 15, 2003
1 parent d382191 commit 0e1f23c
Showing 1 changed file with 93 additions and 66 deletions.
159 changes: 93 additions & 66 deletions admin/export.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,27 +44,54 @@
header("Pragma: no-cache"); // HTTP/1.0
include ("config.php");
echo "$htmlheader";
echo "<TABLE WIDTH='350' ALIGN='CENTER'><TR><TD ALIGN='CENTER'>$setfont<B>Export Data</TD></TR>\n";
echo "<FORM ACTION='export.php' METHOD='post'>";
echo "<TR><TD HEIGHT='2' BGCOLOR='SILVER'></TD></TR>\n";
echo "<TR><TD>$setfont<INPUT TYPE='radio' CHECKED NAME='style' VALUE='abrev'>Abreviated Headings<BR>";
echo "<INPUT TYPE='radio' NAME='style' VALUE='full'>Full question headings</TD></TR>\n";
echo "<TR><TD HEIGHT='2' BGCOLOR='SILVER'></TD></TR>\n";
echo "<TR><TD>$setfont<INPUT TYPE='radio' CHECKED NAME='answers' VALUE='short'>Brief Answers<BR>";
echo "<INPUT TYPE='radio' NAME='answers' VALUE='long'>Extended Answers</TD></TR>\n";
echo "<TR><TD HEIGHT='2' BGCOLOR='SILVER'></TD></TR>\n";
echo "<TR><TD>$setfont<INPUT TYPE='radio' CHECKED NAME='type' VALUE='doc'>Microsoft Word Format<BR>";
echo "<INPUT TYPE='radio' NAME='type' VALUE='xls' checked>Microsoft Excel Format<BR>\n";
echo "<INPUT TYPE='radio' NAME='type' VALUE='csv'>CSV Comma Delimited Format</TD></TR>\n";
echo "<TR><TD HEIGHT='2' BGCOLOR='SILVER'></TD></TR>\n";
echo "<TR><TD ALIGN='CENTER'>$setfont<INPUT TYPE='SUBMIT' VALUE='Export Data'></TD></TR>\n";
echo "<INPUT TYPE='HIDDEN' NAME='sid' VALUE='$sid'></FORM>";
echo "<TR><TD ALIGN=\"CENTER\"><INPUT TYPE='SUBMIT' VALUE='Close' onClick=\"window.close()\"></TD></TR>\n";
echo "</TABLE>\n";
echo "<table width='350' align='center'>\n";
echo "\t<tr>\n";
echo "\t\t<td align='center'>\n";
echo "\t\t\t$setfont<b>Export Data</b>\n";
echo "\t\t</td>\n";
echo "\t</tr>\n";
echo "\t<form action='export.php' method='post'>\n";
echo "\t<tr><td height='2' bgcolor='silver'></td></tr>\n";
echo "\t<tr>\n";
echo "\t\t<td>\n";
echo "\t\t\t$setfont<input type='radio' checked name='style' value='abrev'>Abreviated Headings<br />\n";
echo "\t\t\t<input type='radio' name='style' value='full'>Full question headings\n";
echo "\t\t</td>\n";
echo "\t</tr>\n";
echo "\t<tr><td height='2' bgcolor='silver'></td></tr>\n";
echo "\t<tr>\n";
echo "\t\t<td>\n";
echo "\t\t\t$setfont<input type='radio' checked name='answers' value='short'>Brief Answers<br />\n";
echo "\t\t\t<input type='radio' name='answers' value='long'>Extended Answers\n";
echo "\t\t</td>\n";
echo "\t</tr>\n";
echo "\t<tr><td height='2' bgcolor='silver'></td></tr>\n";
echo "\t<tr>\n";
echo "\t\t<td>\n";
echo "\t\t\t$setfont<input type='radio' checked name='type' value='doc'>Microsoft Word Format<br />\n";
echo "\t\t\t<input type='radio' name='type' value='xls' checked>Microsoft Excel Format<br />\n";
echo "\t\t\t<input type='radio' name='type' value='csv'>CSV Comma Delimited Format\n";
echo "\t\t</td>\n";
echo "\t</tr>\n";
echo "\t<tr><td height='2' bgcolor='silver'></td></tr>\n";
echo "\t<tr>\n";
echo "\t\t<td align='center'>\n";
echo "\t\t\t$setfont<input type='submit' value='Export Data'>\n";
echo "\t\t</td>\n";
echo "\t</tr>\n";
echo "\t<input type='hidden' name='sid' value='$sid'>\n";
echo "\t</form>\n";
echo "\t<tr>\n";
echo "\t\t<td align=\"center\">\n";
echo "\t\t\t<input type='submit' value='Close' onClick=\"window.close()\">\n";
echo "\t\t</td>\n";
echo "\t</tr>\n";
echo "</table>\n";
echo "</body>\n</html>";
}
else
{
//header ("Content-Type: application/vnd.ms-excel"); //EXCEL FILE
//header("Content-Type: application/vnd.ms-excel"); //EXCEL FILE
//header("Content-Type: application/msword"); //EXPORT INTO MSWORD
if ($type == "doc") {header("Content-Disposition: attachment; filename=survey.doc");}
elseif ($type == "xls") {header("Content-Disposition: attachment; filename=survey.xls");}
Expand All @@ -82,61 +109,61 @@
//STEP 1: First line is column headings
$cquery = "SELECT * FROM questions, groups WHERE questions.gid=groups.gid AND questions.sid=$sid ORDER BY group_name, title";
$cresult = mysql_query($cquery);
$s="\t";
$s = "\t";
$firstline = "id$s ";
while ($crow = mysql_fetch_row($cresult))
while ($crow = mysql_fetch_array($cresult))
{
if ($style == "abrev")
{
if ($crow[3] != "M" && $crow[3] != "A" && $crow[3] != "B" && $crow[3] != "C" && $crow[3] != "P" && $crow[3] != "O")
if ($crow['type'] != "M" && $crow['type'] != "A" && $crow['type'] != "B" && $crow['type'] != "C" && $crow['type'] != "P" && $crow['type'] != "O")
{
$firstline .= "Grp$crow[1]Qst$crow[4]$s ";
$firstline .= "Grp{$crow['sid']}Qst{$crow['title']}$s ";
}
elseif ($crow[3] == "O")
elseif ($crow['type'] == "O")
{
$firstline .= "Grp$crow[1]Qst$crow[4]$s ";
$firstline .= "Grp$crow[1]Qst$crow[4][comment]$s ";
$firstline .= "Grp{$crow['sid']}Qst{$crow['title']}$s ";
$firstline .= "Grp{$crow['sid']}Qst{$crow['title']}[comment]$s ";
}
else
{
$i2query="SELECT answers.*, questions.other FROM answers, questions WHERE answers.qid=questions.qid AND questions.qid=$crow[0] AND questions.sid=$sid ORDER BY code";
$i2query="SELECT answers.*, questions.other FROM answers, questions WHERE answers.qid=questions.qid AND questions.qid={$crow['qid']} AND questions.sid=$sid ORDER BY code";
$i2result=mysql_query($i2query);
while ($i2row=mysql_fetch_row($i2result))
while ($i2row=mysql_fetch_array($i2result))
{
$firstline .= "Grp$crow[1]Qst$crow[4]Opt$i2row[1]$s ";
$firstline .= "Grp{$crow['sid']}Qst{$crow['title']}Opt$i2row[1]$s ";
if ($i2row[4] == "Y") {$otherexists="Y";}
if ($crow[3] == "P") {$firstline .= "Grp$crow[1]Qst$crow[4]Opt$i2row[1]comment$s ";}
if ($crow['type'] == "P") {$firstline .= "Grp{$crow['sid']}Qst{$crow['title']}Opt$i2row[1]comment$s ";}
}
if ($otherexists == "Y")
{
$firstline .= "Grp$crow[1]Qst$crow[4]OptOther$s ";
$firstline .= "Grp{$crow['sid']}Qst{$crow['title']}OptOther$s ";
}
}
}
elseif ($style == "full")
{
if ($crow[3] != "M" && $crow[3] != "A" && $crow[3] != "B" && $crow[3] != "C" && $crow[3] != "P" && $crow[3] != "O")
if ($crow['type'] != "M" && $crow['type'] != "A" && $crow['type'] != "B" && $crow['type'] != "C" && $crow['type'] != "P" && $crow['type'] != "O")
{
$firstline .= str_replace("<BR>", " ", str_replace("\r\n", " ", $crow[5]))."$s ";
$firstline .= str_replace("<BR>", " ", str_replace("\r\n", " ", $crow['question']))."$s ";
}
elseif ($crow[3] == "O")
elseif ($crow['type'] == "O")
{
$firstline .= str_replace("<BR>", " ", str_replace("\r\n", " ", $crow[5]))."$s ";
$firstline .= str_replace("<BR>", " ", str_replace("\r\n", " ", $crow[5]))."[Comment]$s ";
$firstline .= str_replace("<BR>", " ", str_replace("\r\n", " ", $crow['question']))."$s ";
$firstline .= str_replace("<BR>", " ", str_replace("\r\n", " ", $crow['question']))."[Comment]$s ";
}
else
{
$i2query="SELECT answers.*, questions.other FROM answers, questions WHERE answers.qid=questions.qid AND questions.qid=$crow[0] AND questions.sid=$sid ORDER BY code";
$i2result=mysql_query($i2query);
while ($i2row=mysql_fetch_row($i2result))
$i2query = "SELECT answers.*, questions.other FROM answers, questions WHERE answers.qid=questions.qid AND questions.qid={$crow['qid']} AND questions.sid=$sid ORDER BY code";
$i2result = mysql_query($i2query);
while ($i2row = mysql_fetch_array($i2result))
{
$firstline .= str_replace("<BR>", " ", str_replace("\r\n", " ", $crow[5])).": $i2row[2]$s ";
if ($i2row[4] == "Y") {$otherexists="Y";}
if ($crow[3] == "P") {$firstline .= str_replace("<BR>", " ", str_replace("\r\n", " ", $crow[5])).": $i2row[2](comment)$s ";}
$firstline .= str_replace("<BR>", " ", str_replace("\r\n", " ", $crow['question'])).": {$i2row['answer']}$s ";
if ($i2row['other'] == "Y") {$otherexists = "Y";}
if ($crow['type'] == "P") {$firstline .= str_replace("<BR>", " ", str_replace("\r\n", " ", $crow['question'])).": {$i2row['answer']}(comment)$s ";}
}
if ($otherexists == "Y")
{
$firstline .= str_replace("<BR>", " ", str_replace("\r\n", " ", $crow[5])).": Other$s ";
$firstline .= str_replace("<BR>", " ", str_replace("\r\n", " ", $crow['question'])).": Other$s ";
}
}
}
Expand All @@ -146,54 +173,54 @@
echo $firstline;

//Now dump the data
$lq="SELECT DISTINCT qid FROM questions WHERE sid=$sid";
$lr=mysql_query($lq);
$legitqs[]="DUMMY ENTRY";
while ($lw=mysql_fetch_row($lr))
$lq = "SELECT DISTINCT qid FROM questions WHERE sid=$sid";
$lr = mysql_query($lq);
$legitqs[] = "DUMMY ENTRY";
while ($lw = mysql_fetch_array($lr))
{
$legitqs[]=$lw[0];
$legitqs[] = $lw[0];
}
$surveytable="survey_{$sid}";
$surveytable = "survey_{$sid}";
$dquery = "SELECT * FROM $surveytable ORDER BY id";
$dresult = mysql_query($dquery);
$fieldcount = mysql_num_fields($dresult);
while ($drow = mysql_fetch_row($dresult))
while ($drow = mysql_fetch_array($dresult))
{
if ($answers == "short") {echo implode($s, str_replace("\r\n", " ", $drow)) . "\n";}
elseif ($answers == "long")
{
$i=0;
$i = 0;
for ($i; $i<$fieldcount; $i++)
{
list($fsid, $fgid, $fqid)=split("X",mysql_field_name($dresult, $i));
if (!$fqid) {$fqid=0;}
list($fsid, $fgid, $fqid) = split("X", mysql_field_name($dresult, $i));
if (!$fqid) {$fqid = 0;}
while (!in_array($fqid, $legitqs))
{
$fqid = substr($fqid, 0, strlen($fqid)-1);
}
$qq="SELECT type FROM questions WHERE qid=$fqid";
$qr=mysql_query($qq);
while ($qrow=mysql_fetch_row($qr))
{$ftype=$qrow[0];}
$qq = "SELECT type FROM questions WHERE qid=$fqid";
$qr = mysql_query($qq);
while ($qrow = mysql_fetch_array($qr))
{$ftype = $qrow['qid'];}
switch ($ftype)
{
case "L": //DROPDOWN LIST
$lq="SELECT * FROM answers WHERE qid=$fqid";
$lr=mysql_query($lq);
while ($lrow=mysql_fetch_row($lr))
$lq = "SELECT * FROM answers WHERE qid=$fqid";
$lr = mysql_query($lq);
while ($lrow = mysql_fetch_array($lr))
{
if ($lrow[1] == $drow[$i]) {echo $lrow[2];}
if ($lrow['code'] == $drow[$i]) {echo $lrow['answer'];}
}
break;
case "O": //DROPDOWN LIST WITH COMMENT
$lq="SELECT * FROM answers WHERE qid=$fqid";
$lr=mysql_query($lq);
while ($lrow=mysql_fetch_row($lr))
$lq = "SELECT * FROM answers WHERE qid=$fqid";
$lr = mysql_query($lq);
while ($lrow = mysql_fetch_array($lr))
{
if ($lrow[1] == $drow[$i]) {echo $lrow[2]; $found="Y";}
if ($lrow['code'] == $drow[$i]) {echo $lrow['answer']; $found = "Y";}
}
if ($found != "Y") {echo str_replace("\r\n", " ", $drow[$i]);}
$found="";
$found = "";
break;
case "Y": //YES\NO
switch($drow[$i])
Expand Down Expand Up @@ -223,7 +250,7 @@
echo str_replace("\r\n", " ", $drow[$i]);
}
echo "$s";
$ftype="";
$ftype = "";
}
echo "\n";
}
Expand Down

0 comments on commit 0e1f23c

Please sign in to comment.