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

server_databases.lib.php « libraries - github.com/phpmyadmin/phpmyadmin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: d66e0dbf2ab5fb2259330f15bc53700e809a8622 (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
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */

/**
 * functions for displaying server databases
 *
 * @usedby  server_databases.php
 *
 * @package PhpMyAdmin
 */
if (! defined('PHPMYADMIN')) {
    exit;
}

/**
 * Returns the html for Database List
 *
 * @param Array  $databases         GBI return databases
 * @param int    $databases_count   database count
 * @param int    $pos               display pos
 * @param Array  $dbstats           database status
 * @param string $sort_by           sort by string
 * @param string $sort_order        sort order string
 * @param bool   $is_superuser      User status
 * @param Array  $cfg               configuration
 * @param string $replication_types replication types
 * @param string $replication_info  replication info
 * @param string $url_query         url query
 *
 * @return string
 */
function PMA_getHtmlForDatabase(
    $databases, $databases_count, $pos, $dbstats,
    $sort_by, $sort_order, $is_superuser, $cfg,
    $replication_types, $replication_info, $url_query
) {
    $html = '<div id="tableslistcontainer">';
    reset($databases);
    $first_database = current($databases);
    // table col order
    $column_order = PMA_getColumnOrder();

    $_url_params = array(
        'pos' => $pos,
        'dbstats' => $dbstats,
        'sort_by' => $sort_by,
        'sort_order' => $sort_order,
    );

    $html .= PMA_Util::getListNavigator(
        $databases_count, $pos, $_url_params, 'server_databases.php',
        'frame_content', $GLOBALS['cfg']['MaxDbList']
    );

    $_url_params['pos'] = $pos;

    $html .= '<form class="ajax" action="server_databases.php" ';
    $html .= 'method="post" name="dbStatsForm" id="dbStatsForm">' . "\n";
    $html .= PMA_URL_getHiddenInputs($_url_params);

    $_url_params['sort_by'] = 'SCHEMA_NAME';
    $_url_params['sort_order']
        = ($sort_by == 'SCHEMA_NAME' && $sort_order == 'asc') ? 'desc' : 'asc';

    $html .= '<table id="tabledatabases" class="data">' . "\n"
        . '<thead>' . "\n"
        . '<tr>' . "\n";

    $html .= PMA_getHtmlForColumnOrderWithSort(
        $is_superuser,
        $cfg['AllowUserDropDatabase'],
        $_url_params,
        $sort_by,
        $sort_order,
        $column_order,
        $first_database
    );

    $html .= PMA_getHtmlForReplicationType(
        $is_superuser,
        $replication_types,
        $cfg['ActionLinksMode']
    );

    $html .= '</tr>' . "\n"
        . '</thead>' . "\n";

    list($output, $column_order) = PMA_getHtmlAndColumnOrderForDatabaseList(
        $databases,
        $is_superuser,
        $url_query,
        $column_order,
        $replication_types,
        $replication_info
    );
    $html .= $output;
    unset($output);

    $html .= PMA_getHtmlForTableFooter(
        $cfg['AllowUserDropDatabase'],
        $is_superuser,
        $databases_count,
        $column_order,
        $replication_types,
        $first_database
    );

    $html .= '</table>' . "\n";

    $html .= PMA_getHtmlForTableFooterButtons(
        $cfg['AllowUserDropDatabase'],
        $is_superuser
    );

    if (empty($dbstats)) {
        //we should put notice above database list
        $html = PMA_getHtmlForNoticeEnableStatistics($url_query, $html);
    }
    $html .= '</form>';
    $html .= '</div>';

    return $html;
}

/**
 * Returns the html for Table footer buttons
 *
 * @param bool $is_allowUserDropDb Allow user drop database
 * @param bool $is_superuser       User status
 *
 * @return string
 */
function PMA_getHtmlForTableFooterButtons($is_allowUserDropDb, $is_superuser)
{
    if (!$is_superuser && !$is_allowUserDropDb) {
        return '';
    }

    $html = '<img class="selectallarrow" src="'
        . $GLOBALS['pmaThemeImage'] . 'arrow_' . $GLOBALS['text_dir'] . '.png"'
        . ' width="38" height="22" alt="' . __('With selected:') . '" />' . "\n"
        . '<input type="checkbox" id="dbStatsForm_checkall" '
        . 'class="checkall_box" title="' . __('Check All') . '" /> '
        . '<label for="dbStatsForm_checkall">' . __('Check All') . '</label> '
        . '<i style="margin-left: 2em">' . __('With selected:') . '</i>' . "\n";
    $html .= PMA_Util::getButtonOrImage(
        '',
        'mult_submit' . ' ajax',
        'drop_selected_dbs',
        __('Drop'), 'b_deltbl.png'
    );

    return $html;
}

/**
 * Returns the html for Table footer
 *
 * @param bool   $is_allowUserDropDb Allow user drop database
 * @param bool   $is_superuser       User status
 * @param int    $databases_count    Database count
 * @param string $column_order       column order
 * @param array  $replication_types  replication types
 * @param string $first_database     First database
 *
 * @return string
 */
function PMA_getHtmlForTableFooter(
    $is_allowUserDropDb, $is_superuser,
    $databases_count, $column_order,
    $replication_types, $first_database
) {
    $html = '<tfoot><tr>' . "\n";
    if ($is_superuser || $is_allowUserDropDb) {
        $html .= '    <th></th>' . "\n";
    }
    $html .= '    <th>' . __('Total') . ': <span id="databases_count">'
        . $databases_count . '</span></th>' . "\n";

    $html .= PMA_getHtmlForColumnOrder($column_order, $first_database);

    foreach ($replication_types as $type) {
        if ($GLOBALS['replication_info'][$type]['status']) {
            $html .= '    <th></th>' . "\n";
        }
    }

    if ($is_superuser) {
        $html .= '    <th></th>' . "\n";
    }
    $html .= '</tr>' . "\n";
    $html .= '</tfoot>' . "\n";
    return $html;
}

/**
 * Returns the html for Database List and Column order
 *
 * @param array  $databases         GBI return databases
 * @param bool   $is_superuser      User status
 * @param Array  $url_query         Url query
 * @param string $column_order      column order
 * @param string $replication_types replication types
 * @param string $replication_info  replication info
 *
 * @return Array
 */
function PMA_getHtmlAndColumnOrderForDatabaseList(
    $databases, $is_superuser, $url_query,
    $column_order, $replication_types, $replication_info
) {
    $odd_row = true;
    $html = '<tbody>' . "\n";

    foreach ($databases as $current) {
        $tr_class = $odd_row ? 'odd' : 'even';
        if ($GLOBALS['dbi']->isSystemSchema($current['SCHEMA_NAME'], true)) {
            $tr_class .= ' noclick';
        }
        $html .= '<tr class="' . $tr_class . '">' . "\n";
        $odd_row = ! $odd_row;

        list($column_order, $generated_html) = PMA_buildHtmlForDb(
            $current,
            $is_superuser,
            $url_query,
            $column_order,
            $replication_types,
            $replication_info
        );

        $html .= $generated_html;

        $html .= '</tr>' . "\n";
    } // end foreach ($databases as $key => $current)
    unset($current, $odd_row);
    $html .= '</tbody>';
    return array($html, $column_order);
}

/**
 * Returns the html for Column Order
 *
 * @param array $column_order   Column order
 * @param array $first_database The first display database
 *
 * @return string
 */
function PMA_getHtmlForColumnOrder($column_order, $first_database)
{
    $html = "";
    // avoid execution path notice
    $unit = "";
    foreach ($column_order as $stat_name => $stat) {
        if (array_key_exists($stat_name, $first_database)) {
            if ($stat['format'] === 'byte') {
                list($value, $unit)
                    = PMA_Util::formatByteDown($stat['footer'], 3, 1);
            } elseif ($stat['format'] === 'number') {
                $value = PMA_Util::formatNumber($stat['footer'], 0);
            } else {
                $value = htmlentities($stat['footer'], 0);
            }
            $html .= '    <th class="value">';
            if (isset($stat['description_function'])) {
                $html .= '<dfn title="'
                    . $stat['description_function']($stat['footer']) . '">';
            }
            $html .= $value;
            if (isset($stat['description_function'])) {
                $html .= '</dfn>';
            }
            $html .= '</th>' . "\n";
            if ($stat['format'] === 'byte') {
                $html .= '    <th class="unit">' . $unit . '</th>' . "\n";
            }
        }
    }

    return $html;
}


/**
 * Returns the html for Column Order with Sort
 *
 * @param bool   $is_superuser       User status
 * @param bool   $is_allowUserDropDb Allow user drop database
 * @param Array  $_url_params        Url params
 * @param string $sort_by            sort column name
 * @param string $sort_order         order
 * @param array  $column_order       column order
 * @param array  $first_database     database to show
 *
 * @return string
 */
function PMA_getHtmlForColumnOrderWithSort(
    $is_superuser, $is_allowUserDropDb,
    $_url_params, $sort_by, $sort_order,
    $column_order, $first_database
) {
    $html = ($is_superuser || $is_allowUserDropDb
        ? '        <th></th>' . "\n"
        : '')
        . '    <th><a href="server_databases.php'
        . PMA_URL_getCommon($_url_params) . '">' . "\n"
        . '            ' . __('Database') . "\n"
        . ($sort_by == 'SCHEMA_NAME'
            ? '                ' . PMA_Util::getImage(
                's_' . $sort_order . '.png',
                ($sort_order == 'asc' ? __('Ascending') : __('Descending'))
            ) . "\n"
            : ''
          )
        . '        </a></th>' . "\n";
    $table_columns = 3;
    foreach ($column_order as $stat_name => $stat) {
        if (!array_key_exists($stat_name, $first_database)) {
            continue;
        }

        if ($stat['format'] === 'byte') {
            $table_columns += 2;
            $colspan = ' colspan="2"';
        } else {
            $table_columns++;
            $colspan = '';
        }
        $_url_params['sort_by'] = $stat_name;
        $_url_params['sort_order']
            = ($sort_by == $stat_name && $sort_order == 'desc') ? 'asc' : 'desc';
        $html .= '    <th' . $colspan . '>'
            . '<a href="server_databases.php'
            . PMA_URL_getCommon($_url_params) . '">' . "\n"
            . '            ' . $stat['disp_name'] . "\n"
            . ($sort_by == $stat_name
                ? '            ' . PMA_Util::getImage(
                    's_' . $sort_order . '.png',
                    ($sort_order == 'asc' ? __('Ascending') : __('Descending'))
                ) . "\n"
                : ''
              )
            . '        </a></th>' . "\n";
    }
    return $html;
}


/**
 * Returns the html for Enable Statistics
 *
 * @param bool   $url_query Url query
 * @param string $html      html for database list
 *
 * @return string
 */
function PMA_getHtmlForNoticeEnableStatistics($url_query, $html)
{
    $notice = PMA_Message::notice(
        __(
            'Note: Enabling the database statistics here might cause '
            . 'heavy traffic between the web server and the MySQL server.'
        )
    )->getDisplay();
    //we should put notice above database list
    $html  = $notice . $html;
    $html .= '<ul><li id="li_switch_dbstats"><strong>' . "\n";
    $html .= '<a href="server_databases.php' . $url_query . '&amp;dbstats=1"'
        . ' title="' . __('Enable Statistics') . '">' . "\n"
        . '            ' . __('Enable Statistics');
    $html .= '</a></strong><br />' . "\n";
    $html .= '</li>' . "\n" . '</ul>' . "\n";

    return $html;
}

/**
 * Returns the html for database replication types
 *
 * @param bool  $is_superuser      User status
 * @param Array $replication_types replication types
 * @param bool  $cfg_iconic        cfg about Properties Iconic
 *
 * @return string
 */
function PMA_getHtmlForReplicationType(
    $is_superuser, $replication_types, $cfg_iconic
) {
    $html = '';
    foreach ($replication_types as $type) {
        if ($type == "master") {
            $name = __('Master replication');
        } elseif ($type == "slave") {
            $name = __('Slave replication');
        }

        if ($GLOBALS['replication_info'][$type]['status']) {
            $html .= '    <th>' . $name . '</th>' . "\n";
        }
    }

    if ($is_superuser && ! PMA_DRIZZLE) {
        $html .= '    <th>' . ($cfg_iconic ? '' : __('Action')) . "\n"
            . '    </th>' . "\n";
    }
    return $html;
}

/**
 * Returns the array about $sort_order and $sort_by
 *
 * @return Array
 */
function PMA_getListForSortDatabase()
{
    if (empty($_REQUEST['sort_by'])) {
        $sort_by = 'SCHEMA_NAME';
    } else {
        $sort_by_whitelist = array(
            'SCHEMA_NAME',
            'DEFAULT_COLLATION_NAME',
            'SCHEMA_TABLES',
            'SCHEMA_TABLE_ROWS',
            'SCHEMA_DATA_LENGTH',
            'SCHEMA_INDEX_LENGTH',
            'SCHEMA_LENGTH',
            'SCHEMA_DATA_FREE'
        );
        if (in_array($_REQUEST['sort_by'], $sort_by_whitelist)) {
            $sort_by = $_REQUEST['sort_by'];
        } else {
            $sort_by = 'SCHEMA_NAME';
        }
    }

    if (isset($_REQUEST['sort_order'])
        && /*overload*/mb_strtolower($_REQUEST['sort_order']) == 'desc'
    ) {
        $sort_order = 'desc';
    } else {
        $sort_order = 'asc';
    }

    return array($sort_by, $sort_order);
}

/**
 * Deal with Drops multiple databases
 *
 * @return null
 */
function PMA_dropMultiDatabases()
{
    if (! isset($_REQUEST['selected_dbs']) && ! isset($_REQUEST['query_type'])) {
        $message = PMA_Message::error(__('No databases selected.'));
    } else {
        $action = 'server_databases.php';
        $submit_mult = 'drop_db';
        $err_url = 'server_databases.php' . PMA_URL_getCommon();
        if (isset($_REQUEST['selected_dbs'])
            && !isset($_REQUEST['is_js_confirmed'])
        ) {
            $selected_db = $_REQUEST['selected_dbs'];
        }
        if (isset($_REQUEST['is_js_confirmed'])) {
            $_REQUEST = array(
                'query_type' => $submit_mult,
                'selected' => $_REQUEST['selected_dbs'],
                'mult_btn' => __('Yes'),
                'db' => $GLOBALS['db'],
                'table' => $GLOBALS['table']);
        }
        //the following variables will be used on mult_submits.inc.php
        global $query_type, $selected, $mult_btn;

        include 'libraries/mult_submits.inc.php';
        unset($action, $submit_mult, $err_url, $selected_db, $GLOBALS['db']);
        if (empty($message)) {
            if ($mult_btn == __('Yes')) {
                $number_of_databases = count($selected);
            } else {
                $number_of_databases = 0;
            }
            $message = PMA_Message::success(
                _ngettext(
                    '%1$d database has been dropped successfully.',
                    '%1$d databases have been dropped successfully.',
                    $number_of_databases
                )
            );
            $message->addParam($number_of_databases);
        }
    }
    if ($GLOBALS['is_ajax_request'] && $message instanceof PMA_Message) {
        $response = PMA_Response::getInstance();
        $response->isSuccess($message->isSuccess());
        $response->addJSON('message', $message);
        exit;
    }
}

?>