Fixed export facilities.
authorjollytoad <jollytoad>
Tue, 29 Mar 2005 09:33:46 +0000 (09:33 +0000)
committerjollytoad <jollytoad>
Tue, 29 Mar 2005 09:33:46 +0000 (09:33 +0000)
Simplified dataexport.php to include dbexport.php rather than redirecting to it.
Now makes use of the common 'subject' req var to determine pg_dump/dumpall rather than the export specific 'mode' var.
Fixed setting of 'search_path' when exporting a query.

all_db.php
database.php
dataexport.php
dbexport.php
display.php
tblproperties.php
viewproperties.php

index cf202567aa886b3e858fb7eea5ef41902f023083..99df2beafee6229cd05d723501d4d702dd61ebaa 100644 (file)
@@ -3,7 +3,7 @@
        /**
         * Manage databases within a server
         *
-        * $Id: all_db.php,v 1.35.4.4 2005/03/22 09:29:43 jollytoad Exp $
+        * $Id: all_db.php,v 1.35.4.5 2005/03/29 09:33:46 jollytoad Exp $
         */
 
        // Include application functions
                echo "<br/><input type=\"radio\" name=\"output\" value=\"download\" />{$lang['strdownload']}</p>\n";
 
                echo "<p><input type=\"hidden\" name=\"action\" value=\"export\" />\n";
-               echo "<p><input type=\"hidden\" name=\"mode\" value=\"cluster\" />\n";          
+               echo "<p><input type=\"hidden\" name=\"subject\" value=\"server\" />\n";                
                echo $misc->form;
                echo "<input type=\"submit\" value=\"{$lang['strexport']}\" /></p>\n";
                echo "</form>\n";
index b1b37a808954569e70504437fe5281fd01edc8ea..35d46d20d1fade3cf8e460eac650f9b0f173b7ca 100755 (executable)
@@ -3,7 +3,7 @@
        /**
         * Manage schemas within a database
         *
-        * $Id: database.php,v 1.65.2.5 2005/03/22 09:29:43 jollytoad Exp $
+        * $Id: database.php,v 1.65.2.6 2005/03/29 09:33:47 jollytoad Exp $
         */
 
        // Include application functions
                }
                echo "</p>\n";
                echo "<p><input type=\"hidden\" name=\"action\" value=\"export\" />\n";
-               echo "<p><input type=\"hidden\" name=\"mode\" value=\"database\" />\n";         
+               echo "<input type=\"hidden\" name=\"subject\" value=\"database\" />\n";
                echo $misc->form;
                echo "<input type=\"submit\" value=\"{$lang['strexport']}\" /></p>\n";
                echo "</form>\n";
index 6f29571f5b98aa345b5a8fdcbadc10b296341a04..b68644885dc2b5bad88dd603cb8a912bf8da7a95 100644 (file)
@@ -4,7 +4,7 @@
         * Does an export to the screen or as a download.  This checks to
         * see if they have pg_dump set up, and will use it if possible.
         *
-        * $Id: dataexport.php,v 1.18 2005/02/09 11:26:24 chriskl Exp $
+        * $Id: dataexport.php,v 1.18.2.1 2005/03/29 09:33:47 jollytoad Exp $
         */
 
        $extensions = array(
@@ -15,7 +15,7 @@
                'html' => 'html',
                'xml' => 'xml'
        );
-
+       
        // Prevent timeouts on large exports
        set_time_limit(0);
 
        // What must we do in this case? Maybe redirect to the homepage?
 
        // If format is set, then perform the export
-       if (isset($_REQUEST['what'])) {          
-
+       if (isset($_REQUEST['what'])) {
+               
                // Include application functions
                $_no_output = true;
                include_once('./libraries/lib.inc.php');
-
+               
                switch ($_REQUEST['what']) {
                        case 'dataonly':
                                // Check to see if they have pg_dump set up and if they do, use that
                                // instead of custom dump code
                                if ($misc->isDumpEnabled()
                                                && ($_REQUEST['d_format'] == 'copy' || $_REQUEST['d_format'] == 'sql')) {
-                                       $url = 'dbexport.php?mode=database&database=' . urlencode($_REQUEST['database']);
-                                       $url .= '&what=' . urlencode($_REQUEST['what']);
-                                       $url .= '&table=' . urlencode($_REQUEST['table']);
-                                       if ($data->hasSchemas()) $url .= '&schema=' . urlencode($_REQUEST['schema']);
-                                       $url .= '&d_format=' . urlencode($_REQUEST['d_format']);
-                                       $url .= '&output=' . urlencode($_REQUEST['output']);
-                                       if (isset($_REQUEST['d_oids'])) $url .= '&d_oids=' . urlencode($_REQUEST['d_oids']);
-                                       $url .= "&" . SID;
-                                       
-                                       header("Location: {$url}");
+                                       include('./dbexport.php');
                                        exit;
                                }
                                else {
                                // Check to see if they have pg_dump set up and if they do, use that
                                // instead of custom dump code
                                if ($misc->isDumpEnabled()) {
-                                       $url = 'dbexport.php?mode=database&database=' . urlencode($_REQUEST['database']);
-                                       $url .= '&what=' . urlencode($_REQUEST['what']);
-                                       $url .= '&table=' . urlencode($_REQUEST['table']);
-                                       if ($data->hasSchemas()) $url .= '&schema=' . urlencode($_REQUEST['schema']);
-                                       $url .= '&output=' . urlencode($_REQUEST['output']);
-                                       if (isset($_REQUEST['s_clean'])) $url .= '&s_clean=' . urlencode($_REQUEST['s_clean']);
-                                       $url .= "&" . SID;
-                                       
-                                       header("Location: {$url}");
+                                       include('./dbexport.php');
                                        exit;
                                }
                                else $clean = isset($_REQUEST['s_clean']);
                                // Check to see if they have pg_dump set up and if they do, use that
                                // instead of custom dump code
                                if ($misc->isDumpEnabled()) {
-                                       $url = 'dbexport.php?mode=database&database=' . urlencode($_REQUEST['database']);
-                                       $url .= '&what=' . urlencode($_REQUEST['what']);
-                                       $url .= '&table=' . urlencode($_REQUEST['table']);
-                                       if ($data->hasSchemas()) $url .= '&schema=' . urlencode($_REQUEST['schema']);
-                                       $url .= '&sd_format=' . urlencode($_REQUEST['sd_format']);
-                                       $url .= '&output=' . urlencode($_REQUEST['output']);
-                                       if (isset($_REQUEST['sd_clean'])) $url .= '&sd_clean=' . urlencode($_REQUEST['sd_clean']);
-                                       if (isset($_REQUEST['sd_oids'])) $url .= '&sd_oids=' . urlencode($_REQUEST['sd_oids']);
-                                       $url .= "&" . SID;
-
-                                       header("Location: {$url}");
+                                       include('./dbexport.php');
                                        exit;
                                }
                                else {
                        if (strstr($_SERVER['HTTP_USER_AGENT'], 'MSIE') && isset($_SERVER['HTTPS'])) {
                                header('Content-Type: text/plain');
                        }
-                       else {\r
+                       else {
                                header('Content-Type: application/download');
                
                                if (isset($extensions[$format]))
        
                if (isset($_REQUEST['query'])) $_REQUEST['query'] = trim(unserialize($_REQUEST['query']));
 
+               // Set the schema search path
+               if ($data->hasSchemas() && isset($_REQUEST['search_path'])) {
+                       $data->setSearchPath(array_map('trim',explode(',',$_REQUEST['search_path'])));
+               }
+               
                // Set up the dump transaction
                $status = $data->beginDump();
 
                $status = $data->endDump();
        }
        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);
+               $misc->printHeader($lang['strexport']);
+               $misc->printBody();
+               $misc->printTrail(isset($_REQUEST['subject']) ? $_REQUEST['subject'] : 'database');
+               $misc->printTitle($lang['strexport']);
+               if (isset($msg)) $misc->printMsg($msg);
 
                echo "<form action=\"{$_SERVER['PHP_SELF']}\" method=\"post\">\n";
                echo "<table>\n";
                        echo "<input type=\"hidden\" name=\"table\" value=\"", htmlspecialchars($_REQUEST['table']), "\" />\n";
                }
                echo "<input type=\"hidden\" name=\"query\" value=\"", htmlspecialchars(serialize($_REQUEST['query'])), "\" />\n";
+               if (isset($_REQUEST['search_path'])) {
+                       echo "<input type=\"hidden\" name=\"search_path\" value=\"", htmlspecialchars($_REQUEST['search_path']), "\" />\n";
+               }
                echo $misc->form;
                echo "<input type=\"submit\" value=\"{$lang['strexport']}\" /></p>\n";
                echo "</form>\n";
index b5a6094441669d30aa9c923dec55a2defd964c6a..4c8949ae8b50b1d8e982cf8d5a4db5a655b15788 100644 (file)
@@ -3,7 +3,7 @@
         * Does an export of a database or a table (via pg_dump)
         * to the screen or as a download.
         *
-        * $Id: dbexport.php,v 1.17.2.1 2005/03/01 10:52:23 jollytoad Exp $
+        * $Id: dbexport.php,v 1.17.2.2 2005/03/29 09:33:47 jollytoad Exp $
         */
 
        // Prevent timeouts on large exports
                $server_info = $misc->getServerInfo();
                
                // Set environmental variable for user and password that pg_dump uses
-               putenv('PGPASSWORD=' . $server_info['password'];
-               putenv('PGUSER=' . $server_info['username'];
+               putenv('PGPASSWORD=' . $server_info['password']);
+               putenv('PGUSER=' . $server_info['username']);
 
                // Prepare command line arguments
                $hostname = $server_info['host'];
                $port = $server_info['port'];
                
-               // Check if we're doing a cluster-wide dump or just a per-database dump
-               if ($_REQUEST['mode'] == 'database') {
-                       // Get path of the pg_dump executable.
-                       $exe = $misc->escapeShellCmd($server_info['pg_dump_path']);
-               }
-               else {
-                       // Get path of the pg_dumpall executable.
-                       $exe = $misc->escapeShellCmd($server_info['pg_dumpall_path']);
-               }
+               // Are we doing a cluster-wide dump or just a per-database dump
+               $dumpall = ($_REQUEST['subject'] == 'server');
+               
+               // Get the path og the pg_dump/pg_dumpall executable
+               $exe = $misc->escapeShellCmd($server_info[$dumpall ? 'pg_dumpall_path' : 'pg_dump_path']);
                
                // Build command for executing pg_dump.  '-i' means ignore version differences.
                $cmd = $exe . " -i";
                        $cmd .= " -p " . $misc->escapeShellArg($port);
                }
                
-               // Check for a table specified
-               if (isset($_REQUEST['table']) && $_REQUEST['mode'] == 'database') {
-                       
+               // Check for a specified table/view
+               switch ($_REQUEST['subject']) {
+               case 'table':
+               case 'view':
                        // Obtain the pg_dump version number
                        $version = array();
                        preg_match("/(\d+(?:\.\d+)?)(?:\.\d+)?.*$/", exec($exe . " --version"), $version);
@@ -80,7 +77,7 @@
                        // set dump schema as well.  Also, mixed case dumping has been fixed
                        // then..
                        if (((float) $version[1]) >= 7.4) {
-                               $cmd .= " -t " . $misc->escapeShellArg($_REQUEST['table']);
+                               $cmd .= " -t " . $misc->escapeShellArg($_REQUEST[$_REQUEST['subject']]);
                                // Even though they're using a schema-enabled pg_dump, the backend database
                                // may not support schemas.
                                if ($data->hasSchemas()) {
                        else {
                                // This is an annoying hack needed to work around a bug in dumping
                                // mixed case tables in pg_dump prior to 7.4
-                               $cmd .= " -t " . $misc->escapeShellArg('"' . $_REQUEST['table'] . '"');
+                               $cmd .= " -t " . $misc->escapeShellArg('"' . $_REQUEST[$_REQUEST['subject']] . '"');
                        }
                }
 
                // Check for GZIP compression specified
-               if ($_REQUEST['output'] == 'gzipped' && $_REQUEST['mode'] == 'database') {
+               if ($_REQUEST['output'] == 'gzipped' && !$dumpall) {
                        $cmd .= " -Z 9";
                }
                                
                                break;
                }
                
-               if ($_REQUEST['mode'] == 'database') {
+               if (!$dumpall) {
                        $cmd .= " " . $misc->escapeShellArg($_REQUEST['database']);
                }
 
index 11351266f123c07db19909c9ce4751c673216608..06dd228a95987720c0072fea72e8d8cd13046ef3 100644 (file)
@@ -9,7 +9,7 @@
         * @param $return_desc The return link name
         * @param $page The current page
         *
-        * $Id: display.php,v 1.47 2005/02/09 11:26:24 chriskl Exp $
+        * $Id: display.php,v 1.47.2.1 2005/03/29 09:33:48 jollytoad Exp $
         */
 
        // Prevent timeouts on large result sets
                        // Report views don't set a schema, so we need to disable create view in that case
                        if (isset($_REQUEST['schema'])) echo " | <a class=\"navlink\" href=\"views.php?action=create&amp;formDefinition=",
                                urlencode($_REQUEST['query']), "&amp;{$misc->href}\">{$lang['strcreateview']}</a>\n";
-                       echo " | <a class=\"navlink\" href=\"dataexport.php?query=",
-                                       urlencode($_REQUEST['query']), "&amp;{$misc->href}\">{$lang['strdownload']}</a>\n";     
+                       echo " | <a class=\"navlink\" href=\"dataexport.php?query=", urlencode($_REQUEST['query']),
+                                       "&amp;search_path=", urlencode($_REQUEST['search_path']),
+                                       "&amp;{$misc->href}\">{$lang['strdownload']}</a>\n";
                }
 
                // Insert
index 181370b22c4c1169b59ae00931dc6921a3816066..06db64e37c667d99c1b4b86c3efa583a32b5b20a 100644 (file)
@@ -3,7 +3,7 @@
        /**
         * List tables in a database
         *
-        * $Id: tblproperties.php,v 1.62.4.1 2005/03/01 10:47:04 jollytoad Exp $
+        * $Id: tblproperties.php,v 1.62.4.2 2005/03/29 09:33:49 jollytoad Exp $
         */
 
        // Include application functions
 
                echo "<p><input type=\"hidden\" name=\"action\" value=\"export\" />\n";
                echo $misc->form;
+               echo "<input type=\"hidden\" name=\"subject\" value=\"table\" />\n";
                echo "<input type=\"hidden\" name=\"table\" value=\"", htmlspecialchars($_REQUEST['table']), "\" />\n";
                echo "<input type=\"submit\" value=\"{$lang['strexport']}\" /></p>\n";
                echo "</form>\n";
index f2714bfe257aa7fad4eef2983cf065925513ae8e..fbd129e7e0d38376d476b676ca9b5e5f45485101 100755 (executable)
@@ -3,7 +3,7 @@
        /**
         * List views in a database
         *
-        * $Id: viewproperties.php,v 1.13.4.1 2005/03/01 10:47:04 jollytoad Exp $
+        * $Id: viewproperties.php,v 1.13.4.2 2005/03/29 09:33:49 jollytoad Exp $
         */
 
        // Include application functions
 
                echo "<p><input type=\"hidden\" name=\"action\" value=\"export\" />\n";
                echo $misc->form;
-               echo "<input type=\"hidden\" name=\"table\" value=\"", htmlspecialchars($_REQUEST['view']), "\" />\n";
+               echo "<input type=\"hidden\" name=\"subject\" value=\"view\" />\n";
+               echo "<input type=\"hidden\" name=\"view\" value=\"", htmlspecialchars($_REQUEST['view']), "\" />\n";
                echo "<input type=\"submit\" value=\"{$lang['strexport']}\" /></p>\n";
                echo "</form>\n";
        }