* A class that implements the DB interface for Postgres\r
* Note: This class uses ADODB and returns RecordSets.\r
*\r
- * $Id: BaseDB.php,v 1.3 2002/07/26 09:03:06 chriskl Exp $\r
+ * $Id: BaseDB.php,v 1.4 2002/09/09 10:16:29 chriskl Exp $\r
*/\r
\r
include_once('../classes/database/ADODB_base.php');\r
function deleteRow($table, $key) {\r
if (!is_array($key)) return -1;\r
else return $this->delete($table, $key);\r
+ }\r
+ \r
+ /**\r
+ * Updates a row in a table\r
+ * @param $table The table in which to update\r
+ * @param $values An array mapping new values for the row\r
+ * @param $key An array mapping column => value to update\r
+ * @return 0 success\r
+ */\r
+ function editRow($table, $values, $key) {\r
+ if (!is_array($values) || !is_array($key)) return -1;\r
+ // @@ WE NEED TO SUPPORT NULL VALUES HERE!\r
+ // @@ ALSO, WE CANNOT USE update AS WE NEED TO NO QUOTE SOME THINGS\r
+ else return $this->update($table, $values, $key);\r
} \r
\r
// Capabilities\r
* A class that implements the DB interface for Postgres\r
* Note: This class uses ADODB and returns RecordSets.\r
*\r
- * $Id: Postgres.php,v 1.4 2002/09/09 05:08:55 chriskl Exp $\r
+ * $Id: Postgres.php,v 1.5 2002/09/09 10:16:31 chriskl Exp $\r
*/\r
\r
// @@@ THOUGHT: What about inherits? ie. use of ONLY???\r
} \r
} \r
}\r
+ \r
+ /**\r
+ * Outputs the HTML code for a particular field\r
+ * @param $name The name to give the field\r
+ * @param $value The value of the field\r
+ * @param $type The database type of the field\r
+ */\r
+ function printField($name, $value, $type) {\r
+ switch ($type) {\r
+ case 'bool':\r
+ case 'boolean':\r
+ echo "<select name=\"", htmlspecialchars($name), "\">\n";\r
+ echo "<option value=\"Y\"", ($value) ? ' selected' : '', ">Yes</option>\n";\r
+ echo "<option value=\"N\"", (!$value) ? ' selected' : '', ">No</option>\n";\r
+ echo "</select>\n";\r
+ break;\r
+ case 'text':\r
+ case 'bytea':\r
+ echo "<textarea name=\"", htmlspecialchars($name), "\" rows=5 cols=35 wrap=virtual>\n";\r
+ echo htmlspecialchars($value);\r
+ echo "</textarea>\n";\r
+ break;\r
+ default:\r
+ echo "<input name=\"", htmlspecialchars($name), "\" value=\"", htmlspecialchars($value), "\" size=35>\n";\r
+ break;\r
+ } \r
+ } \r
\r
/**\r
* Return all database available on the server\r
* @return A recordset\r
*/\r
function &browseTable($table, $offset, $limit) {\r
- return $this->selectTable("SELECT * FROM \"{$table}\"", $offset, $limit);\r
+ return $this->selectTable("SELECT oid, * FROM \"{$table}\"", $offset, $limit);\r
}\r
- \r
+\r
+ /**\r
+ * Returns a recordset of all columns in a table\r
+ * @param $table The name of a table\r
+ * @param $key The associative array holding the key to retrieve\r
+ * @return A recordset\r
+ */\r
+ function &browseRow($table, $key) { \r
+ $sql = "SELECT * FROM \"{$table}\" WHERE true";\r
+ foreach ($key as $k => $v) {\r
+ $this->clean($k);\r
+ $this->clean($v);\r
+ $sql .= " AND \"{$k}\"='{$v}'";\r
+ }\r
+ \r
+ return $this->selectSet($sql);\r
+ }\r
+\r
/**\r
*\r
*/\r
* 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.11 2002/07/26 09:03:06 chriskl Exp $\r
+ * $Id: Postgres71.php,v 1.12 2002/09/09 10:16:31 chriskl Exp $\r
*/\r
\r
// @@@ THOUGHT: What about inherits? ie. use of ONLY???\r
return $this->execute($sql);\r
}\r
\r
- /**\r
- *\r
- */\r
- function &browseTable($table, $offset, $limit) {\r
- return $this->selectTable("SELECT * FROM \"{$table}\"", $offset, $limit);\r
- }\r
- \r
- /**\r
- *\r
- */\r
- function &selectTable($sql, $offset, $limit) {\r
- return $this->selectSet($sql, $offset, $limit);\r
- }\r
-\r
/**\r
* Adds a check constraint to a table\r
* @param $table The table to which to add the check\r
* Language template file for WebDB. Use this to base language\r
* files.\r
*\r
- * $Id: template.php,v 1.9 2002/08/30 15:10:09 xzilla Exp $\r
+ * $Id: template.php,v 1.10 2002/09/09 10:16:31 chriskl Exp $\r
*/\r
\r
$appLang = 'english';\r
\r
// Sequences\r
$strNoSequences = 'No sequences found.';\r
+ \r
+ // Tables\r
+ $strField = 'Field';\r
+ $strType = 'Type';\r
+ $strValue = 'Value';\r
\r
?>\r
/**\r
* List tables in a database\r
*\r
- * $Id: tables.php,v 1.4 2002/07/26 09:03:06 chriskl Exp $\r
+ * $Id: tables.php,v 1.5 2002/09/09 10:16:31 chriskl Exp $\r
*/\r
\r
// Include application functions\r
$action = (isset($_REQUEST['action'])) ? $_REQUEST['action'] : '';\r
$PHP_SELF = $_SERVER['PHP_SELF'];\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
+ $rs = &$localData->browseRow($_REQUEST['table'], $key);\r
+ \r
+ echo "<form action=\"$PHP_SELF\" method=\"post\">\n";\r
+ if ($rs->recordCount() == 1) {\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
+ foreach ($rs->f as $k => $v) {\r
+ $id = (($i % 2) == 0 ? '1' : '2');\r
+ echo "<tr>\n";\r
+ echo "<td class=data{$id} nowrap>", htmlspecialchars($k), "</td>";\r
+ echo "<td class=data{$id} nowrap>Type</td>";\r
+ echo "<td class=data{$id} nowrap>", $localData->printField("values[{$k}]", $v, 'type goes here'), "</td>";\r
+ echo "</tr>\n";\r
+ $i++;\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
$misc->printMsg($msg);\r
\r
$rs = &$localData->browseTable($_REQUEST['table'], $_REQUEST['offset'], $_REQUEST['limit']);\r
- \r
+\r
// Fetch unique row identifier, if there is one\r
$key = $localData->getRowIdentifier($_REQUEST['table']);\r
\r
$key_str .= urlencode("key[{$v}]") . '=' . urlencode($rs->f[$v]);\r
}\r
\r
- echo "<td class=opbutton{$id}><a href=\"{$PHP_SELF}?action=editrow&database=", urlencode($_REQUEST['database']),\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
echo "<body>\n";\r
\r
switch ($action) {\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