you can now download the results of a select or report
authorchriskl <chriskl>
Mon, 25 Aug 2003 01:44:04 +0000 (01:44 +0000)
committerchriskl <chriskl>
Mon, 25 Aug 2003 01:44:04 +0000 (01:44 +0000)
BUGS
HISTORY
TODO
dataexport.php [new file with mode: 0644]
display.php
lang/english.php
lang/recoded/english.php
tables.php
tblproperties.php
views.php

diff --git a/BUGS b/BUGS
index e974d78a1292c2106cc27355da57d4fd820fd3cc..ca65bff8c028d046b8e4983220cd549def791916 100644 (file)
--- a/BUGS
+++ b/BUGS
@@ -1,5 +1,3 @@
-* Create trigger screen doesn't save fields if it fails creating trigger
-* XML output can't use field names as tag names...
 * Backport findObject to pre-7.3
 * Add db comments everywhere
 * Add owner everywhere
@@ -7,4 +5,7 @@
 * reports - unindexed fk's
          - slow indexes
 * Get table comments for pre-7.3
+* make getrowidentifier prefer unique indexes that don't allow nulls,
+  and don't use partial indexes
+* remove tblexport.php from cvs
 
diff --git a/HISTORY b/HISTORY
index faed154d7c1c08eea45fd82a896d8dd90b8400c9..457e4bc820f929e2888508dc33803e788497ccb1 100644 (file)
--- a/HISTORY
+++ b/HISTORY
@@ -32,6 +32,7 @@ Features:
 * 'Save as Report' feature when viewing record sets
 * Tick all box on Select feature
 * Export in HTML format
+* Download the results of selects and reports
 
 Bug Fixes:
 * Lots of NULL value in table dump fixes (XML format changed slightly)
diff --git a/TODO b/TODO
index ef66789688d79fe47c92d6dc761cbf6a82b77b71..b15f26337bfcabd1bd8f22ba226821d6558ed846 100644 (file)
--- a/TODO
+++ b/TODO
@@ -113,6 +113,8 @@ Settings
 Miscellaneous
 -------------
 
+* Allow simultaneous logins to different clusters (mark gibson)
+
 Exotic
 ------
 
diff --git a/dataexport.php b/dataexport.php
new file mode 100644 (file)
index 0000000..cee9019
--- /dev/null
@@ -0,0 +1,255 @@
+<?php
+
+       /**
+        * Does an export to the screen or as a download
+        *
+        * $Id: dataexport.php,v 1.1 2003/08/25 01:44:04 chriskl Exp $
+        */
+
+       $extensions = array(
+               'sql' => 'sql',
+               'copy' => 'sql',
+               'csv' => 'csv',
+               'tab' => 'txt',
+               'html' => 'html',
+               'xml' => 'xml'
+       );
+
+       // If format is set, then perform the download
+       if (isset($_REQUEST['format'])) {                
+                
+               // Make it do a download, if necessary
+               if (isset($_REQUEST['download'])) {
+                       header('Content-Type: application/download');
+       
+                       if (isset($extensions[$_REQUEST['format']]))
+                               $ext = $extensions[$_REQUEST['format']];
+                       else
+                               $ext = 'txt';
+       
+                       header('Content-Disposition: attachment; filename=dump.' . $ext);
+               }
+               else {
+                       header('Content-Type: text/plain');
+               }
+       
+               // Include application functions
+               $_no_output = true;
+               include_once('libraries/lib.inc.php');
+       
+               if (isset($_REQUEST['query'])) $_REQUEST['query'] = trim(unserialize($_REQUEST['query']));
+               if (isset($_REQUEST['table']) || $_REQUEST['query'] != '') {
+                       // Get database encoding
+                       $dbEncoding = $localData->getDatabaseEncoding();
+                       // Set fetch mode to NUM so that duplicate field names are properly returned
+                       $localData->conn->setFetchMode(ADODB_FETCH_NUM);
+                       // Execute the query, if set, otherwise grab all rows from the table
+                       if (isset($_REQUEST['table']))
+                               $rs = &$localData->dumpRelation($_REQUEST['table'], isset($_REQUEST['oids']));
+                       else
+                               $rs = $localData->conn->Execute($_REQUEST['query']);
+
+                       if ($_REQUEST['format'] == 'copy') {
+                               $data->fieldClean($_REQUEST['table']);
+                               echo "COPY \"{$_REQUEST['table']}\"";
+                               if (isset($_REQUEST['oids'])) echo " WITH OIDS";
+                               echo " FROM stdin;\n";
+                               while (!$rs->EOF) {
+                                       $first = true;
+                                       while(list($k, $v) = each($rs->f)) {
+                                               // Escape value
+                                               // addCSlashes converts all weird ASCII characters to octal representation,
+                                               // EXCEPT the 'special' ones like \r \n \t, etc.
+                                               $v = addCSlashes($v, "\0..\37\177..\377");
+                                               // We add an extra escaping slash onto octal encoded characters
+                                               $v = ereg_replace('\\\\([0-7]{3})', '\\\\\1', $v);
+                                               if ($first) {
+                                                       echo ($v == null) ? '\\N' : $v;
+                                                       $first = false;
+                                               }
+                                               else echo "\t", ($v == null) ? '\\N' : $v;
+                                       }
+                                       echo "\n";
+                                       $rs->moveNext();
+                               }
+                               echo "\\.\n";
+                       }
+                       elseif ($_REQUEST['format'] == 'html') {
+                               echo "<html>\r\n";
+                               echo "<head>\r\n";
+                               echo "\t<meta http-equiv=\"Content-Type\" content=\"text/html; charset={$localData->codemap[$dbEncoding]}\" />\r\n";
+                               echo "</head>\r\n";
+                               echo "<body>\r\n";
+                               echo "<table class=\"phppgadmin\">\r\n";
+                               echo "\t<tr>\r\n";
+                               if (!$rs->EOF) {
+                                       // Output header row
+                                       $j = 0;
+                                       foreach ($rs->f as $k => $v) {
+                                               $finfo = $rs->fetchField($j++);
+                                               if ($finfo->name == $localData->id && !isset($_REQUEST['oids'])) continue;
+                                               echo "\t\t<th>", $misc->printVal($finfo->name, true), "</th>\r\n";
+                                       }
+                               }
+                               echo "\t</tr>\r\n";
+                               while (!$rs->EOF) {
+                                       echo "\t<tr>\r\n";
+                                       $j = 0;
+                                       foreach ($rs->f as $k => $v) {
+                                               $finfo = $rs->fetchField($j++);
+                                               if ($finfo->name == $localData->id && !isset($_REQUEST['oids'])) continue;
+                                               echo "\t\t<td>", $misc->printVal($v, true, $finfo->type), "</td>\r\n";
+                                       }
+                                       echo "\t</tr>\r\n";
+                                       $rs->moveNext();
+                               }
+                               echo "</table>\r\n";
+                               echo "</body>\r\n";
+                               echo "</html>\r\n";
+                       }
+                       elseif ($_REQUEST['format'] == 'xml') {
+                               echo "<?xml version=\"1.0\"";
+                               if (isset($localData->codemap[$dbEncoding]))
+                                       echo " encoding=\"{$localData->codemap[$dbEncoding]}\"";
+                               echo " ?>\n";
+                               echo "<records>\n";
+                               if (!$rs->EOF) {
+                                       // Output header row
+                                       $j = 0;
+                                       echo "\t<header>\n";
+                                       foreach ($rs->f as $k => $v) {
+                                               $finfo = $rs->fetchField($j++);
+                                               $name = htmlspecialchars($finfo->name);
+                                               $type = htmlspecialchars($finfo->type);
+                                               echo "\t\t<column name=\"{$name}\" type=\"{$type}\" />\n";
+                                       }
+                                       echo "\t</header>\n";
+                               }
+                               while (!$rs->EOF) {
+                                       $j = 0;
+                                       echo "\t<row>\n";
+                                       foreach ($rs->f as $k => $v) {
+                                               $finfo = $rs->fetchField($j++);
+                                               $name = htmlspecialchars($finfo->name);
+                                               if ($v != null) $v = htmlspecialchars($v);
+                                               echo "\t\t<column name=\"{$name}\"", ($v == null ? ' null="null"' : ''), ">{$v}</column>\n";
+                                       }
+                                       echo "\t</row>\n";
+                                       $rs->moveNext();
+                               }
+                               echo "</records>\n";
+                       }
+                       elseif ($_REQUEST['format'] == 'sql') {
+                               $data->fieldClean($_REQUEST['table']);
+                               while (!$rs->EOF) {
+                                       echo "INSERT INTO \"{$_REQUEST['table']}\" (";
+                                       $first = true;
+                                       $j = 0;
+                                       foreach ($rs->f as $k => $v) {
+                                               $finfo = $rs->fetchField($j++);
+                                               $k = $finfo->name;
+                                               // SQL (INSERT) format cannot handle oids
+//                                             if ($k == $localData->id) continue;
+                                               // Output field
+                                               $data->fieldClean($k);
+                                               if ($first) echo "\"{$k}\"";
+                                               else echo ", \"{$k}\"";
+                                               
+                                               if ($v != null) {
+                                                       // Output value
+                                                       // addCSlashes converts all weird ASCII characters to octal representation,
+                                                       // EXCEPT the 'special' ones like \r \n \t, etc.
+                                                       $v = addCSlashes($v, "\0..\37\177..\377");
+                                                       // We add an extra escaping slash onto octal encoded characters
+                                                       $v = ereg_replace('\\\\([0-7]{3})', '\\\1', $v);
+                                                       // Finally, escape all apostrophes
+                                                       $v = str_replace("'", "''", $v);
+                                               }
+                                               if ($first) {
+                                                       $values = ($v === null) ? 'NULL' : "'{$v}'";
+                                                       $first = false;
+                                               }
+                                               else $values .= ', ' . (($v === null) ? 'NULL' : "'{$v}'");
+                                       }
+                                       echo ") VALUES ({$values});\n";
+                                       $rs->moveNext();
+                               }
+                       }
+                       else {
+                               switch ($_REQUEST['format']) {
+                                       case 'tab':
+                                               $sep = "\t";
+                                               break;
+                                       case 'csv':
+                                       default:
+                                               $sep = ',';
+                                               break;
+                               }
+                               if (!$rs->EOF) {
+                                       // Output header row
+                                       $first = true;
+                                       foreach ($rs->f as $k => $v) {                                          
+                                               $finfo = $rs->fetchField($k);
+                                               $v = $finfo->name;
+                                               if ($v != null) $v = str_replace('"', '""', $v);
+                                               if ($first) {
+                                                       echo "\"{$v}\"";
+                                                       $first = false;
+                                               }
+                                               else echo "{$sep}\"{$v}\"";
+                                       }
+                                       echo "\r\n";
+                               }
+                               while (!$rs->EOF) {
+                                       $first = true;
+                                       foreach ($rs->f as $k => $v) {
+                                               if ($v != null) $v = str_replace('"', '""', $v);
+                                               if ($first) {
+                                                       echo ($v == null) ? "\"\\N\"" : "\"{$v}\"";
+                                                       $first = false;
+                                               }
+                                               else echo ($v == null) ? "{$sep}\"\\N\"" : "{$sep}\"{$v}\"";
+                                       }
+                                       echo "\r\n";
+                                       $rs->moveNext();
+                               }
+                       }
+               }
+       }
+       else {
+               if (!isset($msg)) $msg = null;
+               
+               // Include application functions
+               include_once('libraries/lib.inc.php');
+
+               $misc->printHeader($lang['strexport']);         
+               echo "<h2>", $misc->printVal($_REQUEST['database']), ": {$lang['strexport']}</h2>\n";
+               $misc->printMsg($msg);
+
+               echo "<form action=\"{$_SERVER['PHP_SELF']}\" method=\"post\">\n";
+               echo "<table>\n";
+               echo "<tr><th class=\"data\">{$lang['strformat']}:</th><td><select name=\"format\">\n";
+               // COPY and SQL require a table
+               if (isset($_REQUEST['table'])) {
+                       echo "<option value=\"copy\">COPY</option>\n";
+                       echo "<option value=\"sql\">SQL</option>\n";
+               }
+               echo "<option value=\"csv\">CSV</option>\n";
+               echo "<option value=\"tab\">Tabbed</option>\n";
+               echo "<option value=\"html\">HTML</option>\n";
+               echo "<option value=\"xml\">XML</option>\n";
+               echo "</select></td></tr>";
+               echo "<tr><th class=\"data\">{$lang['strdownload']}</th><td><input type=\"checkbox\" name=\"download\" /></td></tr>";
+               echo "</table>\n";
+
+               echo "<p><input type=\"hidden\" name=\"action\" value=\"export\" />\n";
+               if (isset($_REQUEST['table'])) {
+                       echo "<input type=\"hidden\" name=\"table\" value=\"", htmlspecialchars($_REQUEST['table']), "\" />\n";
+               }
+               echo "<input type=\"hidden\" name=\"query\" value=\"", htmlspecialchars(serialize($_REQUEST['query'])), "\" />\n";
+               echo $misc->form;
+               echo "<input type=\"submit\" value=\"{$lang['strexport']}\" /></p>\n";
+               echo "</form>\n";
+       }       
+
+?>
index 3a85fb8a86ed8d093cdbc9f66b030ba270f4ee8d..5b0df0aed6f3eb2a60d43ee94f3b19b5e9d6260b 100644 (file)
@@ -9,7 +9,7 @@
         * @param $return_desc The return link name
         * @param $page The current page
         *
-        * $Id: display.php,v 1.23 2003/08/18 08:20:43 chriskl Exp $
+        * $Id: display.php,v 1.24 2003/08/25 01:44:04 chriskl Exp $
         */
 
        // Include application functions
        echo "<p><a class=\"navlink\" href=\"{$_REQUEST['return_url']}\">{$_REQUEST['return_desc']}</a>";
        if ($conf['show_reports'] && is_object($rs) && $rs->recordCount() > 0) {
                echo " | <a class=\"navlink\" href=\"reports.php?action=create&db_name=", urlencode($_REQUEST['database']), "&report_sql=",
-                       urlencode($_REQUEST['query']), "\">Save As Report</a></p>\n";
+                       urlencode($_REQUEST['query']), "\">{$lang['strsaveasreport']}</a>\n";
        }
+       if (is_object($rs) && $rs->recordCount() > 0) {
+               echo " | <a class=\"navlink\" href=\"dataexport.php?query=",
+                               urlencode($_REQUEST['query']), "&{$misc->href}\">{$lang['strdownload']}</a>\n"; 
+       }               
        echo "</p>\n";
 
        $misc->printFooter();
index a4a89e93d8b936ce5ac02113ec8d326b8ad15605..29d1202b19a38c8ce0d3aa5f2e07848082a08f07 100755 (executable)
@@ -4,7 +4,7 @@
         * English language file for phpPgAdmin.  Use this as a basis
         * for new translations.
         *
-        * $Id: english.php,v 1.97 2003/08/12 03:27:20 chriskl Exp $
+        * $Id: english.php,v 1.98 2003/08/25 01:44:04 chriskl Exp $
         */
 
        // Language and character set
        $lang['strrefresh'] = 'Refresh';
        $lang['strtaller'] = 'Taller';
        $lang['strshorter'] = 'Shorter';
+       $lang['strdownload'] = 'Download';
 
        // Error handling
        $lang['strnoframes'] = 'You need a frames-enabled browser to use this application.';
        $lang['strreportneedsdef'] = 'You must give SQL for your report.';
        $lang['strreportcreated'] = 'Report saved.';
        $lang['strreportcreatedbad'] = 'Failed to save report.';
+       $lang['strsaveasreport'] = 'Save as Report';
 
        // Domains
        $lang['strdomain'] = 'Domain';
index 5f6cce02c9be7333bbc6429473093736e4830305..9e880d50070e3a9d65096d88c6d3cddee7c30419 100644 (file)
@@ -4,7 +4,7 @@
         * English language file for phpPgAdmin.  Use this as a basis
         * for new translations.
         *
-        * $Id: english.php,v 1.49 2003/08/12 03:27:20 chriskl Exp $
+        * $Id: english.php,v 1.50 2003/08/25 01:44:04 chriskl Exp $
         */
 
        // Language and character set
        $lang['strrefresh'] = 'Refresh';
        $lang['strtaller'] = 'Taller';
        $lang['strshorter'] = 'Shorter';
+       $lang['strdownload'] = 'Download';
 
        // Error handling
        $lang['strnoframes'] = 'You need a frames-enabled browser to use this application.';
        $lang['strreportneedsdef'] = 'You must give SQL for your report.';
        $lang['strreportcreated'] = 'Report saved.';
        $lang['strreportcreatedbad'] = 'Failed to save report.';
+       $lang['strsaveasreport'] = 'Save as Report';
 
        // Domains
        $lang['strdomain'] = 'Domain';
index 20a54060da9e80cd2d86f556a0845e355dbf318a..64b62e728c65ba387826d0a3943259c2adf4b286 100644 (file)
@@ -3,7 +3,7 @@
        /**
         * List tables in a database
         *
-        * $Id: tables.php,v 1.32 2003/08/19 04:04:12 chriskl Exp $
+        * $Id: tables.php,v 1.33 2003/08/25 01:44:04 chriskl Exp $
         */
 
        // Include application functions
 
                        $attrs = &$localData->getTableAttributes($_REQUEST['table']);
 
-                       echo "<form action=\"$PHP_SELF\" method=\"post\" name=\"selectform\">\n";
+                       echo "<form action=\"$PHP_SELF\" method=\"get\" name=\"selectform\">\n";
                        if ($attrs->recordCount() > 0) {
                                // JavaScript for select all feature
                                echo "<script language=\"JavaScript\">\n";
                        echo "</form>\n";
                }
                else {
-                       if (!isset($_POST['show'])) $_POST['show'] = array();
-                       if (!isset($_POST['values'])) $_POST['values'] = array();
-                       if (!isset($_POST['nulls'])) $_POST['nulls'] = array();
+                       if (!isset($_GET['show'])) $_GET['show'] = array();
+                       if (!isset($_GET['values'])) $_GET['values'] = array();
+                       if (!isset($_GET['nulls'])) $_GET['nulls'] = array();
                        
-                       if (sizeof($_POST['show']) == 0)
+                       if (sizeof($_GET['show']) == 0)
                                doSelectRows(true, $lang['strselectneedscol']);
                        else {
                                // Generate query SQL
-                               $query = $localData->getSelectSQL($_REQUEST['table'], array_keys($_POST['show']),
-                                       $_POST['values'], array_keys($_POST['nulls']));
+                               $query = $localData->getSelectSQL($_REQUEST['table'], array_keys($_GET['show']),
+                                       $_GET['values'], array_keys($_GET['nulls']));
                                $_REQUEST['query'] = $query;
                                $_REQUEST['return_url'] = "tables.php?action=confselectrows&{$misc->href}&table={$_REQUEST['table']}";
                                $_REQUEST['return_desc'] = $lang['strback'];
index 92f01390957855e019ab687ec97cead39f49a8c7..7510e45dcd2041bed6ae5de04b68f2a6a87d2139 100644 (file)
@@ -3,7 +3,7 @@
        /**
         * List tables in a database
         *
-        * $Id: tblproperties.php,v 1.22 2003/08/21 04:49:36 chriskl Exp $
+        * $Id: tblproperties.php,v 1.23 2003/08/25 01:44:04 chriskl Exp $
         */
 
        // Include application functions
@@ -94,7 +94,7 @@
                echo "<h2>", $misc->printVal($_REQUEST['database']), ": ", $misc->printVal($_REQUEST['table']), ": {$lang['strexport']}</h2>\n";
                $misc->printMsg($msg);
 
-               echo "<form action=\"tblexport.php\" method=\"post\">\n";
+               echo "<form action=\"dataexport.php\" method=\"post\">\n";
                echo "<table>\n";
                echo "<tr><th class=\"data\">{$lang['strformat']}:</th><td><select name=\"format\">\n";
                echo "<option value=\"copy\">COPY</option>\n";
                echo "<p><input type=\"hidden\" name=\"action\" value=\"export\" />\n";
                echo $misc->form;
                echo "<input type=\"hidden\" name=\"table\" value=\"", htmlspecialchars($_REQUEST['table']), "\" />\n";
-               echo "<input type=\"submit\" value=\"{$lang['strexport']}\" /> <input type=\"reset\" value=\"{$lang['strreset']}\" /></p>\n";
+               echo "<input type=\"submit\" value=\"{$lang['strexport']}\" /></p>\n";
                echo "</form>\n";
        }
 
index 9f08213b5e5de3a07d9e94c739d1a73aaba8859b..6104ba32903cd0796ea02c7fca693a7b759cabb7 100644 (file)
--- a/views.php
+++ b/views.php
@@ -3,7 +3,7 @@
        /**
         * Manage views in a database
         *
-        * $Id: views.php,v 1.17 2003/08/18 08:27:07 chriskl Exp $
+        * $Id: views.php,v 1.18 2003/08/25 01:44:04 chriskl Exp $
         */
 
        // Include application functions
@@ -94,7 +94,7 @@
                        }
                }
 
-}
+       }
        
        /** 
         * Function to save after editing a view