alterTable($_POST['table'], $_POST['name'], $_POST['owner'], $_POST['comment']); 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; } doDefault($lang['strtablealtered']); } else doAlter($lang['strtablealteredbad']); } /** * Function to allow altering of a table */ function doAlter($msg = '') { global $data, $misc; global $PHP_SELF, $lang; echo "

", $misc->printVal($_REQUEST['database']), ": ", $misc->printVal($_REQUEST['table']), ": {$lang['stralter']}

\n"; $misc->printMsg($msg); // Fetch table info $table = &$data->getTable($_REQUEST['table']); // Fetch all users $users = &$data->getUsers(); if ($table->recordCount() > 0) { if (!isset($_POST['name'])) $_POST['name'] = $table->f[$data->tbFields['tbname']]; if (!isset($_POST['owner'])) $_POST['owner'] = $table->f[$data->tbFields['tbowner']]; if (!isset($_POST['comment'])) $_POST['comment'] = $table->f[$data->tbFields['tbcomment']]; echo "
\n"; echo "\n"; echo "\n"; echo "\n"; if ($data->hasAlterTableOwner() && $data->isSuperUser($_SESSION['webdbUsername'])) { echo "\n"; echo "\n"; } echo "\n"; echo "\n"; echo "
{$lang['strname']}"; echo "_maxNameLen}\" value=\"", htmlspecialchars($_POST['name']), "\" />
{$lang['strowner']}
{$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 $PHP_SELF, $lang; // Determine whether or not the table has an object ID $hasID = $data->hasObjectID($_REQUEST['table']); $misc->printTableNav(); echo "

", $misc->printVal($_REQUEST['database']), ": ", $misc->printVal($_REQUEST['table']), ": {$lang['strexport']}

\n"; $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['strdataonly']}{$lang['strformat']}\n
{$lang['stroids']}
{$lang['strstructureonly']}{$lang['strdrop']}
"; echo "{$lang['strstructureanddata']}{$lang['strformat']}\n
{$lang['strdrop']}
{$lang['stroids']}
\n"; echo "

{$lang['stroptions']}

\n"; echo "

{$lang['strshow']}\n"; echo "
{$lang['strdownload']}

\n"; echo "

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

\n"; echo "
\n"; } /** * Displays a screen where they can add a column */ function doAddColumn($msg = '') { global $data, $misc; global $PHP_SELF, $lang; if (!isset($_REQUEST['stage'])) $_REQUEST['stage'] = 1; switch ($_REQUEST['stage']) { case 1: global $lang; // Set variable defaults if (!isset($_POST['field'])) $_POST['field'] = ''; if (!isset($_POST['type'])) $_POST['type'] = ''; if (!isset($_POST['length'])) $_POST['length'] = ''; // Fetch all available types $types = &$data->getTypes(true); echo "

", $misc->printVal($_REQUEST['database']), ": ", $misc->printVal($_REQUEST['table']), ": {$lang['straddcolumn']}

\n"; $misc->printMsg($msg); echo "
\n"; // Output table header echo "\n"; echo ""; echo ""; echo "\n"; echo ""; echo "
{$lang['strfield']}{$lang['strtype']}{$lang['strlength']}
_maxNameLen}\" value=\"", htmlspecialchars($_POST['field']), "\" />
\n"; echo "\n"; echo "\n"; echo $misc->form; echo "\n"; echo "

\n"; echo "

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

{$lang['strinvalidparam']}

\n"; } } /** * Displays a screen where they can alter a column */ function doProperties($msg = '') { global $data, $misc; global $PHP_SELF, $lang; if (!isset($_REQUEST['stage'])) $_REQUEST['stage'] = 1; switch ($_REQUEST['stage']) { case 1: global $lang; echo "

", $misc->printVal($_REQUEST['database']), ": {$lang['strtables']}: {$lang['straltercolumn']}: ", $misc->printVal($_REQUEST['column']), "

\n"; $misc->printMsg($msg); echo "
\n"; // Output table header echo "\n"; echo ""; $column = &$data->getTableAttributes($_REQUEST['table'], $_REQUEST['column']); $column->f['attnotnull'] = $data->phpBool($column->f['attnotnull']); if (!isset($_REQUEST['default'])) { $_REQUEST['field'] = $column->f['attname']; $_REQUEST['default'] = $_REQUEST['olddefault'] = $column->f['adsrc']; if ($column->f['attnotnull']) $_REQUEST['notnull'] = 'YES'; } echo ""; echo ""; echo "\n"; echo ""; echo "
{$lang['strname']}{$lang['strtype']}{$lang['strnotnull']}{$lang['strdefault']}
", $misc->printVal($data->formatType($column->f['type'], $column->f['atttypmod'])), "
\n"; echo "

\n"; echo "\n"; echo $misc->form; 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['strfieldneedsname']); return; } $status = $data->alterColumn($_REQUEST['table'], $_REQUEST['column'], $_REQUEST['field'], isset($_REQUEST['notnull']), $_REQUEST['default'], $_REQUEST['olddefault']); if ($status == 0) doDefault($lang['strcolumnaltered']); else { $_REQUEST['stage'] = 1; doProperties($lang['strcolumnalteredbad']); return; } break; default: echo "

{$lang['strinvalidparam']}

\n"; } } /** * Show confirmation of drop column and perform actual drop */ function doDrop($confirm) { global $data, $database, $misc; global $PHP_SELF, $lang; if ($confirm) { echo "

", $misc->printVal($_REQUEST['database']), ": {$lang['strtables']}: ", $misc->printVal($_REQUEST['table']), ": " , $misc->printVal($_REQUEST['column']), ": {$lang['strdrop']}

\n"; echo "

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

\n"; echo "
\n"; echo "\n"; echo "\n"; echo "\n"; echo $misc->form; // Show cascade drop option if supportd if ($data->hasDropBehavior()) { echo "

{$lang['strcascade']}

\n"; } echo "\n"; echo "\n"; echo "
\n"; } else { $status = $data->dropColumn($_POST['table'], $_POST['column'], isset($_POST['cascade'])); if ($status == 0) doDefault($lang['strcolumndropped']); else doDefault($lang['strcolumndroppedbad']); } } /** * Show default list of columns in the table */ function doDefault($msg = '') { global $data, $misc; global $PHP_SELF, $lang; $misc->printTableNav(); echo "

", $misc->printVal($_REQUEST['database']), ": ", $misc->printVal($_REQUEST['table']), "

\n"; // Get table $tdata = &$data->getTable($_REQUEST['table']); // Get columns $attrs = &$data->getTableAttributes($_REQUEST['table']); $misc->printMsg($msg); // Show comment if any if ($tdata->f[$data->tbFields['tbcomment']] != null) echo "

", htmlspecialchars($tdata->f[$data->tbFields['tbcomment']]), "

\n"; echo "\n"; echo "\n\t\n\t\n"; echo "\t\n\t\n"; if ($data->hasDropColumn()) echo "\t\n"; else echo "\t\n"; echo "\n"; $i = 0; while (!$attrs->EOF) { $attrs->f['attnotnull'] = $data->phpBool($attrs->f['attnotnull']); $id = (($i % 2) == 0 ? '1' : '2'); echo "\n\t\n"; echo "\t\n"; echo "\t\n"; echo "\t\n"; echo "\t\n"; if ($data->hasDropColumn()) { echo "\t\n"; } echo "\n"; $attrs->moveNext(); $i++; } echo "
{$lang['strfield']}{$lang['strtype']}{$lang['strnotnull']}{$lang['strdefault']}{$lang['stractions']}{$lang['stractions']}
", $misc->printVal($attrs->f['attname']), "", $misc->printVal($data->formatType($attrs->f['type'], $attrs->f['atttypmod'])), "", ($attrs->f['attnotnull'] ? 'NOT NULL' : ''), "", $misc->printVal($attrs->f['adsrc']), "href}&table=", urlencode($_REQUEST['table']), "&column=", urlencode($attrs->f['attname']), "&action=properties\">{$lang['stralter']}href}&table=", urlencode($_REQUEST['table']), "&column=", urlencode($attrs->f['attname']), "&action=confirm_drop\">{$lang['strdrop']}
\n"; echo "
\n"; echo "\n"; } $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 '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(); ?>