Commit: 43b45b690c191aa60cb7742be9eb2575a152203f Author: Kalle Sommer Nielsen <[email protected]> Thu, 24 Aug 2017 09:58:05 +0200 Parents: d6ea2e4a291ab56343fecc5bc339e5b29878696a Branches: master
Link: http://git.php.net/?p=web/bugs.git;a=commitdiff;h=43b45b690c191aa60cb7742be9eb2575a152203f Log: Make the outputs a little prettier instead of print_r/var_dump calls Changed paths: M include/functions.php M www/admin/index.php Diff: diff --git a/include/functions.php b/include/functions.php index 37ea6ab..13fa5d4 100644 --- a/include/functions.php +++ b/include/functions.php @@ -1966,6 +1966,76 @@ function backtrace_inline_menu($platform) echo "</p>\n"; } +function admin_table_static(array $header, array $rows) +{ + if (!$header || !$rows || sizeof($header) != sizeof($rows)) { + return; + } + + echo "<table>\n"; + echo "<tr class=\"bug_header\">\n"; + + foreach ($header as $name) { + echo "<th>$name</th>\n"; + } + + echo "</tr>\n"; + + + foreach ($rows as $row) { + $i = 0; + + echo "<tr>\n"; + + foreach ($row as $value) { + echo "<td class=\"bug_bg" . (int) !(!$i || !($i % 2)) . "\">$value</td>\n"; + + ++$i; + } + + echo "</tr>\n"; + } + + echo "</table>\n"; +} + +function admin_table_dynamic(array $rows) +{ + if (!$rows) { + return; + } + + $printed_header = false; + + echo "<table>\n"; + + foreach ($rows as $row) { + if (!$printed_header) { + echo "<tr class=\"bug_header\">\n"; + + foreach (array_keys($row) as $column) { + echo "<th>$column</th>\n"; + } + + echo "</tr>\n"; + + $printed_header = true; + } + + $i = 0; + + echo "<tr>\n"; + + foreach ($row as $value) { + echo "<td class=\"bug_bg" . (int) !(!$i || !($i % 2)) . "\">$value</td>\n"; + + ++$i; + } + + echo "</tr>\n"; + } +} + function mailto_list(array $mails) { if(!$mails) { diff --git a/www/admin/index.php b/www/admin/index.php index 9656eb2..57f695e 100644 --- a/www/admin/index.php +++ b/www/admin/index.php @@ -65,13 +65,17 @@ if ($action === 'phpinfo') { FROM bugdb_resolves "); - echo "<h3>List Responses</h3>"; - echo "<pre>\n"; + echo "<h3>List Responses</h3>\n"; + + $rows = array(); while ($row = $res->fetchRow(MDB2_FETCHMODE_ASSOC)) { - print_r($row); + // This is ugly but works (tm) + $row['message'] = '<pre>' . $row['message'] . '</pre>'; + + $rows[] = $row; } - echo "</pre>\n"; + admin_table_dynamic($rows); } elseif ($action === 'mysql') { $res = $dbh->query("SHOW TABLES"); @@ -88,19 +92,24 @@ if ($action === 'phpinfo') { echo "<p>Running MySQL <b>".$row['mysql_version']."</b></p>"; unset($row['mysql_version']); - echo "<p>Number of rows:</p><table><tr><th>Table</th><th>#</th></tr>\n"; - foreach ($row as $k => $v) { - echo "<tr><td>".str_replace("cnt_", "", $k)."</td>" - ."<td>$v</td></tr>\n"; - } - echo "</table>"; + echo "<h3>Number of rows:</h3>\n"; + + $rows = array(); + array_walk($row, function(&$value, $key) use($rows) { + $rows[str_replace('cnt_', '', $key)] = $value; + }); + + admin_table_static(['Table', 'Rows'], $rows); + + $rows = array(); $res = $dbh->query("SHOW TABLE STATUS"); - echo "<p>Table status:</p><pre>"; + echo "<h3>Table status:</h3>\n"; while ($row = $res->fetchRow(MDB2_FETCHMODE_ASSOC)) { - var_dump($row); + $rows[] = $row; } - echo "</pre>"; + + admin_table_dynamic($rows); } response_footer(); -- PHP Webmaster List Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
