Translated using Weblate (Italian)
[phpmyadmin.git] / db_structure.php
blob12f1de5cc519db5c1f2c9b21f46c2ec069d1b8eb
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 information
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\Template::get('structure/table_header')->render(
131 array(
132 'db_is_system_schema' => $db_is_system_schema,
133 'replication' => $GLOBALS['replication_info']['slave']['status']
138 $i = $sum_entries = 0;
139 $overhead_check = '';
140 $create_time_all = '';
141 $update_time_all = '';
142 $check_time_all = '';
143 $num_columns = $cfg['PropertiesNumColumns'] > 1
144 ? ceil($num_tables / $cfg['PropertiesNumColumns']) + 1
145 : 0;
146 $row_count = 0;
147 $sum_size = (double) 0;
148 $overhead_size = (double) 0;
150 $hidden_fields = array();
151 $odd_row = true;
152 $overall_approx_rows = false;
153 // Instance of PMA_RecentFavoriteTable class.
154 $fav_instance = PMA_RecentFavoriteTable::getInstance('favorite');
155 foreach ($tables as $keyname => $current_table) {
156 // Get valid statistics whatever is the table type
158 $drop_query = '';
159 $drop_message = '';
160 $already_favorite = false;
161 $overhead = '';
163 $table_is_view = false;
164 $table_encoded = urlencode($current_table['TABLE_NAME']);
165 // Sets parameters for links
166 $tbl_url_query = $url_query . '&amp;table=' . $table_encoded;
167 // do not list the previous table's size info for a view
169 list($current_table, $formatted_size, $unit, $formatted_overhead,
170 $overhead_unit, $overhead_size, $table_is_view, $sum_size)
171 = PMA_getStuffForEngineTypeTable(
172 $current_table, $db_is_system_schema,
173 $is_show_stats, $table_is_view, $sum_size, $overhead_size
176 $_table = new PMA_Table($current_table['TABLE_NAME'], $db);
177 if (! $_table->isMerge()) {
178 $sum_entries += $current_table['TABLE_ROWS'];
181 if (isset($current_table['Collation'])) {
182 $collation = '<dfn title="'
183 . PMA_getCollationDescr($current_table['Collation']) . '">'
184 . $current_table['Collation'] . '</dfn>';
185 } else {
186 $collation = '---';
189 if ($is_show_stats) {
190 if ($formatted_overhead != '') {
191 $overhead = '<a href="tbl_structure.php'
192 . $tbl_url_query . '#showusage">'
193 . '<span>' . $formatted_overhead . '</span>&nbsp;'
194 . '<span class="unit">' . $overhead_unit . '</span>'
195 . '</a>' . "\n";
196 $overhead_check .=
197 "markAllRows('row_tbl_" . ($i + 1) . "');";
198 } else {
199 $overhead = '-';
201 } // end if
203 unset($showtable);
205 if ($GLOBALS['cfg']['ShowDbStructureCreation']) {
206 list($create_time, $create_time_all) = PMA_getTimeForCreateUpdateCheck(
207 $current_table, 'Create_time', $create_time_all
211 if ($GLOBALS['cfg']['ShowDbStructureLastUpdate']) {
212 // $showtable might already be set from ShowDbStructureCreation, see above
213 list($update_time, $update_time_all) = PMA_getTimeForCreateUpdateCheck(
214 $current_table, 'Update_time', $update_time_all
218 if ($GLOBALS['cfg']['ShowDbStructureLastCheck']) {
219 // $showtable might already be set from ShowDbStructureCreation, see above
220 list($check_time, $check_time_all) = PMA_getTimeForCreateUpdateCheck(
221 $current_table, 'Check_time', $check_time_all
225 list($alias, $truename) = PMA_getAliasAndTrueName(
226 $tooltip_aliasname, $current_table, $tooltip_truename
229 $i++;
231 $row_count++;
232 if ($table_is_view) {
233 $hidden_fields[] = '<input type="hidden" name="views[]" value="'
234 . htmlspecialchars($current_table['TABLE_NAME']) . '" />';
238 * Always activate links for Browse, Search and Empty, even if
239 * the icons are greyed, because
240 * 1. for views, we don't know the number of rows at this point
241 * 2. for tables, another source could have populated them since the
242 * page was generated
244 * I could have used the PHP ternary conditional operator but I find
245 * the code easier to read without this operator.
247 list($browse_table, $search_table, $browse_table_label,
248 $empty_table, $tracking_icon
249 ) = PMA_getHtmlForActionLinks(
250 $current_table, $table_is_view, $tbl_url_query,
251 $titles, $truename, $db_is_system_schema, $url_query
254 if (! $db_is_system_schema) {
255 list($drop_query, $drop_message)
256 = PMA_getTableDropQueryAndMessage($table_is_view, $current_table);
259 if ($num_columns > 0
260 && $num_tables > $num_columns
261 && ($row_count % $num_columns) == 0
263 $row_count = 1;
264 $odd_row = true;
266 $response->addHTML(
267 '</tr></tbody></table>'
270 $response->addHTML(
271 PMA\Template::get('structure/table_header')->render(
272 array(
273 'db_is_system_schema' => false,
274 'replication' => $GLOBALS['replication_info']['slave']['status']
280 list($do, $ignored) = PMA_getServerSlaveStatus(
281 $GLOBALS['replication_info']['slave']['status'], $truename
283 // Handle favorite table list. ----START----
284 $already_favorite = PMA_checkFavoriteTable($db, $current_table['TABLE_NAME']);
286 if (isset($_REQUEST['remove_favorite'])) {
287 if ($already_favorite) {
288 // If already in favorite list, remove it.
289 $favorite_table = $_REQUEST['favorite_table'];
290 $fav_instance->remove($db, $favorite_table);
294 if (isset($_REQUEST['add_favorite'])) {
295 if (!$already_favorite) {
296 // Otherwise add to favorite list.
297 $favorite_table = $_REQUEST['favorite_table'];
298 $fav_instance->add($db, $favorite_table);
300 } // Handle favorite table list. ----ENDS----
302 list($html_output, $odd_row, $approx_rows) = PMA_getHtmlForStructureTableRow(
303 $i, $odd_row, $table_is_view, $current_table,
304 $browse_table_label, $tracking_icon,
305 $GLOBALS['replication_info']['slave']['status'],
306 $browse_table, $tbl_url_query, $search_table, $db_is_system_schema,
307 $titles, $empty_table, $drop_query, $drop_message, $collation,
308 $formatted_size, $unit, $overhead,
309 (isset ($create_time) ? $create_time : ''),
310 (isset ($update_time) ? $update_time : ''),
311 (isset ($check_time) ? $check_time : ''),
312 $is_show_stats, $ignored, $do, $colspan_for_structure
314 $overall_approx_rows = $overall_approx_rows || $approx_rows;
315 $response->addHTML($html_output);
317 } // end foreach
319 // Show Summary
320 $response->addHTML('</tbody>');
321 $response->addHTML(
322 PMA\Template::get('structure/body_for_table_summary')->render(
323 array(
324 'num_tables' => $num_tables,
325 'server_slave_status' => $GLOBALS['replication_info']['slave']['status'],
326 'db_is_system_schema' => $db_is_system_schema,
327 'sum_entries' => $sum_entries,
328 'db_collation' => $db_collation,
329 'is_show_stats' => $is_show_stats,
330 'sum_size' => $sum_size,
331 'overhead_size' => $overhead_size,
332 'create_time_all' => $create_time_all,
333 'update_time_all' => $update_time_all,
334 'check_time_all' => $check_time_all,
335 'approx_rows' => $overall_approx_rows
339 $response->addHTML('</table>');
340 //check all
341 $response->addHTML(
342 PMA\Template::get('structure/check_all_tables')->render(
343 array(
344 'pmaThemeImage' => $pmaThemeImage,
345 'text_dir' => $text_dir,
346 'overhead_check' => $overhead_check,
347 'db_is_system_schema' => $db_is_system_schema,
348 'hidden_fields' => $hidden_fields
352 $response->addHTML('</form>'); //end of form
354 // display again the table list navigator
355 $response->addHTML(
356 PMA_Util::getListNavigator(
357 $total_num_tables, $pos, $_url_params, 'db_structure.php',
358 'frame_content', $GLOBALS['cfg']['MaxTableList']
362 $response->addHTML('</div><hr />');
365 * Work on the database
367 /* DATABASE WORK */
368 /* Printable view of a table */
369 $response->addHTML(
370 PMA\Template::get('structure/print_view_data_dictionary_link')->render(
371 array('url_query' => $url_query)
375 PMA_possiblyShowCreateTableDialog($db, $db_is_system_schema, $response);