~skye/poker/index.php
view raw
<?php
require 'com.php';
require 'src/db.php';
/* generate an html form. accepts a name $n (either login or register) */
function mk_form($n) {
return <<<HTML
<form method="post" action="/act/auth.php">
<table>
<tr>
<td>name</td>
<td><input type="text" name="name"></td>
</tr>
<tr>
<td>password</td>
<td><input type="password" name="pass"></td>
</tr>
</table>
<input type="hidden" name="action" value="$n">
<input type="submit" value="$n">
</form>
HTML;
}
$db = new Database();
$me = whoami($db);
if (!!$me) {
$n = $me->name;
/* for those we know */
echo page("home", <<<HTML
<h1>welcome, <a href="/act/user.php?u=$n">$n</a></h1>
<h3>create new room</h3>
<form action="/act/mkroom.php" method="post">
<table>
<tr>
<td>name</td>
<td>
<input
type="text"
name="name"
>
</td>
</tr>
<tr>
<td>size</td>
<td>
<input
type="number"
name="size"
value="10"
>
</td>
</tr>
</table>
<input type="submit" value="create">
</form>
HTML);
} else {
/* for strangers */
$login = mk_form("login");
$register = mk_form("register");
echo page("home", <<<HTML
<h1>welcome to {$_(Cfg::TITLE)}</h1>
<div id="login-form" class="form">$login</div>
<div id="register-form" class="form">$register</div>
HTML);
}
?>