<?php
function dj_file($dj) {
	if (!strcmp('alice', $dj)) return 'alice-votes.txt';
	if (!strcmp('r3', $dj)) return 'r3-votes.txt';
	return false;
}
function cast_vote($dj) {
	if (!($file = dj_file($dj))) return false;
	$fp = fopen($file, 'r');
	if ($fp) {
		$votes = fgets($fp);
		fclose($fp);
	} else $votes = 0;
	$fp = fopen($file, 'w');
	fputs($fp, ++$votes);
	fclose($fp);
}
function get_votes($dj) {
	$file = dj_file($dj);
	$fp = fopen($file, 'r');
	if ($fp) { $votes = fgets($fp); fclose($fp); }
	else $votes = 0;
	return $votes;
}
if (isset($_POST['dj'])) {
	cast_vote($_POST['dj']);
	header('Location: ' . $_SERVER['REQUEST_URI']);
	exit();
}
?><!DOCTYPE HTML>
<HTML>
<head>
	<title>30XXFM Radio - Pretty Boy Yumi's Personal Website</title>
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<link rel=stylesheet href="/yumi.css">
	<link rel=stylesheet href="radio.css">
	<meta name=description content="30XXFM Future Radio" />
</head>
<body>
<main>
<span>[ <a href="/">Home</a> ]</span>
<header>
	<h1>30XXFM Radio</h1>
	<span>Internet Radio from the Future</span><br />
</header>
<hr>
<h2>Battle of the Millenia: Pick your DJ</h2>
<p>Click either button to check out a DJ's set.</p>
<div class=radio-choice>
	<a href="alicedj/" id=alice>30XXFM-1<br />Alice DJ</a>
	<a href="r3/" id=r3>30XXFM-2<br />DJR3</a>
</div>
<p>Welcome to the dual-broadcast internet radio station, 30XXFM, run out of
Prettyboy-Yumi's apartment in Raleigh North Carolina.</p>

<p>Yumi has programmed two
intelligent DJs to battle each other on the air-waves of 30XXFM for a millenia... who will
win: only who is still standing after 1000 years...? It will be a fierce battle of
thumping sound and club beats, becoming the zenith music-reality of all
time: 30XX.</p>

<div id=bargraph><dl>
<?php
	$data = [
		'Alice DJ' => get_votes('alice'),
		'DJR3' => get_votes('r3')
	];
	foreach ($data as $label => $value)
		if ($value > $max) $max = $value;
	foreach ($data as $label => $value) {
		$ratio = $value / $max;
		$width = ($ratio * 100) . '%';
	print <<<BAR
		<dt>$label</dt>
		<dd style="width:$width;">$value</dd>
BAR;
	}
?>
</div>
<form method=post class=dj-vote>My favorite DJ is:<br />
	<input type=radio name=dj value=alice>Alice DJ</input>
  	<input type=radio name=dj value=r3>DJR3</input><br />
<input type=submit value='Vote!'></form>

<h3><a href="alicedj/">30XXFM-1</a> Alice DJ's Future Show</h3><hr />
<p>30XXFM-1 is run by <strong>Alice DJ</strong> who
likes to play pop music and chill tunes; she is a really cool DJ and is very
sociable; she plays at clubs in Shibuya, Toyko and is the center of every
group of DJ friends she's met. She likes to play electronic, JRock,
chillwave, hip-hop and American pop.</p>
<h3><a href="r3/">30XXFM-2</a> DJR3's Basement Show</h3><hr />
<p>30XXFM-2 is run by the mysterious <strong>DJR3</strong> who plays <em>jungle,
hardstyle, gabber</em> hits that you won't hear outside that weird
basement show your cousin goes to every Friday night. DJR3 plays music that will excite
you; in fact, it's rumored nobody has ever battled
DJR3 and lived...</p>
<p><em>Who will be standing after 1000 years? We've only just begun to
know...</em></p>
</main>
</body>
</HTML>
