mega commit. unify all table browsing, select browsing, view browsing and report...
authorchriskl <chriskl>
Wed, 5 Nov 2003 08:32:03 +0000 (08:32 +0000)
committerchriskl <chriskl>
Wed, 5 Nov 2003 08:32:03 +0000 (08:32 +0000)
13 files changed:
BUGS
CREDITS
HISTORY
browser.php
classes/Reports.php
classes/database/BaseDB.php
classes/database/Postgres.php
classes/database/Postgres71.php
classes/database/Postgres73.php
display.php
tables.php
tblproperties.php
views.php

diff --git a/BUGS b/BUGS
index 2983c933c0d1b94558f30e0d3be5df1cb9f66d1b..de4cca5cf0e5f257ae2a5d51a0a28400aa65ccea 100644 (file)
--- a/BUGS
+++ b/BUGS
@@ -1,6 +1,9 @@
+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?
 
diff --git a/CREDITS b/CREDITS
index 36b9403bdfa1d10e9959ded28d1d8777991bc8bc..fe96d3eb25296989ecf00dec3065046ac3dd8e81 100644 (file)
--- a/CREDITS
+++ b/CREDITS
@@ -41,4 +41,4 @@ Contributors
 - Brett Toolin
 - Mark Gibson (Pop-up SQL window)
 - Nicola Soranzo
-
+- Oliver Meyer & Sven Kiera (Table icons link to browse table)
diff --git a/HISTORY b/HISTORY
index d03a1d538f0f9b7494f001c54aeec4c9b979b7d0..4a247fa2aeec0b20ba086ca223af16f588891074 100644 (file)
--- a/HISTORY
+++ b/HISTORY
@@ -6,6 +6,9 @@ Version 3.2-dev
 
 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.
index 46bc3a5ae95380843a3afa88472be97ceac4c870..6fa65e4ebab89865670c5165ba5f15612ef88ae0 100644 (file)
@@ -5,7 +5,7 @@
         * 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
@@ -56,6 +56,7 @@
                        
                        $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=" .
@@ -64,7 +65,8 @@
                                                                '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
index c75b80c3ddda177956d0fbadb7328cc214111071..43f90e95d3f871c56ad9a44f30dcd59d8b5ad846 100644 (file)
@@ -4,7 +4,7 @@
         * 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 {
@@ -42,7 +42,7 @@
 
                        $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);
                }
index b78a6034a4dfb1eb74cae22aba165f9695815f5e..23b47eff967cfcf4259c6751f16a6a5624b6b9d8 100644 (file)
@@ -4,7 +4,7 @@
  * 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');
@@ -147,16 +147,26 @@ class BaseDB extends ADODB_base {
        /**
         * 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']}\".";
@@ -196,9 +206,13 @@ class BaseDB extends ADODB_base {
 
                // 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;
        }
 
index 542367ca215b8680cdb34ceda03c23d21278dda7..fdd98df4f6787bab4b71de6314b356c9ebf217c9 100755 (executable)
@@ -4,7 +4,7 @@
  * 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???
@@ -1295,83 +1295,9 @@ class Postgres extends BaseDB {
                
                $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.
@@ -1380,7 +1306,7 @@ class Postgres extends BaseDB {
         * @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)) {
@@ -1392,8 +1318,12 @@ class Postgres extends BaseDB {
        
        /**
         * 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
@@ -1401,17 +1331,40 @@ class Postgres extends BaseDB {
         * @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;
@@ -1427,11 +1380,24 @@ class Postgres extends BaseDB {
                }
 
                // 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();
index d8e12c80de2be9c1a2dacff1e49d497d9f7af6f2..58c98eac5db8fd9ea3d508ab2a20f1f692079611 100644 (file)
@@ -4,7 +4,7 @@
  * 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???
@@ -116,7 +116,7 @@ class Postgres71 extends Postgres {
         * @return The count of rows
         * @return -1 error
         */
-       function browseSQLCount($query, $count) {
+       function browseQueryCount($query, $count) {
                return $this->selectField($count, 'total');
        }
                
index 3a52beda92bbb48662636b706fa0fb0f07562660..78a1b18a1ce1b3952b968519013a6671a4122ae9 100644 (file)
@@ -4,7 +4,7 @@
  * 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???
@@ -222,7 +222,7 @@ class Postgres73 extends Postgres72 {
                
                $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 
index 06d8e64001951290925cb3871b0450f4c82d09e7..ad1401d3b9544fdbd26da42796b08753d19a76dc 100644 (file)
@@ -9,7 +9,7 @@
         * @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 "&nbsp;</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 . "&amp;page=" . urlencode($_REQUEST['page']);
+               if (isset($_REQUEST['table'])) $str .= "&amp;table=" . urlencode($_REQUEST['table']);
+               if (isset($_REQUEST['query'])) $str .= "&amp;query=" . urlencode($_REQUEST['query']);
+               if (isset($_REQUEST['count'])) $str .= "&amp;count=" . urlencode($_REQUEST['count']);
+               if (isset($_REQUEST['return_url'])) $str .= "&amp;return_url=" . urlencode($_REQUEST['return_url']);
+               if (isset($_REQUEST['return_desc'])) $str .= "&amp;return_desc=" . urlencode($_REQUEST['return_desc']);
+               
+               // This string just contains sort info
+               $str2 = "sortkey=" . urlencode($_REQUEST['sortkey']) . 
+                       "&amp;sortdir=" . urlencode($_REQUEST['sortdir']);
+                       
+               if (is_object($rs) && $rs->recordCount() > 0) {
+                       // Show page navigation
+                       $misc->printPages($_REQUEST['page'], $max_pages, "display.php?page=%s&amp;{$str}&amp;{$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}&amp;sortkey=", ($j + 1), "&amp;sortdir=";
+                               // Sort direction opposite to current direction, unless it's currently ''
+                               echo ($_REQUEST['sortdir'] == 'asc' && $_REQUEST['sortkey'] == ($j + 1)) ? 'desc' : 'asc';
+                               echo "&amp;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 .= '&amp;';
+                                               $key_str .= urlencode("key[{$v}]") . '=' . urlencode($rs->f[$v]);
+                                       }
+                                       if ($has_nulls) {
+                                               echo "<td class=\"data{$id}\" colspan=\"2\">&nbsp;</td>\n";
+                                       } else {
+                                               echo "<td class=\"opbutton{$id}\"><a href=\"display.php?action=confeditrow&amp;strings=", 
+                                                       urlencode($_REQUEST['strings']), "&amp;{$key_str}&amp;{$str}&amp;{$str2}\">{$lang['stredit']}</a></td>\n";
+                                               echo "<td class=\"opbutton{$id}\"><a href=\"display.php?action=confdelrow&amp;strings=", 
+                                                       urlencode($_REQUEST['strings']), "&amp;{$key_str}&amp;{$str}&amp;{$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}\">&nbsp;</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}&amp;{$str2}&amp;strings=collapsed\">{$lang['strcollapse']}</a>\n";
+               else
+                       echo "| <a class=\"navlink\" href=\"display.php?{$str}&amp;{$str2}&amp;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&amp;db_name=", urlencode($_REQUEST['database']), "&amp;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&amp;formDefinition=",
+                               urlencode($_REQUEST['query']), "&amp;{$misc->href}\">{$lang['strcreateview']}</a>\n";
+                       echo " | <a class=\"navlink\" href=\"dataexport.php?query=",
+                                       urlencode($_REQUEST['query']), "&amp;{$misc->href}\">{$lang['strdownload']}</a>\n";     
+               }
+               // Refresh
+               echo "| <a class=\"navlink\" href=\"display.php?{$str}&amp;{$str2}&amp;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();
 ?>
index 43cbc82e792dc01200007f0afe3125864e7545c6..839389157c9e76a3fb5094ae1f6f85faafef6897 100644 (file)
@@ -3,7 +3,7 @@
        /**
         * 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 "&nbsp;</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\">&nbsp;</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}\">&nbsp;</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}&amp;table=",
+                                       urlencode($tables->f[$data->tbFields['tbname']]), "&amp;return_url={$return_url}&amp;return_desc=",
+                                       urlencode($lang['strback']), "\">{$lang['strbrowse']}</a></td>\n";
+                               echo "\t<td class=\"opbutton{$id}\"><a href=\"$PHP_SELF?action=confselectrows&amp;{$misc->href}&amp;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&amp;{$misc->href}&amp;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}&amp;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&amp;{$misc->href}&amp;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&amp;{$misc->href}&amp;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&amp;{$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;
index e7c0fb8dc521113e39876f0667a29faf8cbe5ece..9b1e3060416a0d119e1efa8553e16e58a6d82155 100644 (file)
@@ -3,7 +3,7 @@
        /**
         * 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";
index 7975db20bb4d005394dc48f0beeff27d20990533..6f11bb9aeeb176b15e2905c2d15457d63b614ba7 100644 (file)
--- a/views.php
+++ b/views.php
@@ -3,7 +3,7 @@
        /**
         * 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;
@@ -42,6 +54,8 @@
                                        // 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 "&nbsp;</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'];