/*
* Parent class of all ADODB objects.
*
- * $Id: ADODB_base.php,v 1.3 2002/05/01 09:37:30 chriskl Exp $
+ * $Id: ADODB_base.php,v 1.4 2002/09/16 15:09:54 chriskl Exp $
*/
include_once('../libraries/adodb/adodb-errorhandler.inc.php');
// If failure, return error value
return $this->conn->ErrorNo();
}
-
+
/**
* Retrieves a ResultSet from a query
* @param $sql The SQL statement to be executed
while(list($key, $value) = each($conditions)) {
$this->clean($key);
$this->clean($value);
- if ($sql) $sql .= " AND {$key}='{$value}'";
- else $sql = "DELETE FROM {$table} WHERE {$key}='{$value}'";
+ if ($sql) $sql .= " AND \"{$key}\"='{$value}'";
+ else $sql = "DELETE FROM \"{$table}\" WHERE \"{$key}\"='{$value}'";
}
// Check for failures
$this->clean($key);
$this->clean($value);
- if ($fields) $fields .= ", {$key}";
- else $fields = "INSERT INTO {$table} ({$key}";
+ if ($fields) $fields .= ", \"{$key}\"";
+ else $fields = "INSERT INTO \"{$table}\" (\"{$key}\"";
if ($values) $values .= ", '{$value}'";
else $values = ") VALUES ('{$value}'";
while(list($key, $value) = each($vars)) {
$this->clean($key);
$this->clean($value);
- if ($setClause) $setClause .= ", {$key}='{$value}'";
- else $setClause = "UPDATE {$table} SET {$key}='{$value}'";
+ if ($setClause) $setClause .= ", \"{$key}\"='{$value}'";
+ else $setClause = "UPDATE \"{$table}\" SET \"{$key}\"='{$value}'";
}
reset($nulls);
while(list(, $value) = each($nulls)) {
$this->clean($value);
- if ($setClause) $setClause .= ", {$value}=NULL";
- else $setClause = "UPDATE {$table} SET {$value}=NULL";
+ if ($setClause) $setClause .= ", \"{$value}\"=NULL";
+ else $setClause = "UPDATE \"{$table}\" SET \"{$value}\"=NULL";
}
reset($where);
while(list($key, $value) = each($where)) {
$this->clean($key);
$this->clean($value);
- if ($whereClause) $whereClause .= " AND {$key}='{$value}'";
- else $whereClause = " WHERE {$key}='{$value}'";
+ if ($whereClause) $whereClause .= " AND \"{$key}\"='{$value}'";
+ else $whereClause = " WHERE \"{$key}\"='{$value}'";
}
// Check for failures
* A class that implements the DB interface for Postgres\r
* Note: This class uses ADODB and returns RecordSets.\r
*\r
- * $Id: Postgres71.php,v 1.13 2002/09/15 07:29:08 chriskl Exp $\r
+ * $Id: Postgres71.php,v 1.14 2002/09/16 15:09:54 chriskl Exp $\r
*/\r
\r
// @@@ THOUGHT: What about inherits? ie. use of ONLY???\r
return $this->selectSet($sql);\r
}\r
\r
+ /**\r
+ * Returns a list of all functions in the database\r
+ * @return All functions\r
+ */\r
+\r
+ function &getFunctions() {\r
+ $sql = "SELECT\r
+ pc.oid,\r
+ proname, \r
+ pt.typname AS return_type,\r
+ oidvectortypes(pc.proargtypes) AS arguments\r
+ FROM\r
+ pg_proc pc, pg_user pu, pg_type pt\r
+ WHERE \r
+ pc.proowner = pu.usesysid\r
+ AND pc.prorettype = pt.oid\r
+ AND pc.oid > '$this->_lastSystemOID'::oid\r
+ UNION\r
+ SELECT \r
+ pc.oid,\r
+ proname, \r
+ 'OPAQUE' AS result, \r
+ oidvectortypes(pc.proargtypes) AS arguments\r
+ FROM\r
+ pg_proc pc, pg_user pu, pg_type pt\r
+ WHERE \r
+ pc.proowner = pu.usesysid\r
+ AND pc.prorettype = 0\r
+ AND pc.oid > '$this->_lastSystemOID'::oid\r
+ ORDER BY\r
+ proname, return_type\r
+ ";\r
+\r
+ return $this->selectSet($sql);\r
+ }\r
+\r
/**\r
* Return all information relating to a table\r
* @param $table The name of the table\r
// @@ How do you do this?\r
return $this->execute($sql);\r
}\r
- \r
+\r
/**\r
* Adds a check constraint to a table\r
* @param $table The table to which to add the check\r
// @@ How do you do this?\r
return $this->execute($sql);\r
} \r
- \r
+\r
/**\r
* Changes the owner of a table\r
* @param $table The table whose owner is to change\r
-<?php\r
-\r
-/**\r
- * A class that implements the DB interface for Postgres\r
- * Note: This class uses ADODB and returns RecordSets.\r
- *\r
- * $Id: Postgres72.php,v 1.6 2002/09/15 07:29:08 chriskl Exp $\r
- */\r
-\r
-\r
-require_once('../classes/database/Postgres71.php');\r
-\r
-class Postgres72 extends Postgres71 {\r
-\r
- var $fnFields = array('fnname' => 'proname', 'fnreturns' => 'return_type', 'fnarguments' => 'arguments','fnoid' => 'oid', 'fndef' => 'source', 'fnlang' => 'language' );\r
- \r
- // @@ Set the maximum built-in ID. Should we bother querying for this?\r
- var $_lastSystemOID = 16554;\r
-\r
- // This gets it from the database. \r
- // $rs = pg_exec($link, "SELECT oid FROM pg_database WHERE datname='template1'") or pg_die(pg_errormessage(), "", __FILE__, __LINE__);\r
- // $builtin_max = pg_result($rs, 0, "oid");\r
-\r
- // Table functions\r
-\r
- /**\r
- * Retrieve the attribute definition of a table\r
- * @param $table The name of the table\r
- * @return All attributes in order\r
- */\r
- function &getTableAttributes($table) {\r
- $this->clean($table);\r
- \r
- $sql = "\r
- SELECT\r
- a.attname,\r
- format_type(a.atttypid, a.atttypmod) as type,\r
- a.attnotnull, a.atthasdef, adef.adsrc\r
- FROM \r
- pg_attribute a LEFT JOIN pg_attrdef adef\r
- ON a.attrelid=adef.adrelid AND a.attnum=adef.adnum\r
- WHERE \r
- a.attrelid = (SELECT oid FROM pg_class WHERE relname='{$table}') \r
- AND a.attnum > 0\r
- ORDER BY a.attnum";\r
- \r
- return $this->selectSet($sql);\r
- } \r
-\r
- // Function functions\r
- \r
- /**\r
- * Returns a list of all functions in the database\r
- * @return All functions\r
- */\r
- \r
- function getFunctions() {\r
-\r
- $sql = "SELECT \r
- pc.oid,\r
- proname, \r
- pt.typname AS return_type, \r
- oidvectortypes(pc.proargtypes) AS arguments\r
- FROM \r
- pg_proc pc, pg_user pu, pg_type pt\r
- WHERE \r
- pc.proowner = pu.usesysid\r
- AND pc.prorettype = pt.oid\r
- AND pc.oid > '$this->_lastSystemOID'::oid\r
- UNION\r
- SELECT \r
- pc.oid,\r
- proname, \r
- 'OPAQUE' AS result, \r
- oidvectortypes(pc.proargtypes) AS arguments\r
- FROM \r
- pg_proc pc, pg_user pu, pg_type pt\r
- WHERE \r
- pc.proowner = pu.usesysid\r
- AND pc.prorettype = 0\r
- AND pc.oid > '$this->_lastSystemOID'::oid\r
- ORDER BY\r
- proname, return_type\r
- ";\r
-\r
- return $this->selectSet($sql);\r
- }\r
-\r
- /**\r
- * Returns all details for a particular function\r
- * @param $func The name of the function to retrieve\r
- * @return Function info\r
- */\r
- function getFunction($function_oid) {\r
- $this->clean($function_oid);\r
- \r
- $sql = "SELECT \r
- pc.oid,\r
- proname, \r
- lanname as language,\r
- format_type(prorettype, NULL) as return_type,\r
- prosrc as source,\r
- probin as binary,\r
- oidvectortypes(pc.proargtypes) AS arguments\r
- FROM \r
- pg_proc pc, pg_language pl\r
- WHERE \r
- pc.oid = '$function_oid'::oid\r
- AND pc.prolang = pl.oid\r
- ";\r
- \r
- return $this->selectSet($sql);\r
- } \r
-\r
- /**\r
- * Creates a new function.\r
- * @param $funcname The name of the function to create\r
- * @param $definition The definition for the new function\r
- * @return 0 success\r
- */\r
- function createFunction($funcname, $definition) {\r
- $this->clean($funcname);\r
- // Note: $definition not cleaned\r
- \r
- $sql = "CREATE VIEW \"{$viewname}\" AS {$definition}";\r
- \r
- return $this->execute($sql);\r
- }\r
- \r
- /**\r
- * Drops a function.\r
- * @param $funcname The name of the view to drop\r
- * @return 0 success\r
- */\r
- function dropFunction($funcname) {\r
- $this->clean($funcname);\r
- \r
- $sql = "DROP FUNCTION {$funcname} ";\r
- \r
- return $this->execute($sql);\r
- }\r
- \r
- /**\r
- * Updates a function. Postgres doesn't have CREATE OR REPLACE function,\r
- * so we do it with a drop and a recreate.\r
- * @param $funcname The name of the function to update\r
- * @param $definition The new definition for the function\r
- * @return 0 success\r
- * @return -1 transaction error\r
- * @return -2 drop function error\r
- * @return -3 create function error\r
- */\r
- function setFunction($funcname, $definition) {\r
- $status = $this->beginTransaction();\r
- if ($status != 0) return -1;\r
- \r
- $status = $this->dropFunction($funcname);\r
- if ($status != 0) {\r
- $this->rollbackTransaction();\r
- return -2;\r
- }\r
- \r
- $status = $this->createFunction($funcname, $definition);\r
- if ($status != 0) {\r
- $this->rollbackTransaction();\r
- return -3;\r
- }\r
- \r
- $status = $this->endTransaction();\r
- return ($status == 0) ? 0 : -1;\r
- }\r
-\r
-}\r
-\r
-?>\r
+<?php
+
+/**
+ * A class that implements the DB interface for Postgres
+ * Note: This class uses ADODB and returns RecordSets.
+ *
+ * $Id: Postgres72.php,v 1.7 2002/09/16 15:09:54 chriskl Exp $
+ */
+
+
+require_once('../classes/database/Postgres71.php');
+
+class Postgres72 extends Postgres71 {
+
+ var $fnFields = array('fnname' => 'proname', 'fnreturns' => 'return_type', 'fnarguments' => 'arguments','fnoid' => 'oid', 'fndef' => 'source', 'fnlang' => 'language' );
+ var $typFields = array('typname' => 'typname');
+
+ // @@ Set the maximum built-in ID. Should we bother querying for this?
+ var $_lastSystemOID = 16554;
+
+ // This gets it from the database.
+ // $rs = pg_exec($link, "SELECT oid FROM pg_database WHERE datname='template1'") or pg_die(pg_errormessage(), "", __FILE__, __LINE__);
+ // $builtin_max = pg_result($rs, 0, "oid");
+
+ // Table functions
+
+ /**
+ * Retrieve the attribute definition of a table
+ * @param $table The name of the table
+ * @return All attributes in order
+ */
+ function &getTableAttributes($table) {
+ $this->clean($table);
+
+ $sql = "
+ SELECT
+ a.attname,
+ format_type(a.atttypid, a.atttypmod) as type,
+ a.attnotnull, a.atthasdef, adef.adsrc
+ FROM
+ pg_attribute a LEFT JOIN pg_attrdef adef
+ ON a.attrelid=adef.adrelid AND a.attnum=adef.adnum
+ WHERE
+ a.attrelid = (SELECT oid FROM pg_class WHERE relname='{$table}')
+ AND a.attnum > 0
+ ORDER BY a.attnum";
+
+ return $this->selectSet($sql);
+ }
+
+ // Function functions
+
+ /**
+ * Returns a list of all functions in the database
+ * @return All functions
+ */
+ function &getFunctions() {
+ $sql = "SELECT
+ p.oid,
+ p.proname,
+ format_type(p.prorettype, NULL) AS return_type,
+ oidvectortypes(p.proargtypes) AS arguments
+ FROM
+ pg_proc p
+ WHERE
+ p.prorettype <> 0
+ AND (pronargs = 0 OR oidvectortypes(p.proargtypes) <> '')
+ AND p.oid > '{$this->_lastSystemOID}'
+ ORDER BY
+ p.proname, return_type
+ ";
+
+ return $this->selectSet($sql);
+ }
+
+ /**
+ * Returns all details for a particular function
+ * @param $func The name of the function to retrieve
+ * @return Function info
+ */
+ function getFunction($function_oid) {
+ $this->clean($function_oid);
+
+ $sql = "SELECT
+ pc.oid,
+ proname,
+ lanname as language,
+ format_type(prorettype, NULL) as return_type,
+ prosrc as source,
+ probin as binary,
+ oidvectortypes(pc.proargtypes) AS arguments
+ FROM
+ pg_proc pc, pg_language pl
+ WHERE
+ pc.oid = '$function_oid'::oid
+ AND pc.prolang = pl.oid
+ ";
+
+ return $this->selectSet($sql);
+ }
+
+ /**
+ * Creates a new function.
+ * @param $funcname The name of the function to create
+ * @param $definition The definition for the new function
+ * @return 0 success
+ */
+ function createFunction($funcname, $definition) {
+ $this->clean($funcname);
+ // Note: $definition not cleaned
+
+ $sql = "CREATE VIEW \"{$viewname}\" AS {$definition}";
+
+ return $this->execute($sql);
+ }
+
+ /**
+ * Drops a function.
+ * @param $funcname The name of the view to drop
+ * @return 0 success
+ */
+ function dropFunction($funcname) {
+ $this->clean($funcname);
+
+ $sql = "DROP FUNCTION {$funcname} ";
+
+ return $this->execute($sql);
+ }
+
+ /**
+ * Updates a function. Postgres doesn't have CREATE OR REPLACE function,
+ * so we do it with a drop and a recreate.
+ * @param $funcname The name of the function to update
+ * @param $definition The new definition for the function
+ * @return 0 success
+ * @return -1 transaction error
+ * @return -2 drop function error
+ * @return -3 create function error
+ */
+ function setFunction($funcname, $definition) {
+ $status = $this->beginTransaction();
+ if ($status != 0) return -1;
+
+ $status = $this->dropFunction($funcname);
+ if ($status != 0) {
+ $this->rollbackTransaction();
+ return -2;
+ }
+
+ $status = $this->createFunction($funcname, $definition);
+ if ($status != 0) {
+ $this->rollbackTransaction();
+ return -3;
+ }
+
+ $status = $this->endTransaction();
+ return ($status == 0) ? 0 : -1;
+ }
+
+ // Type functions
+
+ /**
+ * Returns a list of all types in the database
+ * @return A recordet
+ */
+ function &getTypes() {
+ $sql = "SELECT
+ format_type(t.oid, NULL) AS typname
+ FROM
+ pg_type t
+ WHERE
+ t.typrelid = 0 AND t.typname !~ '^_.*'
+ ORDER BY typname
+ ";
+
+ return $this->selectSet($sql);
+ }
+
+}
+
+?>
-<?php\r
-\r
- /**\r
- * Manage functions in a database\r
- *\r
- * $Id: functions.php,v 1.3 2002/09/10 18:46:25 xzilla Exp $\r
- */\r
-\r
- // Include application functions\r
- include_once('../conf/config.inc.php');\r
- \r
- $action = (isset($_REQUEST['action'])) ? $_REQUEST['action'] : '';\r
- if (!isset($msg)) $msg = '';\r
- $PHP_SELF = $_SERVER['PHP_SELF'];\r
- \r
- /** \r
- * Function to save after editing a function\r
- */\r
- function doSaveEdit() {\r
- global $localData;\r
- \r
- $status = $localData->setView($_POST['view'], $_POST['formDefinition']);\r
- if ($status == 0)\r
- doProperties('Function updated.');\r
- else\r
- doEdit('Function update failed.');\r
- }\r
- \r
- /**\r
- * Function to allow editing of a Function\r
- */\r
- function doEdit($msg = '') {\r
- global $data, $localData, $misc;\r
- global $PHP_SELF, $strName, $strDefinition;\r
- \r
- echo "<h2>", htmlspecialchars($_REQUEST['database']), ": Views: ", htmlspecialchars($_REQUEST['view']), ": Edit</h2>\n";\r
- $misc->printMsg($msg);\r
- \r
- $viewdata = &$localData->getView($_REQUEST['view']);\r
- \r
- if ($viewdata->recordCount() > 0) {\r
- echo "<form action=\"$PHP_SELF\" method=post>\n";\r
- echo "<table width=100%>\n";\r
- echo "<tr><th class=data>{$strName}</th></tr>\n";\r
- echo "<tr><td class=data1>", htmlspecialchars($viewdata->f[$data->vwFields['vwname']]), "</td></tr>\n";\r
- echo "<tr><th class=data>{$strDefinition}</th></tr>\n";\r
- echo "<tr><td class=data1><textarea style=\"width:100%;\" rows=20 cols=50 name=formDefinition wrap=virtual>", \r
- htmlspecialchars($viewdata->f[$data->vwFields['vwdef']]), "</textarea></td></tr>\n";\r
- echo "</table>\n";\r
- echo "<input type=hidden name=action value=save_edit>\n";\r
- echo "<input type=hidden name=view value=\"", htmlspecialchars($_REQUEST['view']), "\">\n";\r
- echo "<input type=hidden name=database value=\"", htmlspecialchars($_REQUEST['database']), "\">\n";\r
- echo "<input type=submit value=Save> <input type=reset>\n";\r
- echo "</form>\n";\r
- }\r
- else echo "<p>No data.</p>\n";\r
- \r
- echo "<p><a class=navlink href=\"$PHP_SELF?database=", urlencode($_REQUEST['database']), "\">Show All Views</a> |\n";\r
- echo "<a class=navlink href=\"$PHP_SELF?action=properties&database=", urlencode($_REQUEST['database']), "&view=", \r
- urlencode($_REQUEST['view']), "\">Properties</a></p>\n";\r
- }\r
- \r
- /**\r
- * Show read only properties for a function\r
- pc.oid,\r
- proname, \r
- lanname as language,\r
- format_type(prorettype, NULL) as return_type,\r
- prosrc as source,\r
- probin as binary,\r
- oidvectortypes(pc.proargtypes) AS arguments\r
-\r
-\r
-\r
- */\r
- function doProperties($msg = '') {\r
- global $data, $localData, $misc;\r
- global $PHP_SELF, $strFunctions, $strArguments, $strReturns, $strActions, $strNoFunctions, $strDefinition, $strLanguage;\r
- \r
- echo "<h2>", htmlspecialchars($_REQUEST['database']), ": Functions: ", htmlspecialchars($_REQUEST['function']), ": Properties</h2>\n";\r
- $misc->printMsg($msg);\r
- \r
- $funcdata = &$localData->getFunction($_REQUEST['function_oid']);\r
- \r
- if ($funcdata->recordCount() > 0) {\r
- echo "<table width=90%>\n";\r
- echo "<tr><th class=data>{$strFunctions}</th>\n";\r
- echo "<th class=data>{$strArguments}</th>\n";\r
- echo "<th class=data>{$strReturns}</th>\n";\r
- echo "<th class=data>{$strLanguage}</th></tr>\n";\r
- echo "<tr><td class=data1>", htmlspecialchars($funcdata->f[$data->fnFields['fnname']]), "</td>\n";\r
- echo "<td class=data1>", htmlspecialchars($funcdata->f[$data->fnFields['fnarguments']]), "</td>\n";\r
- echo "<td class=data1>", htmlspecialchars($funcdata->f[$data->fnFields['fnreturns']]), "</td>\n";\r
- echo "<td class=data1>", htmlspecialchars($funcdata->f[$data->fnFields['fnlang']]), "</td></tr>\n";\r
- echo "<tr><th class=data colspan=4>{$strDefinition}</th></tr>\n";\r
- echo "<tr><td class=data1 colspan=4>", nl2br(htmlspecialchars($funcdata->f[$data->fnFields['fndef']])), "</td></tr>\n";\r
- echo "</table>\n";\r
- }\r
- else echo "<p>No data.</p>\n";\r
- \r
- echo "<p><a class=navlink href=\"$PHP_SELF?database=", urlencode($_REQUEST['database']), "\">Show All Functions</a> |\n";\r
- echo "<a class=navlink href=\"$PHP_SELF?action=edit&database=", urlencode($_REQUEST['database']), "&function=", \r
- urlencode($_REQUEST['function']), "\">Edit</a></p>\n";\r
- }\r
- \r
- /**\r
- * Show confirmation of drop and perform actual drop\r
- */\r
- function doDrop($confirm) {\r
- global $localData, $database;\r
- global $PHP_SELF;\r
-\r
- if ($confirm) { \r
- echo "<h2>", htmlspecialchars($_REQUEST['database']), ": Functions: ", htmlspecialchars($_REQUEST['function']), ": Drop</h2>\n";\r
- \r
- echo "<p>Are you sure you want to drop the function \"", htmlspecialchars($_REQUEST['function']), "\"?</p>\n";\r
- \r
- echo "<form action=\"$PHP_SELF\" method=\"post\">\n";\r
- echo "<input type=hidden name=action value=drop>\n";\r
- echo "<input type=hidden name=function value=\"", htmlspecialchars($_REQUEST['function']), "\">\n";\r
- echo "<input type=hidden name=database value=\"", htmlspecialchars($_REQUEST['database']), "\">\n";\r
- echo "<input type=submit name=choice value=\"Yes\"> <input type=submit name=choice value=\"No\">\n";\r
- echo "</form>\n";\r
- }\r
- else {\r
- $status = $localData->dropFunction($_POST['function']);\r
- if ($status == 0)\r
- doDefault('Function dropped.');\r
- else\r
- doDefault('Function drop failed.');\r
- }\r
- \r
- }\r
- \r
- /**\r
- * Displays a screen where they can enter a new view\r
- */\r
- function doCreate($msg = '') {\r
- global $data, $localData, $misc;\r
- global $PHP_SELF, $strName, $strDefinition;\r
- \r
- if (!isset($_POST['formFunc'])) $_POST['formFunc'] = '';\r
- if (!isset($_POST['formDefinition'])) $_POST['formDefinition'] = '';\r
- \r
- echo "<h2>", htmlspecialchars($_REQUEST['database']), ": Views: Create View</h2>\n";\r
- $misc->printMsg($msg);\r
- \r
- echo "<form action=\"$PHP_SELF\" method=post>\n";\r
- echo "<table width=100%>\n";\r
- echo "<tr><th class=data>{$strName}</th></tr>\n";\r
- echo "<tr><td class=data1><input name=formView size={$data->_maxNameLen} maxlength={$data->_maxNameLen} value=\"", \r
- htmlspecialchars($_POST['formView']), "\"></td></tr>\n";\r
- echo "<tr><th class=data>{$strDefinition}</th></tr>\n";\r
- echo "<tr><td class=data1><textarea style=\"width:100%;\" rows=20 cols=50 name=formDefinition wrap=virtual>", \r
- htmlspecialchars($_POST['formDefinition']), "</textarea></td></tr>\n";\r
- echo "</table>\n";\r
- echo "<input type=hidden name=action value=save_create>\n";\r
- echo "<input type=hidden name=database value=\"", htmlspecialchars($_REQUEST['database']), "\">\n";\r
- echo "<input type=submit value=Save> <input type=reset>\n";\r
- echo "</form>\n";\r
- \r
- echo "<p><a class=navlink href=\"$PHP_SELF?database=", urlencode($_REQUEST['database']), "\">Show All Views</a></p>\n";\r
- }\r
- \r
- /**\r
- * Actually creates the new view in the database\r
- */\r
- function doSaveCreate() {\r
- global $localData, $strViewNeedsName, $strViewNeedsDef;\r
- \r
- // Check that they've given a name and a definition\r
- if ($_POST['formView'] == '') doCreate($strViewNeedsName);\r
- elseif ($_POST['formDefinition'] == '') doCreate($strViewNeedsDef);\r
- else { \r
- $status = $localData->createView($_POST['formView'], $_POST['formDefinition']);\r
- if ($status == 0)\r
- doDefault('View created.');\r
- else\r
- doCreate('View creation failed.');\r
- }\r
- } \r
-\r
- /**\r
- * Show default list of views in the database\r
- */\r
- function doDefault($msg = '') {\r
- global $data, $localData, $misc, $database, $func;\r
- global $PHP_SELF, $strFunctions, $strArguments, $strReturns, $strActions, $strNoFunctions;\r
- \r
- echo "<h2>", htmlspecialchars($_REQUEST['database']), ": Functions</h2>\n";\r
- $misc->printMsg($msg);\r
- \r
- $funcs = &$localData->getFunctions();\r
- \r
- if ($funcs->recordCount() > 0) {\r
- echo "<table>\n";\r
- echo "<tr><th class=data>{$strFunctions}</th><th class=data>{$strReturns}</th><th class=data>{$strArguments}</th><th colspan=3 class=data>{$strActions}</th>\n";\r
- $i = 0;\r
- while (!$funcs->EOF) {\r
-\r
- $func_full = $funcs->f[$data->fnFields['fnname']] . "(". $funcs->f[$data->fnFields['fnarguments']] .")";\r
-\r
- $id = (($i % 2) == 0 ? '1' : '2');\r
- echo "<tr><td class=data{$id}>", htmlspecialchars($funcs->f[$data->fnFields['fnname']]), "</td>\n";\r
- echo "<td class=data{$id}>", htmlspecialchars($funcs->f[$data->fnFields['fnreturns']]), "</td>\n";\r
- echo "<td class=data{$id}>", htmlspecialchars($funcs->f[$data->fnFields['fnarguments']]), "</td>\n";\r
- echo "<td class=opbutton{$id}><a href=\"$PHP_SELF?action=properties&database=", \r
- htmlspecialchars($_REQUEST['database']), "&function=", urlencode($func_full), "&function_oid=", $funcs->f[$data->fnFields['fnoid']], "\">Properties</a></td>\n";\r
- echo "<td class=opbutton{$id}>Edit</td>\n";\r
- echo "<td class=opbutton{$id}><a href=\"$PHP_SELF?action=confirm_drop&database=", \r
- htmlspecialchars($_REQUEST['database']), "&function=", urlencode($func_full), "&function_oid=", $funcs->f[$data->fnFields['fnoid']], "\">Drop</a></td>\n";\r
- echo "</tr>\n";\r
- $funcs->moveNext();\r
- $i++;\r
- }\r
-\r
- echo "</table>\n";\r
- }\r
- else {\r
- echo "<p>{$strNoFunctions}</p>\n";\r
- }\r
- \r
- echo "<p><a class=navlink href=\"$PHP_SELF?action=create&database=", urlencode($_REQUEST['database']), "\">Create Function</a></p>\n";\r
-\r
- }\r
-\r
- echo "<html>\n";\r
- echo "<body>\n";\r
- \r
- switch ($action) {\r
- case 'save_create':\r
- doSaveCreate();\r
- break;\r
- case 'create':\r
- doCreate();\r
- break;\r
- case 'drop':\r
- if ($_POST['choice'] == 'Yes') doDrop(false);\r
- else doDefault();\r
- break;\r
- case 'confirm_drop':\r
- doDrop(true);\r
- break; \r
- case 'save_edit':\r
- doSaveEdit();\r
- break;\r
- case 'edit':\r
- doEdit();\r
- break;\r
- case 'properties':\r
- doProperties();\r
- break;\r
- case 'browse':\r
- // @@ Not yet implemented\r
- default:\r
- doDefault();\r
- break;\r
- } \r
-\r
- echo "</body>\n";\r
- echo "</html>\n";\r
- \r
-?>\r
+<?php
+
+ /**
+ * Manage functions in a database
+ *
+ * $Id: functions.php,v 1.4 2002/09/16 15:09:54 chriskl Exp $
+ */
+
+ // Include application functions
+ include_once('../conf/config.inc.php');
+
+ $action = (isset($_REQUEST['action'])) ? $_REQUEST['action'] : '';
+ if (!isset($msg)) $msg = '';
+ $PHP_SELF = $_SERVER['PHP_SELF'];
+
+ /**
+ * Function to save after editing a function
+ */
+ function doSaveEdit() {
+ global $localData;
+
+ $status = $localData->setFunction($_POST['view'], $_POST['formDefinition']);
+ if ($status == 0)
+ doProperties('Function updated.');
+ else
+ doEdit('Function update failed.');
+ }
+
+ /**
+ * Function to allow editing of a Function
+ */
+ function doEdit($msg = '') {
+ global $data, $localData, $misc;
+ global $PHP_SELF, $strName, $strDefinition;
+
+ echo "<h2>", htmlspecialchars($_REQUEST['database']), ": Functions: ", htmlspecialchars($_REQUEST['function']), ": Edit</h2>\n";
+ $misc->printMsg($msg);
+
+ $fndata = &$localData->getFunction($_REQUEST['function']);
+
+ if ($fndata->recordCount() > 0) {
+ echo "<form action=\"$PHP_SELF\" method=post>\n";
+ echo "<table width=100%>\n";
+ echo "<tr><th class=data>{$strName}</th></tr>\n";
+ echo "<tr><td class=data1>", htmlspecialchars($fndata->f[$data->vwFields['vwname']]), "</td></tr>\n";
+ echo "<tr><th class=data>{$strDefinition}</th></tr>\n";
+ echo "<tr><td class=data1><textarea style=\"width:100%;\" rows=20 cols=50 name=formDefinition wrap=virtual>",
+ htmlspecialchars($fndata->f[$data->vwFields['vwdef']]), "</textarea></td></tr>\n";
+ echo "</table>\n";
+ echo "<input type=hidden name=action value=save_edit>\n";
+ echo "<input type=hidden name=function value=\"", htmlspecialchars($_REQUEST['function']), "\">\n";
+ echo "<input type=hidden name=database value=\"", htmlspecialchars($_REQUEST['database']), "\">\n";
+ echo "<input type=submit value=Save> <input type=reset>\n";
+ echo "</form>\n";
+ }
+ else echo "<p>No data.</p>\n";
+
+ echo "<p><a class=navlink href=\"$PHP_SELF?database=", urlencode($_REQUEST['database']), "\">Show All Functions</a> |\n";
+ echo "<a class=navlink href=\"$PHP_SELF?action=properties&database=", urlencode($_REQUEST['database']), "&function=",
+ urlencode($_REQUEST['function']), "\">Properties</a></p>\n";
+ }
+
+ /**
+ * Show read only properties for a function
+ pc.oid,
+ proname,
+ lanname as language,
+ format_type(prorettype, NULL) as return_type,
+ prosrc as source,
+ probin as binary,
+ oidvectortypes(pc.proargtypes) AS arguments
+
+
+
+ */
+ function doProperties($msg = '') {
+ global $data, $localData, $misc;
+ global $PHP_SELF, $strFunctions, $strArguments, $strReturns, $strActions, $strNoFunctions, $strDefinition, $strLanguage;
+
+ echo "<h2>", htmlspecialchars($_REQUEST['database']), ": Functions: ", htmlspecialchars($_REQUEST['function']), ": Properties</h2>\n";
+ $misc->printMsg($msg);
+
+ $funcdata = &$localData->getFunction($_REQUEST['function_oid']);
+
+ if ($funcdata->recordCount() > 0) {
+ echo "<table width=90%>\n";
+ echo "<tr><th class=data>{$strFunctions}</th>\n";
+ echo "<th class=data>{$strArguments}</th>\n";
+ echo "<th class=data>{$strReturns}</th>\n";
+ echo "<th class=data>{$strLanguage}</th></tr>\n";
+ echo "<tr><td class=data1>", htmlspecialchars($funcdata->f[$data->fnFields['fnname']]), "</td>\n";
+ echo "<td class=data1>", htmlspecialchars($funcdata->f[$data->fnFields['fnarguments']]), "</td>\n";
+ echo "<td class=data1>", htmlspecialchars($funcdata->f[$data->fnFields['fnreturns']]), "</td>\n";
+ echo "<td class=data1>", htmlspecialchars($funcdata->f[$data->fnFields['fnlang']]), "</td></tr>\n";
+ echo "<tr><th class=data colspan=4>{$strDefinition}</th></tr>\n";
+ echo "<tr><td class=data1 colspan=4>", nl2br(htmlspecialchars($funcdata->f[$data->fnFields['fndef']])), "</td></tr>\n";
+ echo "</table>\n";
+ }
+ else echo "<p>No data.</p>\n";
+
+ echo "<p><a class=navlink href=\"$PHP_SELF?database=", urlencode($_REQUEST['database']), "\">Show All Functions</a> |\n";
+ echo "<a class=navlink href=\"$PHP_SELF?action=edit&database=", urlencode($_REQUEST['database']), "&function=",
+ urlencode($_REQUEST['function']), "\">Edit</a></p>\n";
+ }
+
+ /**
+ * Show confirmation of drop and perform actual drop
+ */
+ function doDrop($confirm) {
+ global $localData, $database;
+ global $PHP_SELF;
+
+ if ($confirm) {
+ echo "<h2>", htmlspecialchars($_REQUEST['database']), ": Functions: ", htmlspecialchars($_REQUEST['function']), ": Drop</h2>\n";
+
+ echo "<p>Are you sure you want to drop the function \"", htmlspecialchars($_REQUEST['function']), "\"?</p>\n";
+
+ echo "<form action=\"$PHP_SELF\" method=\"post\">\n";
+ echo "<input type=hidden name=action value=drop>\n";
+ echo "<input type=hidden name=function value=\"", htmlspecialchars($_REQUEST['function']), "\">\n";
+ echo "<input type=hidden name=database value=\"", htmlspecialchars($_REQUEST['database']), "\">\n";
+ echo "<input type=submit name=choice value=\"Yes\"> <input type=submit name=choice value=\"No\">\n";
+ echo "</form>\n";
+ }
+ else {
+ $status = $localData->dropFunction($_POST['function']);
+ if ($status == 0)
+ doDefault('Function dropped.');
+ else
+ doDefault('Function drop failed.');
+ }
+
+ }
+
+ /**
+ * Displays a screen where they can enter a new function
+ */
+ function doCreate($msg = '') {
+ global $data, $localData, $misc;
+ global $PHP_SELF, $strName, $strArguments, $strReturns, $strDefinition;
+
+ if (!isset($_POST['formFunction'])) $_POST['formFunction'] = '';
+ if (!isset($_POST['formArguments'])) $_POST['formArguments'] = '';
+ if (!isset($_POST['formReturns'])) $_POST['formReturns'] = '';
+ if (!isset($_POST['formDefinition'])) $_POST['formDefinition'] = '';
+
+ $types = &$localData->getTypes();
+
+ echo "<h2>", htmlspecialchars($_REQUEST['database']), ": Functions: Create Function</h2>\n";
+ $misc->printMsg($msg);
+
+ echo "<form action=\"$PHP_SELF\" method=post>\n";
+ echo "<table width=100%>\n";
+ echo "<tr><th class=data>{$strName}</th></tr>\n";
+ echo "<tr><td class=data1><input name=formFunction size={$data->_maxNameLen} maxlength={$data->_maxNameLen} value=\"",
+ htmlspecialchars($_POST['formFunction']), "\"></td></tr>\n";
+ echo "<tr><th class=data>{$strArguments}</th></tr>\n";
+ echo "<tr><td class=data1><input name=formArguments style=\"width:100%;\" size={$data->_maxNameLen} maxlength={$data->_maxNameLen} value=\"",
+ htmlspecialchars($_POST['formArguments']), "\"></td></tr>\n";
+ echo "<tr><th class=data>{$strReturns}</th></tr>\n";
+ echo "<tr><td class=data1><select name=formReturns>\n";
+ while (!$types->EOF) {
+ echo "<option value=\"", htmlspecialchars($types->f[$data->typFields['typname']]), "\">",
+ htmlspecialchars($types->f[$data->typFields['typname']]), "</option>\n";
+ $types->moveNext();
+ }
+ echo "</td></tr>\n";
+ echo "<tr><th class=data>{$strDefinition}</th></tr>\n";
+ echo "<tr><td class=data1><textarea style=\"width:100%;\" rows=20 cols=50 name=formDefinition wrap=virtual>",
+ htmlspecialchars($_POST['formDefinition']), "</textarea></td></tr>\n";
+ echo "</table>\n";
+ echo "<input type=hidden name=action value=save_create>\n";
+ echo "<input type=hidden name=database value=\"", htmlspecialchars($_REQUEST['database']), "\">\n";
+ echo "<input type=submit value=Save> <input type=reset>\n";
+ echo "</form>\n";
+
+ echo "<p><a class=navlink href=\"$PHP_SELF?database=", urlencode($_REQUEST['database']), "\">Show All Functions</a></p>\n";
+ }
+
+ /**
+ * Actually creates the new function in the database
+ */
+ function doSaveCreate() {
+ global $localData, $strFunctionNeedsName, $strFunctionNeedsDef;
+
+ // Check that they've given a name and a definition
+ if ($_POST['formFunction'] == '') doCreate($strFunctionNeedsName);
+ elseif ($_POST['formDefinition'] == '') doCreate($strFunctionNeedsDef);
+ else {
+ $status = $localData->createFunction($_POST['formFunction'], $_POST['formDefinition']);
+ if ($status == 0)
+ doDefault('Function created.');
+ else
+ doCreate('Function creation failed.');
+ }
+ }
+
+ /**
+ * Show default list of functions in the database
+ */
+ function doDefault($msg = '') {
+ global $data, $localData, $misc, $database, $func;
+ global $PHP_SELF, $strFunctions, $strArguments, $strReturns, $strActions, $strNoFunctions;
+
+ echo "<h2>", htmlspecialchars($_REQUEST['database']), ": Functions</h2>\n";
+ $misc->printMsg($msg);
+
+ $funcs = &$localData->getFunctions();
+
+ if ($funcs->recordCount() > 0) {
+ echo "<table>\n";
+ echo "<tr><th class=data>{$strFunctions}</th><th class=data>{$strReturns}</th><th class=data>{$strArguments}</th><th colspan=3 class=data>{$strActions}</th>\n";
+ $i = 0;
+ while (!$funcs->EOF) {
+ $func_full = $funcs->f[$data->fnFields['fnname']] . "(". $funcs->f[$data->fnFields['fnarguments']] .")";
+ $id = (($i % 2) == 0 ? '1' : '2');
+ echo "<tr><td class=data{$id}>", htmlspecialchars($funcs->f[$data->fnFields['fnname']]), "</td>\n";
+ echo "<td class=data{$id}>", htmlspecialchars($funcs->f[$data->fnFields['fnreturns']]), "</td>\n";
+ echo "<td class=data{$id}>", htmlspecialchars($funcs->f[$data->fnFields['fnarguments']]), "</td>\n";
+ echo "<td class=opbutton{$id}><a href=\"$PHP_SELF?action=properties&database=",
+ htmlspecialchars($_REQUEST['database']), "&function=", urlencode($func_full), "&function_oid=", $funcs->f[$data->fnFields['fnoid']], "\">Properties</a></td>\n";
+ echo "<td class=opbutton{$id}>Edit</td>\n";
+ echo "<td class=opbutton{$id}><a href=\"$PHP_SELF?action=confirm_drop&database=",
+ htmlspecialchars($_REQUEST['database']), "&function=", urlencode($func_full), "&function_oid=", $funcs->f[$data->fnFields['fnoid']], "\">Drop</a></td>\n";
+ echo "</tr>\n";
+ $funcs->moveNext();
+ $i++;
+ }
+
+ echo "</table>\n";
+ }
+ else {
+ echo "<p>{$strNoFunctions}</p>\n";
+ }
+
+ echo "<p><a class=navlink href=\"$PHP_SELF?action=create&database=", urlencode($_REQUEST['database']), "\">Create Function</a></p>\n";
+
+ }
+
+ echo "<html>\n";
+ echo "<body>\n";
+
+ switch ($action) {
+ case 'save_create':
+ doSaveCreate();
+ break;
+ case 'create':
+ doCreate();
+ break;
+ case 'drop':
+ if ($_POST['choice'] == 'Yes') doDrop(false);
+ else doDefault();
+ break;
+ case 'confirm_drop':
+ doDrop(true);
+ break;
+ case 'save_edit':
+ doSaveEdit();
+ break;
+ case 'edit':
+ doEdit();
+ break;
+ case 'properties':
+ doProperties();
+ break;
+ case 'browse':
+ // @@ Not yet implemented
+ default:
+ doDefault();
+ break;
+ }
+
+ echo "</body>\n";
+ echo "</html>\n";
+
+?>
-<?php\r
-\r
- /**\r
- * List tables in a database\r
- *\r
- * $Id: tables.php,v 1.8 2002/09/16 10:12:01 chriskl Exp $\r
- */\r
-\r
- // Include application functions\r
- include_once('../conf/config.inc.php');\r
-\r
- $action = (isset($_REQUEST['action'])) ? $_REQUEST['action'] : '';\r
- $PHP_SELF = $_SERVER['PHP_SELF'];\r
-\r
- /**\r
- * Ask for insert parameters and then actually insert row\r
- */\r
- function doInsertRow($confirm, $msg = '') {\r
- global $localData, $database, $misc;\r
- global $strField, $strType, $strNull, $strValue;\r
- global $PHP_SELF;\r
-\r
- if ($confirm) { \r
- echo "<h2>", htmlspecialchars($_REQUEST['database']), ": Tables: ", htmlspecialchars($_REQUEST['table']), ": Insert Row</h2>\n";\r
- $misc->printMsg($msg);\r
-\r
- $attrs = &$localData->getTableAttributes($_REQUEST['table']);\r
-\r
- echo "<form action=\"$PHP_SELF\" method=\"post\">\n";\r
- if ($attrs->recordCount() > 0) {\r
- echo "<table>\n<tr>";\r
- \r
- // Output table header\r
- echo "<tr><th class=data>{$strField}</th><th class=data>{$strType}</th><th class=data>{$strNull}</th><th class=data>{$strValue}</th></tr>";\r
- \r
- $i = 0;\r
- while (!$attrs->EOF) {\r
- $attrs->f['attnotnull'] = $localData->phpBool($attrs->f['attnotnull']);\r
- // Set up default value if there isn't one already\r
- if (!isset($_REQUEST['values'][$attrs->f['attname']]))\r
- $_REQUEST['values'][$attrs->f['attname']] = null;\r
- // Continue drawing row\r
- $id = (($i % 2) == 0 ? '1' : '2');\r
- echo "<tr>\n";\r
- echo "<td class=data{$id} nowrap>", htmlspecialchars($attrs->f['attname']), "</td>";\r
- echo "<td class=data{$id} nowrap>", htmlspecialchars($attrs->f['type']), "</td>";\r
- echo "<td class=data{$id} nowrap>";\r
- // Output null box if the column allows nulls (doesn't look at CHECKs or ASSERTIONS)\r
- if (!$attrs->f['attnotnull'])\r
- echo "<input type=checkbox name=\"nulls[{$attrs->f['attname']}]\"", \r
- isset($_REQUEST['nulls'][$attrs->f['attname']]) ? ' checked' : '', "></td>";\r
- else\r
- echo " </td>";\r
- echo "<td class=data{$id} nowrap>", $localData->printField("values[{$attrs->f['attname']}]", \r
- $_REQUEST['values'][$attrs->f['attname']], $attrs->f['type']), "</td>";\r
- echo "</tr>\n";\r
- $i++;\r
- $attrs->moveNext();\r
- }\r
- echo "</table></p>\n";\r
- }\r
- else echo "<p>No data.</p>\n";\r
-\r
- echo "<input type=hidden name=action value=insertrow>\n";\r
- echo "<input type=hidden name=table value=\"", htmlspecialchars($_REQUEST['table']), "\">\n";\r
- echo "<input type=hidden name=database value=\"", htmlspecialchars($_REQUEST['database']), "\">\n";\r
- echo "<input type=submit name=choice value=\"Save\">\n";\r
- echo "<input type=submit name=choice value=\"Save & Repeat\">\n";\r
- echo "<input type=submit name=choice value=\"Cancel\">\n";\r
- echo "</form>\n";\r
- }\r
- else {\r
- if (!isset($_POST['values'])) $_POST['values'] = array();\r
- if (!isset($_POST['nulls'])) $_POST['nulls'] = array();\r
- $status = $localData->insertRow($_POST['table'], $_POST['values'], $_POST['nulls']);\r
- if ($status == 0) {\r
- // @@@ AAARGH - THIS WON'T WORK WITH OTHER LANGUAGES!!\r
- if ($_POST['choice'] == 'Save')\r
- doDefault('Row inserted.');\r
- else {\r
- $_REQUEST['values'] = array();\r
- $_REQUEST['nulls'] = array();\r
- doInsertRow(true, 'Row inserted.');\r
- } \r
- }\r
- else\r
- doInsertRow(true, 'Row insert failed.');\r
- }\r
- \r
- }\r
-\r
- /**\r
- * Show confirmation of empty and perform actual empty\r
- */\r
- function doEmpty($confirm) {\r
- global $localData, $database;\r
- global $PHP_SELF;\r
-\r
- if ($confirm) {\r
- echo "<h2>", htmlspecialchars($_REQUEST['database']), ": Tables: ", htmlspecialchars($_REQUEST['table']), ": Empty</h2>\n";\r
-\r
- echo "<p>Are you sure you want to empty the table \"", htmlspecialchars($_REQUEST['table']), "\"?</p>\n";\r
-\r
- echo "<form action=\"$PHP_SELF\" method=\"post\">\n";\r
- echo "<input type=hidden name=action value=empty>\n";\r
- echo "<input type=hidden name=table value=\"", htmlspecialchars($_REQUEST['table']), "\">\n";\r
- echo "<input type=hidden name=database value=\"", htmlspecialchars($_REQUEST['database']), "\">\n";\r
- echo "<input type=submit name=choice value=\"Yes\"> <input type=submit name=choice value=\"No\">\n";\r
- echo "</form>\n";\r
- }\r
- else {\r
- $status = $localData->emptyTable($_POST['table']);\r
- if ($status == 0)\r
- doDefault('Table emptied.');\r
- else\r
- doDefault('Table empty failed.');\r
- }\r
- \r
- }\r
-\r
- /**\r
- * Show confirmation of drop and perform actual drop\r
- */\r
- function doDrop($confirm) {\r
- global $localData, $database;\r
- global $PHP_SELF;\r
-\r
- if ($confirm) {\r
- echo "<h2>", htmlspecialchars($_REQUEST['database']), ": Tables: ", htmlspecialchars($_REQUEST['table']), ": Drop</h2>\n";\r
-\r
- echo "<p>Are you sure you want to drop the table \"", htmlspecialchars($_REQUEST['table']), "\"?</p>\n";\r
-\r
- echo "<form action=\"$PHP_SELF\" method=\"post\">\n";\r
- echo "<input type=hidden name=action value=drop>\n";\r
- echo "<input type=hidden name=table value=\"", htmlspecialchars($_REQUEST['table']), "\">\n";\r
- echo "<input type=hidden name=database value=\"", htmlspecialchars($_REQUEST['database']), "\">\n";\r
- echo "<input type=submit name=choice value=\"Yes\"> <input type=submit name=choice value=\"No\">\n";\r
- echo "</form>\n";\r
- }\r
- else {\r
- $status = $localData->dropTable($_POST['table']);\r
- if ($status == 0)\r
- doDefault('Table dropped.');\r
- else\r
- doDefault('Table drop failed.');\r
- }\r
- \r
- }\r
-\r
- /**\r
- * Show confirmation of edit and perform actual update\r
- */\r
- function doEditRow($confirm, $msg = '') {\r
- global $localData, $database, $misc;\r
- global $strField, $strType, $strValue;\r
- global $PHP_SELF;\r
-\r
- $key = $_REQUEST['key'];\r
-\r
- if ($confirm) { \r
- echo "<h2>", htmlspecialchars($_REQUEST['database']), ": Tables: ", htmlspecialchars($_REQUEST['table']), ": Edit Row</h2>\n";\r
- $misc->printMsg($msg);\r
-\r
- $attrs = &$localData->getTableAttributes($_REQUEST['table']);\r
- $rs = &$localData->browseRow($_REQUEST['table'], $key);\r
-\r
- echo "<form action=\"$PHP_SELF\" method=\"post\">\n";\r
- if ($rs->recordCount() == 1 && $attrs->recordCount() > 0) {\r
- echo "<table>\n<tr>";\r
- \r
- // Output table header\r
- echo "<tr><th class=data>{$strField}</th><th class=data>{$strType}</th><th class=data>{$strValue}</th></tr>";\r
- \r
- // @@ CHECK THAT KEY ACTUALLY IS IN THE RESULT SET...\r
- \r
- $i = 0;\r
- while (!$attrs->EOF) {\r
- $id = (($i % 2) == 0 ? '1' : '2');\r
- echo "<tr>\n";\r
- echo "<td class=data{$id} nowrap>", htmlspecialchars($attrs->f['attname']), "</td>";\r
- echo "<td class=data{$id} nowrap>", htmlspecialchars($attrs->f['type']), "</td>";\r
- echo "<td class=data{$id} nowrap>", $localData->printField("values[{$attrs->f['attname']}]", \r
- $rs->f[$attrs->f['attname']], $attrs->f['type']), "</td>";\r
- echo "</tr>\n";\r
- $i++;\r
- $attrs->moveNext();\r
- }\r
- echo "</table></p>\n";\r
- }\r
- else echo "<p>No data.</p>\n";\r
-\r
- echo "<input type=hidden name=action value=editrow>\n";\r
- echo "<input type=hidden name=table value=\"", htmlspecialchars($_REQUEST['table']), "\">\n";\r
- echo "<input type=hidden name=database value=\"", htmlspecialchars($_REQUEST['database']), "\">\n";\r
- echo "<input type=hidden name=offset value=\"", htmlspecialchars($_REQUEST['offset']), "\">\n";\r
- echo "<input type=hidden name=limit value=\"", htmlspecialchars($_REQUEST['limit']), "\">\n";\r
- echo "<input type=hidden name=key value=\"", htmlspecialchars(serialize($key)), "\">\n";\r
- echo "<input type=submit name=choice value=\"Save\"> <input type=submit name=choice value=\"Cancel\">\n";\r
- echo "</form>\n";\r
- }\r
- else {\r
- $status = $localData->editRow($_POST['table'], $_POST['values'], unserialize($_POST['key']));\r
- if ($status == 0)\r
- doBrowse('Row updated.');\r
- else\r
- doBrowse('Row update failed.');\r
- }\r
- \r
- } \r
- \r
- /**\r
- * Show confirmation of drop and perform actual drop\r
- */\r
- function doDelRow($confirm) {\r
- global $localData, $database;\r
- global $PHP_SELF;\r
-\r
- if ($confirm) { \r
- echo "<h2>", htmlspecialchars($_REQUEST['database']), ": Tables: ", htmlspecialchars($_REQUEST['table']), ": Delete Row</h2>\n";\r
-\r
- echo "<p>Are you sure you want to delete this row?</p>\n";\r
- \r
- echo "<form action=\"$PHP_SELF\" method=\"post\">\n";\r
- echo "<input type=hidden name=action value=delrow>\n";\r
- echo "<input type=hidden name=table value=\"", htmlspecialchars($_REQUEST['table']), "\">\n";\r
- echo "<input type=hidden name=database value=\"", htmlspecialchars($_REQUEST['database']), "\">\n";\r
- echo "<input type=hidden name=offset value=\"", htmlspecialchars($_REQUEST['offset']), "\">\n";\r
- echo "<input type=hidden name=limit value=\"", htmlspecialchars($_REQUEST['limit']), "\">\n";\r
- echo "<input type=hidden name=key value=\"", htmlspecialchars(serialize($_REQUEST['key'])), "\">\n";\r
- echo "<input type=submit name=choice value=\"Yes\"> <input type=submit name=choice value=\"No\">\n";\r
- echo "</form>\n";\r
- }\r
- else {\r
- $status = $localData->deleteRow($_POST['table'], unserialize($_POST['key']));\r
- if ($status == 0)\r
- doBrowse('Row deleted.');\r
- else\r
- doBrowse('Row deletion failed.');\r
- }\r
- \r
- }\r
- \r
- /**\r
- * Browse a table\r
- */\r
- function doBrowse($msg = '') {\r
- global $data, $localData, $misc;\r
- global $PHP_SELF, $strActions, $guiShowOIDs, $strShowAllTables;\r
- \r
- echo "<h2>", htmlspecialchars($_REQUEST['database']), ": ", htmlspecialchars($_REQUEST['table']), "</h2>\n";\r
- $misc->printMsg($msg);\r
-\r
- $rs = &$localData->browseTable($_REQUEST['table'], $_REQUEST['offset'], $_REQUEST['limit']);\r
-\r
- // Fetch unique row identifier, if there is one\r
- $key = $localData->getRowIdentifier($_REQUEST['table']);\r
- \r
- if ($rs->recordCount() > 0) {\r
- echo "<table>\n<tr>";\r
- reset($rs->f);\r
- while(list($k, ) = each($rs->f)) {\r
- if ($k == $localData->id && !$guiShowOIDs) continue;\r
- echo "<th class=data>", htmlspecialchars($k), "</td>";\r
- }\r
- \r
- // @@ CHECK THAT KEY ACTUALLY IS IN THE RESULT SET...\r
- \r
- if (sizeof($key) > 0)\r
- echo "<th colspan=2 class=data>{$strActions}</th>\n";\r
- \r
- $i = 0;\r
- reset($rs->f);\r
- while (!$rs->EOF) {\r
- $id = (($i % 2) == 0 ? '1' : '2');\r
- echo "<tr>\n";\r
- while(list($k, $v) = each($rs->f)) {\r
- if ($k == $localData->id && !$guiShowOIDs) continue;\r
- echo "<td class=data{$id} nowrap>", nl2br(htmlspecialchars($v)), "</td>";\r
- } \r
- if (sizeof($key) > 0) {\r
- $key_str = '';\r
- foreach ($key as $v) {\r
- if ($key_str != '') $key_str .= '&';\r
- $key_str .= urlencode("key[{$v}]") . '=' . urlencode($rs->f[$v]);\r
- }\r
- \r
- echo "<td class=opbutton{$id}><a href=\"{$PHP_SELF}?action=confeditrow&database=", urlencode($_REQUEST['database']),\r
- "&table=", urlencode($_REQUEST['table']), "&offset=", $_REQUEST['offset'], "&limit=", $_REQUEST['limit'], "&{$key_str}\">Edit</a></td>\n";\r
- echo "<td class=opbutton{$id}><a href=\"{$PHP_SELF}?action=confdelrow&database=", urlencode($_REQUEST['database']),\r
- "&table=", urlencode($_REQUEST['table']), "&offset=", $_REQUEST['offset'], "&limit=", $_REQUEST['limit'], "&{$key_str}\">Delete</a></td>\n";\r
- }\r
- echo "</tr>\n";\r
- $rs->moveNext();\r
- $i++;\r
- }\r
- }\r
- else echo "<p>No data.</p>\n";\r
- \r
- echo "<p><a class=navlink href=\"$PHP_SELF?database=", urlencode($_REQUEST['database']), "\">{$strShowAllTables}</a></p>\n";\r
- }\r
- \r
- /**\r
- * Show default list of tables in the database\r
- */\r
- function doDefault($msg = '') {\r
- global $data, $localData;\r
- global $PHP_SELF, $strTable, $strOwner, $strActions, $strNoTables;\r
- global $strBrowse, $strProperties;\r
- \r
- echo "<h2>", htmlspecialchars($_REQUEST['database']), "</h2>\n";\r
- \r
- $tables = &$localData->getTables();\r
- \r
- if ($tables->recordCount() > 0) {\r
- echo "<table>\n";\r
- echo "<tr><th class=data>{$strTable}</th><th class=data>{$strOwner}</th><th colspan=6 class=data>{$strActions}</th>\n";\r
- $i = 0;\r
- while (!$tables->EOF) {\r
- $id = (($i % 2) == 0 ? '1' : '2');\r
- echo "<tr><td class=data{$id}>", htmlspecialchars($tables->f[$data->tbFields['tbname']]), "</td>\n";\r
- echo "<td class=data{$id}>", htmlspecialchars($tables->f[$data->tbFields['tbowner']]), "</td>\n";\r
- echo "<td class=opbutton{$id}><a href=\"{$PHP_SELF}?action=browse&offset=0&limit=30&database=", \r
- htmlspecialchars($_REQUEST['database']), "&table=", htmlspecialchars($tables->f[$data->tbFields['tbname']]), "\">{$strBrowse}</a></td>\n";\r
- echo "<td class=opbutton{$id}>Select</td>\n";\r
- echo "<td class=opbutton{$id}><a href=\"$PHP_SELF?action=confinsertrow&database=",\r
- htmlspecialchars($_REQUEST['database']), "&table=", urlencode($tables->f[$data->tbFields['tbname']]), "\">Insert</a></td>\n";\r
- echo "<td class=opbutton{$id}><a href=\"tblproperties.php?database=",\r
- htmlspecialchars($_REQUEST['database']), "&table=", htmlspecialchars($tables->f[$data->tbFields['tbname']]), "\">{$strProperties}</a></td>\n";\r
- echo "<td class=opbutton{$id}><a href=\"$PHP_SELF?action=confirm_empty&database=",\r
- htmlspecialchars($_REQUEST['database']), "&table=", urlencode($tables->f[$data->tbFields['tbname']]), "\">Empty</a></td>\n";\r
- echo "<td class=opbutton{$id}><a href=\"$PHP_SELF?action=confirm_drop&database=",\r
- htmlspecialchars($_REQUEST['database']), "&table=", urlencode($tables->f[$data->tbFields['tbname']]), "\">Drop</a></td>\n";\r
- echo "</tr>\n";\r
- $tables->moveNext();\r
- $i++;\r
- }\r
- }\r
- else {\r
- echo "<p>{$strNoTables}</p>\n";\r
- }\r
- }\r
- \r
- echo "<html>\n";\r
- echo "<body>\n";\r
- \r
- switch ($action) {\r
- case 'insertrow':\r
- if ($_POST['choice'] != 'Cancel') doInsertRow(false);\r
- else doDefault();\r
- break;\r
- case 'confinsertrow':\r
- doInsertRow(true);\r
- break; \r
- case 'empty':\r
- if ($_POST['choice'] == 'Yes') doEmpty(false);\r
- else doDefault();\r
- break;\r
- case 'confirm_empty':\r
- doEmpty(true);\r
- break;\r
- case 'drop':\r
- if ($_POST['choice'] == 'Yes') doDrop(false);\r
- else doDefault();\r
- break;\r
- case 'confirm_drop':\r
- doDrop(true);\r
- break;\r
- case 'editrow':\r
- if ($_POST['choice'] == 'Save') doEditRow(false);\r
- else doBrowse();\r
- break;\r
- case 'confeditrow':\r
- doEditRow(true);\r
- break; \r
- case 'delrow':\r
- if ($_POST['choice'] == 'Yes') doDelRow(false);\r
- else doBrowse();\r
- break;\r
- case 'confdelrow':\r
- doDelRow(true);\r
- break; \r
- case 'browse':\r
- doBrowse();\r
- break;\r
- default:\r
- doDefault();\r
- break;\r
- } \r
-\r
- echo "</body>\n";\r
- echo "</html>\n";\r
-\r
-?>\r
+<?php
+
+ /**
+ * List tables in a database
+ *
+ * $Id: tables.php,v 1.9 2002/09/16 15:09:54 chriskl Exp $
+ */
+
+ // Include application functions
+ include_once('../conf/config.inc.php');
+
+ $action = (isset($_REQUEST['action'])) ? $_REQUEST['action'] : '';
+ $PHP_SELF = $_SERVER['PHP_SELF'];
+
+ /**
+ * Ask for insert parameters and then actually insert row
+ */
+ function doSelectRows($confirm, $msg = '') {
+ global $localData, $database, $misc;
+ global $strField, $strType, $strNull, $strFunction, $strValue;
+ global $PHP_SELF;
+
+ if ($confirm) {
+ echo "<h2>", htmlspecialchars($_REQUEST['database']), ": Tables: ", htmlspecialchars($_REQUEST['table']), ": Select</h2>\n";
+ $misc->printMsg($msg);
+
+ $attrs = &$localData->getTableAttributes($_REQUEST['table']);
+
+ echo "<form action=\"$PHP_SELF\" method=\"post\">\n";
+ if ($attrs->recordCount() > 0) {
+ echo "<table>\n<tr>";
+
+ // Output table header
+ echo "<tr><th class=data>Show</th><th class=data>{$strField}</th><th class=data>{$strType}</th><th class=data>{$strNull}</th><th class=data>{$strFunction}</th><th class=data>{$strValue}</th></tr>";
+
+ $i = 0;
+ while (!$attrs->EOF) {
+ $attrs->f['attnotnull'] = $localData->phpBool($attrs->f['attnotnull']);
+ // Set up default value if there isn't one already
+ if (!isset($_REQUEST['values'][$attrs->f['attname']]))
+ $_REQUEST['values'][$attrs->f['attname']] = null;
+ // Continue drawing row
+ $id = (($i % 2) == 0 ? '1' : '2');
+ echo "<tr>\n";
+ echo "<td class=data{$id} 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=\"show[{$attrs->f['attname']}]\"",
+ isset($_REQUEST['show'][$attrs->f['attname']]) ? ' checked' : '', "></td>";
+ else
+ echo " </td>";
+ echo "<td class=data{$id} nowrap>", htmlspecialchars($attrs->f['attname']), "</td>";
+ echo "<td class=data{$id} nowrap>", htmlspecialchars($attrs->f['type']), "</td>";
+ echo "<td class=data{$id} 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' : '', "></td>";
+ else
+ echo " </td>";
+ echo "<td class=data{$id} nowrap><input size=10 name=\"function[{$attrs->f['attname']}]\"></td>";
+ echo "<td class=data{$id} nowrap>", $localData->printField("values[{$attrs->f['attname']}]",
+ $_REQUEST['values'][$attrs->f['attname']], $attrs->f['type']), "</td>";
+ echo "</tr>\n";
+ $i++;
+ $attrs->moveNext();
+ }
+ echo "</table></p>\n";
+ }
+ else echo "<p>No data.</p>\n";
+
+ echo "<p><input type=hidden name=action value=selectrows>\n";
+ echo "<input type=hidden name=table value=\"", htmlspecialchars($_REQUEST['table']), "\">\n";
+ echo "<input type=hidden name=database value=\"", htmlspecialchars($_REQUEST['database']), "\">\n";
+ echo "<input type=submit name=choice value=\"Select\">\n";
+ echo "<input type=submit name=choice value=\"Cancel\"></p>\n";
+ echo "</form>\n";
+ }
+ else {
+ if (!isset($_POST['values'])) $_POST['values'] = array();
+ if (!isset($_POST['nulls'])) $_POST['nulls'] = array();
+ $status = $localData->selectRows($_POST['table'], $_POST['values'], $_POST['nulls']);
+ if ($status == 0) {
+ // @@@ AAARGH - THIS WON'T WORK WITH OTHER LANGUAGES!!
+ if ($_POST['choice'] == 'Save')
+ doDefault('Row inserted.');
+ else {
+ $_REQUEST['values'] = array();
+ $_REQUEST['nulls'] = array();
+ doInsertRow(true, 'Row inserted.');
+ }
+ }
+ else
+ doInsertRow(true, 'Row insert failed.');
+ }
+
+ }
+
+ /**
+ * Ask for insert parameters and then actually insert row
+ */
+ function doInsertRow($confirm, $msg = '') {
+ global $localData, $database, $misc;
+ global $strField, $strType, $strNull, $strValue;
+ global $PHP_SELF;
+
+ if ($confirm) {
+ echo "<h2>", htmlspecialchars($_REQUEST['database']), ": Tables: ", htmlspecialchars($_REQUEST['table']), ": Insert Row</h2>\n";
+ $misc->printMsg($msg);
+
+ $attrs = &$localData->getTableAttributes($_REQUEST['table']);
+
+ echo "<form action=\"$PHP_SELF\" method=\"post\">\n";
+ if ($attrs->recordCount() > 0) {
+ echo "<table>\n<tr>";
+
+ // Output table header
+ echo "<tr><th class=data>{$strField}</th><th class=data>{$strType}</th><th class=data>{$strNull}</th><th class=data>{$strValue}</th></tr>";
+
+ $i = 0;
+ while (!$attrs->EOF) {
+ $attrs->f['attnotnull'] = $localData->phpBool($attrs->f['attnotnull']);
+ // Set up default value if there isn't one already
+ if (!isset($_REQUEST['values'][$attrs->f['attname']]))
+ $_REQUEST['values'][$attrs->f['attname']] = null;
+ // Continue drawing row
+ $id = (($i % 2) == 0 ? '1' : '2');
+ echo "<tr>\n";
+ echo "<td class=data{$id} nowrap>", htmlspecialchars($attrs->f['attname']), "</td>";
+ echo "<td class=data{$id} nowrap>", htmlspecialchars($attrs->f['type']), "</td>";
+ echo "<td class=data{$id} 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' : '', "></td>";
+ else
+ echo " </td>";
+ echo "<td class=data{$id} nowrap>", $localData->printField("values[{$attrs->f['attname']}]",
+ $_REQUEST['values'][$attrs->f['attname']], $attrs->f['type']), "</td>";
+ echo "</tr>\n";
+ $i++;
+ $attrs->moveNext();
+ }
+ echo "</table></p>\n";
+ }
+ else echo "<p>No data.</p>\n";
+
+ echo "<input type=hidden name=action value=insertrow>\n";
+ echo "<input type=hidden name=table value=\"", htmlspecialchars($_REQUEST['table']), "\">\n";
+ echo "<input type=hidden name=database value=\"", htmlspecialchars($_REQUEST['database']), "\">\n";
+ echo "<input type=submit name=choice value=\"Save\">\n";
+ echo "<input type=submit name=choice value=\"Save & Repeat\">\n";
+ echo "<input type=submit name=choice value=\"Cancel\">\n";
+ echo "</form>\n";
+ }
+ else {
+ if (!isset($_POST['values'])) $_POST['values'] = array();
+ if (!isset($_POST['nulls'])) $_POST['nulls'] = array();
+ $status = $localData->insertRow($_POST['table'], $_POST['values'], $_POST['nulls']);
+ if ($status == 0) {
+ // @@@ AAARGH - THIS WON'T WORK WITH OTHER LANGUAGES!!
+ if ($_POST['choice'] == 'Save')
+ doDefault('Row inserted.');
+ else {
+ $_REQUEST['values'] = array();
+ $_REQUEST['nulls'] = array();
+ doInsertRow(true, 'Row inserted.');
+ }
+ }
+ else
+ doInsertRow(true, 'Row insert failed.');
+ }
+
+ }
+
+ /**
+ * Show confirmation of empty and perform actual empty
+ */
+ function doEmpty($confirm) {
+ global $localData, $database;
+ global $PHP_SELF;
+
+ if ($confirm) {
+ echo "<h2>", htmlspecialchars($_REQUEST['database']), ": Tables: ", htmlspecialchars($_REQUEST['table']), ": Empty</h2>\n";
+
+ echo "<p>Are you sure you want to empty the table \"", htmlspecialchars($_REQUEST['table']), "\"?</p>\n";
+
+ echo "<form action=\"$PHP_SELF\" method=\"post\">\n";
+ echo "<input type=hidden name=action value=empty>\n";
+ echo "<input type=hidden name=table value=\"", htmlspecialchars($_REQUEST['table']), "\">\n";
+ echo "<input type=hidden name=database value=\"", htmlspecialchars($_REQUEST['database']), "\">\n";
+ echo "<input type=submit name=choice value=\"Yes\"> <input type=submit name=choice value=\"No\">\n";
+ echo "</form>\n";
+ }
+ else {
+ $status = $localData->emptyTable($_POST['table']);
+ if ($status == 0)
+ doDefault('Table emptied.');
+ else
+ doDefault('Table empty failed.');
+ }
+
+ }
+
+ /**
+ * Show confirmation of drop and perform actual drop
+ */
+ function doDrop($confirm) {
+ global $localData, $database;
+ global $PHP_SELF;
+
+ if ($confirm) {
+ echo "<h2>", htmlspecialchars($_REQUEST['database']), ": Tables: ", htmlspecialchars($_REQUEST['table']), ": Drop</h2>\n";
+
+ echo "<p>Are you sure you want to drop the table \"", htmlspecialchars($_REQUEST['table']), "\"?</p>\n";
+
+ echo "<form action=\"$PHP_SELF\" method=\"post\">\n";
+ echo "<input type=hidden name=action value=drop>\n";
+ echo "<input type=hidden name=table value=\"", htmlspecialchars($_REQUEST['table']), "\">\n";
+ echo "<input type=hidden name=database value=\"", htmlspecialchars($_REQUEST['database']), "\">\n";
+ echo "<input type=submit name=choice value=\"Yes\"> <input type=submit name=choice value=\"No\">\n";
+ echo "</form>\n";
+ }
+ else {
+ $status = $localData->dropTable($_POST['table']);
+ if ($status == 0)
+ doDefault('Table dropped.');
+ else
+ doDefault('Table drop failed.');
+ }
+
+ }
+
+ /**
+ * Show confirmation of edit and perform actual update
+ */
+ function doEditRow($confirm, $msg = '') {
+ global $localData, $database, $misc;
+ global $strField, $strType, $strValue;
+ global $PHP_SELF;
+
+ $key = $_REQUEST['key'];
+
+ if ($confirm) {
+ echo "<h2>", htmlspecialchars($_REQUEST['database']), ": Tables: ", htmlspecialchars($_REQUEST['table']), ": Edit Row</h2>\n";
+ $misc->printMsg($msg);
+
+ $attrs = &$localData->getTableAttributes($_REQUEST['table']);
+ $rs = &$localData->browseRow($_REQUEST['table'], $key);
+
+ echo "<form action=\"$PHP_SELF\" method=\"post\">\n";
+ if ($rs->recordCount() == 1 && $attrs->recordCount() > 0) {
+ echo "<table>\n<tr>";
+
+ // Output table header
+ echo "<tr><th class=data>{$strField}</th><th class=data>{$strType}</th><th class=data>{$strValue}</th></tr>";
+
+ // @@ CHECK THAT KEY ACTUALLY IS IN THE RESULT SET...
+
+ $i = 0;
+ while (!$attrs->EOF) {
+ $id = (($i % 2) == 0 ? '1' : '2');
+ echo "<tr>\n";
+ echo "<td class=data{$id} nowrap>", htmlspecialchars($attrs->f['attname']), "</td>";
+ echo "<td class=data{$id} nowrap>", htmlspecialchars($attrs->f['type']), "</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";
+ }
+ else echo "<p>No data.</p>\n";
+
+ echo "<input type=hidden name=action value=editrow>\n";
+ echo "<input type=hidden name=table value=\"", htmlspecialchars($_REQUEST['table']), "\">\n";
+ echo "<input type=hidden name=database value=\"", htmlspecialchars($_REQUEST['database']), "\">\n";
+ echo "<input type=hidden name=offset value=\"", htmlspecialchars($_REQUEST['offset']), "\">\n";
+ echo "<input type=hidden name=limit value=\"", htmlspecialchars($_REQUEST['limit']), "\">\n";
+ echo "<input type=hidden name=key value=\"", htmlspecialchars(serialize($key)), "\">\n";
+ echo "<input type=submit name=choice value=\"Save\"> <input type=submit name=choice value=\"Cancel\">\n";
+ echo "</form>\n";
+ }
+ else {
+ $status = $localData->editRow($_POST['table'], $_POST['values'], unserialize($_POST['key']));
+ if ($status == 0)
+ doBrowse('Row updated.');
+ else
+ doBrowse('Row update failed.');
+ }
+
+ }
+
+ /**
+ * Show confirmation of drop and perform actual drop
+ */
+ function doDelRow($confirm) {
+ global $localData, $database;
+ global $PHP_SELF;
+
+ if ($confirm) {
+ echo "<h2>", htmlspecialchars($_REQUEST['database']), ": Tables: ", htmlspecialchars($_REQUEST['table']), ": Delete Row</h2>\n";
+
+ echo "<p>Are you sure you want to delete this row?</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 "<input type=hidden name=database value=\"", htmlspecialchars($_REQUEST['database']), "\">\n";
+ echo "<input type=hidden name=offset value=\"", htmlspecialchars($_REQUEST['offset']), "\">\n";
+ echo "<input type=hidden name=limit value=\"", htmlspecialchars($_REQUEST['limit']), "\">\n";
+ echo "<input type=hidden name=key value=\"", htmlspecialchars(serialize($_REQUEST['key'])), "\">\n";
+ echo "<input type=submit name=choice value=\"Yes\"> <input type=submit name=choice value=\"No\">\n";
+ echo "</form>\n";
+ }
+ else {
+ $status = $localData->deleteRow($_POST['table'], unserialize($_POST['key']));
+ if ($status == 0)
+ doBrowse('Row deleted.');
+ else
+ doBrowse('Row deletion failed.');
+ }
+
+ }
+
+ /**
+ * Browse a table
+ */
+ function doBrowse($msg = '') {
+ global $data, $localData, $misc;
+ global $PHP_SELF, $strActions, $guiShowOIDs, $strShowAllTables;
+
+ echo "<h2>", htmlspecialchars($_REQUEST['database']), ": ", htmlspecialchars($_REQUEST['table']), "</h2>\n";
+ $misc->printMsg($msg);
+
+ $rs = &$localData->browseTable($_REQUEST['table'], $_REQUEST['offset'], $_REQUEST['limit']);
+
+ // Fetch unique row identifier, if there is one
+ $key = $localData->getRowIdentifier($_REQUEST['table']);
+
+ if ($rs->recordCount() > 0) {
+ echo "<table>\n<tr>";
+ reset($rs->f);
+ while(list($k, ) = each($rs->f)) {
+ if ($k == $localData->id && !$guiShowOIDs) continue;
+ echo "<th class=data>", htmlspecialchars($k), "</td>";
+ }
+
+ // @@ CHECK THAT KEY ACTUALLY IS IN THE RESULT SET...
+
+ if (sizeof($key) > 0)
+ echo "<th colspan=2 class=data>{$strActions}</th>\n";
+
+ $i = 0;
+ reset($rs->f);
+ while (!$rs->EOF) {
+ $id = (($i % 2) == 0 ? '1' : '2');
+ echo "<tr>\n";
+ while(list($k, $v) = each($rs->f)) {
+ if ($k == $localData->id && !$guiShowOIDs) continue;
+ echo "<td class=data{$id} nowrap>", nl2br(htmlspecialchars($v)), "</td>";
+ }
+ if (sizeof($key) > 0) {
+ $key_str = '';
+ foreach ($key as $v) {
+ if ($key_str != '') $key_str .= '&';
+ $key_str .= urlencode("key[{$v}]") . '=' . urlencode($rs->f[$v]);
+ }
+
+ echo "<td class=opbutton{$id}><a href=\"{$PHP_SELF}?action=confeditrow&database=", urlencode($_REQUEST['database']),
+ "&table=", urlencode($_REQUEST['table']), "&offset=", $_REQUEST['offset'], "&limit=", $_REQUEST['limit'], "&{$key_str}\">Edit</a></td>\n";
+ echo "<td class=opbutton{$id}><a href=\"{$PHP_SELF}?action=confdelrow&database=", urlencode($_REQUEST['database']),
+ "&table=", urlencode($_REQUEST['table']), "&offset=", $_REQUEST['offset'], "&limit=", $_REQUEST['limit'], "&{$key_str}\">Delete</a></td>\n";
+ }
+ echo "</tr>\n";
+ $rs->moveNext();
+ $i++;
+ }
+ echo "</table>\n";
+ }
+ else echo "<p>No data.</p>\n";
+
+ echo "<p><a class=navlink href=\"$PHP_SELF?database=", urlencode($_REQUEST['database']), "\">{$strShowAllTables}</a></p>\n";
+ }
+
+ /**
+ * Show default list of tables in the database
+ */
+ function doDefault($msg = '') {
+ global $data, $localData;
+ global $PHP_SELF, $strTable, $strOwner, $strActions, $strNoTables;
+ global $strBrowse, $strProperties;
+
+ echo "<h2>", htmlspecialchars($_REQUEST['database']), "</h2>\n";
+
+ $tables = &$localData->getTables();
+
+ if ($tables->recordCount() > 0) {
+ echo "<table>\n";
+ echo "<tr><th class=data>{$strTable}</th><th class=data>{$strOwner}</th><th colspan=6 class=data>{$strActions}</th>\n";
+ $i = 0;
+ while (!$tables->EOF) {
+ $id = (($i % 2) == 0 ? '1' : '2');
+ echo "<tr><td class=data{$id}>", htmlspecialchars($tables->f[$data->tbFields['tbname']]), "</td>\n";
+ echo "<td class=data{$id}>", htmlspecialchars($tables->f[$data->tbFields['tbowner']]), "</td>\n";
+ echo "<td class=opbutton{$id}><a href=\"{$PHP_SELF}?action=browse&offset=0&limit=30&database=",
+ htmlspecialchars($_REQUEST['database']), "&table=", htmlspecialchars($tables->f[$data->tbFields['tbname']]), "\">{$strBrowse}</a></td>\n";
+ echo "<td class=opbutton{$id}><a href=\"$PHP_SELF?action=confselectrows&database=",
+ htmlspecialchars($_REQUEST['database']), "&table=", urlencode($tables->f[$data->tbFields['tbname']]), "\">Select</a></td>\n";
+ echo "<td class=opbutton{$id}><a href=\"$PHP_SELF?action=confinsertrow&database=",
+ htmlspecialchars($_REQUEST['database']), "&table=", urlencode($tables->f[$data->tbFields['tbname']]), "\">Insert</a></td>\n";
+ echo "<td class=opbutton{$id}><a href=\"tblproperties.php?database=",
+ htmlspecialchars($_REQUEST['database']), "&table=", htmlspecialchars($tables->f[$data->tbFields['tbname']]), "\">{$strProperties}</a></td>\n";
+ echo "<td class=opbutton{$id}><a href=\"$PHP_SELF?action=confirm_empty&database=",
+ htmlspecialchars($_REQUEST['database']), "&table=", urlencode($tables->f[$data->tbFields['tbname']]), "\">Empty</a></td>\n";
+ echo "<td class=opbutton{$id}><a href=\"$PHP_SELF?action=confirm_drop&database=",
+ htmlspecialchars($_REQUEST['database']), "&table=", urlencode($tables->f[$data->tbFields['tbname']]), "\">Drop</a></td>\n";
+ echo "</tr>\n";
+ $tables->moveNext();
+ $i++;
+ }
+ echo "</table>\n";
+ }
+ else {
+ echo "<p>{$strNoTables}</p>\n";
+ }
+ }
+
+ echo "<html>\n";
+ echo "<body>\n";
+
+ switch ($action) {
+ case 'selectrows':
+ if ($_POST['choice'] != 'Cancel') doSelectRows(false);
+ else doDefault();
+ break;
+ case 'confselectrows':
+ doSelectRows(true);
+ break;
+ case 'insertrow':
+ if ($_POST['choice'] != 'Cancel') doInsertRow(false);
+ else doDefault();
+ break;
+ case 'confinsertrow':
+ doInsertRow(true);
+ break;
+ case 'empty':
+ if ($_POST['choice'] == 'Yes') doEmpty(false);
+ else doDefault();
+ break;
+ case 'confirm_empty':
+ doEmpty(true);
+ break;
+ case 'drop':
+ if ($_POST['choice'] == 'Yes') doDrop(false);
+ else doDefault();
+ break;
+ case 'confirm_drop':
+ doDrop(true);
+ break;
+ case 'editrow':
+ if ($_POST['choice'] == 'Save') doEditRow(false);
+ else doBrowse();
+ break;
+ case 'confeditrow':
+ doEditRow(true);
+ break;
+ case 'delrow':
+ if ($_POST['choice'] == 'Yes') doDelRow(false);
+ else doBrowse();
+ break;
+ case 'confdelrow':
+ doDelRow(true);
+ break;
+ case 'browse':
+ doBrowse();
+ break;
+ default:
+ doDefault();
+ break;
+ }
+
+ echo "</body>\n";
+ echo "</html>\n";
+
+?>