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"; } else echo "{$lang['strnodata']}
\n"; } function doExport($msg = '') { global $data, $misc; global $lang; // Determine whether or not the table has an object ID $hasID = $data->hasObjectID($_REQUEST['table']); $misc->printTrail('table'); $misc->printTabs('table','export'); $misc->printMsg($msg); 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"; } } 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"; 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"; } 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->printTreeXML($columns, $attrs); 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']['url'] .= 'query=' . urlencode("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'], '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']) .'" />'; break; case 'f': $str .= 'icon('ForeignKey') .'" alt="[fk]" title="'. htmlentities($c['consrc']) .'" />'; break; case 'u': $str .= 'icon('UniqueConstraint') .'" alt="[uniq]" title="'. htmlentities($c['consrc']) .'" />'; break; case 'c': $str .= 'icon('CheckConstraint') .'" alt="[check]" title="'. htmlentities($c['consrc']) .'" />'; } } return $str; } $return_url = urlencode("tblproperties.php?{$misc->href}&table=". urlencode($_REQUEST['table'])); $actions = array( 'browse' => array( 'title' => $lang['strbrowse'], 'url' => "display.php?{$misc->href}&subject=column&return_url={$return_url}&table=".urlencode($_REQUEST['table'])."&return_desc=" . urlencode($lang['strback']) . '&', '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'), ), ); $misc->printTable($attrs, $columns, $actions, null, 'attPre'); echo "