250 |
kaklik |
1 |
<?php |
|
|
2 |
/* $Id: server_databases.php,v 2.35.2.3 2006/03/14 17:53:44 lem9 Exp $ */ |
|
|
3 |
// vim: expandtab sw=4 ts=4 sts=4: |
|
|
4 |
|
|
|
5 |
/** |
|
|
6 |
* Does the common work |
|
|
7 |
*/ |
|
|
8 |
require_once('./libraries/common.lib.php'); |
|
|
9 |
|
|
|
10 |
|
|
|
11 |
$js_to_run = 'functions.js'; |
|
|
12 |
require('./libraries/server_common.inc.php'); |
|
|
13 |
|
|
|
14 |
/** |
|
|
15 |
* Sorts the databases array according to the user's choice |
|
|
16 |
* |
|
|
17 |
* @param array a record associated to a database |
|
|
18 |
* @param array a record associated to a database |
|
|
19 |
* |
|
|
20 |
* @return integer a value representing whether $a should be before $b in the |
|
|
21 |
* sorted array or not |
|
|
22 |
* |
|
|
23 |
* @global string the column the array shall be sorted by |
|
|
24 |
* @global string the sorting order ('asc' or 'desc') |
|
|
25 |
* |
|
|
26 |
* @access private |
|
|
27 |
*/ |
|
|
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'; |
|
|
34 |
} |
|
|
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); |
|
|
41 |
} |
|
|
42 |
} // end of the 'PMA_dbCmp()' function |
|
|
43 |
|
|
|
44 |
|
|
|
45 |
/** |
|
|
46 |
* avoids 'undefined index' errors |
|
|
47 |
*/ |
|
|
48 |
if (empty($sort_by)) { |
|
|
49 |
$sort_by = 'SCHEMA_NAME'; |
|
|
50 |
} else { |
|
|
51 |
$sort_by = PMA_sanitize($sort_by); |
|
|
52 |
} |
|
|
53 |
if (empty($sort_order)) { |
|
|
54 |
if ($sort_by == 'SCHEMA_NAME') { |
|
|
55 |
$sort_order = 'asc'; |
|
|
56 |
} else { |
|
|
57 |
$sort_order = 'desc'; |
|
|
58 |
} |
|
|
59 |
} else { |
|
|
60 |
$sort_order = PMA_sanitize($sort_order); |
|
|
61 |
} |
|
|
62 |
|
|
|
63 |
$dbstats = empty( $dbstats ) ? 0 : 1; |
|
|
64 |
|
|
|
65 |
|
|
|
66 |
/** |
|
|
67 |
* Drops multiple databases |
|
|
68 |
*/ |
|
|
69 |
|
|
|
70 |
// workaround for IE behavior (it returns some coordinates based on where |
|
|
71 |
// the mouse was on the Drop image): |
|
|
72 |
|
|
|
73 |
if (isset($drop_selected_dbs_x)) { |
|
|
74 |
$drop_selected_dbs = 'Drop'; |
|
|
75 |
} |
|
|
76 |
|
|
|
77 |
if ((!empty($drop_selected_dbs) || isset($query_type)) && ($is_superuser || $cfg['AllowUserDropDatabase'])) { |
|
|
78 |
if (! isset($selected_db) && ! isset($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 |
require('./libraries/mult_submits.inc.php'); |
|
|
85 |
if ($mult_btn == $strYes) { |
|
|
86 |
$message = sprintf($strDatabasesDropped, count($selected)); |
|
|
87 |
} else { |
|
|
88 |
$message = sprintf($strDatabasesDropped, 0); |
|
|
89 |
} |
|
|
90 |
} |
|
|
91 |
} |
|
|
92 |
|
|
|
93 |
/** |
|
|
94 |
* Displays the links |
|
|
95 |
*/ |
|
|
96 |
require('./libraries/server_links.inc.php'); |
|
|
97 |
|
|
|
98 |
|
|
|
99 |
/** |
|
|
100 |
* Displays the sub-page heading |
|
|
101 |
*/ |
|
|
102 |
echo '<h2>' . "\n" |
|
|
103 |
. ( $GLOBALS['cfg']['MainPageIconic'] |
|
|
104 |
? '<img class="icon" src="' . $pmaThemeImage . 's_db.png" width="16"' |
|
|
105 |
.' height="16" alt="" />' |
|
|
106 |
: '' ) |
|
|
107 |
. ( $dbstats ? $strDatabasesStats : $strDatabases ) . "\n" |
|
|
108 |
.'</h2>' . "\n"; |
|
|
109 |
|
|
|
110 |
/** |
|
|
111 |
* Gets the databases list |
|
|
112 |
*/ |
|
|
113 |
if ($server > 0) { |
|
|
114 |
$databases = PMA_DBI_get_databases_full(null, $dbstats); |
|
|
115 |
} else { |
|
|
116 |
$databases = array(); |
|
|
117 |
} |
|
|
118 |
|
|
|
119 |
|
|
|
120 |
/** |
|
|
121 |
* Displays the page |
|
|
122 |
*/ |
|
|
123 |
$tmp_count = count($databases); |
|
|
124 |
if ($tmp_count > 0) { |
|
|
125 |
if ($tmp_count > 1) { |
|
|
126 |
// sorts the array |
|
|
127 |
usort( $databases, 'PMA_dbCmp' ); |
|
|
128 |
} else { |
|
|
129 |
// when there is only one database, the sort would not happen and |
|
|
130 |
// the index would not become numeric (reproduced in MySQL 3.23.52) |
|
|
131 |
$tmp_each = each($databases); |
|
|
132 |
$databases = array(); |
|
|
133 |
$databases[0] = $tmp_each['value']; |
|
|
134 |
unset($tmp_each); |
|
|
135 |
} |
|
|
136 |
|
|
|
137 |
// table col order |
|
|
138 |
// there is no db specific collation or charset prior 4.1.0 |
|
|
139 |
if (PMA_MYSQL_INT_VERSION >= 40100) { |
|
|
140 |
$column_order['DEFAULT_COLLATION_NAME'] = array( |
|
|
141 |
'disp_name' => $strCollation, |
|
|
142 |
'description_function' => 'PMA_getCollationDescr', |
|
|
143 |
'format' => 'string', |
|
|
144 |
'footer' => PMA_getServerCollation(), |
|
|
145 |
); |
|
|
146 |
} |
|
|
147 |
$column_order['SCHEMA_TABLES'] = array( |
|
|
148 |
'disp_name' => $strNumTables, |
|
|
149 |
'format' => 'number', |
|
|
150 |
'footer' => 0, |
|
|
151 |
); |
|
|
152 |
$column_order['SCHEMA_TABLE_ROWS'] = array( |
|
|
153 |
'disp_name' => $strRows, |
|
|
154 |
'format' => 'number', |
|
|
155 |
'footer' => 0, |
|
|
156 |
); |
|
|
157 |
$column_order['SCHEMA_DATA_LENGTH'] = array( |
|
|
158 |
'disp_name' => $strData, |
|
|
159 |
'format' => 'byte', |
|
|
160 |
'footer' => 0, |
|
|
161 |
); |
|
|
162 |
$column_order['SCHEMA_INDEX_LENGTH'] = array( |
|
|
163 |
'disp_name' => $strIndexes, |
|
|
164 |
'format' => 'byte', |
|
|
165 |
'footer' => 0, |
|
|
166 |
); |
|
|
167 |
$column_order['SCHEMA_LENGTH'] = array( |
|
|
168 |
'disp_name' => $strTotalUC, |
|
|
169 |
'format' => 'byte', |
|
|
170 |
'footer' => 0, |
|
|
171 |
); |
|
|
172 |
$column_order['SCHEMA_DATA_FREE'] = array( |
|
|
173 |
'disp_name' => $strOverhead, |
|
|
174 |
'format' => 'byte', |
|
|
175 |
'footer' => 0, |
|
|
176 |
); |
|
|
177 |
|
|
|
178 |
echo '<form action="./server_databases.php" method="post" name="dbStatsForm" id="dbStatsForm">' . "\n" |
|
|
179 |
. PMA_generate_common_hidden_inputs('', '', 1) |
|
|
180 |
. '<input type="hidden" name="dbstats" value="' . $dbstats . '" />' . "\n" |
|
|
181 |
. '<input type="hidden" name="sort_by" value="' . $sort_by . '" />' . "\n" |
|
|
182 |
. '<input type="hidden" name="sort_order" value="' . $sort_order . '" />' . "\n" |
|
|
183 |
. '<table id="tabledatabases" class="data">' . "\n" |
|
|
184 |
. '<thead>' . "\n" |
|
|
185 |
. '<tr>' . "\n" |
|
|
186 |
. ($is_superuser || $cfg['AllowUserDropDatabase'] ? ' <th> </th>' . "\n" : '') |
|
|
187 |
. ' <th><a href="./server_databases.php?' . $url_query . '&dbstats=' . $dbstats . '&sort_by=SCHEMA_NAME&sort_order=' . (($sort_by == 'SCHEMA_NAME' && $sort_order == 'asc') ? 'desc' : 'asc') . '">' . "\n" |
|
|
188 |
. ' ' . $strDatabase . "\n" |
|
|
189 |
. ($sort_by == 'SCHEMA_NAME' ? ' <img class="icon" src="' . $pmaThemeImage . 's_' . $sort_order . '.png" width="11" height="9" alt="' . ($sort_order == 'asc' ? $strAscending : $strDescending) . '" />' . "\n" : '') |
|
|
190 |
. ' </a></th>' . "\n"; |
|
|
191 |
$table_columns = 3; |
|
|
192 |
foreach ( $column_order as $stat_name => $stat ) { |
|
|
193 |
if ( array_key_exists( $stat_name, $databases[0] ) ) { |
|
|
194 |
if ( $stat['format'] === 'byte' ) { |
|
|
195 |
$table_columns += 2; |
|
|
196 |
$colspan = ' colspan="2"'; |
|
|
197 |
} else { |
|
|
198 |
$table_columns++; |
|
|
199 |
$colspan = ''; |
|
|
200 |
} |
|
|
201 |
echo ' <th' . $colspan . '>' |
|
|
202 |
.'<a href="./server_databases.php?' . $url_query . '&dbstats=' . (int) $dbstats . '&sort_by=' . urlencode( $stat_name ) . '&sort_order=' . (($sort_by == $stat_name && $sort_order == 'desc') ? 'asc' : 'desc') . '">' . "\n" |
|
|
203 |
.' ' . $stat['disp_name'] . "\n" |
|
|
204 |
.($sort_by == $stat_name ? ' <img class="icon" src="' . $pmaThemeImage . 's_' . $sort_order . '.png" width="11" height="9" alt="' . ($sort_order == 'asc' ? $strAscending : $strDescending) . '" />' . "\n" : '') |
|
|
205 |
.' </a></th>' . "\n"; |
|
|
206 |
} |
|
|
207 |
} |
|
|
208 |
if ($is_superuser) { |
|
|
209 |
echo ' <th>' . ($cfg['PropertiesIconic'] ? ' ' : $strAction ) . "\n" |
|
|
210 |
. ' </th>' . "\n"; |
|
|
211 |
} |
|
|
212 |
echo '</tr>' . "\n" |
|
|
213 |
. '</thead>' . "\n" |
|
|
214 |
. '<tbody>' . "\n"; |
|
|
215 |
|
|
|
216 |
$odd_row = true; |
|
|
217 |
foreach ( $databases as $key => $current ) { |
|
|
218 |
|
|
|
219 |
echo '<tr class="' . ( $odd_row ? 'odd' : 'even' ) . '">' . "\n"; |
|
|
220 |
$odd_row = ! $odd_row; |
|
|
221 |
|
|
|
222 |
if ( $is_superuser || $cfg['AllowUserDropDatabase'] ) { |
|
|
223 |
echo ' <td class="tool">' . "\n"; |
|
|
224 |
if ($current['SCHEMA_NAME'] != 'mysql' && (PMA_MYSQL_INT_VERSION < 50002 || $current['SCHEMA_NAME'] != 'information_schema')) { |
|
|
225 |
echo ' <input type="checkbox" name="selected_db[]" title="' . htmlspecialchars($current['SCHEMA_NAME']) . '" value="' . htmlspecialchars($current['SCHEMA_NAME']) . '" ' . (empty($checkall) ? '' : 'checked="checked" ') . '/>' . "\n"; |
|
|
226 |
} else { |
|
|
227 |
echo ' <input type="checkbox" name="selected_db[]" title="' . htmlspecialchars($current['SCHEMA_NAME']) . '" value="' . htmlspecialchars($current['SCHEMA_NAME']) . '" disabled="disabled"/>' . "\n"; |
|
|
228 |
} |
|
|
229 |
echo ' </td>' . "\n"; |
|
|
230 |
} |
|
|
231 |
echo ' <td class="name">' . "\n" |
|
|
232 |
. ' <a onclick="if ( window.parent.openDb(\'' . urlencode($current['SCHEMA_NAME']) . '\') ) return false;" href="index.php?' . $url_query . '&db=' . urlencode($current['SCHEMA_NAME']) . '" title="' . sprintf($strJumpToDB, htmlspecialchars($current['SCHEMA_NAME'])) . '" target="_parent">' . "\n" |
|
|
233 |
. ' ' . htmlspecialchars($current['SCHEMA_NAME']) . "\n" |
|
|
234 |
. ' </a>' . "\n" |
|
|
235 |
. ' </td>' . "\n"; |
|
|
236 |
|
|
|
237 |
foreach ( $column_order as $stat_name => $stat ) { |
|
|
238 |
if ( array_key_exists( $stat_name, $current ) ) { |
|
|
239 |
if ( is_numeric( $stat['footer'] ) ) { |
|
|
240 |
$column_order[$stat_name]['footer'] += $current[$stat_name]; |
|
|
241 |
} |
|
|
242 |
if ( $stat['format'] === 'byte' ) { |
|
|
243 |
list( $value, $unit ) = PMA_formatByteDown( $current[$stat_name], 3, 1 ); |
|
|
244 |
} elseif ( $stat['format'] === 'number' ) { |
|
|
245 |
$value = PMA_formatNumber( $current[$stat_name], 0 ); |
|
|
246 |
} else { |
|
|
247 |
$value = htmlentities( $current[$stat_name], 0 ); |
|
|
248 |
} |
|
|
249 |
echo ' <td class="value">'; |
|
|
250 |
if ( isset( $stat['description_function'] ) ) { |
|
|
251 |
echo '<dfn title="' . $stat['description_function']( $current[$stat_name] ) . '">'; |
|
|
252 |
} |
|
|
253 |
echo $value; |
|
|
254 |
if ( isset( $stat['description_function'] ) ) { |
|
|
255 |
echo '</dfn>'; |
|
|
256 |
} |
|
|
257 |
echo '</td>' . "\n"; |
|
|
258 |
if ( $stat['format'] === 'byte' ) { |
|
|
259 |
echo ' <td class="unit">' . $unit . '</td>' . "\n"; |
|
|
260 |
} |
|
|
261 |
} |
|
|
262 |
} |
|
|
263 |
|
|
|
264 |
if ($is_superuser) { |
|
|
265 |
echo ' <td class="tool">' . "\n" |
|
|
266 |
. ' <a onclick="window.parent.setDb(\'' . urlencode($current['SCHEMA_NAME']) . '\');" href="./server_privileges.php?' . $url_query . '&checkprivs=' . urlencode($current['SCHEMA_NAME']) . '" title="' . sprintf($strCheckPrivsLong, htmlspecialchars($current['SCHEMA_NAME'])) . '">'. "\n" |
|
|
267 |
. ' ' .($cfg['PropertiesIconic'] ? '<img class="icon" src="' . $pmaThemeImage . 's_rights.png" width="16" height="16" alt=" ' .$strCheckPrivs . '" /> ' : $strCheckPrivs ). "\n" |
|
|
268 |
. ' </a></td>' . "\n"; |
|
|
269 |
} |
|
|
270 |
echo '</tr>' . "\n"; |
|
|
271 |
} // end foreach ( $databases as $key => $current ) |
|
|
272 |
unset( $key, $current, $odd_row ); |
|
|
273 |
|
|
|
274 |
echo '<tr>' . "\n"; |
|
|
275 |
if ( $is_superuser || $cfg['AllowUserDropDatabase'] ) { |
|
|
276 |
echo ' <th> </th>' . "\n"; |
|
|
277 |
} |
|
|
278 |
echo ' <th>' . $strTotalUC . ': ' . count( $databases ) . '</th>' . "\n"; |
|
|
279 |
foreach ( $column_order as $stat_name => $stat ) { |
|
|
280 |
if ( array_key_exists( $stat_name, $databases[0] ) ) { |
|
|
281 |
if ( $stat['format'] === 'byte' ) { |
|
|
282 |
list( $value, $unit ) = PMA_formatByteDown( $stat['footer'], 3, 1 ); |
|
|
283 |
} elseif ( $stat['format'] === 'number' ) { |
|
|
284 |
$value = PMA_formatNumber( $stat['footer'], 0 ); |
|
|
285 |
} else { |
|
|
286 |
$value = htmlentities( $stat['footer'], 0 ); |
|
|
287 |
} |
|
|
288 |
echo ' <th class="value">'; |
|
|
289 |
if ( isset( $stat['description_function'] ) ) { |
|
|
290 |
echo '<dfn title="' . $stat['description_function']( $stat['footer'] ) . '">'; |
|
|
291 |
} |
|
|
292 |
echo $value; |
|
|
293 |
if ( isset( $stat['description_function'] ) ) { |
|
|
294 |
echo '</dfn>'; |
|
|
295 |
} |
|
|
296 |
echo '</th>' . "\n"; |
|
|
297 |
if ( $stat['format'] === 'byte' ) { |
|
|
298 |
echo ' <th class="unit">' . $unit . '</th>' . "\n"; |
|
|
299 |
} |
|
|
300 |
} |
|
|
301 |
} |
|
|
302 |
if ( $is_superuser ) { |
|
|
303 |
echo ' <th> </th>' . "\n"; |
|
|
304 |
} |
|
|
305 |
echo '</tr>' . "\n"; |
|
|
306 |
echo '</tbody>' . "\n" |
|
|
307 |
.'</table>' . "\n"; |
|
|
308 |
unset( $column_order, $stat_name, $stat, $databases, $table_columns ); |
|
|
309 |
|
|
|
310 |
if ($is_superuser || $cfg['AllowUserDropDatabase']) { |
|
|
311 |
$common_url_query = PMA_generate_common_url() . '&sort_by=' . $sort_by . '&sort_order=' . $sort_order . '&dbstats=' . $dbstats; |
|
|
312 |
echo '<img class="selectallarrow" src="' . $pmaThemeImage . 'arrow_' . $text_dir . '.png" width="38" height="22" alt="' . $strWithChecked . '" />' . "\n" |
|
|
313 |
. '<a href="./server_databases.php?' . $common_url_query . '&checkall=1" onclick="if ( markAllRows(\'tabledatabases\') ) return false;">' . "\n" |
|
|
314 |
. ' ' . $strCheckAll . '</a> / ' . "\n" |
|
|
315 |
. '<a href="./server_databases.php?' . $common_url_query . '" onclick="if ( unMarkAllRows(\'tabledatabases\') ) return false;">' . "\n" |
|
|
316 |
. ' ' . $strUncheckAll . '</a>' . "\n" |
|
|
317 |
. '<i>' . $strWithChecked . '</i>' . "\n"; |
|
|
318 |
PMA_buttonOrImage( 'drop_selected_dbs', 'mult_submit', 'drop_selected_dbs', $strDrop, 'b_deltbl.png' ); |
|
|
319 |
} |
|
|
320 |
|
|
|
321 |
if ( PMA_MYSQL_INT_VERSION < 50002 ) { |
|
|
322 |
echo '<ul><li id="li_switch_dbstats"><strong>' . "\n"; |
|
|
323 |
if ( empty( $dbstats ) ) { |
|
|
324 |
echo ' <a href="./server_databases.php?' . $url_query . '&dbstats=1"' |
|
|
325 |
.' title="' . $strDatabasesStatsEnable . '">' . "\n" |
|
|
326 |
.' ' . $strDatabasesStatsEnable; |
|
|
327 |
} else { |
|
|
328 |
echo ' <a href="./server_databases.php?' . $url_query . '"' |
|
|
329 |
.' title="' . $strDatabasesStatsDisable . '">' . "\n" |
|
|
330 |
.' ' . $strDatabasesStatsDisable; |
|
|
331 |
} |
|
|
332 |
echo '</a></strong><br />' . "\n" |
|
|
333 |
.' <div class="warning">' |
|
|
334 |
. $strDatabasesStatsHeavyTraffic . '</div></li>' . "\n" |
|
|
335 |
.'</ul>' . "\n"; |
|
|
336 |
} |
|
|
337 |
echo '</form>'; |
|
|
338 |
} else { |
|
|
339 |
echo $strNoDatabases; |
|
|
340 |
} |
|
|
341 |
unset($tmp_count); |
|
|
342 |
|
|
|
343 |
/** |
|
|
344 |
* Create new database. |
|
|
345 |
*/ |
|
|
346 |
echo '<ul><li id="li_create_database">' . "\n"; |
|
|
347 |
require('./libraries/display_create_database.lib.php'); |
|
|
348 |
echo ' </li>' . "\n"; |
|
|
349 |
echo '</ul>' . "\n"; |
|
|
350 |
|
|
|
351 |
/** |
|
|
352 |
* Sends the footer |
|
|
353 |
*/ |
|
|
354 |
require_once('./libraries/footer.inc.php'); |
|
|
355 |
|
|
|
356 |
?> |