<?

// Both the "brainfile" and a corresponding jpg file must exist for the menu item to appear.

include 'init.inc';
include 'misc.inc';
include_once 'classes/babble_generator.inc';

$selector = (int)$_GET['id'];
$sectioncount = 40;
if ($_SESSION['login']['general']>0 && $_GET['count']>0)
{
	$sectioncount = (int)$_GET['count'];
}

$gen = new babble_generator();

if ($_GET['list']!='')
{
	$html = implode(', ', $gen->list_commands());
	echo showpage($html."<br><br><br>");
	exit;
}

$brainfiles = array( array(),
	array(
		'title'=>'Shady drinks menu',
		'filename'=>'drink'),
	array(
		'title'=>'Random music genres',
		'filename'=>'music_genre'),
	array(
		'title'=>'Værktøj jeg skal huske',
		'filename'=>'vaerktoej'),
	array(
		'title'=>'Minecraft villager names',
		'filename'=>'villager'),
	array(
		'title'=>'Sære dyr fra andre planeter',
		'filename'=>'saere_dyr_fra_andre_planeter'),
	array(
		'title'=>'sounds',
		'filename'=>'sounds',
		'wordlength'=>3,
		'separator'=>"\n",
		'multiply_amount'=>5),
	array(
		'title'=>'A.I. Control Tags',
		'filename'=>'ai_control_tag',
		'wordlength'=>1,
		'separator'=>"<br><br>\n"),
	array(
		'title'=>'Bogstavsuppe .dk',
		'filename'=>'bogstavsuppe',
		'link'=>'http://www.bogstavsuppe.dk/'),
	array(
		'title'=>'R.Y.M genres',
		'filename'=>'rate your music',
		'wordlength'=>mt_rand(3,6),
		'sectioncount'=>6),
	array(
		'title'=>'Try',
		'filename'=>'a_try',
		'wordlength'=>5,
		'sectioncount'=>1),
	// array(
		// 'title'=>'Test',
		// 'filename'=>'test'),
	);

// besides the manually specified ones, also add anything listed by the API (if there's a .jpg for it)
foreach ($gen->list_commands() as $key=>$val)
{
	$exists = false;
	$filename = str_replace(' ', '_', $val);
	for ($x=0; $x<count($brainfiles); $x++)
	{
		if ($brainfiles[$x]['filename'] == $filename)
		{
			$exists = true;
		}
	}

	if (!$exists)
	{
		$brainfiles[] = array('title'=>ucfirst($val), 'filename'=>str_replace(' ', '_', $val));
	}
}

if (count($brainfiles[$selector])==0)
{
	include 'menu.php';
	exit;
}

$html = "<h1>".$brainfiles[$selector]['title']."</h1><br>\n";
$html .= "<a href=\"./\"><img src=\"media_step_back.png\" alt=\"Back\"></a> &nbsp; &nbsp; &nbsp; &nbsp; <a href=\"\"><img src=\"refresh.png\" alt=\"More\"></a><br><br>\n";

$separator = $brainfiles[$selector]['separator'] == '' ? "<br>\n" : $brainfiles[$selector]['separator'];
$gen->initialize($brainfiles[$selector]['filename']);

if ($brainfiles[$selector]['multiply_amount'] > 0)
{
	$sectioncount *= $brainfiles[$selector]['multiply_amount'];
}

if ($brainfiles[$selector]['sectioncount'] > 0)
{
	$sectioncount = $brainfiles[$selector]['sectioncount'];
}

$html .= str_replace("\n", $separator, $gen->generate($sectioncount, $brainfiles[$selector]['wordlength']));
$html .= "<br><br>\n";

echo showpage($html, array('title' => $brainfiles[$selector]['title']));

?>
