more indenting

This commit is contained in:
rootcoma 2013-11-25 23:08:19 -08:00
parent 0262a4afb7
commit 838dbf35b3
2 changed files with 256 additions and 275 deletions

View File

@ -1,9 +1,8 @@
<!DOCTYPE html>
<html lang="en">
<?php
include('config.php');
if(array_key_exists('username', $_GET)) {
// Convert username to lowercase in irc
// Convert username to lowercase in irc
$username = $_GET['username'];
$ircLowerSymbols = array("\\"=>"|", "["=>"{", "]"=>"}", "~"=>"^");
$usernameCanonical = strtr($username, $ircLowerSymbols);
@ -12,7 +11,53 @@ if(array_key_exists('username', $_GET)) {
$username = '';
$usernameCanonical = '';
}
if ($db && $username != '') {
$q = $db->prepare('select
tl.username as usrname,
sum(tl2.t * (tl2.n / (select sum(num_answered) from triviauserlog where username_canonical=:username))) as count,
sum(tl2.p * (tl2.n / (select sum(num_answered) from triviauserlog where username_canonical=:username))) as score,
(select sum(points_made) from triviauserlog t3 where username_canonical=:username) as points,
(select sum(num_answered) from triviauserlog t4 where username_canonical=:username) as q_asked,
(select num_editted from triviausers where username_canonical=:username) as num_e,
(select num_editted_accepted from triviausers where username_canonical=:username) as num_e_accepted,
(select num_questions_added from triviausers where username_canonical=:username) as num_q,
(select num_questions_accepted from triviausers where username_canonical=:username) as num_q_accepted,
(select num_reported from triviausers where username_canonical=:username) as num_r
from (select tl3.id as id2, tl3.average_time * 1.0 as t, tl3.average_score * 1.0 as p, tl3.num_answered * 1.0 as n from triviauserlog tl3) tl2
inner join triviauserlog tl
on tl.username_canonical=:username
and tl.id=tl2.id2');
$q->execute(array(':username'=>$usernameCanonical));
if ($q === false) {
die("Error: database error: table does not exist\n");
} else {
$result = $q->fetchAll();
if(sizeOf($result) > 0) {
$result = $result[0];
}
if(is_null($result['usrname'])) {
$result['usrname'] = "Not found";
$result['count'] = 0;
$result['score'] = 0;
$result['points'] = 0;
$result['q_asked'] = 0;
$result['num_e'] = 0;
$result['num_e_accepted'] = 0;
$result['num_q'] = 0;
$result['num_q_accepted'] = 0;
$result['num_r'] = 0;
}
}
} else {
if(isset($err)) {
die($err);
}
}
?>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Players &middot; TriviaTime</title>
@ -48,168 +93,104 @@ if(array_key_exists('username', $_GET)) {
</div><!-- /.navbar -->
</div>
<?php
if ($db && $username != '') {
$q = $db->prepare('select
tl.username as usrname,
sum(tl2.t * (tl2.n /
(select sum(num_answered)
from triviauserlog
where username_canonical=:username))
) as count,
sum(tl2.p * (tl2.n /
(select sum(num_answered)
from triviauserlog
where username_canonical=:username))
) as score,
(select sum(points_made) from triviauserlog t3 where username_canonical=:username) as points,
(select sum(num_answered) from triviauserlog t4 where username_canonical=:username) as q_asked,
(select num_editted from triviausers where username_canonical=:username) as num_e,
(select num_editted_accepted from triviausers where username_canonical=:username) as num_e_accepted,
(select num_questions_added from triviausers where username_canonical=:username) as num_q,
(select num_questions_accepted from triviausers where username_canonical=:username) as num_q_accepted,
(select num_reported from triviausers where username_canonical=:username) as num_r
from (select
tl3.id as id2,
tl3.average_time * 1.0 as t,
tl3.average_score * 1.0 as p,
tl3.num_answered * 1.0 as n
from triviauserlog tl3
) tl2
inner join triviauserlog tl
on tl.username_canonical=:username
and tl.id=tl2.id2
');
$q->execute(array(':username'=>$usernameCanonical));
if ($q === false) {
die("Error: database error: table does not exist\n");
} else {
$result = $q->fetchAll();
if(sizeOf($result) > 0) {
$result = $result[0];
}
if(is_null($result['usrname'])) {
$result['usrname'] = "Not found";
$result['count'] = 0;
$result['score'] = 0;
$result['points'] = 0;
$result['q_asked'] = 0;
$result['num_e'] = 0;
$result['num_e_accepted'] = 0;
$result['num_q'] = 0;
$result['num_q_accepted'] = 0;
$result['num_r'] = 0;
}
}
} else {
if(isset($err)) {
die($err);
}
}
?>
<div class="hero-unit">
<h1><?php echo $result['usrname']; ?></h1>
<p>Profile and user summary.</p>
<p>
</p>
</div>
<div class="hero-unit">
<h1><?php echo $result['usrname']; ?></h1>
<p>Profile and user summary.</p>
<p>
</p>
</div>
<div class="row">
<div class="span6">
<h2>Averages</h2>
<table class="table">
<thead>
<tr>
<th>Average Time/Question*</th>
<th>Average Points/Question*</th>
</tr>
</thead>
<tbody>
<?php
<div class="row">
<div class="span6">
<h2>Averages</h2>
<table class="table">
<thead>
<tr>
<th>Average Time/Question*</th>
<th>Average Points/Question*</th>
</tr>
</thead>
<tbody>
<?php
if(isset($result)) {
if(!is_null($result['usrname']) && $result['usrname'] != 'Not found') {
echo '<tr>';
echo '<td>' . number_format($result['count'],2) . '</td>';
echo '<td>' . number_format($result['score'],2) . '</td>';
echo '</tr>';
}
}
?>
</tbody>
</table>
</div>
<div class="span6">
<h2>Totals</h2>
<table class="table">
<thead>
<tr>
<th>Total Points</th>
<th>Number Answered*</th>
</tr>
</thead>
<tbody>
<?php
if(isset($result)) {
if(!is_null($result['usrname']) && $result['usrname'] != 'Not found') {
echo '<tr>';
echo '<td>' . number_format($result['points'],0) . '</td>';
echo '<td>' . number_format($result['q_asked'],0) . '</td>';
echo '</tr>';
}
}
?>
</tbody>
</table>
</div>
</div>
<div class="row">
<div class="span12">
<h2>Contributions</h2>
<table class="table">
<thead>
<tr>
<th>Number Edited</th>
<th>Edits Accepted</th>
<th>Questions Added</th>
<th>Questions Accepted</th>
<th>Reports Made</th>
</tr>
</thead>
<tbody>
<?php
if(isset($result)) {
if(!is_null($result['usrname']) && $result['usrname'] != 'Not found') {
echo '<tr>';
echo '<td>' . number_format($result['num_e'],0) . '</td>';
echo '<td>' . number_format($result['num_e_accepted'],0) . '</td>';
echo '<td>' . number_format($result['num_q'],0) . '</td>';
echo '<td>' . number_format($result['num_q_accepted'],0) . '</td>';
echo '<td>' . number_format($result['num_r'],0) . '</td>';
echo '</tr>';
}
}
?>
</tbody>
</table>
</div>
</div>
if(isset($result)) {
if(!is_null($result['usrname']) && $result['usrname'] != 'Not found') {
echo '<tr>';
echo '<td>' . number_format($result['count'],2) . '</td>';
echo '<td>' . number_format($result['score'],2) . '</td>';
echo '</tr>';
}
}
?>
</tbody>
</table>
</div>
<div class="span6">
<h2>Totals</h2>
<table class="table">
<thead>
<tr>
<th>Total Points</th>
<th>Number Answered*</th>
</tr>
</thead>
<tbody>
<?php
<div class="row">
<div class="span12">
<p>* These stats do not include KAOS</p>
</div>
</div>
<div class="footer">
<p>&copy; Trivialand 2013 - <a target="_blank" href="https://github.com/tannn/TriviaTime">Github</a></p>
</div>
if(isset($result)) {
if(!is_null($result['usrname']) && $result['usrname'] != 'Not found') {
echo '<tr>';
echo '<td>' . number_format($result['points'],0) . '</td>';
echo '<td>' . number_format($result['q_asked'],0) . '</td>';
echo '</tr>';
}
}
?>
</tbody>
</table>
</div>
</div>
<div class="row">
<div class="span12">
<h2>Contributions</h2>
<table class="table">
<thead>
<tr>
<th>Number Edited</th>
<th>Edits Accepted</th>
<th>Questions Added</th>
<th>Questions Accepted</th>
<th>Reports Made</th>
</tr>
</thead>
<tbody>
<?php
if(isset($result)) {
if(!is_null($result['usrname']) && $result['usrname'] != 'Not found') {
echo '<tr>';
echo '<td>' . number_format($result['num_e'],0) . '</td>';
echo '<td>' . number_format($result['num_e_accepted'],0) . '</td>';
echo '<td>' . number_format($result['num_q'],0) . '</td>';
echo '<td>' . number_format($result['num_q_accepted'],0) . '</td>';
echo '<td>' . number_format($result['num_r'],0) . '</td>';
echo '</tr>';
}
}
?>
</tbody>
</table>
</div>
</div>
<div class="row">
<div class="span12">
<p>* These stats do not include KAOS</p>
</div>
</div>
<div class="footer">
<p>&copy; Trivialand 2013 - <a target="_blank" href="https://github.com/tannn/TriviaTime">Github</a></p>
</div>
</div> <!-- /container -->
</div> <!-- /container -->
<!-- Le javascript
================================================== -->

View File

@ -101,129 +101,129 @@ include('config.php');
' and month=' . $week->format('n') .
' and year=' . $week->format('Y') .
')';
$week->add($interval);
}
?>
<div class="span6">
<h2>Week Top Scores</h2>
<table class="table">
<thead>
<tr>
<th>#</th>
<th>Username</th>
<th>Points</th>
</tr>
</thead>
<tbody>
<?php
if ($db) {
$q = $db->query("SELECT username, sum(points_made) as points FROM triviauserlog WHERE $sqlClause GROUP BY username_canonical ORDER BY points DESC LIMIT 10");
if ($q === false) {
die("Error: database error: table does not exist\n");
} else {
$result = $q->fetchAll();
foreach($result as $key=>$res) {
echo '<tr>';
echo '<td>' . ($key+1) . '</td>';
echo '<td><a href="profile.php?username=' . $res['username'] . '">' . $res['username'] . '</a></td>';
echo '<td>' . number_format($res['points'],0) . '</td>';
echo '</tr>';
}
}
} else {
die($err);
$week->add($interval);
}
?>
</tbody>
</table>
</div>
</div>
<div class="row">
<div class="span6">
<h2>Month Top Scores</h2>
<table class="table">
<thead>
<tr>
<th>#</th>
<th>Username</th>
<th>Points</th>
</tr>
</thead>
<tbody>
<?php
$day = date('j');
$month = date('m');
$year = date('Y');
if ($db) {
$q = $db->prepare("SELECT username, sum(points_made) as points FROM triviauserlog WHERE year=:year AND month=:month GROUP BY username_canonical ORDER BY points DESC LIMIT 10");
$q->execute(array(':year'=>$year, ':month'=>$month));
if ($q === false) {
die("Error: database error: table does not exist\n");
} else {
$result = $q->fetchAll();
foreach($result as $key=>$res) {
echo '<tr>';
echo '<td>' . ($key+1) . '</td>';
echo '<td><a href="profile.php?username=' . $res['username'] . '">' . $res['username'] . '</a></td>';
echo '<td>' . number_format($res['points'],0) . '</td>';
echo '</tr>';
<div class="span6">
<h2>Week Top Scores</h2>
<table class="table">
<thead>
<tr>
<th>#</th>
<th>Username</th>
<th>Points</th>
</tr>
</thead>
<tbody>
<?php
if ($db) {
$q = $db->query("SELECT username, sum(points_made) as points FROM triviauserlog WHERE $sqlClause GROUP BY username_canonical ORDER BY points DESC LIMIT 10");
if ($q === false) {
die("Error: database error: table does not exist\n");
} else {
$result = $q->fetchAll();
foreach($result as $key=>$res) {
echo '<tr>';
echo '<td>' . ($key+1) . '</td>';
echo '<td><a href="profile.php?username=' . $res['username'] . '">' . $res['username'] . '</a></td>';
echo '<td>' . number_format($res['points'],0) . '</td>';
echo '</tr>';
}
}
} else {
die($err);
}
}
} else {
die($err);
}
?>
</tbody>
</table>
</div>
<div class="span6">
<h2>Year Top Scores</h2>
<table class="table">
<thead>
<tr>
<th>#</th>
<th>Username</th>
<th>Points</th>
</tr>
</thead>
<tbody>
<?php
$day = date('j');
$month = date('m');
$year = date('Y');
?>
if ($db) {
$q = $db->prepare("SELECT username, sum(points_made) as points FROM triviauserlog WHERE year=:year GROUP BY username_canonical ORDER BY points DESC LIMIT 10");
$q->execute(array(':year'=>$year));
if ($q === false) {
die("Error: database error: table does not exist\n");
} else {
$result = $q->fetchAll();
foreach($result as $key=>$res) {
echo '<tr>';
echo '<td>' . ($key+1) . '</td>';
echo '<td><a href="profile.php?username=' . $res['username'] . '">' . $res['username'] . '</a></td>';
echo '<td>' . number_format($res['points'],0) . '</td>';
echo '</tr>';
</tbody>
</table>
</div>
</div>
<div class="row">
<div class="span6">
<h2>Month Top Scores</h2>
<table class="table">
<thead>
<tr>
<th>#</th>
<th>Username</th>
<th>Points</th>
</tr>
</thead>
<tbody>
<?php
$day = date('j');
$month = date('m');
$year = date('Y');
if ($db) {
$q = $db->prepare("SELECT username, sum(points_made) as points FROM triviauserlog WHERE year=:year AND month=:month GROUP BY username_canonical ORDER BY points DESC LIMIT 10");
$q->execute(array(':year'=>$year, ':month'=>$month));
if ($q === false) {
die("Error: database error: table does not exist\n");
} else {
$result = $q->fetchAll();
foreach($result as $key=>$res) {
echo '<tr>';
echo '<td>' . ($key+1) . '</td>';
echo '<td><a href="profile.php?username=' . $res['username'] . '">' . $res['username'] . '</a></td>';
echo '<td>' . number_format($res['points'],0) . '</td>';
echo '</tr>';
}
}
} else {
die($err);
}
}
} else {
die($err);
}
?>
?>
</tbody>
</table>
</div>
<div class="span6">
<h2>Year Top Scores</h2>
<table class="table">
<thead>
<tr>
<th>#</th>
<th>Username</th>
<th>Points</th>
</tr>
</thead>
<tbody>
<?php
$day = date('j');
$month = date('m');
$year = date('Y');
</tbody>
</table>
</div>
</div>
if ($db) {
$q = $db->prepare("SELECT username, sum(points_made) as points FROM triviauserlog WHERE year=:year GROUP BY username_canonical ORDER BY points DESC LIMIT 10");
$q->execute(array(':year'=>$year));
if ($q === false) {
die("Error: database error: table does not exist\n");
} else {
$result = $q->fetchAll();
foreach($result as $key=>$res) {
echo '<tr>';
echo '<td>' . ($key+1) . '</td>';
echo '<td><a href="profile.php?username=' . $res['username'] . '">' . $res['username'] . '</a></td>';
echo '<td>' . number_format($res['points'],0) . '</td>';
echo '</tr>';
}
}
} else {
die($err);
}
?>
<div class="footer">
<p>&copy; Trivialand 2013 - <a target="_blank" href="https://github.com/tannn/TriviaTime">Github</a></p>
</div>
</tbody>
</table>
</div>
</div>
</div> <!-- /container -->
<div class="footer">
<p>&copy; Trivialand 2013 - <a target="_blank" href="https://github.com/tannn/TriviaTime">Github</a></p>
</div>
</div> <!-- /container -->
<!-- Le javascript
================================================== -->