diff options
author | jollytoad | 2005-03-14 09:57:58 +0000 |
---|---|---|
committer | jollytoad | 2005-03-14 09:57:58 +0000 |
commit | 1e53297e623edd9406e2560a817c7ad33b468bbf (patch) | |
tree | e6a0f5d183b9f47bcec228c5195d6659463b9d5d | |
parent | 4c2cbb0e47f148e909353ee9482fdbac00e3c64d (diff) |
Promote the use of decorators for URL's in tree generation, greatly simplifying
printTreeXML and node definitions.
-rw-r--r-- | aggregates.php | 14 | ||||
-rw-r--r-- | all_db.php | 44 | ||||
-rw-r--r-- | classes/Misc.php | 83 | ||||
-rw-r--r-- | conversions.php | 13 | ||||
-rwxr-xr-x | database.php | 69 | ||||
-rw-r--r-- | domains.php | 28 | ||||
-rw-r--r-- | functions.php | 31 | ||||
-rw-r--r-- | opclasses.php | 14 | ||||
-rw-r--r-- | operators.php | 31 | ||||
-rw-r--r-- | sequences.php | 28 | ||||
-rw-r--r-- | servers.php | 57 | ||||
-rw-r--r-- | tables.php | 24 | ||||
-rw-r--r-- | types.php | 28 | ||||
-rw-r--r-- | views.php | 24 |
14 files changed, 249 insertions, 239 deletions
diff --git a/aggregates.php b/aggregates.php index 11296a40..5e9f5f30 100644 --- a/aggregates.php +++ b/aggregates.php @@ -3,7 +3,7 @@ /** * Manage aggregates in a database * - * $Id: aggregates.php,v 1.10.4.2 2005/03/09 12:29:01 jollytoad Exp $ + * $Id: aggregates.php,v 1.10.4.3 2005/03/14 09:57:59 jollytoad Exp $ */ // Include application functions @@ -56,15 +56,13 @@ $proto = concat(field('proname'), ' (', field('proargtypes'), ')'); - $actions = array( - 'item' => array( - 'text' => $proto, - 'icon' => 'functions', - 'toolTip' => field('aggcomment'), - ), + $attrs = array( + 'text' => $proto, + 'icon' => 'functions', + 'toolTip'=> field('aggcomment'), ); - $misc->printTreeXML($aggregates, $actions); + $misc->printTreeXML($aggregates, $attrs); exit; } @@ -3,7 +3,7 @@ /** * Manage databases within a server * - * $Id: all_db.php,v 1.35.4.2 2005/03/08 09:56:37 jollytoad Exp $ + * $Id: all_db.php,v 1.35.4.3 2005/03/14 09:57:59 jollytoad Exp $ */ // Include application functions @@ -253,34 +253,26 @@ $databases = &$data->getDatabases(); - $actions = array( - 'item' => array( - 'text' => field('datname'), - 'icon' => 'database', - 'url' => 'redirect.php', - 'urlvars' => array( - 'subject' => 'database', - 'database' => field('datname'), - ), - ), - 'expand' => array( - 'url' => 'database.php', - 'urlvars' => array( - 'subject' => 'database', - 'action' => 'tree', - 'database' => field('datname'), - ), - ), - ); + $reqvars = $misc->getRequestVars('database'); - $opts = array( - 'postxml' => - "<tree text=\"{$lang['strusers']}\" action=\"users.php?{$misc->href}\" target=\"detail\"/>". - "<tree text=\"{$lang['strgroups']}\" action=\"groups.php?{$misc->href}\" target=\"detail\"/>". - "<tree text=\"{$lang['strreports']}\" action=\"reports.php?{$misc->href}\" target=\"detail\"/>" + $attrs = array( + 'text' => field('datname'), + 'icon' => 'database', + 'toolTip'=> field('datcomment'), + 'action' => url('redirect.php', + $reqvars, + array('database' => field('datname')) + ), + 'branch' => url('database.php', + $reqvars, + array( + 'action' => 'tree', + 'database' => field('datname') + ) + ), ); - $misc->printTreeXML($databases, $actions, $opts); + $misc->printTreeXML($databases, $attrs); exit; } diff --git a/classes/Misc.php b/classes/Misc.php index 031a0acf..7f2d9a81 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.98.2.10 2005/03/09 12:23:00 jollytoad Exp $ + * $Id: Misc.php,v 1.98.2.11 2005/03/14 09:57:58 jollytoad Exp $ */ class Misc { @@ -1165,6 +1165,10 @@ * '$attr='. */ function printActionUrl(&$action, &$fields, $attr = null) { + $url = value($action['url'], $fields); + + if ($url === false) return ''; + if (!empty($action['urlvars'])) { $urlvars = value($action['urlvars'], $fields); } else { @@ -1183,18 +1187,13 @@ } } } - - $url = value($action['url'], $fields); $sep = '?'; foreach ($urlvars as $var => $varfield) { $url .= $sep . value_url($var, $fields) . '=' . value_url($varfield, $fields); $sep = '&'; } - if (!empty($action['urlfn'])) { - $fn = value($action['urlfn'], $fields); - $url = $fn($url, $action, $fields); - } + $url = htmlentities($url); if ($attr !== null && $url != '') @@ -1202,6 +1201,22 @@ else return $url; } + + function getRequestVars($subject = '') { + $v = array(); + if (!empty($subject)) + $v['subject'] = $subject; + if (isset($_REQUEST['server']) && $subject != 'root') { + $v['server'] = $_REQUEST['server']; + if (isset($_REQUEST['database']) && $subject != 'server') { + $v['database'] = $_REQUEST['database']; + if (isset($_REQUEST['schema']) && $subject != 'database') { + $v['schema'] = $_REQUEST['schema']; + } + } + } + return $v; + } function printUrlVars(&$vars, &$fields) { foreach ($vars as $var => $varfield) { @@ -1352,61 +1367,53 @@ /** Produce XML data for the browser tree * @param $treedata A set of records to populate the tree. - * @param $actions The actions to perform for the items, - * similar to the $actions array given to printTable. - * Two actions may be specified: - * 'item' - the action from clicking the item, - * 'expand' - the action to return XML for the subtree. - * @param $opts Associative array of optional arguments: - * 'prexml' - static XML to place before items. - * 'postxml' - static XML to place after items. - * 'nodata' - message to display for no records. + * @param $attrs Attributes for tree items + * 'text' - the text for the tree node + * 'icon' - an icon for node + * 'openIcon' - an alternative icon when the node is expanded + * 'toolTip' - tool tip text for the node + * 'action' - URL to visit when single clicking the node + * 'branch' - URL for child nodes (tree XML) + * 'expand' - the action to return XML for the subtree + * 'nodata' - message to display when node has no children */ - function printTreeXML(&$treedata, &$actions, $opts = array()) { + function printTreeXML(&$treedata, &$attrs) { global $conf, $lang; header("Content-Type: text/xml"); header("Cache-Control: no-cache"); echo "<?xml version=\"1.0\"?>\n"; - echo "<tree>\n"; - if (!empty($opts['prexml'])) echo $opts['prexml']; + echo "<tree>\n"; if ($treedata->recordCount() > 0) { while (!$treedata->EOF) { - echo "<tree", value_xml_attr('text', $actions['item']['text'], $treedata->f); + $rec =& $treedata->f; - echo $this->printActionUrl($actions['item'], $treedata->f, 'action'); + echo "<tree"; + echo value_xml_attr('text', $attrs['text'], $rec); + echo value_xml_attr('action', $attrs['action'], $rec); + echo value_xml_attr('src', $attrs['branch'], $rec); - if (!empty($actions['expand'])) { - echo $this->printActionUrl($actions['expand'], $treedata->f, 'src'); - } + $icon = $this->icon(value($attrs['icon'], $rec)); + echo value_xml_attr('icon', $icon, $rec); - if (!empty($actions['item']['icon'])) { - $icon = $this->icon(value_xml($actions['item']['icon'], $treedata->f)); - echo " icon=\"{$icon}\""; - } - if (!empty($actions['item']['openIcon'])) { - $icon = $this->icon(value_xml($actions['item']['openIcon'], $treedata->f)); + if (!empty($attrs['openIcon'])) { + $icon = $this->icon(value($attrs['openIcon'], $rec)); } - if (isset($icon)) - echo " openIcon=\"{$icon}\""; + echo value_xml_attr('openIcon', $icon, $rec); - if (!empty($actions['item']['toolTip'])) { - echo value_xml_attr('toolTip', $actions['item']['toolTip'], $treedata->f); - } + echo value_xml_attr('toolTip', $attrs['toolTip'], $rec); echo "/>\n"; $treedata->moveNext(); } } else { - $msg = isset($opts['nodata']) ? $opts['nodata'] : $lang['strnoobjects']; + $msg = isset($attrs['nodata']) ? $attrs['nodata'] : $lang['strnoobjects']; echo "<tree text=\"{$msg}\" onaction=\"this.parentNode.reload()\" icon=\"", $this->icon('error'), "\"/>\n"; } - if (!empty($opts['postxml'])) echo $opts['postxml']; - echo "</tree>\n"; } diff --git a/conversions.php b/conversions.php index 617d5bc1..7cd0ad9c 100644 --- a/conversions.php +++ b/conversions.php @@ -3,7 +3,7 @@ /** * Manage conversions in a database * - * $Id: conversions.php,v 1.9.4.1 2005/03/01 10:47:03 jollytoad Exp $ + * $Id: conversions.php,v 1.9.4.2 2005/03/14 09:58:00 jollytoad Exp $ */ // Include application functions @@ -63,14 +63,13 @@ $conversions = &$data->getconversions(); - $actions = array( - 'item' => array( - 'text' => field('conname'), - 'icon' => 'conversions', - ), + $attrs = array( + 'text' => field('conname'), + 'icon' => 'conversions', + 'toolTip'=> field('concomment') ); - $misc->printTreeXML($conversions, $actions); + $misc->printTreeXML($conversions, $attrs); exit; } diff --git a/database.php b/database.php index 01a79ec7..3e47e33e 100755 --- a/database.php +++ b/database.php @@ -3,7 +3,7 @@ /** * Manage schemas within a database * - * $Id: database.php,v 1.65.2.3 2005/03/08 12:27:06 jollytoad Exp $ + * $Id: database.php,v 1.65.2.4 2005/03/14 09:58:00 jollytoad Exp $ */ // Include application functions @@ -718,27 +718,29 @@ $schemas = &$data->getSchemas(); - $actions = array( - 'item' => array( - 'text' => field('nspname'), - 'icon' => 'folder', - 'url' => 'redirect.php', - 'urlvars' => array( - 'subject' => 'schema', - 'schema' => field('nspname') - ), - ), - 'expand' => array( - 'url' => 'database.php', - 'urlvars' => array( - 'subject' => 'schema', - 'action' => 'subtree', - 'schema' => field('nspname') - ), - ), + $reqvars = $misc->getRequestVars('schema'); + + $attrs = array( + 'text' => field('nspname'), + 'icon' => 'folder', + 'toolTip'=> field('nspcomment'), + 'action' => url('redirect.php', + $reqvars, + array( + 'subject' => 'schema', + 'schema' => field('nspname') + ) + ), + 'branch' => url('database.php', + $reqvars, + array( + 'action' => 'subtree', + 'schema' => field('nspname') + ) + ) ); - $misc->printTreeXML($schemas, $actions); + $misc->printTreeXML($schemas, $attrs); exit; } @@ -758,20 +760,23 @@ } $items =& new ArrayRecordSet($tabs); - $actions = array( - 'item' => array( - 'text' => noEscape(field('title')), - 'icon' => field('icon', 'folder'), - 'url' => field('url'), - 'urlvars' => field('urlvars', array()), - ), - 'expand' => array( - 'url' => field('url'), - 'urlvars' => merge(field('urlvars'), array('action' => 'tree')), - ), + $reqvars = $misc->getRequestVars('schema'); + + $attrs = array( + 'text' => noEscape(field('title')), + 'icon' => field('icon', 'folder'), + 'action' => url(field('url'), + $reqvars, + field('urlvars', array()) + ), + 'branch' => url(field('url'), + $reqvars, + field('urlvars'), + array('action' => 'tree') + ) ); - $misc->printTreeXML($items, $actions); + $misc->printTreeXML($items, $attrs); exit; } diff --git a/domains.php b/domains.php index 1812cda9..63476dc4 100644 --- a/domains.php +++ b/domains.php @@ -3,7 +3,7 @@ /** * Manage domains in a database * - * $Id: domains.php,v 1.19.4.1 2005/03/01 10:47:03 jollytoad Exp $ + * $Id: domains.php,v 1.19.4.2 2005/03/14 09:58:00 jollytoad Exp $ */ // Include application functions @@ -433,20 +433,22 @@ $domains = &$data->getDomains(); - $actions = array( - 'item' => array( - 'text' => field('domname'), - 'icon' => 'domains', - 'url' => 'domains.php', - 'urlvars' => array( - 'subject' => 'domain', - 'action' => 'properties', - 'domain' => field('domname'), - ), - ), + $reqvars = $misc->getRequestVars('domain'); + + $attrs = array( + 'text' => field('domname'), + 'icon' => 'domains', + 'toolTip'=> field('domcomment'), + 'action' => url('domains.php', + $reqvars, + array( + 'action' => 'properties', + 'domain' => field('domname') + ) + ) ); - $misc->printTreeXML($domains, $actions); + $misc->printTreeXML($domains, $attrs); exit; } diff --git a/functions.php b/functions.php index d2f89277..54b04964 100644 --- a/functions.php +++ b/functions.php @@ -3,7 +3,7 @@ /** * Manage functions in a database * - * $Id: functions.php,v 1.47.4.2 2005/03/09 12:29:01 jollytoad Exp $ + * $Id: functions.php,v 1.47.4.3 2005/03/14 09:58:00 jollytoad Exp $ */ // Include application functions @@ -540,22 +540,23 @@ $proto = concat(field('proname'),' (',field('proarguments'),')'); - $actions = array( - 'item' => array( - 'text' => $proto, - 'icon' => 'functions', - 'toolTip' => field('procomment'), - 'url' => 'redirect.php', - 'urlvars' => array( - 'subject' => 'function', - 'action' => 'properties', - 'function' => $proto, - 'function_oid' => field('prooid'), - ), - ), + $reqvars = $misc->getRequestVars('function'); + + $attrs = array( + 'text' => $proto, + 'icon' => 'functions', + 'toolTip' => field('procomment'), + 'action' => url('redirect.php', + $reqvars, + array( + 'action' => 'properties', + 'function' => $proto, + 'function_oid' => field('prooid') + ) + ) ); - $misc->printTreeXML($funcs, $actions); + $misc->printTreeXML($funcs, $attrs); exit; } diff --git a/opclasses.php b/opclasses.php index 0845886a..ad4ac730 100644 --- a/opclasses.php +++ b/opclasses.php @@ -3,7 +3,7 @@ /** * Manage opclasss in a database * - * $Id: opclasses.php,v 1.6.4.2 2005/03/09 12:29:01 jollytoad Exp $ + * $Id: opclasses.php,v 1.6.4.3 2005/03/14 09:58:01 jollytoad Exp $ */ // Include application functions @@ -65,15 +65,13 @@ // OpClass prototype: "op_class/access_method" $proto = concat(field('opcname'),'/',field('amname')); - $actions = array( - 'item' => array( - 'text' => $proto, - 'icon' => 'operators', - 'toolTip' => field('opccomment'), - ), + $attrs = array( + 'text' => $proto, + 'icon' => 'operators', + 'toolTip'=> field('opccomment'), ); - $misc->printTreeXML($opclasses, $actions); + $misc->printTreeXML($opclasses, $attrs); exit; } diff --git a/operators.php b/operators.php index cd09fbb1..8ac6465d 100644 --- a/operators.php +++ b/operators.php @@ -3,7 +3,7 @@ /** * Manage operators in a database * - * $Id: operators.php,v 1.17.4.2 2005/03/09 12:29:01 jollytoad Exp $ + * $Id: operators.php,v 1.17.4.3 2005/03/14 09:58:01 jollytoad Exp $ */ // Include application functions @@ -170,22 +170,23 @@ // Alternative prototype: "operator (type,type)" #$proto = concat(field('oprname'), ' (', field('oprleftname','NONE'), ',', field('oprrightname','NONE'), ')'); - $actions = array( - 'item' => array( - 'text' => $proto, - 'icon' => 'operators', - 'toolTip' => field('oprcomment'), - 'url' => 'operators.php', - 'urlvars' => array( - 'subject' => 'operator', - 'action' => 'properties', - 'operator' => $proto, - 'operator_oid' => field('oid'), - ), - ), + $reqvars = $misc->getRequestVars('operator'); + + $attrs = array( + 'text' => $proto, + 'icon' => 'operators', + 'toolTip'=> field('oprcomment'), + 'action' => url('operators.php', + $reqvars, + array( + 'action' => 'properties', + 'operator' => $proto, + 'operator_oid' => field('oid') + ) + ) ); - $misc->printTreeXML($operators, $actions); + $misc->printTreeXML($operators, $attrs); exit; } diff --git a/sequences.php b/sequences.php index f89ff0aa..184ccaad 100644 --- a/sequences.php +++ b/sequences.php @@ -3,7 +3,7 @@ /** * Manage sequences in a database * - * $Id: sequences.php,v 1.27.4.1 2005/03/01 10:47:03 jollytoad Exp $ + * $Id: sequences.php,v 1.27.4.2 2005/03/14 09:58:01 jollytoad Exp $ */ // Include application functions @@ -76,20 +76,22 @@ $sequences = &$data->getSequences(); - $actions = array( - 'item' => array( - 'text' => field('seqname'), - 'icon' => 'sequences', - 'url' => 'sequences.php', - 'urlvars' => array( - 'subject' => 'sequence', - 'action' => 'properties', - 'sequence' => field('seqname'), - ), - ), + $reqvars = $misc->getRequestVars('sequence'); + + $attrs = array( + 'text' => field('seqname'), + 'icon' => 'sequences', + 'toolTip'=> field('seqcomment'), + 'action' => url('sequences.php', + $reqvars, + array ( + 'action' => 'properties', + 'sequence' => field('seqname') + ) + ) ); - $misc->printTreeXML($sequences, $actions); + $misc->printTreeXML($sequences, $attrs); exit; } diff --git a/servers.php b/servers.php index 980b4e02..bda8990a 100644 --- a/servers.php +++ b/servers.php @@ -3,7 +3,7 @@ /** * Manage servers * - * $Id: servers.php,v 1.1.2.2 2005/03/08 09:45:22 jollytoad Exp $ + * $Id: servers.php,v 1.1.2.3 2005/03/14 09:58:01 jollytoad Exp $ */ // Include application functions @@ -15,11 +15,13 @@ $PHP_SELF = $_SERVER['PHP_SELF']; function doLogout() { - global $misc, $lang; + global $misc, $lang, $_reload_browser; $server_info = $misc->getServerInfo($_REQUEST['logoutServer']); $misc->setServerInfo(null,null,$_REQUEST['logoutServer']); doDefault(sprintf($lang['strlogoutmsg'], $server_info['desc'])); + + $_reload_browser = true; } function doDefault($msg = '') { @@ -79,34 +81,35 @@ $servers =& $misc->getServers(true); - function notLoggedIn($url, $action, $fields) { - if (empty($fields['username'])) - return ''; - return $url; - } + $reqvars = $misc->getRequestVars('server'); - $actions = array( - 'item' => array( - 'text' => field('desc'), - 'icon' => 'folder', - 'url' => 'redirect.php', - 'urlvars' => array( - 'subject' => 'server', - 'server' => field('id'), - ), - ), - 'expand' => array( - 'url' => 'all_db.php', - 'urlvars' => array( - 'subject' => 'server', - 'action' => 'tree', - 'server' => field('id') - ), - 'urlfn' => 'notLoggedIn', - ), + $attrs = array( + 'text' => field('desc'), + + // Show different icons for logged in/out + 'icon' => ifempty(field('username'), 'serverOut', 'server'), + + 'toolTip'=> field('id'), + + 'action' => url('redirect.php', + $reqvars, + array('server' => field('id')) + ), + + // Only create a branch url if the user has + // logged into the server. + 'branch' => ifempty(field('username'), false, + url('all_db.php', + $reqvars, + array( + 'action' => 'tree', + 'server' => field('id') + ) + ) + ), ); - $misc->printTreeXML($servers, $actions); + $misc->printTreeXML($servers, $attrs); exit; } @@ -3,7 +3,7 @@ /** * List tables in a database * - * $Id: tables.php,v 1.69.2.1 2005/03/01 10:47:04 jollytoad Exp $ + * $Id: tables.php,v 1.69.2.2 2005/03/14 09:58:01 jollytoad Exp $ */ // Include application functions @@ -612,19 +612,19 @@ $tables = &$data->getTables(); - $actions = array( - 'item' => array( - 'text' => field('relname'), - 'icon' => 'tables', - 'url' => 'redirect.php', - 'urlvars' => array( - 'subject' => 'table', - 'table' => field('relname'), - ), - ), + $reqvars = $misc->getRequestVars('table'); + + $attrs = array( + 'text' => field('relname'), + 'icon' => 'tables', + 'toolTip'=> field('relcomment'), + 'action' => url('redirect.php', + $reqvars, + array('table' => field('relname')) + ) ); - $misc->printTreeXML($tables, $actions); + $misc->printTreeXML($tables, $attrs); exit; } @@ -3,7 +3,7 @@ /** * Manage types in a database * - * $Id: types.php,v 1.25.4.1 2005/03/01 10:47:04 jollytoad Exp $ + * $Id: types.php,v 1.25.4.2 2005/03/14 09:58:01 jollytoad Exp $ */ // Include application functions @@ -466,20 +466,22 @@ $types = &$data->getTypes(); - $actions = array( - 'item' => array( - 'text' => field('basename'), - 'icon' => 'types', - 'url' => 'types.php', - 'urlvars' => array( - 'subject' => 'type', - 'action' => 'properties', - 'type' => field('basename'), - ), - ), + $reqvars = $misc->getRequestVars('type'); + + $attrs = array( + 'text' => field('basename'), + 'icon' => 'types', + 'toolTip'=> field('typcomment'), + 'action' => url('types.php', + $reqvars, + array( + 'action' => 'properties', + 'type' => field('basename') + ) + ) ); - $misc->printTreeXML($types, $actions); + $misc->printTreeXML($types, $attrs); exit; } @@ -3,7 +3,7 @@ /** * Manage views in a database * - * $Id: views.php,v 1.52.2.1 2005/03/01 10:47:04 jollytoad Exp $ + * $Id: views.php,v 1.52.2.2 2005/03/14 09:58:01 jollytoad Exp $ */ // Include application functions @@ -591,19 +591,19 @@ $views = &$data->getViews(); - $actions = array( - 'item' => array( - 'text' => field('relname'), - 'icon' => 'views', - 'url' => 'redirect.php', - 'urlvars' => array( - 'subject' => 'view', - 'view' => field('relname'), - ), - ), + $reqvars = $misc->getRequestVars('view'); + + $attrs = array( + 'text' => field('relname'), + 'icon' => 'views', + 'toolTip'=> field('relcomment'), + 'action' => url('redirect.php', + $reqvars, + array('view' => field('relname')) + ) ); - $misc->printTreeXML($views, $actions); + $misc->printTreeXML($views, $attrs); exit; } |