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 // Add/Remove favorite tables using Ajax request.
20 if ($GLOBALS['is_ajax_request'] && ! empty($_REQUEST['favorite_table'])) {
21 PMA_addRemoveFavoriteTables($db);
25 $response = PMA_Response
::getInstance();
26 $header = $response->getHeader();
27 $scripts = $header->getScripts();
28 $scripts->addFile('db_structure.js');
29 $scripts->addFile('tbl_change.js');
30 $scripts->addFile('jquery/jquery-ui-timepicker-addon.js');
32 // Drops/deletes/etc. multiple tables if required
33 if ((!empty($_POST['submit_mult']) && isset($_POST['selected_tbl']))
34 ||
isset($_POST['mult_btn'])
36 $action = 'db_structure.php';
37 $err_url = 'db_structure.php' . PMA_URL_getCommon(array('db' => $db));
39 // see bug #2794840; in this case, code path is:
40 // db_structure.php -> libraries/mult_submits.inc.php -> sql.php
41 // -> db_structure.php and if we got an error on the multi submit,
42 // we must display it here and not call again mult_submits.inc.php
43 if (! isset($_POST['error']) ||
false === $_POST['error']) {
44 include 'libraries/mult_submits.inc.php';
46 if (empty($_POST['message'])) {
47 $_POST['message'] = PMA_Message
::success();
51 require 'libraries/db_common.inc.php';
52 $url_query .= '&goto=db_structure.php';
54 // Gets the database structure
55 $sub_part = '_structure';
56 require 'libraries/db_info.inc.php';
58 // If there is an Ajax request for real row count of a table.
59 if ($GLOBALS['is_ajax_request']
60 && isset($_REQUEST['real_row_count'])
61 && $_REQUEST['real_row_count'] == true
63 PMA_handleRealRowCountRequest();
68 include_once 'libraries/replication.inc.php';
70 $GLOBALS['replication_info']['slave']['status'] = false;
73 require_once 'libraries/bookmark.lib.php';
75 require_once 'libraries/mysql_charsets.inc.php';
76 $db_collation = PMA_getDbCollation($db);
78 $titles = PMA_Util
::buildActionTitles();
82 if ($num_tables == 0) {
84 PMA_message
::notice(__('No tables found in database.'))
86 PMA_possiblyShowCreateTableDialog($db, $db_is_system_schema, $response);
91 // 2. Shows table informations
94 * Displays the tables list
96 $response->addHTML('<div id="tableslistcontainer">');
101 // Add the sort options if they exists
102 if (isset($_REQUEST['sort'])) {
103 $_url_params['sort'] = $_REQUEST['sort'];
106 if (isset($_REQUEST['sort_order'])) {
107 $_url_params['sort_order'] = $_REQUEST['sort_order'];
111 PMA_Util
::getListNavigator(
112 $total_num_tables, $pos, $_url_params, 'db_structure.php',
113 'frame_content', $GLOBALS['cfg']['MaxTableList']
119 '<form method="post" action="db_structure.php" '
120 . 'name="tablesForm" id="tablesForm">'
123 $response->addHTML(PMA_URL_getHiddenInputs($db));
127 $db_is_system_schema, $GLOBALS['replication_info']['slave']['status']
131 $i = $sum_entries = 0;
132 $overhead_check = '';
133 $create_time_all = '';
134 $update_time_all = '';
135 $check_time_all = '';
136 $num_columns = $cfg['PropertiesNumColumns'] > 1
137 ?
ceil($num_tables / $cfg['PropertiesNumColumns']) +
1
140 $sum_size = (double) 0;
141 $overhead_size = (double) 0;
143 $hidden_fields = array();
145 // Instance of PMA_RecentFavoriteTable class.
146 $fav_instance = PMA_RecentFavoriteTable
::getInstance('favorite');
147 foreach ($tables as $keyname => $current_table) {
148 // Get valid statistics whatever is the table type
152 $already_favorite = false;
155 $table_is_view = false;
156 $table_encoded = urlencode($current_table['TABLE_NAME']);
157 // Sets parameters for links
158 $tbl_url_query = $url_query . '&table=' . $table_encoded;
159 // do not list the previous table's size info for a view
161 list($current_table, $formatted_size, $unit, $formatted_overhead,
162 $overhead_unit, $overhead_size, $table_is_view, $sum_size)
163 = PMA_getStuffForEngineTypeTable(
164 $current_table, $db_is_system_schema,
165 $is_show_stats, $table_is_view, $sum_size, $overhead_size
168 if (! PMA_Table
::isMerge($db, $current_table['TABLE_NAME'])) {
169 $sum_entries +
= $current_table['TABLE_ROWS'];
172 if (isset($current_table['Collation'])) {
173 $collation = '<dfn title="'
174 . PMA_getCollationDescr($current_table['Collation']) . '">'
175 . $current_table['Collation'] . '</dfn>';
180 if ($is_show_stats) {
181 if ($formatted_overhead != '') {
182 $overhead = '<a href="tbl_structure.php'
183 . $tbl_url_query . '#showusage">'
184 . '<span>' . $formatted_overhead . '</span>'
185 . '<span class="unit">' . $overhead_unit . '</span>'
188 "markAllRows('row_tbl_" . ($i +
1) . "');";
196 if ($GLOBALS['cfg']['ShowDbStructureCreation']) {
197 list($create_time, $create_time_all) = PMA_getTimeForCreateUpdateCheck(
198 $current_table, 'Create_time', $create_time_all
202 if ($GLOBALS['cfg']['ShowDbStructureLastUpdate']) {
203 // $showtable might already be set from ShowDbStructureCreation, see above
204 list($update_time, $update_time_all) = PMA_getTimeForCreateUpdateCheck(
205 $current_table, 'Update_time', $update_time_all
209 if ($GLOBALS['cfg']['ShowDbStructureLastCheck']) {
210 // $showtable might already be set from ShowDbStructureCreation, see above
211 list($check_time, $check_time_all) = PMA_getTimeForCreateUpdateCheck(
212 $current_table, 'Check_time', $check_time_all
216 list($alias, $truename) = PMA_getAliasAndTrueName(
217 $tooltip_aliasname, $current_table, $tooltip_truename
223 if ($table_is_view) {
224 $hidden_fields[] = '<input type="hidden" name="views[]" value="'
225 . htmlspecialchars($current_table['TABLE_NAME']) . '" />';
229 * Always activate links for Browse, Search and Empty, even if
230 * the icons are greyed, because
231 * 1. for views, we don't know the number of rows at this point
232 * 2. for tables, another source could have populated them since the
235 * I could have used the PHP ternary conditional operator but I find
236 * the code easier to read without this operator.
238 list($browse_table, $search_table, $browse_table_label,
239 $empty_table, $tracking_icon
240 ) = PMA_getHtmlForActionLinks(
241 $current_table, $table_is_view, $tbl_url_query,
242 $titles, $truename, $db_is_system_schema, $url_query
245 if (! $db_is_system_schema) {
246 list($drop_query, $drop_message)
247 = PMA_getTableDropQueryAndMessage($table_is_view, $current_table);
251 && $num_tables > $num_columns
252 && ($row_count %
$num_columns) == 0
258 '</tr></tbody></table>'
262 PMA_tableHeader(false, $GLOBALS['replication_info']['slave']['status'])
266 list($do, $ignored) = PMA_getServerSlaveStatus(
267 $GLOBALS['replication_info']['slave']['status'], $truename
269 // Handle favorite table list. ----START----
270 $already_favorite = PMA_checkFavoriteTable($db, $current_table['TABLE_NAME']);
272 if (isset($_REQUEST['remove_favorite'])) {
273 if ($already_favorite) {
274 // If already in favorite list, remove it.
275 $favorite_table = $_REQUEST['favorite_table'];
276 $fav_instance->remove($db, $favorite_table);
280 if (isset($_REQUEST['add_favorite'])) {
281 if (!$already_favorite) {
282 // Otherwise add to favorite list.
283 $favorite_table = $_REQUEST['favorite_table'];
284 $fav_instance->add($db, $favorite_table);
286 } // Handle favorite table list. ----ENDS----
288 list($html_output, $odd_row, $approx_rows) = PMA_getHtmlForStructureTableRow(
289 $i, $odd_row, $table_is_view, $current_table,
290 $browse_table_label, $tracking_icon,
291 $GLOBALS['replication_info']['slave']['status'],
292 $browse_table, $tbl_url_query, $search_table, $db_is_system_schema,
293 $titles, $empty_table, $drop_query, $drop_message, $collation,
294 $formatted_size, $unit, $overhead,
295 (isset ($create_time) ?
$create_time : ''),
296 (isset ($update_time) ?
$update_time : ''),
297 (isset ($check_time) ?
$check_time : ''),
298 $is_show_stats, $ignored, $do, $colspan_for_structure
300 $response->addHTML($html_output);
305 $response->addHTML('</tbody>');
307 PMA_getHtmlBodyForTableSummary(
308 $num_tables, $GLOBALS['replication_info']['slave']['status'],
309 $db_is_system_schema, $sum_entries, $db_collation, $is_show_stats, $sum_size,
310 $overhead_size, $create_time_all, $update_time_all, $check_time_all,
311 isset($approx_rows) ?
$approx_rows : false
314 $response->addHTML('</table>');
317 PMA_getHtmlForCheckAllTables(
318 $pmaThemeImage, $text_dir, $overhead_check,
319 $db_is_system_schema, $hidden_fields
322 $response->addHTML('</form>'); //end of form
324 // display again the table list navigator
326 PMA_Util
::getListNavigator(
327 $total_num_tables, $pos, $_url_params, 'db_structure.php',
328 'frame_content', $GLOBALS['cfg']['MaxTableList']
332 $response->addHTML('</div><hr />');
335 * Work on the database
338 /* Printable view of a table */
340 PMA_getHtmlForTablePrintViewLink($url_query)
341 . PMA_getHtmlForDataDictionaryLink($url_query)
344 PMA_possiblyShowCreateTableDialog($db, $db_is_system_schema, $response);