Merge remote-tracking branch 'origin/master'
[phpmyadmin.git] / db_central_columns.php
blob41d58e707a5f7c4d5f4ffebf7029af35a3278901
1 <?php
3 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 /**
5 * Central Columns view/edit
7 * @package PhpMyAdmin
8 */
9 use PMA\libraries\URL;
11 /**
12 * Gets some core libraries
14 require_once 'libraries/common.inc.php';
15 require_once 'libraries/central_columns.lib.php';
17 if (isset($_POST['edit_save']) || isset($_POST['add_new_column'])) {
18 $col_name = $_POST['col_name'];
19 if (isset($_POST['edit_save'])) {
20 $orig_col_name = $_POST['orig_col_name'];
22 $col_default = $_POST['col_default'];
23 if ($col_default == 'NONE' && $_POST['col_default_sel'] != 'USER_DEFINED') {
24 $col_default = "";
26 $col_extra = isset($_POST['col_extra']) ? $_POST['col_extra'] : '';
27 $col_isNull = isset($_POST['col_isNull'])?1:0;
28 $col_length = $_POST['col_length'];
29 $col_attribute = $_POST['col_attribute'];
30 $col_type = $_POST['col_type'];
31 $collation = $_POST['collation'];
32 if (isset($orig_col_name) && $orig_col_name) {
33 echo PMA_updateOneColumn(
34 $db, $orig_col_name, $col_name, $col_type, $col_attribute,
35 $col_length, $col_isNull, $collation, $col_extra, $col_default
37 exit;
38 } else {
39 $tmp_msg = PMA_updateOneColumn(
40 $db, "", $col_name, $col_type, $col_attribute,
41 $col_length, $col_isNull, $collation, $col_extra, $col_default
45 if (isset($_POST['populateColumns'])) {
46 $selected_tbl = $_POST['selectedTable'];
47 echo PMA_getHTMLforColumnDropdown($db, $selected_tbl);
48 exit;
50 if (isset($_POST['getColumnList'])) {
51 echo PMA_getCentralColumnsListRaw($db, $_POST['cur_table']);
52 exit;
54 if (isset($_POST['add_column'])) {
55 $selected_col = array();
56 $selected_tbl = $_POST['table-select'];
57 $selected_col[] = $_POST['column-select'];
58 $tmp_msg = PMA_syncUniqueColumns($selected_col, false, $selected_tbl);
60 $response = PMA\libraries\Response::getInstance();
61 $header = $response->getHeader();
62 $scripts = $header->getScripts();
63 $scripts->addFile('jquery/jquery.uitablefilter.js');
64 $scripts->addFile('jquery/jquery.tablesorter.js');
65 $scripts->addFile('db_central_columns.js');
66 $cfgCentralColumns = PMA_centralColumnsGetParams();
67 $pmadb = $cfgCentralColumns['db'];
68 $pmatable = $cfgCentralColumns['table'];
69 $max_rows = intval($GLOBALS['cfg']['MaxRows']);
71 if (isset($_REQUEST['edit_central_columns_page'])) {
72 $selected_fld = $_REQUEST['selected_fld'];
73 $selected_db = $_REQUEST['db'];
74 $edit_central_column_page = PMA_getHTMLforEditingPage(
75 $selected_fld, $selected_db
77 $response->addHTML($edit_central_column_page);
78 exit;
80 if (isset($_POST['multi_edit_central_column_save'])) {
81 $message = PMA_updateMultipleColumn();
82 if (!is_bool($message)) {
83 $response->setRequestStatus(false);
84 $response->addJSON('message', $message);
87 if (isset($_POST['delete_save'])) {
88 $col_name = array();
89 parse_str($_POST['col_name'], $col_name);
90 $tmp_msg = PMA_deleteColumnsFromList($col_name['selected_fld'], false);
92 if (isset($_REQUEST['total_rows']) && $_REQUEST['total_rows']) {
93 $total_rows = $_REQUEST['total_rows'];
94 } else {
95 $total_rows = PMA_getCentralColumnsCount($db);
97 if (PMA_isValid($_REQUEST['pos'], 'integer')) {
98 $pos = intval($_REQUEST['pos']);
99 } else {
100 $pos = 0;
102 $addNewColumn = PMA_getHTMLforAddNewColumn($db);
103 $response->addHTML($addNewColumn);
104 if ($total_rows <= 0) {
105 $response->addHTML(
106 '<fieldset>' . __(
107 'The central list of columns for the current database is empty.'
108 ) . '</fieldset>'
110 $columnAdd = PMA_getHTMLforAddCentralColumn($total_rows, $pos, $db);
111 $response->addHTML($columnAdd);
112 exit;
114 $table_navigation_html = PMA_getHTMLforTableNavigation($total_rows, $pos, $db);
115 $response->addHTML($table_navigation_html);
116 $columnAdd = PMA_getHTMLforAddCentralColumn($total_rows, $pos, $db);
117 $response->addHTML($columnAdd);
118 $deleteRowForm = '<form method="post" id="del_form" action="db_central_columns.php">'
119 . URL::getHiddenInputs(
122 . '<input id="del_col_name" type="hidden" name="col_name" value="">'
123 . '<input type="hidden" name="pos" value="' . $pos . '">'
124 . '<input type="hidden" name="delete_save" value="delete"></form>';
125 $response->addHTML($deleteRowForm);
126 $table_struct = '<div id="tableslistcontainer">'
127 . '<form name="tableslistcontainer">'
128 . '<table id="table_columns" class="tablesorter" '
129 . 'style="min-width:100%" class="data">';
130 $response->addHTML($table_struct);
131 $tableheader = PMA_getCentralColumnsTableHeader(
132 'column_heading', __('Click to sort.'), 2
134 $response->addHTML($tableheader);
135 $result = PMA_getColumnsList($db, $pos, $max_rows);
136 $row_num = 0;
137 foreach ($result as $row) {
138 $tableHtmlRow = PMA_getHTMLforCentralColumnsTableRow(
139 $row, $row_num, $db
141 $response->addHTML($tableHtmlRow);
142 $row_num++;
144 $response->addHTML('</table>');
145 $tablefooter = PMA_getCentralColumnsTableFooter($pmaThemeImage, $text_dir);
146 $response->addHTML($tablefooter);
147 $response->addHTML('</form></div>');
148 $message = PMA\libraries\Message::success(
149 sprintf(__('Showing rows %1$s - %2$s.'), ($pos + 1), ($pos + count($result)))
151 if (isset($tmp_msg) && $tmp_msg !== true) {
152 $message = $tmp_msg;