initial support for multi-action options with support for tables. This is based on...
authorxzilla <xzilla>
Sat, 3 Mar 2007 20:00:48 +0000 (20:00 +0000)
committerxzilla <xzilla>
Sat, 3 Mar 2007 20:00:48 +0000 (20:00 +0000)
classes/Misc.php
lang/english.php
lang/recoded/english.php
multiactionform.js [new file with mode: 0644]
tables.php

index 4848efb64c6f66bf63b8953a7f9c5629d0229b4f..a84f46de3d1a56f0851d3942c32314476410c5e0 100644 (file)
@@ -2,7 +2,7 @@
        /**
         * Class to hold various commonly used functions
         *
-        * $Id: Misc.php,v 1.138 2007/01/10 01:56:06 soranzo Exp $
+        * $Id: Misc.php,v 1.139 2007/03/03 20:00:48 xzilla Exp $
         */
         
        class Misc {
                 *                                      'vars'  => Associative array of (URL variable => field name),
                 *                              ), ...
                 *                      );
+                * @param $multiactions  Actions to be provided to a series of items defined by checkboxes
+                *                      $multiactions = array(
+                *                      'keycols' => array('table' => 'relname'),
+                *                      'url' => "{$PHP_SELF}",
+                *                      'actions' => array(
+                *                              'empty' => array(
+                *                              'action' => 'confirm_empty',
+                *                              'title' => $lang['strempty'],
+                *                      ),
+                *                      'drop' => array(
+                *                              'action' => 'confirm_drop',
+                *                              'title' => $lang['strdrop'],
+                *                      ),
+                *                      'vacuum' => array(
+                *                              'action' => 'confirm_vacuum',
+                *                                      'title' => $lang['strvacuum'],
+                *                              )
+                *                      )
                 * @param $nodata    (optional) Message to display if data set is empty.
                 * @param $pre_fn    (optional) Name of a function to call for each row,
                 *                                       it will be passed two params: $rowdata and $actions,
                 *                                       or if nothing is returned then the standard actions are used.
                 *                                       (see functions.php and constraints.php for examples)
                 */
-               function printTable(&$tabledata, &$columns, &$actions, $nodata = null, $pre_fn = null) {
-                       global $data, $conf, $misc;
+               function printTable(&$tabledata, &$columns, &$actions, $nodata = null, $pre_fn = null, &$multiactions = null) {
+                       global $data, $conf, $misc, $lang;
                        global $PHP_SELF;
 
                        if ($tabledata->recordCount() > 0) {
                                // (Remove this section to keep the 'Properties' button instead of links)
                                if (isset($actions['properties'])) {
                                        reset($columns);
-                                       $first_column = key($columns);
+                                       list($first_column) = each($columns);
                                        $columns[$first_column]['url'] = $actions['properties']['url'];
                                        $columns[$first_column]['vars'] = $actions['properties']['vars'];
                                        unset($actions['properties']);
                                        // TODO: This should be a user option.
                                        //$columns['comment']['params']['clip'] = true;
                                }
-                               
+
+                               if (isset($multiactions)) {
+                                       echo "<form id=\"multi_form\" action=\"{$multiactions['url']}\" method=\"post\" enctype=\"multipart/form-data\">\n";
+                                       if (isset($multiactions['vars']))
+                                               foreach ($multiactions['vars'] as $k => $v)
+                                                       echo "<input type=\"hidden\" name=\"$k\" value=\"$v\" />";
+                               }
+
                                echo "<table>\n";
                                echo "<tr>\n";
                                // Display column headings
+                               if (isset($multiactions)) echo "<th></th>";
                                foreach ($columns as $column_id => $column) {
                                        switch ($column_id) {
                                                case 'actions':
                                        unset($alt_actions);
                                        if (!is_null($pre_fn)) $alt_actions = $pre_fn($tabledata, $actions);
                                        if (!isset($alt_actions)) $alt_actions =& $actions;
-                                       
+
                                        echo "<tr>\n";
-                                       
+                                       if (isset($multiactions)) {
+                                               foreach ($multiactions['keycols'] as $k => $v)
+                                                       $a[$k] = $tabledata->fields[$v];
+                                               echo "<td class=\"data{$id}\">";
+                                               echo "<input type=\"checkbox\" name=\"ma[]\" value=\"". htmlentities(serialize($a)) ."\" />";
+                                               echo "</td>\n";
+                                       }
+                                               
                                        foreach ($columns as $column_id => $column) {
-                                       
+
                                                // Apply default values for missing parameters
                                                if (isset($column['url']) && !isset($column['vars'])) $column['vars'] = array();
-                                               
+
                                                switch ($column_id) {
                                                        case 'actions':
                                                                foreach ($alt_actions as $action) {
                                        $tabledata->moveNext();
                                        $i++;
                                }
-                               
                                echo "</table>\n";
+
+                               // Multi action table footer w/ options & [un]check'em all
+                               if (isset($multiactions)) {
+                                       echo "<table>\n";
+                                       echo "<tr>\n";
+                                       echo "<th class=\"data\" align=\"left\" colspan=\"3\">{$lang['stractionsonmultiplelines']}</th>\n";
+                                       echo "</tr>\n"; 
+                                       echo "<tr>\n";
+                                       echo "<td class=\"data1\">";
+                                       echo "<a href=\"#\" onclick=\"javascript:checkAll(true);\">{$lang['strcheckall']}</a> / ";
+                                       echo "<a href=\"#\" onclick=\"javascript:checkAll(false);\">{$lang['struncheckall']}</a></td>\n";
+                                       echo "<td class=\"data1\">&nbsp;--->&nbsp;</td>\n";
+                                       echo "<td class=\"data1\">\n";
+                                       echo "\t<select name=\"action\">\n";
+                                               foreach($multiactions['actions'] as $o)
+                                                       echo "\t\t<option value=\"{$o['action']}\">{$o['title']}</option>\n";
+                                       echo "\t</select>\n";
+                                       echo "<input type=\"submit\" value=\"submit\" />\n";
+                                       echo $misc->form;
+                                       echo "</td>\n";
+                                       echo "</tr>\n";
+                                       echo "</table>\n";
+                                       echo '</form>';
+                               }; 
                                
                                return true;
                        } else {
index 1f74a46a867fcacbcb0352c60bcb19c9e6530687..b9e668a488887d231fbe4378355470e2734ea9e5 100755 (executable)
@@ -4,7 +4,7 @@
         * English language file for phpPgAdmin.  Use this as a basis
         * for new translations.
         *
-        * $Id: english.php,v 1.200 2007/02/10 03:48:34 xzilla Exp $
+        * $Id: english.php,v 1.201 2007/03/03 20:00:48 xzilla Exp $
         */
 
        // Language and character set
        $lang['strfile'] = 'File';
        $lang['strfileimported'] = 'File imported.';
        $lang['strtrycred'] = 'Use these credentials for all servers';
+       $lang['stractionsonmultiplelines'] = 'Actions on multiple lines';
+       $lang['strcheckall'] = 'Check All';
+       $lang['struncheckall'] = 'Uncheck All';
 
        // Database sizes
        $lang['strsize'] = 'Size';
index 50c97ed358b8ba3ea687dcca81503a7772e7977f..5cd3d68004d2408647b46330ce37a9ed0697a1d5 100644 (file)
@@ -4,7 +4,7 @@
         * English language file for phpPgAdmin.  Use this as a basis
         * for new translations.
         *
-        * $Id: english.php,v 1.152 2006/12/31 16:21:27 soranzo Exp $
+        * $Id: english.php,v 1.153 2007/03/03 20:00:48 xzilla Exp $
         */
 
        // Language and character set
        $lang['strfile'] = 'File';
        $lang['strfileimported'] = 'File imported.';
        $lang['strtrycred'] = 'Use these credentials for all servers';
+       $lang['stractionsonmultiplelines'] = 'Actions on multiple lines';
+       $lang['strcheckall'] = 'Check All';
+       $lang['struncheckall'] = 'Uncheck All';
 
        // Database sizes
        $lang['strsize'] = 'Size';
        $lang['strvacuumcostdelay'] = 'Vacuum Cost Delay'; 
        $lang['strvacuumcostlimit'] = 'Vacuum Cost Limit';  
 
-        // Table-level Locks
+    // Table-level Locks
        $lang['strlocks'] = 'Locks';
        $lang['strtransaction'] = 'Transaction ID';
        $lang['strprocessid'] = 'Process ID';
diff --git a/multiactionform.js b/multiactionform.js
new file mode 100644 (file)
index 0000000..1950608
--- /dev/null
@@ -0,0 +1,9 @@
+function checkAll(bool) {
+
+       var inputs = document.getElementById('multi_form').getElementsByTagName('input');
+
+       for (var i=0; i<inputs.length; i++) {
+               if (inputs[i].type == 'checkbox')
+                       inputs[i].checked = bool;
+       }
+}
index 421f41e2722713fd458e0e47e1b715b6df9f1045..ff999da0f0eebbfd76b4c1f420e81de0879855a8 100644 (file)
@@ -3,7 +3,7 @@
        /**
         * List tables in a database
         *
-        * $Id: tables.php,v 1.86 2007/02/05 19:48:06 xzilla Exp $
+        * $Id: tables.php,v 1.87 2007/03/03 20:00:48 xzilla Exp $
         */
 
        // Include application functions
                global $lang;
                global $PHP_SELF;
 
+               if (empty($_REQUEST['table']) && empty($_REQUEST['ma'])) {
+                       doDefault('No table(s) given to empty...'); //TODO i18n
+                       exit();
+               }
+               
                if ($confirm) {
-                       $misc->printTrail('table');
-                       $misc->printTitle($lang['strempty'],'pg.table.empty');
+                       if (isset($_REQUEST['ma'])) {
+                               $misc->printTrail('schema');
+                               $misc->printTitle($lang['strempty'],'pg.table.empty');
 
-                       echo "<p>", sprintf($lang['strconfemptytable'], $misc->printVal($_REQUEST['table'])), "</p>\n";
+                               echo "<form action=\"$PHP_SELF\" method=\"post\">\n";
+                               foreach ($_REQUEST['ma'] as $v) {
+                                       $a = unserialize(html_entity_decode($v));
+                                       echo "<p>", sprintf($lang['strconfemptytable'], $misc->printVal($a['table'])), "</p>\n";
+                                       printf('<input type="hidden" name="table[]" value="%s" />', htmlspecialchars($a['table']));
+                               }
+                       } // END mutli empty
+                       else { 
+                               $misc->printTrail('table');
+                               $misc->printTitle($lang['strempty'],'pg.table.empty');
+
+                               echo "<p>", sprintf($lang['strconfemptytable'], $misc->printVal($_REQUEST['table'])), "</p>\n";
+
+                               echo "<form action=\"$PHP_SELF\" method=\"post\">\n";
+                               echo "<input type=\"hidden\" name=\"table\" value=\"", htmlspecialchars($_REQUEST['table']), "\" />\n";
+                       } // END not mutli empty
 
-                       echo "<form action=\"$PHP_SELF\" method=\"post\">\n";
                        echo "<input type=\"hidden\" name=\"action\" value=\"empty\" />\n";
-                       echo "<input type=\"hidden\" name=\"table\" value=\"", htmlspecialchars($_REQUEST['table']), "\" />\n";
                        echo $misc->form;
                        echo "<input type=\"submit\" name=\"empty\" value=\"{$lang['strempty']}\" /> <input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" />\n";
                        echo "</form>\n";
-               }
-               else {
-                       $status = $data->emptyTable($_POST['table']);
-                       if ($status == 0)
-                               doDefault($lang['strtableemptied']);
-                       else
-                               doDefault($lang['strtableemptiedbad']);
-               }
-               
+               } // END if confirm
+               else { // Do Empty
+                       if (is_array($_REQUEST['table'])) {
+                               $msg='';
+                               foreach($_REQUEST['table'] as $t) {
+                                       $status = $data->emptyTable($t);
+                                       if ($status == 0)
+                                               $msg.= sprintf('%s: %s<br />', $t, $lang['strtableemptied']);
+                                       else {
+                                               doDefault(sprintf('%s%s: %s<br />', $msg, $t, $lang['strtableemptiedbad']));
+                                               return;
+                                       }
+                               }
+                               doDefault($msg);
+                       } // END mutli empty
+                       else { 
+                               $status = $data->emptyTable($_POST['table']);
+                               if ($status == 0)
+                                       doDefault($lang['strtableemptied']);
+                               else
+                                       doDefault($lang['strtableemptiedbad']);
+                       } // END not mutli empty
+               } // END do Empty
        }
 
        /**
                global $data, $misc;
                global $lang, $_reload_browser;
                global $PHP_SELF;
-
+               
+               if (empty($_REQUEST['table']) && empty($_REQUEST['ma'])) {
+                       doDefault('No table(s) given to drop...'); // TODO i18n
+                       exit();
+               }
+               
                if ($confirm) {
-                       $misc->printTrail('table');
-                       $misc->printTitle($lang['strdrop'], 'pg.table.drop');
+                       //If multi drop
+                       if (isset($_REQUEST['ma'])) {
+
+                               $misc->printTrail('schema');
+                               $misc->printTitle($lang['strdrop'], 'pg.table.drop');
+
+                               echo "<form action=\"$PHP_SELF\" method=\"post\">\n";
+                               foreach($_REQUEST['ma'] as $v) {
+                                       $a = unserialize(html_entity_decode($v));
+                                       echo "<p>", sprintf($lang['strconfdroptable'], $misc->printVal($a['table'])), "</p>\n";
+                                       printf('<input type="hidden" name="table[]" value="%s" />', htmlspecialchars($a['table']));
+                               }
+                       } else {
+
+                               $misc->printTrail('table');
+                               $misc->printTitle($lang['strdrop'], 'pg.table.drop');
 
-                       echo "<p>", sprintf($lang['strconfdroptable'], $misc->printVal($_REQUEST['table'])), "</p>\n";
+                               echo "<p>", sprintf($lang['strconfdroptable'], $misc->printVal($_REQUEST['table'])), "</p>\n";
+
+                               echo "<form action=\"$PHP_SELF\" method=\"post\">\n";
+                               echo "<input type=\"hidden\" name=\"table\" value=\"", htmlspecialchars($_REQUEST['table']), "\" />\n";
+                       }// END if multi drop
 
-                       echo "<form action=\"$PHP_SELF\" method=\"post\">\n";
                        echo "<input type=\"hidden\" name=\"action\" value=\"drop\" />\n";
-                       echo "<input type=\"hidden\" name=\"table\" value=\"", htmlspecialchars($_REQUEST['table']), "\" />\n";
                        echo $misc->form;
                        // 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 "<input type=\"submit\" name=\"drop\" value=\"{$lang['strdrop']}\" />\n";
                        echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" />\n";
                        echo "</form>\n";
-               }
+               } // END confirm
                else {
-                       $status = $data->dropTable($_POST['table'], isset($_POST['cascade']));
-                       if ($status == 0) {
+                       //If multi drop
+                       if (is_array($_REQUEST['table'])) {
+                               $msg='';
+                               foreach($_REQUEST['table'] as $t) {
+                                       $status = $data->dropTable($t, isset($_POST['cascade']));
+                                       if ($status == 0)
+                                               $msg.= sprintf('%s: %s<br />', $t, $lang['strtabledropped']);
+                                       else {
+                                               doDefault(sprintf('%s%s: %s<br />', $msg, $t, $lang['strtabledroppedbad']));
+                                               return;
+                                       }
+                               }
+                               // Everything went fine, back to the Default page....
                                $_reload_browser = true;
-                               doDefault($lang['strtabledropped']);
+                               doDefault($msg);
+                       } else {
+                               $status = $data->dropTable($_POST['table'], isset($_POST['cascade']));
+                               if ($status == 0) {
+                                       $_reload_browser = true;
+                                       doDefault($lang['strtabledropped']);
+                               }
+                               else
+                                       doDefault($lang['strtabledroppedbad']);
                        }
-                       else
-                               doDefault($lang['strtabledroppedbad']);
-               }
-               
-       }
+               } // END DROP
+       }// END Function
 
 
        /**
                global $lang, $_reload_browser;
                global $PHP_SELF;
 
+               if (empty($_REQUEST['table']) && empty($_REQUEST['ma'])) {
+                       doDefault('No table(s) given to vacuum...'); //TODO i18n
+                       exit();
+               }
                if ($confirm) {
-                       $misc->printTrail('table');
-                       $misc->printTitle($lang['strvacuum'], 'pg.vacuum');
+                       if (isset($_REQUEST['ma'])) {
+                               $misc->printTrail('schema');
+                               $misc->printTitle($lang['strvacuum'], 'pg.vacuum');
 
-                       echo "<p>", sprintf($lang['strconfvacuumtable'], $misc->printVal($_REQUEST['table'])), "</p>\n";
+                               echo "<form action=\"$PHP_SELF\" method=\"post\">\n";
+                               foreach($_REQUEST['ma'] as $v) {
+                                       $a = unserialize(html_entity_decode($v));
+                                       echo "<p>", sprintf($lang['strconfvacuumtable'], $misc->printVal($a['table'])), "</p>\n";
+                                       echo "<input type=\"hidden\" name=\"table[]\" value=\"", htmlspecialchars($a['table']), "\" />\n";
+                               }
+                       } // END if multi vacuum
+                       else {
+                               $misc->printTrail('table');
+                               $misc->printTitle($lang['strvacuum'], 'pg.vacuum');
 
-                       echo "<form action=\"$PHP_SELF\" method=\"post\">\n";
+                               echo "<p>", sprintf($lang['strconfvacuumtable'], $misc->printVal($_REQUEST['table'])), "</p>\n";
+
+                               echo "<form action=\"$PHP_SELF\" method=\"post\">\n";
+                               echo "<input type=\"hidden\" name=\"table\" value=\"", htmlspecialchars($_REQUEST['table']), "\" />\n";
+                       }
                        echo "<input type=\"hidden\" name=\"action\" value=\"vacuum\" />\n";
-                       echo "<input type=\"hidden\" name=\"table\" value=\"", htmlspecialchars($_REQUEST['table']), "\" />\n";
                        echo $misc->form;
                        // Show vacuum full option if supportd
                        if ($data->hasFullVacuum()) {
                        echo "<input type=\"submit\" name=\"vacuum\" value=\"{$lang['strvacuum']}\" />\n";
                        echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" />\n";
                        echo "</form>\n";
-               }
+               } // END single vacuum
                else {
-                       $status = $data->vacuumDB($_POST['table'], isset($_REQUEST['vacuum_analyze']), isset($_REQUEST['vacuum_full']), '');
-                       if ($status == 0) {
-                               $_reload_browser = true;
-                               doDefault($lang['strvacuumgood']);
+                       //If multi drop
+                       if (is_array($_REQUEST['table'])) {
+                               $msg='';
+                               foreach($_REQUEST['table'] as $t) {
+                                       $status = $data->vacuumDB($t, isset($_REQUEST['vacuum_analyze']), isset($_REQUEST['vacuum_full']), '');
+                                       if ($status == 0)
+                                               $msg.= sprintf('%s: %s<br />', $t, $lang['strvacuumgood']);
+                                       else {
+                                               doDefault(sprintf('%s%s: %s<br />', $msg, $t, $lang['strvacuumbad']));
+                                               return;
+                                       }
+                               }
+                                // Everything went fine, back to the Default page....
+                                $_reload_browser = true;
+                                doDefault($msg);
+                       }
+                       else {
+                               $status = $data->vacuumDB($_POST['table'], isset($_REQUEST['vacuum_analyze']), isset($_REQUEST['vacuum_full']), '');
+                               if ($status == 0) {
+                                       $_reload_browser = true;
+                                       doDefault($lang['strvacuumgood']);
+                               }
+                               else
+                                       doDefault($lang['strvacuumbad']);
                        }
-                       else
-                               doDefault($lang['strvacuumbad']);
                }
-               
        }
 
        /**
                $misc->printTrail('schema');
                $misc->printTabs('schema','tables');
                $misc->printMsg($msg);
-               
+       
+               echo "<script src=\"multiactionform.js\" type=\"text/javascript\"></script>";
+
                $tables = $data->getTables();
                
+               $multiactions = array(
+                       'keycols' => array('table' => 'relname'),
+                       'url' => "{$PHP_SELF}",
+                       'actions' => array(
+                               'empty' => array(
+                                       'action' => 'confirm_empty',
+                                       'title' => $lang['strempty'],
+                               ),
+                               'drop' => array(
+                                       'action' => 'confirm_drop',
+                                       'title' => $lang['strdrop'],
+                               ),
+                               'vacuum' => array(
+                                       'action' => 'confirm_vacuum',
+                                       'title' => $lang['strvacuum'],
+                               )
+                       )
+               );
+                       
                $columns = array(
                        'table' => array(
                                'title' => $lang['strtable'],
                
                if (!$data->hasTablespaces()) unset($columns['tablespace']);
 
-               $misc->printTable($tables, $columns, $actions, $lang['strnotables']);
+               $misc->printTable($tables, $columns, $actions, $lang['strnotables'], null, $multiactions);
 
                echo "<p><a class=\"navlink\" href=\"$PHP_SELF?action=create&amp;{$misc->href}\">{$lang['strcreatetable']}</a></p>\n";
        }