Translated using Weblate (Slovenian)
[phpmyadmin.git] / db_structure.php
blob24d3bb2ce4234540d906968715191ec885d6c163
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_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 $_table = new PMA_Table($current_table['TABLE_NAME'], $db);
174 if (! $_table->isMerge()) {
175 $sum_entries += $current_table['TABLE_ROWS'];
178 if (isset($current_table['Collation'])) {
179 $collation = '<dfn title="'
180 . PMA_getCollationDescr($current_table['Collation']) . '">'
181 . $current_table['Collation'] . '</dfn>';
182 } else {
183 $collation = '---';
186 if ($is_show_stats) {
187 if ($formatted_overhead != '') {
188 $overhead = '<a href="tbl_structure.php'
189 . $tbl_url_query . '#showusage">'
190 . '<span>' . $formatted_overhead . '</span>&nbsp;'
191 . '<span class="unit">' . $overhead_unit . '</span>'
192 . '</a>' . "\n";
193 $overhead_check .=
194 "markAllRows('row_tbl_" . ($i + 1) . "');";
195 } else {
196 $overhead = '-';
198 } // end if
200 unset($showtable);
202 if ($GLOBALS['cfg']['ShowDbStructureCreation']) {
203 list($create_time, $create_time_all) = PMA_getTimeForCreateUpdateCheck(
204 $current_table, 'Create_time', $create_time_all
208 if ($GLOBALS['cfg']['ShowDbStructureLastUpdate']) {
209 // $showtable might already be set from ShowDbStructureCreation, see above
210 list($update_time, $update_time_all) = PMA_getTimeForCreateUpdateCheck(
211 $current_table, 'Update_time', $update_time_all
215 if ($GLOBALS['cfg']['ShowDbStructureLastCheck']) {
216 // $showtable might already be set from ShowDbStructureCreation, see above
217 list($check_time, $check_time_all) = PMA_getTimeForCreateUpdateCheck(
218 $current_table, 'Check_time', $check_time_all
222 list($alias, $truename) = PMA_getAliasAndTrueName(
223 $tooltip_aliasname, $current_table, $tooltip_truename
226 $i++;
228 $row_count++;
229 if ($table_is_view) {
230 $hidden_fields[] = '<input type="hidden" name="views[]" value="'
231 . htmlspecialchars($current_table['TABLE_NAME']) . '" />';
235 * Always activate links for Browse, Search and Empty, even if
236 * the icons are greyed, because
237 * 1. for views, we don't know the number of rows at this point
238 * 2. for tables, another source could have populated them since the
239 * page was generated
241 * I could have used the PHP ternary conditional operator but I find
242 * the code easier to read without this operator.
244 list($browse_table, $search_table, $browse_table_label,
245 $empty_table, $tracking_icon
246 ) = PMA_getHtmlForActionLinks(
247 $current_table, $table_is_view, $tbl_url_query,
248 $titles, $truename, $db_is_system_schema, $url_query
251 if (! $db_is_system_schema) {
252 list($drop_query, $drop_message)
253 = PMA_getTableDropQueryAndMessage($table_is_view, $current_table);
256 if ($num_columns > 0
257 && $num_tables > $num_columns
258 && ($row_count % $num_columns) == 0
260 $row_count = 1;
261 $odd_row = true;
263 $response->addHTML(
264 '</tr></tbody></table>'
267 $response->addHTML(
268 PMA_tableHeader(false, $GLOBALS['replication_info']['slave']['status'])
272 list($do, $ignored) = PMA_getServerSlaveStatus(
273 $GLOBALS['replication_info']['slave']['status'], $truename
275 // Handle favorite table list. ----START----
276 $already_favorite = PMA_checkFavoriteTable($db, $current_table['TABLE_NAME']);
278 if (isset($_REQUEST['remove_favorite'])) {
279 if ($already_favorite) {
280 // If already in favorite list, remove it.
281 $favorite_table = $_REQUEST['favorite_table'];
282 $fav_instance->remove($db, $favorite_table);
286 if (isset($_REQUEST['add_favorite'])) {
287 if (!$already_favorite) {
288 // Otherwise add to favorite list.
289 $favorite_table = $_REQUEST['favorite_table'];
290 $fav_instance->add($db, $favorite_table);
292 } // Handle favorite table list. ----ENDS----
294 list($html_output, $odd_row, $approx_rows) = PMA_getHtmlForStructureTableRow(
295 $i, $odd_row, $table_is_view, $current_table,
296 $browse_table_label, $tracking_icon,
297 $GLOBALS['replication_info']['slave']['status'],
298 $browse_table, $tbl_url_query, $search_table, $db_is_system_schema,
299 $titles, $empty_table, $drop_query, $drop_message, $collation,
300 $formatted_size, $unit, $overhead,
301 (isset ($create_time) ? $create_time : ''),
302 (isset ($update_time) ? $update_time : ''),
303 (isset ($check_time) ? $check_time : ''),
304 $is_show_stats, $ignored, $do, $colspan_for_structure
306 $overall_approx_rows = $overall_approx_rows || $approx_rows;
307 $response->addHTML($html_output);
309 } // end foreach
311 // Show Summary
312 $response->addHTML('</tbody>');
313 $response->addHTML(
314 PMA_getHtmlBodyForTableSummary(
315 $num_tables, $GLOBALS['replication_info']['slave']['status'],
316 $db_is_system_schema, $sum_entries, $db_collation, $is_show_stats, $sum_size,
317 $overhead_size, $create_time_all, $update_time_all, $check_time_all,
318 $overall_approx_rows
321 $response->addHTML('</table>');
322 //check all
323 $response->addHTML(
324 PMA_getHtmlForCheckAllTables(
325 $pmaThemeImage, $text_dir, $overhead_check,
326 $db_is_system_schema, $hidden_fields
329 $response->addHTML('</form>'); //end of form
331 // display again the table list navigator
332 $response->addHTML(
333 PMA_Util::getListNavigator(
334 $total_num_tables, $pos, $_url_params, 'db_structure.php',
335 'frame_content', $GLOBALS['cfg']['MaxTableList']
339 $response->addHTML('</div><hr />');
342 * Work on the database
344 /* DATABASE WORK */
345 /* Printable view of a table */
346 $response->addHTML(
347 PMA_getHtmlForTablePrintViewLink()
348 . PMA_getHtmlForDataDictionaryLink($url_query)
351 PMA_possiblyShowCreateTableDialog($db, $db_is_system_schema, $response);