Translation update done using Pootle.
[phpmyadmin/dkf.git] / server_databases.php
blob8ce1f8ed712281958f01d238dcd73726464033d5
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';
13 require './libraries/server_common.inc.php';
14 require './libraries/replication.inc.php';
16 /**
17 * avoids 'undefined index' errors
19 if (empty($_REQUEST['sort_by'])) {
20 $sort_by = 'SCHEMA_NAME';
21 } else {
22 $sort_by_whitelist = array(
23 'SCHEMA_NAME',
24 'DEFAULT_COLLATION_NAME',
25 'SCHEMA_TABLES',
26 'SCHEMA_TABLE_ROWS',
27 'SCHEMA_DATA_LENGTH',
28 'SCHEMA_INDEX_LENGTH',
29 'SCHEMA_LENGTH',
30 'SCHEMA_DATA_FREE'
32 if (in_array($_REQUEST['sort_by'], $sort_by_whitelist)) {
33 $sort_by = $_REQUEST['sort_by'];
34 } else {
35 $sort_by = 'SCHEMA_NAME';
39 if (isset($_REQUEST['sort_order'])
40 && strtolower($_REQUEST['sort_order']) == 'desc') {
41 $sort_order = 'desc';
42 } else {
43 $sort_order = 'asc';
46 $dbstats = empty($_REQUEST['dbstats']) ? 0 : 1;
47 $pos = empty($_REQUEST['pos']) ? 0 : (int) $_REQUEST['pos'];
50 /**
51 * Drops multiple databases
54 // workaround for IE behavior (it returns some coordinates based on where
55 // the mouse was on the Drop image):
56 if (isset($_REQUEST['drop_selected_dbs_x'])) {
57 $_REQUEST['drop_selected_dbs'] = true;
60 if ((isset($_REQUEST['drop_selected_dbs']) || isset($_REQUEST['query_type']))
61 && ($is_superuser || $cfg['AllowUserDropDatabase'])) {
62 if (! isset($_REQUEST['selected_dbs']) && ! isset($_REQUEST['query_type'])) {
63 $message = PMA_Message::error(__('No databases selected.'));
64 } else {
65 $action = 'server_databases.php';
66 $submit_mult = 'drop_db' ;
67 $err_url = 'server_databases.php?' . PMA_generate_common_url();
68 if (isset($_REQUEST['selected_dbs'])) {
69 $selected_db = $_REQUEST['selected_dbs'];
71 require './libraries/mult_submits.inc.php';
72 unset($action, $submit_mult, $err_url, $selected_db, $GLOBALS['db']);
73 if (empty($message)) {
74 $message = PMA_Message::success(__('%s databases have been dropped successfully.'));
75 if ($mult_btn == __('Yes')) {
76 $message->addParam(count($selected));
77 } else {
78 $message->addParam(0);
85 /**
86 * Displays the links
88 require './libraries/server_links.inc.php';
91 /**
92 * Displays the sub-page heading
94 echo '<h2>' . "\n"
95 . ($GLOBALS['cfg']['MainPageIconic']
96 ? '<img class="icon" src="' . $pmaThemeImage . 's_db.png" width="16"'
97 .' height="16" alt="" />'
98 : '')
99 . ($dbstats ? __('Databases statistics') : __('Databases')) . "\n"
100 .'</h2>' . "\n";
103 * Gets the databases list
105 if ($server > 0) {
106 $databases = PMA_DBI_get_databases_full(null, $dbstats, null, $sort_by,
107 $sort_order, $pos, true);
108 $databases_count = count($GLOBALS['pma']->databases);
109 } else {
110 $databases_count = 0;
115 * Displays the page
117 if ($databases_count > 0) {
118 reset($databases);
119 $first_database = current($databases);
120 // table col order
121 $column_order['DEFAULT_COLLATION_NAME'] = array(
122 'disp_name' => __('Collation'),
123 'description_function' => 'PMA_getCollationDescr',
124 'format' => 'string',
125 'footer' => PMA_getServerCollation(),
127 $column_order['SCHEMA_TABLES'] = array(
128 'disp_name' => __('Tables'),
129 'format' => 'number',
130 'footer' => 0,
132 $column_order['SCHEMA_TABLE_ROWS'] = array(
133 'disp_name' => __('Rows'),
134 'format' => 'number',
135 'footer' => 0,
137 $column_order['SCHEMA_DATA_LENGTH'] = array(
138 'disp_name' => __('Data'),
139 'format' => 'byte',
140 'footer' => 0,
142 $column_order['SCHEMA_INDEX_LENGTH'] = array(
143 'disp_name' => __('Indexes'),
144 'format' => 'byte',
145 'footer' => 0,
147 $column_order['SCHEMA_LENGTH'] = array(
148 'disp_name' => __('Total'),
149 'format' => 'byte',
150 'footer' => 0,
152 $column_order['SCHEMA_DATA_FREE'] = array(
153 'disp_name' => __('Overhead'),
154 'format' => 'byte',
155 'footer' => 0,
158 $_url_params = array(
159 'pos' => $pos,
160 'dbstats' => $dbstats,
161 'sort_by' => $sort_by,
162 'sort_order' => $sort_order,
165 PMA_listNavigator($databases_count, $pos, $_url_params, 'server_databases.php', 'frame_content', $GLOBALS['cfg']['MaxDbList']);
167 $_url_params['pos'] = $pos;
169 echo '<form action="./server_databases.php" method="post" name="dbStatsForm" id="dbStatsForm">' . "\n"
170 . PMA_generate_common_hidden_inputs($_url_params);
172 $_url_params['sort_by'] = 'SCHEMA_NAME';
173 $_url_params['sort_order'] = ($sort_by == 'SCHEMA_NAME' && $sort_order == 'asc') ? 'desc' : 'asc';
175 echo '<table id="tabledatabases" class="data">' . "\n"
176 . '<thead>' . "\n"
177 . '<tr>' . "\n"
178 . ($is_superuser || $cfg['AllowUserDropDatabase'] ? ' <th></th>' . "\n" : '')
179 . ' <th><a href="./server_databases.php' . PMA_generate_common_url($_url_params) . '">' . "\n"
180 . ' ' . __('Database') . "\n"
181 . ($sort_by == 'SCHEMA_NAME' ? ' <img class="icon" src="' . $pmaThemeImage . 's_' . $sort_order . '.png" width="11" height="9" alt="' . ($sort_order == 'asc' ? __('Ascending') : __('Descending')) . '" />' . "\n" : '')
182 . ' </a></th>' . "\n";
183 $table_columns = 3;
184 foreach ($column_order as $stat_name => $stat) {
185 if (array_key_exists($stat_name, $first_database)) {
186 if ($stat['format'] === 'byte') {
187 $table_columns += 2;
188 $colspan = ' colspan="2"';
189 } else {
190 $table_columns++;
191 $colspan = '';
193 $_url_params['sort_by'] = $stat_name;
194 $_url_params['sort_order'] = ($sort_by == $stat_name && $sort_order == 'desc') ? 'asc' : 'desc';
195 echo ' <th' . $colspan . '>'
196 .'<a href="./server_databases.php' . PMA_generate_common_url($_url_params) . '">' . "\n"
197 .' ' . $stat['disp_name'] . "\n"
198 .($sort_by == $stat_name ? ' <img class="icon" src="' . $pmaThemeImage . 's_' . $sort_order . '.png" width="11" height="9" alt="' . ($sort_order == 'asc' ? __('Ascending') : __('Descending')) . '" />' . "\n" : '')
199 .' </a></th>' . "\n";
203 foreach ($replication_types as $type)
205 if ($type=="master")
206 $name = __('Master replication');
207 elseif($type == "slave")
208 $name = __('Slave replication');
209 if (${"server_{$type}_status"})
210 echo ' <th>'. $name .'</th>' . "\n";
213 if ($is_superuser) {
214 echo ' <th>' . ($cfg['PropertiesIconic'] ? '' : __('Action')) . "\n"
215 . ' </th>' . "\n";
217 echo '</tr>' . "\n"
218 . '</thead>' . "\n"
219 . '<tbody>' . "\n";
221 $odd_row = true;
222 foreach ($databases as $current) {
223 echo '<tr class="' . ($odd_row ? 'odd' : 'even') . '">' . "\n";
224 $odd_row = ! $odd_row;
226 if ($is_superuser || $cfg['AllowUserDropDatabase']) {
227 echo ' <td class="tool">' . "\n";
228 if ($current['SCHEMA_NAME'] != 'mysql'
229 && $current['SCHEMA_NAME'] != 'information_schema') {
230 echo ' <input type="checkbox" name="selected_dbs[]" title="' . htmlspecialchars($current['SCHEMA_NAME']) . '" value="' . htmlspecialchars($current['SCHEMA_NAME']) . '" ' . (empty($checkall) ? '' : 'checked="checked" ') . '/>' . "\n";
231 } else {
232 echo ' <input type="checkbox" name="selected_dbs[]" title="' . htmlspecialchars($current['SCHEMA_NAME']) . '" value="' . htmlspecialchars($current['SCHEMA_NAME']) . '" disabled="disabled"/>' . "\n";
234 echo ' </td>' . "\n";
236 echo ' <td class="name">' . "\n"
237 . ' <a onclick="'
238 . 'if (window.parent.openDb &amp;&amp; window.parent.openDb(\'' . PMA_jsFormat($current['SCHEMA_NAME'], false) . '\')) return false;'
239 . '" href="index.php?' . $url_query . '&amp;db='
240 . urlencode($current['SCHEMA_NAME']) . '" title="'
241 . sprintf(__('Jump to database'), htmlspecialchars($current['SCHEMA_NAME']))
242 . '" target="_parent">' . "\n"
243 . ' ' . htmlspecialchars($current['SCHEMA_NAME']) . "\n"
244 . ' </a>' . "\n"
245 . ' </td>' . "\n";
247 foreach ($column_order as $stat_name => $stat) {
248 if (array_key_exists($stat_name, $current)) {
249 if (is_numeric($stat['footer'])) {
250 $column_order[$stat_name]['footer'] += $current[$stat_name];
252 if ($stat['format'] === 'byte') {
253 list($value, $unit) = PMA_formatByteDown($current[$stat_name], 3, 1);
254 } elseif ($stat['format'] === 'number') {
255 $value = PMA_formatNumber($current[$stat_name], 0);
256 } else {
257 $value = htmlentities($current[$stat_name], 0);
259 echo ' <td class="value">';
260 if (isset($stat['description_function'])) {
261 echo '<dfn title="' . $stat['description_function']($current[$stat_name]) . '">';
263 echo $value;
264 if (isset($stat['description_function'])) {
265 echo '</dfn>';
267 echo '</td>' . "\n";
268 if ($stat['format'] === 'byte') {
269 echo ' <td class="unit">' . $unit . '</td>' . "\n";
273 foreach ($replication_types as $type) {
274 if (${"server_{$type}_status"}) {
275 echo '<td class="tool" style="text-align: center;">' . "\n";
277 if (strlen(array_search($current["SCHEMA_NAME"], ${"server_{$type}_Ignore_DB"}))>0) {
278 echo '<img class="icon" src="' . $pmaThemeImage . 's_cancel.png" width="16" height="16" alt="' . __('Not replicated') . '" />' . "\n";
279 } else {
280 $key = array_search($current["SCHEMA_NAME"], ${"server_{$type}_Do_DB"});
282 if (strlen($key) > 0 || (${"server_{$type}_Do_DB"}[0] == "" && count(${"server_{$type}_Do_DB"}) == 1)) {
283 // if ($key != null) did not work for index "0"
284 echo '<img class="icon" src="' . $pmaThemeImage . 's_success.png" width="16" height="16" alt="' . __('Replicated') . '" />' . "\n";
285 } else {
286 echo '';
290 echo '</td>';
294 if ($is_superuser) {
295 echo ' <td class="tool">' . "\n"
296 . ' <a onclick="'
297 . 'if (window.parent.setDb) window.parent.setDb(\'' . PMA_jsFormat($current['SCHEMA_NAME']) . '\');'
298 . '" href="./server_privileges.php?' . $url_query
299 . '&amp;checkprivs=' . urlencode($current['SCHEMA_NAME'])
300 . '" title="' . sprintf(__('Check privileges for database &quot;%s&quot;.'), htmlspecialchars($current['SCHEMA_NAME']))
301 . '">'. "\n"
302 . ' '
303 . ($cfg['PropertiesIconic']
304 ? '<img class="icon" src="' . $pmaThemeImage . 's_rights.png" width="16" height="16" alt=" ' . __('Check Privileges') . '" /> '
305 : __('Check Privileges')) . "\n"
306 . ' </a></td>' . "\n";
308 echo '</tr>' . "\n";
309 } // end foreach ($databases as $key => $current)
310 unset($current, $odd_row);
312 echo '<tr id="db_summary_row">' . "\n";
313 if ($is_superuser || $cfg['AllowUserDropDatabase']) {
314 echo ' <th></th>' . "\n";
316 echo ' <th>' . __('Total') . ': ' . $databases_count . '</th>' . "\n";
317 foreach ($column_order as $stat_name => $stat) {
318 if (array_key_exists($stat_name, $first_database)) {
319 if ($stat['format'] === 'byte') {
320 list($value, $unit) = PMA_formatByteDown($stat['footer'], 3, 1);
321 } elseif ($stat['format'] === 'number') {
322 $value = PMA_formatNumber($stat['footer'], 0);
323 } else {
324 $value = htmlentities($stat['footer'], 0);
326 echo ' <th class="value">';
327 if (isset($stat['description_function'])) {
328 echo '<dfn title="' . $stat['description_function']($stat['footer']) . '">';
330 echo $value;
331 if (isset($stat['description_function'])) {
332 echo '</dfn>';
334 echo '</th>' . "\n";
335 if ($stat['format'] === 'byte') {
336 echo ' <th class="unit">' . $unit . '</th>' . "\n";
341 foreach ($replication_types as $type)
343 if (${"server_{$type}_status"})
344 echo ' <th></th>' . "\n";
347 if ($is_superuser) {
348 echo ' <th></th>' . "\n";
350 echo '</tr>' . "\n";
351 echo '</tbody>' . "\n"
352 .'</table>' . "\n";
353 unset($column_order, $stat_name, $stat, $databases, $table_columns);
355 if ($is_superuser || $cfg['AllowUserDropDatabase']) {
356 $common_url_query = PMA_generate_common_url(array('sort_by' => $sort_by, 'sort_order' => $sort_order, 'dbstats' => $dbstats));
357 echo '<img class="selectallarrow" src="' . $pmaThemeImage . 'arrow_' . $text_dir . '.png" width="38" height="22" alt="' . __('With selected:') . '" />' . "\n"
358 . '<a href="./server_databases.php' . $common_url_query . '&amp;checkall=1" onclick="if (markAllRows(\'tabledatabases\')) return false;">' . "\n"
359 . ' ' . __('Check All') . '</a> / ' . "\n"
360 . '<a href="./server_databases.php' . $common_url_query . '" onclick="if (unMarkAllRows(\'tabledatabases\')) return false;">' . "\n"
361 . ' ' . __('Uncheck All') . '</a>' . "\n"
362 . '<i>' . __('With selected:') . '</i>' . "\n";
363 PMA_buttonOrImage('drop_selected_dbs', 'mult_submit', 'drop_selected_dbs', __('Drop'), 'b_deltbl.png');
366 echo '<ul><li id="li_switch_dbstats"><strong>' . "\n";
367 if (empty($dbstats)) {
368 echo ' <a href="./server_databases.php?' . $url_query . '&amp;dbstats=1"'
369 .' title="' . __('Enable Statistics') . '">' . "\n"
370 .' ' . __('Enable Statistics');
371 } else {
372 echo ' <a href="./server_databases.php?' . $url_query . '"'
373 .' title="' . __('Disable Statistics') . '">' . "\n"
374 .' ' . __('Disable Statistics');
376 echo '</a></strong><br />' . "\n";
377 PMA_Message::warning(__('Note: Enabling the database statistics here might cause heavy traffic between the web server and the MySQL server.'))->display();
378 echo '</li>' . "\n"
379 .'</ul>' . "\n";
380 echo '</form>';
381 } else {
382 echo __('No databases');
384 unset($databases_count);
387 * Create new database.
389 if ($cfg['ShowCreateDb']) {
390 echo '<ul><li id="li_create_database">' . "\n";
391 require './libraries/display_create_database.lib.php';
392 echo ' </li>' . "\n";
393 echo '</ul>' . "\n";
397 * Sends the footer
399 require './libraries/footer.inc.php';