bugfix: use true/false for boolean values read from <select>s instead of 1/0
[phpmyadmin.git] / server_databases.php
blob7aeee672cda4d0782d20c94fec8ce09a59a3ac5b
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 = PMA_sanitize($_REQUEST['sort_by']);
25 if (isset($_REQUEST['sort_order'])
26 && strtolower($_REQUEST['sort_order']) == 'desc') {
27 $sort_order = 'desc';
28 } else {
29 $sort_order = 'asc';
32 $dbstats = empty($_REQUEST['dbstats']) ? 0 : 1;
33 $pos = empty($_REQUEST['pos']) ? 0 : (int) $_REQUEST['pos'];
36 /**
37 * Drops multiple databases
40 // workaround for IE behavior (it returns some coordinates based on where
41 // the mouse was on the Drop image):
42 if (isset($_REQUEST['drop_selected_dbs_x'])) {
43 $_REQUEST['drop_selected_dbs'] = true;
46 if ((isset($_REQUEST['drop_selected_dbs']) || isset($_REQUEST['query_type']))
47 && ($is_superuser || $cfg['AllowUserDropDatabase'])) {
48 if (! isset($_REQUEST['selected_dbs']) && ! isset($_REQUEST['query_type'])) {
49 $message = PMA_Message::error(__('No databases selected.'));
50 } else {
51 $action = 'server_databases.php';
52 $submit_mult = 'drop_db' ;
53 $err_url = 'server_databases.php?' . PMA_generate_common_url();
54 if (isset($_REQUEST['selected_dbs'])) {
55 $selected_db = $_REQUEST['selected_dbs'];
57 require './libraries/mult_submits.inc.php';
58 unset($action, $submit_mult, $err_url, $selected_db, $GLOBALS['db']);
59 if (empty($message)) {
60 $message = PMA_Message::success(__('%s databases have been dropped successfully.'));
61 if ($mult_btn == __('Yes')) {
62 $message->addParam(count($selected));
63 } else {
64 $message->addParam(0);
71 /**
72 * Displays the links
74 require './libraries/server_links.inc.php';
77 /**
78 * Displays the sub-page heading
80 echo '<h2>' . "\n"
81 . ($GLOBALS['cfg']['MainPageIconic']
82 ? '<img class="icon" src="' . $pmaThemeImage . 's_db.png" width="16"'
83 .' height="16" alt="" />'
84 : '')
85 . ($dbstats ? __('Databases statistics') : __('Databases')) . "\n"
86 .'</h2>' . "\n";
88 /**
89 * Gets the databases list
91 if ($server > 0) {
92 $databases = PMA_DBI_get_databases_full(null, $dbstats, null, $sort_by,
93 $sort_order, $pos, true);
94 $databases_count = count($GLOBALS['pma']->databases);
95 } else {
96 $databases_count = 0;
101 * Displays the page
103 if ($databases_count > 0) {
104 reset($databases);
105 $first_database = current($databases);
106 // table col order
107 $column_order['DEFAULT_COLLATION_NAME'] = array(
108 'disp_name' => __('Collation'),
109 'description_function' => 'PMA_getCollationDescr',
110 'format' => 'string',
111 'footer' => PMA_getServerCollation(),
113 $column_order['SCHEMA_TABLES'] = array(
114 'disp_name' => __('Tables'),
115 'format' => 'number',
116 'footer' => 0,
118 $column_order['SCHEMA_TABLE_ROWS'] = array(
119 'disp_name' => __('Rows'),
120 'format' => 'number',
121 'footer' => 0,
123 $column_order['SCHEMA_DATA_LENGTH'] = array(
124 'disp_name' => __('Data'),
125 'format' => 'byte',
126 'footer' => 0,
128 $column_order['SCHEMA_INDEX_LENGTH'] = array(
129 'disp_name' => __('Indexes'),
130 'format' => 'byte',
131 'footer' => 0,
133 $column_order['SCHEMA_LENGTH'] = array(
134 'disp_name' => __('Total'),
135 'format' => 'byte',
136 'footer' => 0,
138 $column_order['SCHEMA_DATA_FREE'] = array(
139 'disp_name' => __('Overhead'),
140 'format' => 'byte',
141 'footer' => 0,
144 $_url_params = array(
145 'pos' => $pos,
146 'dbstats' => $dbstats,
147 'sort_by' => $sort_by,
148 'sort_order' => $sort_order,
151 PMA_listNavigator($databases_count, $pos, $_url_params, 'server_databases.php', 'frame_content', $GLOBALS['cfg']['MaxDbList']);
153 $_url_params['pos'] = $pos;
155 echo '<form action="./server_databases.php" method="post" name="dbStatsForm" id="dbStatsForm">' . "\n"
156 . PMA_generate_common_hidden_inputs($_url_params);
158 $_url_params['sort_by'] = 'SCHEMA_NAME';
159 $_url_params['sort_order'] = ($sort_by == 'SCHEMA_NAME' && $sort_order == 'asc') ? 'desc' : 'asc';
161 echo '<table id="tabledatabases" class="data">' . "\n"
162 . '<thead>' . "\n"
163 . '<tr>' . "\n"
164 . ($is_superuser || $cfg['AllowUserDropDatabase'] ? ' <th></th>' . "\n" : '')
165 . ' <th><a href="./server_databases.php' . PMA_generate_common_url($_url_params) . '">' . "\n"
166 . ' ' . __('Database') . "\n"
167 . ($sort_by == 'SCHEMA_NAME' ? ' <img class="icon" src="' . $pmaThemeImage . 's_' . $sort_order . '.png" width="11" height="9" alt="' . ($sort_order == 'asc' ? __('Ascending') : __('Descending')) . '" />' . "\n" : '')
168 . ' </a></th>' . "\n";
169 $table_columns = 3;
170 foreach ($column_order as $stat_name => $stat) {
171 if (array_key_exists($stat_name, $first_database)) {
172 if ($stat['format'] === 'byte') {
173 $table_columns += 2;
174 $colspan = ' colspan="2"';
175 } else {
176 $table_columns++;
177 $colspan = '';
179 $_url_params['sort_by'] = $stat_name;
180 $_url_params['sort_order'] = ($sort_by == $stat_name && $sort_order == 'desc') ? 'asc' : 'desc';
181 echo ' <th' . $colspan . '>'
182 .'<a href="./server_databases.php' . PMA_generate_common_url($_url_params) . '">' . "\n"
183 .' ' . $stat['disp_name'] . "\n"
184 .($sort_by == $stat_name ? ' <img class="icon" src="' . $pmaThemeImage . 's_' . $sort_order . '.png" width="11" height="9" alt="' . ($sort_order == 'asc' ? __('Ascending') : __('Descending')) . '" />' . "\n" : '')
185 .' </a></th>' . "\n";
189 foreach ($replication_types as $type)
191 if ($type=="master")
192 $name = __('Master replication');
193 elseif($type == "slave")
194 $name = __('Slave replication');
195 if (${"server_{$type}_status"})
196 echo ' <th>'. $name .'</th>' . "\n";
199 if ($is_superuser) {
200 echo ' <th>' . ($cfg['PropertiesIconic'] ? '' : __('Action')) . "\n"
201 . ' </th>' . "\n";
203 echo '</tr>' . "\n"
204 . '</thead>' . "\n"
205 . '<tbody>' . "\n";
207 $odd_row = true;
208 foreach ($databases as $current) {
209 echo '<tr class="' . ($odd_row ? 'odd' : 'even') . '">' . "\n";
210 $odd_row = ! $odd_row;
212 if ($is_superuser || $cfg['AllowUserDropDatabase']) {
213 echo ' <td class="tool">' . "\n";
214 if ($current['SCHEMA_NAME'] != 'mysql'
215 && $current['SCHEMA_NAME'] != 'information_schema') {
216 echo ' <input type="checkbox" name="selected_dbs[]" title="' . htmlspecialchars($current['SCHEMA_NAME']) . '" value="' . htmlspecialchars($current['SCHEMA_NAME']) . '" ' . (empty($checkall) ? '' : 'checked="checked" ') . '/>' . "\n";
217 } else {
218 echo ' <input type="checkbox" name="selected_dbs[]" title="' . htmlspecialchars($current['SCHEMA_NAME']) . '" value="' . htmlspecialchars($current['SCHEMA_NAME']) . '" disabled="disabled"/>' . "\n";
220 echo ' </td>' . "\n";
222 echo ' <td class="name">' . "\n"
223 . ' <a onclick="'
224 . 'if (window.parent.openDb &amp;&amp; window.parent.openDb(\'' . PMA_jsFormat($current['SCHEMA_NAME'], false) . '\')) return false;'
225 . '" href="index.php?' . $url_query . '&amp;db='
226 . urlencode($current['SCHEMA_NAME']) . '" title="'
227 . sprintf(__('Jump to database'), htmlspecialchars($current['SCHEMA_NAME']))
228 . '" target="_parent">' . "\n"
229 . ' ' . htmlspecialchars($current['SCHEMA_NAME']) . "\n"
230 . ' </a>' . "\n"
231 . ' </td>' . "\n";
233 foreach ($column_order as $stat_name => $stat) {
234 if (array_key_exists($stat_name, $current)) {
235 if (is_numeric($stat['footer'])) {
236 $column_order[$stat_name]['footer'] += $current[$stat_name];
238 if ($stat['format'] === 'byte') {
239 list($value, $unit) = PMA_formatByteDown($current[$stat_name], 3, 1);
240 } elseif ($stat['format'] === 'number') {
241 $value = PMA_formatNumber($current[$stat_name], 0);
242 } else {
243 $value = htmlentities($current[$stat_name], 0);
245 echo ' <td class="value">';
246 if (isset($stat['description_function'])) {
247 echo '<dfn title="' . $stat['description_function']($current[$stat_name]) . '">';
249 echo $value;
250 if (isset($stat['description_function'])) {
251 echo '</dfn>';
253 echo '</td>' . "\n";
254 if ($stat['format'] === 'byte') {
255 echo ' <td class="unit">' . $unit . '</td>' . "\n";
259 foreach ($replication_types as $type) {
260 if (${"server_{$type}_status"}) {
261 echo '<td class="tool" style="text-align: center;">' . "\n";
263 if (strlen(array_search($current["SCHEMA_NAME"], ${"server_{$type}_Ignore_DB"}))>0) {
264 echo '<img class="icon" src="' . $pmaThemeImage . 's_cancel.png" width="16" height="16" alt="' . __('Not replicated') . '" />' . "\n";
265 } else {
266 $key = array_search($current["SCHEMA_NAME"], ${"server_{$type}_Do_DB"});
268 if (strlen($key) > 0 || (${"server_{$type}_Do_DB"}[0] == "" && count(${"server_{$type}_Do_DB"}) == 1)) {
269 // if ($key != null) did not work for index "0"
270 echo '<img class="icon" src="' . $pmaThemeImage . 's_success.png" width="16" height="16" alt="' . __('Replicated') . '" />' . "\n";
271 } else {
272 echo '';
276 echo '</td>';
280 if ($is_superuser) {
281 echo ' <td class="tool">' . "\n"
282 . ' <a onclick="'
283 . 'if (window.parent.setDb) window.parent.setDb(\'' . PMA_jsFormat($current['SCHEMA_NAME']) . '\');'
284 . '" href="./server_privileges.php?' . $url_query
285 . '&amp;checkprivs=' . urlencode($current['SCHEMA_NAME'])
286 . '" title="' . sprintf(__('Check privileges for database &quot;%s&quot;.'), htmlspecialchars($current['SCHEMA_NAME']))
287 . '">'. "\n"
288 . ' '
289 . ($cfg['PropertiesIconic']
290 ? '<img class="icon" src="' . $pmaThemeImage . 's_rights.png" width="16" height="16" alt=" ' . __('Check Privileges') . '" /> '
291 : __('Check Privileges')) . "\n"
292 . ' </a></td>' . "\n";
294 echo '</tr>' . "\n";
295 } // end foreach ($databases as $key => $current)
296 unset($current, $odd_row);
298 echo '<tr>' . "\n";
299 if ($is_superuser || $cfg['AllowUserDropDatabase']) {
300 echo ' <th></th>' . "\n";
302 echo ' <th>' . __('Total') . ': ' . $databases_count . '</th>' . "\n";
303 foreach ($column_order as $stat_name => $stat) {
304 if (array_key_exists($stat_name, $first_database)) {
305 if ($stat['format'] === 'byte') {
306 list($value, $unit) = PMA_formatByteDown($stat['footer'], 3, 1);
307 } elseif ($stat['format'] === 'number') {
308 $value = PMA_formatNumber($stat['footer'], 0);
309 } else {
310 $value = htmlentities($stat['footer'], 0);
312 echo ' <th class="value">';
313 if (isset($stat['description_function'])) {
314 echo '<dfn title="' . $stat['description_function']($stat['footer']) . '">';
316 echo $value;
317 if (isset($stat['description_function'])) {
318 echo '</dfn>';
320 echo '</th>' . "\n";
321 if ($stat['format'] === 'byte') {
322 echo ' <th class="unit">' . $unit . '</th>' . "\n";
327 foreach ($replication_types as $type)
329 if (${"server_{$type}_status"})
330 echo ' <th></th>' . "\n";
333 if ($is_superuser) {
334 echo ' <th></th>' . "\n";
336 echo '</tr>' . "\n";
337 echo '</tbody>' . "\n"
338 .'</table>' . "\n";
339 unset($column_order, $stat_name, $stat, $databases, $table_columns);
341 if ($is_superuser || $cfg['AllowUserDropDatabase']) {
342 $common_url_query = PMA_generate_common_url() . '&amp;sort_by=' . $sort_by . '&amp;sort_order=' . $sort_order . '&amp;dbstats=' . $dbstats;
343 echo '<img class="selectallarrow" src="' . $pmaThemeImage . 'arrow_' . $text_dir . '.png" width="38" height="22" alt="' . __('With selected:') . '" />' . "\n"
344 . '<a href="./server_databases.php?' . $common_url_query . '&amp;checkall=1" onclick="if (markAllRows(\'tabledatabases\')) return false;">' . "\n"
345 . ' ' . __('Check All') . '</a> / ' . "\n"
346 . '<a href="./server_databases.php?' . $common_url_query . '" onclick="if (unMarkAllRows(\'tabledatabases\')) return false;">' . "\n"
347 . ' ' . __('Uncheck All') . '</a>' . "\n"
348 . '<i>' . __('With selected:') . '</i>' . "\n";
349 PMA_buttonOrImage('drop_selected_dbs', 'mult_submit', 'drop_selected_dbs', __('Drop'), 'b_deltbl.png');
352 echo '<ul><li id="li_switch_dbstats"><strong>' . "\n";
353 if (empty($dbstats)) {
354 echo ' <a href="./server_databases.php?' . $url_query . '&amp;dbstats=1"'
355 .' title="' . __('Enable Statistics') . '">' . "\n"
356 .' ' . __('Enable Statistics');
357 } else {
358 echo ' <a href="./server_databases.php?' . $url_query . '"'
359 .' title="' . __('Disable Statistics') . '">' . "\n"
360 .' ' . __('Disable Statistics');
362 echo '</a></strong><br />' . "\n";
363 PMA_Message::warning(__('Note: Enabling the database statistics here might cause heavy traffic between the web server and the MySQL server.'))->display();
364 echo '</li>' . "\n"
365 .'</ul>' . "\n";
366 echo '</form>';
367 } else {
368 echo __('No databases');
370 unset($databases_count);
373 * Create new database.
375 if ($cfg['ShowCreateDb']) {
376 echo '<ul><li id="li_create_database">' . "\n";
377 require './libraries/display_create_database.lib.php';
378 echo ' </li>' . "\n";
379 echo '</ul>' . "\n";
383 * Sends the footer
385 require './libraries/footer.inc.php';