add multi-drop to schemas
authorioguix <ioguix>
Sat, 15 Dec 2007 21:46:44 +0000 (21:46 +0000)
committerioguix <ioguix>
Sat, 15 Dec 2007 21:46:44 +0000 (21:46 +0000)
lang/english.php
schemas.php

index 929d6d1a312258bec7b0f896172eef849feb8d08..e72e9411ce241718431fdfef7f454c37509066d8 100755 (executable)
@@ -4,7 +4,7 @@
         * English language file for phpPgAdmin.  Use this as a basis
         * for new translations.
         *
-        * $Id: english.php,v 1.223 2007/11/29 23:23:56 ioguix Exp $
+        * $Id: english.php,v 1.224 2007/12/15 21:46:44 ioguix Exp $
         */
 
        // Language and character set
        $lang['strschemaaltered'] = 'Schema altered.';
        $lang['strschemaalteredbad'] = 'Schema alteration failed.';
        $lang['strsearchpath'] = 'Schema search path';
+       $lang['strspecifyschematodrop'] = 'You must specify at least one schema to drop';
 
        // Reports
        $lang['strreport'] = 'Report';
index a7226f99753ba54f82ae321e054d6e6bb11441a1..af7c64af64f6af01ea59e01f8218ef844cf18398 100755 (executable)
@@ -3,12 +3,12 @@
        /**
         * Manage schemas in a database
         *
-        * $Id: schemas.php,v 1.20 2007/09/28 11:46:56 ioguix Exp $
+        * $Id: schemas.php,v 1.21 2007/12/15 21:46:44 ioguix Exp $
         */
 
        // Include application functions
        include_once('./libraries/lib.inc.php');
-       
+
        $action = (isset($_REQUEST['action'])) ? $_REQUEST['action'] : '';
        if (!isset($msg)) $msg = '';
 
        function doDefault($msg = '') {
                global $data, $misc, $conf;
                global $lang;
-               
+
                $misc->printTrail('database');
                $misc->printTabs('database','schemas');
                $misc->printMsg($msg);
-               
+
                // Check that the DB actually supports schemas
                if ($data->hasSchemas()) {
                        $schemas = $data->getSchemas();
                                        'field' => field('nspcomment'),
                                ),
                        );
-                       
+
                        $actions = array(
+                               'multiactions' => array(
+                                       'keycols' => array('nsp' => 'nspname'),
+                                       'url' => 'schemas.php',
+                               ),
                                'drop' => array(
                                        'title' => $lang['strdrop'],
                                        'url'   => "schemas.php?action=drop&amp;{$misc->href}&amp;",
-                                       'vars'  => array('schema' => 'nspname'),
+                                       'vars'  => array('nsp' => 'nspname'),
+                                       'multiaction' => 'drop',
                                ),
                                'privileges' => array(
                                        'title' => $lang['strprivileges'],
@@ -64,7 +69,7 @@
                                        'vars'  => array('schema' => 'nspname'),
                                ),
                        );
-                       
+
                        $misc->printTable($schemas, $columns, $actions, $lang['strnoschemas']);
 
                        echo "<p><a class=\"navlink\" href=\"schemas.php?action=create&amp;{$misc->href}\">{$lang['strcreateschema']}</a></p>\n";
@@ -82,7 +87,7 @@
                global $lang;
 
                $server_info = $misc->getServerInfo();
-               
+
                if (!isset($_POST['formName'])) $_POST['formName'] = '';
                if (!isset($_POST['formAuth'])) $_POST['formAuth'] = $server_info['username'];
                if (!isset($_POST['formSpc'])) $_POST['formSpc'] = '';
@@ -94,7 +99,7 @@
                $misc->printTrail('database');
                $misc->printTitle($lang['strcreateschema'],'pg.schema.create');
                $misc->printMsg($msg);
-               
+
                echo "<form action=\"schemas.php\" method=\"post\">\n";
                echo "<table style=\"width: 100%\">\n";
                echo "\t<tr>\n\t\t<th class=\"data left required\">{$lang['strname']}</th>\n";
                }
                echo "\t\t\t</select>\n\t\t</td>\n\t</tr>\n";
                echo "\t<tr>\n\t\t<th class=\"data left\">{$lang['strcomment']}</th>\n";
-               echo "\t\t<td class=\"data1\"><textarea name=\"formComment\" rows=\"3\" cols=\"32\">", 
+               echo "\t\t<td class=\"data1\"><textarea name=\"formComment\" rows=\"3\" cols=\"32\">",
                        htmlspecialchars($_POST['formComment']), "</textarea></td>\n\t</tr>\n";
-                       
+
                echo "</table>\n";
                echo "<p>\n";
                echo "<input type=\"hidden\" name=\"action\" value=\"create\" />\n";
                        else
                                doCreate($lang['strschemacreatedbad']);
                }
-       }       
-       
+       }
+
        /**
         * Display a form to permit editing schema properies.
         * TODO: permit changing owner
         */
        function doAlter($msg = '') {
                global $data, $misc, $lang;
-               
+
                $misc->printTrail('schema');
                $misc->printTitle($lang['stralter'],'pg.schema.alter');
                $misc->printMsg($msg);
 
                        echo "<form action=\"schemas.php\" method=\"post\">\n";
                        echo "<table>\n";
-               
+
                        echo "\t<tr>\n";
                        echo "\t\t<th class=\"data left required\">{$lang['strname']}</th>\n";
                        echo "\t\t<td class=\"data1\">";
-                       echo "\t\t\t<input name=\"name\" size=\"32\" maxlength=\"{$data->_maxNameLen}\" value=\"", 
+                       echo "\t\t\t<input name=\"name\" size=\"32\" maxlength=\"{$data->_maxNameLen}\" value=\"",
                                htmlspecialchars($_POST['name']), "\" />\n";
                        echo "\t\t</td>\n";
                        echo "\t</tr>\n";
         */
        function doSaveAlter($msg = '') {
                global $data, $misc, $lang, $_reload_browser;
-               
+
                $status = $data->updateSchema($_POST['schema'], $_POST['comment'], $_POST['name']);
                if ($status == 0) {
                        $_reload_browser = true;
                global $data, $misc;
                global $lang, $_reload_browser;
 
+               if (empty($_REQUEST['schema']) && empty($_REQUEST['ma'])) {
+                       doDefault($lang['strspecifyschematodrop']);
+                       exit();
+               }
+               
                if ($confirm) {
                        $misc->printTrail('schema');
                        $misc->printTitle($lang['strdrop'],'pg.schema.drop');
 
-                       echo "<p>", sprintf($lang['strconfdropschema'], $misc->printVal($_REQUEST['schema'])), "</p>\n";
-
                        echo "<form action=\"schemas.php\" method=\"post\">\n";
+                       //If multi drop
+                       if (isset($_REQUEST['ma'])) {
+                               foreach($_REQUEST['ma'] as $v) {
+                                       $a = unserialize(htmlspecialchars_decode($v, ENT_QUOTES));
+                                       echo '<p>', sprintf($lang['strconfdropschema'], $misc->printVal($a['nsp'])), "</p>\n";
+                                       echo '<input type="hidden" name="nsp[]" value="', htmlspecialchars($a['nsp']), "\" />\n";
+                               }
+                       }
+                       else {
+                               echo "<p>", sprintf($lang['strconfdropschema'], $misc->printVal($_REQUEST['nsp'])), "</p>\n";
+                               echo "<input type=\"hidden\" name=\"nsp\" value=\"", htmlspecialchars($_REQUEST['nsp']), "\" />\n";
+                       }
+
                        // Show cascade drop option if supportd
                        if ($data->hasDropBehavior()) {
                                echo "<p><input type=\"checkbox\" id=\"cascade\" name=\"cascade\" /> <label for=\"cascade\">{$lang['strcascade']}</label></p>\n";
                        }
                        echo "<p><input type=\"hidden\" name=\"action\" value=\"drop\" />\n";
                        echo "<input type=\"hidden\" name=\"database\" value=\"", htmlspecialchars($_REQUEST['database']), "\" />\n";
-                       echo "<input type=\"hidden\" name=\"schema\" value=\"", htmlspecialchars($_REQUEST['schema']), "\" />\n";
                        echo $misc->form;
                        echo "<input type=\"submit\" name=\"drop\" value=\"{$lang['strdrop']}\" />\n";
                        echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n";
                        echo "</form>\n";
                }
                else {
-                       $status = $data->dropSchema($_POST['schema'], isset($_POST['cascade']));
-                       if ($status == 0) {
-                               $_reload_browser = true;
-                               doDefault($lang['strschemadropped']);
+                       if (is_array($_POST['nsp'])) {
+                               $msg='';
+                               $status = $data->beginTransaction();
+                               if ($status == 0) {
+                                       foreach($_POST['nsp'] as $s) {
+                                               $status = $data->dropSchema($s, isset($_POST['cascade']));
+                                               if ($status == 0)
+                                                       $msg.= sprintf('%s: %s<br />', htmlentities($s), $lang['strschemadropped']);
+                                               else {
+                                                       $data->endTransaction();
+                                                       doDefault(sprintf('%s%s: %s<br />', $msg, htmlentities($s), $lang['strschemadroppedbad']));
+                                                       return;
+                                               }
+                                       }
+                               }
+                               if($data->endTransaction() == 0) {
+                                       // Everything went fine, back to the Default page....
+                                       $_reload_browser = true;
+                                       doDefault($msg);
+                               }
+                               else doDefault($lang['strschemadroppedbad']);
+                       }
+                       else{
+                               $status = $data->dropSchema($_POST['nsp'], isset($_POST['cascade']));
+                               if ($status == 0) {
+                                       $_reload_browser = true;
+                                       doDefault($lang['strschemadropped']);
+                               }
+                               else
+                                       doDefault($lang['strschemadroppedbad']);
                        }
-                       else
-                               doDefault($lang['strschemadroppedbad']);
                }
-               
        }
 
        /**
         */
        function doTree() {
                global $misc, $data, $lang, $slony;
-               
+
                $schemas = $data->getSchemas();
-               
+
                $reqvars = $misc->getRequestVars('schema');
-               
+
                $attrs = array(
                        'text'   => field('nspname'),
                        'icon'   => 'Schema',
                                                        )
                                                ),
                );
-               
+
                $misc->printTreeXML($schemas, $attrs);
-               
+
                exit;
        }
-       
+
        function doSubTree() {
                global $misc, $data, $lang;
-               
+
                $tabs = $misc->getNavTabs('schema');
-               
+
                $items = $misc->adjustTabsForTree($tabs);
-               
+
                $reqvars = $misc->getRequestVars('schema');
-               
+
                $attrs = array(
                        'text'   => noEscape(field('title')),
                        'icon'   => field('icon'),
                                                        array('action' => 'tree')
                                                )
                );
-               
+
                $misc->printTreeXML($items, $attrs);
                exit;
        }
-       
+
        if ($action == 'tree') doTree();
        if ($action == 'subtree') doSubTree();
-       
+
        $misc->printHeader($lang['strschemas']);
        $misc->printBody();
 
        if (isset($_POST['cancel'])) $action = '';
-       
+
        switch ($action) {
                case 'create':
                        if (isset($_POST['create'])) doSaveCreate();