Welcome to mirror list, hosted at ThFree Co, Russian Federation.

db_structure.php - github.com/phpmyadmin/phpmyadmin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 07eaa2d0fcba0744c1fabd4747254434d7908629 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
 * Database structure manipulation
 *
 * @package PhpMyAdmin
 */

/**
 *
 */
require_once 'libraries/common.inc.php';

/**
 * Function implementations for this script
 */
require_once 'libraries/structure.lib.php';

// Add/Remove favorite tables using Ajax request.
if ($GLOBALS['is_ajax_request'] && ! empty($_REQUEST['favorite_table'])) {
    PMA_addRemoveFavoriteTables($db);
    exit;
}

$response = PMA_Response::getInstance();
$header   = $response->getHeader();
$scripts  = $header->getScripts();
$scripts->addFile('db_structure.js');
$scripts->addFile('tbl_change.js');
$scripts->addFile('jquery/jquery-ui-timepicker-addon.js');

// Drops/deletes/etc. multiple tables if required
if ((!empty($_POST['submit_mult']) && isset($_POST['selected_tbl']))
    || isset($_POST['mult_btn'])
) {
    $action = 'db_structure.php';
    $err_url = 'db_structure.php' . PMA_URL_getCommon(array('db' => $db));

    // see bug #2794840; in this case, code path is:
    // db_structure.php -> libraries/mult_submits.inc.php -> sql.php
    // -> db_structure.php and if we got an error on the multi submit,
    // we must display it here and not call again mult_submits.inc.php
    if (! isset($_POST['error']) || false === $_POST['error']) {
        include 'libraries/mult_submits.inc.php';
    }
    if (empty($_POST['message'])) {
        $_POST['message'] = PMA_Message::success();
    }
}

require 'libraries/db_common.inc.php';
$url_query .= '&amp;goto=db_structure.php';

// Gets the database structure
$sub_part = '_structure';
require 'libraries/db_info.inc.php';

// If there is an Ajax request for real row count of a table.
if ($GLOBALS['is_ajax_request']
    && isset($_REQUEST['real_row_count'])
    && $_REQUEST['real_row_count'] == true
) {
    PMA_handleRealRowCountRequest();
    exit;
}

if (!PMA_DRIZZLE) {
    include_once 'libraries/replication.inc.php';
} else {
    $GLOBALS['replication_info']['slave']['status'] = false;
}

require_once 'libraries/bookmark.lib.php';

require_once 'libraries/mysql_charsets.inc.php';
$db_collation = PMA_getDbCollation($db);

$titles = PMA_Util::buildActionTitles();

// 1. No tables

if ($num_tables == 0) {
    $response->addHTML(
        PMA_message::notice(__('No tables found in database.'))
    );
    PMA_possiblyShowCreateTableDialog($db, $db_is_system_schema, $response);
    exit;
}

// else
// 2. Shows table informations

/**
 * Displays the tables list
 */
$response->addHTML('<div id="tableslistcontainer">');
$_url_params = array(
    'pos' => $pos,
    'db'  => $db);

// Add the sort options if they exists
if (isset($_REQUEST['sort'])) {
    $_url_params['sort'] = $_REQUEST['sort'];
}

if (isset($_REQUEST['sort_order'])) {
    $_url_params['sort_order'] = $_REQUEST['sort_order'];
}

$response->addHTML(
    PMA_Util::getListNavigator(
        $total_num_tables, $pos, $_url_params, 'db_structure.php',
        'frame_content', $GLOBALS['cfg']['MaxTableList']
    )
);

// tables form
$response->addHTML(
    '<form method="post" action="db_structure.php" '
    . 'name="tablesForm" id="tablesForm">'
);

$response->addHTML(PMA_URL_getHiddenInputs($db));

$response->addHTML(
    PMA_tableHeader(
        $db_is_system_schema, $GLOBALS['replication_info']['slave']['status']
    )
);

$i = $sum_entries = 0;
$overhead_check = '';
$create_time_all = '';
$update_time_all = '';
$check_time_all = '';
$num_columns    = $cfg['PropertiesNumColumns'] > 1
    ? ceil($num_tables / $cfg['PropertiesNumColumns']) + 1
    : 0;
$row_count      = 0;
$sum_size       = (double) 0;
$overhead_size  = (double) 0;

$hidden_fields = array();
$odd_row       = true;
// Instance of PMA_RecentFavoriteTable class.
$fav_instance = PMA_RecentFavoriteTable::getInstance('favorite');
foreach ($tables as $keyname => $current_table) {
    // Get valid statistics whatever is the table type

    $drop_query = '';
    $drop_message = '';
    $already_favorite = false;
    $overhead = '';

    $table_is_view = false;
    $table_encoded = urlencode($current_table['TABLE_NAME']);
    // Sets parameters for links
    $tbl_url_query = $url_query . '&amp;table=' . $table_encoded;
    // do not list the previous table's size info for a view

    list($current_table, $formatted_size, $unit, $formatted_overhead,
        $overhead_unit, $overhead_size, $table_is_view, $sum_size)
            = PMA_getStuffForEngineTypeTable(
                $current_table, $db_is_system_schema,
                $is_show_stats, $table_is_view, $sum_size, $overhead_size
            );

    if (! PMA_Table::isMerge($db, $current_table['TABLE_NAME'])) {
        $sum_entries += $current_table['TABLE_ROWS'];
    }

    if (isset($current_table['Collation'])) {
        $collation = '<dfn title="'
            . PMA_getCollationDescr($current_table['Collation']) . '">'
            . $current_table['Collation'] . '</dfn>';
    } else {
        $collation = '---';
    }

    if ($is_show_stats) {
        if ($formatted_overhead != '') {
            $overhead = '<a href="tbl_structure.php'
                . $tbl_url_query . '#showusage">'
                . '<span>' . $formatted_overhead . '</span>'
                . '<span class="unit">' . $overhead_unit . '</span>'
                . '</a>' . "\n";
            $overhead_check .=
                "markAllRows('row_tbl_" . ($i + 1) . "');";
        } else {
            $overhead = '-';
        }
    } // end if

    unset($showtable);

    if ($GLOBALS['cfg']['ShowDbStructureCreation']) {
        list($create_time, $create_time_all) = PMA_getTimeForCreateUpdateCheck(
            $current_table, 'Create_time', $create_time_all
        );
    }

    if ($GLOBALS['cfg']['ShowDbStructureLastUpdate']) {
        // $showtable might already be set from ShowDbStructureCreation, see above
        list($update_time, $update_time_all) = PMA_getTimeForCreateUpdateCheck(
            $current_table, 'Update_time', $update_time_all
        );
    }

    if ($GLOBALS['cfg']['ShowDbStructureLastCheck']) {
        // $showtable might already be set from ShowDbStructureCreation, see above
        list($check_time, $check_time_all) = PMA_getTimeForCreateUpdateCheck(
            $current_table, 'Check_time', $check_time_all
        );
    }

    list($alias, $truename) = PMA_getAliasAndTrueName(
        $tooltip_aliasname, $current_table, $tooltip_truename
    );

    $i++;

    $row_count++;
    if ($table_is_view) {
        $hidden_fields[] = '<input type="hidden" name="views[]" value="'
            .  htmlspecialchars($current_table['TABLE_NAME']) . '" />';
    }

    /*
     * Always activate links for Browse, Search and Empty, even if
     * the icons are greyed, because
     * 1. for views, we don't know the number of rows at this point
     * 2. for tables, another source could have populated them since the
     *    page was generated
     *
     * I could have used the PHP ternary conditional operator but I find
     * the code easier to read without this operator.
     */
    list($browse_table, $search_table, $browse_table_label, $empty_table,
        $tracking_icon) = PMA_getHtmlForActionLinks(
            $current_table, $table_is_view, $tbl_url_query,
            $titles, $truename, $db_is_system_schema, $url_query
        );

    if (! $db_is_system_schema) {
        list($drop_query, $drop_message)
            = PMA_getTableDropQueryAndMessage($table_is_view, $current_table);
    }

    if ($num_columns > 0
        && $num_tables > $num_columns
        && ($row_count % $num_columns) == 0
    ) {
        $row_count = 1;
        $odd_row = true;

        $response->addHTML(
            '</tr></tbody></table>'
        );

        $response->addHTML(
            PMA_tableHeader(false, $GLOBALS['replication_info']['slave']['status'])
        );
    }

    list($do, $ignored) = PMA_getServerSlaveStatus(
        $GLOBALS['replication_info']['slave']['status'], $truename
    );
    // Handle favorite table list. ----START----
    $already_favorite = PMA_checkFavoriteTable($db, $current_table['TABLE_NAME']);

    if (isset($_REQUEST['remove_favorite'])) {
        if ($already_favorite) {
            // If already in favorite list, remove it.
            $favorite_table = $_REQUEST['favorite_table'];
            $fav_instance->remove($db, $favorite_table);
        }
    }

    if (isset($_REQUEST['add_favorite'])) {
        if (!$already_favorite) {
            // Otherwise add to favorite list.
            $favorite_table = $_REQUEST['favorite_table'];
            $fav_instance->add($db, $favorite_table);
        }
    } // Handle favorite table list. ----ENDS----

    list($html_output, $odd_row, $approx_rows) = PMA_getHtmlForStructureTableRow(
        $i, $odd_row, $table_is_view, $current_table,
        $browse_table_label, $tracking_icon,
        $GLOBALS['replication_info']['slave']['status'],
        $browse_table, $tbl_url_query, $search_table, $db_is_system_schema,
        $titles, $empty_table, $drop_query, $drop_message, $collation,
        $formatted_size, $unit, $overhead,
        (isset ($create_time) ? $create_time : ''),
        (isset ($update_time) ? $update_time : ''),
        (isset ($check_time) ? $check_time : ''),
        $is_show_stats, $ignored, $do, $colspan_for_structure
    );
    $response->addHTML($html_output);

} // end foreach

// Show Summary
$response->addHTML('</tbody>');
$response->addHTML(
    PMA_getHtmlBodyForTableSummary(
        $num_tables, $GLOBALS['replication_info']['slave']['status'],
        $db_is_system_schema, $sum_entries, $db_collation, $is_show_stats, $sum_size,
        $overhead_size, $create_time_all, $update_time_all, $check_time_all,
        isset($approx_rows) ? $approx_rows : false
    )
);
$response->addHTML('</table>');
//check all
$response->addHTML(
    PMA_getHtmlForCheckAllTables(
        $pmaThemeImage, $text_dir, $overhead_check,
        $db_is_system_schema, $hidden_fields
    )
);
$response->addHTML('</form>'); //end of form

// display again the table list navigator
$response->addHTML(
    PMA_Util::getListNavigator(
        $total_num_tables, $pos, $_url_params, 'db_structure.php',
        'frame_content', $GLOBALS['cfg']['MaxTableList']
    )
);

$response->addHTML('</div><hr />');

/**
 * Work on the database
 */
/* DATABASE WORK */
/* Printable view of a table */
$response->addHTML(
    PMA_getHtmlForTablePrintViewLink($url_query)
    . PMA_getHtmlForDataDictionaryLink($url_query)
);

PMA_possiblyShowCreateTableDialog($db, $db_is_system_schema, $response);

?>