mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-16 15:41:16 +01:00
improve to print each game as multiple rows, one per device.
This commit is contained in:
parent
8c52836f9d
commit
ca49078730
1 changed files with 104 additions and 16 deletions
|
@ -3,25 +3,104 @@
|
||||||
<head></head>
|
<head></head>
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
<table border="3">
|
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
include "pwd.php";
|
include "pwd.php";
|
||||||
|
|
||||||
$cols = array( "array_upper(nperdevice,1)",
|
class Column {
|
||||||
"dead",
|
public $colname;
|
||||||
"room",
|
private $isArray;
|
||||||
"lang",
|
private $converter;
|
||||||
"ntotal",
|
function __construct( $name, $converter, $isArray ) {
|
||||||
"nperdevice",
|
$this->colname = $name;
|
||||||
"nsent" );
|
$this->isArray = $isArray;
|
||||||
|
$this->converter = $converter;
|
||||||
|
}
|
||||||
|
|
||||||
$sql = "SELECT " . join(",",$cols) . " FROM games";
|
function printTD( $index, $row, $nrows, $colData ) {
|
||||||
|
if ( 0 < $index ) {
|
||||||
|
if ( !$this->isArray && 0 < $row ) {
|
||||||
|
/* do nothing */
|
||||||
|
} else if ( 0 == $row && !$this->isArray ) {
|
||||||
|
$td = call_user_func( $this->converter, $colData );
|
||||||
|
echo "<td rowspan=$nrows>$td</td>";
|
||||||
|
} else {
|
||||||
|
$td = call_user_func( $this->converter, $this->nth_elem( $colData, $row ) );
|
||||||
|
echo "<td>$td</td>";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function nth_elem( $arr, $nn ) {
|
||||||
|
$arr = explode(',', trim($arr, '{}'));
|
||||||
|
return $arr[$nn];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function count_devs( $row ) {
|
||||||
|
return $row[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
function identity( $str ) {
|
||||||
|
return $str;
|
||||||
|
}
|
||||||
|
|
||||||
|
function int_to_lang( $str ) {
|
||||||
|
$lang = "unknown";
|
||||||
|
switch ( $str ) {
|
||||||
|
case 1: $lang = "English"; break;
|
||||||
|
case 2: $lang = "French"; break;
|
||||||
|
case 3: $lang = "German"; break;
|
||||||
|
case 4: $lang = "Turkish"; break;
|
||||||
|
case 5: $lang = "Arabic"; break;
|
||||||
|
case 6: $lang = "Spanish"; break;
|
||||||
|
case 7: $lang = "Swedish"; break;
|
||||||
|
case 8: $lang = "Polish"; break;
|
||||||
|
case 9: $lang = "Danish"; break;
|
||||||
|
case 10: $lang = "Italian"; break;
|
||||||
|
case 11: $lang = "Dutch"; break;
|
||||||
|
case 12: $lang = "Catalan"; break;
|
||||||
|
case 13: $lang = "Portuguese"; break;
|
||||||
|
case 15: $lang = "Russian"; break;
|
||||||
|
case 17: $lang = "Czech"; break;
|
||||||
|
case 18: $lang = "Greek"; break;
|
||||||
|
case 19: $lang = "Slovak"; break;
|
||||||
|
}
|
||||||
|
return $lang;
|
||||||
|
}
|
||||||
|
|
||||||
|
function ip_to_host($ip) {
|
||||||
|
return gethostbyaddr($ip);
|
||||||
|
}
|
||||||
|
|
||||||
|
$cols = array( new Column("array_upper(nperdevice,1)", null, false),
|
||||||
|
new Column("dead", "identity", false ),
|
||||||
|
new Column("room", "identity", false ),
|
||||||
|
new Column("lang", "int_to_lang", false ),
|
||||||
|
new Column("ntotal", "identity", false ),
|
||||||
|
new Column("nperdevice", "identity", true ),
|
||||||
|
new Column("ack", "identity", true ),
|
||||||
|
new Column("nsent", "identity", false ),
|
||||||
|
new Column("addrs", "ip_to_host", true ),
|
||||||
|
new Column("mtimes", "identity", true ),
|
||||||
|
);
|
||||||
|
|
||||||
|
$colnames = array();
|
||||||
|
foreach ( $cols as $index => $col ) {
|
||||||
|
$colnames[] = $col->colname;
|
||||||
|
}
|
||||||
|
$sql = "SELECT " . join( ",", $colnames ) . " FROM games "
|
||||||
|
. "WHERE NOT -NTOTAL = sum_array(nperdevice) LIMIT 200;";
|
||||||
echo "<p>$sql</p>";
|
echo "<p>$sql</p>";
|
||||||
|
|
||||||
|
echo "\n<table border=\"3\">\n";
|
||||||
|
|
||||||
echo "<tr>";
|
echo "<tr>";
|
||||||
|
/* index has no header */
|
||||||
|
echo "<th> </th>";
|
||||||
foreach ( $cols as $index => $col ) {
|
foreach ( $cols as $index => $col ) {
|
||||||
echo "<th>$col</th>";
|
if ( 0 != $index ) {
|
||||||
|
echo "<th>$col->colname</th>";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
echo "</tr>\n";
|
echo "</tr>\n";
|
||||||
|
|
||||||
|
@ -39,20 +118,29 @@ if (!$result) {
|
||||||
|
|
||||||
// iterate over result set
|
// iterate over result set
|
||||||
// print each row
|
// print each row
|
||||||
|
$count = 0;
|
||||||
while ( $row = pg_fetch_array($result) ) {
|
while ( $row = pg_fetch_array($result) ) {
|
||||||
|
$nrows = count_devs( $row );
|
||||||
|
for ( $devIndex = 0; $devIndex < $nrows; ++$devIndex ) {
|
||||||
echo "<tr>";
|
echo "<tr>";
|
||||||
|
if ( 0 == $devIndex ) {
|
||||||
|
echo "<td rowspan=$nrows>$count</td>";
|
||||||
|
}
|
||||||
foreach ( $cols as $index => $col ) {
|
foreach ( $cols as $index => $col ) {
|
||||||
echo "<td>" . "$row[$index]" . "</td>";
|
$col->printTD( $index, $devIndex, $nrows, $row[$index] );
|
||||||
}
|
}
|
||||||
echo "</tr>\n";
|
echo "</tr>\n";
|
||||||
}
|
}
|
||||||
|
++$count;
|
||||||
|
}
|
||||||
|
|
||||||
/* cleanup */
|
/* cleanup */
|
||||||
pg_free_result( $result );
|
pg_free_result( $result );
|
||||||
pg_close( $db );
|
pg_close( $db );
|
||||||
|
|
||||||
|
echo "</table>";
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
||||||
</table>
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
Loading…
Reference in a new issue