diff options
author | ioguix | 2007-11-29 23:23:56 +0000 |
---|---|---|
committer | ioguix | 2007-11-29 23:23:56 +0000 |
commit | ce7225e6433df005dbea4b5d436bc041e5f04839 (patch) | |
tree | 02a7ac3211118b2e33d110a90699145e714ea1ce | |
parent | bbe6b7e28725501242ebb411a0b328ac8f40b824 (diff) |
add request history popup + fix redirect.php to really get the latest tab
-rw-r--r-- | HISTORY | 6 | ||||
-rw-r--r-- | TODO | 1 | ||||
-rw-r--r-- | classes/Misc.php | 88 | ||||
-rwxr-xr-x | database.php | 3 | ||||
-rw-r--r-- | display.php | 13 | ||||
-rw-r--r-- | history.php | 144 | ||||
-rwxr-xr-x | lang/english.php | 11 | ||||
-rw-r--r-- | redirect.php | 11 | ||||
-rw-r--r-- | sql.php | 6 | ||||
-rw-r--r-- | sqledit.php | 50 |
10 files changed, 267 insertions, 66 deletions
@@ -20,7 +20,11 @@ Features properties page (ioguix) * Add Support for Enum type creation (ioguix,xzilla) * Add alter name, owner, comment and properties for sequences (ioguix) -* Add function costing options +* Add function costing options (xzilla) +* Add alter owner & schema on function (xzilla) +* Add a popup window for the session requests history (karl, ioguix) +* Add alter table schema (ioguix) +* Add alter sequence schema (ioguix) Bugs * Fix inability to assign a field type/domain of a different schema @@ -212,6 +212,7 @@ Miscellaneous * Translated FAQ * Pull FAQ/HISTORY/CREDITS/etc... from CVS for website. * Add support for csvlogs [8.3] +* Add exectued file scripts in history Exotic ------ diff --git a/classes/Misc.php b/classes/Misc.php index 69110676..3b267cb8 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.164 2007/11/23 17:58:47 xzilla Exp $ + * $Id: Misc.php,v 1.165 2007/11/29 23:23:56 ioguix Exp $ */ class Misc { @@ -1072,7 +1072,7 @@ else $tab = reset($tabs); - return isset($tab['url']) ? $tab['url'] : null; + return isset($tab['url']) ? $tab : null; } function printTopbar() { @@ -1096,15 +1096,18 @@ echo "</td>"; if (isset($_REQUEST['server'])) { - $url = "sqledit.php?{$this->href}&action="; - - $window_id = htmlspecialchars('sqledit:'.$_REQUEST['server']); + $sql_url = "sqledit.php?{$this->href}&action="; + $sql_window_id = htmlspecialchars('sqledit:'.$_REQUEST['server']); + $history_url = "history.php?{$this->href}&action=pophistory"; + $history_window_id = htmlspecialchars('history:'.$_REQUEST['server']); echo "<td style=\"text-align: right\">"; - echo "<ul class=\"toplink\">\n\t<li><a class=\"toplink\" href=\"{$url}sql\" target=\"sqledit\" onclick=\"window.open('{$url}sql','{$window_id}','toolbar=no,width=600,height=400,resizable=yes,scrollbars=no').focus(); return false;\">{$lang['strsql']}</a></li>\n"; + echo "<ul class=\"toplink\">\n\t<li><a class=\"toplink\" href=\"{$sql_url}sql\" target=\"sqledit\" onclick=\"window.open('{$sql_url}sql','{$sql_window_id}','toolbar=no,width=600,height=400,resizable=yes,scrollbars=no').focus(); return false;\">{$lang['strsql']}</a></li>\n"; + + echo "\t<li><a class=\"toplink\" href=\"{$history_url}\" onclick=\"window.open('{$history_url}','{$history_window_id}','toolbar=no,width=800,height=600,resizable=yes,scrollbars=yes').focus(); return false;\">{$lang['strhistory']}</a></li>\n"; - echo "\t<li><a class=\"toplink\" href=\"{$url}find\" target=\"sqledit\" onclick=\"window.open('{$url}find','{$window_id}','toolbar=no,width=600,height=400,resizable=yes,scrollbars=no').focus(); return false;\">{$lang['strfind']}</a></li>\n"; + echo "\t<li><a class=\"toplink\" href=\"{$sql_url}find\" target=\"sqledit\" onclick=\"window.open('{$sql_url}find','{$sql_window_id}','toolbar=no,width=600,height=400,resizable=yes,scrollbars=no').focus(); return false;\">{$lang['strfind']}</a></li>\n"; echo "\t<li><a class=\"toplink\" href=\"servers.php?action=logout&logoutServer=".htmlspecialchars($server_info['host']).":".htmlspecialchars($server_info['port']).":".htmlspecialchars($server_info['sslmode'])."\">{$lang['strlogout']}</a></li>\n</ul>\n"; @@ -1688,6 +1691,8 @@ echo "<a href=\"{$action['url']}"; if ($action['url'] === '') echo '?'; $misc->printUrlVars($action['vars'], $tabledata->fields); + if (isset($action['target'])) + echo "\" target=\"{$action['target']}"; echo "\">{$action['title']}</a></td>\n"; } } @@ -1994,5 +1999,74 @@ $this->setHREF(); return 0; } + + /** + * Save the given SQL script in the history + * of the database and server. + * @param $script the SQL script to save. + */ + function saveScriptHistory($script) { + list($usec, $sec) = explode(' ', microtime()); + $time = ((float)$usec + (float)$sec); + $_SESSION['history'][$_REQUEST['server']][$_REQUEST['database']]["$time"] = array( + 'query' => $script, + 'paginate' => (!isset($_REQUEST['paginate'])? 'f':'t'), + 'queryid' => $time, + ); + } + + /* + * Output dropdown list to select server and + * databases form the popups windows. + * @param $onchange Javascript action to take when selections change. + */ + function printConnection($onchange) { + global $data, $lang, $misc; + + echo "<table style=\"width: 100%\"><tr><td>\n"; + echo "<label>"; + $misc->printHelp($lang['strserver'], 'pg.server'); + echo "</label>"; + echo ": <select name=\"server\" {$onchange}>\n"; + + $servers = $misc->getServers(); + foreach($servers as $info) { + if (empty($info['username'])) continue; // not logged on this server + echo "<option value=\"", htmlspecialchars($info['id']), "\"", + ((isset($_REQUEST['server']) && $info['id'] == $_REQUEST['server'])) ? ' selected="selected"' : '', ">", + htmlspecialchars("{$info['desc']} ({$info['id']})"), "</option>\n"; + } + echo "</select>\n</td><td style=\"text-align: right\">\n"; + + // Get the list of all databases + $databases = $data->getDatabases(); + + if ($databases->recordCount() > 0) { + + echo "<label>"; + $misc->printHelp($lang['strdatabase'], 'pg.database'); + echo ": <select name=\"database\" {$onchange}>\n"; + + //if no database was selected, user should select one + if (!isset($_REQUEST['database'])) + echo "<option value=\"\">--</option>\n"; + + while (!$databases->EOF) { + $dbname = $databases->fields['datname']; + echo "<option value=\"", htmlspecialchars($dbname), "\"", + ((isset($_REQUEST['database']) && $dbname == $_REQUEST['database'])) ? ' selected="selected"' : '', ">", + htmlspecialchars($dbname), "</option>\n"; + $databases->moveNext(); + } + echo "</select></label>\n"; + } + else { + $server_info = $misc->getServerInfo(); + echo "<input type=\"hidden\" name=\"database\" value=\"", + htmlspecialchars($server_info['defaultdb']), "\" />\n"; + } + + echo "</td></tr></table>\n"; + } } ?> diff --git a/database.php b/database.php index 2fe05c52..c46ae706 100755 --- a/database.php +++ b/database.php @@ -3,7 +3,7 @@ /** * Manage schemas within a database * - * $Id: database.php,v 1.102 2007/09/18 05:03:29 xzilla Exp $ + * $Id: database.php,v 1.103 2007/11/29 23:23:56 ioguix Exp $ */ // Include application functions @@ -857,7 +857,6 @@ $misc->printTrail('database'); $misc->printTabs('database','sql'); - echo "<p>{$lang['strentersql']}</p>\n"; echo "<form action=\"sql.php\" method=\"post\" enctype=\"multipart/form-data\">\n"; echo "<p>{$lang['strsql']}<br />\n"; diff --git a/display.php b/display.php index 15f846d6..004324be 100644 --- a/display.php +++ b/display.php @@ -9,7 +9,7 @@ * @param $return_desc The return link name * @param $page The current page * - * $Id: display.php,v 1.64 2007/09/13 13:41:01 ioguix Exp $ + * $Id: display.php,v 1.65 2007/11/29 23:23:56 ioguix Exp $ */ // Prevent timeouts on large exports (non-safe mode only) @@ -253,8 +253,12 @@ function doBrowse($msg = '') { global $data, $conf, $misc, $lang; + $save_history = false; // If current page is not set, default to first page - if (!isset($_REQUEST['page'])) $_REQUEST['page'] = 1; + if (!isset($_REQUEST['page'])) + $_REQUEST['page'] = 1; + if (!isset($_REQUEST['nohistory'])) + $save_history = true; if (isset($_REQUEST['subject'])) { $subject = $_REQUEST['subject']; @@ -321,9 +325,12 @@ $str2 = "sortkey=" . urlencode($_REQUEST['sortkey']) . "&sortdir=" . urlencode($_REQUEST['sortdir']); + if ($save_history && is_object($rs) && ($type == 'QUERY')) //{ + $misc->saveScriptHistory($_REQUEST['query']); + if (is_object($rs) && $rs->recordCount() > 0) { // Show page navigation - $misc->printPages($_REQUEST['page'], $max_pages, "display.php?page=%s&{$str}&{$str2}&strings=" . urlencode($_REQUEST['strings'])); + $misc->printPages($_REQUEST['page'], $max_pages, "display.php?page=%s&{$str}&{$str2}&nohistory=t&strings=" . urlencode($_REQUEST['strings'])); echo "<table>\n<tr>"; // Check that the key is actually in the result set. This can occur for select diff --git a/history.php b/history.php new file mode 100644 index 00000000..4cdc443f --- /dev/null +++ b/history.php @@ -0,0 +1,144 @@ +<?php + + /** + * Alternative SQL editing window + * + * $Id: history.php,v 1.1 2007/11/29 23:23:56 ioguix Exp $ + */ + + // Include application functions + include_once('./libraries/lib.inc.php'); + + $action = (isset($_REQUEST['action'])) ? $_REQUEST['action'] : ''; + + function doDefault() { + global $data, $misc, $lang, $conf; + + $onchange = "onchange=\"location.href='history.php?server=' + encodeURI(server.options[server.selectedIndex].value) + '&database=' + encodeURI(database.options[database.selectedIndex].value) + '&'\""; + + $misc->printHeader($lang['strhistory']); + + // Bring to the front always + echo "<body onload=\"window.focus();\">\n"; + + echo "<form action=\"history.php\" method=\"post\">\n"; + $misc->printConnection($onchange); + echo "</form><br />"; + + if (!isset($_REQUEST['database'])) { + echo "<p>{$lang['strnodatabaseselected']}</p>\n"; + return; + } + + if (isset($_SESSION['history'][$_REQUEST['server']][$_REQUEST['database']])) { + include_once('classes/ArrayRecordSet.php'); + + $history = new ArrayRecordSet($_SESSION['history'][$_REQUEST['server']][$_REQUEST['database']]); + + $columns = array( + 'query' => array( + 'title' => $lang['strsql'], + 'field' => field('query'), + ), + 'paginate' => array( + 'title' => $lang['strpaginate'], + 'field' => field('paginate'), + 'type' => 'yesno', + ), + 'actions' => array( + 'title' => $lang['stractions'], + ), + ); + + $actions = array( + 'run' => array( + 'title' => $lang['strexecute'], + 'url' => "sql.php?{$misc->href}&nohistory=t&", + 'vars' => array('query' => 'query', 'paginate' => 'paginate'), + 'target' => 'detail', + ), + 'remove' => array( + 'title' => $lang['strdelete'], + 'url' => "history.php?{$misc->href}&action=confdelhistory&", + 'vars' => array('queryid' => 'queryid'), + ), + ); + + $misc->printTable($history, $columns, $actions, $lang['strnohistory']); + } + else echo "<p>{$lang['strnohistory']}</p>\n"; + + echo "<ul class=\"navlink\">\n"; + if (isset($_SESSION['history'][$_REQUEST['server']][$_REQUEST['database']]) + && count($_SESSION['history'][$_REQUEST['server']][$_REQUEST['database']])) + echo "\t<li><a href=\"history.php?action=confclearhistory&{$misc->href}\">{$lang['strclearhistory']}</a></li>\n"; + echo "\t<li><a href=\"history.php?action=history&{$misc->href}\">{$lang['strrefresh']}</a></li>\n</ul>\n"; + } + + function doDelHistory($qid, $confirm) { + global $misc, $lang; + + if ($confirm) { + $misc->printHeader($lang['strhistory']); + + echo "<h3>{$lang['strdelhistory']}</h3>\n"; + echo "<p>{$lang['strconfdelhistory']}</p>\n"; + + echo "<pre>", htmlentities($_SESSION['history'][$_REQUEST['server']][$_REQUEST['database']][$qid]['query']), "</pre>"; + echo "<form action=\"history.php\" method=\"post\">\n"; + echo "<input type=\"hidden\" name=\"action\" value=\"delhistory\" />\n"; + echo "<input type=\"hidden\" name=\"queryid\" value=\"$qid\" />\n"; + echo $misc->form; + echo "<input type=\"submit\" name=\"yes\" value=\"{$lang['stryes']}\" />\n"; + echo "<input type=\"submit\" name=\"no\" value=\"{$lang['strno']}\" />\n"; + echo "</form>\n"; + } + else + unset($_SESSION['history'][$_REQUEST['server']][$_REQUEST['database']][$qid]); + } + + function doClearHistory($confirm) { + global $misc, $lang; + + if ($confirm) { + $misc->printHeader($lang['strhistory']); + + echo "<h3>{$lang['strclearhistory']}</h3>\n"; + echo "<p>{$lang['strconfclearhistory']}</p>\n"; + + echo "<form action=\"history.php\" method=\"post\">\n"; + echo "<input type=\"hidden\" name=\"action\" value=\"clearhistory\" />\n"; + echo $misc->form; + echo "<input type=\"submit\" name=\"yes\" value=\"{$lang['stryes']}\" />\n"; + echo "<input type=\"submit\" name=\"no\" value=\"{$lang['strno']}\" />\n"; + echo "</form>\n"; + } + else + unset($_SESSION['history'][$_REQUEST['server']][$_REQUEST['database']]); + } + + + switch ($action) { + case 'confdelhistory': + doDelHistory($_REQUEST['queryid'], true); + break; + case 'delhistory': + if (isset($_POST['yes'])) doDelHistory($_REQUEST['queryid'], false); + doDefault(); + break; + case 'confclearhistory': + doClearHistory(true); + break; + case 'clearhistory': + if (isset($_POST['yes'])) doClearHistory(false); + doDefault(); + break; + default: + doDefault(); + } + + // Set the name of the window + $misc->setWindowName('history'); + $misc->printFooter(); + +?> diff --git a/lang/english.php b/lang/english.php index e381f141..929d6d1a 100755 --- a/lang/english.php +++ b/lang/english.php @@ -4,7 +4,7 @@ * English language file for phpPgAdmin. Use this as a basis * for new translations. * - * $Id: english.php,v 1.222 2007/11/23 17:58:47 xzilla Exp $ + * $Id: english.php,v 1.223 2007/11/29 23:23:56 ioguix Exp $ */ // Language and character set @@ -140,6 +140,15 @@ $lang['strunselectall'] = 'Unselect all'; $lang['strlocale'] = 'Locale'; + // User-supplied SQL history + $lang['strhistory'] = 'History'; + $lang['strnohistory'] = 'No history.'; + $lang['strclearhistory'] = 'Clear history'; + $lang['strdelhistory'] = 'Delete from history'; + $lang['strconfdelhistory'] = 'Really remove this request from history ?'; + $lang['strconfclearhistory'] = 'Really clear history ?'; + $lang['strnodatabaseselected'] = 'Please, select a database.'; + // Database sizes $lang['strsize'] = 'Size'; $lang['strbytes'] = 'bytes'; diff --git a/redirect.php b/redirect.php index 002c0896..f199681a 100644 --- a/redirect.php +++ b/redirect.php @@ -6,16 +6,17 @@ include_once('./libraries/lib.inc.php'); - $url = parse_url($misc->getLastTabURL($subject)); + $url = $misc->getLastTabURL($subject); // Load query vars into superglobal arrays - if (isset($url['query'])) { + if (isset($url['urlvars'])) { $vars = array(); - parse_str($url['query'], $vars); - + parse_str(value(url($url['url'], $url['urlvars']), $_REQUEST), $vars); + array_shift($vars); + $_REQUEST = array_merge($_REQUEST, $vars); $_GET = array_merge($_GET, $vars); } - require $url['path']; + require $url['url']; ?> @@ -6,7 +6,7 @@ * how many SQL statements have been strung together with semi-colons * @param $query The SQL query string to execute * - * $Id: sql.php,v 1.38 2007/09/13 13:41:01 ioguix Exp $ + * $Id: sql.php,v 1.39 2007/11/29 23:23:56 ioguix Exp $ */ // Prevent timeouts on large exports (non-safe mode only) @@ -124,6 +124,10 @@ // $rs will only be an object if there is no error if (is_object($rs)) { + // Request was run, saving it in history + if(!isset($_REQUEST['nohistory'])) + $misc->saveScriptHistory($_REQUEST['query']); + // Now, depending on what happened do various things // First, if rows returned, then display the results diff --git a/sqledit.php b/sqledit.php index 17b78afd..c9e9f9a9 100644 --- a/sqledit.php +++ b/sqledit.php @@ -3,7 +3,7 @@ /** * Alternative SQL editing window * - * $Id: sqledit.php,v 1.35 2007/07/12 19:26:22 xzilla Exp $ + * $Id: sqledit.php,v 1.36 2007/11/29 23:23:56 ioguix Exp $ */ // Include application functions @@ -26,56 +26,14 @@ // The exact URL to reload to is different between SQL and Find mode, however. if ($action == 'find') { - $onchange .= "'&term=' + encodeURI(term.value) + '&filter=' + encodeURI(filter.value) + '&" . SID . "'\">\n"; + $onchange .= "'&term=' + encodeURI(term.value) + '&filter=' + encodeURI(filter.value) + '&'\""; } else { $onchange .= "'&query=' + encodeURI(query.value) "; if ($data->hasSchemas()) $onchange .= "+ '&search_path=' + encodeURI(search_path.value) "; - $onchange .= "+ (paginate.checked ? '&paginate=on' : '') + '&" . SID . "'\""; + $onchange .= "+ (paginate.checked ? '&paginate=on' : '') + '&'\""; } - echo "<table style=\"width: 100%\"><tr><td>\n"; - echo "<label>"; - $misc->printHelp($lang['strserver'], 'pg.server'); - echo "</label>"; - echo ": <select name=\"server\" {$onchange}>\n"; - - $servers = $misc->getServers(); - foreach($servers as $info) { - if (empty($info['username'])) continue; - echo "<option value=\"", htmlspecialchars($info['id']), "\"", - ((isset($_REQUEST['server']) && $info['id'] == $_REQUEST['server'])) ? ' selected="selected"' : '', ">", - htmlspecialchars("{$info['desc']} ({$info['id']})"), "</option>\n"; - } - echo "</select>\n</td><td style=\"text-align: right\">\n"; - - // Get the list of all databases - $databases = $data->getDatabases(); - - if ($databases->recordCount() > 0) { - // The javascript action on the select box reloads - // the popup whenever the database is changed. - // This ensures that the correct page encoding is used. - - echo "<label>"; - $misc->printHelp($lang['strdatabase'], 'pg.database'); - echo ": <select name=\"database\" {$onchange}>\n"; - - while (!$databases->EOF) { - $dbname = $databases->fields['datname']; - echo "<option value=\"", htmlspecialchars($dbname), "\"", - ((isset($_REQUEST['database']) && $dbname == $_REQUEST['database'])) ? ' selected="selected"' : '', ">", - htmlspecialchars($dbname), "</option>\n"; - $databases->moveNext(); - } - echo "</select></label>\n"; - } - else { - $server_info = $misc->getServerInfo(); - echo "<input type=\"hidden\" name=\"database\" value=\"", - htmlspecialchars($server_info['defaultdb']), "\" />\n"; - } - - echo "</td></tr></table>\n"; + $misc->printConnection($onchange); } /** |