wrong path
[phpmyadmin/crack.git] / server_databases.php
blobbd176efa4e76265bbae94d3e61e79df781581d3f
1 <?php
2 /* $Id$ */
3 // vim: expandtab sw=4 ts=4 sts=4:
5 /**
6 * Does the common work
7 */
8 require_once './libraries/common.lib.php';
11 $js_to_run = 'functions.js';
12 require './libraries/server_common.inc.php';
14 /**
15 * Sorts the databases array according to the user's choice
17 * @param array a record associated to a database
18 * @param array a record associated to a database
20 * @return integer a value representing whether $a should be before $b in the
21 * sorted array or not
23 * @global string the column the array shall be sorted by
24 * @global string the sorting order ('asc' or 'desc')
26 * @access private
28 function PMA_dbCmp($a, $b) {
29 global $sort_by, $sort_order;
30 if ($GLOBALS['cfg']['NaturalOrder']) {
31 $sorter = 'strnatcmp';
32 } else {
33 $sorter = 'strcasecmp';
35 if ($sort_by == 'SCHEMA_NAME') {
36 return ($sort_order == 'asc' ? 1 : -1) * $sorter($a['SCHEMA_NAME'], $b['SCHEMA_NAME']);
37 } elseif ($a[$sort_by] == $b[$sort_by]) {
38 return $sorter($a['SCHEMA_NAME'], $b['SCHEMA_NAME']);
39 } else {
40 return ($sort_order == 'asc' ? 1 : -1) * ((int)$a[$sort_by] > (int)$b[$sort_by] ? 1 : -1);
42 } // end of the 'PMA_dbCmp()' function
45 /**
46 * avoids 'undefined index' errors
48 if (empty($_REQUEST['sort_by'])) {
49 $sort_by = 'SCHEMA_NAME';
50 } else {
51 $sort_by = PMA_sanitize($_REQUEST['sort_by']);
53 if (empty($_REQUEST['sort_order'])) {
54 if ($sort_by == 'SCHEMA_NAME') {
55 $sort_order = 'asc';
56 } else {
57 $sort_order = 'desc';
59 } else {
60 $sort_order = PMA_sanitize($_REQUEST['sort_order']);
63 $dbstats = empty($dbstats) ? 0 : 1;
66 /**
67 * Drops multiple databases
70 // workaround for IE behavior (it returns some coordinates based on where
71 // the mouse was on the Drop image):
72 if (isset($_REQUEST['drop_selected_dbs_x'])) {
73 $_REQUEST['drop_selected_dbs'] = true;
76 if ((isset($_REQUEST['drop_selected_dbs']) || isset($_REQUEST['query_type']))
77 && ($is_superuser || $cfg['AllowUserDropDatabase'])) {
78 if (! isset($_REQUEST['selected_dbs']) && ! isset($_REQUEST['query_type'])) {
79 $message = $strNoDatabasesSelected;
80 } else {
81 $action = 'server_databases.php';
82 $submit_mult = 'drop_db' ;
83 $err_url = 'server_databases.php?' . PMA_generate_common_url();
84 if (isset($_REQUEST['selected_dbs'])) {
85 $selected_db = $_REQUEST['selected_dbs'];
87 require './libraries/mult_submits.inc.php';
88 unset($action, $submit_mult, $err_url, $selected_db);
89 if ($mult_btn == $strYes) {
90 $message = sprintf($strDatabasesDropped, count($selected));
91 } else {
92 $message = sprintf($strDatabasesDropped, 0);
97 /**
98 * Displays the links
100 require './libraries/server_links.inc.php';
104 * Displays the sub-page heading
106 echo '<h2>' . "\n"
107 . ( $GLOBALS['cfg']['MainPageIconic']
108 ? '<img class="icon" src="' . $pmaThemeImage . 's_db.png" width="16"'
109 .' height="16" alt="" />'
110 : '' )
111 . ( $dbstats ? $strDatabasesStats : $strDatabases ) . "\n"
112 .'</h2>' . "\n";
115 * Gets the databases list
117 if ($server > 0) {
118 $databases = PMA_DBI_get_databases_full(null, $dbstats);
119 } else {
120 $databases = array();
125 * Displays the page
128 $tmp_count = count($databases);
129 if ($tmp_count > 0) {
130 if ($tmp_count > 1) {
131 // sorts the array
132 usort( $databases, 'PMA_dbCmp' );
133 } else {
134 // when there is only one database, the sort would not happen and
135 // the index would not become numeric (reproduced in MySQL 3.23.52)
136 $tmp_each = each($databases);
137 $databases = array();
138 $databases[0] = $tmp_each['value'];
139 unset($tmp_each);
142 // table col order
143 // there is no db specific collation or charset prior 4.1.0
144 if (PMA_MYSQL_INT_VERSION >= 40100) {
145 $column_order['DEFAULT_COLLATION_NAME'] = array(
146 'disp_name' => $strCollation,
147 'description_function' => 'PMA_getCollationDescr',
148 'format' => 'string',
149 'footer' => PMA_getServerCollation(),
152 $column_order['SCHEMA_TABLES'] = array(
153 'disp_name' => $strNumTables,
154 'format' => 'number',
155 'footer' => 0,
157 $column_order['SCHEMA_TABLE_ROWS'] = array(
158 'disp_name' => $strRows,
159 'format' => 'number',
160 'footer' => 0,
162 $column_order['SCHEMA_DATA_LENGTH'] = array(
163 'disp_name' => $strData,
164 'format' => 'byte',
165 'footer' => 0,
167 $column_order['SCHEMA_INDEX_LENGTH'] = array(
168 'disp_name' => $strIndexes,
169 'format' => 'byte',
170 'footer' => 0,
172 $column_order['SCHEMA_LENGTH'] = array(
173 'disp_name' => $strTotalUC,
174 'format' => 'byte',
175 'footer' => 0,
177 $column_order['SCHEMA_DATA_FREE'] = array(
178 'disp_name' => $strOverhead,
179 'format' => 'byte',
180 'footer' => 0,
183 echo '<form action="./server_databases.php" method="post" name="dbStatsForm" id="dbStatsForm">' . "\n"
184 . PMA_generate_common_hidden_inputs('', '', 1)
185 . '<input type="hidden" name="dbstats" value="' . $dbstats . '" />' . "\n"
186 . '<input type="hidden" name="sort_by" value="' . $sort_by . '" />' . "\n"
187 . '<input type="hidden" name="sort_order" value="' . $sort_order . '" />' . "\n"
188 . '<table id="tabledatabases" class="data">' . "\n"
189 . '<thead>' . "\n"
190 . '<tr>' . "\n"
191 . ($is_superuser || $cfg['AllowUserDropDatabase'] ? ' <th>&nbsp;</th>' . "\n" : '')
192 . ' <th><a href="./server_databases.php?' . $url_query . '&amp;dbstats=' . $dbstats . '&amp;sort_by=SCHEMA_NAME&amp;sort_order=' . (($sort_by == 'SCHEMA_NAME' && $sort_order == 'asc') ? 'desc' : 'asc') . '">' . "\n"
193 . ' ' . $strDatabase . "\n"
194 . ($sort_by == 'SCHEMA_NAME' ? ' <img class="icon" src="' . $pmaThemeImage . 's_' . $sort_order . '.png" width="11" height="9" alt="' . ($sort_order == 'asc' ? $strAscending : $strDescending) . '" />' . "\n" : '')
195 . ' </a></th>' . "\n";
196 $table_columns = 3;
197 foreach ( $column_order as $stat_name => $stat ) {
198 if ( array_key_exists( $stat_name, $databases[0] ) ) {
199 if ( $stat['format'] === 'byte' ) {
200 $table_columns += 2;
201 $colspan = ' colspan="2"';
202 } else {
203 $table_columns++;
204 $colspan = '';
206 echo ' <th' . $colspan . '>'
207 .'<a href="./server_databases.php?' . $url_query . '&amp;dbstats=' . (int) $dbstats . '&amp;sort_by=' . urlencode( $stat_name ) . '&amp;sort_order=' . (($sort_by == $stat_name && $sort_order == 'desc') ? 'asc' : 'desc') . '">' . "\n"
208 .' ' . $stat['disp_name'] . "\n"
209 .($sort_by == $stat_name ? ' <img class="icon" src="' . $pmaThemeImage . 's_' . $sort_order . '.png" width="11" height="9" alt="' . ($sort_order == 'asc' ? $strAscending : $strDescending) . '" />' . "\n" : '')
210 .' </a></th>' . "\n";
213 if ($is_superuser) {
214 echo ' <th>' . ($cfg['PropertiesIconic'] ? '&nbsp;' : $strAction ) . "\n"
215 . ' </th>' . "\n";
217 echo '</tr>' . "\n"
218 . '</thead>' . "\n"
219 . '<tbody>' . "\n";
221 $odd_row = true;
222 foreach ( $databases as $key => $current ) {
224 echo '<tr class="' . ( $odd_row ? 'odd' : 'even' ) . '">' . "\n";
225 $odd_row = ! $odd_row;
227 if ( $is_superuser || $cfg['AllowUserDropDatabase'] ) {
228 echo ' <td class="tool">' . "\n";
229 if ($current['SCHEMA_NAME'] != 'mysql' && (PMA_MYSQL_INT_VERSION < 50002 || $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="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"
238 . ' ' . htmlspecialchars($current['SCHEMA_NAME']) . "\n"
239 . ' </a>' . "\n"
240 . ' </td>' . "\n";
242 foreach ( $column_order as $stat_name => $stat ) {
243 if ( array_key_exists( $stat_name, $current ) ) {
244 if ( is_numeric( $stat['footer'] ) ) {
245 $column_order[$stat_name]['footer'] += $current[$stat_name];
247 if ( $stat['format'] === 'byte' ) {
248 list( $value, $unit ) = PMA_formatByteDown( $current[$stat_name], 3, 1 );
249 } elseif ( $stat['format'] === 'number' ) {
250 $value = PMA_formatNumber( $current[$stat_name], 0 );
251 } else {
252 $value = htmlentities( $current[$stat_name], 0 );
254 echo ' <td class="value">';
255 if ( isset( $stat['description_function'] ) ) {
256 echo '<dfn title="' . $stat['description_function']( $current[$stat_name] ) . '">';
258 echo $value;
259 if ( isset( $stat['description_function'] ) ) {
260 echo '</dfn>';
262 echo '</td>' . "\n";
263 if ( $stat['format'] === 'byte' ) {
264 echo ' <td class="unit">' . $unit . '</td>' . "\n";
269 if ($is_superuser) {
270 echo ' <td class="tool">' . "\n"
271 . ' <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"
272 . ' ' .($cfg['PropertiesIconic'] ? '<img class="icon" src="' . $pmaThemeImage . 's_rights.png" width="16" height="16" alt=" ' .$strCheckPrivs . '" /> ' : $strCheckPrivs ). "\n"
273 . ' </a></td>' . "\n";
275 echo '</tr>' . "\n";
276 } // end foreach ( $databases as $key => $current )
277 unset( $key, $current, $odd_row );
279 echo '<tr>' . "\n";
280 if ( $is_superuser || $cfg['AllowUserDropDatabase'] ) {
281 echo ' <th>&nbsp;</th>' . "\n";
283 echo ' <th>' . $strTotalUC . ': ' . count( $databases ) . '</th>' . "\n";
284 foreach ( $column_order as $stat_name => $stat ) {
285 if ( array_key_exists( $stat_name, $databases[0] ) ) {
286 if ( $stat['format'] === 'byte' ) {
287 list( $value, $unit ) = PMA_formatByteDown( $stat['footer'], 3, 1 );
288 } elseif ( $stat['format'] === 'number' ) {
289 $value = PMA_formatNumber( $stat['footer'], 0 );
290 } else {
291 $value = htmlentities( $stat['footer'], 0 );
293 echo ' <th class="value">';
294 if ( isset( $stat['description_function'] ) ) {
295 echo '<dfn title="' . $stat['description_function']( $stat['footer'] ) . '">';
297 echo $value;
298 if ( isset( $stat['description_function'] ) ) {
299 echo '</dfn>';
301 echo '</th>' . "\n";
302 if ( $stat['format'] === 'byte' ) {
303 echo ' <th class="unit">' . $unit . '</th>' . "\n";
307 if ( $is_superuser ) {
308 echo ' <th>&nbsp;</th>' . "\n";
310 echo '</tr>' . "\n";
311 echo '</tbody>' . "\n"
312 .'</table>' . "\n";
313 unset( $column_order, $stat_name, $stat, $databases, $table_columns );
315 if ($is_superuser || $cfg['AllowUserDropDatabase']) {
316 $common_url_query = PMA_generate_common_url() . '&amp;sort_by=' . $sort_by . '&amp;sort_order=' . $sort_order . '&amp;dbstats=' . $dbstats;
317 echo '<img class="selectallarrow" src="' . $pmaThemeImage . 'arrow_' . $text_dir . '.png" width="38" height="22" alt="' . $strWithChecked . '" />' . "\n"
318 . '<a href="./server_databases.php?' . $common_url_query . '&amp;checkall=1" onclick="if ( markAllRows(\'tabledatabases\') ) return false;">' . "\n"
319 . ' ' . $strCheckAll . '</a> / ' . "\n"
320 . '<a href="./server_databases.php?' . $common_url_query . '" onclick="if ( unMarkAllRows(\'tabledatabases\') ) return false;">' . "\n"
321 . ' ' . $strUncheckAll . '</a>' . "\n"
322 . '<i>' . $strWithChecked . '</i>' . "\n";
323 PMA_buttonOrImage( 'drop_selected_dbs', 'mult_submit', 'drop_selected_dbs', $strDrop, 'b_deltbl.png' );
326 if ( PMA_MYSQL_INT_VERSION < 50002 ) {
327 echo '<ul><li id="li_switch_dbstats"><strong>' . "\n";
328 if ( empty( $dbstats ) ) {
329 echo ' <a href="./server_databases.php?' . $url_query . '&amp;dbstats=1"'
330 .' title="' . $strDatabasesStatsEnable . '">' . "\n"
331 .' ' . $strDatabasesStatsEnable;
332 } else {
333 echo ' <a href="./server_databases.php?' . $url_query . '"'
334 .' title="' . $strDatabasesStatsDisable . '">' . "\n"
335 .' ' . $strDatabasesStatsDisable;
337 echo '</a></strong><br />' . "\n"
338 .' <div class="warning">'
339 . $strDatabasesStatsHeavyTraffic . '</div></li>' . "\n"
340 .'</ul>' . "\n";
342 echo '</form>';
343 } else {
344 echo $strNoDatabases;
346 unset($tmp_count);
349 * Create new database.
351 echo '<ul><li id="li_create_database">' . "\n";
352 require './libraries/display_create_database.lib.php';
353 echo ' </li>' . "\n";
354 echo '</ul>' . "\n";
357 * Sends the footer
359 require_once './libraries/footer.inc.php';