/** * Function to save after altering a table */ function doSaveAlter() { global $data, $lang, $_reload_browser, $misc; // For databases that don't allow owner change if (!isset($_POST['owner'])) { $_POST['owner'] = ''; } // Default tablespace to null if it isn't set if (!isset($_POST['tablespace'])) { $_POST['tablespace'] = null; } if (!isset($_POST['newschema'])) { $_POST['newschema'] = null; } $status = $data->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 save after altering a domain */ function doSaveAlter() { global $data, $lang; $status = $data->alterDomain($_POST['domain'], $_POST['domdefault'], isset($_POST['domnotnull']), $_POST['domowner']); if ($status == 0) { doProperties($lang['strdomainaltered']); } else { doAlter($lang['strdomainalteredbad']); } }
/** * Function to save after altering a trigger */ function doSaveAlter() { global $data, $lang; $status = $data->alterTrigger($_POST['table'], $_POST['trigger'], $_POST['name']); if ($status == 0) { doDefault($lang['strtriggeraltered']); } else { doAlter($lang['strtriggeralteredbad']); } }
/** * Function to save after altering a tablespace */ function doSaveAlter() { global $data, $lang; // Check data if (trim($_POST['name']) == '') { doAlter($lang['strtablespaceneedsname']); } else { $status = $data->alterTablespace($_POST['tablespace'], $_POST['name'], $_POST['owner'], $_POST['comment']); if ($status == 0) { // If tablespace has been renamed, need to change to the new name if ($_POST['tablespace'] != $_POST['name']) { // Jump them to the new table name $_REQUEST['tablespace'] = $_POST['name']; } doDefault($lang['strtablespacealtered']); } else { doAlter($lang['strtablespacealteredbad']); } } }
doSaveCreate(); } break; case 'create': doCreate(); break; case 'drop': if (isset($_REQUEST['drop'])) { doDrop(false); } else { doDefault(); } break; case 'confirm_drop': doDrop(true); break; case 'alter': if (isset($_POST['oldname']) && isset($_POST['newname']) && !isset($_POST['cancel'])) { doAlter(false); } else { doDefault(); } break; case 'confirm_alter': doAlter(true); break; default: doDefault(); break; } $misc->printFooter();
/** * Save the form submission containing changes to a schema */ function doSaveAlter($msg = '') { global $data, $misc, $lang, $_reload_browser; $status = $data->updateSchema($_POST['schema'], $_POST['comment'], $_POST['name'], $_POST['owner']); if ($status == 0) { $_reload_browser = true; doDefault($lang['strschemaaltered']); } else { doAlter($lang['strschemaalteredbad']); } }
doReset(); break; case 'nextval': doNextval(); break; case 'setval': if (isset($_POST['setval'])) { doSaveSetval(); } else { doDefault(); } break; case 'confirm_setval': doSetval(); break; case 'alter': if (isset($_POST['alter'])) { doSaveAlter(); } else { doDefault(); } break; case 'confirm_alter': doAlter(); break; default: doDefault(); break; } // Print footer $misc->printFooter();
function doAlter($confirm = false, $msg = '') { if ($confirm) { global $data, $misc, $lang; $misc->printTrail('view'); $misc->printTitle($lang['stralter'], 'pg.view.alter'); $misc->printMsg($msg); // Fetch view info $view = $data->getView($_REQUEST['view']); if ($view->recordCount() > 0) { if (!isset($_POST['name'])) { $_POST['name'] = $view->fields['relname']; } if (!isset($_POST['owner'])) { $_POST['owner'] = $view->fields['relowner']; } if (!isset($_POST['newschema'])) { $_POST['newschema'] = $view->fields['nspname']; } if (!isset($_POST['comment'])) { $_POST['comment'] = $view->fields['relcomment']; } echo "<form action=\"viewproperties.php\" method=\"post\">\n"; echo "<table>\n"; echo "<tr><th class=\"data left required\">{$lang['strname']}</th>\n"; echo "<td class=\"data1\">"; echo "<input name=\"name\" size=\"32\" maxlength=\"{$data->_maxNameLen}\" value=\"", htmlspecialchars($_POST['name']), "\" /></td></tr>\n"; if ($data->isSuperUser()) { // Fetch all users $users = $data->getUsers(); echo "<tr><th class=\"data left required\">{$lang['strowner']}</th>\n"; echo "<td class=\"data1\"><select name=\"owner\">"; while (!$users->EOF) { $uname = $users->fields['usename']; echo "<option value=\"", htmlspecialchars($uname), "\"", $uname == $_POST['owner'] ? ' selected="selected"' : '', ">", htmlspecialchars($uname), "</option>\n"; $users->moveNext(); } echo "</select></td></tr>\n"; } if ($data->hasAlterTableSchema()) { $schemas = $data->getSchemas(); echo "<tr><th class=\"data left required\">{$lang['strschema']}</th>\n"; echo "<td class=\"data1\"><select name=\"newschema\">"; while (!$schemas->EOF) { $schema = $schemas->fields['nspname']; echo "<option value=\"", htmlspecialchars($schema), "\"", $schema == $_POST['newschema'] ? ' selected="selected"' : '', ">", htmlspecialchars($schema), "</option>\n"; $schemas->moveNext(); } echo "</select></td></tr>\n"; } echo "<tr><th class=\"data left\">{$lang['strcomment']}</th>\n"; echo "<td class=\"data1\">"; echo "<textarea rows=\"3\" cols=\"32\" name=\"comment\">", htmlspecialchars($_POST['comment']), "</textarea></td></tr>\n"; echo "</table>\n"; echo "<input type=\"hidden\" name=\"action\" value=\"alter\" />\n"; echo "<input type=\"hidden\" name=\"view\" value=\"", htmlspecialchars($_REQUEST['view']), "\" />\n"; echo $misc->form; echo "<p><input type=\"submit\" name=\"alter\" value=\"{$lang['stralter']}\" />\n"; echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n"; echo "</form>\n"; } else { echo "<p>{$lang['strnodata']}</p>\n"; } } else { global $data, $lang, $_reload_browser, $misc; // For databases that don't allow owner change if (!isset($_POST['owner'])) { $_POST['owner'] = ''; } if (!isset($_POST['newschema'])) { $_POST['newschema'] = null; } $status = $data->alterView($_POST['view'], $_POST['name'], $_POST['owner'], $_POST['newschema'], $_POST['comment']); if ($status == 0) { // If view has been renamed, need to change to the new name and // reload the browser frame. if ($_POST['view'] != $_POST['name']) { // Jump them to the new view name $_REQUEST['view'] = $_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['strviewaltered']); } else { doAlter(true, $lang['strviewalteredbad']); } } }
/** * Displays a screen where they can alter a column */ function doAlter($msg = '') { global $data, $misc, $_reload_browser; global $lang; if (!isset($_REQUEST['stage'])) { $_REQUEST['stage'] = 1; } switch ($_REQUEST['stage']) { case 1: $misc->printTrail('column'); $misc->printTitle($lang['stralter'], 'pg.column.alter'); $misc->printMsg($msg); echo "<script src=\"tables.js\" type=\"text/javascript\"></script>"; echo "<form action=\"colproperties.php\" method=\"post\">\n"; // Output table header echo "<table>\n"; echo "<tr><th class=\"data required\">{$lang['strname']}</th>\n"; if ($data->hasAlterColumnType()) { echo "<th class=\"data required\" colspan=\"2\">{$lang['strtype']}</th>\n"; echo "<th class=\"data\">{$lang['strlength']}</th>\n"; } else { echo "<th class=\"data required\">{$lang['strtype']}</th>\n"; } echo "<th class=\"data\">{$lang['strnotnull']}</th>\n<th class=\"data\">{$lang['strdefault']}</th>\n<th class=\"data\">{$lang['strcomment']}</th></tr>\n"; $column = $data->getTableAttributes($_REQUEST['table'], $_REQUEST['column']); $column->fields['attnotnull'] = $data->phpBool($column->fields['attnotnull']); // Upon first drawing the screen, load the existing column information // from the database. if (!isset($_REQUEST['default'])) { $_REQUEST['field'] = $column->fields['attname']; $_REQUEST['type'] = $column->fields['base_type']; // Check to see if its' an array type... // XXX: HACKY if (substr($column->fields['base_type'], strlen($column->fields['base_type']) - 2) == '[]') { $_REQUEST['type'] = substr($column->fields['base_type'], 0, strlen($column->fields['base_type']) - 2); $_REQUEST['array'] = '[]'; } else { $_REQUEST['type'] = $column->fields['base_type']; $_REQUEST['array'] = ''; } // To figure out the length, look in the brackets :( // XXX: HACKY if ($column->fields['type'] != $column->fields['base_type'] && preg_match('/\\(([0-9, ]*)\\)/', $column->fields['type'], $bits)) { $_REQUEST['length'] = $bits[1]; } else { $_REQUEST['length'] = ''; } $_REQUEST['default'] = $_REQUEST['olddefault'] = $column->fields['adsrc']; if ($column->fields['attnotnull']) { $_REQUEST['notnull'] = 'YES'; } $_REQUEST['comment'] = $column->fields['comment']; } // Column name echo "<tr><td><input name=\"field\" size=\"16\" maxlength=\"{$data->_maxNameLen}\" value=\"", htmlspecialchars($_REQUEST['field']), "\" /></td>\n"; // Column type $escaped_predef_types = array(); // the JS escaped array elements if ($data->hasAlterColumnType()) { // Fetch all available types $types = $data->getTypes(true, false, true); $types_for_js = array(); echo "<td><select name=\"type\" id=\"type\" onchange=\"checkLengths(document.getElementById('type').value,'');\">\n"; while (!$types->EOF) { $typname = $types->fields['typname']; $types_for_js[] = $typname; echo "\t<option value=\"", htmlspecialchars($typname), "\"", $typname == $_REQUEST['type'] ? ' selected="selected"' : '', ">", $misc->printVal($typname), "</option>\n"; $types->moveNext(); } echo "</select></td>\n"; // Output array type selector echo "<td><select name=\"array\">\n"; echo "\t<option value=\"\"", $_REQUEST['array'] == '' ? ' selected="selected"' : '', "></option>\n"; echo "\t<option value=\"[]\"", $_REQUEST['array'] == '[]' ? ' selected="selected"' : '', ">[ ]</option>\n"; echo "</select></td>\n"; $predefined_size_types = array_intersect($data->predefined_size_types, $types_for_js); foreach ($predefined_size_types as $value) { $escaped_predef_types[] = "'{$value}'"; } echo "<td><input name=\"length\" id=\"lengths\" size=\"8\" value=\"", htmlspecialchars($_REQUEST['length']), "\" /></td>\n"; } else { // Otherwise draw the read-only type name echo "<td>", $misc->printVal($data->formatType($column->fields['type'], $column->fields['atttypmod'])), "</td>\n"; } echo "<td><input type=\"checkbox\" name=\"notnull\"", isset($_REQUEST['notnull']) ? ' checked="checked"' : '', " /></td>\n"; echo "<td><input name=\"default\" size=\"20\" value=\"", htmlspecialchars($_REQUEST['default']), "\" /></td>\n"; echo "<td><input name=\"comment\" size=\"40\" value=\"", htmlspecialchars($_REQUEST['comment']), "\" /></td></tr>\n"; echo "</table>\n"; echo "<p><input type=\"hidden\" name=\"action\" value=\"properties\" />\n"; echo "<input type=\"hidden\" name=\"stage\" value=\"2\" />\n"; echo $misc->form; echo "<input type=\"hidden\" name=\"table\" value=\"", htmlspecialchars($_REQUEST['table']), "\" />\n"; echo "<input type=\"hidden\" name=\"column\" value=\"", htmlspecialchars($_REQUEST['column']), "\" />\n"; echo "<input type=\"hidden\" name=\"olddefault\" value=\"", htmlspecialchars($_REQUEST['olddefault']), "\" />\n"; if ($column->fields['attnotnull']) { echo "<input type=\"hidden\" name=\"oldnotnull\" value=\"on\" />\n"; } echo "<input type=\"hidden\" name=\"oldtype\" value=\"", htmlspecialchars($data->formatType($column->fields['type'], $column->fields['atttypmod'])), "\" />\n"; // Add hidden variables to suppress error notices if we don't support altering column type if (!$data->hasAlterColumnType()) { echo "<input type=\"hidden\" name=\"type\" value=\"", htmlspecialchars($_REQUEST['type']), "\" />\n"; echo "<input type=\"hidden\" name=\"length\" value=\"", htmlspecialchars($_REQUEST['length']), "\" />\n"; echo "<input type=\"hidden\" name=\"array\" value=\"", htmlspecialchars($_REQUEST['array']), "\" />\n"; } echo "<input type=\"submit\" value=\"{$lang['stralter']}\" />\n"; echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n"; echo "</form>\n"; echo "<script type=\"text/javascript\">predefined_lengths = new Array(" . implode(",", $escaped_predef_types) . ");checkLengths(document.getElementById('type').value,'');</script>\n"; break; case 2: // Check inputs if (trim($_REQUEST['field']) == '') { $_REQUEST['stage'] = 1; doAlter($lang['strcolneedsname']); return; } if (!isset($_REQUEST['length'])) { $_REQUEST['length'] = ''; } $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; doAlter($lang['strcolumnalteredbad']); return; } break; default: echo "<p>{$lang['strinvalidparam']}</p>\n"; } }
/** * Grant permissions on an object to a user * @param $confirm To show entry screen * @param $mode 'grant' or 'revoke' * @param $msg (optional) A message to show */ function doAlter($confirm, $mode, $msg = '') { global $data, $misc; global $lang; if (!isset($_REQUEST['username'])) { $_REQUEST['username'] = array(); } if (!isset($_REQUEST['groupname'])) { $_REQUEST['groupname'] = array(); } if (!isset($_REQUEST['privilege'])) { $_REQUEST['privilege'] = array(); } if ($confirm) { // Get users from the database $users = $data->getUsers(); // Get groups from the database $groups = $data->getGroups(); $misc->printTrail($_REQUEST['subject']); switch ($mode) { case 'grant': $misc->printTitle($lang['strgrant'], 'pg.privilege.grant'); break; case 'revoke': $misc->printTitle($lang['strrevoke'], 'pg.privilege.revoke'); break; } $misc->printMsg($msg); echo "<form action=\"privileges.php\" method=\"post\">\n"; echo "<table>\n"; echo "<tr><th class=\"data left\">{$lang['strusers']}</th>\n"; echo "<td class=\"data1\"><select name=\"username[]\" multiple=\"multiple\" size=\"", min(6, $users->recordCount()), "\">\n"; while (!$users->EOF) { $uname = htmlspecialchars($users->fields['usename']); echo "<option value=\"{$uname}\"", in_array($users->fields['usename'], $_REQUEST['username']) ? ' selected="selected"' : '', ">{$uname}</option>\n"; $users->moveNext(); } echo "</select></td></tr>\n"; echo "<tr><th class=\"data left\">{$lang['strgroups']}</th>\n"; echo "<td class=\"data1\">\n"; echo "<input type=\"checkbox\" id=\"public\" name=\"public\"", isset($_REQUEST['public']) ? ' checked="checked"' : '', " /><label for=\"public\">PUBLIC</label>\n"; // Only show groups if there are groups! if ($groups->recordCount() > 0) { echo "<br /><select name=\"groupname[]\" multiple=\"multiple\" size=\"", min(6, $groups->recordCount()), "\">\n"; while (!$groups->EOF) { $gname = htmlspecialchars($groups->fields['groname']); echo "<option value=\"{$gname}\"", in_array($groups->fields['groname'], $_REQUEST['groupname']) ? ' selected="selected"' : '', ">{$gname}</option>\n"; $groups->moveNext(); } echo "</select>\n"; } echo "</td></tr>\n"; echo "<tr><th class=\"data left required\">{$lang['strprivileges']}</th>\n"; echo "<td class=\"data1\">\n"; foreach ($data->privlist[$_REQUEST['subject']] as $v) { $v = htmlspecialchars($v); echo "<input type=\"checkbox\" id=\"privilege[{$v}]\" name=\"privilege[{$v}]\"", isset($_REQUEST['privilege'][$v]) ? ' checked="checked"' : '', " /><label for=\"privilege[{$v}]\">{$v}</label><br />\n"; } echo "</td></tr>\n"; // Grant option if ($data->hasGrantOption()) { echo "<tr><th class=\"data left\">{$lang['stroptions']}</th>\n"; echo "<td class=\"data1\">\n"; if ($mode == 'grant') { echo "<input type=\"checkbox\" id=\"grantoption\" name=\"grantoption\"", isset($_REQUEST['grantoption']) ? ' checked="checked"' : '', " /><label for=\"grantoption\">GRANT OPTION</label>\n"; } elseif ($mode == 'revoke') { echo "<input type=\"checkbox\" id=\"grantoption\" name=\"grantoption\"", isset($_REQUEST['grantoption']) ? ' checked="checked"' : '', " /><label for=\"grantoption\">GRANT OPTION FOR</label><br />\n"; echo "<input type=\"checkbox\" id=\"cascade\" name=\"cascade\"", isset($_REQUEST['cascade']) ? ' checked="checked"' : '', " /><label for=\"cascade\">CASCADE</label><br />\n"; } echo "</td></tr>\n"; } echo "</table>\n"; echo "<p><input type=\"hidden\" name=\"action\" value=\"save\" />\n"; echo "<input type=\"hidden\" name=\"mode\" value=\"", htmlspecialchars($mode), "\" />\n"; echo "<input type=\"hidden\" name=\"subject\" value=\"", htmlspecialchars($_REQUEST['subject']), "\" />\n"; if (isset($_REQUEST[$_REQUEST['subject'] . '_oid'])) { echo "<input type=\"hidden\" name=\"", htmlspecialchars($_REQUEST['subject'] . '_oid'), "\" value=\"", htmlspecialchars($_REQUEST[$_REQUEST['subject'] . '_oid']), "\" />\n"; } echo "<input type=\"hidden\" name=\"", htmlspecialchars($_REQUEST['subject']), "\" value=\"", htmlspecialchars($_REQUEST[$_REQUEST['subject']]), "\" />\n"; if ($_REQUEST['subject'] == 'column') { echo "<input type=\"hidden\" name=\"table\" value=\"", htmlspecialchars($_REQUEST['table']), "\" />\n"; } echo $misc->form; if ($mode == 'grant') { echo "<input type=\"submit\" name=\"grant\" value=\"{$lang['strgrant']}\" />\n"; } elseif ($mode == 'revoke') { echo "<input type=\"submit\" name=\"revoke\" value=\"{$lang['strrevoke']}\" />\n"; } echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>"; echo "</form>\n"; } else { // Determine whether object should be ref'd by name or oid. if (isset($_REQUEST[$_REQUEST['subject'] . '_oid'])) { $object = $_REQUEST[$_REQUEST['subject'] . '_oid']; } else { $object = $_REQUEST[$_REQUEST['subject']]; } if (isset($_REQUEST['table'])) { $table = $_REQUEST['table']; } else { $table = null; } $status = $data->setPrivileges($mode == 'grant' ? 'GRANT' : 'REVOKE', $_REQUEST['subject'], $object, isset($_REQUEST['public']), $_REQUEST['username'], $_REQUEST['groupname'], array_keys($_REQUEST['privilege']), isset($_REQUEST['grantoption']), isset($_REQUEST['cascade']), $table); if ($status == 0) { doDefault($lang['strgranted']); } elseif ($status == -3 || $status == -4) { doAlter(true, $_REQUEST['mode'], $lang['strgrantbad']); } else { doAlter(true, $_REQUEST['mode'], $lang['strgrantfailed']); } } }
/** * Function to save after altering an aggregate */ function doSaveAlter() { global $data, $lang; // Check inputs if (trim($_REQUEST['aggrname']) == '') { doAlter($lang['straggrneedsname']); return; } $status = $data->alterAggregate($_REQUEST['aggrname'], $_REQUEST['aggrtype'], $_REQUEST['aggrowner'], $_REQUEST['aggrschema'], $_REQUEST['aggrcomment'], $_REQUEST['newaggrname'], $_REQUEST['newaggrowner'], $_REQUEST['newaggrschema'], $_REQUEST['newaggrcomment']); if ($status == 0) { doDefault($lang['straggraltered']); } else { doAlter($lang['straggralteredbad']); return; } }
/** * Function to save after editing a role */ function doSaveAlter() { global $data, $lang; if (!isset($_POST['memberof'])) { $_POST['memberof'] = array(); } if (!isset($_POST['members'])) { $_POST['members'] = array(); } if (!isset($_POST['adminmembers'])) { $_POST['adminmembers'] = array(); } // Check name and password if (isset($_POST['formNewRoleName']) && $_POST['formNewRoleName'] == '') { doAlter($lang['strroleneedsname']); } else { if ($_POST['formPassword'] != $_POST['formConfirm']) { doAlter($lang['strpasswordconfirm']); } else { if (isset($_POST['formNewRoleName'])) { $status = $data->setRenameRole($_POST['rolename'], $_POST['formPassword'], isset($_POST['formSuper']), isset($_POST['formCreateDB']), isset($_POST['formCreateRole']), isset($_POST['formInherits']), isset($_POST['formCanLogin']), $_POST['formConnLimit'], $_POST['formExpires'], $_POST['memberof'], $_POST['members'], $_POST['adminmembers'], $_POST['memberofold'], $_POST['membersold'], $_POST['adminmembersold'], $_POST['formNewRoleName']); } else { $status = $data->setRole($_POST['rolename'], $_POST['formPassword'], isset($_POST['formSuper']), isset($_POST['formCreateDB']), isset($_POST['formCreateRole']), isset($_POST['formInherits']), isset($_POST['formCanLogin']), $_POST['formConnLimit'], $_POST['formExpires'], $_POST['memberof'], $_POST['members'], $_POST['adminmembers'], $_POST['memberofold'], $_POST['membersold'], $_POST['adminmembersold']); } if ($status == 0) { doDefault($lang['strrolealtered']); } else { doAlter($lang['strrolealteredbad']); } } } }