Translated using Weblate (French)
[phpmyadmin.git] / server_databases.php
blob0cda459aff0fd84fb9dbc26a4f76136532ffa833
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
5 * @package PhpMyAdmin
6 */
8 /**
9 * Does the common work
11 require_once 'libraries/common.inc.php';
12 $response = PMA_Response::getInstance();
13 $header = $response->getHeader();
14 $scripts = $header->getScripts();
15 $scripts->addFile('server_databases.js');
17 require 'libraries/server_common.inc.php';
18 if (! PMA_DRIZZLE) {
19 include_once 'libraries/replication.inc.php';
20 } else {
21 $replication_types = array();
22 $replication_info = null;
24 require 'libraries/build_html_for_db.lib.php';
26 /**
27 * Sets globals from $_POST
29 $post_params = array(
30 'mult_btn',
31 'query_type',
32 'selected'
34 foreach ($post_params as $one_post_param) {
35 if (isset($_POST[$one_post_param])) {
36 $GLOBALS[$one_post_param] = $_POST[$one_post_param];
40 /**
41 * avoids 'undefined index' errors
43 if (empty($_REQUEST['sort_by'])) {
44 $sort_by = 'SCHEMA_NAME';
45 } else {
46 $sort_by_whitelist = array(
47 'SCHEMA_NAME',
48 'DEFAULT_COLLATION_NAME',
49 'SCHEMA_TABLES',
50 'SCHEMA_TABLE_ROWS',
51 'SCHEMA_DATA_LENGTH',
52 'SCHEMA_INDEX_LENGTH',
53 'SCHEMA_LENGTH',
54 'SCHEMA_DATA_FREE'
56 if (in_array($_REQUEST['sort_by'], $sort_by_whitelist)) {
57 $sort_by = $_REQUEST['sort_by'];
58 } else {
59 $sort_by = 'SCHEMA_NAME';
63 if (isset($_REQUEST['sort_order'])
64 && strtolower($_REQUEST['sort_order']) == 'desc'
65 ) {
66 $sort_order = 'desc';
67 } else {
68 $sort_order = 'asc';
71 $dbstats = empty($_REQUEST['dbstats']) ? 0 : 1;
72 $pos = empty($_REQUEST['pos']) ? 0 : (int) $_REQUEST['pos'];
75 /**
76 * Drops multiple databases
79 // workaround for IE behavior (it returns some coordinates based on where
80 // the mouse was on the Drop image):
81 if (isset($_REQUEST['drop_selected_dbs_x'])) {
82 $_REQUEST['drop_selected_dbs'] = true;
85 if ((isset($_REQUEST['drop_selected_dbs']) || isset($_REQUEST['query_type']))
86 && ($is_superuser || $cfg['AllowUserDropDatabase'])
87 ) {
88 if (! isset($_REQUEST['selected_dbs']) && ! isset($_REQUEST['query_type'])) {
89 $message = PMA_Message::error(__('No databases selected.'));
90 } else {
91 $action = 'server_databases.php';
92 $submit_mult = 'drop_db';
93 $err_url = 'server_databases.php?' . PMA_generate_common_url();
94 if (isset($_REQUEST['selected_dbs'])
95 && !isset($_REQUEST['is_js_confirmed'])
96 ) {
97 $selected_db = $_REQUEST['selected_dbs'];
99 if (isset($_REQUEST['is_js_confirmed'])) {
100 $_REQUEST = array(
101 'query_type' => $submit_mult,
102 'selected' => $_REQUEST['selected_dbs'],
103 'mult_btn' => __('Yes'),
104 'db' => $GLOBALS['db'],
105 'table' => $GLOBALS['table']);
107 include 'libraries/mult_submits.inc.php';
108 unset($action, $submit_mult, $err_url, $selected_db, $GLOBALS['db']);
109 if (empty($message)) {
110 if ($mult_btn == __('Yes')) {
111 $number_of_databases = count($selected);
112 } else {
113 $number_of_databases = 0;
115 $message = PMA_Message::success(
116 _ngettext(
117 '%1$d database has been dropped successfully.',
118 '%1$d databases have been dropped successfully.',
119 $number_of_databases
122 $message->addParam($number_of_databases);
125 if ($GLOBALS['is_ajax_request'] && $message instanceof PMA_Message) {
126 $response = PMA_Response::getInstance();
127 $response->isSuccess($message->isSuccess());
128 $response->addJSON('message', $message);
129 exit;
134 * Displays the sub-page heading
136 echo '<h2>' . "\n"
137 . PMA_Util::getImage('s_db.png')
138 . ($dbstats ? __('Databases statistics') : __('Databases')) . "\n"
139 .'</h2>' . "\n";
142 * Create database.
144 if ($cfg['ShowCreateDb']) {
145 echo '<ul><li id="li_create_database" class="no_bullets">' . "\n";
146 include 'libraries/display_create_database.lib.php';
147 echo ' </li>' . "\n";
148 echo '</ul>' . "\n";
152 * Gets the databases list
154 if ($server > 0) {
155 $databases = PMA_DBI_get_databases_full(
156 null, $dbstats, null, $sort_by, $sort_order, $pos, true
158 $databases_count = count($GLOBALS['pma']->databases);
159 } else {
160 $databases_count = 0;
165 * Displays the page
167 if ($databases_count > 0) {
168 echo '<div id="tableslistcontainer">';
169 reset($databases);
170 $first_database = current($databases);
171 // table col order
172 $column_order = PMA_getColumnOrder();
174 $_url_params = array(
175 'pos' => $pos,
176 'dbstats' => $dbstats,
177 'sort_by' => $sort_by,
178 'sort_order' => $sort_order,
181 echo PMA_Util::getListNavigator(
182 $databases_count, $pos, $_url_params, 'server_databases.php',
183 'frame_content', $GLOBALS['cfg']['MaxDbList']
186 $_url_params['pos'] = $pos;
187 $_url_params['drop_selected_dbs'] = 1;
189 echo '<form class="ajax" action="server_databases.php" ';
190 echo 'method="post" name="dbStatsForm" id="dbStatsForm">' . "\n";
191 echo PMA_generate_common_hidden_inputs($_url_params);
193 $_url_params['sort_by'] = 'SCHEMA_NAME';
194 $_url_params['sort_order'] = ($sort_by == 'SCHEMA_NAME' && $sort_order == 'asc') ? 'desc' : 'asc';
196 echo '<table id="tabledatabases" class="data">' . "\n"
197 . '<thead>' . "\n"
198 . '<tr>' . "\n"
199 . ($is_superuser || $cfg['AllowUserDropDatabase'] ? ' <th></th>' . "\n" : '')
200 . ' <th><a href="server_databases.php' . PMA_generate_common_url($_url_params) . '">' . "\n"
201 . ' ' . __('Database') . "\n"
202 . ($sort_by == 'SCHEMA_NAME' ? ' ' . PMA_Util::getImage('s_' . $sort_order . '.png', ($sort_order == 'asc' ? __('Ascending') : __('Descending'))) . "\n" : '')
203 . ' </a></th>' . "\n";
204 $table_columns = 3;
205 foreach ($column_order as $stat_name => $stat) {
206 if (array_key_exists($stat_name, $first_database)) {
207 if ($stat['format'] === 'byte') {
208 $table_columns += 2;
209 $colspan = ' colspan="2"';
210 } else {
211 $table_columns++;
212 $colspan = '';
214 $_url_params['sort_by'] = $stat_name;
215 $_url_params['sort_order'] = ($sort_by == $stat_name && $sort_order == 'desc') ? 'asc' : 'desc';
216 echo ' <th' . $colspan . '>'
217 . '<a href="server_databases.php' . PMA_generate_common_url($_url_params) . '">' . "\n"
218 . ' ' . $stat['disp_name'] . "\n"
219 . ($sort_by == $stat_name ? ' ' . PMA_Util::getImage('s_' . $sort_order . '.png', ($sort_order == 'asc' ? __('Ascending') : __('Descending'))) . "\n" : '')
220 . ' </a></th>' . "\n";
224 foreach ($replication_types as $type) {
225 if ($type=="master") {
226 $name = __('Master replication');
227 } elseif ($type == "slave") {
228 $name = __('Slave replication');
230 if (${"server_{$type}_status"}) {
231 echo ' <th>'. $name .'</th>' . "\n";
235 if ($is_superuser && ! PMA_DRIZZLE) {
236 echo ' <th>' . ($cfg['PropertiesIconic'] ? '' : __('Action')) . "\n"
237 . ' </th>' . "\n";
239 echo '</tr>' . "\n"
240 . '</thead>' . "\n"
241 . '<tbody>' . "\n";
243 $odd_row = true;
244 foreach ($databases as $current) {
245 $tr_class = $odd_row ? 'odd' : 'even';
246 if (PMA_is_system_schema($current['SCHEMA_NAME'], true)) {
247 $tr_class .= ' noclick';
249 echo '<tr class="' . $tr_class . '">' . "\n";
250 $odd_row = ! $odd_row;
252 list($column_order, $generated_html) = PMA_buildHtmlForDb(
253 $current,
254 $is_superuser,
255 $url_query,
256 $column_order,
257 $replication_types,
258 $replication_info
261 echo $generated_html;
263 echo '</tr>' . "\n";
264 } // end foreach ($databases as $key => $current)
265 unset($current, $odd_row);
267 echo '</tbody><tfoot><tr>' . "\n";
268 if ($is_superuser || $cfg['AllowUserDropDatabase']) {
269 echo ' <th></th>' . "\n";
271 echo ' <th>' . __('Total') . ': <span id="databases_count">' . $databases_count . '</span></th>' . "\n";
272 foreach ($column_order as $stat_name => $stat) {
273 if (array_key_exists($stat_name, $first_database)) {
274 if ($stat['format'] === 'byte') {
275 list($value, $unit) = PMA_Util::formatByteDown($stat['footer'], 3, 1);
276 } elseif ($stat['format'] === 'number') {
277 $value = PMA_Util::formatNumber($stat['footer'], 0);
278 } else {
279 $value = htmlentities($stat['footer'], 0);
281 echo ' <th class="value">';
282 if (isset($stat['description_function'])) {
283 echo '<dfn title="' . $stat['description_function']($stat['footer']) . '">';
285 echo $value;
286 if (isset($stat['description_function'])) {
287 echo '</dfn>';
289 echo '</th>' . "\n";
290 if ($stat['format'] === 'byte') {
291 echo ' <th class="unit">' . $unit . '</th>' . "\n";
296 foreach ($replication_types as $type) {
297 if (${"server_{$type}_status"}) {
298 echo ' <th></th>' . "\n";
302 if ($is_superuser) {
303 echo ' <th></th>' . "\n";
305 echo '</tr>' . "\n";
306 echo '</tfoot>' . "\n"
307 .'</table>' . "\n";
308 unset($column_order, $stat_name, $stat, $databases, $table_columns);
310 if ($is_superuser || $cfg['AllowUserDropDatabase']) {
311 $common_url_query = PMA_generate_common_url(
312 array(
313 'sort_by' => $sort_by,
314 'sort_order' => $sort_order,
315 'dbstats' => $dbstats
318 echo '<img class="selectallarrow" src="' . $pmaThemeImage . 'arrow_' . $text_dir . '.png"'
319 . ' width="38" height="22" alt="' . __('With selected:') . '" />' . "\n"
320 . '<input type="checkbox" id="checkall" title="' . __('Check All') . '" /> '
321 . '<label for="checkall">' . __('Check All') . '</label> '
322 . '<i style="margin-left: 2em">' . __('With selected:') . '</i>' . "\n";
323 echo PMA_Util::getButtonOrImage(
325 'mult_submit' . ' ajax',
326 'drop_selected_dbs',
327 __('Drop'), 'b_deltbl.png'
331 if (empty($dbstats)) {
332 echo '<ul><li id="li_switch_dbstats"><strong>' . "\n";
333 echo '<a href="server_databases.php?' . $url_query . '&amp;dbstats=1"'
334 . ' title="' . __('Enable Statistics') . '">' . "\n"
335 . ' ' . __('Enable Statistics');
336 echo '</a></strong><br />' . "\n";
337 PMA_Message::notice(
338 __('Note: Enabling the database statistics here might cause heavy traffic between the web server and the MySQL server.')
339 )->display();
340 echo '</li>' . "\n" . '</ul>' . "\n";
342 echo '</form>';
343 echo '</div>';
344 } else {
345 echo __('No databases');
347 unset($databases_count);