From b677ac7ecb8eef0733145e5af4024f77256a0da4 Mon Sep 17 00:00:00 2001 From: Jason Cleeland Date: Thu, 29 Jan 2004 11:05:29 +0000 Subject: [PATCH] Added functionality: outer join with tokens table where appropriate (ie: survey not anonymous, tokens table exists). User given option of adding first name, last name, email, attribute_1 and attribute_2 to survey export. git-svn-id: file:///Users/Shitiz/Downloads/lssvn/trunk/unstable@858 b72ed6b6-b9f8-46b5-92b4-906544132732 --- admin/export.php | 215 ++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 185 insertions(+), 30 deletions(-) diff --git a/admin/export.php b/admin/export.php index b165dc27c4b..27c12118ebd 100644 --- a/admin/export.php +++ b/admin/export.php @@ -46,40 +46,51 @@ sendcacheheaders(); echo $htmlheader ."
\n" + ."" + ."\n" + .""; + //FIND OUT HOW MANY FIELDS WILL BE NEEDED - FOR 255 COLUMN LIMIT + $query="SELECT * FROM {$dbprefix}survey_$sid LIMIT 1"; + $result=mysql_query($query) or die("Couldn't count fields
$query
".mysql_error()); + $afieldcount=mysql_num_fields($result); + $query="SELECT private FROM {$dbprefix}surveys WHERE sid=$sid"; //Find out if tokens are used + $result=mysql_query($query) or die("Couldn't get privacy data
$query
".mysql_error()); + while ($rows = mysql_fetch_array($result)) {$surveyprivate=$rows['private'];} + if ($surveyprivate == "N") + { + $query="SHOW TABLES LIKE '{$dbprefix}tokens_$sid'"; //SEE IF THERE IS AN ASSOCIATED TOKENS TABLE + $result=mysql_query($query) or die("Couldn't get table list
$query
".mysql_error()); + $tablecount=mysql_num_rows($result); + } + if ($afieldcount > 255 || $tablecount > 0) //Do second column + { + //OPTIONAL EXTRAS (FROM TOKENS TABLE) + if ($tablecount > 0) + { + echo ""; + } + } + + echo "" + ."\t\n" + ."
\n" ."\n" - ."\t\n" - ."\t\n" - ."\t\n" + echo "\n" + ."\t\n" ."\t\n" ."\t\t\n" ."\t\n" - ."\t\n" + ."\t\n" ."\t\n" ."\t\t\n" ."\t\n" - ."\t\n" + ."\t\n" ."\t\n" ."\t\t\n" ."\t\n" @@ -97,20 +108,79 @@ .stripcslashes($_POST['sql']) ."\">\n"; } - echo "\t\n" - ."\t\n" + echo "\t\n" ."\t\t\n" ."\t\n" ."
" + ."\t
" + ."" ._EXPORTRESULTS; if (isset($_POST['sql'])) {echo " ("._EX_FROMSTATS.")";} - echo "
"._EX_HEADINGS."
$setfont" + ._EX_HEADINGS."
\n" - ."\t\t\t$setfont
" - ._EX_ANSWERS."
$setfont" + ._EX_ANSWERS."
\n" - ."\t\t\t$setfont
" - ._EX_FORMAT."
$setfont" + ._EX_FORMAT."
\n" - ."\t\t\t$setfont
\n" ."\t\t\t\n" ."\t\t
\n" - ."
\n" + ."
\n" + ."" + ."\t\n" + ."\t\t\n" + ."\t\n" + ."\t\n" + ."\t\t\n" + ."\t\n" + ."\t\n" + ."\t\t\n" + ."\t\n" + ."
" + ."Token Options\n" + ."\t\t
$setfont\n" + ."Include Token Fields:" + ."\t\t
$setfont" + ."" + ."
\n" + ."" + ."
\n" + ."" + ."
\n"; + $query = "SELECT * FROM {$dbprefix}tokens_$sid LIMIT 1"; //SEE IF TOKENS TABLE HAS ATTRIBUTE FIELDS + $result = mysql_query($query) or die ($query."
".mysql_error()); + $rowcount = mysql_num_fields($result); + if ($rowcount > 7) + { + echo "" + ."
\n" + ."" + ."
\n"; + } + echo "\t\t
" + ."

\n" .htmlfooter("instructions.html", "General PHPSurveyor Instructions") ."\n"; exit; } +//HERE WE EXPORT THE ACTUAL RESULTS + if ($type == "doc") { header("Content-Disposition: attachment; filename=survey.doc"); @@ -133,12 +203,7 @@ { header("Content-Disposition: attachment; filename=survey.doc"); } -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"); - // always modified -header("Cache-Control: no-store, no-cache, must-revalidate"); // HTTP/1.1 -header("Cache-Control: post-check=0, pre-check=0", false); -header("Pragma: no-cache"); // HTTP/1.0 +sendcacheheaders(); //Select public language file $query = "SELECT language FROM {$dbprefix}surveys WHERE sid=$sid"; @@ -159,10 +224,38 @@ $legitqs[] = $lw['qid']; //this creates an array of question id's' } -//Get the fieldnames from the survey table +//Get the fieldnames from the survey table for column headings $surveytable = "{$dbprefix}survey_$sid"; -$dquery = "SELECT * FROM $surveytable ORDER BY id LIMIT 1"; -$dresult = mysql_query($dquery); +$dquery = "SELECT $surveytable.*"; +if (isset($_POST['first_name']) && $_POST['first_name']=="on") + { + $dquery .= ", {$dbprefix}tokens_$sid.firstname"; + } +if (isset($_POST['last_name']) && $_POST['last_name']=="on") + { + $dquery .= ", {$dbprefix}tokens_$sid.lastname"; + } +if (isset($_POST['email_address']) && $_POST['email_address']=="on") + { + $dquery .= ", {$dbprefix}tokens_$sid.email"; + } +if (isset($_POST['attribute_1']) && $_POST['attribute_1']=="on") + { + $dquery .= ", {$dbprefix}tokens_$sid.attribute_1"; + } +if (isset($_POST['attribute_2']) && $_POST['attribute_2']=="on") + { + $dquery .= ", {$dbprefix}tokens_$sid.attribute_2"; + } +$dquery .= " FROM $surveytable"; +if ((isset($_POST['attribute_1']) && $_POST['attribute_1']=="on") || (isset($_POST['attribute_2']) && $_POST['attribute_2']=="on") || (isset($_POST['email_address']) && $_POST['email_address']=="on")) + { + $dquery .= "" + . " LEFT OUTER JOIN {$dbprefix}tokens_$sid" + . " ON $surveytable.token = {$dbprefix}tokens_$sid.token"; + } +$dquery .=" ORDER BY id LIMIT 1"; +$dresult = mysql_query($dquery) or die(_ERROR." getting results
$dquery
".mysql_error()); $fieldcount = mysql_num_fields($dresult); $firstline=""; for ($i=0; $i<$fieldcount; $i++) @@ -170,7 +263,17 @@ $fieldinfo=mysql_field_name($dresult, $i); if ($fieldinfo == "token") { - if ($answers == "short") {if ($type == "csv") {$firstline.="\"Token\"$s";} else {$firstline .= "Token$s";}} + if ($answers == "short") + { + if ($type == "csv") + { + $firstline.="\"Token\"$s"; + } + else + { + $firstline .= "Token$s"; + } + } if ($answers == "long") { if ($style == "abrev") @@ -185,6 +288,31 @@ } } } + elseif ($fieldinfo == "lastname") + { + if ($type == "csv") {$firstline .= "\""._TL_LAST."\"$s";} + else {$firstline .= _TL_LAST."$s";} + } + elseif ($fieldinfo == "firstname") + { + if ($type == "csv") {$firstline .= "\""._TL_FIRST."\"$s";} + else {$firstline .= _TL_FIRST."$s";} + } + elseif ($fieldinfo == "email") + { + if ($type == "csv") {$firstline .= "\""._EMAIL."\"$s";} + else {$firstline .= _EMAIL."$s";} + } + elseif ($fieldinfo == "attribute_1") + { + if ($type == "csv") {$firstline .= "\"attr1\"$s";} + else {$firstline .= _TL_ATTR1."$s";} + } + elseif ($fieldinfo == "attribute_2") + { + if ($type == "csv") {$firstline .= "\"attr2\"$s";} + else {$firstline .= _TL_ATTR2."$s";} + } elseif ($fieldinfo == "id") { if ($type == "csv") {$firstline .= "\"id\"$s";} @@ -347,10 +475,9 @@ } } -//$firstline = substr($firstline, 0, strlen($firstline)-1); $firstline = trim($firstline); $firstline .= "\n"; -echo $firstline; +echo $firstline; //Sending the header row //Now dump the data @@ -359,6 +486,34 @@ if ($_POST['sql'] == "NULL") {$dquery = "SELECT * FROM $surveytable ORDER BY id";} else {$dquery = "SELECT * FROM $surveytable WHERE ".stripcslashes($_POST['sql'])." ORDER BY id";} } +elseif ((isset($_POST['attribute_1']) && $_POST['attribute_1']=="on") || (isset($_POST['attribute_2']) && $_POST['attribute_2'] == "on") || (isset($_POST['email_address']) && $_POST['email_address'] == "on")) + { + $dquery = "SELECT $surveytable.*"; + if (isset($_POST['first_name']) && $_POST['first_name']=="on") + { + $dquery .= ", {$dbprefix}tokens_$sid.firstname"; + } + if (isset($_POST['last_name']) && $_POST['last_name']=="on") + { + $dquery .= ", {$dbprefix}tokens_$sid.lastname"; + } + if (isset($_POST['email_address']) && $_POST['email_address']=="on") + { + $dquery .= ", {$dbprefix}tokens_$sid.email"; + } + if (isset($_POST['attribute_1']) && $_POST['attribute_1']=="on") + { + $dquery .= ", {$dbprefix}tokens_$sid.attribute_1"; + } + if (isset($_POST['attribute_2']) && $_POST['attribute_2']=="on") + { + $dquery .= ", {$dbprefix}tokens_$sid.attribute_2"; + } + $dquery .= " FROM $surveytable " + . "LEFT OUTER JOIN {$dbprefix}tokens_$sid " + . "ON $surveytable.token={$dbprefix}tokens_$sid.token " + . "ORDER BY $surveytable.id"; + } else // this applies for exporting everything { $dquery = "SELECT * FROM $surveytable ORDER BY id";