patch #2550323 [XHTML] in server_databases.php
[phpmyadmin/crack.git] / server_databases.php
blob660e7d74781609d97e4824aad72c6a3ce98710ec
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
5 * @version $Id$
6 */
8 /**
9 * Does the common work
11 require_once './libraries/common.inc.php';
14 $GLOBALS['js_include'][] = 'functions.js';
15 require './libraries/server_common.inc.php';
17 /**
18 * avoids 'undefined index' errors
20 if (empty($_REQUEST['sort_by'])) {
21 $sort_by = 'SCHEMA_NAME';
22 } else {
23 $sort_by = PMA_sanitize($_REQUEST['sort_by']);
26 if (isset($_REQUEST['sort_order'])
27 && strtolower($_REQUEST['sort_order']) == 'desc') {
28 $sort_order = 'desc';
29 } else {
30 $sort_order = 'asc';
33 $dbstats = empty($_REQUEST['dbstats']) ? 0 : 1;
34 $pos = empty($_REQUEST['pos']) ? 0 : (int) $_REQUEST['pos'];
37 /**
38 * Drops multiple databases
41 // workaround for IE behavior (it returns some coordinates based on where
42 // the mouse was on the Drop image):
43 if (isset($_REQUEST['drop_selected_dbs_x'])) {
44 $_REQUEST['drop_selected_dbs'] = true;
47 if ((isset($_REQUEST['drop_selected_dbs']) || isset($_REQUEST['query_type']))
48 && ($is_superuser || $cfg['AllowUserDropDatabase'])) {
49 if (! isset($_REQUEST['selected_dbs']) && ! isset($_REQUEST['query_type'])) {
50 $message = PMA_Message::error('strNoDatabasesSelected');
51 } else {
52 $action = 'server_databases.php';
53 $submit_mult = 'drop_db' ;
54 $err_url = 'server_databases.php?' . PMA_generate_common_url();
55 if (isset($_REQUEST['selected_dbs'])) {
56 $selected_db = $_REQUEST['selected_dbs'];
58 require './libraries/mult_submits.inc.php';
59 unset($action, $submit_mult, $err_url, $selected_db);
60 if (empty($message)) {
61 $message = PMA_Message::success('strDatabasesDropped');
62 if ($mult_btn == $strYes) {
63 $message->addParam(count($selected));
64 } else {
65 $message->addParam(0);
72 /**
73 * Displays the links
75 require './libraries/server_links.inc.php';
78 /**
79 * Displays the sub-page heading
81 echo '<h2>' . "\n"
82 . ($GLOBALS['cfg']['MainPageIconic']
83 ? '<img class="icon" src="' . $pmaThemeImage . 's_db.png" width="16"'
84 .' height="16" alt="" />'
85 : '')
86 . ($dbstats ? $strDatabasesStats : $strDatabases) . "\n"
87 .'</h2>' . "\n";
89 /**
90 * Gets the databases list
92 if ($server > 0) {
93 $databases = PMA_DBI_get_databases_full(null, $dbstats, null, $sort_by,
94 $sort_order, $pos, true);
95 $databases_count = count($GLOBALS['pma']->databases);
96 } else {
97 $databases_count = 0;
102 * Displays the page
104 if ($databases_count > 0) {
105 reset($databases);
106 $first_database = current($databases);
107 // table col order
108 $column_order['DEFAULT_COLLATION_NAME'] = array(
109 'disp_name' => $strCollation,
110 'description_function' => 'PMA_getCollationDescr',
111 'format' => 'string',
112 'footer' => PMA_getServerCollation(),
114 $column_order['SCHEMA_TABLES'] = array(
115 'disp_name' => $strNumTables,
116 'format' => 'number',
117 'footer' => 0,
119 $column_order['SCHEMA_TABLE_ROWS'] = array(
120 'disp_name' => $strRows,
121 'format' => 'number',
122 'footer' => 0,
124 $column_order['SCHEMA_DATA_LENGTH'] = array(
125 'disp_name' => $strData,
126 'format' => 'byte',
127 'footer' => 0,
129 $column_order['SCHEMA_INDEX_LENGTH'] = array(
130 'disp_name' => $strIndexes,
131 'format' => 'byte',
132 'footer' => 0,
134 $column_order['SCHEMA_LENGTH'] = array(
135 'disp_name' => $strTotalUC,
136 'format' => 'byte',
137 'footer' => 0,
139 $column_order['SCHEMA_DATA_FREE'] = array(
140 'disp_name' => $strOverhead,
141 'format' => 'byte',
142 'footer' => 0,
145 $_url_params = array(
146 'pos' => $pos,
147 'dbstats' => $dbstats,
148 'sort_by' => $sort_by,
149 'sort_order' => $sort_order,
152 PMA_listNavigator($databases_count, $pos, $_url_params, 'server_databases.php', 'frame_content', $GLOBALS['cfg']['MaxDbList']);
154 $_url_params['pos'] = $pos;
156 echo '<form action="./server_databases.php" method="post" name="dbStatsForm" id="dbStatsForm">' . "\n"
157 . PMA_generate_common_hidden_inputs($_url_params);
159 $_url_params['sort_by'] = 'SCHEMA_NAME';
160 $_url_params['sort_order'] = ($sort_by == 'SCHEMA_NAME' && $sort_order == 'asc') ? 'desc' : 'asc';
162 echo '<table id="tabledatabases" class="data">' . "\n"
163 . '<thead>' . "\n"
164 . '<tr>' . "\n"
165 . ($is_superuser || $cfg['AllowUserDropDatabase'] ? ' <th>&nbsp;</th>' . "\n" : '')
166 . ' <th><a href="./server_databases.php' . PMA_generate_common_url($_url_params) . '">' . "\n"
167 . ' ' . $strDatabase . "\n"
168 . ($sort_by == 'SCHEMA_NAME' ? ' <img class="icon" src="' . $pmaThemeImage . 's_' . $sort_order . '.png" width="11" height="9" alt="' . ($sort_order == 'asc' ? $strAscending : $strDescending) . '" />' . "\n" : '')
169 . ' </a></th>' . "\n";
170 $table_columns = 3;
171 foreach ($column_order as $stat_name => $stat) {
172 if (array_key_exists($stat_name, $first_database)) {
173 if ($stat['format'] === 'byte') {
174 $table_columns += 2;
175 $colspan = ' colspan="2"';
176 } else {
177 $table_columns++;
178 $colspan = '';
180 $_url_params['sort_by'] = $stat_name;
181 $_url_params['sort_order'] = ($sort_by == $stat_name && $sort_order == 'desc') ? 'asc' : 'desc';
182 echo ' <th' . $colspan . '>'
183 .'<a href="./server_databases.php' . PMA_generate_common_url($_url_params) . '">' . "\n"
184 .' ' . $stat['disp_name'] . "\n"
185 .($sort_by == $stat_name ? ' <img class="icon" src="' . $pmaThemeImage . 's_' . $sort_order . '.png" width="11" height="9" alt="' . ($sort_order == 'asc' ? $strAscending : $strDescending) . '" />' . "\n" : '')
186 .' </a></th>' . "\n";
189 if ($is_superuser) {
190 echo ' <th>' . ($cfg['PropertiesIconic'] ? '&nbsp;' : $strAction) . "\n"
191 . ' </th>' . "\n";
193 echo '</tr>' . "\n"
194 . '</thead>' . "\n"
195 . '<tbody>' . "\n";
197 $odd_row = true;
198 foreach ($databases as $current) {
199 echo '<tr class="' . ($odd_row ? 'odd' : 'even') . '">' . "\n";
200 $odd_row = ! $odd_row;
202 if ($is_superuser || $cfg['AllowUserDropDatabase']) {
203 echo ' <td class="tool">' . "\n";
204 if ($current['SCHEMA_NAME'] != 'mysql'
205 && $current['SCHEMA_NAME'] != 'information_schema') {
206 echo ' <input type="checkbox" name="selected_dbs[]" title="' . htmlspecialchars($current['SCHEMA_NAME']) . '" value="' . htmlspecialchars($current['SCHEMA_NAME']) . '" ' . (empty($checkall) ? '' : 'checked="checked" ') . '/>' . "\n";
207 } else {
208 echo ' <input type="checkbox" name="selected_dbs[]" title="' . htmlspecialchars($current['SCHEMA_NAME']) . '" value="' . htmlspecialchars($current['SCHEMA_NAME']) . '" disabled="disabled"/>' . "\n";
210 echo ' </td>' . "\n";
212 echo ' <td class="name">' . "\n"
213 . ' <a onclick="'
214 . 'if (window.parent.openDb &amp;&amp; window.parent.openDb(\'' . PMA_jsFormat($current['SCHEMA_NAME'], false) . '\')) return false;'
215 . '" href="index.php?' . $url_query . '&amp;db='
216 . urlencode($current['SCHEMA_NAME']) . '" title="'
217 . sprintf($strJumpToDB, htmlspecialchars($current['SCHEMA_NAME']))
218 . '" target="_parent">' . "\n"
219 . ' ' . htmlspecialchars($current['SCHEMA_NAME']) . "\n"
220 . ' </a>' . "\n"
221 . ' </td>' . "\n";
223 foreach ($column_order as $stat_name => $stat) {
224 if (array_key_exists($stat_name, $current)) {
225 if (is_numeric($stat['footer'])) {
226 $column_order[$stat_name]['footer'] += $current[$stat_name];
228 if ($stat['format'] === 'byte') {
229 list($value, $unit) = PMA_formatByteDown($current[$stat_name], 3, 1);
230 } elseif ($stat['format'] === 'number') {
231 $value = PMA_formatNumber($current[$stat_name], 0);
232 } else {
233 $value = htmlentities($current[$stat_name], 0);
235 echo ' <td class="value">';
236 if (isset($stat['description_function'])) {
237 echo '<dfn title="' . $stat['description_function']($current[$stat_name]) . '">';
239 echo $value;
240 if (isset($stat['description_function'])) {
241 echo '</dfn>';
243 echo '</td>' . "\n";
244 if ($stat['format'] === 'byte') {
245 echo ' <td class="unit">' . $unit . '</td>' . "\n";
250 if ($is_superuser) {
251 echo ' <td class="tool">' . "\n"
252 . ' <a onclick="
253 // <![CDATA[
254 if (window.parent.setDb) window.parent.setDb(\'' . PMA_jsFormat($current['SCHEMA_NAME']) . '\');
255 // ]]>" href="./server_privileges.php?' . $url_query
256 . '&amp;checkprivs=' . urlencode($current['SCHEMA_NAME'])
257 . '" title="' . sprintf($strCheckPrivsLong, htmlspecialchars($current['SCHEMA_NAME']))
258 . '">'. "\n"
259 . ' '
260 . ($cfg['PropertiesIconic']
261 ? '<img class="icon" src="' . $pmaThemeImage . 's_rights.png" width="16" height="16" alt=" ' . $strCheckPrivs . '" /> '
262 : $strCheckPrivs) . "\n"
263 . ' </a></td>' . "\n";
265 echo '</tr>' . "\n";
266 } // end foreach ($databases as $key => $current)
267 unset($current, $odd_row);
269 echo '<tr>' . "\n";
270 if ($is_superuser || $cfg['AllowUserDropDatabase']) {
271 echo ' <th>&nbsp;</th>' . "\n";
273 echo ' <th>' . $strTotalUC . ': ' . $databases_count . '</th>' . "\n";
274 foreach ($column_order as $stat_name => $stat) {
275 if (array_key_exists($stat_name, $first_database)) {
276 if ($stat['format'] === 'byte') {
277 list($value, $unit) = PMA_formatByteDown($stat['footer'], 3, 1);
278 } elseif ($stat['format'] === 'number') {
279 $value = PMA_formatNumber($stat['footer'], 0);
280 } else {
281 $value = htmlentities($stat['footer'], 0);
283 echo ' <th class="value">';
284 if (isset($stat['description_function'])) {
285 echo '<dfn title="' . $stat['description_function']($stat['footer']) . '">';
287 echo $value;
288 if (isset($stat['description_function'])) {
289 echo '</dfn>';
291 echo '</th>' . "\n";
292 if ($stat['format'] === 'byte') {
293 echo ' <th class="unit">' . $unit . '</th>' . "\n";
297 if ($is_superuser) {
298 echo ' <th>&nbsp;</th>' . "\n";
300 echo '</tr>' . "\n";
301 echo '</tbody>' . "\n"
302 .'</table>' . "\n";
303 unset($column_order, $stat_name, $stat, $databases, $table_columns);
305 if ($is_superuser || $cfg['AllowUserDropDatabase']) {
306 $common_url_query = PMA_generate_common_url() . '&amp;sort_by=' . $sort_by . '&amp;sort_order=' . $sort_order . '&amp;dbstats=' . $dbstats;
307 echo '<img class="selectallarrow" src="' . $pmaThemeImage . 'arrow_' . $text_dir . '.png" width="38" height="22" alt="' . $strWithChecked . '" />' . "\n"
308 . '<a href="./server_databases.php?' . $common_url_query . '&amp;checkall=1" onclick="if (markAllRows(\'tabledatabases\')) return false;">' . "\n"
309 . ' ' . $strCheckAll . '</a> / ' . "\n"
310 . '<a href="./server_databases.php?' . $common_url_query . '" onclick="if (unMarkAllRows(\'tabledatabases\')) return false;">' . "\n"
311 . ' ' . $strUncheckAll . '</a>' . "\n"
312 . '<i>' . $strWithChecked . '</i>' . "\n";
313 PMA_buttonOrImage('drop_selected_dbs', 'mult_submit', 'drop_selected_dbs', $strDrop, 'b_deltbl.png');
316 echo '<ul><li id="li_switch_dbstats"><strong>' . "\n";
317 if (empty($dbstats)) {
318 echo ' <a href="./server_databases.php?' . $url_query . '&amp;dbstats=1"'
319 .' title="' . $strDatabasesStatsEnable . '">' . "\n"
320 .' ' . $strDatabasesStatsEnable;
321 } else {
322 echo ' <a href="./server_databases.php?' . $url_query . '"'
323 .' title="' . $strDatabasesStatsDisable . '">' . "\n"
324 .' ' . $strDatabasesStatsDisable;
326 echo '</a></strong><br />' . "\n";
327 PMA_Message::warning('strDatabasesStatsHeavyTraffic')->display();
328 echo '</li>' . "\n"
329 .'</ul>' . "\n";
330 echo '</form>';
331 } else {
332 echo $strNoDatabases;
334 unset($databases_count);
337 * Create new database.
339 if ($cfg['ShowCreateDb']) {
340 echo '<ul><li id="li_create_database">' . "\n";
341 require './libraries/display_create_database.lib.php';
342 echo ' </li>' . "\n";
343 echo '</ul>' . "\n";
347 * Sends the footer
349 require_once './libraries/footer.inc.php';