+better detection for when reports database hasn't been installed.
fix getIndexes() and getConstraints() for < 7.3 to know about index type
(eg. constraints can only be btree indexes)
re-enable help system
all DROP and ALTER commands MUST be fully schema-qualified otherwise you can accidentally drop stuff in pg_catalog :(
need icons for Casts and Conversions and Languages
+submit changes to HTML_TreeMenu maintainer
+fix up view select feature (select all) maybe combine this with the table select stuff?
- Brett Toolin
- Mark Gibson (Pop-up SQL window)
- Nicola Soranzo
-
+- Oliver Meyer & Sven Kiera (Table icons link to browse table)
Features
* Option to dump table structure, data or structure and data
+* Results of table browse, table select, view browsing and report browsing
+ can now ALL be sorted by column
+* Result rows of table selects can now be edited and deleted
* Set datestyle and extra_float_digits when dumping data
* Extra login security to prevent logging into servers as postgres and
no password - a VERY common newbie error.
* if you click on a database it shows a list of database objects in that
* database.
*
- * $Id: browser.php,v 1.23 2003/11/03 01:26:37 chriskl Exp $
+ * $Id: browser.php,v 1.24 2003/11/05 08:32:03 chriskl Exp $
*/
// Include application functions
$tables = &$localData->getTables();
while (!$tables->EOF) {
+ $return_url = urlencode("tblproperties.php?table=" . urlencode($tables->f[$data->tbFields['tbname']]) . "&{$querystr}");
$item_node = &new HTML_TreeNode(array(
'text' => addslashes($misc->printVal($tables->f[$data->tbFields['tbname']])),
'link' => addslashes(htmlspecialchars("tblproperties.php?{$querystr}&table=" .
'expandedIcon' => "../../../images/themes/{$conf['theme']}/tables.png",
'expanded' => false,
'linkTarget' => 'detail',
- 'browseLink' => addslashes(htmlspecialchars('tables.php?action=browse&page=1&table='.urlencode($tables->f[$data->tbFields['tbname']]).'&'.$querystr))
+ 'browseLink' => addslashes(htmlspecialchars('display.php?table='.urlencode($tables->f[$data->tbFields['tbname']]).'&'.$querystr.
+ "&return_url={$return_url}&return_desc=" . urlencode($lang['strback'])))
));
// Add table folder to schema
* the functions provided by the database driver exclusively, and hence
* will work with any database without modification.
*
- * $Id: Reports.php,v 1.7 2003/10/15 01:23:42 chriskl Exp $
+ * $Id: Reports.php,v 1.8 2003/11/05 08:32:03 chriskl Exp $
*/
class Reports {
$sql = $this->driver->getSelectSQL('ppa_reports',
array('report_id', 'report_name', 'db_name', 'date_created', 'created_by', 'descr', 'report_sql'),
- $filter, $ops, array('report_name'));
+ $filter, $ops, array(2 => 'asc'));
return $this->driver->selectSet($sql);
}
* A class that implements the DB interface for Postgres
* Note: This class uses ADODB and returns RecordSets.
*
- * $Id: BaseDB.php,v 1.32 2003/10/26 12:12:28 chriskl Exp $
+ * $Id: BaseDB.php,v 1.33 2003/11/05 08:32:03 chriskl Exp $
*/
include_once('classes/database/ADODB_base.php');
/**
* Generates the SQL for the 'select' function
* @param $table The table from which to select
- * @param $show An array of columns to show
+ * @param $show An array of columns to show. Empty array means all columns.
* @param $values An array mapping columns to values
* @param $ops An array of the operators to use
- * @param $orderby (optional) An array of columns to order by
+ * @param $orderby (optional) An array of column numbers (one based)
+ * mapped to sort direction (asc or desc or '' or null) to order by
* @return The SQL query
*/
function getSelectSQL($table, $show, $values, $ops, $orderby = array()) {
$this->fieldClean($table);
+ $this->fieldArrayClean($show);
- $sql = "SELECT \"" . join('","', $show) . "\" FROM ";
+ // If an empty array is passed in, then show all columns
+ if (sizeof($show) == 0) {
+ if ($this->hasObjectID($table))
+ $sql = "SELECT oid, * FROM ";
+ else
+ $sql = "SELECT * FROM ";
+ }
+ else
+ $sql = "SELECT \"" . join('","', $show) . "\" FROM ";
if ($this->hasSchemas() && isset($_REQUEST['schema'])) {
$this->fieldClean($_REQUEST['schema']);
$sql .= "\"{$_REQUEST['schema']}\".";
// ORDER BY
if (is_array($orderby) && sizeof($orderby) > 0) {
- $sql .= " ORDER BY \"" . join('","', $orderby) . "\"";
+ $sql .= " ORDER BY ";
+ foreach ($orderby as $k => $v) {
+ $sql .= $k;
+ if (strtoupper($v) == 'DESC') $sql .= " DESC";
+ }
}
-
+
return $sql;
}
* A class that implements the DB interface for Postgres
* Note: This class uses ADODB and returns RecordSets.
*
- * $Id: Postgres.php,v 1.160 2003/10/27 05:43:18 chriskl Exp $
+ * $Id: Postgres.php,v 1.161 2003/11/05 08:32:03 chriskl Exp $
*/
// @@@ THOUGHT: What about inherits? ie. use of ONLY???
$sql = "ALTER TABLE \"{$table}\" RENAME TO \"{$newName}\"";
- // @@ How do you do this?
return $this->execute($sql);
}
- /**
- * Returns a recordset of all columns in a relation. Supports paging.
- * @param $relation The name of a relation
- * @param $sortkey Field over which to sort. '' for no sort.
- * @param $sortdir 'asc' or 'desc'
- * @param $page The page of the relation to retrieve
- * @param $page_size The number of rows per page
- * @param &$max_pages (return-by-ref) The max number of pages in the relation
- * @return A recordset on success
- * @return -1 transaction error
- * @return -2 counting error
- * @return -3 page or page_size invalid
- */
- function &browseRelation($relation, $sortkey, $sortdir, $page, $page_size, &$max_pages) {
- $oldrelation = $relation;
- $this->fieldClean($relation);
-
- // Check that we're not going to divide by zero
- if (!is_numeric($page_size) || $page_size != (int)$page_size || $page_size <= 0) return -3;
-
- // Open a transaction
- $status = $this->beginTransaction();
- if ($status != 0) return -1;
-
- // Count the number of rows
- $sql = "SELECT COUNT(*) AS total FROM \"{$relation}\"";
- $total = $this->selectField($sql, 'total');
- if ($total < 0) {
- $this->rollbackTransaction();
- return -2;
- }
-
- // Calculate max pages
- $max_pages = ceil($total / $page_size);
-
- // Check that page is less than or equal to max pages
- if (!is_numeric($page) || $page != (int)$page || $page > $max_pages || $page < 1) {
- $this->rollbackTransaction();
- return -3;
- }
-
- // Figure out ORDER BY
- if ($sortkey != '') {
- $this->fieldClean($sortkey);
- $orderby = " ORDER BY \"{$sortkey}\"";
- // Add sort order
- if ($sortdir == 'desc')
- $orderby .= ' DESC';
- else
- $orderby .= ' ASC';
- }
- else $orderby = '';
-
- // We need to do a check to see if the relation has an OID column. If so, then
- // we need to include it in the result set, in case the user has created a primary key
- // constraint on it.
- $hasID = $this->hasObjectID($oldrelation);
-
- // Actually retrieve the rows, with offset and limit
- if ($hasID)
- $rs = $this->selectSet("SELECT \"{$this->id}\",* FROM \"{$relation}\" {$orderby} LIMIT {$page_size} OFFSET " . ($page - 1) * $page_size);
- else
- $rs = $this->selectSet("SELECT * FROM \"{$relation}\" {$orderby} LIMIT {$page_size} OFFSET " . ($page - 1) * $page_size);
-
- $status = $this->endTransaction();
- if ($status != 0) {
- $this->rollbackTransaction();
- return -1;
- }
-
- return $rs;
- }
-
/**
* Finds the number of rows that would be returned by a
* query.
* @return The count of rows
* @return -1 error
*/
- function browseSQLCount($query, $count) {
+ function browseQueryCount($query, $count) {
// Count the number of rows
$rs = $this->selectSet($query);
if (!is_object($rs)) {
/**
* Returns a recordset of all columns in a query. Supports paging.
- * @param $query The SQL SELECT query.
- * @param $count The same SQL query, but only retrieves the count of the rows (AS total)
+ * @param $type Either 'QUERY' if it is an SQL query, or 'TABLE' if it is a table identifier,
+ * or 'SELECT" if it's a select query
+ * @param $table The base table of the query. NULL for no table.
+ * @param $query The query that is being executed. NULL for no query.
+ * @param $sortkey The column number to sort by, or '' or null for no sorting
+ * @param $sortdir The direction in which to sort the specified column ('asc' or 'desc')
* @param $page The page of the relation to retrieve
* @param $page_size The number of rows per page
* @param &$max_pages (return-by-ref) The max number of pages in the relation
* @return -1 transaction error
* @return -2 counting error
* @return -3 page or page_size invalid
+ * @return -4 unknown type
*/
- function &browseSQL($query, $count, $page, $page_size, &$max_pages) {
+ function &browseQuery($type, $table, $query, $sortkey, $sortdir, $page, $page_size, &$max_pages) {
// Check that we're not going to divide by zero
if (!is_numeric($page_size) || $page_size != (int)$page_size || $page_size <= 0) return -3;
+ // If $type is TABLE, then generate the query
+ switch ($type) {
+ case 'TABLE':
+ if (ereg('^[0-9]+$', $sortkey) && $sortkey > 0) $orderby = array($sortkey => $sortdir);
+ else $orderby = array();
+ $query = $this->getSelectSQL($table, array(), array(), array(), $orderby);
+ break;
+ case 'QUERY':
+ case 'SELECT':
+ // Trim query
+ $query = trim($query);
+ // Trim off trailing semi-colon if there is one
+ if (substr($query, strlen($query) - 1, 1) == ';')
+ $query = substr($query, 0, strlen($query) - 1);
+ break;
+ default:
+ return -4;
+ }
+
+ // Generate count query
+ $count = "SELECT COUNT(*) AS total FROM ($query) AS sub";
+
// Open a transaction
$status = $this->beginTransaction();
if ($status != 0) return -1;
// Count the number of rows
- $total = $this->browseSQLCount($query, $count);
+ $total = $this->browseQueryCount($query, $count);
if ($total < 0) {
$this->rollbackTransaction();
return -2;
}
// Set fetch mode to NUM so that duplicate field names are properly returned
- $this->conn->setFetchMode(ADODB_FETCH_NUM);
+ // for non-table queries. Since the SELECT feature only allows selecting one
+ // table, duplicate fields shouldn't appear.
+ if ($type == 'QUERY') $this->conn->setFetchMode(ADODB_FETCH_NUM);
+
+ // Figure out ORDER BY. Sort key is always the column number (based from one)
+ // of the column to order by. Only need to do this for non-TABLE queries
+ if ($type != 'TABLE' && ereg('^[0-9]+$', $sortkey) && $sortkey > 0) {
+ $orderby = " ORDER BY {$sortkey}";
+ // Add sort order
+ if ($sortdir == 'desc')
+ $orderby .= ' DESC';
+ else
+ $orderby .= ' ASC';
+ }
+ else $orderby = '';
// Actually retrieve the rows, with offset and limit
- $rs = $this->selectSet("{$query} LIMIT {$page_size} OFFSET " . ($page - 1) * $page_size);
-
+ $rs = $this->selectSet("SELECT * FROM ({$query}) AS sub {$orderby} LIMIT {$page_size} OFFSET " . ($page - 1) * $page_size);
$status = $this->endTransaction();
if ($status != 0) {
$this->rollbackTransaction();
* A class that implements the DB interface for Postgres
* Note: This class uses ADODB and returns RecordSets.
*
- * $Id: Postgres71.php,v 1.44 2003/10/22 07:22:43 chriskl Exp $
+ * $Id: Postgres71.php,v 1.45 2003/11/05 08:32:03 chriskl Exp $
*/
// @@@ THOUGHT: What about inherits? ie. use of ONLY???
* @return The count of rows
* @return -1 error
*/
- function browseSQLCount($query, $count) {
+ function browseQueryCount($query, $count) {
return $this->selectField($count, 'total');
}
* A class that implements the DB interface for Postgres
* Note: This class uses ADODB and returns RecordSets.
*
- * $Id: Postgres73.php,v 1.76 2003/10/28 04:02:15 chriskl Exp $
+ * $Id: Postgres73.php,v 1.77 2003/11/05 08:32:04 chriskl Exp $
*/
// @@@ THOUGHT: What about inherits? ie. use of ONLY???
$status = $this->beginTransaction();
if ($status != 0) return -1;
-
+
// Get the first primary or unique index (sorting primary keys first) that
// is NOT a partial index.
$sql = "SELECT indrelid, indkey FROM pg_catalog.pg_index WHERE indisunique AND
* @param $return_desc The return link name
* @param $page The current page
*
- * $Id: display.php,v 1.28 2003/09/10 07:25:49 chriskl Exp $
+ * $Id: display.php,v 1.29 2003/11/05 08:32:03 chriskl Exp $
*/
// Include application functions
$action = (isset($_REQUEST['action'])) ? $_REQUEST['action'] : '';
$PHP_SELF = $_SERVER['PHP_SELF'];
- $misc->printHeader($lang['strqueryresults']);
- $misc->printBody();
+ /**
+ * Show confirmation of edit and perform actual update
+ */
+ function doEditRow($confirm, $msg = '') {
+ global $localData, $database, $misc;
+ global $lang;
+ global $PHP_SELF;
- echo "<h2>", $misc->printVal($_REQUEST['database']), ": {$lang['strqueryresults']}</h2>\n";
-
- // If current page is not set, default to first page
- if (!isset($_REQUEST['page'])) $_REQUEST['page'] = 1;
-
- $sub = trim($_REQUEST['query']);
- // Trim off trailing semi-colon if there is one
- if (substr($sub, strlen($sub) - 1, 1) == ';')
- $sub = substr($sub, 0, strlen($sub) - 1);
-
- // If 'count' variable is not set, then set it to select count(*) from
- // 'query'
- if (!isset($_REQUEST['count'])) {
- $_REQUEST['count'] = "SELECT COUNT(*) AS total FROM ({$sub}) AS sub";
+ $key = $_REQUEST['key'];
+
+ if ($confirm) {
+ echo "<h2>", $misc->printVal($_REQUEST['database']), ": {$lang['strtables']}: ", $misc->printVal($_REQUEST['table']), ": {$lang['streditrow']}</h2>\n";
+ $misc->printMsg($msg);
+
+ $attrs = &$localData->getTableAttributes($_REQUEST['table']);
+ $rs = &$localData->browseRow($_REQUEST['table'], $key);
+
+ echo "<form action=\"$PHP_SELF\" method=\"post\">\n";
+ $error = true;
+ if ($rs->recordCount() == 1 && $attrs->recordCount() > 0) {
+ echo "<table>\n<tr>";
+
+ // Output table header
+ echo "<tr><th class=\"data\">{$lang['strfield']}</th><th class=\"data\">{$lang['strtype']}</th>";
+ echo "<th class=\"data\">{$lang['strformat']}</th>\n";
+ echo "<th class=\"data\">{$lang['strnull']}</th><th class=\"data\">{$lang['strvalue']}</th></tr>";
+
+ $i = 0;
+ while (!$attrs->EOF) {
+ $attrs->f['attnotnull'] = $localData->phpBool($attrs->f['attnotnull']);
+ $id = (($i % 2) == 0 ? '1' : '2');
+
+ // Initialise variables
+ if (!isset($_REQUEST['format'][$attrs->f['attname']]))
+ $_REQUEST['format'][$attrs->f['attname']] = 'VALUE';
+
+ echo "<tr>\n";
+ echo "<td class=\"data{$id}\" nowrap=\"nowrap\">", $misc->printVal($attrs->f['attname']), "</td>";
+ echo "<td class=\"data{$id}\" nowrap=\"nowrap\">\n";
+ echo $misc->printVal($localData->formatType($attrs->f['type'], $attrs->f['atttypmod']));
+ echo "<input type=\"hidden\" name=\"types[", htmlspecialchars($attrs->f['attname']), "]\" value=\"",
+ htmlspecialchars($attrs->f['type']), "\" /></td>";
+ echo "<td class=\"data{$id}\" nowrap=\"nowrap\">\n";
+ echo "<select name=\"format[", htmlspecialchars($attrs->f['attname']), "]\">\n";
+ echo "<option value=\"VALUE\"", ($_REQUEST['format'][$attrs->f['attname']] == 'VALUE') ? ' selected="selected"' : '', ">{$lang['strvalue']}</option>\n";
+ echo "<option value=\"EXPRESSION\"", ($_REQUEST['format'][$attrs->f['attname']] == 'EXPRESSION') ? ' selected="selected"' : '', ">{$lang['strexpression']}</option>\n";
+ echo "</select>\n</td>\n";
+ echo "<td class=\"data{$id}\" nowrap=\"nowrap\">";
+ // Output null box if the column allows nulls (doesn't look at CHECKs or ASSERTIONS)
+ if (!$attrs->f['attnotnull']) {
+ // Set initial null values
+ if ($_REQUEST['action'] == 'confeditrow' && $rs->f[$attrs->f['attname']] === null) {
+ $_REQUEST['nulls'][$attrs->f['attname']] = 'on';
+ }
+ echo "<input type=\"checkbox\" name=\"nulls[{$attrs->f['attname']}]\"",
+ isset($_REQUEST['nulls'][$attrs->f['attname']]) ? ' checked="checked"' : '', " /></td>";
+ }
+ else
+ echo " </td>";
+
+ echo "<td class=\"data{$id}\" nowrap>", $localData->printField("values[{$attrs->f['attname']}]",
+ $rs->f[$attrs->f['attname']], $attrs->f['type']), "</td>";
+ echo "</tr>\n";
+ $i++;
+ $attrs->moveNext();
+ }
+ echo "</table></p>\n";
+ $error = false;
+ }
+ elseif ($rs->recordCount() != 1) {
+ echo "<p>{$lang['strrownotunique']}</p>\n";
+ }
+ else {
+ echo "<p>{$lang['strinvalidparam']}</p>\n";
+ }
+
+ echo "<input type=\"hidden\" name=\"action\" value=\"editrow\" />\n";
+ echo $misc->form;
+ if (isset($_REQUEST['table']))
+ echo "<input type=\"hidden\" name=\"table\" value=\"", htmlspecialchars($_REQUEST['table']), "\" />\n";
+ if (isset($_REQUEST['query']))
+ echo "<input type=\"hidden\" name=\"query\" value=\"", htmlspecialchars($_REQUEST['query']), "\" />\n";
+ if (isset($_REQUEST['count']))
+ echo "<input type=\"hidden\" name=\"count\" value=\"", htmlspecialchars($_REQUEST['count']), "\" />\n";
+ if (isset($_REQUEST['return_url']))
+ echo "<input type=\"hidden\" name=\"return_url\" value=\"", htmlspecialchars($_REQUEST['return_url']), "\" />\n";
+ if (isset($_REQUEST['return_desc']))
+ echo "<input type=\"hidden\" name=\"return_desc\" value=\"", htmlspecialchars($_REQUEST['return_desc']), "\" />\n";
+ echo "<input type=\"hidden\" name=\"page\" value=\"", htmlspecialchars($_REQUEST['page']), "\" />\n";
+ echo "<input type=\"hidden\" name=\"sortkey\" value=\"", htmlspecialchars($_REQUEST['sortkey']), "\" />\n";
+ echo "<input type=\"hidden\" name=\"sortdir\" value=\"", htmlspecialchars($_REQUEST['sortdir']), "\" />\n";
+ echo "<input type=\"hidden\" name=\"strings\" value=\"", htmlspecialchars($_REQUEST['strings']), "\" />\n";
+ echo "<input type=\"hidden\" name=\"key\" value=\"", htmlspecialchars(serialize($key)), "\" />\n";
+ echo "<p>";
+ if (!$error) echo "<input type=\"submit\" name=\"save\" value=\"{$lang['strsave']}\" />\n";
+ echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n";
+ echo "</form>\n";
+ }
+ else {
+ if (!isset($_POST['values'])) $_POST['values'] = array();
+ if (!isset($_POST['nulls'])) $_POST['nulls'] = array();
+
+ $status = $localData->editRow($_POST['table'], $_POST['values'], $_POST['nulls'],
+ $_POST['format'], $_POST['types'], unserialize($_POST['key']));
+ if ($status == 0)
+ doBrowse($lang['strrowupdated']);
+ elseif ($status == -2)
+ doEditRow(true, $lang['strrownotunique']);
+ else
+ doEditRow(true, $lang['strrowupdatedbad']);
+ }
+
+ }
+
+ /**
+ * Show confirmation of drop and perform actual drop
+ */
+ function doDelRow($confirm) {
+ global $localData, $database, $misc;
+ global $lang;
+ global $PHP_SELF;
+
+ if ($confirm) {
+ echo "<h2>", $misc->printVal($_REQUEST['database']), ": {$lang['strtables']}: ", $misc->printVal($_REQUEST['table']), ": {$lang['strdeleterow']}</h2>\n";
+
+ echo "<p>{$lang['strconfdeleterow']}</p>\n";
+
+ echo "<form action=\"$PHP_SELF\" method=\"post\">\n";
+ echo "<input type=\"hidden\" name=\"action\" value=\"delrow\" />\n";
+ echo $misc->form;
+ if (isset($_REQUEST['table']))
+ echo "<input type=\"hidden\" name=\"table\" value=\"", htmlspecialchars($_REQUEST['table']), "\" />\n";
+ if (isset($_REQUEST['query']))
+ echo "<input type=\"hidden\" name=\"query\" value=\"", htmlspecialchars($_REQUEST['query']), "\" />\n";
+ if (isset($_REQUEST['count']))
+ echo "<input type=\"hidden\" name=\"count\" value=\"", htmlspecialchars($_REQUEST['count']), "\" />\n";
+ if (isset($_REQUEST['return_url']))
+ echo "<input type=\"hidden\" name=\"return_url\" value=\"", htmlspecialchars($_REQUEST['return_url']), "\" />\n";
+ if (isset($_REQUEST['return_desc']))
+ echo "<input type=\"hidden\" name=\"return_desc\" value=\"", htmlspecialchars($_REQUEST['return_desc']), "\" />\n";
+ echo "<input type=\"hidden\" name=\"page\" value=\"", htmlspecialchars($_REQUEST['page']), "\" />\n";
+ echo "<input type=\"hidden\" name=\"sortkey\" value=\"", htmlspecialchars($_REQUEST['sortkey']), "\" />\n";
+ echo "<input type=\"hidden\" name=\"sortdir\" value=\"", htmlspecialchars($_REQUEST['sortdir']), "\" />\n";
+ echo "<input type=\"hidden\" name=\"strings\" value=\"", htmlspecialchars($_REQUEST['strings']), "\" />\n";
+ echo "<input type=\"hidden\" name=\"key\" value=\"", htmlspecialchars(serialize($_REQUEST['key'])), "\" />\n";
+ echo "<input type=\"submit\" name=\"yes\" value=\"{$lang['stryes']}\" />\n";
+ echo "<input type=\"submit\" name=\"no\" value=\"{$lang['strno']}\" />\n";
+ echo "</form>\n";
+ }
+ else {
+ $status = $localData->deleteRow($_POST['table'], unserialize($_POST['key']));
+ if ($status == 0)
+ doBrowse($lang['strrowdeleted']);
+ elseif ($status == -2)
+ doBrowse($lang['strrownotunique']);
+ else
+ doBrowse($lang['strrowdeletedbad']);
+ }
+
}
- // Retrieve page from table. $max_pages is returned by reference.
- $rs = &$localData->browseSQL($sub, $_REQUEST['count'], $_REQUEST['page'], $conf['max_rows'], $max_pages);
-
- if (is_object($rs) && $rs->recordCount() > 0) {
- // Show page navigation
- $misc->printPages($_REQUEST['page'], $max_pages, "display.php?page=%s&{$misc->href}&query=" .
- urlencode($_REQUEST['query']) . '&count=' . urlencode($_REQUEST['count']) . '&return_url=' .
- urlencode($_REQUEST['return_url']) . '&return_desc=' . urlencode($_REQUEST['return_desc']));
- echo "<table>\n<tr>";
+ /**
+ * Displays requested data
+ */
+ function doBrowse() {
+ global $localData, $conf, $misc, $lang;
- foreach ($rs->f as $k => $v) {
- $finfo = $rs->fetchField($k);
- echo "<th class=\"data\">", $misc->printVal($finfo->name), "</th>";
+ // If current page is not set, default to first page
+ if (!isset($_REQUEST['page'])) $_REQUEST['page'] = 1;
+
+ // If 'table' is not set, default to '' and set type
+ if (isset($_REQUEST['table']) && isset($_REQUEST['query'])) {
+ echo "<h2>", $misc->printVal($_REQUEST['database']), ": {$lang['strtables']}: ", $misc->printVal($_REQUEST['table']), ": {$lang['strselect']}</h2>\n";
+ $type = 'SELECT';
+ }
+ elseif (isset($_REQUEST['table'])) {
+ echo "<h2>", $misc->printVal($_REQUEST['database']), ": {$lang['strtables']}: ", $misc->printVal($_REQUEST['table']), ": {$lang['strbrowse']}</h2>\n";
+ $type = 'TABLE';
+ }
+ else {
+ echo "<h2>", $misc->printVal($_REQUEST['database']), ": {$lang['strqueryresults']}</h2>\n";
+ $type = 'QUERY';
}
- echo "</tr>\n";
+ // If 'sortkey' is not set, default to ''
+ if (!isset($_REQUEST['sortkey'])) $_REQUEST['sortkey'] = '';
+
+ // If 'sortdir' is not set, default to ''
+ if (!isset($_REQUEST['sortdir'])) $_REQUEST['sortdir'] = '';
+
+ // If 'strings' is not set, default to collapsed
+ if (!isset($_REQUEST['strings'])) $_REQUEST['strings'] = 'collapsed';
+
+ // Fetch unique row identifier, if this is a table browse request.
+ if (isset($_REQUEST['table']))
+ $key = $localData->getRowIdentifier($_REQUEST['table']);
+ else
+ $key = array();
+
+ // Retrieve page from query. $max_pages is returned by reference.
+ $rs = &$localData->browseQuery($type,
+ isset($_REQUEST['table']) ? $_REQUEST['table'] : null,
+ isset($_REQUEST['query']) ? $_REQUEST['query'] : null,
+ $_REQUEST['sortkey'], $_REQUEST['sortdir'], $_REQUEST['page'],
+ $conf['max_rows'], $max_pages);
+
+ // Build strings for GETs
+ $str = $misc->href . "&page=" . urlencode($_REQUEST['page']);
+ if (isset($_REQUEST['table'])) $str .= "&table=" . urlencode($_REQUEST['table']);
+ if (isset($_REQUEST['query'])) $str .= "&query=" . urlencode($_REQUEST['query']);
+ if (isset($_REQUEST['count'])) $str .= "&count=" . urlencode($_REQUEST['count']);
+ if (isset($_REQUEST['return_url'])) $str .= "&return_url=" . urlencode($_REQUEST['return_url']);
+ if (isset($_REQUEST['return_desc'])) $str .= "&return_desc=" . urlencode($_REQUEST['return_desc']);
+
+ // This string just contains sort info
+ $str2 = "sortkey=" . urlencode($_REQUEST['sortkey']) .
+ "&sortdir=" . urlencode($_REQUEST['sortdir']);
+
+ if (is_object($rs) && $rs->recordCount() > 0) {
+ // Show page navigation
+ $misc->printPages($_REQUEST['page'], $max_pages, "display.php?page=%s&{$str}&{$str2}");
+ echo "<table>\n<tr>";
+
+ // Check that the key is actually in the result set. This can occur for select
+ // operations where the key fields aren't part of the select. XXX: We should
+ // be able to support this, somehow.
+ foreach ($key as $v) {
+ // If a key column is not found in the record set, then we
+ // can't use the key.
+ if (!in_array($v, array_keys($rs->f))) {
+ $key = array();
+ break;
+ }
+ }
+ // Display edit and delete actions if we have a key
+ if (sizeof($key) > 0)
+ echo "<th colspan=\"2\" class=\"data\">{$lang['stractions']}</th>\n";
- $i = 0;
- while (!$rs->EOF) {
- $id = (($i % 2) == 0 ? '1' : '2');
- echo "<tr>\n";
+ $j = 0;
foreach ($rs->f as $k => $v) {
- $finfo = $rs->fetchField($k);
- echo "<td class=\"data{$id}\" nowrap=\"nowrap\">", $misc->printVal($v, true, $finfo->type), "</td>";
- }
+ if (isset($_REQUEST['table']) && $k == $localData->id && !$conf['show_oids']) {
+ $j++;
+ continue;
+ }
+ $finfo = $rs->fetchField($j);
+ // Display column headers with sorting options
+ echo "<th class=\"data\"><a href=\"display.php?{$str}&sortkey=", ($j + 1), "&sortdir=";
+ // Sort direction opposite to current direction, unless it's currently ''
+ echo ($_REQUEST['sortdir'] == 'asc' && $_REQUEST['sortkey'] == ($j + 1)) ? 'desc' : 'asc';
+ echo "&strings=", urlencode($_REQUEST['strings']), "\">",
+ $misc->printVal($finfo->name), "</a></th>\n";
+ $j++;
+ }
+
echo "</tr>\n";
- $rs->moveNext();
- $i++;
+
+ $i = 0;
+ reset($rs->f);
+ while (!$rs->EOF) {
+ $id = (($i % 2) == 0 ? '1' : '2');
+ echo "<tr>\n";
+ // Display edit and delete links if we have a key
+ if (sizeof($key) > 0) {
+ $key_str = '';
+ $has_nulls = false;
+ foreach ($key as $v) {
+ if ($rs->f[$v] === null) {
+ $has_nulls = true;
+ break;
+ }
+ if ($key_str != '') $key_str .= '&';
+ $key_str .= urlencode("key[{$v}]") . '=' . urlencode($rs->f[$v]);
+ }
+ if ($has_nulls) {
+ echo "<td class=\"data{$id}\" colspan=\"2\"> </td>\n";
+ } else {
+ echo "<td class=\"opbutton{$id}\"><a href=\"display.php?action=confeditrow&strings=",
+ urlencode($_REQUEST['strings']), "&{$key_str}&{$str}&{$str2}\">{$lang['stredit']}</a></td>\n";
+ echo "<td class=\"opbutton{$id}\"><a href=\"display.php?action=confdelrow&strings=",
+ urlencode($_REQUEST['strings']), "&{$key_str}&{$str}&{$str2}\">{$lang['strdelete']}</a></td>\n";
+ }
+ }
+ $j = 0;
+ foreach ($rs->f as $k => $v) {
+ $finfo = $rs->fetchField($j++);
+ if (isset($_REQUEST['table']) && $k == $localData->id && !$conf['show_oids']) continue;
+ elseif ($v !== null && $v == '') echo "<td class=\"data{$id}\"> </td>";
+ else {
+ // Trim strings if over length
+ if ($_REQUEST['strings'] == 'collapsed' && strlen($v) > $conf['max_chars']) {
+ $v = substr($v, 0, $conf['max_chars'] - 1) . $lang['strellipsis'];
+ }
+ echo "<td class=\"data{$id}\" nowrap=\"nowrap\">", $misc->printVal($v, true, $finfo->type), "</td>";
+ }
+ }
+ echo "</tr>\n";
+ $rs->moveNext();
+ $i++;
+ }
+ echo "</table>\n";
+ echo "<p>", $rs->recordCount(), " {$lang['strrows']}</p>\n";
}
-
- echo "</table>\n";
- echo "<p>", $rs->recordCount(), " {$lang['strrows']}</p>\n";
- }
- else echo "<p>{$lang['strnodata']}</p>\n";
+ else echo "<p>{$lang['strnodata']}</p>\n";
- echo "<p><a class=\"navlink\" href=\"{$_REQUEST['return_url']}\">{$_REQUEST['return_desc']}</a>";
- if ($conf['show_reports'] && isset($rs) && is_object($rs) && $rs->recordCount() > 0) {
- echo " | <a class=\"navlink\" href=\"reports.php?action=create&db_name=", urlencode($_REQUEST['database']), "&report_sql=",
- urlencode($_REQUEST['query']), "\">{$lang['strcreatereport']}</a>\n";
+ // Return
+ echo "<p><a class=\"navlink\" href=\"{$_REQUEST['return_url']}\">{$_REQUEST['return_desc']}</a>\n";
+ // Expand/Collapse
+ if ($_REQUEST['strings'] == 'expanded')
+ echo "| <a class=\"navlink\" href=\"display.php?{$str}&{$str2}&strings=collapsed\">{$lang['strcollapse']}</a>\n";
+ else
+ echo "| <a class=\"navlink\" href=\"display.php?{$str}&{$str2}&strings=expanded\">{$lang['strexpand']}</a>\n";
+ // Create report
+ if (isset($_REQUEST['query']) && $conf['show_reports'] && isset($rs) && is_object($rs) && $rs->recordCount() > 0) {
+ echo " | <a class=\"navlink\" href=\"reports.php?action=create&db_name=", urlencode($_REQUEST['database']), "&report_sql=",
+ urlencode($_REQUEST['query']), "\">{$lang['strcreatereport']}</a>\n";
+ }
+ // Create view and download
+ if (isset($_REQUEST['query']) && isset($rs) && is_object($rs) && $rs->recordCount() > 0) {
+ echo " | <a class=\"navlink\" href=\"views.php?action=create&formDefinition=",
+ urlencode($_REQUEST['query']), "&{$misc->href}\">{$lang['strcreateview']}</a>\n";
+ echo " | <a class=\"navlink\" href=\"dataexport.php?query=",
+ urlencode($_REQUEST['query']), "&{$misc->href}\">{$lang['strdownload']}</a>\n";
+ }
+ // Refresh
+ echo "| <a class=\"navlink\" href=\"display.php?{$str}&{$str2}&strings=", urlencode($_REQUEST['strings']),
+ "\">{$lang['strrefresh']}</a></p>\n";
+
+ echo "</p>\n";
}
- if (isset($rs) && is_object($rs) && $rs->recordCount() > 0) {
- echo " | <a class=\"navlink\" href=\"views.php?action=create&formDefinition=",
- urlencode($_REQUEST['query']), "&{$misc->href}\">{$lang['strcreateview']}</a>\n";
- echo " | <a class=\"navlink\" href=\"dataexport.php?query=",
- urlencode($_REQUEST['query']), "&{$misc->href}\">{$lang['strdownload']}</a>\n";
+
+ // If a table is specified, then set the title differently
+ if (isset($_REQUEST['table']))
+ $misc->printHeader($lang['strtables']);
+ else
+ $misc->printHeader($lang['strqueryresults']);
+ $misc->printBody();
+
+ switch ($action) {
+ case 'editrow':
+ if (isset($_POST['save'])) doEditRow(false);
+ else doBrowse();
+ break;
+ case 'confeditrow':
+ doEditRow(true);
+ break;
+ case 'delrow':
+ if (isset($_POST['yes'])) doDelRow(false);
+ else doBrowse();
+ break;
+ case 'confdelrow':
+ doDelRow(true);
+ break;
+ default:
+ doBrowse();
+ break;
}
- echo "</p>\n";
$misc->printFooter();
?>
/**
* List tables in a database
*
- * $Id: tables.php,v 1.38 2003/10/13 08:50:03 chriskl Exp $
+ * $Id: tables.php,v 1.39 2003/11/05 08:32:03 chriskl Exp $
*/
// Include application functions
}
- /**
- * Show confirmation of edit and perform actual update
- */
- function doEditRow($confirm, $msg = '') {
- global $localData, $database, $misc;
- global $lang;
- global $PHP_SELF;
-
- $key = $_REQUEST['key'];
-
- if ($confirm) {
- echo "<h2>", $misc->printVal($_REQUEST['database']), ": {$lang['strtables']}: ", $misc->printVal($_REQUEST['table']), ": {$lang['streditrow']}</h2>\n";
- $misc->printMsg($msg);
-
- $attrs = &$localData->getTableAttributes($_REQUEST['table']);
- $rs = &$localData->browseRow($_REQUEST['table'], $key);
-
- echo "<form action=\"$PHP_SELF\" method=\"post\">\n";
- $error = true;
- if ($rs->recordCount() == 1 && $attrs->recordCount() > 0) {
- echo "<table>\n<tr>";
-
- // Output table header
- echo "<tr><th class=\"data\">{$lang['strfield']}</th><th class=\"data\">{$lang['strtype']}</th>";
- echo "<th class=\"data\">{$lang['strformat']}</th>\n";
- echo "<th class=\"data\">{$lang['strnull']}</th><th class=\"data\">{$lang['strvalue']}</th></tr>";
-
- // @@ CHECK THAT KEY ACTUALLY IS IN THE RESULT SET...
-
- $i = 0;
- while (!$attrs->EOF) {
- $attrs->f['attnotnull'] = $localData->phpBool($attrs->f['attnotnull']);
- $id = (($i % 2) == 0 ? '1' : '2');
-
- // Initialise variables
- if (!isset($_REQUEST['format'][$attrs->f['attname']]))
- $_REQUEST['format'][$attrs->f['attname']] = 'VALUE';
-
- echo "<tr>\n";
- echo "<td class=\"data{$id}\" nowrap=\"nowrap\">", $misc->printVal($attrs->f['attname']), "</td>";
- echo "<td class=\"data{$id}\" nowrap=\"nowrap\">\n";
- echo $misc->printVal($localData->formatType($attrs->f['type'], $attrs->f['atttypmod']));
- echo "<input type=\"hidden\" name=\"types[", htmlspecialchars($attrs->f['attname']), "]\" value=\"",
- htmlspecialchars($attrs->f['type']), "\" /></td>";
- echo "<td class=\"data{$id}\" nowrap=\"nowrap\">\n";
- echo "<select name=\"format[", htmlspecialchars($attrs->f['attname']), "]\">\n";
- echo "<option value=\"VALUE\"", ($_REQUEST['format'][$attrs->f['attname']] == 'VALUE') ? ' selected="selected"' : '', ">{$lang['strvalue']}</option>\n";
- echo "<option value=\"EXPRESSION\"", ($_REQUEST['format'][$attrs->f['attname']] == 'EXPRESSION') ? ' selected="selected"' : '', ">{$lang['strexpression']}</option>\n";
- echo "</select>\n</td>\n";
- echo "<td class=\"data{$id}\" nowrap=\"nowrap\">";
- // Output null box if the column allows nulls (doesn't look at CHECKs or ASSERTIONS)
- if (!$attrs->f['attnotnull']) {
- // Set initial null values
- if ($_REQUEST['action'] == 'confeditrow' && $rs->f[$attrs->f['attname']] === null) {
- $_REQUEST['nulls'][$attrs->f['attname']] = 'on';
- }
- echo "<input type=\"checkbox\" name=\"nulls[{$attrs->f['attname']}]\"",
- isset($_REQUEST['nulls'][$attrs->f['attname']]) ? ' checked="checked"' : '', " /></td>";
- }
- else
- echo " </td>";
-
- echo "<td class=\"data{$id}\" nowrap>", $localData->printField("values[{$attrs->f['attname']}]",
- $rs->f[$attrs->f['attname']], $attrs->f['type']), "</td>";
- echo "</tr>\n";
- $i++;
- $attrs->moveNext();
- }
- echo "</table></p>\n";
- $error = false;
- }
- elseif ($rs->recordCount() != 1) {
- echo "<p>{$lang['strrownotunique']}</p>\n";
- }
- else {
- echo "<p>{$lang['strinvalidparam']}</p>\n";
- }
-
- echo "<input type=\"hidden\" name=\"action\" value=\"editrow\" />\n";
- echo "<input type=\"hidden\" name=\"table\" value=\"", htmlspecialchars($_REQUEST['table']), "\" />\n";
- echo $misc->form;
- echo "<input type=\"hidden\" name=\"page\" value=\"", htmlspecialchars($_REQUEST['page']), "\" />\n";
- echo "<input type=\"hidden\" name=\"sortkey\" value=\"", htmlspecialchars($_REQUEST['sortkey']), "\" />\n";
- echo "<input type=\"hidden\" name=\"sortdir\" value=\"", htmlspecialchars($_REQUEST['sortdir']), "\" />\n";
- echo "<input type=\"hidden\" name=\"strings\" value=\"", htmlspecialchars($_REQUEST['strings']), "\" />\n";
- echo "<input type=\"hidden\" name=\"key\" value=\"", htmlspecialchars(serialize($key)), "\" />\n";
- echo "<p>";
- if (!$error) echo "<input type=\"submit\" name=\"save\" value=\"{$lang['strsave']}\" />\n";
- echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n";
- echo "</form>\n";
- }
- else {
- if (!isset($_POST['values'])) $_POST['values'] = array();
- if (!isset($_POST['nulls'])) $_POST['nulls'] = array();
-
- $status = $localData->editRow($_POST['table'], $_POST['values'], $_POST['nulls'],
- $_POST['format'], $_POST['types'], unserialize($_POST['key']));
- if ($status == 0)
- doBrowse($lang['strrowupdated']);
- elseif ($status == -2)
- doEditRow(true, $lang['strrownotunique']);
- else
- doEditRow(true, $lang['strrowupdatedbad']);
- }
-
- }
-
- /**
- * Show confirmation of drop and perform actual drop
- */
- function doDelRow($confirm) {
- global $localData, $database, $misc;
- global $lang;
- global $PHP_SELF;
-
- if ($confirm) {
- echo "<h2>", $misc->printVal($_REQUEST['database']), ": {$lang['strtables']}: ", $misc->printVal($_REQUEST['table']), ": {$lang['strdeleterow']}</h2>\n";
-
- echo "<p>{$lang['strconfdeleterow']}</p>\n";
-
- echo "<form action=\"$PHP_SELF\" method=\"post\">\n";
- echo "<input type=\"hidden\" name=\"action\" value=\"delrow\" />\n";
- echo "<input type=\"hidden\" name=\"table\" value=\"", htmlspecialchars($_REQUEST['table']), "\" />\n";
- echo $misc->form;
- echo "<input type=\"hidden\" name=\"page\" value=\"", htmlspecialchars($_REQUEST['page']), "\" />\n";
- echo "<input type=\"hidden\" name=\"sortkey\" value=\"", htmlspecialchars($_REQUEST['sortkey']), "\" />\n";
- echo "<input type=\"hidden\" name=\"sortdir\" value=\"", htmlspecialchars($_REQUEST['sortdir']), "\" />\n";
- echo "<input type=\"hidden\" name=\"strings\" value=\"", htmlspecialchars($_REQUEST['strings']), "\" />\n";
- echo "<input type=\"hidden\" name=\"key\" value=\"", htmlspecialchars(serialize($_REQUEST['key'])), "\" />\n";
- echo "<input type=\"submit\" name=\"yes\" value=\"{$lang['stryes']}\" />\n";
- echo "<input type=\"submit\" name=\"no\" value=\"{$lang['strno']}\" />\n";
- echo "</form>\n";
- }
- else {
- $status = $localData->deleteRow($_POST['table'], unserialize($_POST['key']));
- if ($status == 0)
- doBrowse($lang['strrowdeleted']);
- elseif ($status == -2)
- doBrowse($lang['strrownotunique']);
- else
- doBrowse($lang['strrowdeletedbad']);
- }
-
- }
-
- /**
- * Browse a table
- */
- function doBrowse($msg = '') {
- global $data, $localData, $misc, $conf;
- global $PHP_SELF, $lang;
-
- echo "<h2>", $misc->printVal($_REQUEST['database']), ": ", $misc->printVal($_REQUEST['table']), ": {$lang['strbrowse']}</h2>\n";
- $misc->printMsg($msg);
-
- if (!isset($_REQUEST['page'])) $_REQUEST['page'] = 1;
- if (!isset($_REQUEST['sortkey'])) $_REQUEST['sortkey'] = '';
- if (!isset($_REQUEST['sortdir'])) $_REQUEST['sortdir'] = '';
- if (!isset($_REQUEST['strings'])) $_REQUEST['strings'] = 'collapsed';
-
- // Retrieve page from table. $max_pages is returned by reference.
- $rs = &$localData->browseRelation($_REQUEST['table'], $_REQUEST['sortkey'], $_REQUEST['sortdir'],
- $_REQUEST['page'], $conf['max_rows'], $max_pages);
-
- // Fetch unique row identifier, if there is one
- $key = $localData->getRowIdentifier($_REQUEST['table']);
-
- if (is_object($rs) && $rs->recordCount() > 0) {
- // Show page navigation
- $misc->printPages($_REQUEST['page'], $max_pages, "{$PHP_SELF}?action=browse&page=%s&{$misc->href}&sortkey=" .
- urlencode($_REQUEST['sortkey']) . "&sortdir=" . urlencode($_REQUEST['sortdir']) .
- "&strings=" . urlencode($_REQUEST['strings']) . "&table=" . urlencode($_REQUEST['table']));
- echo "<table>\n<tr>";
-
- // @@ CHECK THAT KEY ACTUALLY IS IN THE RESULT SET...
-
- if (sizeof($key) > 0)
- echo "<th colspan=\"2\" class=\"data\">{$lang['stractions']}</th>\n";
-
- reset($rs->f);
- while(list($k, ) = each($rs->f)) {
- if ($k == $localData->id && !$conf['show_oids']) continue;
- echo "<th class=\"data\"><a href=\"{$PHP_SELF}?action=browse&page=", $_REQUEST['page'],
- "&{$misc->href}&sortkey=", urlencode($k), "&sortdir=";
- // Sort direction opposite to current direction, unless it's currently ''
- echo ($_REQUEST['sortdir'] == 'asc' && $_REQUEST['sortkey'] == $k) ? 'desc' : 'asc';
- echo "&strings=", urlencode($_REQUEST['strings']), "&table=",
- urlencode($_REQUEST['table']), "\">", $misc->printVal($k), "</a></th>\n";
- }
-
- $i = 0;
- reset($rs->f);
- while (!$rs->EOF) {
- $id = (($i % 2) == 0 ? '1' : '2');
- echo "<tr>\n";
- if (sizeof($key) > 0) {
- $key_str = '';
- $has_nulls = false;
- foreach ($key as $v) {
- if ($rs->f[$v] === null) {
- $has_nulls = true;
- break;
- }
- if ($key_str != '') $key_str .= '&';
- $key_str .= urlencode("key[{$v}]") . '=' . urlencode($rs->f[$v]);
- }
- if ($has_nulls) {
- echo "<td class=\"data{$id}\" colspan=\"2\"> </td>\n";
- } else {
- echo "<td class=\"opbutton{$id}\"><a href=\"{$PHP_SELF}?action=confeditrow&{$misc->href}&sortkey=",
- urlencode($_REQUEST['sortkey']), "&sortdir=", urlencode($_REQUEST['sortdir']),
- "&table=", urlencode($_REQUEST['table']), "&strings=", urlencode($_REQUEST['strings']),
- "&page=", $_REQUEST['page'], "&{$key_str}\">{$lang['stredit']}</a></td>\n";
- echo "<td class=\"opbutton{$id}\"><a href=\"{$PHP_SELF}?action=confdelrow&{$misc->href}&sortkey=",
- urlencode($_REQUEST['sortkey']), "&sortdir=", urlencode($_REQUEST['sortdir']),
- "&table=", urlencode($_REQUEST['table']), "&strings=", urlencode($_REQUEST['strings']),
- "&page=", $_REQUEST['page'], "&{$key_str}\">{$lang['strdelete']}</a></td>\n";
- }
- }
- $j = 0;
- foreach ($rs->f as $k => $v) {
- $finfo = $rs->fetchField($j++);
- if ($k == $localData->id && !$conf['show_oids']) continue;
- elseif ($v !== null && $v == '') echo "<td class=\"data{$id}\"> </td>";
- else {
- // Trim strings if over length
- if ($_REQUEST['strings'] == 'collapsed' && strlen($v) > $conf['max_chars']) {
- $v = substr($v, 0, $conf['max_chars'] - 1) . $lang['strellipsis'];
- }
- echo "<td class=\"data{$id}\" nowrap=\"nowrap\">", $misc->printVal($v, true, $finfo->type), "</td>";
- }
- }
- echo "</tr>\n";
- $rs->moveNext();
- $i++;
- }
- echo "</table>\n";
-
- // Show page navigation
- $misc->printPages($_REQUEST['page'], $max_pages, "{$PHP_SELF}?action=browse&page=%s&{$misc->href}&sortkey=" .
- urlencode($_REQUEST['sortkey']) . "&sortdir=" . urlencode($_REQUEST['sortdir']) .
- "&strings=" . urlencode($_REQUEST['strings']) . "&table=" . urlencode($_REQUEST['table']));
-
- echo "<p>", $rs->recordCount(), " {$lang['strrows']}</p>\n";
- }
- else echo "<p>{$lang['strnodata']}</p>\n";
-
- echo "<p><a class=\"navlink\" href=\"$PHP_SELF?{$misc->href}\">{$lang['strshowalltables']}</a> |\n";
- if ($_REQUEST['strings'] == 'expanded')
- echo "<a class=\"navlink\" href=\"{$PHP_SELF}?action=browse&{$misc->href}&sortkey=",
- urlencode($_REQUEST['sortkey']), "&sortdir=", urlencode($_REQUEST['sortdir']), "&table=", urlencode($_REQUEST['table']),
- "&strings=collapsed&page=", $_REQUEST['page'], "\">{$lang['strcollapse']}</a>\n";
- else
- echo "<a class=\"navlink\" href=\"{$PHP_SELF}?action=browse&{$misc->href}&sortkey=",
- urlencode($_REQUEST['sortkey']), "&sortdir=", urlencode($_REQUEST['sortdir']), "&table=", urlencode($_REQUEST['table']),
- "&strings=expanded&page=", $_REQUEST['page'], "\">{$lang['strexpand']}</a>\n";
- echo "| <a class=\"navlink\" href=\"{$PHP_SELF}?action=browse&{$misc->href}&sortkey=",
- urlencode($_REQUEST['sortkey']), "&sortdir=", urlencode($_REQUEST['sortdir']), "&table=", urlencode($_REQUEST['table']),
- "&strings={$_REQUEST['strings']}&page=", $_REQUEST['page'], "\">{$lang['strrefresh']}</a></p>\n";
-
- }
-
/**
* Show default list of tables in the database
*/
echo "\t<th colspan=\"6\" class=\"data\">{$lang['stractions']}</th>\n</tr>\n";
$i = 0;
while (!$tables->EOF) {
+ $return_url = urlencode("tables.php?{$misc->href}");
$id = (($i % 2) == 0 ? '1' : '2');
echo "<tr>\n\t<td class=\"data{$id}\">", $misc->printVal($tables->f[$data->tbFields['tbname']]), "</td>\n";
echo "\t<td class=\"data{$id}\">", $misc->printVal($tables->f[$data->tbFields['tbowner']]), "</td>\n";
- echo "\t<td class=\"opbutton{$id}\"><a href=\"{$PHP_SELF}?action=browse&page=1&{$misc->href}&table=",
- urlencode($tables->f[$data->tbFields['tbname']]), "\">{$lang['strbrowse']}</a></td>\n";
- echo "\t<td class=\"opbutton{$id}\"><a href=\"$PHP_SELF?action=confselectrows&{$misc->href}&table=",
+ echo "\t<td class=\"opbutton{$id}\"><a href=\"display.php?{$misc->href}&table=",
+ urlencode($tables->f[$data->tbFields['tbname']]), "&return_url={$return_url}&return_desc=",
+ urlencode($lang['strback']), "\">{$lang['strbrowse']}</a></td>\n";
+ echo "\t<td class=\"opbutton{$id}\"><a href=\"$PHP_SELF?action=confselectrows&{$misc->href}&table=",
urlencode($tables->f[$data->tbFields['tbname']]), "\">{$lang['strselect']}</a></td>\n";
- echo "\t<td class=\"opbutton{$id}\"><a href=\"$PHP_SELF?action=confinsertrow&{$misc->href}&table=",
+ echo "\t<td class=\"opbutton{$id}\"><a href=\"$PHP_SELF?action=confinsertrow&{$misc->href}&table=",
urlencode($tables->f[$data->tbFields['tbname']]), "\">{$lang['strinsert']}</a></td>\n";
- echo "\t<td class=\"opbutton{$id}\"><a href=\"tblproperties.php?{$misc->href}&table=",
+ echo "\t<td class=\"opbutton{$id}\"><a href=\"tblproperties.php?{$misc->href}&table=",
urlencode($tables->f[$data->tbFields['tbname']]), "\">{$lang['strproperties']}</a></td>\n";
- echo "\t<td class=\"opbutton{$id}\"><a href=\"$PHP_SELF?action=confirm_empty&{$misc->href}&table=",
+ echo "\t<td class=\"opbutton{$id}\"><a href=\"$PHP_SELF?action=confirm_empty&{$misc->href}&table=",
urlencode($tables->f[$data->tbFields['tbname']]), "\">{$lang['strempty']}</a></td>\n";
- echo "\t<td class=\"opbutton{$id}\"><a href=\"$PHP_SELF?action=confirm_drop&{$misc->href}&table=",
+ echo "\t<td class=\"opbutton{$id}\"><a href=\"$PHP_SELF?action=confirm_drop&{$misc->href}&table=",
urlencode($tables->f[$data->tbFields['tbname']]), "\">{$lang['strdrop']}</a></td>\n";
echo "</tr>\n";
$tables->moveNext();
echo "<p>{$lang['strnotables']}</p>\n";
}
- echo "<p><a class=\"navlink\" href=\"$PHP_SELF?action=create&{$misc->href}\">{$lang['strcreatetable']}</a></p>\n";
+ echo "<p><a class=\"navlink\" href=\"$PHP_SELF?action=create&{$misc->href}\">{$lang['strcreatetable']}</a></p>\n";
}
$misc->printHeader($lang['strtables']);
case 'confirm_drop':
doDrop(true);
break;
- case 'editrow':
- if (isset($_POST['save'])) doEditRow(false);
- else doBrowse();
- break;
- case 'confeditrow':
- doEditRow(true);
- break;
- case 'delrow':
- if (isset($_POST['yes'])) doDelRow(false);
- else doBrowse();
- break;
- case 'confdelrow':
- doDelRow(true);
- break;
- case 'browse':
- doBrowse();
- break;
default:
doDefault();
break;
/**
* List tables in a database
*
- * $Id: tblproperties.php,v 1.29 2003/10/13 08:50:04 chriskl Exp $
+ * $Id: tblproperties.php,v 1.30 2003/11/05 08:32:03 chriskl Exp $
*/
// Include application functions
echo "<br />\n";
echo "<ul>\n";
- echo "\t<li><a href=\"tables.php?action=browse&page=1&{$misc->href}&table=", urlencode($_REQUEST['table']),"\">{$lang['strbrowse']}</a></li>\n";
+ $return_url = urlencode("tblproperties.php?{$misc->href}&table={$_REQUEST['table']}");
+ echo "\t<li><a href=\"display.php?{$misc->href}&table=", urlencode($_REQUEST['table']), "&return_url={$return_url}&return_desc=",
+ urlencode($lang['strback']), "\">{$lang['strbrowse']}</a></li>\n";
echo "\t<li><a href=\"tables.php?action=confselectrows&{$misc->href}&table=", urlencode($_REQUEST['table']),"\">{$lang['strselect']}</a></li>\n";
echo "\t<li><a href=\"tables.php?action=confinsertrow&{$misc->href}&table=", urlencode($_REQUEST['table']),"\">{$lang['strinsert']}</a></li>\n";
echo "\t<li><a href=\"tables.php?action=confirm_empty&{$misc->href}&table=", urlencode($_REQUEST['table']),"\">{$lang['strempty']}</a></li>\n";
/**
* Manage views in a database
*
- * $Id: views.php,v 1.23 2003/10/15 16:00:06 soranzo Exp $
+ * $Id: views.php,v 1.24 2003/11/05 08:32:03 chriskl Exp $
*/
// Include application functions
$attrs = &$localData->getTableAttributes($_REQUEST['view']);
- echo "<form action=\"$PHP_SELF\" method=\"post\">\n";
+ echo "<form action=\"$PHP_SELF\" method=\"get\" name=\"selectform\">\n";
if ($attrs->recordCount() > 0) {
+ // JavaScript for select all feature
+ echo "<script language=\"JavaScript\">\n";
+ echo "<!--\n";
+ echo " function selectAll() {\n";
+ echo " for (var i=0; i<document.selectform.elements.length; i++) {\n";
+ echo " var e = document.selectform.elements[i];\n";
+ echo " if (e.name.indexOf('show') == 0) e.checked = document.selectform.selectall.checked;\n";
+ echo " }\n";
+ echo " }\n";
+ echo "//-->\n";
+ echo "</script>\n";
+
echo "<table>\n<tr>";
// Output table header
echo "<tr><th class=\"data\">{$lang['strshow']}</th><th class=\"data\">{$lang['strfield']}</th>";
- echo "<th class=\"data\">{$lang['strtype']}</th><th class=\"data\">{$lang['strnull']}</th>";
+ echo "<th class=\"data\">{$lang['strtype']}</th><th class=\"data\">{$lang['stroperator']}</th>";
echo "<th class=\"data\">{$lang['strvalue']}</th></tr>";
$i = 0;
// Set up default value if there isn't one already
if (!isset($_REQUEST['values'][$attrs->f['attname']]))
$_REQUEST['values'][$attrs->f['attname']] = null;
+ if (!isset($_REQUEST['ops'][$attrs->f['attname']]))
+ $_REQUEST['ops'][$attrs->f['attname']] = null;
// Continue drawing row
$id = (($i % 2) == 0 ? '1' : '2');
echo "<tr>\n";
echo "<input type=\"checkbox\" name=\"show[", htmlspecialchars($attrs->f['attname']), "]\"",
isset($_REQUEST['show'][$attrs->f['attname']]) ? ' checked="checked"' : '', " /></td>";
echo "<td class=\"data{$id}\" nowrap=\"nowrap\">", $misc->printVal($attrs->f['attname']), "</td>";
- echo "<td class=\"data{$id}\" nowrap=\"nowrap\">", $misc->printVal($attrs->f['type']), "</td>";
+ echo "<td class=\"data{$id}\" nowrap=\"nowrap\">", $misc->printVal($localData->formatType($attrs->f['type'], $attrs->f['atttypmod'])), "</td>";
echo "<td class=\"data{$id}\" nowrap=\"nowrap\">";
- // Output null box if the column allows nulls (doesn't look at CHECKs or ASSERTIONS)
- if (!$attrs->f['attnotnull'])
- echo "<input type=\"checkbox\" name=\"nulls[{$attrs->f['attname']}]\"",
- isset($_REQUEST['nulls'][$attrs->f['attname']]) ? ' checked="checked"' : '', " /></td>";
- else
- echo " </td>";
- echo "<td class=\"data{$id}\" nowrap>", $localData->printField("values[{$attrs->f['attname']}]",
+ echo "<select name=\"ops[{$attrs->f['attname']}]\">\n";
+ foreach (array_keys($localData->selectOps) as $v) {
+ echo "<option value=\"", htmlspecialchars($v), "\"", ($v == $_REQUEST['ops'][$attrs->f['attname']]) ? ' selected="selected"' : '',
+ ">", htmlspecialchars($v), "</option>\n";
+ }
+ echo "</select>\n";
+ echo "<td class=\"data{$id}\" nowrap=\"nowrap\">", $localData->printField("values[{$attrs->f['attname']}]",
$_REQUEST['values'][$attrs->f['attname']], $attrs->f['type']), "</td>";
echo "</tr>\n";
$i++;
$attrs->moveNext();
}
+ // Select all checkbox
+ echo "<tr><td colspan=\"5\"><input type=\"checkbox\" name=\"selectall\" onClick=\"javascript:selectAll()\" />{$lang['strselectallfields']}</td>";
echo "</table></p>\n";
}
else echo "<p>{$lang['strinvalidparam']}</p>\n";
echo "</form>\n";
}
else {
- if (!isset($_POST['show'])) $_POST['show'] = array();
- if (!isset($_POST['values'])) $_POST['values'] = array();
- if (!isset($_POST['nulls'])) $_POST['nulls'] = array();
+ if (!isset($_GET['show'])) $_GET['show'] = array();
+ if (!isset($_GET['values'])) $_GET['values'] = array();
+ if (!isset($_GET['nulls'])) $_GET['nulls'] = array();
- if (sizeof($_POST['show']) == 0)
- doSelectRows(true, $lang['strselectneedscol']);
+ // Verify that they haven't supplied a value for unary operators
+ foreach ($_GET['ops'] as $k => $v) {
+ if ($localData->selectOps[$v] == 'p' && $_GET['values'][$k] != '') {
+ doSelectRows(true, $lang['strselectunary']);
+ return;
+ }
+ }
+
+ if (sizeof($_GET['show']) == 0)
+ doSelectRows(true, $lang['strselectneedscol']);
else {
// Generate query SQL
- $query = $localData->getSelectSQL($_REQUEST['view'], array_keys($_POST['show']),
- $_POST['values'], array_keys($_POST['nulls']));
+ $query = $localData->getSelectSQL($_REQUEST['view'], array_keys($_GET['show']),
+ $_GET['values'], $_GET['ops']);
$_REQUEST['query'] = $query;
$_REQUEST['return_url'] = "views.php?action=confselectrows&{$misc->href}&view={$_REQUEST['view']}";
$_REQUEST['return_desc'] = $lang['strback'];