Translated using Weblate (Norwegian Bokmål)
[phpmyadmin.git] / db_structure.php
blobcdc787ee19ce9024c73ec3c8196260591e205dbf
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Database structure manipulation
6 * @package PhpMyAdmin
7 */
9 /**
12 require_once 'libraries/common.inc.php';
14 /**
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);
22 exit;
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'])
35 ) {
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 .= '&amp;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
62 ) {
63 PMA_handleRealRowCountRequest();
64 exit;
67 if (!PMA_DRIZZLE) {
68 include_once 'libraries/replication.inc.php';
69 } else {
70 $GLOBALS['replication_info']['slave']['status'] = false;
74 require_once 'libraries/config/page_settings.class.php';
75 PMA_PageSettings::showGroup('DbStructure');
77 require_once 'libraries/bookmark.lib.php';
79 require_once 'libraries/mysql_charsets.inc.php';
80 $db_collation = PMA_getDbCollation($db);
82 $titles = PMA_Util::buildActionTitles();
84 // 1. No tables
86 if ($num_tables == 0) {
87 $response->addHTML(
88 PMA_message::notice(__('No tables found in database.'))
90 PMA_possiblyShowCreateTableDialog($db, $db_is_system_schema, $response);
91 exit;
94 // else
95 // 2. Shows table informations
97 /**
98 * Displays the tables list
100 $response->addHTML('<div id="tableslistcontainer">');
101 $_url_params = array(
102 'pos' => $pos,
103 'db' => $db);
105 // Add the sort options if they exists
106 if (isset($_REQUEST['sort'])) {
107 $_url_params['sort'] = $_REQUEST['sort'];
110 if (isset($_REQUEST['sort_order'])) {
111 $_url_params['sort_order'] = $_REQUEST['sort_order'];
114 $response->addHTML(
115 PMA_Util::getListNavigator(
116 $total_num_tables, $pos, $_url_params, 'db_structure.php',
117 'frame_content', $GLOBALS['cfg']['MaxTableList']
121 // tables form
122 $response->addHTML(
123 '<form method="post" action="db_structure.php" '
124 . 'name="tablesForm" id="tablesForm">'
127 $response->addHTML(PMA_URL_getHiddenInputs($db));
129 $response->addHTML(
130 PMA_tableHeader(
131 $db_is_system_schema, $GLOBALS['replication_info']['slave']['status']
135 $i = $sum_entries = 0;
136 $overhead_check = '';
137 $create_time_all = '';
138 $update_time_all = '';
139 $check_time_all = '';
140 $num_columns = $cfg['PropertiesNumColumns'] > 1
141 ? ceil($num_tables / $cfg['PropertiesNumColumns']) + 1
142 : 0;
143 $row_count = 0;
144 $sum_size = (double) 0;
145 $overhead_size = (double) 0;
147 $hidden_fields = array();
148 $odd_row = true;
149 // Instance of PMA_RecentFavoriteTable class.
150 $fav_instance = PMA_RecentFavoriteTable::getInstance('favorite');
151 foreach ($tables as $keyname => $current_table) {
152 // Get valid statistics whatever is the table type
154 $drop_query = '';
155 $drop_message = '';
156 $already_favorite = false;
157 $overhead = '';
159 $table_is_view = false;
160 $table_encoded = urlencode($current_table['TABLE_NAME']);
161 // Sets parameters for links
162 $tbl_url_query = $url_query . '&amp;table=' . $table_encoded;
163 // do not list the previous table's size info for a view
165 list($current_table, $formatted_size, $unit, $formatted_overhead,
166 $overhead_unit, $overhead_size, $table_is_view, $sum_size)
167 = PMA_getStuffForEngineTypeTable(
168 $current_table, $db_is_system_schema,
169 $is_show_stats, $table_is_view, $sum_size, $overhead_size
172 if (! PMA_Table::isMerge($db, $current_table['TABLE_NAME'])) {
173 $sum_entries += $current_table['TABLE_ROWS'];
176 if (isset($current_table['Collation'])) {
177 $collation = '<dfn title="'
178 . PMA_getCollationDescr($current_table['Collation']) . '">'
179 . $current_table['Collation'] . '</dfn>';
180 } else {
181 $collation = '---';
184 if ($is_show_stats) {
185 if ($formatted_overhead != '') {
186 $overhead = '<a href="tbl_structure.php'
187 . $tbl_url_query . '#showusage">'
188 . '<span>' . $formatted_overhead . '</span>&nbsp;'
189 . '<span class="unit">' . $overhead_unit . '</span>'
190 . '</a>' . "\n";
191 $overhead_check .=
192 "markAllRows('row_tbl_" . ($i + 1) . "');";
193 } else {
194 $overhead = '-';
196 } // end if
198 unset($showtable);
200 if ($GLOBALS['cfg']['ShowDbStructureCreation']) {
201 list($create_time, $create_time_all) = PMA_getTimeForCreateUpdateCheck(
202 $current_table, 'Create_time', $create_time_all
206 if ($GLOBALS['cfg']['ShowDbStructureLastUpdate']) {
207 // $showtable might already be set from ShowDbStructureCreation, see above
208 list($update_time, $update_time_all) = PMA_getTimeForCreateUpdateCheck(
209 $current_table, 'Update_time', $update_time_all
213 if ($GLOBALS['cfg']['ShowDbStructureLastCheck']) {
214 // $showtable might already be set from ShowDbStructureCreation, see above
215 list($check_time, $check_time_all) = PMA_getTimeForCreateUpdateCheck(
216 $current_table, 'Check_time', $check_time_all
220 list($alias, $truename) = PMA_getAliasAndTrueName(
221 $tooltip_aliasname, $current_table, $tooltip_truename
224 $i++;
226 $row_count++;
227 if ($table_is_view) {
228 $hidden_fields[] = '<input type="hidden" name="views[]" value="'
229 . htmlspecialchars($current_table['TABLE_NAME']) . '" />';
233 * Always activate links for Browse, Search and Empty, even if
234 * the icons are greyed, because
235 * 1. for views, we don't know the number of rows at this point
236 * 2. for tables, another source could have populated them since the
237 * page was generated
239 * I could have used the PHP ternary conditional operator but I find
240 * the code easier to read without this operator.
242 list($browse_table, $search_table, $browse_table_label,
243 $empty_table, $tracking_icon
244 ) = PMA_getHtmlForActionLinks(
245 $current_table, $table_is_view, $tbl_url_query,
246 $titles, $truename, $db_is_system_schema, $url_query
249 if (! $db_is_system_schema) {
250 list($drop_query, $drop_message)
251 = PMA_getTableDropQueryAndMessage($table_is_view, $current_table);
254 if ($num_columns > 0
255 && $num_tables > $num_columns
256 && ($row_count % $num_columns) == 0
258 $row_count = 1;
259 $odd_row = true;
261 $response->addHTML(
262 '</tr></tbody></table>'
265 $response->addHTML(
266 PMA_tableHeader(false, $GLOBALS['replication_info']['slave']['status'])
270 list($do, $ignored) = PMA_getServerSlaveStatus(
271 $GLOBALS['replication_info']['slave']['status'], $truename
273 // Handle favorite table list. ----START----
274 $already_favorite = PMA_checkFavoriteTable($db, $current_table['TABLE_NAME']);
276 if (isset($_REQUEST['remove_favorite'])) {
277 if ($already_favorite) {
278 // If already in favorite list, remove it.
279 $favorite_table = $_REQUEST['favorite_table'];
280 $fav_instance->remove($db, $favorite_table);
284 if (isset($_REQUEST['add_favorite'])) {
285 if (!$already_favorite) {
286 // Otherwise add to favorite list.
287 $favorite_table = $_REQUEST['favorite_table'];
288 $fav_instance->add($db, $favorite_table);
290 } // Handle favorite table list. ----ENDS----
292 list($html_output, $odd_row, $approx_rows) = PMA_getHtmlForStructureTableRow(
293 $i, $odd_row, $table_is_view, $current_table,
294 $browse_table_label, $tracking_icon,
295 $GLOBALS['replication_info']['slave']['status'],
296 $browse_table, $tbl_url_query, $search_table, $db_is_system_schema,
297 $titles, $empty_table, $drop_query, $drop_message, $collation,
298 $formatted_size, $unit, $overhead,
299 (isset ($create_time) ? $create_time : ''),
300 (isset ($update_time) ? $update_time : ''),
301 (isset ($check_time) ? $check_time : ''),
302 $is_show_stats, $ignored, $do, $colspan_for_structure
304 $response->addHTML($html_output);
306 } // end foreach
308 // Show Summary
309 $response->addHTML('</tbody>');
310 $response->addHTML(
311 PMA_getHtmlBodyForTableSummary(
312 $num_tables, $GLOBALS['replication_info']['slave']['status'],
313 $db_is_system_schema, $sum_entries, $db_collation, $is_show_stats, $sum_size,
314 $overhead_size, $create_time_all, $update_time_all, $check_time_all,
315 isset($approx_rows) ? $approx_rows : false
318 $response->addHTML('</table>');
319 //check all
320 $response->addHTML(
321 PMA_getHtmlForCheckAllTables(
322 $pmaThemeImage, $text_dir, $overhead_check,
323 $db_is_system_schema, $hidden_fields
326 $response->addHTML('</form>'); //end of form
328 // display again the table list navigator
329 $response->addHTML(
330 PMA_Util::getListNavigator(
331 $total_num_tables, $pos, $_url_params, 'db_structure.php',
332 'frame_content', $GLOBALS['cfg']['MaxTableList']
336 $response->addHTML('</div><hr />');
339 * Work on the database
341 /* DATABASE WORK */
342 /* Printable view of a table */
343 $response->addHTML(
344 PMA_getHtmlForTablePrintViewLink($url_query)
345 . PMA_getHtmlForDataDictionaryLink($url_query)
348 PMA_possiblyShowCreateTableDialog($db, $db_is_system_schema, $response);