remove todo, after upgrade PHPExcel
[phpmyadmin/arisferyanto.git] / server_databases.php
blob47037cc66e400ce4d6ec1f4eaa4edcc47cc5dbd5
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 = PMA_sanitize($_REQUEST['sort_by']);
28 if (isset($_REQUEST['sort_order'])
29 && strtolower($_REQUEST['sort_order']) == 'desc') {
30 $sort_order = 'desc';
31 } else {
32 $sort_order = 'asc';
35 $dbstats = empty($_REQUEST['dbstats']) ? 0 : 1;
36 $pos = empty($_REQUEST['pos']) ? 0 : (int) $_REQUEST['pos'];
39 /**
40 * Drops multiple databases
43 // workaround for IE behavior (it returns some coordinates based on where
44 // the mouse was on the Drop image):
45 if (isset($_REQUEST['drop_selected_dbs_x'])) {
46 $_REQUEST['drop_selected_dbs'] = true;
49 if ((isset($_REQUEST['drop_selected_dbs']) || isset($_REQUEST['query_type']))
50 && ($is_superuser || $cfg['AllowUserDropDatabase'])) {
51 if (! isset($_REQUEST['selected_dbs']) && ! isset($_REQUEST['query_type'])) {
52 $message = PMA_Message::error('strNoDatabasesSelected');
53 } else {
54 $action = 'server_databases.php';
55 $submit_mult = 'drop_db' ;
56 $err_url = 'server_databases.php?' . PMA_generate_common_url();
57 if (isset($_REQUEST['selected_dbs'])) {
58 $selected_db = $_REQUEST['selected_dbs'];
60 require './libraries/mult_submits.inc.php';
61 unset($action, $submit_mult, $err_url, $selected_db, $GLOBALS['db']);
62 if (empty($message)) {
63 $message = PMA_Message::success('strDatabasesDropped');
64 if ($mult_btn == $strYes) {
65 $message->addParam(count($selected));
66 } else {
67 $message->addParam(0);
74 /**
75 * Displays the links
77 require './libraries/server_links.inc.php';
80 /**
81 * Displays the sub-page heading
83 echo '<h2>' . "\n"
84 . ($GLOBALS['cfg']['MainPageIconic']
85 ? '<img class="icon" src="' . $pmaThemeImage . 's_db.png" width="16"'
86 .' height="16" alt="" />'
87 : '')
88 . ($dbstats ? $strDatabasesStats : $strDatabases) . "\n"
89 .'</h2>' . "\n";
91 /**
92 * Gets the databases list
94 if ($server > 0) {
95 $databases = PMA_DBI_get_databases_full(null, $dbstats, null, $sort_by,
96 $sort_order, $pos, true);
97 $databases_count = count($GLOBALS['pma']->databases);
98 } else {
99 $databases_count = 0;
104 * Displays the page
106 if ($databases_count > 0) {
107 reset($databases);
108 $first_database = current($databases);
109 // table col order
110 $column_order['DEFAULT_COLLATION_NAME'] = array(
111 'disp_name' => $strCollation,
112 'description_function' => 'PMA_getCollationDescr',
113 'format' => 'string',
114 'footer' => PMA_getServerCollation(),
116 $column_order['SCHEMA_TABLES'] = array(
117 'disp_name' => $strNumTables,
118 'format' => 'number',
119 'footer' => 0,
121 $column_order['SCHEMA_TABLE_ROWS'] = array(
122 'disp_name' => $strRows,
123 'format' => 'number',
124 'footer' => 0,
126 $column_order['SCHEMA_DATA_LENGTH'] = array(
127 'disp_name' => $strData,
128 'format' => 'byte',
129 'footer' => 0,
131 $column_order['SCHEMA_INDEX_LENGTH'] = array(
132 'disp_name' => $strIndexes,
133 'format' => 'byte',
134 'footer' => 0,
136 $column_order['SCHEMA_LENGTH'] = array(
137 'disp_name' => $strTotalUC,
138 'format' => 'byte',
139 'footer' => 0,
141 $column_order['SCHEMA_DATA_FREE'] = array(
142 'disp_name' => $strOverhead,
143 'format' => 'byte',
144 'footer' => 0,
147 $_url_params = array(
148 'pos' => $pos,
149 'dbstats' => $dbstats,
150 'sort_by' => $sort_by,
151 'sort_order' => $sort_order,
154 PMA_listNavigator($databases_count, $pos, $_url_params, 'server_databases.php', 'frame_content', $GLOBALS['cfg']['MaxDbList']);
156 $_url_params['pos'] = $pos;
158 echo '<form action="./server_databases.php" method="post" name="dbStatsForm" id="dbStatsForm">' . "\n"
159 . PMA_generate_common_hidden_inputs($_url_params);
161 $_url_params['sort_by'] = 'SCHEMA_NAME';
162 $_url_params['sort_order'] = ($sort_by == 'SCHEMA_NAME' && $sort_order == 'asc') ? 'desc' : 'asc';
164 echo '<table id="tabledatabases" class="data">' . "\n"
165 . '<thead>' . "\n"
166 . '<tr>' . "\n"
167 . ($is_superuser || $cfg['AllowUserDropDatabase'] ? ' <th></th>' . "\n" : '')
168 . ' <th><a href="./server_databases.php' . PMA_generate_common_url($_url_params) . '">' . "\n"
169 . ' ' . $strDatabase . "\n"
170 . ($sort_by == 'SCHEMA_NAME' ? ' <img class="icon" src="' . $pmaThemeImage . 's_' . $sort_order . '.png" width="11" height="9" alt="' . ($sort_order == 'asc' ? $strAscending : $strDescending) . '" />' . "\n" : '')
171 . ' </a></th>' . "\n";
172 $table_columns = 3;
173 foreach ($column_order as $stat_name => $stat) {
174 if (array_key_exists($stat_name, $first_database)) {
175 if ($stat['format'] === 'byte') {
176 $table_columns += 2;
177 $colspan = ' colspan="2"';
178 } else {
179 $table_columns++;
180 $colspan = '';
182 $_url_params['sort_by'] = $stat_name;
183 $_url_params['sort_order'] = ($sort_by == $stat_name && $sort_order == 'desc') ? 'asc' : 'desc';
184 echo ' <th' . $colspan . '>'
185 .'<a href="./server_databases.php' . PMA_generate_common_url($_url_params) . '">' . "\n"
186 .' ' . $stat['disp_name'] . "\n"
187 .($sort_by == $stat_name ? ' <img class="icon" src="' . $pmaThemeImage . 's_' . $sort_order . '.png" width="11" height="9" alt="' . ($sort_order == 'asc' ? $strAscending : $strDescending) . '" />' . "\n" : '')
188 .' </a></th>' . "\n";
192 foreach ($replication_types as $type)
194 if ($type=="master")
195 $name = "strReplicationMaster";
196 elseif($type == "slave")
197 $name = "strReplicationSlave";
198 if (${"server_{$type}_status"})
199 echo ' <th>'.$GLOBALS[$name].'</th>' . "\n";
202 if ($is_superuser) {
203 echo ' <th>' . ($cfg['PropertiesIconic'] ? '' : $strAction) . "\n"
204 . ' </th>' . "\n";
206 echo '</tr>' . "\n"
207 . '</thead>' . "\n"
208 . '<tbody>' . "\n";
210 $odd_row = true;
211 foreach ($databases as $current) {
212 echo '<tr class="' . ($odd_row ? 'odd' : 'even') . '">' . "\n";
213 $odd_row = ! $odd_row;
215 if ($is_superuser || $cfg['AllowUserDropDatabase']) {
216 echo ' <td class="tool">' . "\n";
217 if ($current['SCHEMA_NAME'] != 'mysql'
218 && $current['SCHEMA_NAME'] != 'information_schema') {
219 echo ' <input type="checkbox" name="selected_dbs[]" title="' . htmlspecialchars($current['SCHEMA_NAME']) . '" value="' . htmlspecialchars($current['SCHEMA_NAME']) . '" ' . (empty($checkall) ? '' : 'checked="checked" ') . '/>' . "\n";
220 } else {
221 echo ' <input type="checkbox" name="selected_dbs[]" title="' . htmlspecialchars($current['SCHEMA_NAME']) . '" value="' . htmlspecialchars($current['SCHEMA_NAME']) . '" disabled="disabled"/>' . "\n";
223 echo ' </td>' . "\n";
225 echo ' <td class="name">' . "\n"
226 . ' <a onclick="'
227 . 'if (window.parent.openDb &amp;&amp; window.parent.openDb(\'' . PMA_jsFormat($current['SCHEMA_NAME'], false) . '\')) return false;'
228 . '" href="index.php?' . $url_query . '&amp;db='
229 . urlencode($current['SCHEMA_NAME']) . '" title="'
230 . sprintf($strJumpToDB, htmlspecialchars($current['SCHEMA_NAME']))
231 . '" target="_parent">' . "\n"
232 . ' ' . htmlspecialchars($current['SCHEMA_NAME']) . "\n"
233 . ' </a>' . "\n"
234 . ' </td>' . "\n";
236 foreach ($column_order as $stat_name => $stat) {
237 if (array_key_exists($stat_name, $current)) {
238 if (is_numeric($stat['footer'])) {
239 $column_order[$stat_name]['footer'] += $current[$stat_name];
241 if ($stat['format'] === 'byte') {
242 list($value, $unit) = PMA_formatByteDown($current[$stat_name], 3, 1);
243 } elseif ($stat['format'] === 'number') {
244 $value = PMA_formatNumber($current[$stat_name], 0);
245 } else {
246 $value = htmlentities($current[$stat_name], 0);
248 echo ' <td class="value">';
249 if (isset($stat['description_function'])) {
250 echo '<dfn title="' . $stat['description_function']($current[$stat_name]) . '">';
252 echo $value;
253 if (isset($stat['description_function'])) {
254 echo '</dfn>';
256 echo '</td>' . "\n";
257 if ($stat['format'] === 'byte') {
258 echo ' <td class="unit">' . $unit . '</td>' . "\n";
262 foreach ($replication_types as $type) {
263 if (${"server_{$type}_status"}) {
264 echo '<td class="tool" style="text-align: center;">' . "\n";
266 if (strlen(array_search($current["SCHEMA_NAME"], ${"server_{$type}_Ignore_DB"}))>0) {
267 echo '<img class="icon" src="' . $pmaThemeImage . 's_cancel.png" width="16" height="16" alt="NOT REPLICATED" />' . "\n";
268 } else {
269 $key = array_search($current["SCHEMA_NAME"], ${"server_{$type}_Do_DB"});
271 if (strlen($key) > 0 || (${"server_{$type}_Do_DB"}[0] == "" && count(${"server_{$type}_Do_DB"}) == 1)) {
272 // if ($key != null) did not work for index "0"
273 echo '<img class="icon" src="' . $pmaThemeImage . 's_success.png" width="16" height="16" alt="REPLICATED" />' . "\n";
274 } else {
275 echo '';
279 echo '</td>';
283 if ($is_superuser) {
284 echo ' <td class="tool">' . "\n"
285 . ' <a onclick="'
286 . 'if (window.parent.setDb) window.parent.setDb(\'' . PMA_jsFormat($current['SCHEMA_NAME']) . '\');'
287 . '" href="./server_privileges.php?' . $url_query
288 . '&amp;checkprivs=' . urlencode($current['SCHEMA_NAME'])
289 . '" title="' . sprintf($strCheckPrivsLong, htmlspecialchars($current['SCHEMA_NAME']))
290 . '">'. "\n"
291 . ' '
292 . ($cfg['PropertiesIconic']
293 ? '<img class="icon" src="' . $pmaThemeImage . 's_rights.png" width="16" height="16" alt=" ' . $strCheckPrivs . '" /> '
294 : $strCheckPrivs) . "\n"
295 . ' </a></td>' . "\n";
297 echo '</tr>' . "\n";
298 } // end foreach ($databases as $key => $current)
299 unset($current, $odd_row);
301 echo '<tr>' . "\n";
302 if ($is_superuser || $cfg['AllowUserDropDatabase']) {
303 echo ' <th></th>' . "\n";
305 echo ' <th>' . $strTotalUC . ': ' . $databases_count . '</th>' . "\n";
306 foreach ($column_order as $stat_name => $stat) {
307 if (array_key_exists($stat_name, $first_database)) {
308 if ($stat['format'] === 'byte') {
309 list($value, $unit) = PMA_formatByteDown($stat['footer'], 3, 1);
310 } elseif ($stat['format'] === 'number') {
311 $value = PMA_formatNumber($stat['footer'], 0);
312 } else {
313 $value = htmlentities($stat['footer'], 0);
315 echo ' <th class="value">';
316 if (isset($stat['description_function'])) {
317 echo '<dfn title="' . $stat['description_function']($stat['footer']) . '">';
319 echo $value;
320 if (isset($stat['description_function'])) {
321 echo '</dfn>';
323 echo '</th>' . "\n";
324 if ($stat['format'] === 'byte') {
325 echo ' <th class="unit">' . $unit . '</th>' . "\n";
330 foreach ($replication_types as $type)
332 if (${"server_{$type}_status"})
333 echo ' <th></th>' . "\n";
336 if ($is_superuser) {
337 echo ' <th></th>' . "\n";
339 echo '</tr>' . "\n";
340 echo '</tbody>' . "\n"
341 .'</table>' . "\n";
342 unset($column_order, $stat_name, $stat, $databases, $table_columns);
344 if ($is_superuser || $cfg['AllowUserDropDatabase']) {
345 $common_url_query = PMA_generate_common_url() . '&amp;sort_by=' . $sort_by . '&amp;sort_order=' . $sort_order . '&amp;dbstats=' . $dbstats;
346 echo '<img class="selectallarrow" src="' . $pmaThemeImage . 'arrow_' . $text_dir . '.png" width="38" height="22" alt="' . $strWithChecked . '" />' . "\n"
347 . '<a href="./server_databases.php?' . $common_url_query . '&amp;checkall=1" onclick="if (markAllRows(\'tabledatabases\')) return false;">' . "\n"
348 . ' ' . $strCheckAll . '</a> / ' . "\n"
349 . '<a href="./server_databases.php?' . $common_url_query . '" onclick="if (unMarkAllRows(\'tabledatabases\')) return false;">' . "\n"
350 . ' ' . $strUncheckAll . '</a>' . "\n"
351 . '<i>' . $strWithChecked . '</i>' . "\n";
352 PMA_buttonOrImage('drop_selected_dbs', 'mult_submit', 'drop_selected_dbs', $strDrop, 'b_deltbl.png');
355 echo '<ul><li id="li_switch_dbstats"><strong>' . "\n";
356 if (empty($dbstats)) {
357 echo ' <a href="./server_databases.php?' . $url_query . '&amp;dbstats=1"'
358 .' title="' . $strDatabasesStatsEnable . '">' . "\n"
359 .' ' . $strDatabasesStatsEnable;
360 } else {
361 echo ' <a href="./server_databases.php?' . $url_query . '"'
362 .' title="' . $strDatabasesStatsDisable . '">' . "\n"
363 .' ' . $strDatabasesStatsDisable;
365 echo '</a></strong><br />' . "\n";
366 PMA_Message::warning('strDatabasesStatsHeavyTraffic')->display();
367 echo '</li>' . "\n"
368 .'</ul>' . "\n";
369 echo '</form>';
370 } else {
371 echo $strNoDatabases;
373 unset($databases_count);
376 * Create new database.
378 if ($cfg['ShowCreateDb']) {
379 echo '<ul><li id="li_create_database">' . "\n";
380 require './libraries/display_create_database.lib.php';
381 echo ' </li>' . "\n";
382 echo '</ul>' . "\n";
386 * Sends the footer
388 require_once './libraries/footer.inc.php';