Translated using Weblate (Bulgarian)
[phpmyadmin.git] / db_structure.php
blob4a17588eab403a70e705e9fabbd508589c782aff
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($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 $server_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();
80 // 1. No tables
82 if ($num_tables == 0) {
83 $response->addHTML(
84 '<p>' . __('No tables found in database.') . '</p>' . "\n"
86 if (empty($db_is_system_schema)) {
87 ob_start();
88 include 'libraries/display_create_table.lib.php';
89 $content = ob_get_contents();
90 ob_end_clean();
91 $response->addHTML($content);
92 unset($content);
93 } // end if (Create Table dialog)
94 exit;
97 // else
98 // 2. Shows table informations
101 * Displays the tables list
103 $response->addHTML('<div id="tableslistcontainer">');
104 $_url_params = array(
105 'pos' => $pos,
106 'db' => $db);
108 // Add the sort options if they exists
109 if (isset($_REQUEST['sort'])) {
110 $_url_params['sort'] = $_REQUEST['sort'];
113 if (isset($_REQUEST['sort_order'])) {
114 $_url_params['sort_order'] = $_REQUEST['sort_order'];
117 $response->addHTML(
118 PMA_Util::getListNavigator(
119 $total_num_tables, $pos, $_url_params, 'db_structure.php',
120 'frame_content', $GLOBALS['cfg']['MaxTableList']
124 // tables form
125 $response->addHTML(
126 '<form method="post" action="db_structure.php" '
127 . 'name="tablesForm" id="tablesForm">'
130 $response->addHTML(PMA_URL_getHiddenInputs($db));
132 $response->addHTML(
133 PMA_tableHeader($db_is_system_schema, $server_slave_status)
136 $i = $sum_entries = 0;
137 $overhead_check = '';
138 $create_time_all = '';
139 $update_time_all = '';
140 $check_time_all = '';
141 $num_columns = $cfg['PropertiesNumColumns'] > 1
142 ? ceil($num_tables / $cfg['PropertiesNumColumns']) + 1
143 : 0;
144 $row_count = 0;
145 $sum_size = (double) 0;
146 $overhead_size = (double) 0;
148 $hidden_fields = array();
149 $odd_row = true;
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>'
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, $empty_table,
244 $tracking_icon) = 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(PMA_tableHeader(false, $server_slave_status));
268 list($do, $ignored) = PMA_getServerSlaveStatus(
269 $server_slave_status, $truename
271 // Handle favorite table list. ----START----
272 $already_favorite = PMA_checkFavoriteTable($db, $current_table['TABLE_NAME']);
274 if (isset($_REQUEST['remove_favorite'])) {
275 if ($already_favorite) {
276 // If already in favorite list, remove it.
277 $favorite_table = $_REQUEST['favorite_table'];
278 $fav_instance->remove($db, $favorite_table);
282 if (isset($_REQUEST['add_favorite'])) {
283 if (!$already_favorite) {
284 // Otherwise add to favorite list.
285 $favorite_table = $_REQUEST['favorite_table'];
286 $fav_instance->add($db, $favorite_table);
288 } // Handle favorite table list. ----ENDS----
290 list($html_output, $odd_row, $approx_rows) = PMA_getHtmlForStructureTableRow(
291 $i, $odd_row, $table_is_view, $current_table,
292 $browse_table_label, $tracking_icon, $server_slave_status,
293 $browse_table, $tbl_url_query, $search_table, $db_is_system_schema,
294 $titles, $empty_table, $drop_query, $drop_message, $collation,
295 $formatted_size, $unit, $overhead,
296 (isset ($create_time) ? $create_time : ''),
297 (isset ($update_time) ? $update_time : ''),
298 (isset ($check_time) ? $check_time : ''),
299 $is_show_stats, $ignored, $do, $colspan_for_structure
301 $response->addHTML($html_output);
303 } // end foreach
305 // Show Summary
306 $response->addHTML('</tbody>');
307 $response->addHTML(
308 PMA_getHtmlBodyForTableSummary(
309 $num_tables, $server_slave_status, $db_is_system_schema, $sum_entries,
310 $db_collation, $is_show_stats, $sum_size, $overhead_size, $create_time_all,
311 $update_time_all, $check_time_all, isset($approx_rows) ? $approx_rows : false
314 $response->addHTML('</table>');
315 //check all
316 $response->addHTML(
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
325 $response->addHTML(
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
337 /* DATABASE WORK */
338 /* Printable view of a table */
339 $response->addHTML(
340 PMA_getHtmlForTablePrintViewLink($url_query)
341 . PMA_getHtmlForDataDictionaryLink($url_query)
344 if (empty($db_is_system_schema)) {
345 ob_start();
346 include 'libraries/display_create_table.lib.php';
347 $content = ob_get_contents();
348 ob_end_clean();
349 $response->addHTML($content);
350 } // end if (Create Table dialog)