From 26ec4b8e00e3e1d3e2e2e0edf79d157f5cc0a596 Mon Sep 17 00:00:00 2001 From: ioguix Date: Tue, 17 Jul 2007 14:59:52 +0000 Subject: [PATCH] multi-action refactoring --- all_db.php | 24 +++++++---------- classes/Misc.php | 68 +++++++++++++++++++++++++----------------------- tables.php | 36 ++++++++----------------- 3 files changed, 55 insertions(+), 73 deletions(-) diff --git a/all_db.php b/all_db.php index 868a044c..449a140d 100644 --- a/all_db.php +++ b/all_db.php @@ -3,7 +3,7 @@ /** * Manage databases within a server * - * $Id: all_db.php,v 1.55 2007/07/16 21:27:28 ioguix Exp $ + * $Id: all_db.php,v 1.56 2007/07/17 14:59:52 ioguix Exp $ */ // Include application functions @@ -106,10 +106,9 @@ } } else { - echo "

", sprintf($lang['strconfdropdatabase'], $misc->printVal($_REQUEST['dropdatabase'])), "

\n"; echo "\n"; - }// END if multi drop + }// END if multi drop echo "\n"; echo $misc->form; @@ -306,17 +305,6 @@ $databases = $data->getDatabases(); - $multiactions = array( - 'keycols' => array('database' => 'datname'), - 'url' => "", - 'actions' => array( - 'drop' => array( - 'action' => 'confirm_drop', - 'title' => $lang['strdrop'], - ) - ) - ); - $columns = array( 'database' => array( 'title' => $lang['strdatabase'], @@ -351,10 +339,16 @@ ); $actions = array( + 'multiactions' => array( + 'keycols' => array('database' => 'datname'), + 'url' => 'all_db.php', + 'default' => null, + ), 'drop' => array( 'title' => $lang['strdrop'], 'url' => "all_db.php?action=confirm_drop&subject=database&{$misc->href}&", 'vars' => array('dropdatabase' => 'datname'), + 'multiaction' => 'confirm_drop', ), 'privileges' => array( 'title' => $lang['strprivileges'], @@ -374,7 +368,7 @@ if (!$data->hasServerAdminFuncs()) unset($columns['dbsize']); if (!isset($data->privlist['database'])) unset($actions['privileges']); - $misc->printTable($databases, $columns, $actions, $lang['strnodatabases'], null, $multiactions); + $misc->printTable($databases, $columns, $actions, $lang['strnodatabases']); echo "

href}\">{$lang['strcreatedatabase']}

\n"; diff --git a/classes/Misc.php b/classes/Misc.php index a3bcf0ad..c19c351f 100644 --- a/classes/Misc.php +++ b/classes/Misc.php @@ -2,7 +2,7 @@ /** * Class to hold various commonly used functions * - * $Id: Misc.php,v 1.154 2007/07/12 19:26:22 xzilla Exp $ + * $Id: Misc.php,v 1.155 2007/07/17 14:59:52 ioguix Exp $ */ class Misc { @@ -1528,32 +1528,25 @@ * ), ... * ); * @param $actions Actions that can be performed on each object: - * $actions = array( + * $actions = array( + * * multi action support + * * parameters are serialized for each entries and given in $_REQUEST['ma'] + * 'multiactions' => array( + * 'keycols' => Associative array of (URL variable => field name), // fields included in the form + * 'url' => URL submission, + * 'default' => Default selected action in the form. + * if null, an empty action is added & selected + * ), + * * actions * * action_id => array( * 'title' => Action heading, * 'url' => Static part of URL. Often we rely - * relative urls, usually '', or just a query string, + * relative urls, usually the page itself (not '' !), or just a query string, * 'vars' => Associative array of (URL variable => field name), + * 'multiaction' => Name of the action to execute. + * Add this action to the multi action form * ), ... * ); - * @param $multiactions Actions to be provided to a series of items defined by checkboxes - * $multiactions = array( - * 'keycols' => array('table' => 'relname'), - * 'url' => "", (See $actions['url']) - * '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, @@ -1563,11 +1556,14 @@ * (see tblproperties.php and constraints.php for examples) * The function must not must not store urls because * they are relative and won't work out of context. - */ - function printTable(&$tabledata, &$columns, &$actions, $nodata = null, $pre_fn = null, $multiactions = null) { + function printTable(&$tabledata, &$columns, &$actions, $nodata = null, $pre_fn = null) { global $data, $conf, $misc, $lang; + if ($has_ma = isset($actions['multiactions'])) + $ma = $actions['multiactions']; + unset($actions['multiactions']); + if ($tabledata->recordCount() > 0) { // Remove the 'comment' column if they have been disabled @@ -1581,18 +1577,18 @@ //$columns['comment']['params']['clip'] = true; } - if (isset($multiactions)) { + if ($has_ma) { echo "\n"; - echo "
\n"; - if (isset($multiactions['vars'])) - foreach ($multiactions['vars'] as $k => $v) + echo "\n"; + if (isset($ma['vars'])) + foreach ($ma['vars'] as $k => $v) echo ""; } echo "\n"; echo "\n"; // Display column headings - if (isset($multiactions)) echo ""; + if ($has_ma) echo ""; foreach ($columns as $column_id => $column) { switch ($column_id) { case 'actions': @@ -1620,8 +1616,8 @@ if (!isset($alt_actions)) $alt_actions =& $actions; echo "\n"; - if (isset($multiactions)) { - foreach ($multiactions['keycols'] as $k => $v) + if ($has_ma) { + foreach ($ma['keycols'] as $k => $v) $a[$k] = $tabledata->fields[$v]; echo "
"; echo ""; @@ -1676,7 +1672,10 @@ echo "
\n"; // Multi action table footer w/ options & [un]check'em all - if (isset($multiactions)) { + if ($has_ma) { + // if default is not set or doesn't exist, set it to null + if (!isset($ma['default']) || !isset($actions[$ma['default']])) + $ma['default'] = null; echo "\n"; echo "\n"; echo "\n"; @@ -1688,8 +1687,11 @@ echo "\n"; echo "
{$lang['stractionsonmultiplelines']} ---> \n"; echo "\t\n"; echo "\n"; echo $misc->form; diff --git a/tables.php b/tables.php index aefd7193..221c8a0f 100644 --- a/tables.php +++ b/tables.php @@ -3,7 +3,7 @@ /** * List tables in a database * - * $Id: tables.php,v 1.99 2007/07/16 21:27:29 ioguix Exp $ + * $Id: tables.php,v 1.100 2007/07/17 14:59:52 ioguix Exp $ */ // Include application functions @@ -777,29 +777,6 @@ $tables = $data->getTables(); - $multiactions = array( - 'keycols' => array('table' => 'relname'), - 'url' => 'tables.php', - 'actions' => array( - 'analyze' => array( - 'action' => 'confirm_analyze', - 'title' => $lang['stranalyze'], - ), - 'drop' => array( - 'action' => 'confirm_drop', - 'title' => $lang['strdrop'], - ), - 'empty' => array( - 'action' => 'confirm_empty', - 'title' => $lang['strempty'], - ), - 'vacuum' => array( - 'action' => 'confirm_vacuum', - 'title' => $lang['strvacuum'], - ) - ) - ); - $columns = array( 'table' => array( 'title' => $lang['strtable'], @@ -830,6 +807,11 @@ ); $actions = array( + 'multiactions' => array( + 'keycols' => array('table' => 'relname'), + 'url' => 'tables.php', + 'default' => 'analyze', + ), 'browse' => array( 'title' => $lang['strbrowse'], 'url' => "display.php?{$misc->href}&subject=table&return_url=".urlencode("tables.php?{$misc->href}")."&return_desc=".urlencode($lang['strback'])."&", @@ -849,28 +831,32 @@ 'title' => $lang['strempty'], 'url' => "tables.php?action=confirm_empty&{$misc->href}&", 'vars' => array('table' => 'relname'), + 'multiaction' => 'confirm_empty', ), 'drop' => array( 'title' => $lang['strdrop'], 'url' => "tables.php?action=confirm_drop&{$misc->href}&", 'vars' => array('table' => 'relname'), + 'multiaction' => 'confirm_drop', ), 'vacuum' => array( 'title' => $lang['strvacuum'], 'url' => "tables.php?action=confirm_vacuum&{$misc->href}&", 'vars' => array('table' => 'relname'), + 'multiaction' => 'confirm_vacuum', ), 'analyze' => array( 'title' => $lang['stranalyze'], 'url' => "tables.php?action=confirm_analyze&{$misc->href}&", 'vars' => array('table' => 'relname'), + 'multiaction' => 'confirm_analyze', ), ); if (!$data->hasAnalyze()) unset($actions['analyze'], $multiactions['actions']['analyze']); if (!$data->hasTablespaces()) unset($columns['tablespace']); - $misc->printTable($tables, $columns, $actions, $lang['strnotables'], null, $multiactions); + $misc->printTable($tables, $columns, $actions, $lang['strnotables']); echo "

href}\">{$lang['strcreatetable']}

\n"; } -- 2.39.5