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
;
21 use Symfony\Component\DependencyInjection\Definition
;
25 require_once ROOT_PATH
. 'libraries/common.inc.php';
27 $container = Container
::getDefaultContainer();
28 $container->set(Response
::class, Response
::getInstance());
30 /** @var Response $response */
31 $response = $container->get(Response
::class);
33 /** @var DatabaseInterface $dbi */
34 $dbi = $container->get(DatabaseInterface
::class);
36 $centralColumns = new CentralColumns($dbi);
37 /* Define dependencies for the concerned controller */
38 $dependency_definitions = [
39 'db' => $container->get('db'),
40 'centralColumns' => $centralColumns,
43 /** @var Definition $definition */
44 $definition = $containerBuilder->getDefinition(CentralColumnsController
::class);
46 static function (string $parameterName, $value) use ($definition) {
47 $definition->replaceArgument($parameterName, $value);
49 array_keys($dependency_definitions),
50 $dependency_definitions
53 /** @var CentralColumnsController $controller */
54 $controller = $containerBuilder->get(CentralColumnsController
::class);
56 if (isset($_POST['edit_save'])) {
57 echo $controller->editSave([
58 'col_name' => $_POST['col_name'] ??
null,
59 'orig_col_name' => $_POST['orig_col_name'] ??
null,
60 'col_default' => $_POST['col_default'] ??
null,
61 'col_default_sel' => $_POST['col_default_sel'] ??
null,
62 'col_extra' => $_POST['col_extra'] ??
null,
63 'col_isNull' => $_POST['col_isNull'] ??
null,
64 'col_length' => $_POST['col_length'] ??
null,
65 'col_attribute' => $_POST['col_attribute'] ??
null,
66 'col_type' => $_POST['col_type'] ??
null,
67 'collation' => $_POST['collation'] ??
null,
70 } elseif (isset($_POST['add_new_column'])) {
71 $tmp_msg = $controller->addNewColumn([
72 'col_name' => $_POST['col_name'] ??
null,
73 'col_default' => $_POST['col_default'] ??
null,
74 'col_default_sel' => $_POST['col_default_sel'] ??
null,
75 'col_extra' => $_POST['col_extra'] ??
null,
76 'col_isNull' => $_POST['col_isNull'] ??
null,
77 'col_length' => $_POST['col_length'] ??
null,
78 'col_attribute' => $_POST['col_attribute'] ??
null,
79 'col_type' => $_POST['col_type'] ??
null,
80 'collation' => $_POST['collation'] ??
null,
83 if (isset($_POST['populateColumns'])) {
84 $response->addHTML($controller->populateColumns([
85 'selectedTable' => $_POST['selectedTable'],
89 if (isset($_POST['getColumnList'])) {
90 $response->addJSON($controller->getColumnList([
91 'cur_table' => $_POST['cur_table'] ??
null,
95 if (isset($_POST['add_column'])) {
96 $tmp_msg = $controller->addColumn([
97 'table-select' => $_POST['table-select'] ??
null,
98 'column-select' => $_POST['column-select'] ??
null,
102 $header = $response->getHeader();
103 $scripts = $header->getScripts();
104 $scripts->addFile('vendor/jquery/jquery.uitablefilter.js');
105 $scripts->addFile('vendor/jquery/jquery.tablesorter.js');
106 $scripts->addFile('db_central_columns.js');
108 if (isset($_POST['edit_central_columns_page'])) {
109 $response->addHTML($controller->editPage([
110 'selected_fld' => $_POST['selected_fld'] ??
null,
111 'db' => $_POST['db'] ??
null,
115 if (isset($_POST['multi_edit_central_column_save'])) {
116 $message = $controller->updateMultipleColumn([
117 'db' => $_POST['db'] ??
null,
118 'orig_col_name' => $_POST['orig_col_name'] ??
null,
119 'field_name' => $_POST['field_name'] ??
null,
120 'field_default_type' => $_POST['field_default_type'] ??
null,
121 'field_default_value' => $_POST['field_default_value'] ??
null,
122 'field_length' => $_POST['field_length'] ??
null,
123 'field_attribute' => $_POST['field_attribute'] ??
null,
124 'field_type' => $_POST['field_type'] ??
null,
125 'field_collation' => $_POST['field_collation'] ??
null,
126 'field_null' => $_POST['field_null'] ??
null,
127 'col_extra' => $_POST['col_extra'] ??
null,
129 if (! is_bool($message)) {
130 $response->setRequestStatus(false);
131 $response->addJSON('message', $message);
134 if (isset($_POST['delete_save'])) {
135 $tmp_msg = $controller->deleteSave([
136 'db' => $_POST['db'] ??
null,
137 'col_name' => $_POST['col_name'] ??
null,
141 $response->addHTML($controller->index([
142 'pos' => $_POST['pos'] ??
null,
143 'total_rows' => $_POST['total_rows'] ??
null,
147 if (Core
::isValid($_POST['pos'], 'integer')) {
148 $pos = (int) $_POST['pos'];
150 $num_cols = $centralColumns->getColumnsCount(
153 (int) $GLOBALS['cfg']['MaxRows']
155 $message = Message
::success(
156 sprintf(__('Showing rows %1$s - %2$s.'), $pos +
1, $pos +
$num_cols)
158 if (isset($tmp_msg) && $tmp_msg !== true) {