3.3.10
[phpmyadmin/ammaryasirr.git] / server_databases.php
blob5e6d0ecc43dedfaabe8229565fa7908c50f0459d
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
5 * @version $Id$
6 * @package phpMyAdmin
7 */
9 /**
10 * Does the common work
12 require_once './libraries/common.inc.php';
15 $GLOBALS['js_include'][] = 'functions.js';
16 require './libraries/server_common.inc.php';
17 require './libraries/replication.inc.php';
19 /**
20 * avoids 'undefined index' errors
22 if (empty($_REQUEST['sort_by'])) {
23 $sort_by = 'SCHEMA_NAME';
24 } else {
25 $sort_by_whitelist = array(
26 'SCHEMA_NAME',
27 'DEFAULT_COLLATION_NAME',
28 'SCHEMA_TABLES',
29 'SCHEMA_TABLE_ROWS',
30 'SCHEMA_DATA_LENGTH',
31 'SCHEMA_INDEX_LENGTH',
32 'SCHEMA_LENGTH',
33 'SCHEMA_DATA_FREE'
35 if (in_array($_REQUEST['sort_by'], $sort_by_whitelist)) {
36 $sort_by = $_REQUEST['sort_by'];
37 } else {
38 $sort_by = 'SCHEMA_NAME';
42 if (isset($_REQUEST['sort_order'])
43 && strtolower($_REQUEST['sort_order']) == 'desc') {
44 $sort_order = 'desc';
45 } else {
46 $sort_order = 'asc';
49 $dbstats = empty($_REQUEST['dbstats']) ? 0 : 1;
50 $pos = empty($_REQUEST['pos']) ? 0 : (int) $_REQUEST['pos'];
53 /**
54 * Drops multiple databases
57 // workaround for IE behavior (it returns some coordinates based on where
58 // the mouse was on the Drop image):
59 if (isset($_REQUEST['drop_selected_dbs_x'])) {
60 $_REQUEST['drop_selected_dbs'] = true;
63 if ((isset($_REQUEST['drop_selected_dbs']) || isset($_REQUEST['query_type']))
64 && ($is_superuser || $cfg['AllowUserDropDatabase'])) {
65 if (! isset($_REQUEST['selected_dbs']) && ! isset($_REQUEST['query_type'])) {
66 $message = PMA_Message::error('strNoDatabasesSelected');
67 } else {
68 $action = 'server_databases.php';
69 $submit_mult = 'drop_db' ;
70 $err_url = 'server_databases.php?' . PMA_generate_common_url();
71 if (isset($_REQUEST['selected_dbs'])) {
72 $selected_db = $_REQUEST['selected_dbs'];
74 require './libraries/mult_submits.inc.php';
75 unset($action, $submit_mult, $err_url, $selected_db, $GLOBALS['db']);
76 if (empty($message)) {
77 $message = PMA_Message::success('strDatabasesDropped');
78 if ($mult_btn == $strYes) {
79 $message->addParam(count($selected));
80 } else {
81 $message->addParam(0);
88 /**
89 * Displays the links
91 require './libraries/server_links.inc.php';
94 /**
95 * Displays the sub-page heading
97 echo '<h2>' . "\n"
98 . ($GLOBALS['cfg']['MainPageIconic']
99 ? '<img class="icon" src="' . $pmaThemeImage . 's_db.png" width="16"'
100 .' height="16" alt="" />'
101 : '')
102 . ($dbstats ? $strDatabasesStats : $strDatabases) . "\n"
103 .'</h2>' . "\n";
106 * Gets the databases list
108 if ($server > 0) {
109 $databases = PMA_DBI_get_databases_full(null, $dbstats, null, $sort_by,
110 $sort_order, $pos, true);
111 $databases_count = count($GLOBALS['pma']->databases);
112 } else {
113 $databases_count = 0;
118 * Displays the page
120 if ($databases_count > 0) {
121 reset($databases);
122 $first_database = current($databases);
123 // table col order
124 $column_order['DEFAULT_COLLATION_NAME'] = array(
125 'disp_name' => $strCollation,
126 'description_function' => 'PMA_getCollationDescr',
127 'format' => 'string',
128 'footer' => PMA_getServerCollation(),
130 $column_order['SCHEMA_TABLES'] = array(
131 'disp_name' => $strNumTables,
132 'format' => 'number',
133 'footer' => 0,
135 $column_order['SCHEMA_TABLE_ROWS'] = array(
136 'disp_name' => $strRows,
137 'format' => 'number',
138 'footer' => 0,
140 $column_order['SCHEMA_DATA_LENGTH'] = array(
141 'disp_name' => $strData,
142 'format' => 'byte',
143 'footer' => 0,
145 $column_order['SCHEMA_INDEX_LENGTH'] = array(
146 'disp_name' => $strIndexes,
147 'format' => 'byte',
148 'footer' => 0,
150 $column_order['SCHEMA_LENGTH'] = array(
151 'disp_name' => $strTotalUC,
152 'format' => 'byte',
153 'footer' => 0,
155 $column_order['SCHEMA_DATA_FREE'] = array(
156 'disp_name' => $strOverhead,
157 'format' => 'byte',
158 'footer' => 0,
161 $_url_params = array(
162 'pos' => $pos,
163 'dbstats' => $dbstats,
164 'sort_by' => $sort_by,
165 'sort_order' => $sort_order,
168 PMA_listNavigator($databases_count, $pos, $_url_params, 'server_databases.php', 'frame_content', $GLOBALS['cfg']['MaxDbList']);
170 $_url_params['pos'] = $pos;
172 echo '<form action="./server_databases.php" method="post" name="dbStatsForm" id="dbStatsForm">' . "\n"
173 . PMA_generate_common_hidden_inputs($_url_params);
175 $_url_params['sort_by'] = 'SCHEMA_NAME';
176 $_url_params['sort_order'] = ($sort_by == 'SCHEMA_NAME' && $sort_order == 'asc') ? 'desc' : 'asc';
178 echo '<table id="tabledatabases" class="data">' . "\n"
179 . '<thead>' . "\n"
180 . '<tr>' . "\n"
181 . ($is_superuser || $cfg['AllowUserDropDatabase'] ? ' <th></th>' . "\n" : '')
182 . ' <th><a href="./server_databases.php' . PMA_generate_common_url($_url_params) . '">' . "\n"
183 . ' ' . $strDatabase . "\n"
184 . ($sort_by == 'SCHEMA_NAME' ? ' <img class="icon" src="' . $pmaThemeImage . 's_' . $sort_order . '.png" width="11" height="9" alt="' . ($sort_order == 'asc' ? $strAscending : $strDescending) . '" />' . "\n" : '')
185 . ' </a></th>' . "\n";
186 $table_columns = 3;
187 foreach ($column_order as $stat_name => $stat) {
188 if (array_key_exists($stat_name, $first_database)) {
189 if ($stat['format'] === 'byte') {
190 $table_columns += 2;
191 $colspan = ' colspan="2"';
192 } else {
193 $table_columns++;
194 $colspan = '';
196 $_url_params['sort_by'] = $stat_name;
197 $_url_params['sort_order'] = ($sort_by == $stat_name && $sort_order == 'desc') ? 'asc' : 'desc';
198 echo ' <th' . $colspan . '>'
199 .'<a href="./server_databases.php' . PMA_generate_common_url($_url_params) . '">' . "\n"
200 .' ' . $stat['disp_name'] . "\n"
201 .($sort_by == $stat_name ? ' <img class="icon" src="' . $pmaThemeImage . 's_' . $sort_order . '.png" width="11" height="9" alt="' . ($sort_order == 'asc' ? $strAscending : $strDescending) . '" />' . "\n" : '')
202 .' </a></th>' . "\n";
206 foreach ($replication_types as $type)
208 if ($type=="master")
209 $name = "strReplicationMaster";
210 elseif($type == "slave")
211 $name = "strReplicationSlave";
212 if (${"server_{$type}_status"})
213 echo ' <th>'.$GLOBALS[$name].'</th>' . "\n";
216 if ($is_superuser) {
217 echo ' <th>' . ($cfg['PropertiesIconic'] ? '' : $strAction) . "\n"
218 . ' </th>' . "\n";
220 echo '</tr>' . "\n"
221 . '</thead>' . "\n"
222 . '<tbody>' . "\n";
224 $odd_row = true;
225 foreach ($databases as $current) {
226 echo '<tr class="' . ($odd_row ? 'odd' : 'even') . '">' . "\n";
227 $odd_row = ! $odd_row;
229 if ($is_superuser || $cfg['AllowUserDropDatabase']) {
230 echo ' <td class="tool">' . "\n";
231 if ($current['SCHEMA_NAME'] != 'mysql'
232 && $current['SCHEMA_NAME'] != 'information_schema') {
233 echo ' <input type="checkbox" name="selected_dbs[]" title="' . htmlspecialchars($current['SCHEMA_NAME']) . '" value="' . htmlspecialchars($current['SCHEMA_NAME']) . '" ' . (empty($checkall) ? '' : 'checked="checked" ') . '/>' . "\n";
234 } else {
235 echo ' <input type="checkbox" name="selected_dbs[]" title="' . htmlspecialchars($current['SCHEMA_NAME']) . '" value="' . htmlspecialchars($current['SCHEMA_NAME']) . '" disabled="disabled"/>' . "\n";
237 echo ' </td>' . "\n";
239 echo ' <td class="name">' . "\n"
240 . ' <a onclick="'
241 . 'if (window.parent.openDb &amp;&amp; window.parent.openDb(\'' . PMA_jsFormat($current['SCHEMA_NAME'], false) . '\')) return false;'
242 . '" href="index.php?' . $url_query . '&amp;db='
243 . urlencode($current['SCHEMA_NAME']) . '" title="'
244 . sprintf($strJumpToDB, htmlspecialchars($current['SCHEMA_NAME']))
245 . '" target="_parent">' . "\n"
246 . ' ' . htmlspecialchars($current['SCHEMA_NAME']) . "\n"
247 . ' </a>' . "\n"
248 . ' </td>' . "\n";
250 foreach ($column_order as $stat_name => $stat) {
251 if (array_key_exists($stat_name, $current)) {
252 if (is_numeric($stat['footer'])) {
253 $column_order[$stat_name]['footer'] += $current[$stat_name];
255 if ($stat['format'] === 'byte') {
256 list($value, $unit) = PMA_formatByteDown($current[$stat_name], 3, 1);
257 } elseif ($stat['format'] === 'number') {
258 $value = PMA_formatNumber($current[$stat_name], 0);
259 } else {
260 $value = htmlentities($current[$stat_name], 0);
262 echo ' <td class="value">';
263 if (isset($stat['description_function'])) {
264 echo '<dfn title="' . $stat['description_function']($current[$stat_name]) . '">';
266 echo $value;
267 if (isset($stat['description_function'])) {
268 echo '</dfn>';
270 echo '</td>' . "\n";
271 if ($stat['format'] === 'byte') {
272 echo ' <td class="unit">' . $unit . '</td>' . "\n";
276 foreach ($replication_types as $type) {
277 if (${"server_{$type}_status"}) {
278 echo '<td class="tool" style="text-align: center;">' . "\n";
280 if (strlen(array_search($current["SCHEMA_NAME"], ${"server_{$type}_Ignore_DB"}))>0) {
281 echo '<img class="icon" src="' . $pmaThemeImage . 's_cancel.png" width="16" height="16" alt="NOT REPLICATED" />' . "\n";
282 } else {
283 $key = array_search($current["SCHEMA_NAME"], ${"server_{$type}_Do_DB"});
285 if (strlen($key) > 0 || (${"server_{$type}_Do_DB"}[0] == "" && count(${"server_{$type}_Do_DB"}) == 1)) {
286 // if ($key != null) did not work for index "0"
287 echo '<img class="icon" src="' . $pmaThemeImage . 's_success.png" width="16" height="16" alt="REPLICATED" />' . "\n";
288 } else {
289 echo '';
293 echo '</td>';
297 if ($is_superuser) {
298 echo ' <td class="tool">' . "\n"
299 . ' <a onclick="'
300 . 'if (window.parent.setDb) window.parent.setDb(\'' . PMA_jsFormat($current['SCHEMA_NAME']) . '\');'
301 . '" href="./server_privileges.php?' . $url_query
302 . '&amp;checkprivs=' . urlencode($current['SCHEMA_NAME'])
303 . '" title="' . sprintf($strCheckPrivsLong, htmlspecialchars($current['SCHEMA_NAME']))
304 . '">'. "\n"
305 . ' '
306 . ($cfg['PropertiesIconic']
307 ? '<img class="icon" src="' . $pmaThemeImage . 's_rights.png" width="16" height="16" alt=" ' . $strCheckPrivs . '" /> '
308 : $strCheckPrivs) . "\n"
309 . ' </a></td>' . "\n";
311 echo '</tr>' . "\n";
312 } // end foreach ($databases as $key => $current)
313 unset($current, $odd_row);
315 echo '<tr>' . "\n";
316 if ($is_superuser || $cfg['AllowUserDropDatabase']) {
317 echo ' <th></th>' . "\n";
319 echo ' <th>' . $strTotalUC . ': ' . $databases_count . '</th>' . "\n";
320 foreach ($column_order as $stat_name => $stat) {
321 if (array_key_exists($stat_name, $first_database)) {
322 if ($stat['format'] === 'byte') {
323 list($value, $unit) = PMA_formatByteDown($stat['footer'], 3, 1);
324 } elseif ($stat['format'] === 'number') {
325 $value = PMA_formatNumber($stat['footer'], 0);
326 } else {
327 $value = htmlentities($stat['footer'], 0);
329 echo ' <th class="value">';
330 if (isset($stat['description_function'])) {
331 echo '<dfn title="' . $stat['description_function']($stat['footer']) . '">';
333 echo $value;
334 if (isset($stat['description_function'])) {
335 echo '</dfn>';
337 echo '</th>' . "\n";
338 if ($stat['format'] === 'byte') {
339 echo ' <th class="unit">' . $unit . '</th>' . "\n";
344 foreach ($replication_types as $type)
346 if (${"server_{$type}_status"})
347 echo ' <th></th>' . "\n";
350 if ($is_superuser) {
351 echo ' <th></th>' . "\n";
353 echo '</tr>' . "\n";
354 echo '</tbody>' . "\n"
355 .'</table>' . "\n";
356 unset($column_order, $stat_name, $stat, $databases, $table_columns);
358 if ($is_superuser || $cfg['AllowUserDropDatabase']) {
359 $common_url_query = PMA_generate_common_url(array('sort_by' => $sort_by, 'sort_order' => $sort_order, 'dbstats' => $dbstats));
360 echo '<img class="selectallarrow" src="' . $pmaThemeImage . 'arrow_' . $text_dir . '.png" width="38" height="22" alt="' . $strWithChecked . '" />' . "\n"
361 . '<a href="./server_databases.php' . $common_url_query . '&amp;checkall=1" onclick="if (markAllRows(\'tabledatabases\')) return false;">' . "\n"
362 . ' ' . $strCheckAll . '</a> / ' . "\n"
363 . '<a href="./server_databases.php' . $common_url_query . '" onclick="if (unMarkAllRows(\'tabledatabases\')) return false;">' . "\n"
364 . ' ' . $strUncheckAll . '</a>' . "\n"
365 . '<i>' . $strWithChecked . '</i>' . "\n";
366 PMA_buttonOrImage('drop_selected_dbs', 'mult_submit', 'drop_selected_dbs', $strDrop, 'b_deltbl.png');
369 echo '<ul><li id="li_switch_dbstats"><strong>' . "\n";
370 if (empty($dbstats)) {
371 echo ' <a href="./server_databases.php?' . $url_query . '&amp;dbstats=1"'
372 .' title="' . $strDatabasesStatsEnable . '">' . "\n"
373 .' ' . $strDatabasesStatsEnable;
374 } else {
375 echo ' <a href="./server_databases.php?' . $url_query . '"'
376 .' title="' . $strDatabasesStatsDisable . '">' . "\n"
377 .' ' . $strDatabasesStatsDisable;
379 echo '</a></strong><br />' . "\n";
380 PMA_Message::warning('strDatabasesStatsHeavyTraffic')->display();
381 echo '</li>' . "\n"
382 .'</ul>' . "\n";
383 echo '</form>';
384 } else {
385 echo $strNoDatabases;
387 unset($databases_count);
390 * Create new database.
392 if ($cfg['ShowCreateDb']) {
393 echo '<ul><li id="li_create_database">' . "\n";
394 require './libraries/display_create_database.lib.php';
395 echo ' </li>' . "\n";
396 echo '</ul>' . "\n";
400 * Sends the footer
402 require_once './libraries/footer.inc.php';