Initial import.
[openemr.git] / interface / main / myadmin / server_databases.php
blobe841ad8de3d8feead22787b02b10a486d36c2331
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_once('./libraries/grab_globals.lib.php');
12 /**
13 * Does the common work
15 $js_to_run = 'functions.js';
16 require('./server_common.inc.php');
19 <script type="text/javascript" language="javascript1.2">
20 <!--
21 function reload_window(db) {
22 if (typeof(window.parent) != 'undefined'
23 && typeof(window.parent.frames['nav']) != 'undefined') {
24 window.parent.frames['nav'].location.replace('./left.php?<?php echo PMA_generate_common_url('','','&');?>&db=' + db + '&hash=' + <?php echo (($cfg['QueryFrame'] && $cfg['QueryFrameJS']) ? 'window.parent.frames[\'queryframe\'].document.hashform.hash.value' : "'" . md5($cfg['PmaAbsoluteUri']) . "'"); ?>);
27 //-->
28 </script>
30 <?php
32 /**
33 * Sorts the databases array according to the user's choice
35 * @param array a record associated to a database
36 * @param array a record associated to a database
38 * @return integer a value representing whether $a should be before $b in the
39 * sorted array or not
41 * @global string the column the array shall be sorted by
42 * @global string the sorting order ('asc' or 'desc')
44 * @access private
46 function PMA_dbCmp($a, $b)
48 global $sort_by, $sort_order;
49 if ($sort_by == 'db_name') {
50 return ($sort_order == 'asc' ? 1 : -1) * strcasecmp($a['db_name'], $b['db_name']);
51 } else if ($a[$sort_by] == $b[$sort_by]) {
52 return strcasecmp($a['db_name'], $b['db_name']);
53 } else {
54 return ($sort_order == 'asc' ? 1 : -1) * ((int)$a[$sort_by] > (int)$b[$sort_by] ? 1 : -1);
56 } // end of the 'PMA_dbCmp()' function
59 /**
60 * Gets the databases list - if it has not been built yet
62 if ($server > 0 && empty($dblist)) {
63 PMA_availableDatabases();
67 /**
68 * Drops multiple databases
70 if ((!empty($drop_selected_dbs) || isset($query_type)) && ($is_superuser || $cfg['AllowUserDropDatabase'])) {
71 if (empty($selected_db) && ! (isset($query_type) && !empty($selected))) {
72 $message = $strNoDatabasesSelected;
73 } else {
74 $action = 'server_databases.php';
75 $submit_mult = 'drop_db' ;
76 $err_url = 'server_databases.php?' . PMA_generate_common_url();
77 require('./mult_submits.inc.php');
78 $message = sprintf($strDatabasesDropped, count($selected));
79 // we need to reload the database list now.
80 PMA_availableDatabases();
81 $reload = 1;
86 /**
87 * Displays the links
89 require('./server_links.inc.php');
92 /**
93 * Displays the sub-page heading
95 echo '<h2>' . "\n"
96 . ' ' . (empty($dbstats) ? $strDatabases : $strDatabasesStats) . "\n"
97 . '</h2>' . "\n";
101 * Checks if the user is allowed to do what he tries to...
103 if (!empty($dbstats) && !$is_superuser) {
104 echo $strNoPrivileges . "\n";
105 require_once('./footer.inc.php');
110 * Prepares the statistics
112 $statistics = array();
113 foreach($dblist AS $current_db) {
114 $tmp_array = array(
115 'db_name' => $current_db,
116 'tbl_cnt' => 0,
117 'data_sz' => 0,
118 'idx_sz' => 0,
119 'tot_sz' => 0
121 if (!empty($dbstats)) {
122 $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) . ';');
123 while ($row = PMA_mysql_fetch_array($res, MYSQL_ASSOC)) {
124 $tmp_array['tbl_cnt']++;
125 $tmp_array['data_sz'] += $row['Data_length'];
126 $tmp_array['idx_sz'] += $row['Index_length'];
129 $tmp_array['tot_sz'] = $tmp_array['data_sz'] + $tmp_array['idx_sz'];
130 $statistics[] = $tmp_array;
133 // avoids 'undefined index' errors
134 if (empty($sort_by)) {
135 $sort_by = 'db_name';
137 if (empty($sort_order)) {
138 if ($sort_by == 'db_name') {
139 $sort_order = 'asc';
140 } else {
141 $sort_order = 'desc';
145 // sorts the array
146 usort($statistics, 'PMA_dbCmp');
150 * Displays the page
152 if (count($statistics) > 0) {
153 echo '<form action="./server_databases.php" method="post" name="dbStatsForm">' . "\n"
154 . PMA_generate_common_hidden_inputs('', '', 1)
155 . ' <input type="hidden" name="dbstats" value="' . (empty($dbstats) ? '0' : '1') . '" />' . "\n"
156 . ' <input type="hidden" name="sort_by" value="' . $sort_by . '" />' . "\n"
157 . ' <input type="hidden" name="sort_order" value="' . $sort_order . '" />' . "\n"
158 . ' <table border="0">' . "\n"
159 . ' <tr>' . "\n"
160 . ($is_superuser || $cfg['AllowUserDropDatabase'] ? ' <th>&nbsp;</th>' . "\n" : '')
161 . ' <th>' . "\n"
162 . ' &nbsp;';
163 if (empty($dbstats)) {
164 echo $strDatabase . "\n"
165 . ' <img src="./images/asc_order.png" border="0" width="7" height="7" alt="' . $strAscending . '" />' . "\n"
166 . ' &nbsp;' . "\n"
167 . ' </th>' . "\n";
168 } else {
169 echo "\n"
170 . ' <a href="./server_databases.php?' . $url_query . '&amp;dbstats=1&amp;sort_by=db_name&amp;sort_order=' . (($sort_by == 'db_name' && $sort_order == 'asc') ? 'desc' : 'asc') . '">' . "\n"
171 . ' ' . $strDatabase . "\n"
172 . ($sort_by == 'db_name' ? ' <img src="./images/' . $sort_order . '_order.png" border="0" width="7" height="7" alt="' . ($sort_order == 'asc' ? $strAscending : $strDescending) . '" />' . "\n" : '')
173 . ' </a>' . "\n"
174 . ' &nbsp;' . "\n"
175 . ' </th>' . "\n"
176 . ' <th>' . "\n"
177 . ' &nbsp;' . "\n"
178 . ' <a href="./server_databases.php?' . $url_query . '&amp;dbstats=1&amp;sort_by=tbl_cnt&amp;sort_order=' . (($sort_by == 'tbl_cnt' && $sort_order == 'desc') ? 'asc' : 'desc') . '">' . "\n"
179 . ' ' . $strNumTables . "\n"
180 . ($sort_by == 'tbl_cnt' ? ' <img src="./images/' . $sort_order . '_order.png" border="0" width="7" height="7" alt="' . ($sort_order == 'asc' ? $strAscending : $strDescending) . '" />' . "\n" : '')
181 . ' </a>' . "\n"
182 . ' &nbsp;' . "\n"
183 . ' </th>' . "\n"
184 . ' <th colspan="2">' . "\n"
185 . ' &nbsp;' . "\n"
186 . ' <a href="./server_databases.php?' . $url_query . '&amp;dbstats=1&amp;sort_by=data_sz&amp;sort_order=' . (($sort_by == 'data_sz' && $sort_order == 'desc') ? 'asc' : 'desc') . '">' . "\n"
187 . ' ' . $strData . "\n"
188 . ($sort_by == 'data_sz' ? ' <img src="./images/' . $sort_order . '_order.png" border="0" width="7" height="7" alt="' . ($sort_order == 'asc' ? $strAscending : $strDescending) . '" />' . "\n" : '')
189 . ' </a>' . "\n"
190 . ' &nbsp;' . "\n"
191 . ' </th>' . "\n"
192 . ' <th colspan="2">' . "\n"
193 . ' &nbsp;' . "\n"
194 . ' <a href="./server_databases.php?' . $url_query . '&amp;dbstats=1&amp;sort_by=idx_sz&amp;sort_order=' . (($sort_by == 'idx_sz' && $sort_order == 'desc') ? 'asc' : 'desc') . '">' . "\n"
195 . ' ' . $strIndexes . "\n"
196 . ($sort_by == 'idx_sz' ? ' <img src="./images/' . $sort_order . '_order.png" border="0" width="7" height="7" alt="' . ($sort_order == 'asc' ? $strAscending : $strDescending) . '" />' . "\n" : '')
197 . ' </a>' . "\n"
198 . ' &nbsp;' . "\n"
199 . ' </th>' . "\n"
200 . ' <th colspan="2">' . "\n"
201 . ' &nbsp;' . "\n"
202 . ' <a href="./server_databases.php?' . $url_query . '&amp;dbstats=1&amp;sort_by=tot_sz&amp;sort_order=' . (($sort_by == 'tot_sz' && $sort_order == 'desc') ? 'asc' : 'desc') . '">' . "\n"
203 . ' ' . $strTotalUC . "\n"
204 . ($sort_by == 'tot_sz' ? ' <img src="./images/' . $sort_order . '_order.png" border="0" width="7" height="7" alt="' . ($sort_order == 'asc' ? $strAscending : $strDescending) . '" />' . "\n" : '')
205 . ' </a>' . "\n"
206 . ' &nbsp;' . "\n"
207 . ' </th>' . "\n";
209 if ($is_superuser) {
210 echo ' <th>' . "\n"
211 . ' &nbsp;' . $strAction . '&nbsp;' . "\n"
212 . ' </th>' . "\n";
214 echo ' </tr>' . "\n";
215 $useBgcolorOne = TRUE;
216 $total_calc = array(
217 'db_cnt' => 0,
218 'tbl_cnt' => 0,
219 'data_sz' => 0,
220 'idx_sz' => 0,
221 'tot_sz' => 0
223 foreach ($statistics as $current) {
224 list($data_size, $data_unit) = PMA_formatByteDown($current['data_sz'], 3, 1);
225 list($idx_size, $idx_unit) = PMA_formatByteDown($current['idx_sz'], 3, 1);
226 list($tot_size, $tot_unit) = PMA_formatByteDown($current['tot_sz'], 3, 1);
227 $total_calc['db_cnt']++;
228 $total_calc['tbl_cnt'] += $current['tbl_cnt'];
229 $total_calc['data_sz'] += $current['data_sz'];
230 $total_calc['idx_sz'] += $current['idx_sz'];
231 $total_calc['tot_sz'] += $current['tot_sz'];
232 echo ' <tr>' . "\n";
233 if ($is_superuser || $cfg['AllowUserDropDatabase']) {
234 echo ' <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . "\n"
235 . ' <input type="checkbox" name="selected_db[]" title="' . htmlspecialchars($current['db_name']) . '" value="' . htmlspecialchars($current['db_name']) . '" ' . (empty($checkall) ? '' : 'checked="checked" ') . '/>' . "\n"
236 . ' </td>' . "\n";
238 echo ' <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . "\n"
239 . ' <a onclick="reload_window(\'' . urlencode($current['db_name']) . '\'); return true;" href="' . $cfg['DefaultTabDatabase'] . '?' . $url_query . '&amp;db=' . urlencode($current['db_name']) . '" title="' . sprintf($strJumpToDB, htmlspecialchars($current['db_name'])) . '">' . "\n"
240 . ' ' . htmlspecialchars($current['db_name']) . "\n"
241 . ' </a>' . "\n"
242 . ' </td>' . "\n";
243 if (!empty($dbstats)) {
244 echo ' <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '" align="right">' . "\n"
245 . ' ' . $current['tbl_cnt'] . "\n"
246 . ' </td>' . "\n"
247 . ' <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '" align="right">' . "\n"
248 . ' ' . $data_size . "\n"
249 . ' </td>' . "\n"
250 . ' <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . "\n"
251 . ' ' . $data_unit . "\n"
252 . ' </td>' . "\n"
253 . ' <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '" align="right">' . "\n"
254 . ' ' . $idx_size . "\n"
255 . ' </td>' . "\n"
256 . ' <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . "\n"
257 . ' ' . $idx_unit . "\n"
258 . ' </td>' . "\n"
259 . ' <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '" align="right">' . "\n"
260 . ' <b>' . "\n"
261 . ' ' . $tot_size . "\n"
262 . ' </b>' . "\n"
263 . ' </td>' . "\n"
264 . ' <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . "\n"
265 . ' <b>' . "\n"
266 . ' ' . $tot_unit . "\n"
267 . ' </b>' . "\n"
268 . ' </td>' . "\n";
270 if ($is_superuser) {
271 echo ' <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . "\n"
272 . ' <a onclick="reload_window(\'' . urlencode($current['db_name']) . '\'); return true;" href="./server_privileges.php?' . $url_query . '&amp;checkprivs=' . urlencode($current['db_name']) . '" title="' . sprintf($strCheckPrivsLong, htmlspecialchars($current['db_name'])) . '">'. "\n"
273 . ' ' . $strCheckPrivs . "\n"
274 . ' </a>' . "\n"
275 . ' </td>' . "\n";
277 echo ' </tr>' . "\n";
278 $useBgcolorOne = !$useBgcolorOne;
279 } // end while
280 if (!empty($dbstats)) {
281 list($data_size, $data_unit) = PMA_formatByteDown($total_calc['data_sz'], 3, 1);
282 list($idx_size, $idx_unit) = PMA_formatByteDown($total_calc['idx_sz'], 3, 1);
283 list($tot_size, $tot_unit) = PMA_formatByteDown($total_calc['tot_sz'], 3, 1);
284 echo ' <tr>' . "\n"
285 . ' <th>&nbsp;</th>' . "\n"
286 . ' <th>' . "\n"
287 . ' &nbsp;' . $strTotalUC . ':&nbsp;' . $total_calc['db_cnt'] . '&nbsp;' . "\n"
288 . ' </th>' . "\n"
289 . ' <th align="right">' . "\n"
290 . ' &nbsp;' . $total_calc['tbl_cnt'] . '&nbsp;' . "\n"
291 . ' </th>' . "\n"
292 . ' <th align="right">' . "\n"
293 . ' &nbsp;' . $data_size . "\n"
294 . ' </th>' . "\n"
295 . ' <th align="left">' . "\n"
296 . ' ' . $data_unit . '&nbsp;' . "\n"
297 . ' </th>' . "\n"
298 . ' <th align="right">' . "\n"
299 . ' &nbsp;' . $idx_size . "\n"
300 . ' </th>' . "\n"
301 . ' <th align="left">' . "\n"
302 . ' ' . $idx_unit . '&nbsp;' . "\n"
303 . ' </th>' . "\n"
304 . ' <th align="right">' . "\n"
305 . ' &nbsp;' . $tot_size . "\n"
306 . ' </th>' . "\n"
307 . ' <th align="left">' . "\n"
308 . ' ' . $tot_unit . '&nbsp;' . "\n"
309 . ' </th>' . "\n"
310 . ' <th>&nbsp;</th>' . "\n"
311 . ' </tr>' . "\n";
313 if ($is_superuser || $cfg['AllowUserDropDatabase']) {
314 $common_url_query = PMA_generate_common_url() . '&amp;sort_by=' . $sort_by . '&amp;sort_order=' . $sort_order . '&amp;dbstats=' . (empty($dbstats) ? '10' : '3');
315 echo ' <tr>' . "\n"
316 . ' <td colspan="' . (empty($dbstats) ? '10' : '3') . '">' . "\n"
317 . ' <img src="./images/arrow_' . $text_dir . '.gif" border="0" width="38" height="22" alt="' . $strWithChecked . '" />' . "\n"
318 . ' <a href="./server_databases.php?' . $common_url_query . '&amp;checkall=1" onclick="setCheckboxes(\'dbStatsForm\', true); return false;">' . "\n"
319 . ' ' . $strCheckAll
320 . ' </a>' . "\n"
321 . ' &nbsp;/&nbsp;' . "\n"
322 . ' <a href="./server_databases.php?' . $common_url_query . '" onclick="setCheckboxes(\'dbStatsForm\', false); return false;">' . "\n"
323 . ' ' . $strUncheckAll
324 . ' </a>' . "\n"
325 . ' </td>' . "\n"
326 . ' </tr>' . "\n";
328 echo ' </table>' . "\n";
329 unset($data_size);
330 unset($data_unit);
331 unset($idx_size);
332 unset($idx_unit);
333 unset($tot_size);
334 unset($tot_unit);
335 if ($is_superuser || $cfg['AllowUserDropDatabase']) {
336 echo ' <ul>' . "\n";
338 if ($is_superuser && empty($dbstats)) {
339 echo ' <li>' . "\n"
340 . ' <b>' . "\n"
341 . ' <a href="./server_databases.php?' . $url_query . '&amp;dbstats=1" title="' . $strDatabasesStatsEnable . '">' . "\n"
342 . ' ' . $strDatabasesStatsEnable . "\n"
343 . ' </a>' . "\n"
344 . ' </b>' . "\n"
345 . ' <br />' . "\n"
346 . ' ' . $strDatabasesStatsHeavyTraffic . "\n"
347 . ' </li><br /><br />' . "\n";
348 } else if ($is_superuser && !empty($dbstats)) {
349 echo ' <li>' . "\n"
350 . ' <b>' . "\n"
351 . ' <a href="./server_databases.php?' . $url_query . '" title="' . $strDatabasesStatsDisable . '">'. "\n"
352 . ' ' . $strDatabasesStatsDisable . "\n"
353 . ' </a>' . "\n"
354 . ' </b>' . "\n"
355 . ' </li><br /><br />' . "\n";
357 if ($is_superuser || $cfg['AllowUserDropDatabase']) {
358 echo ' <li>' . "\n"
359 . ' <b>' . "\n"
360 . ' ' . $strDropSelectedDatabases . "\n"
361 . ' </b><br />' . "\n"
362 . ' <input type="submit" name="drop_selected_dbs" value="' . $strGo . '" />' . "\n"
363 . ' </li>' . "\n"
364 . ' </ul>' . "\n";
366 echo '</form>' . "\n";
367 } else {
368 echo $strNoDatabases . "\n";
373 * Sends the footer
375 require_once('./footer.inc.php');