db_central_columns.php 5.2 KB

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