tableName = &$_REQUEST['table']; } elseif (isset($_REQUEST['view'])) { $this->tableName = &$_REQUEST['view']; } elseif (isset($_REQUEST['matview'])) { $this->tableName = &$_REQUEST['matview']; } else { $this->halt($this->lang['strnotableprovided']); } $this->printHeader($this->headerTitle('', '', $this->tableName), null, true, 'header_select2.twig'); $this->printBody(); if (isset($_REQUEST['view']) || isset($_REQUEST['matview'])) { $this->doDefault(null, false); } else { switch ($this->action) { case 'properties': if (isset($_POST['cancel'])) { $this->doDefault(); } else { $this->doAlter(); } break; default: $this->doDefault(); break; } } $this->printFooter(); } /** * Show default list of columns in the table. * * @param string $msg message to display * @param bool $isTable tells if we're showing table properties */ public function doDefault($msg = '', $isTable = true) { if (!isset($_REQUEST['table']) || empty($_REQUEST['table'])) { $isTable = false; } $data = $this->misc->getDatabaseAccessor(); $attPre = function (&$rowdata) use ($data) { $rowdata->fields['+type'] = $data->formatType($rowdata->fields['type'], $rowdata->fields['atttypmod']); }; if (empty($_REQUEST['column'])) { $msg .= "
{$this->lang['strnoobjects']}"; } $this->printTrail('column'); //$this->printTitle($this->lang['strcolprop']); $this->printTabs('column', 'properties'); $this->printMsg($msg); if (!empty($_REQUEST['column'])) { // Get table $tdata = $data->getTable($this->tableName); //\Kint::dump($tdata); // Get columns $attrs = $data->getTableAttributes($this->tableName, $_REQUEST['column']); // Show comment if any if (null !== $attrs->fields['comment']) { echo '

', $this->misc->printVal($attrs->fields['comment']), '

'.PHP_EOL; } $this->prtrace('$isTable', $isTable); $column = [ 'column' => [ 'title' => $this->lang['strcolumn'], 'field' => Decorator::field('attname'), ], 'type' => [ 'title' => $this->lang['strtype'], 'field' => Decorator::field('+type'), ], ]; if ($isTable) { $column['notnull'] = [ 'title' => $this->lang['strnotnull'], 'field' => Decorator::field('attnotnull'), 'type' => 'bool', 'params' => ['true' => 'NOT NULL', 'false' => ''], ]; $column['default'] = [ 'title' => $this->lang['strdefault'], 'field' => Decorator::field('adsrc'), ]; } $actions = []; echo $this->printTable($attrs, $column, $actions, $this->table_place, $this->lang['strnodata'], $attPre); echo '
'.PHP_EOL; $f_attname = $_REQUEST['column']; $f_table = $this->tableName; $f_schema = $data->_schema; $data->fieldClean($f_attname); $data->fieldClean($f_table); $data->fieldClean($f_schema); if ($isTable) { $navlinks = [ 'browse' => [ 'attr' => [ 'href' => [ 'url' => 'display', 'method' => 'post', 'urlvars' => [ 'subject' => 'column', 'server' => $_REQUEST['server'], 'database' => $_REQUEST['database'], 'schema' => $_REQUEST['schema'], 'table' => $this->tableName, 'column' => $_REQUEST['column'], 'return' => 'column', 'f_attname' => $f_attname, 'f_table' => $f_table, 'f_schema' => $f_schema, ], ], ], 'content' => $this->lang['strbrowse'], ], 'alter' => [ 'attr' => [ 'href' => [ 'url' => 'colproperties', 'urlvars' => [ 'action' => 'properties', 'server' => $_REQUEST['server'], 'database' => $_REQUEST['database'], 'schema' => $_REQUEST['schema'], 'table' => $this->tableName, 'column' => $_REQUEST['column'], ], ], ], 'content' => $this->lang['stralter'], ], 'drop' => [ 'attr' => [ 'href' => [ 'url' => 'tblproperties', 'urlvars' => [ 'action' => 'confirm_drop', 'server' => $_REQUEST['server'], 'database' => $_REQUEST['database'], 'schema' => $_REQUEST['schema'], 'table' => $this->tableName, 'column' => $_REQUEST['column'], ], ], ], 'content' => $this->lang['strdrop'], ], ]; } else { // Browse link $navlinks = [ 'browse' => [ 'attr' => [ 'href' => [ 'url' => 'display', 'method' => 'post', 'urlvars' => [ 'subject' => 'column', 'server' => $_REQUEST['server'], 'database' => $_REQUEST['database'], 'schema' => $_REQUEST['schema'], 'view' => $this->tableName, 'column' => $_REQUEST['column'], 'return' => 'column', 'f_attname' => $f_attname, 'f_table' => $f_table, 'f_schema' => $f_schema, ], ], ], 'content' => $this->lang['strbrowse'], ], ]; } $this->printNavLinks($navlinks, $this->table_place, get_defined_vars()); } } /** * Displays a screen where they can alter a column. * * @param mixed $msg */ public function doAlter($msg = '') { $data = $this->misc->getDatabaseAccessor(); $this->coalesceArr($_REQUEST, 'stage', 1); $this->prtrace('$_REQUEST', $_REQUEST, 'msg', $msg); switch ($_REQUEST['stage']) { case 1: $this->printTrail('column'); $this->printTitle($this->lang['stralter'], 'pg.column.alter'); $this->printMsg($msg); echo ''; echo '
'.PHP_EOL; // Output table header echo ''.PHP_EOL; echo "".PHP_EOL; if ($data->hasAlterColumnType()) { echo "".PHP_EOL; echo "".PHP_EOL; } else { echo "".PHP_EOL; } echo "\n\n".PHP_EOL; $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 "'.PHP_EOL; // Column type $escaped_predef_types = []; // the JS escaped array elements if ($data->hasAlterColumnType()) { // Fetch all available types $types = $data->getTypes(true, false, true); $types_for_js = []; echo "'.PHP_EOL; // Output array type selector echo ''.PHP_EOL; $predefined_size_types = array_intersect($data->predefined_size_types, $types_for_js); foreach ($predefined_size_types as $value) { $escaped_predef_types[] = "'{$value}'"; } echo ''.PHP_EOL; } else { // Otherwise draw the read-only type name echo ''.PHP_EOL; } echo ''.PHP_EOL; echo ''.PHP_EOL; echo ''.PHP_EOL; echo '
{$this->lang['strname']}{$this->lang['strtype']}{$this->lang['strlength']}{$this->lang['strtype']}{$this->lang['strnotnull']}{$this->lang['strdefault']}{$this->lang['strcomment']}
_maxNameLen}\" value=\"", htmlspecialchars($_REQUEST['field']), '" />'.PHP_EOL; echo '', $this->misc->printVal($data->formatType($column->fields['type'], $column->fields['atttypmod'])), '
'.PHP_EOL; echo '

'.PHP_EOL; echo ''.PHP_EOL; echo $this->misc->form; echo ''.PHP_EOL; echo ''.PHP_EOL; echo ''.PHP_EOL; if ($column->fields['attnotnull']) { echo ''.PHP_EOL; } echo ''.PHP_EOL; // Add hidden variables to suppress error notices if we don't support altering column type if (!$data->hasAlterColumnType()) { echo ''.PHP_EOL; echo ''.PHP_EOL; echo ''.PHP_EOL; } echo "lang['stralter']}\" />".PHP_EOL; echo "lang['strcancel']}\" />

".PHP_EOL; echo '
'.PHP_EOL; echo '".PHP_EOL; break; case 2: // Check inputs if ('' == trim($_REQUEST['field'])) { $_REQUEST['stage'] = 1; $this->doAlter($this->lang['strcolneedsname']); return; } $this->coalesceArr($_REQUEST, 'length', ''); list($status, $sql) = $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'] ); $this->prtrace('status', $status, 'sql', $sql); if (0 == $status) { if ($_REQUEST['column'] != $_REQUEST['field']) { $_REQUEST['column'] = $_REQUEST['field']; $this->misc->setReloadBrowser(true); } $this->doDefault($sql."
{$this->lang['strcolumnaltered']}"); } else { $_REQUEST['stage'] = 1; $this->doAlter($sql."
{$this->lang['strcolumnalteredbad']}"); return; } break; default: echo "

{$this->lang['strinvalidparam']}

".PHP_EOL; } } }