update
[phpmyadmin/crack.git] / server_databases.php3
bloba2ad63979cd20e7c33c9362c49b5bb709a8989eb
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) && ($is_superuser || $cfg['AllowUserDropDatabase'])) {
58 if (empty($selected_db)) {
59 $message = $strNoDatabasesSelected;
60 } else {
61 $sql_query = array();
62 while (list(, $current_db) = each($selected_db)) {
63 $current_query = 'DROP DATABASE ' . PMA_backquote($current_db) . ';';
64 $sql_query[] = $current_query;
65 PMA_mysql_query($current_query, $userlink)
66 // rabus: in case of an error, we display the full query in
67 // order to let the user know which databases have already been
68 // dropped.
69 or PMA_mysqlDie(PMA_mysql_error($userlink), join("\n", $sql_query));
71 // PMA_showMessage() needs a string...
72 $sql_query = join("\n", $sql_query);
73 $message = sprintf($strDatabasesDropped, count($selected_db));
74 // we need to reload the database list now.
75 PMA_availableDatabases();
76 $reload = 1;
81 /**
82 * Displays the links
84 require('./server_links.inc.php3');
87 /**
88 * Displays the sub-page heading
90 echo '<h2>' . "\n"
91 . ' ' . (empty($dbstats) ? $strDatabases : $strDatabasesStats) . "\n"
92 . '</h2>' . "\n";
95 /**
96 * Checks if the user is allowed to do what he tries to...
98 if (!empty($dbstats) && (!$is_superuser || PMA_MYSQL_INT_VERSION < 32303)) {
99 echo $strNoPrivileges . "\n";
100 include('./footer.inc.php3');
101 exit;
106 * Prepares the statistics
108 $statistics = array();
109 while (list(, $current_db) = each($dblist)) {
110 $tmp_array = array(
111 'db_name' => $current_db,
112 'tbl_cnt' => 0,
113 'data_sz' => 0,
114 'idx_sz' => 0,
115 'tot_sz' => 0
117 if (!empty($dbstats)) {
118 $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) . ';');
119 while ($row = PMA_mysql_fetch_array($res, MYSQL_ASSOC)) {
120 $tmp_array['tbl_cnt']++;
121 $tmp_array['data_sz'] += $row['Data_length'];
122 $tmp_array['idx_sz'] += $row['Index_length'];
125 $tmp_array['tot_sz'] = $tmp_array['data_sz'] + $tmp_array['idx_sz'];
126 $statistics[] = $tmp_array;
129 // avoids 'undefined index' errors
130 if (empty($sort_by)) {
131 $sort_by = 'db_name';
133 if (empty($sort_order)) {
134 if ($sort_by == 'db_name') {
135 $sort_order = 'asc';
136 } else {
137 $sort_order = 'desc';
141 // sorts the array
142 usort($statistics, 'PMA_dbCmp');
146 * Displays the page
148 if (count($statistics) > 0) {
149 echo '<form action="./server_databases.php3" method="post" name="dbStatsForm">' . "\n"
150 . PMA_generate_common_hidden_inputs('', '', 1)
151 . ' <input type="hidden" name="dbstats" value="' . (empty($dbstats) ? '0' : '1') . '" />' . "\n"
152 . ' <input type="hidden" name="sort_by" value="' . $sort_by . '" />' . "\n"
153 . ' <input type="hidden" name="sort_order" value="' . $sort_order . '" />' . "\n"
154 . ' <table border="0">' . "\n"
155 . ' <tr>' . "\n"
156 . ($is_superuser || $cfg['AllowUserDropDatabase'] ? ' <th>&nbsp;</th>' . "\n" : '')
157 . ' <th>' . "\n"
158 . ' &nbsp;';
159 if (empty($dbstats)) {
160 echo $strDatabase . "\n"
161 . ' <img src="./images/asc_order.png" border="0" width="7" height="7" alt="' . $strAscending . '" />' . "\n"
162 . ' &nbsp;' . "\n"
163 . ' </th>' . "\n";
164 } else {
165 echo "\n"
166 . ' <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"
167 . ' ' . $strDatabase . "\n"
168 . ($sort_by == 'db_name' ? ' <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>' . "\n"
173 . ' &nbsp;' . "\n"
174 . ' <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"
175 . ' ' . $strNumTables . "\n"
176 . ($sort_by == 'tbl_cnt' ? ' <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=data_sz&amp;sort_order=' . (($sort_by == 'data_sz' && $sort_order == 'desc') ? 'asc' : 'desc') . '">' . "\n"
183 . ' ' . $strData . "\n"
184 . ($sort_by == 'data_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=idx_sz&amp;sort_order=' . (($sort_by == 'idx_sz' && $sort_order == 'desc') ? 'asc' : 'desc') . '">' . "\n"
191 . ' ' . $strIndexes . "\n"
192 . ($sort_by == 'idx_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"
196 . ' <th colspan="2">' . "\n"
197 . ' &nbsp;' . "\n"
198 . ' <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"
199 . ' ' . $strTotalUC . "\n"
200 . ($sort_by == 'tot_sz' ? ' <img src="./images/' . $sort_order . '_order.png" border="0" width="7" height="7" alt="' . ($sort_order == 'asc' ? $strAscending : $strDescending) . '" />' . "\n" : '')
201 . ' </a>' . "\n"
202 . ' &nbsp;' . "\n"
203 . ' </th>' . "\n";
205 if ($is_superuser) {
206 echo ' <th>' . "\n"
207 . ' &nbsp;' . $strAction . '&nbsp;' . "\n"
208 . ' </th>' . "\n";
210 echo ' </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 if ($is_superuser || $cfg['AllowUserDropDatabase']) {
230 echo ' <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . "\n"
231 . ' <input type="checkbox" name="selected_db[]" title="' . htmlspecialchars($current['db_name']) . '" value="' . htmlspecialchars($current['db_name']) . '" ' . (empty($checkall) ? '' : 'checked="checked" ') . '/>' . "\n"
232 . ' </td>' . "\n";
234 echo ' <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . "\n"
235 . ' <a href="' . $cfg['DefaultTabDatabase'] . '?' . $url_query . '&amp;db=' . urlencode($current['db_name']) . '" title="' . sprintf($strJumpToDB, htmlspecialchars($current['db_name'])) . '">' . "\n"
236 . ' ' . htmlspecialchars($current['db_name']) . "\n"
237 . ' </a>' . "\n"
238 . ' </td>' . "\n";
239 if (!empty($dbstats)) {
240 echo ' <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '" align="right">' . "\n"
241 . ' ' . $current['tbl_cnt'] . "\n"
242 . ' </td>' . "\n"
243 . ' <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '" align="right">' . "\n"
244 . ' ' . $data_size . "\n"
245 . ' </td>' . "\n"
246 . ' <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . "\n"
247 . ' ' . $data_unit . "\n"
248 . ' </td>' . "\n"
249 . ' <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '" align="right">' . "\n"
250 . ' ' . $idx_size . "\n"
251 . ' </td>' . "\n"
252 . ' <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . "\n"
253 . ' ' . $idx_unit . "\n"
254 . ' </td>' . "\n"
255 . ' <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '" align="right">' . "\n"
256 . ' <b>' . "\n"
257 . ' ' . $tot_size . "\n"
258 . ' </b>' . "\n"
259 . ' </td>' . "\n"
260 . ' <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . "\n"
261 . ' <b>' . "\n"
262 . ' ' . $tot_unit . "\n"
263 . ' </b>' . "\n"
264 . ' </td>' . "\n";
266 if ($is_superuser) {
267 echo ' <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . "\n"
268 . ' <a href="./server_privileges.php3?' . $url_query . '&amp;checkprivs=' . urlencode($current['db_name']) . '" title="' . sprintf($strCheckPrivsLong, htmlspecialchars($current['db_name'])) . '">'. "\n"
269 . ' ' . $strCheckPrivs . "\n"
270 . ' </a>' . "\n"
271 . ' </td>' . "\n";
273 echo ' </tr>' . "\n";
274 $useBgcolorOne = !$useBgcolorOne;
275 } // end while
276 if (!empty($dbstats)) {
277 list($data_size, $data_unit) = PMA_formatByteDown($total_calc['data_sz'], 3, 1);
278 list($idx_size, $idx_unit) = PMA_formatByteDown($total_calc['idx_sz'], 3, 1);
279 list($tot_size, $tot_unit) = PMA_formatByteDown($total_calc['tot_sz'], 3, 1);
280 echo ' <tr>' . "\n"
281 . ' <th>&nbsp;</th>' . "\n"
282 . ' <th>' . "\n"
283 . ' &nbsp;' . $strTotalUC . ':&nbsp;' . $total_calc['db_cnt'] . '&nbsp;' . "\n"
284 . ' </th>' . "\n"
285 . ' <th align="right">' . "\n"
286 . ' &nbsp;' . $total_calc['tbl_cnt'] . '&nbsp;' . "\n"
287 . ' </th>' . "\n"
288 . ' <th align="right">' . "\n"
289 . ' &nbsp;' . $data_size . "\n"
290 . ' </th>' . "\n"
291 . ' <th align="left">' . "\n"
292 . ' ' . $data_unit . '&nbsp;' . "\n"
293 . ' </th>' . "\n"
294 . ' <th align="right">' . "\n"
295 . ' &nbsp;' . $idx_size . "\n"
296 . ' </th>' . "\n"
297 . ' <th align="left">' . "\n"
298 . ' ' . $idx_unit . '&nbsp;' . "\n"
299 . ' </th>' . "\n"
300 . ' <th align="right">' . "\n"
301 . ' &nbsp;' . $tot_size . "\n"
302 . ' </th>' . "\n"
303 . ' <th align="left">' . "\n"
304 . ' ' . $tot_unit . '&nbsp;' . "\n"
305 . ' </th>' . "\n"
306 . ' <th>&nbsp;</th>' . "\n"
307 . ' </tr>' . "\n";
309 if ($is_superuser || $cfg['AllowUserDropDatabase']) {
310 $common_url_query = PMA_generate_common_url() . '&amp;sort_by=' . $sort_by . '&amp;sort_order=' . $sort_order . '&amp;dbstats=' . (empty($dbstats) ? '10' : '3');
311 echo ' <tr>' . "\n"
312 . ' <td colspan="' . (empty($dbstats) ? '10' : '3') . '">' . "\n"
313 . ' <img src="./images/arrow_' . $text_dir . '.gif" border="0" width="38" height="22" alt="' . $strWithChecked . '" />' . "\n"
314 . ' <a href="./server_databases.php3?' . $common_url_query . '&amp;checkall=1" onclick="setCheckboxes(\'dbStatsForm\', true); return false;">' . "\n"
315 . ' ' . $strCheckAll
316 . ' </a>' . "\n"
317 . ' &nbsp;/&nbsp;' . "\n"
318 . ' <a href="./server_databases.php3?' . $common_url_query . '" onclick="setCheckboxes(\'dbStatsForm\', false); return false;">' . "\n"
319 . ' ' . $strUncheckAll
320 . ' </a>' . "\n"
321 . ' </td>' . "\n"
322 . ' </tr>' . "\n";
324 echo ' </table>' . "\n";
325 unset($data_size);
326 unset($data_unit);
327 unset($idx_size);
328 unset($idx_unit);
329 unset($tot_size);
330 unset($tot_unit);
331 if ($is_superuser || $cfg['AllowUserDropDatabase']) {
332 echo ' <ul>' . "\n";
334 if ($is_superuser && empty($dbstats) && PMA_MYSQL_INT_VERSION >= 32303) {
335 echo ' <li>' . "\n"
336 . ' <b>' . "\n"
337 . ' <a href="./server_databases.php3?' . $url_query . '&amp;dbstats=1" title="' . $strDatabasesStatsEnable . '">' . "\n"
338 . ' ' . $strDatabasesStatsEnable . "\n"
339 . ' </a>' . "\n"
340 . ' </b>' . "\n"
341 . ' </li><br /><br />' . "\n"
342 . $strDatabasesStatsHeavyTraffic . "\n";
343 } else if ($is_superuser && !empty($dbstats)) {
344 echo ' <li>' . "\n"
345 . ' <b>' . "\n"
346 . ' <a href="./server_databases.php3?' . $url_query . '" title="' . $strDatabasesStatsDisable . '">'. "\n"
347 . ' ' . $strDatabasesStatsDisable . "\n"
348 . ' </a>' . "\n"
349 . ' </b>' . "\n"
350 . ' </li><br /><br />' . "\n";
352 if ($is_superuser || $cfg['AllowUserDropDatabase']) {
353 echo ' <li>' . "\n"
354 . ' <b>' . "\n"
355 . ' ' . $strDropSelectedDatabases . "\n"
356 . ' </b><br />' . "\n"
357 . ' <input type="submit" name="drop_selected_dbs" value="' . $strGo . '" />' . "\n"
358 . ' </li>' . "\n"
359 . ' </ul>' . "\n";
361 echo '</form>' . "\n";
362 } else {
363 echo $strNoDatabases . "\n";
368 * Sends the footer
370 require('./footer.inc.php3');