Move DefaultFunctions back to config.default.php
[phpmyadmin.git] / server_databases.php
blob051345dc4ed93bfccc1fd7cdf40bdcac8c990385
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';
15 require './libraries/build_html_for_db.lib.php';
17 /**
18 * avoids 'undefined index' errors
20 if (empty($_REQUEST['sort_by'])) {
21 $sort_by = 'SCHEMA_NAME';
22 } else {
23 $sort_by_whitelist = array(
24 'SCHEMA_NAME',
25 'DEFAULT_COLLATION_NAME',
26 'SCHEMA_TABLES',
27 'SCHEMA_TABLE_ROWS',
28 'SCHEMA_DATA_LENGTH',
29 'SCHEMA_INDEX_LENGTH',
30 'SCHEMA_LENGTH',
31 'SCHEMA_DATA_FREE'
33 if (in_array($_REQUEST['sort_by'], $sort_by_whitelist)) {
34 $sort_by = $_REQUEST['sort_by'];
35 } else {
36 $sort_by = 'SCHEMA_NAME';
40 if (isset($_REQUEST['sort_order'])
41 && strtolower($_REQUEST['sort_order']) == 'desc') {
42 $sort_order = 'desc';
43 } else {
44 $sort_order = 'asc';
47 $dbstats = empty($_REQUEST['dbstats']) ? 0 : 1;
48 $pos = empty($_REQUEST['pos']) ? 0 : (int) $_REQUEST['pos'];
51 /**
52 * Drops multiple databases
55 // workaround for IE behavior (it returns some coordinates based on where
56 // the mouse was on the Drop image):
57 if (isset($_REQUEST['drop_selected_dbs_x'])) {
58 $_REQUEST['drop_selected_dbs'] = true;
61 if ((isset($_REQUEST['drop_selected_dbs']) || isset($_REQUEST['query_type']))
62 && ($is_superuser || $cfg['AllowUserDropDatabase'])) {
63 if (! isset($_REQUEST['selected_dbs']) && ! isset($_REQUEST['query_type'])) {
64 $message = PMA_Message::error(__('No databases selected.'));
65 } else {
66 $action = 'server_databases.php';
67 $submit_mult = 'drop_db' ;
68 $err_url = 'server_databases.php?' . PMA_generate_common_url();
69 if (isset($_REQUEST['selected_dbs'])) {
70 $selected_db = $_REQUEST['selected_dbs'];
72 require './libraries/mult_submits.inc.php';
73 unset($action, $submit_mult, $err_url, $selected_db, $GLOBALS['db']);
74 if (empty($message)) {
75 $message = PMA_Message::success(__('%s databases have been dropped successfully.'));
76 if ($mult_btn == __('Yes')) {
77 $message->addParam(count($selected));
78 } else {
79 $message->addParam(0);
86 /**
87 * Displays the links
89 require './libraries/server_links.inc.php';
92 /**
93 * Displays the sub-page heading
95 echo '<h2>' . "\n"
96 . ($GLOBALS['cfg']['MainPageIconic']
97 ? '<img class="icon" src="' . $pmaThemeImage . 's_db.png" width="16"'
98 .' height="16" alt="" />'
99 : '')
100 . ($dbstats ? __('Databases statistics') : __('Databases')) . "\n"
101 .'</h2>' . "\n";
104 * Create database.
106 if ($cfg['ShowCreateDb']) {
107 echo '<ul><li id="li_create_database">' . "\n";
108 require './libraries/display_create_database.lib.php';
109 echo ' </li>' . "\n";
110 echo '</ul>' . "\n";
114 * Gets the databases list
116 if ($server > 0) {
117 $databases = PMA_DBI_get_databases_full(null, $dbstats, null, $sort_by,
118 $sort_order, $pos, true);
119 $databases_count = count($GLOBALS['pma']->databases);
120 } else {
121 $databases_count = 0;
126 * Displays the page
128 if ($databases_count > 0) {
129 echo '<div id="tableslistcontainer">';
130 reset($databases);
131 $first_database = current($databases);
132 // table col order
133 $column_order = PMA_getColumnOrder();
135 $_url_params = array(
136 'pos' => $pos,
137 'dbstats' => $dbstats,
138 'sort_by' => $sort_by,
139 'sort_order' => $sort_order,
142 PMA_listNavigator($databases_count, $pos, $_url_params, 'server_databases.php', 'frame_content', $GLOBALS['cfg']['MaxDbList']);
144 $_url_params['pos'] = $pos;
146 echo '<form action="./server_databases.php" method="post" name="dbStatsForm" id="dbStatsForm">' . "\n"
147 . PMA_generate_common_hidden_inputs($_url_params);
149 $_url_params['sort_by'] = 'SCHEMA_NAME';
150 $_url_params['sort_order'] = ($sort_by == 'SCHEMA_NAME' && $sort_order == 'asc') ? 'desc' : 'asc';
152 echo '<table id="tabledatabases" class="data">' . "\n"
153 . '<thead>' . "\n"
154 . '<tr>' . "\n"
155 . ($is_superuser || $cfg['AllowUserDropDatabase'] ? ' <th></th>' . "\n" : '')
156 . ' <th><a href="./server_databases.php' . PMA_generate_common_url($_url_params) . '">' . "\n"
157 . ' ' . __('Database') . "\n"
158 . ($sort_by == 'SCHEMA_NAME' ? ' <img class="icon" src="' . $pmaThemeImage . 's_' . $sort_order . '.png" width="11" height="9" alt="' . ($sort_order == 'asc' ? __('Ascending') : __('Descending')) . '" />' . "\n" : '')
159 . ' </a></th>' . "\n";
160 $table_columns = 3;
161 foreach ($column_order as $stat_name => $stat) {
162 if (array_key_exists($stat_name, $first_database)) {
163 if ($stat['format'] === 'byte') {
164 $table_columns += 2;
165 $colspan = ' colspan="2"';
166 } else {
167 $table_columns++;
168 $colspan = '';
170 $_url_params['sort_by'] = $stat_name;
171 $_url_params['sort_order'] = ($sort_by == $stat_name && $sort_order == 'desc') ? 'asc' : 'desc';
172 echo ' <th' . $colspan . '>'
173 .'<a href="./server_databases.php' . PMA_generate_common_url($_url_params) . '">' . "\n"
174 .' ' . $stat['disp_name'] . "\n"
175 .($sort_by == $stat_name ? ' <img class="icon" src="' . $pmaThemeImage . 's_' . $sort_order . '.png" width="11" height="9" alt="' . ($sort_order == 'asc' ? __('Ascending') : __('Descending')) . '" />' . "\n" : '')
176 .' </a></th>' . "\n";
180 foreach ($replication_types as $type)
182 if ($type=="master")
183 $name = __('Master replication');
184 elseif($type == "slave")
185 $name = __('Slave replication');
186 if (${"server_{$type}_status"})
187 echo ' <th>'. $name .'</th>' . "\n";
190 if ($is_superuser) {
191 echo ' <th>' . ($cfg['PropertiesIconic'] ? '' : __('Action')) . "\n"
192 . ' </th>' . "\n";
194 echo '</tr>' . "\n"
195 . '</thead>' . "\n"
196 . '<tbody>' . "\n";
198 $odd_row = true;
199 foreach ($databases as $current) {
200 $tr_class = $odd_row ? 'odd' : 'even';
201 if ($current['SCHEMA_NAME'] == 'mysql' || $current['SCHEMA_NAME'] == 'information_schema') {
202 $tr_class .= ' noclick';
204 echo '<tr class="' . $tr_class . '">' . "\n";
205 $odd_row = ! $odd_row;
207 list($column_order, $generated_html) = PMA_buildHtmlForDb($current, $is_superuser, (isset($checkall) ? $checkall : ''), $url_query, $column_order, $replication_types, $replication_info);
209 echo $generated_html;
211 echo '</tr>' . "\n";
212 } // end foreach ($databases as $key => $current)
213 unset($current, $odd_row);
215 echo '<tr id="db_summary_row">' . "\n";
216 if ($is_superuser || $cfg['AllowUserDropDatabase']) {
217 echo ' <th></th>' . "\n";
219 echo ' <th>' . __('Total') . ': <span id="databases_count">' . $databases_count . '</span></th>' . "\n";
220 foreach ($column_order as $stat_name => $stat) {
221 if (array_key_exists($stat_name, $first_database)) {
222 if ($stat['format'] === 'byte') {
223 list($value, $unit) = PMA_formatByteDown($stat['footer'], 3, 1);
224 } elseif ($stat['format'] === 'number') {
225 $value = PMA_formatNumber($stat['footer'], 0);
226 } else {
227 $value = htmlentities($stat['footer'], 0);
229 echo ' <th class="value">';
230 if (isset($stat['description_function'])) {
231 echo '<dfn title="' . $stat['description_function']($stat['footer']) . '">';
233 echo $value;
234 if (isset($stat['description_function'])) {
235 echo '</dfn>';
237 echo '</th>' . "\n";
238 if ($stat['format'] === 'byte') {
239 echo ' <th class="unit">' . $unit . '</th>' . "\n";
244 foreach ($replication_types as $type)
246 if (${"server_{$type}_status"})
247 echo ' <th></th>' . "\n";
250 if ($is_superuser) {
251 echo ' <th></th>' . "\n";
253 echo '</tr>' . "\n";
254 echo '</tbody>' . "\n"
255 .'</table>' . "\n";
256 unset($column_order, $stat_name, $stat, $databases, $table_columns);
258 if ($is_superuser || $cfg['AllowUserDropDatabase']) {
259 $common_url_query = PMA_generate_common_url(array('sort_by' => $sort_by, 'sort_order' => $sort_order, 'dbstats' => $dbstats));
260 echo '<img class="selectallarrow" src="' . $pmaThemeImage . 'arrow_' . $text_dir . '.png" width="38" height="22" alt="' . __('With selected:') . '" />' . "\n"
261 . '<a href="./server_databases.php' . $common_url_query . '&amp;checkall=1" onclick="if (markAllRows(\'tabledatabases\')) return false;">' . "\n"
262 . ' ' . __('Check All') . '</a> / ' . "\n"
263 . '<a href="./server_databases.php' . $common_url_query . '" onclick="if (unMarkAllRows(\'tabledatabases\')) return false;">' . "\n"
264 . ' ' . __('Uncheck All') . '</a>' . "\n"
265 . '<i>' . __('With selected:') . '</i>' . "\n";
266 PMA_buttonOrImage('drop_selected_dbs', 'mult_submit', 'drop_selected_dbs', __('Drop'), 'b_deltbl.png');
269 if (empty($dbstats)) {
270 echo '<ul><li id="li_switch_dbstats"><strong>' . "\n";
271 echo ' <a href="./server_databases.php?' . $url_query . '&amp;dbstats=1"'
272 .' title="' . __('Enable Statistics') . '">' . "\n"
273 .' ' . __('Enable Statistics');
274 echo '</a></strong><br />' . "\n";
275 PMA_Message::notice(__('Note: Enabling the database statistics here might cause heavy traffic between the web server and the MySQL server.'))->display();
276 echo '</li>' . "\n" . '</ul>' . "\n";
278 echo '</form>';
279 echo '</div>';
280 } else {
281 echo __('No databases');
283 unset($databases_count);
286 * Sends the footer
288 require './libraries/footer.inc.php';