From 1d7a45d0fe4f4c8a9f7c6ac49f2adfc996ec086c Mon Sep 17 00:00:00 2001 From: xzilla Date: Thu, 3 Aug 2006 19:43:38 +0000 Subject: [PATCH] Refactor column properties into thier own page. Columns properties can now be accessed from the tree. Browsing via a column icon gives you the aggregate count of the values in that table. Patch from JGuillaume 'ioguix' De Rorthais --- colproperties.php | 284 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 284 insertions(+) create mode 100644 colproperties.php diff --git a/colproperties.php b/colproperties.php new file mode 100644 index 00000000..5657f670 --- /dev/null +++ b/colproperties.php @@ -0,0 +1,284 @@ +printTrail('column'); + $misc->printTitle($lang['straltercolumn'], 'pg.column.alter'); + $misc->printMsg($msg); + + echo "
\n"; + + // Output table header + echo "\n"; + echo ""; + if ($data->hasAlterColumnType()) { + echo ""; + echo ""; + } + else { + echo ""; + } + echo ""; + + $column = $data->getTableAttributes($_REQUEST['table'], $_REQUEST['column']); + $column->f['attnotnull'] = $data->phpBool($column->f['attnotnull']); + + // Upon first drawing the screen, load the existing column information + // from the database. + if (!isset($_REQUEST['default'])) { + $_REQUEST['field'] = $column->f['attname']; + $_REQUEST['type'] = $column->f['base_type']; + // Check to see if its' an array type... + // XXX: HACKY + if (substr($column->f['base_type'], strlen($column->f['base_type']) - 2) == '[]') { + $_REQUEST['type'] = substr($column->f['base_type'], 0, strlen($column->f['base_type']) - 2); + $_REQUEST['array'] = '[]'; + } + else { + $_REQUEST['type'] = $column->f['base_type']; + $_REQUEST['array'] = ''; + } + // To figure out the length, look in the brackets :( + // XXX: HACKY + if ($column->f['type'] != $column->f['base_type'] && ereg('\\(([0-9, ]*)\\)', $column->f['type'], $bits)) { + $_REQUEST['length'] = $bits[1]; + } + else + $_REQUEST['length'] = ''; + $_REQUEST['default'] = $_REQUEST['olddefault'] = $column->f['adsrc']; + if ($column->f['attnotnull']) $_REQUEST['notnull'] = 'YES'; + $_REQUEST['comment'] = $column->f['comment']; + } + + // Column name + echo ""; + + // Column type + if ($data->hasAlterColumnType()) { + // Fetch all available types + $types = $data->getTypes(true, false, true); + + echo ""; + + // Output array type selector + echo "\n"; + + echo ""; + } else { + // Otherwise draw the read-only type name + echo ""; + } + + echo "\n"; + echo ""; + echo ""; + + echo "
{$lang['strname']}{$lang['strtype']}{$lang['strlength']}{$lang['strtype']}{$lang['strnotnull']}{$lang['strdefault']}{$lang['strcomment']}
", $misc->printVal($data->formatType($column->f['type'], $column->f['atttypmod'])), "
\n"; + echo "

\n"; + echo "\n"; + echo $misc->form; + echo "\n"; + echo "\n"; + echo "\n"; + if ($column->f['attnotnull']) echo "\n"; + echo "formatType($column->f['type'], $column->f['atttypmod'])), "\" />\n"; + // Add hidden variables to suppress error notices if we don't support altering column type + if (!$data->hasAlterColumnType()) { + echo "\n"; + echo "\n"; + echo "\n"; + } + echo "\n"; + echo "

\n"; + echo "
\n"; + + break; + case 2: + global $data, $lang; + + // Check inputs + if (trim($_REQUEST['field']) == '') { + $_REQUEST['stage'] = 1; + doProperties($lang['strcolneedsname']); + return; + } + + $status = $data->alterColumn($_REQUEST['table'], $_REQUEST['column'], $_REQUEST['field'], + isset($_REQUEST['notnull']), isset($_REQUEST['oldnotnull']), + $_REQUEST['default'], $_REQUEST['olddefault'], + $_REQUEST['type'], $_REQUEST['length'], $_REQUEST['array'], $_REQUEST['oldtype'], + $_REQUEST['comment']); + if ($status == 0) { + if ($_REQUEST['column'] != $_REQUEST['field']) { + $_REQUEST['column']=$_REQUEST['field']; + $_reload_browser = true; + } + doDefault($lang['strcolumnaltered']); + } + else { + $_REQUEST['stage'] = 1; + doProperties($lang['strcolumnalteredbad']); + return; + } + break; + default: + echo "

{$lang['strinvalidparam']}

\n"; + } + } + + /** + * Show default list of columns in the table + */ + function doDefault($msg = '', $isTable = true) { + global $data, $conf, $misc, $tableName; + global $PHP_SELF, $lang; + + function attPre(&$rowdata) { + global $data; + $rowdata->f['+type'] = $data->formatType($rowdata->f['type'], $rowdata->f['atttypmod']); + } + + if (empty($_REQUEST['column'])) + $msg.= "
{$lang['strnoobjects']}"; + + $misc->printTrail('column'); + $misc->printTitle($lang['strcolprop']); + #$misc->printTabs('column','properties'); + $misc->printMsg($msg); + + if (! empty($_REQUEST['column'])) { + // Get table + $tdata = $data->getTable($tableName); + // Get columns + $attrs = $data->getTableAttributes($tableName, $_REQUEST['column']); + + // Show comment if any + if ($attrs->f['comment'] !== null) + echo "

", $misc->printVal($attrs->f['comment']), "

\n"; + + $column = array( + 'column' => array( + 'title' => $lang['strcolumn'], + 'field' => 'attname', + ), + 'type' => array( + 'title' => $lang['strtype'], + 'field' => '+type', + ) + ); + + if ($isTable) { + $column['notnull'] = array( + 'title' => $lang['strnotnull'], + 'field' => 'attnotnull', + 'type' => 'bool', + 'params'=> array('true' => 'NOT NULL', 'false' => '') + ); + $column['default'] = array( + 'title' => $lang['strdefault'], + 'field' => 'adsrc' + ); + } + + $actions=array(); + $misc->printTable($attrs, $column, $actions, null, 'attPre'); + + echo "
\n"; + + echo "\n"; + } + } + + $misc->printHeader($lang['strtables'] . ' - ' . $tableName); + $misc->printBody(); + + if (isset($_REQUEST['view'])) + doDefault(null, false); + else + switch ($action) { + case 'properties': + if (isset($_POST['cancel'])) doDefault(); + else doProperties(); + break; + default: + doDefault(); + break; + } + + $misc->printFooter(); + +?> -- 2.39.5