db_central_columns.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * Central Columns view/edit
  5. *
  6. * @package PhpMyAdmin
  7. */
  8. use PhpMyAdmin\CentralColumns;
  9. use PhpMyAdmin\Core;
  10. use PhpMyAdmin\Message;
  11. use PhpMyAdmin\Response;
  12. use PhpMyAdmin\Url;
  13. /**
  14. * Gets some core libraries
  15. */
  16. require_once 'libraries/common.inc.php';
  17. $centralColumns = new CentralColumns($GLOBALS['dbi']);
  18. if (isset($_POST['edit_save']) || isset($_POST['add_new_column'])) {
  19. $col_name = $_POST['col_name'];
  20. if (isset($_POST['edit_save'])) {
  21. $orig_col_name = $_POST['orig_col_name'];
  22. }
  23. $col_default = $_POST['col_default'];
  24. if ($col_default == 'NONE' && $_POST['col_default_sel'] != 'USER_DEFINED') {
  25. $col_default = "";
  26. }
  27. $col_extra = isset($_POST['col_extra']) ? $_POST['col_extra'] : '';
  28. $col_isNull = isset($_POST['col_isNull'])?1:0;
  29. $col_length = $_POST['col_length'];
  30. $col_attribute = $_POST['col_attribute'];
  31. $col_type = $_POST['col_type'];
  32. $collation = $_POST['collation'];
  33. if (isset($orig_col_name) && $orig_col_name) {
  34. echo $centralColumns->updateOneColumn(
  35. $db, $orig_col_name, $col_name, $col_type, $col_attribute,
  36. $col_length, $col_isNull, $collation, $col_extra, $col_default
  37. );
  38. exit;
  39. } else {
  40. $tmp_msg = $centralColumns->updateOneColumn(
  41. $db, "", $col_name, $col_type, $col_attribute,
  42. $col_length, $col_isNull, $collation, $col_extra, $col_default
  43. );
  44. }
  45. }
  46. if (isset($_POST['populateColumns'])) {
  47. $selected_tbl = $_POST['selectedTable'];
  48. echo $centralColumns->getHtmlForColumnDropdown(
  49. $db,
  50. $selected_tbl
  51. );
  52. exit;
  53. }
  54. if (isset($_POST['getColumnList'])) {
  55. echo $centralColumns->getListRaw(
  56. $db,
  57. $_POST['cur_table']
  58. );
  59. exit;
  60. }
  61. if (isset($_POST['add_column'])) {
  62. $selected_col = array();
  63. $selected_tbl = $_POST['table-select'];
  64. $selected_col[] = $_POST['column-select'];
  65. $tmp_msg = $centralColumns->syncUniqueColumns(
  66. $selected_col,
  67. false,
  68. $selected_tbl
  69. );
  70. }
  71. $response = Response::getInstance();
  72. $header = $response->getHeader();
  73. $scripts = $header->getScripts();
  74. $scripts->addFile('vendor/jquery/jquery.uitablefilter.js');
  75. $scripts->addFile('vendor/jquery/jquery.tablesorter.js');
  76. $scripts->addFile('db_central_columns.js');
  77. $cfgCentralColumns = $centralColumns->getParams();
  78. $pmadb = $cfgCentralColumns['db'];
  79. $pmatable = $cfgCentralColumns['table'];
  80. $max_rows = intval($GLOBALS['cfg']['MaxRows']);
  81. if (isset($_POST['edit_central_columns_page'])) {
  82. $selected_fld = $_POST['selected_fld'];
  83. $selected_db = $_POST['db'];
  84. $edit_central_column_page = $centralColumns->getHtmlForEditingPage(
  85. $selected_fld,
  86. $selected_db
  87. );
  88. $response->addHTML($edit_central_column_page);
  89. exit;
  90. }
  91. if (isset($_POST['multi_edit_central_column_save'])) {
  92. $message = $centralColumns->updateMultipleColumn();
  93. if (!is_bool($message)) {
  94. $response->setRequestStatus(false);
  95. $response->addJSON('message', $message);
  96. }
  97. }
  98. if (isset($_POST['delete_save'])) {
  99. $col_name = array();
  100. parse_str($_POST['col_name'], $col_name);
  101. $tmp_msg = $centralColumns->deleteColumnsFromList(
  102. $col_name['selected_fld'],
  103. false
  104. );
  105. }
  106. if (!empty($_POST['total_rows'])
  107. && Core::isValid($_POST['total_rows'], 'integer')
  108. ) {
  109. $total_rows = $_POST['total_rows'];
  110. } else {
  111. $total_rows = $centralColumns->getCount($db);
  112. }
  113. if (Core::isValid($_POST['pos'], 'integer')) {
  114. $pos = intval($_POST['pos']);
  115. } else {
  116. $pos = 0;
  117. }
  118. $addNewColumn = $centralColumns->getHtmlForAddNewColumn($db, $total_rows);
  119. $response->addHTML($addNewColumn);
  120. if ($total_rows <= 0) {
  121. $response->addHTML(
  122. '<fieldset>' . __(
  123. 'The central list of columns for the current database is empty.'
  124. ) . '</fieldset>'
  125. );
  126. $columnAdd = $centralColumns->getHtmlForAddColumn($total_rows, $pos, $db);
  127. $response->addHTML($columnAdd);
  128. exit;
  129. }
  130. $table_navigation_html = $centralColumns->getHtmlForTableNavigation(
  131. $total_rows,
  132. $pos,
  133. $db
  134. );
  135. $response->addHTML($table_navigation_html);
  136. $columnAdd = $centralColumns->getHtmlForAddColumn($total_rows, $pos, $db);
  137. $response->addHTML($columnAdd);
  138. $deleteRowForm = '<form method="post" id="del_form" action="db_central_columns.php">'
  139. . Url::getHiddenInputs(
  140. $db
  141. )
  142. . '<input id="del_col_name" type="hidden" name="col_name" value="">'
  143. . '<input type="hidden" name="pos" value="' . $pos . '">'
  144. . '<input type="hidden" name="delete_save" value="delete"></form>';
  145. $response->addHTML($deleteRowForm);
  146. $table_struct = '<div id="tableslistcontainer">'
  147. . '<form name="tableslistcontainer">'
  148. . '<table id="table_columns" class="tablesorter" '
  149. . 'class="data">';
  150. $response->addHTML($table_struct);
  151. $tableheader = $centralColumns->getTableHeader(
  152. 'column_heading', __('Click to sort.'), 2
  153. );
  154. $response->addHTML($tableheader);
  155. $result = $centralColumns->getColumnsList($db, $pos, $max_rows);
  156. $row_num = 0;
  157. foreach ($result as $row) {
  158. $tableHtmlRow = $centralColumns->getHtmlForTableRow(
  159. $row,
  160. $row_num,
  161. $db
  162. );
  163. $response->addHTML($tableHtmlRow);
  164. $row_num++;
  165. }
  166. $response->addHTML('</table>');
  167. $tablefooter = $centralColumns->getTableFooter($pmaThemeImage, $text_dir);
  168. $response->addHTML($tablefooter);
  169. $response->addHTML('</form></div>');
  170. $message = Message::success(
  171. sprintf(__('Showing rows %1$s - %2$s.'), ($pos + 1), ($pos + count($result)))
  172. );
  173. if (isset($tmp_msg) && $tmp_msg !== true) {
  174. $message = $tmp_msg;
  175. }