2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Central Columns view/edit
8 declare(strict_types
=1);
10 if (! defined('ROOT_PATH')) {
11 define('ROOT_PATH', __DIR__
. DIRECTORY_SEPARATOR
);
14 use PhpMyAdmin\CentralColumns
;
15 use PhpMyAdmin\Controllers\Database\CentralColumnsController
;
17 use PhpMyAdmin\DatabaseInterface
;
18 use PhpMyAdmin\Di\Container
;
19 use PhpMyAdmin\Message
;
20 use PhpMyAdmin\Response
;
22 require_once ROOT_PATH
. 'libraries/common.inc.php';
24 $container = Container
::getDefaultContainer();
25 $container->set(Response
::class, Response
::getInstance());
27 /** @var Response $response */
28 $response = $container->get(Response
::class);
30 /** @var DatabaseInterface $dbi */
31 $dbi = $container->get(DatabaseInterface
::class);
33 $centralColumns = new CentralColumns($dbi);
35 $controller = new CentralColumnsController(
42 if (isset($_POST['edit_save'])) {
43 echo $controller->editSave([
44 'col_name' => $_POST['col_name'] ??
null,
45 'orig_col_name' => $_POST['orig_col_name'] ??
null,
46 'col_default' => $_POST['col_default'] ??
null,
47 'col_default_sel' => $_POST['col_default_sel'] ??
null,
48 'col_extra' => $_POST['col_extra'] ??
null,
49 'col_isNull' => $_POST['col_isNull'] ??
null,
50 'col_length' => $_POST['col_length'] ??
null,
51 'col_attribute' => $_POST['col_attribute'] ??
null,
52 'col_type' => $_POST['col_type'] ??
null,
53 'collation' => $_POST['collation'] ??
null,
56 } elseif (isset($_POST['add_new_column'])) {
57 $tmp_msg = $controller->addNewColumn([
58 'col_name' => $_POST['col_name'] ??
null,
59 'col_default' => $_POST['col_default'] ??
null,
60 'col_default_sel' => $_POST['col_default_sel'] ??
null,
61 'col_extra' => $_POST['col_extra'] ??
null,
62 'col_isNull' => $_POST['col_isNull'] ??
null,
63 'col_length' => $_POST['col_length'] ??
null,
64 'col_attribute' => $_POST['col_attribute'] ??
null,
65 'col_type' => $_POST['col_type'] ??
null,
66 'collation' => $_POST['collation'] ??
null,
69 if (isset($_POST['populateColumns'])) {
70 $response->addHTML($controller->populateColumns([
71 'selectedTable' => $_POST['selectedTable'],
75 if (isset($_POST['getColumnList'])) {
76 $response->addJSON($controller->getColumnList([
77 'cur_table' => $_POST['cur_table'] ??
null,
81 if (isset($_POST['add_column'])) {
82 $tmp_msg = $controller->addColumn([
83 'table-select' => $_POST['table-select'] ??
null,
84 'column-select' => $_POST['column-select'] ??
null,
88 $header = $response->getHeader();
89 $scripts = $header->getScripts();
90 $scripts->addFile('vendor/jquery/jquery.uitablefilter.js');
91 $scripts->addFile('vendor/jquery/jquery.tablesorter.js');
92 $scripts->addFile('db_central_columns.js');
94 if (isset($_POST['edit_central_columns_page'])) {
95 $response->addHTML($controller->editPage([
96 'selected_fld' => $_POST['selected_fld'] ??
null,
97 'db' => $_POST['db'] ??
null,
101 if (isset($_POST['multi_edit_central_column_save'])) {
102 $message = $controller->updateMultipleColumn([
103 'db' => $_POST['db'] ??
null,
104 'orig_col_name' => $_POST['orig_col_name'] ??
null,
105 'field_name' => $_POST['field_name'] ??
null,
106 'field_default_type' => $_POST['field_default_type'] ??
null,
107 'field_default_value' => $_POST['field_default_value'] ??
null,
108 'field_length' => $_POST['field_length'] ??
null,
109 'field_attribute' => $_POST['field_attribute'] ??
null,
110 'field_type' => $_POST['field_type'] ??
null,
111 'field_collation' => $_POST['field_collation'] ??
null,
112 'field_null' => $_POST['field_null'] ??
null,
113 'col_extra' => $_POST['col_extra'] ??
null,
115 if (! is_bool($message)) {
116 $response->setRequestStatus(false);
117 $response->addJSON('message', $message);
120 if (isset($_POST['delete_save'])) {
121 $tmp_msg = $controller->deleteSave([
122 'db' => $_POST['db'] ??
null,
123 'col_name' => $_POST['col_name'] ??
null,
127 $response->addHTML($controller->index([
128 'pos' => $_POST['pos'] ??
null,
129 'total_rows' => $_POST['total_rows'] ??
null,
133 if (Core
::isValid($_POST['pos'], 'integer')) {
134 $pos = (int) $_POST['pos'];
136 $num_cols = $centralColumns->getColumnsCount(
139 (int) $GLOBALS['cfg']['MaxRows']
141 $message = Message
::success(
142 sprintf(__('Showing rows %1$s - %2$s.'), $pos +
1, $pos +
$num_cols)
144 if (isset($tmp_msg) && $tmp_msg !== true) {