sanitize $after_field
[phpmyadmin/dkf.git] / server_databases.php
blobb9b8898b0e438e22b25532686436d011559d5b59
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
5 * @version $Id$
6 */
8 /**
9 * Does the common work
11 require_once './libraries/common.inc.php';
14 $js_to_run = 'functions.js';
15 require './libraries/server_common.inc.php';
17 /**
18 * avoids 'undefined index' errors
20 if (empty($_REQUEST['sort_by'])) {
21 $sort_by = 'SCHEMA_NAME';
22 } else {
23 $sort_by = PMA_sanitize($_REQUEST['sort_by']);
26 if (isset($_REQUEST['sort_order'])
27 && strtolower($_REQUEST['sort_order']) == 'desc') {
28 $sort_order = 'desc';
29 } else {
30 $sort_order = 'asc';
33 $dbstats = empty($_REQUEST['dbstats']) ? 0 : 1;
34 $pos = empty($_REQUEST['pos']) ? 0 : (int) $_REQUEST['pos'];
37 /**
38 * Drops multiple databases
41 // workaround for IE behavior (it returns some coordinates based on where
42 // the mouse was on the Drop image):
43 if (isset($_REQUEST['drop_selected_dbs_x'])) {
44 $_REQUEST['drop_selected_dbs'] = true;
47 if ((isset($_REQUEST['drop_selected_dbs']) || isset($_REQUEST['query_type']))
48 && ($is_superuser || $cfg['AllowUserDropDatabase'])) {
49 if (! isset($_REQUEST['selected_dbs']) && ! isset($_REQUEST['query_type'])) {
50 $message = $strNoDatabasesSelected;
51 } else {
52 $action = 'server_databases.php';
53 $submit_mult = 'drop_db' ;
54 $err_url = 'server_databases.php?' . PMA_generate_common_url();
55 if (isset($_REQUEST['selected_dbs'])) {
56 $selected_db = $_REQUEST['selected_dbs'];
58 require './libraries/mult_submits.inc.php';
59 unset($action, $submit_mult, $err_url, $selected_db);
60 if ($mult_btn == $strYes) {
61 $message = sprintf($strDatabasesDropped, count($selected));
62 } else {
63 $message = sprintf($strDatabasesDropped, 0);
68 /**
69 * Displays the links
71 require './libraries/server_links.inc.php';
74 /**
75 * Displays the sub-page heading
77 echo '<h2>' . "\n"
78 . ($GLOBALS['cfg']['MainPageIconic']
79 ? '<img class="icon" src="' . $pmaThemeImage . 's_db.png" width="16"'
80 .' height="16" alt="" />'
81 : '')
82 . ($dbstats ? $strDatabasesStats : $strDatabases) . "\n"
83 .'</h2>' . "\n";
85 /**
86 * Gets the databases list
88 if ($server > 0) {
89 $databases = PMA_DBI_get_databases_full(null, $dbstats, null, $sort_by,
90 $sort_order, $pos, true);
91 $databases_count = $PMA_List_Database->count();
92 } else {
93 $databases_count = 0;
97 /**
98 * Displays the page
100 if ($databases_count > 0) {
101 reset($databases);
102 $first_database = current($databases);
103 // table col order
104 // there is no db specific collation or charset prior 4.1.0
105 if (PMA_MYSQL_INT_VERSION >= 40100) {
106 $column_order['DEFAULT_COLLATION_NAME'] = array(
107 'disp_name' => $strCollation,
108 'description_function' => 'PMA_getCollationDescr',
109 'format' => 'string',
110 'footer' => PMA_getServerCollation(),
113 $column_order['SCHEMA_TABLES'] = array(
114 'disp_name' => $strNumTables,
115 'format' => 'number',
116 'footer' => 0,
118 $column_order['SCHEMA_TABLE_ROWS'] = array(
119 'disp_name' => $strRows,
120 'format' => 'number',
121 'footer' => 0,
123 $column_order['SCHEMA_DATA_LENGTH'] = array(
124 'disp_name' => $strData,
125 'format' => 'byte',
126 'footer' => 0,
128 $column_order['SCHEMA_INDEX_LENGTH'] = array(
129 'disp_name' => $strIndexes,
130 'format' => 'byte',
131 'footer' => 0,
133 $column_order['SCHEMA_LENGTH'] = array(
134 'disp_name' => $strTotalUC,
135 'format' => 'byte',
136 'footer' => 0,
138 $column_order['SCHEMA_DATA_FREE'] = array(
139 'disp_name' => $strOverhead,
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>&nbsp;</th>' . "\n" : '')
165 . ' <th><a href="./server_databases.php' . PMA_generate_common_url($_url_params) . '">' . "\n"
166 . ' ' . $strDatabase . "\n"
167 . ($sort_by == 'SCHEMA_NAME' ? ' <img class="icon" src="' . $pmaThemeImage . 's_' . $sort_order . '.png" width="11" height="9" alt="' . ($sort_order == 'asc' ? $strAscending : $strDescending) . '" />' . "\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' ? $strAscending : $strDescending) . '" />' . "\n" : '')
185 .' </a></th>' . "\n";
188 if ($is_superuser) {
189 echo ' <th>' . ($cfg['PropertiesIconic'] ? '&nbsp;' : $strAction) . "\n"
190 . ' </th>' . "\n";
192 echo '</tr>' . "\n"
193 . '</thead>' . "\n"
194 . '<tbody>' . "\n";
196 $odd_row = true;
197 foreach ($databases as $current) {
198 echo '<tr class="' . ($odd_row ? 'odd' : 'even') . '">' . "\n";
199 $odd_row = ! $odd_row;
201 if ($is_superuser || $cfg['AllowUserDropDatabase']) {
202 echo ' <td class="tool">' . "\n";
203 if ($current['SCHEMA_NAME'] != 'mysql' && (PMA_MYSQL_INT_VERSION < 50002 || $current['SCHEMA_NAME'] != 'information_schema')) {
204 echo ' <input type="checkbox" name="selected_dbs[]" title="' . htmlspecialchars($current['SCHEMA_NAME']) . '" value="' . htmlspecialchars($current['SCHEMA_NAME']) . '" ' . (empty($checkall) ? '' : 'checked="checked" ') . '/>' . "\n";
205 } else {
206 echo ' <input type="checkbox" name="selected_dbs[]" title="' . htmlspecialchars($current['SCHEMA_NAME']) . '" value="' . htmlspecialchars($current['SCHEMA_NAME']) . '" disabled="disabled"/>' . "\n";
208 echo ' </td>' . "\n";
210 echo ' <td class="name">' . "\n"
211 . ' <a onclick="if (window.parent.openDb(\'' . urlencode($current['SCHEMA_NAME']) . '\')) return false;" href="index.php?' . $url_query . '&amp;db=' . urlencode($current['SCHEMA_NAME']) . '" title="' . sprintf($strJumpToDB, htmlspecialchars($current['SCHEMA_NAME'])) . '" target="_parent">' . "\n"
212 . ' ' . htmlspecialchars($current['SCHEMA_NAME']) . "\n"
213 . ' </a>' . "\n"
214 . ' </td>' . "\n";
216 foreach ($column_order as $stat_name => $stat) {
217 if (array_key_exists($stat_name, $current)) {
218 if (is_numeric($stat['footer'])) {
219 $column_order[$stat_name]['footer'] += $current[$stat_name];
221 if ($stat['format'] === 'byte') {
222 list($value, $unit) = PMA_formatByteDown($current[$stat_name], 3, 1);
223 } elseif ($stat['format'] === 'number') {
224 $value = PMA_formatNumber($current[$stat_name], 0);
225 } else {
226 $value = htmlentities($current[$stat_name], 0);
228 echo ' <td class="value">';
229 if (isset($stat['description_function'])) {
230 echo '<dfn title="' . $stat['description_function']($current[$stat_name]) . '">';
232 echo $value;
233 if (isset($stat['description_function'])) {
234 echo '</dfn>';
236 echo '</td>' . "\n";
237 if ($stat['format'] === 'byte') {
238 echo ' <td class="unit">' . $unit . '</td>' . "\n";
243 if ($is_superuser) {
244 echo ' <td class="tool">' . "\n"
245 . ' <a onclick="window.parent.setDb(\'' . urlencode($current['SCHEMA_NAME']) . '\');" href="./server_privileges.php?' . $url_query . '&amp;checkprivs=' . urlencode($current['SCHEMA_NAME']) . '" title="' . sprintf($strCheckPrivsLong, htmlspecialchars($current['SCHEMA_NAME'])) . '">'. "\n"
246 . ' ' .($cfg['PropertiesIconic'] ? '<img class="icon" src="' . $pmaThemeImage . 's_rights.png" width="16" height="16" alt=" ' .$strCheckPrivs . '" /> ' : $strCheckPrivs). "\n"
247 . ' </a></td>' . "\n";
249 echo '</tr>' . "\n";
250 } // end foreach ($databases as $key => $current)
251 unset($current, $odd_row);
253 echo '<tr>' . "\n";
254 if ($is_superuser || $cfg['AllowUserDropDatabase']) {
255 echo ' <th>&nbsp;</th>' . "\n";
257 echo ' <th>' . $strTotalUC . ': ' . $databases_count . '</th>' . "\n";
258 foreach ($column_order as $stat_name => $stat) {
259 if (array_key_exists($stat_name, $first_database)) {
260 if ($stat['format'] === 'byte') {
261 list($value, $unit) = PMA_formatByteDown($stat['footer'], 3, 1);
262 } elseif ($stat['format'] === 'number') {
263 $value = PMA_formatNumber($stat['footer'], 0);
264 } else {
265 $value = htmlentities($stat['footer'], 0);
267 echo ' <th class="value">';
268 if (isset($stat['description_function'])) {
269 echo '<dfn title="' . $stat['description_function']($stat['footer']) . '">';
271 echo $value;
272 if (isset($stat['description_function'])) {
273 echo '</dfn>';
275 echo '</th>' . "\n";
276 if ($stat['format'] === 'byte') {
277 echo ' <th class="unit">' . $unit . '</th>' . "\n";
281 if ($is_superuser) {
282 echo ' <th>&nbsp;</th>' . "\n";
284 echo '</tr>' . "\n";
285 echo '</tbody>' . "\n"
286 .'</table>' . "\n";
287 unset($column_order, $stat_name, $stat, $databases, $table_columns);
289 if ($is_superuser || $cfg['AllowUserDropDatabase']) {
290 $common_url_query = PMA_generate_common_url() . '&amp;sort_by=' . $sort_by . '&amp;sort_order=' . $sort_order . '&amp;dbstats=' . $dbstats;
291 echo '<img class="selectallarrow" src="' . $pmaThemeImage . 'arrow_' . $text_dir . '.png" width="38" height="22" alt="' . $strWithChecked . '" />' . "\n"
292 . '<a href="./server_databases.php?' . $common_url_query . '&amp;checkall=1" onclick="if (markAllRows(\'tabledatabases\')) return false;">' . "\n"
293 . ' ' . $strCheckAll . '</a> / ' . "\n"
294 . '<a href="./server_databases.php?' . $common_url_query . '" onclick="if (unMarkAllRows(\'tabledatabases\')) return false;">' . "\n"
295 . ' ' . $strUncheckAll . '</a>' . "\n"
296 . '<i>' . $strWithChecked . '</i>' . "\n";
297 PMA_buttonOrImage('drop_selected_dbs', 'mult_submit', 'drop_selected_dbs', $strDrop, 'b_deltbl.png');
300 echo '<ul><li id="li_switch_dbstats"><strong>' . "\n";
301 if (empty($dbstats)) {
302 echo ' <a href="./server_databases.php?' . $url_query . '&amp;dbstats=1"'
303 .' title="' . $strDatabasesStatsEnable . '">' . "\n"
304 .' ' . $strDatabasesStatsEnable;
305 } else {
306 echo ' <a href="./server_databases.php?' . $url_query . '"'
307 .' title="' . $strDatabasesStatsDisable . '">' . "\n"
308 .' ' . $strDatabasesStatsDisable;
310 echo '</a></strong><br />' . "\n"
311 .' <div class="warning">'
312 . $strDatabasesStatsHeavyTraffic . '</div></li>' . "\n"
313 .'</ul>' . "\n";
314 echo '</form>';
315 } else {
316 echo $strNoDatabases;
318 unset($databases_count);
321 * Create new database.
323 if ($cfg['ShowCreateDb']) {
324 echo '<ul><li id="li_create_database">' . "\n";
325 require './libraries/display_create_database.lib.php';
326 echo ' </li>' . "\n";
327 echo '</ul>' . "\n";
331 * Sends the footer
333 require_once './libraries/footer.inc.php';