bugfixes and reimplementations
[phpmyadmin/crack.git] / server_databases.php3
blobd6d89d743d1f26e129b2c7bf56ed30dc6001cda6
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');
10 if (!empty($drop_selected_dbs)) {
11 $reload = 1;
15 /**
16 * Does the common work
18 $js_to_run = 'functions.js';
19 require('./server_common.inc.php3');
22 /**
23 * Sorts the databases array according to the user's choice
25 * @param array a record associated to a database
26 * @param array a record associated to a database
28 * @return integer a value representing whether $a should be before $b in the
29 * sorted array or not
31 * @global string the column the array shall be sorted by
32 * @global string the sorting order ('asc' or 'desc')
34 * @access private
36 function PMA_dbCmp($a, $b)
38 global $sort_by, $sort_order;
39 if ($sort_by == 'db_name') {
40 return ($sort_order == 'asc' ? 1 : -1) * strcasecmp($a['db_name'], $b['db_name']);
41 } else if ($a[$sort_by] == $b[$sort_by]) {
42 return strcasecmp($a['db_name'], $b['db_name']);
43 } else {
44 return ($sort_order == 'asc' ? 1 : -1) * ((int)$a[$sort_by] > (int)$b[$sort_by] ? 1 : -1);
46 } // end of the 'PMA_dbCmp()' function
49 /**
50 * Gets the databases list - if it has not been built yet
52 if ($server > 0 && empty($dblist)) {
53 PMA_availableDatabases();
57 /**
58 * Drops multiple databases
60 if (!empty($drop_selected_dbs)) {
61 if (empty($selected_db)) {
62 $message = $strNoDatabasesSelected;
63 } else {
64 $sql_query = array();
65 while (list(, $current_db) = each($selected_db)) {
66 $current_query = 'DROP DATABASE ' . PMA_backquote($current_db) . ';';
67 $sql_query[] = $current_query;
68 PMA_mysql_query($current_query, $userlink)
69 // rabus: in case of an error, we display the full query in
70 // order to let the user know which databases have already been
71 // dropped.
72 or PMA_mysqlDie(PMA_mysql_error($userlink), join("\n", $sql_query));
74 // PMA_showMessage() needs a string...
75 $sql_query = join("\n", $sql_query);
76 $message = sprintf($strDatabasesDropped, count($selected_db));
77 // we need to reload the database list now.
78 PMA_availableDatabases();
83 /**
84 * Displays the links
86 require('./server_links.inc.php3');
89 /**
90 * Displays the sub-page heading
92 echo '<h2>' . "\n"
93 . ' ' . (empty($dbstats) ? $strDatabases : $strDatabasesStats) . "\n"
94 . '</h2>' . "\n";
97 /**
98 * Checks if the user is allowed to do what he tries to...
100 if (!empty($dbstats) && (!$is_superuser || PMA_MYSQL_INT_VERSION < 32303)) {
101 echo $strNoPrivileges . "\n";
102 include('./footer.inc.php3');
103 exit;
108 * Prepares the statistics
110 $statistics = array();
111 while (list(, $current_db) = each($dblist)) {
112 $tmp_array = array(
113 'db_name' => $current_db,
114 'tbl_cnt' => 0,
115 'data_sz' => 0,
116 'idx_sz' => 0,
117 'tot_sz' => 0
119 if (!empty($dbstats)) {
120 $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) . ';');
121 while ($row = PMA_mysql_fetch_array($res, MYSQL_ASSOC)) {
122 $tmp_array['tbl_cnt']++;
123 $tmp_array['data_sz'] += $row['Data_length'];
124 $tmp_array['idx_sz'] += $row['Index_length'];
127 $tmp_array['tot_sz'] = $tmp_array['data_sz'] + $tmp_array['idx_sz'];
128 $statistics[] = $tmp_array;
131 // avoids 'undefined index' errors
132 if (empty($sort_by)) {
133 $sort_by = 'db_name';
135 if (empty($sort_order)) {
136 if ($sort_by == 'db_name') {
137 $sort_order = 'asc';
138 } else {
139 $sort_order = 'desc';
143 // sorts the array
144 usort($statistics, 'PMA_dbCmp');
148 * Displays the page
150 if (count($statistics) > 0) {
151 echo '<form action="./server_databases.php3" method="post" name="dbStatsForm">' . "\n"
152 . PMA_generate_common_hidden_inputs('', '', 1)
153 . ' <input type="hidden" name="dbstats" value="' . (empty($dbstats) ? '0' : '1') . '" />' . "\n"
154 . ' <input type="hidden" name="sort_by" value="' . $sort_by . '" />' . "\n"
155 . ' <input type="hidden" name="sort_order" value="' . $sort_order . '" />' . "\n"
156 . ' <table border="0">' . "\n"
157 . ' <tr>' . "\n"
158 . ' <th>&nbsp;</th>' . "\n"
159 . ' <th>' . "\n"
160 . ' &nbsp;';
161 if (empty($dbstats)) {
162 echo $strDatabase . "\n"
163 . ' <img src="./images/asc_order.png" border="0" width="7" height="7" alt="' . $strAscending . '" />' . "\n"
164 . ' &nbsp;' . "\n"
165 . ' </th>' . "\n";
166 } else {
167 echo "\n"
168 . ' <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"
169 . ' ' . $strDatabase . "\n"
170 . ($sort_by == 'db_name' ? ' <img src="./images/' . $sort_order . '_order.png" border="0" width="7" height="7" alt="' . ($sort_order == 'asc' ? $strAscending : $strDescending) . '" />' . "\n" : '')
171 . ' </a>' . "\n"
172 . ' &nbsp;' . "\n"
173 . ' </th>' . "\n"
174 . ' <th>' . "\n"
175 . ' &nbsp;' . "\n"
176 . ' <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"
177 . ' ' . $strNumTables . "\n"
178 . ($sort_by == 'tbl_cnt' ? ' <img src="./images/' . $sort_order . '_order.png" border="0" width="7" height="7" alt="' . ($sort_order == 'asc' ? $strAscending : $strDescending) . '" />' . "\n" : '')
179 . ' </a>' . "\n"
180 . ' &nbsp;' . "\n"
181 . ' </th>' . "\n"
182 . ' <th colspan="2">' . "\n"
183 . ' &nbsp;' . "\n"
184 . ' <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"
185 . ' ' . $strData . "\n"
186 . ($sort_by == 'data_sz' ? ' <img src="./images/' . $sort_order . '_order.png" border="0" width="7" height="7" alt="' . ($sort_order == 'asc' ? $strAscending : $strDescending) . '" />' . "\n" : '')
187 . ' </a>' . "\n"
188 . ' &nbsp;' . "\n"
189 . ' </th>' . "\n"
190 . ' <th colspan="2">' . "\n"
191 . ' &nbsp;' . "\n"
192 . ' <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"
193 . ' ' . $strIndexes . "\n"
194 . ($sort_by == 'idx_sz' ? ' <img src="./images/' . $sort_order . '_order.png" border="0" width="7" height="7" alt="' . ($sort_order == 'asc' ? $strAscending : $strDescending) . '" />' . "\n" : '')
195 . ' </a>' . "\n"
196 . ' &nbsp;' . "\n"
197 . ' </th>' . "\n"
198 . ' <th colspan="2">' . "\n"
199 . ' &nbsp;' . "\n"
200 . ' <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"
201 . ' ' . $strTotalUC . "\n"
202 . ($sort_by == 'tot_sz' ? ' <img src="./images/' . $sort_order . '_order.png" border="0" width="7" height="7" alt="' . ($sort_order == 'asc' ? $strAscending : $strDescending) . '" />' . "\n" : '')
203 . ' </a>' . "\n"
204 . ' &nbsp;' . "\n"
205 . ' </th>' . "\n";
207 echo ' <th>' . "\n"
208 . ' &nbsp;' . $strAction . '&nbsp;' . "\n"
209 . ' </th>' . "\n"
210 . ' </tr>' . "\n";
211 $useBgcolorOne = TRUE;
212 $total_calc = array(
213 'db_cnt' => 0,
214 'tbl_cnt' => 0,
215 'data_sz' => 0,
216 'idx_sz' => 0,
217 'tot_sz' => 0
219 while (list(, $current) = each($statistics)) {
220 list($data_size, $data_unit) = PMA_formatByteDown($current['data_sz'], 3, 1);
221 list($idx_size, $idx_unit) = PMA_formatByteDown($current['idx_sz'], 3, 1);
222 list($tot_size, $tot_unit) = PMA_formatByteDown($current['tot_sz'], 3, 1);
223 $total_calc['db_cnt']++;
224 $total_calc['tbl_cnt'] += $current['tbl_cnt'];
225 $total_calc['data_sz'] += $current['data_sz'];
226 $total_calc['idx_sz'] += $current['idx_sz'];
227 $total_calc['tot_sz'] += $current['tot_sz'];
228 echo ' <tr>' . "\n"
229 . ' <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . "\n"
230 . ' <input type="checkbox" name="selected_db[]" title="' . htmlspecialchars($current['db_name']) . '" value="' . htmlspecialchars($current['db_name']) . '" ' . (empty($checkall) ? '' : 'checked="checked" ') . '/>' . "\n"
231 . ' </td>' . "\n"
232 . ' <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . "\n"
233 . ' <a href="' . $cfg['DefaultTabDatabase'] . $url_query . '&amp;db=' . urlencode($current['db_name']) . '" title="' . sprintf($strJumpToDB, htmlspecialchars($current['db_name'])) . '">' . "\n"
234 . ' ' . htmlspecialchars($current['db_name']) . "\n"
235 . ' </a>' . "\n"
236 . ' </td>' . "\n";
237 if (!empty($dbstats)) {
238 echo ' <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '" align="right">' . "\n"
239 . ' ' . $current['tbl_cnt'] . "\n"
240 . ' </td>' . "\n"
241 . ' <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '" align="right">' . "\n"
242 . ' ' . $data_size . "\n"
243 . ' </td>' . "\n"
244 . ' <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . "\n"
245 . ' ' . $data_unit . "\n"
246 . ' </td>' . "\n"
247 . ' <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '" align="right">' . "\n"
248 . ' ' . $idx_size . "\n"
249 . ' </td>' . "\n"
250 . ' <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . "\n"
251 . ' ' . $idx_unit . "\n"
252 . ' </td>' . "\n"
253 . ' <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '" align="right">' . "\n"
254 . ' <b>' . "\n"
255 . ' ' . $tot_size . "\n"
256 . ' </b>' . "\n"
257 . ' </td>' . "\n"
258 . ' <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . "\n"
259 . ' <b>' . "\n"
260 . ' ' . $tot_unit . "\n"
261 . ' </b>' . "\n"
262 . ' </td>' . "\n";
264 echo ' <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . "\n"
265 . ' <a href="./server_privileges.php3?' . $url_query . '&amp;checkprivs=' . urlencode($current['db_name']) . '" title="' . sprintf($strCheckPrivsLong, htmlspecialchars($current['db_name'])) . '">'. "\n"
266 . ' ' . $strCheckPrivs . "\n"
267 . ' </a>' . "\n"
268 . ' </td>' . "\n"
269 . ' </tr>' . "\n";
270 $useBgcolorOne = !$useBgcolorOne;
271 } // end while
272 if (!empty($dbstats)) {
273 list($data_size, $data_unit) = PMA_formatByteDown($total_calc['data_sz'], 3, 1);
274 list($idx_size, $idx_unit) = PMA_formatByteDown($total_calc['idx_sz'], 3, 1);
275 list($tot_size, $tot_unit) = PMA_formatByteDown($total_calc['tot_sz'], 3, 1);
276 echo ' <tr>' . "\n"
277 . ' <th>&nbsp;</th>' . "\n"
278 . ' <th>' . "\n"
279 . ' &nbsp;' . $strTotalUC . ':&nbsp;' . $total_calc['db_cnt'] . '&nbsp;' . "\n"
280 . ' </th>' . "\n"
281 . ' <th align="right">' . "\n"
282 . ' &nbsp;' . $total_calc['tbl_cnt'] . '&nbsp;' . "\n"
283 . ' </th>' . "\n"
284 . ' <th align="right">' . "\n"
285 . ' &nbsp;' . $data_size . "\n"
286 . ' </th>' . "\n"
287 . ' <th align="left">' . "\n"
288 . ' ' . $data_unit . '&nbsp;' . "\n"
289 . ' </th>' . "\n"
290 . ' <th align="right">' . "\n"
291 . ' &nbsp;' . $idx_size . "\n"
292 . ' </th>' . "\n"
293 . ' <th align="left">' . "\n"
294 . ' ' . $idx_unit . '&nbsp;' . "\n"
295 . ' </th>' . "\n"
296 . ' <th align="right">' . "\n"
297 . ' &nbsp;' . $tot_size . "\n"
298 . ' </th>' . "\n"
299 . ' <th align="left">' . "\n"
300 . ' ' . $tot_unit . '&nbsp;' . "\n"
301 . ' </th>' . "\n"
302 . ' <th>&nbsp;</th>' . "\n"
303 . ' </tr>' . "\n";
305 $common_url_query = PMA_generate_common_url() . '&amp;sort_by=' . $sort_by . '&amp;sort_order=' . $sort_order . '&amp;dbstats=' . (empty($dbstats) ? '10' : '3');
306 echo ' <tr>' . "\n"
307 . ' <td colspan="' . (empty($dbstats) ? '10' : '3') . '">' . "\n"
308 . ' <img src="./images/arrow_' . $text_dir . '.gif" border="0" width="38" height="22" alt="' . $strWithChecked . '" />' . "\n"
309 . ' <a href="./server_databases.php3?' . $common_url_query . '&amp;checkall=1" onclick="setCheckboxes(\'dbStatsForm\', true); return false;">' . "\n"
310 . ' ' . $strCheckAll
311 . ' </a>' . "\n"
312 . ' &nbsp;/&nbsp;' . "\n"
313 . ' <a href="./server_databases.php3?' . $common_url_query . '" onclick="setCheckboxes(\'dbStatsForm\', false); return false;">' . "\n"
314 . ' ' . $strUncheckAll
315 . ' </a>' . "\n"
316 . ' </td>' . "\n"
317 . ' </tr>' . "\n"
318 . ' </table>' . "\n"
319 . ' <ul>' . "\n";
320 unset($data_size);
321 unset($data_unit);
322 unset($idx_size);
323 unset($idx_unit);
324 unset($tot_size);
325 unset($tot_unit);
326 echo ' <li>' . "\n"
327 . ' <b>' . "\n";
328 if ($is_superuser && empty($dbstats) && PMA_MYSQL_INT_VERSION >= 32303) {
329 echo ' <a href="./server_databases.php3?' . $url_query . '&amp;dbstats=1" title="' . $strDatabasesStatsEnable . '">' . "\n"
330 . ' ' . $strDatabasesStatsEnable . "\n"
331 . ' </a>' . "\n"
332 . ' </b><br />' . "\n"
333 . $strDatabasesStatsHeavyTraffic . "\n";
334 } else if (!empty($dbstats)) {
335 echo ' <a href="./server_databases.php3?' . $url_query . '" title="' . $strDatabasesStatsDisable . '">'. "\n"
336 . ' ' . $strDatabasesStatsDisable . "\n"
337 . ' </a>' . "\n"
338 . ' </b>' . "\n";
340 echo ' </li><br /><br />' . "\n"
341 . ' <li>' . "\n"
342 . ' <b>' . "\n"
343 . ' ' . $strDropSelectedDatabases . "\n"
344 . ' </b><br />' . "\n"
345 . ' <input type="submit" name="drop_selected_dbs" value="' . $strGo . '" />' . "\n"
346 . ' </li>' . "\n"
347 . ' </ul>' . "\n"
348 . '</form>' . "\n";
349 } else {
350 echo $strNoDatabases . "\n";
355 * Sends the footer
357 require('./footer.inc.php3');