Translated using Weblate (Interlingua)
[phpmyadmin.git] / db_structure.php
blob208551597fff8873597ca91cd60ab0ff45a8ddac
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 $fav_instance = PMA_RecentFavoriteTable::getInstance('favorite');
22 $favorite_tables = json_decode($_REQUEST['favorite_tables'], true);
23 // Required to keep each user's preferences seperate.
24 $user = sha1($GLOBALS['cfg']['Server']['user']);
26 // Request for Synchronization of favorite tables.
27 if (isset($_REQUEST['sync_favorite_tables'])) {
29 $fav_instance_tables = $fav_instance->getTables();
31 if (empty($fav_instance_tables)
32 && isset($favorite_tables[$user])
33 ) {
34 foreach ($favorite_tables[$user] as $key => $value) {
35 $fav_instance->add($value['db'], $value['table']);
38 $favorite_tables[$user] = $fav_instance->getTables();
40 $ajax_response = PMA_Response::getInstance();
41 $ajax_response->addJSON(
42 'favorite_tables',
43 json_encode($favorite_tables)
45 $ajax_response->addJSON(
46 'list',
47 $fav_instance->getHtmlList()
49 $server_id = $GLOBALS['server'];
50 // Set flag when localStorage and pmadb(if present) are in sync.
51 $_SESSION['tmpval']['favorites_synced'][$server_id] = true;
52 exit;
54 global $db;
55 $changes = true;
56 $msg = '';
57 $titles = PMA_Util::buildActionTitles();
58 $favorite_table = $_REQUEST['favorite_table'];
59 $already_favorite = PMA_checkFavoriteTable($db, $favorite_table);
61 if (isset($_REQUEST['remove_favorite'])) {
62 if ($already_favorite) {
63 // If already in favorite list, remove it.
64 $fav_instance->remove($db, $favorite_table);
66 } elseif (isset($_REQUEST['add_favorite'])) {
67 if (!$already_favorite) {
68 if (count($fav_instance->getTables()) == $GLOBALS['cfg']['NumFavoriteTables']) {
69 $changes = false;
70 $msg = '<div class="error"><img src="themes/dot.gif" '
71 . 'title="" alt="" class="icon ic_s_error" />'
72 . __("Favorite List is full!")
73 . '</div>';
74 } else {
75 // Otherwise add to favorite list.
76 $fav_instance->add($db, $favorite_table);
81 $favorite_tables[$user] = $fav_instance->getTables();
82 $ajax_response = PMA_Response::getInstance();
83 $ajax_response->addJSON(
84 'changes',
85 $changes
87 if ($changes) {
88 $ajax_response->addJSON(
89 'user',
90 $user
92 $ajax_response->addJSON(
93 'favorite_tables',
94 json_encode($favorite_tables)
96 $ajax_response->addJSON(
97 'list',
98 $fav_instance->getHtmlList()
100 $ajax_response->addJSON(
101 'anchor',
102 PMA_getHtmlForFavoriteAnchor(
103 $db, array('TABLE_NAME' => $favorite_table), $titles
106 } else {
107 $ajax_response->addJSON(
108 'message',
109 $msg
112 exit;
115 $response = PMA_Response::getInstance();
116 $header = $response->getHeader();
117 $scripts = $header->getScripts();
118 $scripts->addFile('db_structure.js');
119 $scripts->addFile('tbl_change.js');
120 $scripts->addFile('jquery/jquery-ui-timepicker-addon.js');
122 // Drops/deletes/etc. multiple tables if required
123 if ((!empty($_POST['submit_mult']) && isset($_POST['selected_tbl']))
124 || isset($_POST['mult_btn'])
126 $action = 'db_structure.php';
127 $err_url = 'db_structure.php?' . PMA_URL_getCommon($db);
129 // see bug #2794840; in this case, code path is:
130 // db_structure.php -> libraries/mult_submits.inc.php -> sql.php
131 // -> db_structure.php and if we got an error on the multi submit,
132 // we must display it here and not call again mult_submits.inc.php
133 if (! isset($_POST['error']) || false === $_POST['error']) {
134 include 'libraries/mult_submits.inc.php';
136 if (empty($_POST['message'])) {
137 $_POST['message'] = PMA_Message::success();
141 require 'libraries/db_common.inc.php';
142 $url_query .= '&amp;goto=db_structure.php';
144 // Gets the database structure
145 $sub_part = '_structure';
146 require 'libraries/db_info.inc.php';
148 if (!PMA_DRIZZLE) {
149 include_once 'libraries/replication.inc.php';
150 } else {
151 $server_slave_status = false;
154 require_once 'libraries/bookmark.lib.php';
156 require_once 'libraries/mysql_charsets.inc.php';
157 $db_collation = PMA_getDbCollation($db);
159 $titles = PMA_Util::buildActionTitles();
161 // 1. No tables
163 if ($num_tables == 0) {
164 $response->addHTML(
165 '<p>' . __('No tables found in database.') . '</p>' . "\n"
167 if (empty($db_is_system_schema)) {
168 ob_start();
169 include 'libraries/display_create_table.lib.php';
170 $content = ob_get_contents();
171 ob_end_clean();
172 $response->addHTML($content);
173 unset($content);
174 } // end if (Create Table dialog)
175 exit;
178 // else
179 // 2. Shows table informations
182 * Displays the tables list
184 $response->addHTML('<div id="tableslistcontainer">');
185 $_url_params = array(
186 'pos' => $pos,
187 'db' => $db);
189 // Add the sort options if they exists
190 if (isset($_REQUEST['sort'])) {
191 $_url_params['sort'] = $_REQUEST['sort'];
194 if (isset($_REQUEST['sort_order'])) {
195 $_url_params['sort_order'] = $_REQUEST['sort_order'];
198 $response->addHTML(
199 PMA_Util::getListNavigator(
200 $total_num_tables, $pos, $_url_params, 'db_structure.php',
201 'frame_content', $GLOBALS['cfg']['MaxTableList']
205 // tables form
206 $response->addHTML(
207 '<form method="post" action="db_structure.php" '
208 . 'name="tablesForm" id="tablesForm">'
211 $response->addHTML(PMA_URL_getHiddenInputs($db));
213 $response->addHTML(
214 PMA_tableHeader($db_is_system_schema, $server_slave_status)
217 $i = $sum_entries = 0;
218 $overhead_check = '';
219 $create_time_all = '';
220 $update_time_all = '';
221 $check_time_all = '';
222 $num_columns = $cfg['PropertiesNumColumns'] > 1
223 ? ceil($num_tables / $cfg['PropertiesNumColumns']) + 1
224 : 0;
225 $row_count = 0;
226 $sum_size = (double) 0;
227 $overhead_size = (double) 0;
229 $hidden_fields = array();
230 $odd_row = true;
231 $sum_row_count_pre = '';
232 // Instance of PMA_RecentFavoriteTable class.
233 $fav_instance = PMA_RecentFavoriteTable::getInstance('favorite');
234 foreach ($tables as $keyname => $current_table) {
235 // Get valid statistics whatever is the table type
237 $drop_query = '';
238 $drop_message = '';
239 $already_favorite = false;
240 $overhead = '';
242 $table_is_view = false;
243 $table_encoded = urlencode($current_table['TABLE_NAME']);
244 // Sets parameters for links
245 $tbl_url_query = $url_query . '&amp;table=' . $table_encoded;
246 // do not list the previous table's size info for a view
248 list($current_table, $formatted_size, $unit, $formatted_overhead,
249 $overhead_unit, $overhead_size, $table_is_view, $sum_size)
250 = PMA_getStuffForEngineTypeTable(
251 $current_table, $db_is_system_schema,
252 $is_show_stats, $table_is_view, $sum_size, $overhead_size
255 if (! PMA_Table::isMerge($db, $current_table['TABLE_NAME'])) {
256 $sum_entries += $current_table['TABLE_ROWS'];
259 if (isset($current_table['Collation'])) {
260 $collation = '<dfn title="'
261 . PMA_getCollationDescr($current_table['Collation']) . '">'
262 . $current_table['Collation'] . '</dfn>';
263 } else {
264 $collation = '---';
267 if ($is_show_stats) {
268 if ($formatted_overhead != '') {
269 $overhead = '<a href="tbl_structure.php?'
270 . $tbl_url_query . '#showusage">'
271 . '<span>' . $formatted_overhead . '</span>'
272 . '<span class="unit">' . $overhead_unit . '</span>'
273 . '</a>' . "\n";
274 $overhead_check .=
275 "markAllRows('row_tbl_" . ($i + 1) . "');";
276 } else {
277 $overhead = '-';
279 } // end if
281 unset($showtable);
283 if ($GLOBALS['cfg']['ShowDbStructureCreation']) {
284 list($create_time, $create_time_all) = PMA_getTimeForCreateUpdateCheck(
285 $current_table, 'Create_time', $create_time_all
289 if ($GLOBALS['cfg']['ShowDbStructureLastUpdate']) {
290 // $showtable might already be set from ShowDbStructureCreation, see above
291 list($update_time, $update_time_all) = PMA_getTimeForCreateUpdateCheck(
292 $current_table, 'Update_time', $update_time_all
296 if ($GLOBALS['cfg']['ShowDbStructureLastCheck']) {
297 // $showtable might already be set from ShowDbStructureCreation, see above
298 list($check_time, $check_time_all) = PMA_getTimeForCreateUpdateCheck(
299 $current_table, 'Check_time', $check_time_all
303 list($alias, $truename) = PMA_getAliasAndTrueName(
304 $tooltip_aliasname, $current_table, $tooltip_truename
307 $i++;
309 $row_count++;
310 if ($table_is_view) {
311 $hidden_fields[] = '<input type="hidden" name="views[]" value="'
312 . htmlspecialchars($current_table['TABLE_NAME']) . '" />';
316 * Always activate links for Browse, Search and Empty, even if
317 * the icons are greyed, because
318 * 1. for views, we don't know the number of rows at this point
319 * 2. for tables, another source could have populated them since the
320 * page was generated
322 * I could have used the PHP ternary conditional operator but I find
323 * the code easier to read without this operator.
325 list($browse_table, $search_table, $browse_table_label, $empty_table,
326 $tracking_icon) = PMA_getHtmlForActionLinks(
327 $current_table, $table_is_view, $tbl_url_query,
328 $titles, $truename, $db_is_system_schema, $url_query
331 if (! $db_is_system_schema) {
332 list($drop_query, $drop_message)
333 = PMA_getTableDropQueryAndMessage($table_is_view, $current_table);
336 if ($num_columns > 0
337 && $num_tables > $num_columns
338 && ($row_count % $num_columns) == 0
340 $row_count = 1;
341 $odd_row = true;
343 $response->addHTML(
344 '</tr></tbody></table>'
347 $response->addHTML(PMA_tableHeader(false, $server_slave_status));
350 list($do, $ignored) = PMA_getServerSlaveStatus(
351 $server_slave_status, $truename
353 // Handle favorite table list. ----START----
354 $already_favorite = PMA_checkFavoriteTable($db, $current_table['TABLE_NAME']);
356 if (isset($_REQUEST['remove_favorite'])) {
357 if ($already_favorite) {
358 // If already in favorite list, remove it.
359 $favorite_table = $_REQUEST['favorite_table'];
360 $fav_instance->remove($db, $favorite_table);
364 if (isset($_REQUEST['add_favorite'])) {
365 if (!$already_favorite) {
366 // Otherwise add to favorite list.
367 $favorite_table = $_REQUEST['favorite_table'];
368 $fav_instance->add($db, $favorite_table);
370 } // Handle favorite table list. ----ENDS----
372 list($html_output, $odd_row) = PMA_getHtmlForStructureTableRow(
373 $i, $odd_row, $table_is_view, $current_table,
374 $browse_table_label, $tracking_icon, $server_slave_status,
375 $browse_table, $tbl_url_query, $search_table, $db_is_system_schema,
376 $titles, $empty_table, $drop_query, $drop_message, $collation,
377 $formatted_size, $unit, $overhead,
378 (isset ($create_time) ? $create_time : ''),
379 (isset ($update_time) ? $update_time : ''),
380 (isset ($check_time) ? $check_time : ''),
381 $is_show_stats, $ignored, $do, $colspan_for_structure
383 $response->addHTML($html_output);
385 } // end foreach
387 // Show Summary
388 $response->addHTML('</tbody>');
389 $response->addHTML(
390 PMA_getHtmlBodyForTableSummary(
391 $num_tables, $server_slave_status, $db_is_system_schema, $sum_entries,
392 $db_collation, $is_show_stats, $sum_size, $overhead_size, $create_time_all,
393 $update_time_all, $check_time_all, $sum_row_count_pre
396 $response->addHTML('</table>');
397 //check all
398 $response->addHTML(
399 PMA_getHtmlForCheckAllTables(
400 $pmaThemeImage, $text_dir, $overhead_check,
401 $db_is_system_schema, $hidden_fields
404 $response->addHTML('</form>'); //end of form
406 // display again the table list navigator
407 $response->addHTML(
408 PMA_Util::getListNavigator(
409 $total_num_tables, $pos, $_url_params, 'db_structure.php',
410 'frame_content', $GLOBALS['cfg']['MaxTableList']
414 $response->addHTML('</div><hr />');
417 * Work on the database
419 /* DATABASE WORK */
420 /* Printable view of a table */
421 $response->addHTML(
422 PMA_getHtmlForTablePrintViewLink($url_query)
423 . PMA_getHtmlForDataDictionaryLink($url_query)
426 if (empty($db_is_system_schema)) {
427 ob_start();
428 include 'libraries/display_create_table.lib.php';
429 $content = ob_get_contents();
430 ob_end_clean();
431 $response->addHTML($content);
432 } // end if (Create Table dialog)