alterTable($_POST['table'], $_POST['name'], $_POST['owner'], $_POST['newschema'], $_POST['comment'], $_POST['tablespace']); if ($status == 0) { // If table has been renamed, need to change to the new name and // reload the browser frame. if ($_POST['table'] != $_POST['name']) { // Jump them to the new table name $_REQUEST['table'] = $_POST['name']; // Force a browser reload $_reload_browser = true; } // If schema has changed, need to change to the new schema and reload the browser if (!empty($_POST['newschema']) && ($_POST['newschema'] != $data->_schema)) { // Jump them to the new sequence schema $misc->setCurrentSchema($_POST['newschema']); $_reload_browser = true; } doDefault($lang['strtablealtered']); } else doAlter($lang['strtablealteredbad']); } /** * Function to allow altering of a table */ function doAlter($msg = '') { global $data, $misc; global $lang; $misc->printTrail('table'); $misc->printTitle($lang['stralter'], 'pg.table.alter'); $misc->printMsg($msg); // Fetch table info $table = $data->getTable($_REQUEST['table']); // Fetch all users $users = $data->getUsers(); // Fetch all tablespaces from the database if ($data->hasTablespaces()) $tablespaces = $data->getTablespaces(true); if ($table->recordCount() > 0) { if (!isset($_POST['name'])) $_POST['name'] = $table->fields['relname']; if (!isset($_POST['owner'])) $_POST['owner'] = $table->fields['relowner']; if (!isset($_POST['newschema'])) $_POST['newschema'] = $table->fields['nspname']; if (!isset($_POST['comment'])) $_POST['comment'] = $table->fields['relcomment']; if ($data->hasTablespaces() && !isset($_POST['tablespace'])) $_POST['tablespace'] = $table->fields['tablespace']; echo "
\n"; echo "\n"; echo "\n"; echo "\n"; if ($data->isSuperUser()) { echo "\n"; echo "\n"; } if ($data->hasAlterTableSchema()) { $schemas = $data->getSchemas(); echo "\n"; echo "\n"; } // Tablespace (if there are any) if ($data->hasTablespaces() && $tablespaces->recordCount() > 0) { echo "\t\n\t\t\n"; echo "\t\t\n\t\n"; } echo "\n"; echo "\n"; echo "
{$lang['strname']}"; echo "_maxNameLen}\" value=\"", htmlspecialchars($_POST['name'], ENT_QUOTES), "\" />
{$lang['strowner']}
{$lang['strschema']}
{$lang['strtablespace']}\n\t\t\t\n\t\t
{$lang['strcomment']}"; echo "
\n"; echo "

\n"; echo "\n"; echo $misc->form; echo "\n"; echo "

\n"; echo "
\n"; } else echo "

{$lang['strnodata']}

\n"; } function doExport($msg = '') { global $data, $misc; global $lang; // Determine whether or not the table has an object ID (Always false if version>=12) $hasID = $data->hasObjectID($_REQUEST['table']); $misc->printTrail('table'); $misc->printTabs('table','export'); $misc->printMsg($msg); echo "
\n"; echo "\n"; echo "\n"; // Data only echo "\n"; echo "\n"; echo "\n\n"; if ($hasID) { echo "\n\n"; } // Structure only echo "\n"; echo "\n\n"; // Structure and data echo "\n"; echo "\n"; echo "\n\n"; echo "\n\n"; if ($hasID) { echo "\n\n"; } echo "
{$lang['strformat']}{$lang['stroptions']}
"; echo "{$lang['strformat']}\n
"; echo "{$lang['strformat']}\n
\n"; echo "

{$lang['stroptions']}

\n"; echo "

\n"; echo "

\n"; echo "

\n"; echo $misc->form; echo "\n"; echo "\n"; echo "

\n"; echo "
\n"; } function doImport($msg = '') { global $data, $misc; global $lang; $misc->printTrail('table'); $misc->printTabs('table','import'); $misc->printMsg($msg); // Check that file uploads are enabled if (ini_get('file_uploads')) { // Don't show upload option if max size of uploads is zero $max_size = $misc->inisizeToBytes(ini_get('upload_max_filesize')); if (is_double($max_size) && $max_size > 0) { echo "
\n"; echo "\n"; echo "\t\n\t\t\n"; echo "\t\t\n\t\n"; echo "\t\n\t\t\n"; echo "\t\t\n\t\n"; echo "\t\n\t\t\n"; echo "\t\t\n\t\n"; echo "
{$lang['strformat']}
{$lang['strallowednulls']}
\n"; echo "\t\t
\n"; echo "\t\t
{$lang['strfile']}"; echo "
\n"; echo "

\n"; echo $misc->form; echo "\n"; echo "

\n"; echo "
\n"; } } else echo "

{$lang['strnouploads']}

\n"; } /** * Displays a screen where they can add a column */ function doAddColumn($msg = '') { global $data, $misc, $_reload_browser; global $lang; if (!isset($_REQUEST['stage'])) $_REQUEST['stage'] = 1; switch ($_REQUEST['stage']) { case 1: // Set variable defaults if (!isset($_POST['field'])) $_POST['field'] = ''; if (!isset($_POST['type'])) $_POST['type'] = ''; if (!isset($_POST['array'])) $_POST['array'] = ''; if (!isset($_POST['length'])) $_POST['length'] = ''; if (!isset($_POST['default'])) $_POST['default'] = ''; if (!isset($_POST['comment'])) $_POST['comment'] = ''; // Fetch all available types $types = $data->getTypes(true, false, true); $types_for_js = array(); $misc->printTrail('table'); $misc->printTitle($lang['straddcolumn'], 'pg.column.add'); $misc->printMsg($msg); echo ""; echo "
\n"; // Output table header echo "\n"; echo "\n\n"; echo "\n"; if ($data->hasCreateFieldWithConstraints()) echo "\n\n"; echo "\n"; echo "\n"; echo "\n"; // Output array type selector echo "\n"; $predefined_size_types = array_intersect($data->predefined_size_types, $types_for_js); $escaped_predef_types = array(); // the JS escaped array elements foreach($predefined_size_types as $value) { $escaped_predef_types[] = "'{$value}'"; } echo "\n"; // Support for adding column with not null and default if ($data->hasCreateFieldWithConstraints()) { echo "\n"; echo "\n"; } echo "\n"; echo "
{$lang['strname']}{$lang['strtype']}{$lang['strlength']}{$lang['strnotnull']}{$lang['strdefault']}{$lang['strcomment']}
_maxNameLen}\" value=\"", htmlspecialchars($_POST['field']), "\" />
\n"; echo "

\n"; echo "\n"; echo $misc->form; echo "\n"; if (!$data->hasCreateFieldWithConstraints()) { echo "\n"; } echo "\n"; echo "

\n"; echo "
\n"; echo "\n"; break; case 2: // Check inputs if (trim($_POST['field']) == '') { $_REQUEST['stage'] = 1; doAddColumn($lang['strcolneedsname']); return; } if (!isset($_POST['length'])) $_POST['length'] = ''; $status = $data->addColumn($_POST['table'], $_POST['field'], $_POST['type'], $_POST['array'] != '', $_POST['length'], isset($_POST['notnull']), $_POST['default'], $_POST['comment']); if ($status == 0) { $_reload_browser = true; doDefault($lang['strcolumnadded']); } else { $_REQUEST['stage'] = 1; doAddColumn($lang['strcolumnaddedbad']); return; } break; default: echo "

{$lang['strinvalidparam']}

\n"; } } /** * Show confirmation of drop column and perform actual drop */ function doDrop($confirm) { global $data, $database, $misc, $_reload_browser; global $lang; if ($confirm) { $misc->printTrail('column'); $misc->printTitle($lang['strdrop'], 'pg.column.drop'); echo "

", sprintf($lang['strconfdropcolumn'], $misc->printVal($_REQUEST['column']), $misc->printVal($_REQUEST['table'])), "

\n"; echo "
\n"; echo "\n"; echo "\n"; echo "\n"; echo $misc->form; echo "

\n"; echo "\n"; echo "\n"; echo "
\n"; } else { $status = $data->dropColumn($_POST['table'], $_POST['column'], isset($_POST['cascade'])); if ($status == 0) { $_reload_browser = true; doDefault($lang['strcolumndropped']); } else doDefault($lang['strcolumndroppedbad']); } } function doTree() { global $misc, $data; $columns = $data->getTableAttributes($_REQUEST['table']); $reqvars = $misc->getRequestVars('column'); $attrs = array ( 'text' => field('attname'), 'action' => url('colproperties.php', $reqvars, array( 'table' => $_REQUEST['table'], 'column' => field('attname') ) ), 'icon' => 'Column', 'iconAction' => url('display.php', $reqvars, array( 'table' => $_REQUEST['table'], 'column' => field('attname'), 'query' => replace( 'SELECT "%column%", count(*) AS "count" FROM "%table%" GROUP BY "%column%" ORDER BY "%column%"', array ( '%column%' => field('attname'), '%table%' => $_REQUEST['table'] ) ) ) ), 'toolTip'=> field('comment') ); $misc->printTree($columns, $attrs, 'tblcolumns'); exit; } if ($action == 'tree') doTree(); /** * Show default list of columns in the table */ function doDefault($msg = '') { global $data, $conf, $misc; global $lang; function attPre(&$rowdata, $actions) { global $data; $rowdata->fields['+type'] = $data->formatType($rowdata->fields['type'], $rowdata->fields['atttypmod']); $attname = $rowdata->fields['attname']; $table = $_REQUEST['table']; $data->fieldClean($attname); $data->fieldClean($table); $actions['browse']['attr']['href']['urlvars']['query'] = "SELECT \"{$attname}\", count(*) AS \"count\" FROM \"{$table}\" GROUP BY \"{$attname}\" ORDER BY \"{$attname}\""; return $actions; } $misc->printTrail('table'); $misc->printTabs('table','columns'); $misc->printMsg($msg); // Get table $tdata = $data->getTable($_REQUEST['table']); // Get columns $attrs = $data->getTableAttributes($_REQUEST['table']); // Get constraints keys $ck = $data->getConstraintsWithFields($_REQUEST['table']); // Show comment if any if ($tdata->fields['relcomment'] !== null) echo '

', $misc->printVal($tdata->fields['relcomment']), "

\n"; $columns = array( 'column' => array( 'title' => $lang['strcolumn'], 'field' => field('attname'), 'url' => "colproperties.php?subject=column&{$misc->href}&table=".urlencode($_REQUEST['table'])."&", 'vars' => array('column' => 'attname'), ), 'type' => array( 'title' => $lang['strtype'], 'field' => field('+type'), ), 'notnull' => array( 'title' => $lang['strnotnull'], 'field' => field('attnotnull'), 'type' => 'bool', 'params'=> array('true' => 'NOT NULL', 'false' => ''), ), 'default' => array( 'title' => $lang['strdefault'], 'field' => field('adsrc'), ), 'keyprop' => array( 'title' => $lang['strconstraints'], 'class' => 'constraint_cell', 'field' => field('attname'), 'type' => 'callback', 'params'=> array( 'function' => 'cstrRender', 'keys' => $ck->getArray() ) ), 'actions' => array( 'title' => $lang['stractions'], ), 'comment' => array( 'title' => $lang['strcomment'], 'field' => field('comment') ), ); function cstrRender($s, $p) { global $misc, $data; $str =''; foreach ($p['keys'] as $k => $c) { if (is_null($p['keys'][$k]['consrc'])) { $atts = $data->getAttributeNames($_REQUEST['table'], explode(' ', $p['keys'][$k]['indkey'])); $c['consrc'] = ($c['contype'] == 'u' ? "UNIQUE (" : "PRIMARY KEY (") . join(',', $atts) . ')'; } if ($c['p_field'] == $s) switch ($c['contype']) { case 'p': $str .= 'icon('PrimaryKey') .'" alt="[pk]" title="'. htmlentities($c['consrc'], ENT_QUOTES, 'UTF-8') .'" />'; break; case 'f': $str .= 'icon('ForeignKey') .'" alt="[fk]" title="'. htmlentities($c['consrc'], ENT_QUOTES, 'UTF-8') .'" />'; break; case 'u': $str .= 'icon('UniqueConstraint') .'" alt="[uniq]" title="'. htmlentities($c['consrc'], ENT_QUOTES, 'UTF-8') .'" />'; break; case 'c': $str .= 'icon('CheckConstraint') .'" alt="[check]" title="'. htmlentities($c['consrc'], ENT_QUOTES, 'UTF-8') .'" />'; } } return $str; } $actions = array( 'browse' => array( 'title' => $lang['strbrowse'], 'url' => "display.php?{$misc->href}&subject=column&return=table&table=".urlencode($_REQUEST['table']).'&', 'vars' => array('column' => 'attname'), ), 'alter' => array( 'title' => $lang['stralter'], 'url' => "colproperties.php?action=properties&{$misc->href}&table=".urlencode($_REQUEST['table'])."&", 'vars' => array('column' => 'attname'), ), 'privileges' => array( 'title' => $lang['strprivileges'], 'url' => "privileges.php?subject=column&{$misc->href}&table=".urlencode($_REQUEST['table'])."&", 'vars' => array('column' => 'attname'), ), 'drop' => array( 'title' => $lang['strdrop'], 'url' => "tblproperties.php?action=confirm_drop&{$misc->href}&table=".urlencode($_REQUEST['table'])."&", 'vars' => array('column' => 'attname'), ), ); $actions = array( 'browse' => array( 'content' => $lang['strbrowse'], 'attr'=> array ( 'href' => array ( 'url' => 'display.php', 'urlvars' => array ( 'table' => $_REQUEST['table'], 'subject' => 'column', 'return' => 'table', 'column' => field('attname') ) ) ) ), 'alter' => array( 'content' => $lang['stralter'], 'attr'=> array ( 'href' => array ( 'url' => 'colproperties.php', 'urlvars' => array ( 'subject' => 'column', 'action' => 'properties', 'table' => $_REQUEST['table'], 'column' => field('attname') ) ) ) ), 'privileges' => array( 'content' => $lang['strprivileges'], 'attr'=> array ( 'href' => array ( 'url' => 'privileges.php', 'urlvars' => array ( 'subject' => 'column', 'table' => $_REQUEST['table'], 'column' => field('attname') ) ) ) ), 'drop' => array( 'content' => $lang['strdrop'], 'attr'=> array ( 'href' => array ( 'url' => 'tblproperties.php', 'urlvars' => array ( 'subject' => 'column', 'action' => 'confirm_drop', 'table' => $_REQUEST['table'], 'column' => field('attname') ) ) ) ), ); $misc->printTable($attrs, $columns, $actions, 'tblproperties-tblproperties', null, 'attPre'); $navlinks = array ( 'browse' => array ( 'attr'=> array ( 'href' => array ( 'url' => 'display.php', 'urlvars' => array ( 'server' => $_REQUEST['server'], 'database' => $_REQUEST['database'], 'schema' => $_REQUEST['schema'], 'table' => $_REQUEST['table'], 'subject' => 'table', 'return' => 'table' ) ) ), 'content' => $lang['strbrowse'] ), 'select' => array ( 'attr'=> array ( 'href' => array ( 'url' => 'tables.php', 'urlvars' => array ( 'action' => 'confselectrows', 'server' => $_REQUEST['server'], 'database' => $_REQUEST['database'], 'schema' => $_REQUEST['schema'], 'table' => $_REQUEST['table'] ) ) ), 'content' => $lang['strselect'] ), 'insert' => array ( 'attr'=> array ( 'href' => array ( 'url' => 'tables.php', 'urlvars' => array ( 'action' => 'confinsertrow', 'server' => $_REQUEST['server'], 'database' => $_REQUEST['database'], 'schema' => $_REQUEST['schema'], 'table' => $_REQUEST['table'] ) ) ), 'content' => $lang['strinsert'] ), 'empty' => array ( 'attr'=> array ( 'href' => array ( 'url' => 'tables.php', 'urlvars' => array ( 'action' => 'confirm_empty', 'server' => $_REQUEST['server'], 'database' => $_REQUEST['database'], 'schema' => $_REQUEST['schema'], 'table' => $_REQUEST['table'] ) ) ), 'content' => $lang['strempty'] ), 'drop' => array ( 'attr'=> array ( 'href' => array ( 'url' => 'tables.php', 'urlvars' => array ( 'action' => 'confirm_drop', 'server' => $_REQUEST['server'], 'database' => $_REQUEST['database'], 'schema' => $_REQUEST['schema'], 'table' => $_REQUEST['table'], ) ) ), 'content' => $lang['strdrop'] ), 'addcolumn' => array ( 'attr'=> array ( 'href' => array ( 'url' => 'tblproperties.php', 'urlvars' => array ( 'action' => 'add_column', 'server' => $_REQUEST['server'], 'database' => $_REQUEST['database'], 'schema' => $_REQUEST['schema'], 'table' => $_REQUEST['table'] ) ) ), 'content' => $lang['straddcolumn'] ), 'alter' => array ( 'attr'=> array ( 'href' => array ( 'url' => 'tblproperties.php', 'urlvars' => array ( 'action' => 'confirm_alter', 'server' => $_REQUEST['server'], 'database' => $_REQUEST['database'], 'schema' => $_REQUEST['schema'], 'table' => $_REQUEST['table'] ) ) ), 'content' => $lang['stralter'] ) ); $misc->printNavLinks($navlinks, 'tblproperties-tblproperties' , get_defined_vars() ); } $misc->printHeader($lang['strtables'] . ' - ' . $_REQUEST['table']); $misc->printBody(); switch ($action) { case 'alter': if (isset($_POST['alter'])) doSaveAlter(); else doDefault(); break; case 'confirm_alter': doAlter(); break; case 'import': doImport(); break; case 'export': doExport(); break; case 'add_column': if (isset($_POST['cancel'])) doDefault(); else doAddColumn(); break; case 'properties': if (isset($_POST['cancel'])) doDefault(); else doProperties(); break; case 'drop': if (isset($_POST['drop'])) doDrop(false); else doDefault(); break; case 'confirm_drop': doDrop(true); break; default: doDefault(); break; } $misc->printFooter(); ?>