/**
* Class to hold various commonly used functions
*
- * $Id: Misc.php,v 1.14 2003/03/01 00:53:50 slubek Exp $
+ * $Id: Misc.php,v 1.15 2003/03/12 02:29:47 chriskl Exp $
*/
class Misc {
* Prints the page header. If global variable $_no_output is
* set then no header is drawn.
* @param $title The title of the page
+ * @param $script script tag
*/
- function printHeader($title = '') {
+ function printHeader($title = '', $script = null) {
global $appName, $appCharset, $_no_output, $guiTheme;
if (!isset($_no_output)) {
if ($title != '') echo " - ", htmlspecialchars($title);
echo "</title>\n";
echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset={$appCharset}\" />\n";
-
+
// Theme
echo "<style type=\"text/css\">\n<!--\n";
include("themes/{$guiTheme}/global.css");
echo "\n-->\n</style>\n";
+ if ($script) echo "\n {$script} \n";
echo "</head>\n";
}
}
--- /dev/null
+<?php\r
+\r
+/**\r
+* XHtmlSimpleElement \r
+* \r
+* Used to generate Xhtml-Code for simple xhtml elements \r
+* (i.e. elements, that can't contain child elements)\r
+* \r
+* \r
+* @author Felix Meinhold\r
+* \r
+*/\r
+class XHtmlSimpleElement {\r
+ var $_element;\r
+ var $_siblings = array();\r
+ var $_htmlcode; \r
+ var $_attributes = array();\r
+\r
+ \r
+ /**\r
+ * Constructor\r
+ * \r
+ * @param string The element's name. Defaults to name of the \r
+ * derived class\r
+ * \r
+ */\r
+ function XHtmlSimpleElement($element = null) {\r
+\r
+ $this->_element = $this->is_element();\r
+ \r
+ }\r
+\r
+ function set_style($style) {\r
+ $this->set_attribute("style", $style);\r
+ }\r
+ \r
+ function set_class($class) {\r
+ $this->set_attribute("class", $class);\r
+ }\r
+\r
+ \r
+ function is_element() {\r
+ return \r
+ str_replace("xhtml_", "", get_class($this));\r
+ }\r
+\r
+ /**\r
+ * Private function generates xhtml\r
+ * @access private \r
+ */\r
+ function _html() {\r
+ $this->_htmlcode = "<";\r
+ foreach ($this->_attributeCollection as $attribute => $value) {\r
+ if (!empty($value)) $this->_htmlcode .= " {$attribute}=\"{$value}\"";\r
+ }\r
+ $this->_htmlcode .= "/>";\r
+ \r
+ return $this->_htmlcode;\r
+ }\r
+ \r
+ /**\r
+ * Returns xhtml code\r
+ * \r
+ */\r
+ function fetch() {\r
+ return $this->_html();\r
+ }\r
+ /**\r
+ * Echoes xhtml\r
+ * \r
+ */ \r
+ function show() {\r
+ echo $this->fetch();\r
+ }\r
+\r
+ function set_attribute($attr, $value) {\r
+ $this->_attributes[$attr] = $value;\r
+ }\r
+\r
+\r
+}\r
+\r
+/**\r
+* XHtmlElement \r
+* \r
+* Used to generate Xhtml-Code for xhtml elements \r
+* that can contain child elements\r
+* \r
+* \r
+*/\r
+class XHtmlElement extends XHtmlSimpleElement {\r
+ var $_text = null; \r
+ var $_htmlcode = "";\r
+ var $_siblings = array();\r
+\r
+ function XHtmlElement($text = null) {\r
+ XHtmlSimpleElement::XHtmlSimpleElement();\r
+ \r
+ if ($text) $this->set_text($text);\r
+ }\r
+\r
+ /*\r
+ * Adds an xhtml child to element\r
+ * \r
+ * @param XHtmlElement The element to become a child of element\r
+ */\r
+ function add(&$object) {\r
+ array_push($this->_siblings,& $object);\r
+ }\r
+\r
+\r
+ /*\r
+ * The CDATA section of Element\r
+ * \r
+ * @param string Text\r
+ */\r
+ function set_text($text) {\r
+ if ($text) $this->_text = htmlspecialchars($text); \r
+ }\r
+\r
+ function fetch() {\r
+ return $this->_html();\r
+ }\r
+\r
+\r
+ function _html() {\r
+\r
+ $this->_htmlcode = "<{$this->_element}";\r
+ foreach ($this->_attributes as $attribute =>$value) {\r
+ if (!empty($value)) $this->_htmlcode .= " {$attribute} =\"{$value}\"";\r
+ }\r
+ $this->_htmlcode .= ">";\r
+\r
+ \r
+ if ($this->_text) { \r
+ $this->_htmlcode .= $this->_text;\r
+ }\r
+ \r
+ foreach ($this->_siblings as $obj) {\r
+ $this->_htmlcode .= $obj->fetch();\r
+ } \r
+\r
+ $this->_htmlcode .= "</{$this->_element}>";\r
+ \r
+ return $this->_htmlcode;\r
+ }\r
+\r
+ /*\r
+ * Returns siblings of Element\r
+ * \r
+ */\r
+ function get_siblings() {\r
+ return $this->_siblings;\r
+ }\r
+ \r
+ function has_siblings() {\r
+ return (count($this->_siblings) != 0);\r
+ }\r
+}\r
+\r
+class XHTML_Button extends XHtmlElement {\r
+ function XHTML_Button ($name, $text = null) {\r
+ parent::XHtmlElement();\r
+ \r
+ $this->set_attribute("name", $name);\r
+ \r
+ if ($text) $this->set_text($text);\r
+ }\r
+}\r
+\r
+\r
+class XHTML_Option extends XHtmlElement {\r
+ function XHTML_Option($text, $value = null) {\r
+ XHtmlElement::XHtmlElement(null); \r
+ $this->set_text($text);\r
+ }\r
+}\r
+\r
+\r
+class XHTML_Select extends XHTMLElement {\r
+ var $_data;\r
+\r
+ function XHTML_Select ($name, $multiple = false, $size = null) {\r
+ XHtmlElement::XHtmlElement(); \r
+\r
+ $this->set_attribute("name", $name);\r
+ if ($multiple) $this->set_attribute("multiple","multiple");\r
+ if ($size) $this->set_attribute("size",$size);\r
+ \r
+ \r
+ }\r
+ \r
+ function set_data(&$data, $delim = ",") {\r
+ switch (gettype($data)) {\r
+ case "string":\r
+ $this->_data = explode($delim, $data);\r
+ break;\r
+ case "array":\r
+ $this->_data = $data;\r
+ break;\r
+ \r
+ default:\r
+ break;\r
+ }\r
+ }\r
+ \r
+ function fetch() {\r
+ if ($this->_data) {\r
+ foreach ($this->_data as $value) { $this->add(new XHTML_Option($value)); }\r
+ }\r
+ return parent::fetch();\r
+ }\r
+ \r
+}\r
+\r
+\r
+?>
\ No newline at end of file
* A class that implements the DB interface for Postgres
* Note: This class uses ADODB and returns RecordSets.
*
- * $Id: Postgres.php,v 1.54 2003/03/10 02:15:15 chriskl Exp $
+ * $Id: Postgres.php,v 1.55 2003/03/12 02:29:47 chriskl Exp $
*/
// @@@ THOUGHT: What about inherits? ie. use of ONLY???
var $sqFields = array('seqname' => 'relname', 'seqowner' => 'usename', 'lastvalue' => 'last_value', 'incrementby' => 'increment_by', 'maxvalue' => 'max_value', 'minvalue'=> 'min_value', 'cachevalue' => 'cache_value', 'logcount' => 'log_cnt', 'iscycled' => 'is_cycled', 'iscalled' => 'is_called' );
var $ixFields = array('idxname' => 'relname', 'idxdef' => 'pg_get_indexdef', 'uniquekey' => 'indisunique', 'primarykey' => 'indisprimary');
var $rlFields = array('rulename' => 'rulename', 'ruledef' => 'definition');
- var $tgFields = array('tgname' => 'tgname');
+ var $tgFields = array('tgname' => 'tgname', 'tgtype' => 'tgtype', 'proname' => 'proname');
var $cnFields = array('conname' => 'conname', 'consrc' => 'consrc', 'contype' => 'contype');
var $typFields = array('typname' => 'typname', 'typowner' => 'typowner', 'typin' => 'typin',
'typout' => 'typout', 'typlen' => 'typlen', 'typdef' => 'typdef', 'typelem' => 'typelem',
var $typStorageDef = 'plain';
// Extra "magic" types
var $extraTypes = array('SERIAL');
+ // Array of allowed index types
+ var $typIndexes = array('BTREE', 'RTREE', 'GiST', 'HASH');
+ // Default index type
+ var $typIndexDef = 'BTREE';
+ // Array of allowed trigger events
+ var $triggerEvents= array('INSERT','UPDATE','DELETE','INSERT OR UPDATE');
+ // When to execute the trigger
+ var $triggerExecTimes = array('BEFORE','AFTER');
// Last oid assigned to a system object
var $_lastSystemOID = 18539;
function &getTriggers($table = '') {
$this->clean($table);
- $sql = "SELECT tgname
- FROM pg_trigger
+ $sql = "SELECT tgname,tgtype,tgargs,proname
+ FROM pg_trigger, pg_proc
WHERE tgrelid = (SELECT oid FROM pg_class WHERE relname='{$table}')
- AND NOT tgisconstraint";
+ AND pg_proc.oid = pg_trigger.tgfoid
+ AND NOT tgisconstraint";
return $this->selectSet($sql);
}
+ /**
+ * Create Trigger
+ *
+ * @param $tgname The name of the trigger to create
+ * @param $table The name of the table
+ * @param $trgpoc The function to execute
+ * @param $trgevent The action
+ * @param $trevent Event
+ */
+ function createTrigger($trgName, $table, $trgFunction, $trgExecTime, $trgEvent) {
+
+ /* No Statement Level Triggers in PostgreSQL (by now) */
+ $sql = "CREATE TRIGGER {$trgName} {$trgExecTime}
+ {$trgEvent} ON {$table}
+ FOR EACH ROW EXECUTE PROCEDURE {$trgFunction} ();";
+
+ return $this->execute($sql);
+
+ }
+
/**
* Drops a trigger
* @param $tgname The name of the trigger to drop
* A class that implements the DB interface for Postgres
* Note: This class uses ADODB and returns RecordSets.
*
- * $Id: Postgres73.php,v 1.21 2003/03/10 02:15:16 chriskl Exp $
+ * $Id: Postgres73.php,v 1.22 2003/03/12 02:29:47 chriskl Exp $
*/
// @@@ THOUGHT: What about inherits? ie. use of ONLY???
function &getTriggers($table = '') {
$this->clean($table);
- $sql = "SELECT t.tgname
- FROM pg_catalog.pg_trigger t
- WHERE t.tgrelid = (SELECT oid FROM pg_catalog.pg_class WHERE relname='{$table}'
- AND relnamespace=(SELECT oid FROM pg_catalog.pg_namespace WHERE nspname='{$this->_schema}'))
- AND (NOT tgisconstraint OR NOT EXISTS
- (SELECT 1 FROM pg_catalog.pg_depend d JOIN pg_catalog.pg_constraint c
- ON (d.refclassid = c.tableoid AND d.refobjid = c.oid)
- WHERE d.classid = t.tableoid AND d.objid = t.oid AND d.deptype = 'i' AND c.contype = 'f'))";
+ $sql = "SELECT
+ t.tgname,t.tgargs,t.tgtype,p.proname
+ FROM pg_catalog.pg_trigger t,pg_catalog.pg_proc p
+
+ WHERE t.tgrelid =(SELECT oid FROM pg_catalog.pg_class WHERE relname='{$table}'
+ AND (p.oid = t.tgfoid)
+ AND relnamespace=(SELECT oid FROM pg_catalog.pg_namespace WHERE nspname='{$this->_schema}'))
+ AND (NOT tgisconstraint OR NOT EXISTS (SELECT 1 FROM pg_catalog.pg_depend d JOIN pg_catalog.pg_constraint c
+ ON (d.refclassid = c.tableoid AND d.refobjid = c.oid)
+
+ WHERE d.classid = t.tableoid AND d.objid = t.oid AND d.deptype = 'i' AND c.contype = 'f'))";
return $this->selectSet($sql);
}
/**
* Returns a list of all functions in the database
* @param $all If true, will find all available functions, if false just those in search path
- * @return All functions
+ * @param $type If not null, will find all functions with return value = type
+ *
+ * @return All functions
*/
- function &getFunctions($all = false) {
+ function &getFunctions($all = false, $type = null) {
if ($all) {
$where = 'pg_catalog.pg_function_is_visible(p.oid)';
$distinct = 'DISTINCT ON (p.proname)';
}
else {
$where = "n.nspname = '{$this->_schema}'";
+
+ if ($type) {
+ $where .= " AND p.prorettype = (select oid from pg_catalog.pg_type p where p.typname = 'trigger') ";
+ }
+
$distinct = '';
}
--- /dev/null
+ // Globals\r
+ //\r
+\r
+\r
+ /*\r
+ * Multiple Selection lists in HTML Document\r
+ */\r
+ var tableColumnList;\r
+ var indexColumnList;\r
+\r
+ /*\r
+ * Two Array vars\r
+ */\r
+\r
+ var indexColumns, tableColumns;\r
+\r
+\r
+ function buttonPressed(object) {\r
+\r
+ if (object.name == "add") {\r
+ from = tableColumnList;\r
+ to = indexColumnList;\r
+ }\r
+ else {\r
+ to = tableColumnList;\r
+ from = indexColumnList;\r
+ }\r
+\r
+ var selectedOptions = getSelectedOptions(from);\r
+\r
+ for (i = 0; i < selectedOptions.length; i++) {\r
+ option = new Option(selectedOptions[i].text);\r
+ addToArray(to, option);\r
+ removeFromArray(from, selectedOptions[i].index);\r
+ }\r
+ }\r
+\r
+ function doSelectAll() {\r
+ for(var x = 0; x < indexColumnList.options.length; x++){\r
+ indexColumnList.options[x].selected = true;\r
+ }\r
+ }\r
+\r
+ function init() {\r
+ tableColumnList = document.formIndex.TableColumnList;\r
+ indexColumnList = document.getElementById("IndexColumnList");\r
+ indexColumns = indexColumnList.options;\r
+ tableColumns = tableColumnList.options;\r
+ }\r
+\r
+\r
+ function getSelectedOptions(obj) {\r
+ var selectedOptions = new Array();\r
+\r
+ for (i = 0; i < obj.options.length; i++) {\r
+ if (obj.options[i].selected) {\r
+ selectedOptions.push(obj.options[i]);\r
+ }\r
+ }\r
+\r
+ return selectedOptions;\r
+ }\r
+\r
+ function removeFromArray(obj, index) {\r
+ obj.remove(index);\r
+ }\r
+\r
+ function addToArray(obj, item) {\r
+ obj.options[obj.options.length] = item;\r
+ }
\ No newline at end of file
/**
* List indexes on a table
*
- * $Id: indexes.php,v 1.4 2003/03/01 00:53:51 slubek Exp $
+ * $Id: indexes.php,v 1.5 2003/03/12 02:29:47 chriskl Exp $
*/
// Include application functions
include_once('libraries/lib.inc.php');
-
+ include_once('classes/class.select.php');
+
$action = (isset($_REQUEST['action'])) ? $_REQUEST['action'] : '';
$PHP_SELF = $_SERVER['PHP_SELF'];
*/
function doCreateIndex($msg = '') {
global $data, $localData, $misc;
- global $PHP_SELF, $strName, $strDefinition, $strCreateIndex, $strIndexes, $strShowAllIndexes, $strColumns, $strSave, $strReset, $strExample;
+ global $PHP_SELF, $strName, $strDefinition, $strCreateIndex, $strShowAllIndexes, $strSave, $strReset, $strExample;
+ global $strTableColumnList, $strIndexColumnList, $strIndexes, $strIndexType, $strIndexName;
- if (!isset($_POST['formIndex'])) $_POST['formIndex'] = '';
+ if (!isset($_POST['formIndexName'])) $_POST['formIndexName'] = '';
if (!isset($_POST['formCols'])) $_POST['formCols'] = '';
echo "<h2>", htmlspecialchars($_REQUEST['database']), ": {$strIndexes} : {$strCreateIndex} </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=formIndex size={$data->_maxNameLen} maxlength={$data->_maxNameLen} value=\"",
- htmlspecialchars($_POST['formIndex']), "\"></td></tr>\n";
- echo "<tr><th class=data>{$strColumns}</th></tr>\n";
- echo "<tr><td class=data1><input name=formCols size={$data->_maxNameLen} value=\"",
- htmlspecialchars($_POST['formCols']), "\"> ({$strExample} col1, col2)</td></tr>\n";
+ $attrs = &$localData->getTableAttributes($_REQUEST['table']);
+
+ $selColumns = new XHTML_select("TableColumnList",true,10);
+ $selColumns->set_style("width: 10em;");
+
+ if ($attrs->recordCount() > 0) {
+ while (!$attrs->EOF) {
+ $selColumns->add(new XHTML_Option($attrs->f['attname']));
+ $attrs->moveNext();
+ }
+ }
+
+ $selIndex = new XHTML_select("IndexColumnList[]", true, 10);
+ $selIndex->set_style("width: 10em;");
+ $selIndex->set_attribute("id", "IndexColumnList");
+ $buttonAdd = new XHTML_Button("add", ">>");
+ $buttonAdd->set_attribute("onclick", "buttonPressed(this);");
+ $buttonAdd->set_attribute("type", "button");
+
+ $buttonRemove = new XHTML_Button("remove", "<<");
+ $buttonRemove->set_attribute("onclick", "buttonPressed(this);");
+ $buttonRemove->set_attribute("type", "button");
+
+ $selTypes = new XHTML_select("formIndexType");
+ $selTypes->set_data($localData->typIndexes);
+
+ echo "<form onsubmit=\"doSelectAll();\" name=\"formIndex\" action=\"$PHP_SELF\" method=\"post\">\n";
+
+
+ echo "<table>\n";
+ echo "<tr>";
+ echo "<th class=\"data\" colspan=\"3\">{$strIndexName}</th>";
+ echo "</tr>";
+ echo "<tr>";
+ echo "<td class=\"data1\" colspan=\"3\"><input type=\"text\" name=\"formIndexName\" size=\"80\" maxlength=\"300\"/></td></tr>";
+ echo "<tr><th class=data>{$strTableColumnList}</th><th class=\"data\"> </th><th class=data>{$strIndexColumnList}</th></tr>\n";
+ echo "<tr><td class=data1>" . $selColumns->fetch() . "</td>\n";
+ echo "<td class=\"data1\">" . $buttonRemove->fetch() . $buttonAdd->fetch() . "</td>";
+ echo "<td class=data1>" . $selIndex->fetch() . "</td></tr>\n";
echo "</table>\n";
+
+ echo "<table> \n";
+ echo "<tr>";
+ echo "<th class=\"data\">{$strIndexType}</th>";
+ echo "<td>" . $selTypes->fetch() . "</td>";
+ echo "</tr>";
+ echo "</table>";
+
+
echo "<p><input type=hidden name=action value=save_create_index>\n";
echo $misc->form;
echo "<input type=hidden name=table value=\"", htmlspecialchars($_REQUEST['table']), "\">\n";
function doSaveCreateIndex() {
global $localData;
global $strIndexNeedsName, $strIndexNeedsCols, $strIndexCreated, $strIndexCreatedBad;
+
+
// Check that they've given a name and at least one column
- if ($_POST['formIndex'] == '') doCreateIndex("{$strIndexNeedsName}");
- elseif ($_POST['formCols'] == '') doCreate("{$strIndexNeedsCols}");
+ if ($_POST['formIndexName'] == '') doCreateIndex("{$strIndexNeedsName}");
+ elseif ($_POST['IndexColumnList'] == '') doCreate("{$strIndexNeedsCols}");
else {
- $status = $localData->createIndex($_POST['formIndex'], $_POST['table'], explode(',', $_POST['formCols']));
+
+ $status = $localData->createIndex($_POST['formIndexName'], $_POST['table'], $_POST['IndexColumnList'], $_POST['formIndexType']);
if ($status == 0)
doDefault($strIndexCreated);
else
function doDefault($msg = '') {
global $data, $localData, $misc;
global $PHP_SELF;
- global $strNoIndexes, $strIndexes, $strActions, $strName, $strDefinition, $strCreateIndex, $strDrop;
+ global $strNoIndexes, $strIndexes, $strActions, $strName, $strDefinition, $strCreateIndex, $strDrop, $strPrivileges;
$misc->printTableNav();
echo "<h2>", htmlspecialchars($_REQUEST['database']), ": ", htmlspecialchars($_REQUEST['table']), ": {$strIndexes}</h2>\n";
if ($indexes->recordCount() > 0) {
echo "<table>\n";
- echo "<tr><th class=\"data\">{$strName}</th><th class=\"data\">{$strDefinition}</th><th class=\"data\">{$strActions}</th>\n";
+ echo "<tr><th class=\"data\">{$strName}</th><th class=\"data\">{$strDefinition}</th><th colspan=\"2\" class=\"data\">{$strActions}</th>\n";
$i = 0;
while (!$indexes->EOF) {
echo "<td class=\"data{$id}\">", htmlspecialchars( $indexes->f[$data->ixFields['idxdef']]), "</td>";
echo "<td class=\"data{$id}\">";
echo "<a href=\"$PHP_SELF?action=confirm_drop_index&{$misc->href}&index=", htmlspecialchars( $indexes->f[$data->ixFields['idxname']]),
- "&table=", htmlspecialchars($_REQUEST['table']), "\">{$strDrop}</td></tr>\n";
+ "&table=", htmlspecialchars($_REQUEST['table']), "\">{$strDrop}</td>\n";
+ echo "<td class=\"data{$id}\">";
+ echo "<a href=\"$PHP_SELF?action=priviledges_index&{$misc->href}&index=", htmlspecialchars( $indexes->f[$data->ixFields['idxname']]), "\">{$strPrivileges}</td></tr>\n";
$indexes->movenext();
$i++;
echo "<p><a class=\"navlink\" href=\"$PHP_SELF?action=create_index&{$misc->href}&table=", htmlspecialchars($_REQUEST['table']), "\">{$strCreateIndex}</a></p>\n";
}
- $misc->printHeader($strTables . ' - ' . $_REQUEST['table'] . ' - ' . $strIndexes);
- $misc->printBody();
+ $misc->printHeader($strIndexes, "<script src=\"indexes.js\" type=\"text/javascript\"></script>");
+
+ echo "<body onload=\"init();\">";
switch ($action) {
case 'save_create_index':
doDefault();
break;
}
-
+
$misc->printFooter();
?>
* Language template file for WebDB. Use this to base language
* files.
*
- * $Id: english.php,v 1.55 2003/03/10 02:15:17 chriskl Exp $
+ * $Id: english.php,v 1.56 2003/03/12 02:29:47 chriskl Exp $
*/
// Language and character set
$strKeyName = 'Key Name';
$strUniqueKey = 'Unique Key';
$strPrimaryKey = 'Primary Key';
+ $strIndexType = 'Type of index';
+ $strIndexName = 'Name of index';
+ $strTableColumnList = 'Columns in Table';
+ $strIndexColumnList = 'Columns in Index';
// Rules
$strRules = 'Rules';
$strConfDropTrigger = 'Are you sure you want to drop the trigger "%s" on "%s"?';
$strTriggerDropped = 'Trigger dropped.';
$strTriggerDroppedBad = 'Trigger drop failed.';
+
// Types
$strType = 'Type';
* Language template file for WebDB. Use this to base language
* files.
*
- * $Id: english.php,v 1.11 2003/03/10 02:15:18 chriskl Exp $
+ * $Id: english.php,v 1.12 2003/03/12 02:29:47 chriskl Exp $
*/
// Language and character set
$strKeyName = 'Key Name';
$strUniqueKey = 'Unique Key';
$strPrimaryKey = 'Primary Key';
+ $strIndexType = 'Type of index';
+ $strIndexName = 'Name of index';
+ $strTableColumnList = 'Columns in Table';
+ $strIndexColumnList = 'Columns in Index';
// Rules
$strRules = 'Rules';
$strConfDropTrigger = 'Are you sure you want to drop the trigger "%s" on "%s"?';
$strTriggerDropped = 'Trigger dropped.';
$strTriggerDroppedBad = 'Trigger drop failed.';
+
// Types
$strType = 'Type';
/**
* List triggers on a table
*
- * $Id: triggers.php,v 1.3 2003/03/01 00:53:51 slubek Exp $
+ * $Id: triggers.php,v 1.4 2003/03/12 02:29:47 chriskl Exp $
*/
// Include application functions
include_once('libraries/lib.inc.php');
-
+ include_once('classes/class.select.php');
+
+ // Constants to figure out tgtype
+
+ define ('TRIGGER_TYPE_ROW', (1 << 0) );
+ define ('TRIGGER_TYPE_BEFORE', (1 << 1) );
+ define ('TRIGGER_TYPE_INSERT', (1 << 2) );
+ define ('TRIGGER_TYPE_DELETE', (1 << 3) );
+ define ('TRIGGER_TYPE_UPDATE', (1 << 4) );
+
$action = (isset($_REQUEST['action'])) ? $_REQUEST['action'] : '';
$PHP_SELF = $_SERVER['PHP_SELF'];
+
+
+ function getTriggerExecTime($type) {
+ $execTime = "AFTER";
+ if ($type & TRIGGER_TYPE_BEFORE) $execTime = "BEFORE";
+
+ return $execTime;
+ }
+
+ function getTriggerEvent($type) {
+ if ($type & TRIGGER_TYPE_INSERT) $event = "INSERT";
+ elseif ($type & TRIGGER_TYPE_DELETE) $event = "DELETE";
+
+ if ($type & TRIGGER_TYPE_UPDATE) $event .= (empty($event)) ? "UPDATE" : " OR UPDATE";
+
+ return $event;
+
+ }
+
/**
* Show confirmation of drop and perform actual drop
*/
}
+ /**
+ * Let them create s.th.
+ */
+ function doCreate($msg = '') {
+ global $data, $localData, $misc;
+ global $PHP_SELF;
+ global $strTriggerEvents, $strTriggerWhen, $strCreateTrigger,$strTriggerNeedsFunction;
+ global $strTriggerFunction,$strTriggerEvent,$strTriggerExecTimes, $strSave, $strReset;
+ global $strFunction,$strTriggerName,$strTriggerArgs;
+
+
+ echo "<h2>",$strCreateTrigger,"</h2>";
+
+ $misc->printMsg($msg);
+
+ // List only functions, that return "trigger"
+ $funcs = &$localData->getFunctions(false, 'trigger');
+
+ if ($funcs->recordCount() == 0) {
+ echo "<p class='message'>" . $strTriggerNeedsFunction . "</p>";
+ return;
+ }
+
+
+ /* Populate functions */
+ $sel0 = new XHTML_Select("formFunction");
+ $sel0->set_style("width: 20em;");
+ while (!$funcs->EOF) {
+ $sel0->add(new XHTML_Option($funcs->f[$data->fnFields['fnname']]));
+ $funcs->moveNext();
+ }
+
+ $sel1 = new XHTML_Select('formExecTime');
+ $sel1->set_style("width: 7em;");
+ $sel1->set_data($localData->triggerExecTimes);
+
+ /* Populate events */
+ $sel2 = new XHTML_Select('formEvent');
+ $sel2->set_style("width: 7em;");
+ $sel2->set_data($localData->triggerEvents);
+
+ echo "<form action=\"$PHP_SELF\" method=\"POST\">\n";
+ echo "<table>";
+ echo "<tr><th colspan=\"4\" class=\"data\">{$strTriggerName}</th>";
+ echo "</tr>";
+ echo "<tr><td colspan=\"4\" class=\"data1\"><input type=\"text\" name=\"formTriggerName\" size=\"80\"/></th>";
+ echo "</tr>";
+ echo "<tr><th class=\"data\"> </th>";
+ echo " <th class=\"data\">{$strFunction}</th>";
+ echo " <th class=\"data\">{$strTriggerWhen}</th>";
+ echo " <th class=\"data\">{$strTriggerEvent}</th>";
+ echo "</tr>";
+ echo " <tr><td class=\"data1\">{$strTriggerFunction}</td>\n";
+ echo " <td class=\"data1\">" . $sel0->fetch() ."</td>";
+ echo " <td class=\"data1\">" . $sel1->fetch() . "</td>";
+ echo " <td class=\"data1\">" . $sel2->fetch() . "</td>";
+ echo "</tr>";
+ echo "<th colspan=\"4\" class=\"data\">{$strTriggerArgs}</th>";
+ echo "<tr><td colspan=\"4\" class=\"data1\"><input type=\"text\" name=\"formTriggerArgs\" size=\"80\"/></th>";
+ echo "</table>";
+ echo "<p><input type=submit value=\"{$strSave}\"> <input type=reset value=\"{$strReset}\"></p>\n";
+ echo "<input type=hidden value=save_create name=\"action\">";
+ echo "<input type=hidden name=table value=\"", htmlspecialchars($_REQUEST['table']), "\">\n";
+ echo $misc->form;
+ echo "</form>";
+ }
+
+
/**
* List all the triggers on the table
*/
function doDefault($msg = '') {
- global $data, $localData, $misc;
+ global $data, $localData, $misc, $database;
global $PHP_SELF;
global $strTriggers, $strName, $strActions, $strNoTriggers, $strCreateTrigger, $strDrop;
-
+ global $strTriggerWhen, $strTriggerEvent,$strFunction;
+
$misc->printTableNav();
echo "<h2>", htmlspecialchars($_REQUEST['database']), ": ", htmlspecialchars($_REQUEST['table']), ": {$strTriggers}</h2>\n";
$misc->printMsg($msg);
if ($triggers->recordCount() > 0) {
echo "<table>\n";
- echo "<tr><th class=\"data\">{$strName}</th><th class=\"data\">{$strActions}</th>\n";
+ echo "<tr>";
+ echo "<th class=\"data\">{$strName}</th>";
+ echo "<th class=\"data\">{$strTriggerWhen}</th>";
+ echo "<th class=\"data\">{$strTriggerEvent}</th>\n";
+ echo "<th class=\"data\">{$strFunction}</th>\n";
+ echo "</tr>";
$i = 0;
-
+
while (!$triggers->EOF) {
+ $execTime = htmlspecialchars( getTriggerExecTime($triggers->f[$data->tgFields['tgtype']]));
+ $event = htmlspecialchars( getTriggerEvent($triggers->f[$data->tgFields['tgtype']]));
$id = ( ($i % 2 ) == 0 ? '1' : '2' );
- echo "<tr><td class=\"data{$id}\">", htmlspecialchars( $triggers->f[$data->tgFields['tgname']]), "</td>";
+
+ echo "<tr>";
+ echo "<td class=\"data{$id}\">", htmlspecialchars( $triggers->f[$data->tgFields['tgname']]), "</td>";
+ echo "<td class=\"data{$id}\">{$execTime}</td>";
+ echo "<td class=\"data{$id}\">{$event}</td>";
+ echo "<td class=\"data{$id}\">",htmlspecialchars( $triggers->f[$data->tgFields['proname']]),"</td>";
echo "<td class=\"data{$id}\">";
echo "<a href=\"$PHP_SELF?action=confirm_drop&{$misc->href}&trigger=", htmlspecialchars( $triggers->f[$data->tgFields['tgname']]),
"&table=", htmlspecialchars($_REQUEST['table']), "\">{$strDrop}</td></tr>\n";
else
echo "<p>{$strNoTriggers}</p>\n";
- //echo "<p><a class=\"navlink\" href=\"$PHP_SELF?action=create&{$misc->href}&table=", htmlspecialchars($_REQUEST['table']), "\">{$strCreateTrigger}</a></p>\n";
+ echo "<p><a class=\"navlink\" href=\"$PHP_SELF?action=create&{$misc->href}&table=", htmlspecialchars($_REQUEST['table']), "\">{$strCreateTrigger}</a></p>\n";
}
+ /**
+ * Actually creates the new trigger in the database
+ */
+ function doSaveCreate() {
+ global $data, $localData, $misc, $database;
+ global $PHP_SELF;
+ global $strTriggerNeedsFunction, $strTriggerDone, $strTriggerNeedsName;
+
+
+ // Check that they've given a name and a definition
+
+ if ($_POST['formFunction'] == '')
+ doCreate($strTriggerNeedsFunction);
+ elseif ($_POST['formExecTime'] == '')
+ doCreate();
+ elseif ($_POST['formTriggerName'] == '')
+ doCreate($strTriggerNeedsName);
+ elseif ($_POST['formEvent'] == '')
+ doCreate();
+ else {
+ $status = &$localData->createTrigger($_POST['formTriggerName'],$_POST['table'], $_POST['formFunction'], $_POST['formExecTime'] , $_POST['formEvent']);
+ if ($status == 0)
+ doDefault($strTriggerDone);
+ else
+ doCreate($strTriggerFailed);
+ }
+ }
+
$misc->printHeader($strTables . ' - ' . $_REQUEST['table'] . ' - ' . $strTriggers);
- $misc->printBody();
switch ($action) {
case 'save_create':