2.5.3-rc2
[phpmyadmin/crack.git] / server_databases.php3
blobf8677940965d9ae0554ffd608e5d374cb81dd2db
1 <?php
2 /* $Id$ */
3 // vim: expandtab sw=4 ts=4 sts=4:
6 /**
7 * Checks if the left frame has to be reloaded
8 */
9 require('./libraries/grab_globals.lib.php3');
12 /**
13 * Does the common work
15 $js_to_run = 'functions.js';
16 require('./server_common.inc.php3');
19 /**
20 * Sorts the databases array according to the user's choice
22 * @param array a record associated to a database
23 * @param array a record associated to a database
25 * @return integer a value representing whether $a should be before $b in the
26 * sorted array or not
28 * @global string the column the array shall be sorted by
29 * @global string the sorting order ('asc' or 'desc')
31 * @access private
33 function PMA_dbCmp($a, $b)
35 global $sort_by, $sort_order;
36 if ($sort_by == 'db_name') {
37 return ($sort_order == 'asc' ? 1 : -1) * strcasecmp($a['db_name'], $b['db_name']);
38 } else if ($a[$sort_by] == $b[$sort_by]) {
39 return strcasecmp($a['db_name'], $b['db_name']);
40 } else {
41 return ($sort_order == 'asc' ? 1 : -1) * ((int)$a[$sort_by] > (int)$b[$sort_by] ? 1 : -1);
43 } // end of the 'PMA_dbCmp()' function
46 /**
47 * Gets the databases list - if it has not been built yet
49 if ($server > 0 && empty($dblist)) {
50 PMA_availableDatabases();
54 /**
55 * Drops multiple databases
57 if ((!empty($drop_selected_dbs) || isset($query_type)) && ($is_superuser || $cfg['AllowUserDropDatabase'])) {
58 if (empty($selected_db) && ! (isset($query_type) && !empty($selected))) {
59 $message = $strNoDatabasesSelected;
60 } else {
61 $action = 'server_databases.php3';
62 $submit_mult = 'drop_db' ;
63 $err_url = 'server_databases.php3?' . PMA_generate_common_url();
64 include('./mult_submits.inc.php3');
65 $message = sprintf($strDatabasesDropped, count($selected));
66 // we need to reload the database list now.
67 PMA_availableDatabases();
68 $reload = 1;
73 /**
74 * Displays the links
76 require('./server_links.inc.php3');
79 /**
80 * Displays the sub-page heading
82 echo '<h2>' . "\n"
83 . ' ' . (empty($dbstats) ? $strDatabases : $strDatabasesStats) . "\n"
84 . '</h2>' . "\n";
87 /**
88 * Checks if the user is allowed to do what he tries to...
90 if (!empty($dbstats) && (!$is_superuser || PMA_MYSQL_INT_VERSION < 32303)) {
91 echo $strNoPrivileges . "\n";
92 include('./footer.inc.php3');
93 exit;
97 /**
98 * Prepares the statistics
100 $statistics = array();
101 while (list(, $current_db) = each($dblist)) {
102 $tmp_array = array(
103 'db_name' => $current_db,
104 'tbl_cnt' => 0,
105 'data_sz' => 0,
106 'idx_sz' => 0,
107 'tot_sz' => 0
109 if (!empty($dbstats)) {
110 $res = PMA_mysql_query('SHOW TABLE STATUS FROM ' . PMA_backquote($current_db) . ';', $userlink) or PMA_mysqlDie(PMA_mysql_error($userlink), 'SHOW TABLE STATUS FROM ' . PMA_backquote($current_db) . ';');
111 while ($row = PMA_mysql_fetch_array($res, MYSQL_ASSOC)) {
112 $tmp_array['tbl_cnt']++;
113 $tmp_array['data_sz'] += $row['Data_length'];
114 $tmp_array['idx_sz'] += $row['Index_length'];
117 $tmp_array['tot_sz'] = $tmp_array['data_sz'] + $tmp_array['idx_sz'];
118 $statistics[] = $tmp_array;
121 // avoids 'undefined index' errors
122 if (empty($sort_by)) {
123 $sort_by = 'db_name';
125 if (empty($sort_order)) {
126 if ($sort_by == 'db_name') {
127 $sort_order = 'asc';
128 } else {
129 $sort_order = 'desc';
133 // sorts the array
134 usort($statistics, 'PMA_dbCmp');
138 * Displays the page
140 if (count($statistics) > 0) {
141 echo '<form action="./server_databases.php3" method="post" name="dbStatsForm">' . "\n"
142 . PMA_generate_common_hidden_inputs('', '', 1)
143 . ' <input type="hidden" name="dbstats" value="' . (empty($dbstats) ? '0' : '1') . '" />' . "\n"
144 . ' <input type="hidden" name="sort_by" value="' . $sort_by . '" />' . "\n"
145 . ' <input type="hidden" name="sort_order" value="' . $sort_order . '" />' . "\n"
146 . ' <table border="0">' . "\n"
147 . ' <tr>' . "\n"
148 . ($is_superuser || $cfg['AllowUserDropDatabase'] ? ' <th>&nbsp;</th>' . "\n" : '')
149 . ' <th>' . "\n"
150 . ' &nbsp;';
151 if (empty($dbstats)) {
152 echo $strDatabase . "\n"
153 . ' <img src="./images/asc_order.png" border="0" width="7" height="7" alt="' . $strAscending . '" />' . "\n"
154 . ' &nbsp;' . "\n"
155 . ' </th>' . "\n";
156 } else {
157 echo "\n"
158 . ' <a href="./server_databases.php3?' . $url_query . '&amp;dbstats=1&amp;sort_by=db_name&amp;sort_order=' . (($sort_by == 'db_name' && $sort_order == 'asc') ? 'desc' : 'asc') . '">' . "\n"
159 . ' ' . $strDatabase . "\n"
160 . ($sort_by == 'db_name' ? ' <img src="./images/' . $sort_order . '_order.png" border="0" width="7" height="7" alt="' . ($sort_order == 'asc' ? $strAscending : $strDescending) . '" />' . "\n" : '')
161 . ' </a>' . "\n"
162 . ' &nbsp;' . "\n"
163 . ' </th>' . "\n"
164 . ' <th>' . "\n"
165 . ' &nbsp;' . "\n"
166 . ' <a href="./server_databases.php3?' . $url_query . '&amp;dbstats=1&amp;sort_by=tbl_cnt&amp;sort_order=' . (($sort_by == 'tbl_cnt' && $sort_order == 'desc') ? 'asc' : 'desc') . '">' . "\n"
167 . ' ' . $strNumTables . "\n"
168 . ($sort_by == 'tbl_cnt' ? ' <img src="./images/' . $sort_order . '_order.png" border="0" width="7" height="7" alt="' . ($sort_order == 'asc' ? $strAscending : $strDescending) . '" />' . "\n" : '')
169 . ' </a>' . "\n"
170 . ' &nbsp;' . "\n"
171 . ' </th>' . "\n"
172 . ' <th colspan="2">' . "\n"
173 . ' &nbsp;' . "\n"
174 . ' <a href="./server_databases.php3?' . $url_query . '&amp;dbstats=1&amp;sort_by=data_sz&amp;sort_order=' . (($sort_by == 'data_sz' && $sort_order == 'desc') ? 'asc' : 'desc') . '">' . "\n"
175 . ' ' . $strData . "\n"
176 . ($sort_by == 'data_sz' ? ' <img src="./images/' . $sort_order . '_order.png" border="0" width="7" height="7" alt="' . ($sort_order == 'asc' ? $strAscending : $strDescending) . '" />' . "\n" : '')
177 . ' </a>' . "\n"
178 . ' &nbsp;' . "\n"
179 . ' </th>' . "\n"
180 . ' <th colspan="2">' . "\n"
181 . ' &nbsp;' . "\n"
182 . ' <a href="./server_databases.php3?' . $url_query . '&amp;dbstats=1&amp;sort_by=idx_sz&amp;sort_order=' . (($sort_by == 'idx_sz' && $sort_order == 'desc') ? 'asc' : 'desc') . '">' . "\n"
183 . ' ' . $strIndexes . "\n"
184 . ($sort_by == 'idx_sz' ? ' <img src="./images/' . $sort_order . '_order.png" border="0" width="7" height="7" alt="' . ($sort_order == 'asc' ? $strAscending : $strDescending) . '" />' . "\n" : '')
185 . ' </a>' . "\n"
186 . ' &nbsp;' . "\n"
187 . ' </th>' . "\n"
188 . ' <th colspan="2">' . "\n"
189 . ' &nbsp;' . "\n"
190 . ' <a href="./server_databases.php3?' . $url_query . '&amp;dbstats=1&amp;sort_by=tot_sz&amp;sort_order=' . (($sort_by == 'tot_sz' && $sort_order == 'desc') ? 'asc' : 'desc') . '">' . "\n"
191 . ' ' . $strTotalUC . "\n"
192 . ($sort_by == 'tot_sz' ? ' <img src="./images/' . $sort_order . '_order.png" border="0" width="7" height="7" alt="' . ($sort_order == 'asc' ? $strAscending : $strDescending) . '" />' . "\n" : '')
193 . ' </a>' . "\n"
194 . ' &nbsp;' . "\n"
195 . ' </th>' . "\n";
197 if ($is_superuser) {
198 echo ' <th>' . "\n"
199 . ' &nbsp;' . $strAction . '&nbsp;' . "\n"
200 . ' </th>' . "\n";
202 echo ' </tr>' . "\n";
203 $useBgcolorOne = TRUE;
204 $total_calc = array(
205 'db_cnt' => 0,
206 'tbl_cnt' => 0,
207 'data_sz' => 0,
208 'idx_sz' => 0,
209 'tot_sz' => 0
211 while (list(, $current) = each($statistics)) {
212 list($data_size, $data_unit) = PMA_formatByteDown($current['data_sz'], 3, 1);
213 list($idx_size, $idx_unit) = PMA_formatByteDown($current['idx_sz'], 3, 1);
214 list($tot_size, $tot_unit) = PMA_formatByteDown($current['tot_sz'], 3, 1);
215 $total_calc['db_cnt']++;
216 $total_calc['tbl_cnt'] += $current['tbl_cnt'];
217 $total_calc['data_sz'] += $current['data_sz'];
218 $total_calc['idx_sz'] += $current['idx_sz'];
219 $total_calc['tot_sz'] += $current['tot_sz'];
220 echo ' <tr>' . "\n";
221 if ($is_superuser || $cfg['AllowUserDropDatabase']) {
222 echo ' <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . "\n"
223 . ' <input type="checkbox" name="selected_db[]" title="' . htmlspecialchars($current['db_name']) . '" value="' . htmlspecialchars($current['db_name']) . '" ' . (empty($checkall) ? '' : 'checked="checked" ') . '/>' . "\n"
224 . ' </td>' . "\n";
226 echo ' <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . "\n"
227 . ' <a href="' . $cfg['DefaultTabDatabase'] . '?' . $url_query . '&amp;db=' . urlencode($current['db_name']) . '" title="' . sprintf($strJumpToDB, htmlspecialchars($current['db_name'])) . '">' . "\n"
228 . ' ' . htmlspecialchars($current['db_name']) . "\n"
229 . ' </a>' . "\n"
230 . ' </td>' . "\n";
231 if (!empty($dbstats)) {
232 echo ' <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '" align="right">' . "\n"
233 . ' ' . $current['tbl_cnt'] . "\n"
234 . ' </td>' . "\n"
235 . ' <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '" align="right">' . "\n"
236 . ' ' . $data_size . "\n"
237 . ' </td>' . "\n"
238 . ' <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . "\n"
239 . ' ' . $data_unit . "\n"
240 . ' </td>' . "\n"
241 . ' <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '" align="right">' . "\n"
242 . ' ' . $idx_size . "\n"
243 . ' </td>' . "\n"
244 . ' <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . "\n"
245 . ' ' . $idx_unit . "\n"
246 . ' </td>' . "\n"
247 . ' <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '" align="right">' . "\n"
248 . ' <b>' . "\n"
249 . ' ' . $tot_size . "\n"
250 . ' </b>' . "\n"
251 . ' </td>' . "\n"
252 . ' <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . "\n"
253 . ' <b>' . "\n"
254 . ' ' . $tot_unit . "\n"
255 . ' </b>' . "\n"
256 . ' </td>' . "\n";
258 if ($is_superuser) {
259 echo ' <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . "\n"
260 . ' <a href="./server_privileges.php3?' . $url_query . '&amp;checkprivs=' . urlencode($current['db_name']) . '" title="' . sprintf($strCheckPrivsLong, htmlspecialchars($current['db_name'])) . '">'. "\n"
261 . ' ' . $strCheckPrivs . "\n"
262 . ' </a>' . "\n"
263 . ' </td>' . "\n";
265 echo ' </tr>' . "\n";
266 $useBgcolorOne = !$useBgcolorOne;
267 } // end while
268 if (!empty($dbstats)) {
269 list($data_size, $data_unit) = PMA_formatByteDown($total_calc['data_sz'], 3, 1);
270 list($idx_size, $idx_unit) = PMA_formatByteDown($total_calc['idx_sz'], 3, 1);
271 list($tot_size, $tot_unit) = PMA_formatByteDown($total_calc['tot_sz'], 3, 1);
272 echo ' <tr>' . "\n"
273 . ' <th>&nbsp;</th>' . "\n"
274 . ' <th>' . "\n"
275 . ' &nbsp;' . $strTotalUC . ':&nbsp;' . $total_calc['db_cnt'] . '&nbsp;' . "\n"
276 . ' </th>' . "\n"
277 . ' <th align="right">' . "\n"
278 . ' &nbsp;' . $total_calc['tbl_cnt'] . '&nbsp;' . "\n"
279 . ' </th>' . "\n"
280 . ' <th align="right">' . "\n"
281 . ' &nbsp;' . $data_size . "\n"
282 . ' </th>' . "\n"
283 . ' <th align="left">' . "\n"
284 . ' ' . $data_unit . '&nbsp;' . "\n"
285 . ' </th>' . "\n"
286 . ' <th align="right">' . "\n"
287 . ' &nbsp;' . $idx_size . "\n"
288 . ' </th>' . "\n"
289 . ' <th align="left">' . "\n"
290 . ' ' . $idx_unit . '&nbsp;' . "\n"
291 . ' </th>' . "\n"
292 . ' <th align="right">' . "\n"
293 . ' &nbsp;' . $tot_size . "\n"
294 . ' </th>' . "\n"
295 . ' <th align="left">' . "\n"
296 . ' ' . $tot_unit . '&nbsp;' . "\n"
297 . ' </th>' . "\n"
298 . ' <th>&nbsp;</th>' . "\n"
299 . ' </tr>' . "\n";
301 if ($is_superuser || $cfg['AllowUserDropDatabase']) {
302 $common_url_query = PMA_generate_common_url() . '&amp;sort_by=' . $sort_by . '&amp;sort_order=' . $sort_order . '&amp;dbstats=' . (empty($dbstats) ? '10' : '3');
303 echo ' <tr>' . "\n"
304 . ' <td colspan="' . (empty($dbstats) ? '10' : '3') . '">' . "\n"
305 . ' <img src="./images/arrow_' . $text_dir . '.gif" border="0" width="38" height="22" alt="' . $strWithChecked . '" />' . "\n"
306 . ' <a href="./server_databases.php3?' . $common_url_query . '&amp;checkall=1" onclick="setCheckboxes(\'dbStatsForm\', true); return false;">' . "\n"
307 . ' ' . $strCheckAll
308 . ' </a>' . "\n"
309 . ' &nbsp;/&nbsp;' . "\n"
310 . ' <a href="./server_databases.php3?' . $common_url_query . '" onclick="setCheckboxes(\'dbStatsForm\', false); return false;">' . "\n"
311 . ' ' . $strUncheckAll
312 . ' </a>' . "\n"
313 . ' </td>' . "\n"
314 . ' </tr>' . "\n";
316 echo ' </table>' . "\n";
317 unset($data_size);
318 unset($data_unit);
319 unset($idx_size);
320 unset($idx_unit);
321 unset($tot_size);
322 unset($tot_unit);
323 if ($is_superuser || $cfg['AllowUserDropDatabase']) {
324 echo ' <ul>' . "\n";
326 if ($is_superuser && empty($dbstats) && PMA_MYSQL_INT_VERSION >= 32303) {
327 echo ' <li>' . "\n"
328 . ' <b>' . "\n"
329 . ' <a href="./server_databases.php3?' . $url_query . '&amp;dbstats=1" title="' . $strDatabasesStatsEnable . '">' . "\n"
330 . ' ' . $strDatabasesStatsEnable . "\n"
331 . ' </a>' . "\n"
332 . ' </b>' . "\n"
333 . ' <br />' . "\n"
334 . ' ' . $strDatabasesStatsHeavyTraffic . "\n"
335 . ' </li><br /><br />' . "\n";
336 } else if ($is_superuser && !empty($dbstats)) {
337 echo ' <li>' . "\n"
338 . ' <b>' . "\n"
339 . ' <a href="./server_databases.php3?' . $url_query . '" title="' . $strDatabasesStatsDisable . '">'. "\n"
340 . ' ' . $strDatabasesStatsDisable . "\n"
341 . ' </a>' . "\n"
342 . ' </b>' . "\n"
343 . ' </li><br /><br />' . "\n";
345 if ($is_superuser || $cfg['AllowUserDropDatabase']) {
346 echo ' <li>' . "\n"
347 . ' <b>' . "\n"
348 . ' ' . $strDropSelectedDatabases . "\n"
349 . ' </b><br />' . "\n"
350 . ' <input type="submit" name="drop_selected_dbs" value="' . $strGo . '" />' . "\n"
351 . ' </li>' . "\n"
352 . ' </ul>' . "\n";
354 echo '</form>' . "\n";
355 } else {
356 echo $strNoDatabases . "\n";
361 * Sends the footer
363 require('./footer.inc.php3');