getDefaultWithOid(); if ($default_with_oids == 'off') $_REQUEST['withoutoids'] = 'on'; } if (!isset($_REQUEST['name'])) $_REQUEST['name'] = ''; if (!isset($_REQUEST['fields'])) $_REQUEST['fields'] = ''; if (!isset($_REQUEST['tblcomment'])) $_REQUEST['tblcomment'] = ''; if (!isset($_REQUEST['spcname'])) $_REQUEST['spcname'] = ''; switch ($_REQUEST['stage']) { case 1: // Fetch all tablespaces from the database if ($data->hasTablespaces()) $tablespaces = $data->getTablespaces(); $misc->printTrail('schema'); $misc->printTitle($lang['strcreatetable'], 'pg.table.create'); $misc->printMsg($msg); echo "
\n"; break; case 2: global $lang; // Check inputs $fields = trim($_REQUEST['fields']); if (trim($_REQUEST['name']) == '') { $_REQUEST['stage'] = 1; doCreate($lang['strtableneedsname']); return; } elseif ($fields == '' || !is_numeric($fields) || $fields != (int)$fields || $fields < 1) { $_REQUEST['stage'] = 1; doCreate($lang['strtableneedscols']); return; } $types = $data->getTypes(true, false, true); $types_for_js = array(); $misc->printTrail('schema'); $misc->printTitle($lang['strcreatetable'], 'pg.table.create'); $misc->printMsg($msg); echo ""; echo "\n"; break; case 3: global $data, $lang, $_reload_browser; if (!isset($_REQUEST['notnull'])) $_REQUEST['notnull'] = array(); if (!isset($_REQUEST['uniquekey'])) $_REQUEST['uniquekey'] = array(); if (!isset($_REQUEST['primarykey'])) $_REQUEST['primarykey'] = array(); if (!isset($_REQUEST['length'])) $_REQUEST['length'] = array(); // Default tablespace to null if it isn't set if (!isset($_REQUEST['spcname'])) $_REQUEST['spcname'] = null; // Check inputs $fields = trim($_REQUEST['fields']); if (trim($_REQUEST['name']) == '') { $_REQUEST['stage'] = 1; doCreate($lang['strtableneedsname']); return; } elseif ($fields == '' || !is_numeric($fields) || $fields != (int)$fields || $fields <= 0) { $_REQUEST['stage'] = 1; doCreate($lang['strtableneedscols']); return; } $status = $data->createTable($_REQUEST['name'], $_REQUEST['fields'], $_REQUEST['field'], $_REQUEST['type'], $_REQUEST['array'], $_REQUEST['length'], $_REQUEST['notnull'], $_REQUEST['default'], isset($_REQUEST['withoutoids']), $_REQUEST['colcomment'], $_REQUEST['tblcomment'], $_REQUEST['spcname'], $_REQUEST['uniquekey'], $_REQUEST['primarykey']); if ($status == 0) { $_reload_browser = true; doDefault($lang['strtablecreated']); } elseif ($status == -1) { $_REQUEST['stage'] = 2; doCreate($lang['strtableneedsfield']); return; } else { $_REQUEST['stage'] = 2; doCreate($lang['strtablecreatedbad']); return; } break; default: echo "{$lang['strinvalidparam']}
\n"; } } /** * Dsiplay a screen where user can create a table from an existing one. * We don't have to check if pg supports schema cause create table like * is available under pg 7.4+ which has schema. */ function doCreateLike($confirm, $msg = '') { global $data, $misc, $lang; if (!$confirm) { include_once('./classes/Gui.php'); if (!isset($_REQUEST['name'])) $_REQUEST['name'] = ''; if (!isset($_REQUEST['like'])) $_REQUEST['like'] = ''; if (!isset($_REQUEST['tablespace'])) $_REQUEST['tablespace'] = ''; $misc->printTrail('schema'); $misc->printTitle($lang['strcreatetable'], 'pg.table.create'); $misc->printMsg($msg); $tbltmp = $data->getTables(true); $tbltmp = $tbltmp->getArray(); $tables = array(); $tblsel = ''; foreach ($tbltmp as $a) { $data->fieldClean($a['nspname']); $data->fieldClean($a['relname']); $tables["\"{$a['nspname']}\".\"{$a['relname']}\""] = serialize(array('schema' => $a['nspname'], 'table' => $a['relname'])); if ($_REQUEST['like'] == $tables["\"{$a['nspname']}\".\"{$a['relname']}\""]) $tblsel = htmlspecialchars($tables["\"{$a['nspname']}\".\"{$a['relname']}\""]); } unset($tbltmp); echo "\n"; } else { global $_reload_browser; if (trim($_REQUEST['name']) == '') { doCreateLike(false, $lang['strtableneedsname']); return; } if (trim($_REQUEST['like']) == '') { doCreateLike(false, $lang['strtablelikeneedslike']); return; } if (!isset($_REQUEST['tablespace'])) $_REQUEST['tablespace'] = ''; $status = $data->createTableLike($_REQUEST['name'], unserialize($_REQUEST['like']), isset($_REQUEST['withdefaults']), isset($_REQUEST['withconstraints']), isset($_REQUEST['withindexes']), $_REQUEST['tablespace']); if ($status == 0) { $_reload_browser = true; doDefault($lang['strtablecreated']); } else { doCreateLike(false, $lang['strtablecreatedbad']); return; } } } /** * Ask for select parameters and perform select */ function doSelectRows($confirm, $msg = '') { global $data, $misc, $_no_output; global $lang; if ($confirm) { $misc->printTrail('table'); $misc->printTitle($lang['strselect'], 'pg.sql.select'); $misc->printMsg($msg); $attrs = $data->getTableAttributes($_REQUEST['table']); echo "\n"; } else { if (!isset($_POST['show'])) $_POST['show'] = array(); if (!isset($_POST['values'])) $_POST['values'] = array(); if (!isset($_POST['nulls'])) $_POST['nulls'] = array(); // Verify that they haven't supplied a value for unary operators foreach ($_POST['ops'] as $k => $v) { if ($data->selectOps[$v] == 'p' && $_POST['values'][$k] != '') { doSelectRows(true, $lang['strselectunary']); return; } } if (sizeof($_POST['show']) == 0) doSelectRows(true, $lang['strselectneedscol']); else { // Generate query SQL $query = $data->getSelectSQL($_REQUEST['table'], array_keys($_POST['show']), $_POST['values'], $_POST['ops']); $_REQUEST['query'] = $query; $_REQUEST['return_url'] = "tables.php?action=confselectrows&{$misc->href}&table={$_REQUEST['table']}"; $_REQUEST['return_desc'] = $lang['strback']; $_no_output = true; include('./display.php'); exit; } } } /** * Ask for insert parameters and then actually insert row */ function doInsertRow($confirm, $msg = '') { global $data, $misc, $conf; global $lang; if ($confirm) { $misc->printTrail('table'); $misc->printTitle($lang['strinsertrow'], 'pg.sql.insert'); $misc->printMsg($msg); $attrs = $data->getTableAttributes($_REQUEST['table']); if (($conf['autocomplete'] != 'disable')) { $fksprops = $misc->getAutocompleteFKProperties($_REQUEST['table']); if ($fksprops !== false) echo $fksprops['code']; } else $fksprops = false; echo "\n"; } else { if (!isset($_POST['values'])) $_POST['values'] = array(); if (!isset($_POST['nulls'])) $_POST['nulls'] = array(); $_POST['fields'] = unserialize(htmlspecialchars_decode($_POST['fields'], ENT_QUOTES)); if ($_SESSION['counter']++ == $_POST['protection_counter']) { $status = $data->insertRow($_POST['table'], $_POST['fields'], $_POST['values'], $_POST['nulls'], $_POST['format'], $_POST['types']); if ($status == 0) { if (isset($_POST['insert'])) doDefault($lang['strrowinserted']); else { $_REQUEST['values'] = array(); $_REQUEST['nulls'] = array(); doInsertRow(true, $lang['strrowinserted']); } } else doInsertRow(true, $lang['strrowinsertedbad']); } else doInsertRow(true, $lang['strrowduplicate']); } } /** * Show confirmation of empty and perform actual empty */ function doEmpty($confirm) { global $data, $misc; global $lang; if (empty($_REQUEST['table']) && empty($_REQUEST['ma'])) { doDefault($lang['strspecifytabletoempty']); exit(); } if ($confirm) { if (isset($_REQUEST['ma'])) { $misc->printTrail('schema'); $misc->printTitle($lang['strempty'],'pg.table.empty'); echo "\n"; } // END if confirm else { // Do Empty if (is_array($_REQUEST['table'])) { $msg=''; foreach($_REQUEST['table'] as $t) { $status = $data->emptyTable($t); if ($status == 0) $msg.= sprintf('%s: %s