~skye/poker/act/user.php

view raw


<?php

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

try {
	form_has_get([
		"u" => [1, Cfg::USERNAME_MAX_LEN]
	]);
} catch (Exception $e) {
	exit(page_err(
		"invalid form parameters: " . $e->getMessage()
	));
}

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

$u = $db->get_user($_GET["u"]);
$n = htmlspecialchars($u->name);

$me = whoami($db);
$admin = !!$me && $me->id == $u->id
	? "<a href=\"/act/admin.php?id={$me->id}\">admin</a>"
	: "";

$i = array();
foreach ($db->get_info($u->id)->into_array() as $k => $v) {
	switch ($k) {
	case "id": continue 2;
	case "uid": continue 2;
	}

	if (!$v) continue;

	$k = htmlspecialchars($k);
	$v = gettype($v) == "string"
		? "<pre>" . htmlspecialchars($v) . "</pre>"
		: htmlspecialchars((string)$v);

	array_push($i, <<<HTML
	<tr class="wide-row">
		<td>$k</td>
		<td>$v</td>
	</tr>
	HTML);
}
$i = join("", $i);

exit(page(
	$n,
	<<<HTML
	<table>
		<tr class="wide-row">
			<td class="p-head">$n</td>
			<td>$admin</td>
		</tr>
	</table>

	<table>$i</table>
	HTML
));

?>