Translated using Weblate (Norwegian Bokmål)
[phpmyadmin.git] / db_structure.php
blob41ec4140eff62de02108bdf00454de6ff605c636
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 $overall_approx_rows = false;
150 // Instance of PMA_RecentFavoriteTable class.
151 $fav_instance = PMA_RecentFavoriteTable::getInstance('favorite');
152 foreach ($tables as $keyname => $current_table) {
153 // Get valid statistics whatever is the table type
155 $drop_query = '';
156 $drop_message = '';
157 $already_favorite = false;
158 $overhead = '';
160 $table_is_view = false;
161 $table_encoded = urlencode($current_table['TABLE_NAME']);
162 // Sets parameters for links
163 $tbl_url_query = $url_query . '&amp;table=' . $table_encoded;
164 // do not list the previous table's size info for a view
166 list($current_table, $formatted_size, $unit, $formatted_overhead,
167 $overhead_unit, $overhead_size, $table_is_view, $sum_size)
168 = PMA_getStuffForEngineTypeTable(
169 $current_table, $db_is_system_schema,
170 $is_show_stats, $table_is_view, $sum_size, $overhead_size
173 if (! PMA_Table::isMerge($db, $current_table['TABLE_NAME'])) {
174 $sum_entries += $current_table['TABLE_ROWS'];
177 if (isset($current_table['Collation'])) {
178 $collation = '<dfn title="'
179 . PMA_getCollationDescr($current_table['Collation']) . '">'
180 . $current_table['Collation'] . '</dfn>';
181 } else {
182 $collation = '---';
185 if ($is_show_stats) {
186 if ($formatted_overhead != '') {
187 $overhead = '<a href="tbl_structure.php'
188 . $tbl_url_query . '#showusage">'
189 . '<span>' . $formatted_overhead . '</span>&nbsp;'
190 . '<span class="unit">' . $overhead_unit . '</span>'
191 . '</a>' . "\n";
192 $overhead_check .=
193 "markAllRows('row_tbl_" . ($i + 1) . "');";
194 } else {
195 $overhead = '-';
197 } // end if
199 unset($showtable);
201 if ($GLOBALS['cfg']['ShowDbStructureCreation']) {
202 list($create_time, $create_time_all) = PMA_getTimeForCreateUpdateCheck(
203 $current_table, 'Create_time', $create_time_all
207 if ($GLOBALS['cfg']['ShowDbStructureLastUpdate']) {
208 // $showtable might already be set from ShowDbStructureCreation, see above
209 list($update_time, $update_time_all) = PMA_getTimeForCreateUpdateCheck(
210 $current_table, 'Update_time', $update_time_all
214 if ($GLOBALS['cfg']['ShowDbStructureLastCheck']) {
215 // $showtable might already be set from ShowDbStructureCreation, see above
216 list($check_time, $check_time_all) = PMA_getTimeForCreateUpdateCheck(
217 $current_table, 'Check_time', $check_time_all
221 list($alias, $truename) = PMA_getAliasAndTrueName(
222 $tooltip_aliasname, $current_table, $tooltip_truename
225 $i++;
227 $row_count++;
228 if ($table_is_view) {
229 $hidden_fields[] = '<input type="hidden" name="views[]" value="'
230 . htmlspecialchars($current_table['TABLE_NAME']) . '" />';
234 * Always activate links for Browse, Search and Empty, even if
235 * the icons are greyed, because
236 * 1. for views, we don't know the number of rows at this point
237 * 2. for tables, another source could have populated them since the
238 * page was generated
240 * I could have used the PHP ternary conditional operator but I find
241 * the code easier to read without this operator.
243 list($browse_table, $search_table, $browse_table_label,
244 $empty_table, $tracking_icon
245 ) = PMA_getHtmlForActionLinks(
246 $current_table, $table_is_view, $tbl_url_query,
247 $titles, $truename, $db_is_system_schema, $url_query
250 if (! $db_is_system_schema) {
251 list($drop_query, $drop_message)
252 = PMA_getTableDropQueryAndMessage($table_is_view, $current_table);
255 if ($num_columns > 0
256 && $num_tables > $num_columns
257 && ($row_count % $num_columns) == 0
259 $row_count = 1;
260 $odd_row = true;
262 $response->addHTML(
263 '</tr></tbody></table>'
266 $response->addHTML(
267 PMA_tableHeader(false, $GLOBALS['replication_info']['slave']['status'])
271 list($do, $ignored) = PMA_getServerSlaveStatus(
272 $GLOBALS['replication_info']['slave']['status'], $truename
274 // Handle favorite table list. ----START----
275 $already_favorite = PMA_checkFavoriteTable($db, $current_table['TABLE_NAME']);
277 if (isset($_REQUEST['remove_favorite'])) {
278 if ($already_favorite) {
279 // If already in favorite list, remove it.
280 $favorite_table = $_REQUEST['favorite_table'];
281 $fav_instance->remove($db, $favorite_table);
285 if (isset($_REQUEST['add_favorite'])) {
286 if (!$already_favorite) {
287 // Otherwise add to favorite list.
288 $favorite_table = $_REQUEST['favorite_table'];
289 $fav_instance->add($db, $favorite_table);
291 } // Handle favorite table list. ----ENDS----
293 list($html_output, $odd_row, $approx_rows) = PMA_getHtmlForStructureTableRow(
294 $i, $odd_row, $table_is_view, $current_table,
295 $browse_table_label, $tracking_icon,
296 $GLOBALS['replication_info']['slave']['status'],
297 $browse_table, $tbl_url_query, $search_table, $db_is_system_schema,
298 $titles, $empty_table, $drop_query, $drop_message, $collation,
299 $formatted_size, $unit, $overhead,
300 (isset ($create_time) ? $create_time : ''),
301 (isset ($update_time) ? $update_time : ''),
302 (isset ($check_time) ? $check_time : ''),
303 $is_show_stats, $ignored, $do, $colspan_for_structure
305 $overall_approx_rows = $overall_approx_rows || $approx_rows;
306 $response->addHTML($html_output);
308 } // end foreach
310 // Show Summary
311 $response->addHTML('</tbody>');
312 $response->addHTML(
313 PMA_getHtmlBodyForTableSummary(
314 $num_tables, $GLOBALS['replication_info']['slave']['status'],
315 $db_is_system_schema, $sum_entries, $db_collation, $is_show_stats, $sum_size,
316 $overhead_size, $create_time_all, $update_time_all, $check_time_all,
317 $overall_approx_rows
320 $response->addHTML('</table>');
321 //check all
322 $response->addHTML(
323 PMA_getHtmlForCheckAllTables(
324 $pmaThemeImage, $text_dir, $overhead_check,
325 $db_is_system_schema, $hidden_fields
328 $response->addHTML('</form>'); //end of form
330 // display again the table list navigator
331 $response->addHTML(
332 PMA_Util::getListNavigator(
333 $total_num_tables, $pos, $_url_params, 'db_structure.php',
334 'frame_content', $GLOBALS['cfg']['MaxTableList']
338 $response->addHTML('</div><hr />');
341 * Work on the database
343 /* DATABASE WORK */
344 /* Printable view of a table */
345 $response->addHTML(
346 PMA_getHtmlForTablePrintViewLink()
347 . PMA_getHtmlForDataDictionaryLink($url_query)
350 PMA_possiblyShowCreateTableDialog($db, $db_is_system_schema, $response);