2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Database structure manipulation
12 require_once 'libraries/common.inc.php';
15 * Function implementations for this script
17 require_once 'libraries/structure.lib.php';
19 $response = PMA_Response
::getInstance();
20 $header = $response->getHeader();
21 $scripts = $header->getScripts();
22 $scripts->addFile('db_structure.js');
23 $scripts->addFile('tbl_change.js');
24 $scripts->addFile('jquery/jquery-ui-timepicker-addon.js');
26 // Drops/deletes/etc. multiple tables if required
27 if ((!empty($_POST['submit_mult']) && isset($_POST['selected_tbl']))
28 ||
isset($_POST['mult_btn'])
30 $action = 'db_structure.php';
31 $err_url = 'db_structure.php?'. PMA_URL_getCommon($db);
33 // see bug #2794840; in this case, code path is:
34 // db_structure.php -> libraries/mult_submits.inc.php -> sql.php
35 // -> db_structure.php and if we got an error on the multi submit,
36 // we must display it here and not call again mult_submits.inc.php
37 if (! isset($_POST['error']) ||
false === $_POST['error']) {
38 include 'libraries/mult_submits.inc.php';
40 if (empty($_POST['message'])) {
41 $_POST['message'] = PMA_Message
::success();
44 require 'libraries/db_common.inc.php';
45 $url_query .= '&goto=db_structure.php';
47 // Gets the database structure
48 $sub_part = '_structure';
49 require 'libraries/db_info.inc.php';
52 include_once 'libraries/replication.inc.php';
54 $server_slave_status = false;
57 require_once 'libraries/bookmark.lib.php';
59 require_once 'libraries/mysql_charsets.inc.php';
60 $db_collation = PMA_getDbCollation($db);
62 $titles = PMA_Util
::buildActionTitles();
66 if ($num_tables == 0) {
68 '<p>' . __('No tables found in database.') . '</p>' . "\n"
70 if (empty($db_is_information_schema)) {
72 include 'libraries/display_create_table.lib.php';
73 $content = ob_get_contents();
75 $response->addHTML($content);
77 } // end if (Create Table dialog)
82 // 2. Shows table informations
85 * Displays the tables list
87 $response->addHTML('<div id="tableslistcontainer">');
92 // Add the sort options if they exists
93 if (isset($_REQUEST['sort'])) {
94 $_url_params['sort'] = $_REQUEST['sort'];
97 if (isset($_REQUEST['sort_order'])) {
98 $_url_params['sort_order'] = $_REQUEST['sort_order'];
102 PMA_Util
::getListNavigator(
103 $total_num_tables, $pos, $_url_params, 'db_structure.php',
104 'frame_content', $GLOBALS['cfg']['MaxTableList']
110 '<form method="post" action="db_structure.php" '
111 . 'name="tablesForm" id="tablesForm">'
114 $response->addHTML(PMA_URL_getHiddenInputs($db));
117 PMA_tableHeader($db_is_information_schema, $server_slave_status)
120 $i = $sum_entries = 0;
121 $overhead_check = '';
122 $create_time_all = '';
123 $update_time_all = '';
124 $check_time_all = '';
125 $num_columns = $cfg['PropertiesNumColumns'] > 1
126 ?
ceil($num_tables / $cfg['PropertiesNumColumns']) +
1
129 $sum_size = (double) 0;
130 $overhead_size = (double) 0;
132 $hidden_fields = array();
134 $sum_row_count_pre = '';
136 foreach ($tables as $keyname => $current_table) {
137 // Get valid statistics whatever is the table type
143 $table_is_view = false;
144 $table_encoded = urlencode($current_table['TABLE_NAME']);
145 // Sets parameters for links
146 $tbl_url_query = $url_query . '&table=' . $table_encoded;
147 // do not list the previous table's size info for a view
149 list($current_table, $formatted_size, $unit, $formatted_overhead,
150 $overhead_unit, $overhead_size, $table_is_view, $sum_size)
151 = PMA_getStuffForEngineTypeTable(
152 $current_table, $db_is_information_schema,
153 $is_show_stats, $table_is_view, $sum_size, $overhead_size
156 if (! PMA_Table
::isMerge($db, $current_table['TABLE_NAME'])) {
157 $sum_entries +
= $current_table['TABLE_ROWS'];
160 if (isset($current_table['Collation'])) {
161 $collation = '<dfn title="'
162 . PMA_getCollationDescr($current_table['Collation']) . '">'
163 . $current_table['Collation'] . '</dfn>';
168 if ($is_show_stats) {
169 if ($formatted_overhead != '') {
170 $overhead = '<a href="tbl_structure.php?'
171 . $tbl_url_query . '#showusage">'
172 . '<span>' . $formatted_overhead . '</span>'
173 . '<span class="unit">' . $overhead_unit . '</span>'
176 "markAllRows('row_tbl_" . ($i +
1) . "');";
184 if ($GLOBALS['cfg']['ShowDbStructureCreation']) {
185 list($create_time, $create_time_all) = PMA_getTimeForCreateUpdateCheck(
186 $current_table, 'Create_time', $create_time_all
190 if ($GLOBALS['cfg']['ShowDbStructureLastUpdate']) {
191 // $showtable might already be set from ShowDbStructureCreation, see above
192 list($update_time, $update_time_all) = PMA_getTimeForCreateUpdateCheck(
193 $current_table, 'Update_time', $update_time_all
197 if ($GLOBALS['cfg']['ShowDbStructureLastCheck']) {
198 // $showtable might already be set from ShowDbStructureCreation, see above
199 list($check_time, $check_time_all) = PMA_getTimeForCreateUpdateCheck(
200 $current_table, 'Check_time', $check_time_all
204 list($alias, $truename) = PMA_getAliasAndTrueName(
205 $tooltip_aliasname, $current_table, $tooltip_truename
211 if ($table_is_view) {
212 $hidden_fields[] = '<input type="hidden" name="views[]" value="'
213 . htmlspecialchars($current_table['TABLE_NAME']) . '" />';
217 * Always activate links for Browse, Search and Empty, even if
218 * the icons are greyed, because
219 * 1. for views, we don't know the number of rows at this point
220 * 2. for tables, another source could have populated them since the
223 * I could have used the PHP ternary conditional operator but I find
224 * the code easier to read without this operator.
226 list($browse_table, $search_table, $browse_table_label, $empty_table,
227 $tracking_icon) = PMA_getHtmlForActionLinks(
228 $current_table, $table_is_view, $tbl_url_query,
229 $titles, $truename, $db_is_information_schema, $url_query
232 if (! $db_is_information_schema) {
233 list($drop_query, $drop_message)
234 = PMA_getTableDropQueryAndMessage($table_is_view, $current_table);
238 && $num_tables > $num_columns
239 && ($row_count %
$num_columns) == 0
245 '</tr></tbody></table>'
248 $response->addHTML(PMA_tableHeader(false, $server_slave_status));
251 list($do, $ignored) = PMA_getServerSlaveStatus(
252 $server_slave_status, $truename
255 list($html_output, $odd_row) = PMA_getHtmlForStructureTableRow(
256 $i, $odd_row, $table_is_view, $current_table,
257 $browse_table_label, $tracking_icon, $server_slave_status,
258 $browse_table, $tbl_url_query, $search_table, $db_is_information_schema,
259 $titles, $empty_table, $drop_query, $drop_message, $collation,
260 $formatted_size, $unit, $overhead,
261 (isset ($create_time) ?
$create_time : ''),
262 (isset ($update_time) ?
$update_time : ''),
263 (isset ($check_time) ?
$check_time : ''),
264 $is_show_stats, $ignored, $do, $colspan_for_structure
266 $response->addHTML($html_output);
271 $response->addHTML('</tbody>');
273 PMA_getHtmlBodyForTableSummary(
274 $num_tables, $server_slave_status, $db_is_information_schema, $sum_entries,
275 $db_collation, $is_show_stats, $sum_size, $overhead_size, $create_time_all,
276 $update_time_all, $check_time_all, $sum_row_count_pre
279 $response->addHTML('</table>');
282 PMA_getHtmlForCheckAllTables(
283 $pmaThemeImage, $text_dir, $overhead_check,
284 $db_is_information_schema, $hidden_fields
287 $response->addHTML('</form>'); //end of form
289 // display again the table list navigator
291 PMA_Util
::getListNavigator(
292 $total_num_tables, $pos, $_url_params, 'db_structure.php',
293 'frame_content', $GLOBALS['cfg']['MaxTableList']
297 $response->addHTML('</div><hr />');
300 * Work on the database
303 /* Printable view of a table */
305 PMA_getHtmlForTablePrintViewLink($url_query)
306 . PMA_getHtmlForDataDictionaryLink($url_query)
309 if (empty($db_is_information_schema)) {
311 include 'libraries/display_create_table.lib.php';
312 $content = ob_get_contents();
314 $response->addHTML($content);
315 } // end if (Create Table dialog)