~skye/poker/act/room.php

view raw


<?php

require '../com.php';
require '../src/room.php';

function mk_user_table($r) {
	$x = join("\n", array_map(
		fn($x) => <<<HTML
		<tr>
			<td>{$x->name}</td>
		</tr>
		HTML,

		$r->get_users()
	));
	return "<table>$x</table>";
}

try {
	form_has_get([
		"h" => [1, 64],
	]);
} catch (Exception $e) {
	exit(page_err("invalid form params: " . $e->getMessage()));
}

$r = Room::from_hash($_GET["h"]);
$n = htmlspecialchars($r->name);
$o = $r->get_owner();

$db = new Database("../run/poker.db");
$me = whoami($db);

/* is logged in? */
$l = !!$me;
/* is joined? */
$j = $me->id == $o->id;
$jh = $j ? "you are in this room" : "";

$ut = mk_user_table($r);
echo page(
	"$n",
	<<<HTML
	<span>
		<span class="p-head-mid">$n</span>
		owned by
		<a href="/act/user.php?u={$o->name}" target="_blank">
			{$o->name}
		</a>
	</span>

	<div class="left">
		<h3>users</h3>
		$ut
	</div>
	<div class="right">
		<p>$jh</p>
	</div>
	HTML
);

?>