<?php

ob_start();

include("include/casino.class.php");
require "include/bittorrent.php";

dbconn();
loggedinorreturn();

$played_type = isset($_GET["t"]) ? intval($_GET["t"]) : false;
$played_game = isset($_GET["g"]) ? intval($_GET["g"]) : false;
$played_zuf = isset($_GET["z"]) ? intval($_GET["z"]) : false;

$casino = new Casino($CURUSER["id"]);

$max_einsatz = $CURUSER["uploaded"] - $CURUSER["downloaded"];
$max_einsatz_gb = round($max_einsatz / CASINO_BYTE_DIV, 2);

// Wetteinsätze auslesen
if ($stakes = Casino::getStakeAll()) {
	// Erzeugt die <option>-Tags für die Wetteinstätze
	foreach($stakes as $stake){
		$stake_options .= "<option value=\"".$stake["csid"]."\"";
		if (isset($_POST["c_stake"]) && $_POST["c_stake"] == $stake["csid"]) {
			$stake_options .= " selected";
		}
		$stake_options .= ">".$stake["name"]."</option>\n";
	}
}

if (!isset($_GET["t"])) {
	$_SESSION["casino_dice"]["round"] = 0;
	$_SESSION["casino_dice"]["win"] = false;
	$_SESSION["casino_dice"]["lost"] = false;
	$_SESSION["casino_dice"]["point"] = false;
	$_SESSION["casino_dice"]["stake"] = false;
}


$_a=0;
//stdhead("New Casino Mod");

//if (get_user_class()>=UC_MODERATOR) {

?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="expires" content="300">
<meta http-equiv="cache-control" content="private">
<meta name="robots" content="noindex, nofollow, noarchive">
<meta name="MSSmartTagsPreventParsing" content="true">
<link rel="stylesheet" href="pic/nightshift/nightshift.css" type="text/css">
</head>
<body>
<table width="75%" align="center">
	<tr>
		<td colspan="3" align="center"><h1>Willkommen im Casino!&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</h1></td>
	</tr>
	<tr>
		<td valign="top" align="center">

<table class="tableinborder" width="200" cellspacing="4" cellpadding="2">
	<tr>
		<td colspan="2" align="center" class="tabletitle"><b><?=$CURUSER["username"]?>'s Konto</b></td>
	</tr>
	<tr>
		<td align="right" class="tabler">zur Verf&uuml;gung:</td>
		<td class="tableb"><?=sprintf("%01.2f",$max_einsatz_gb)?> <?=CASINO_BYTE_STR?></td>
	</tr>
	<tr>
		<td align="right" class="tabler">Ratio:</td>
		<td class="tableb"><?=round($casino->ratio, 3)?></td>
	</tr>
</table>
<table class="tableinborder" width="200" cellspacing="4" cellpadding="2">
	<tr>
		<td align="right" class="tabler">Gewonnen:</td>
		<td class="tableb"><?=sprintf("%01.2f",$casino->win_all / CASINO_BYTE_DIV)?> <?=CASINO_BYTE_STR?></td>
	</tr>
	<tr>
		<td align="right" class="tabler">Verloren:</td>
		<td class="tableb"><?=sprintf("%01.2f",$casino->lost_all / CASINO_BYTE_DIV)?> <?=CASINO_BYTE_STR?></td>
	</tr>
	<tr>
		<td align="right" class="tabler">Spiele <small>(heute)</small>:</td>
		<td class="tableb"><?=$casino->games_today?> <small>(max. <?=$casino->max_games_day?>)</small></td>
	</tr>
</table>
<table class="tableinborder" width="200" cellspacing="4" cellpadding="2">
	<tr>
		<td colspan="2" align="center" class="tabletitle"><b>Casino Stats</b></td>
	</tr>
	<tr>
		<td align="right" class="tabler">Gewonnen:</td>
		<td class="tableb"><?=sprintf("%01.2f",$casino->win_overall / CASINO_BYTE_DIV / 1024)?> GB</td>
	</tr>
	<tr>
		<td align="right" class="tabler">Verloren:</td>
		<td class="tableb"><?=sprintf("%01.2f",$casino->lost_overall / CASINO_BYTE_DIV / 1024)?> GB</td>
	</tr>
	<tr>
		<td align="right" class="tabler">Spiele <small>(gesamt)</small>:</td>
		<td class="tableb"><?=$casino->games_anz_all?></td>
	</tr>
</table>


		</td>
		<td valign="top" align="center">


<form method="POST" action="casino_do.php">
<table class="tableinborder" width="250" cellspacing="4" cellpadding="2">
	<tr>
		<td colspan="2" align="center" class="tabletitle"><b>Rot oder Schwarz?</b></td>
	</tr>
<?
// Wurde "Rot oder Schwarz" gespielt?
if ($played_type == 1 && $played_game != 0) {
	echo "<tr><td align=\"center\" colspan=\"2\" class=\"tableb\" style=\"text-align: center;\">";
	if ($played_zuf == 1) {
		echo "<div style=\"width: 100%; color: white; background-color: red;\">Rot</div>";
	}
	else echo "<div style=\"width: 100%; color: white; background-color: black;\">Schwarz</div>";
	if ($played_game == 1) {
		echo "<div class=\"c_win\">Du hast gewonnen!</div>";
	}
	else echo "<div class=\"c_lost\">leider verloren!</div>";
	echo "</td></tr>";
}
elseif ($played_type == 1) {
	echo "<tr><td align=\"center\" colspan=\"2\" class=\"tableb\" style=\"text-align: center\">";
	echo "Bitte eine Farbe auswählen!";
	echo "</td></tr>";
}
?>
	<tr>
		<td class="tabler">Ich setze auf:</td>
		<td class="tableb">
			<div style="background-color: red; text-align: center"><input type="radio" name="c_farbe" value="1"></div>
			<div style="background-color: black; text-align: center"><input type="radio" name="c_farbe" value="2"></div>
		</td>
	</tr>
	<tr>
		<td class="tabler">Einsatz:</td>
		<td class="tableb">
			<select name="c_stake">
				<?=$stake_options?>
			</select>
		</td>
	</tr>
	<tr>
		<td class="tableb" colspan="2" style="text-align: center; padding: 5px">
			<input type="submit" name="c_rob" value="los"><br />
		</td>
	</tr>
	<tr>
		<td class="tablec" colspan="2" align="center">
			<small>( Gewinnchance 1:2 )</small>
		</td>
	</tr>
</table>
</form>

<br /><br />

<form method="POST" action="casino_do.php">
<table class="tableinborder" width="250" cellspacing="4" cellpadding="2">
	<tr>
		<td colspan="2" align="center" class="tabletitle"><b>BET or DIE</b></td>
	</tr>
	<tr>
		<td align="center" class="tableb" style="text-align:center; padding: 3px;" colspan="2"><b>Jackpot: <?=round($casino->bet_jackpot / CASINO_BYTE_DIV, 0)?> <?=CASINO_BYTE_STR?></b></td>
	</tr>
<?
// Wurde "Bet or Die" gespielt?
if ($played_type == 3) {
	echo "<tr><td align=\"center\" colspan=\"2\" class=\"tableb\" style=\"text-align: center;\">";
	if ($played_game == 1) {
		echo "Leider nicht die richtige Zahl,<br />probiers nochmal!";
	}

	elseif ($_SESSION["casino_bet"]["err"]["minmax"]) echo "die Zahl muss zwischen<br />".CASINO_MIN_BET." und ".CASINO_MAX_BET." liegen";
	elseif ($_SESSION["casino_bet"]["err"]["isbet"]) echo "Auf die Zahl<br />wurde schon gesetzt!";
	elseif ($_SESSION["casino_bet"]["win"]) echo "<div class=\"c_win\">Du hast den Jackpot gewonnen!<br />Dir wurden ".$_SESSION["casino_bet"]["win"]." ".CASINO_BYTE_STR." gutgeschrieben ;)</div>";


	echo "</td></tr>";
}
?>
	<tr>
		<td class="tabler">Ich setze auf die Zahl:</td>
		<td class="tableb">
			<input type="text" name="c_number" size="8">
		</td>
	</tr>
	<tr>
		<td class="tabler">Einsatz:</td>
		<td class="tableb">
			<?=$casino->bet_ammount?> <?=CASINO_BYTE_STR?>
		</td>
	</tr>
	<tr>
		<td class="tableb" colspan="2" style="text-align: center; padding: 5px">
			<input type="submit" name="c_bet" value="wetten"><br />
		</td>
	</tr>
	<tr>
		<td class="tablec" colspan="2" align="center">
			<small>( Gewinnchance 1:<?=((CASINO_MAX_BET - (CASINO_MIN_BET-1)) - $casino->bet_anz_all)?> )</small>
		</td>
	</tr>
</table>
</form>

		</td>
		<td valign="top" align="center">

<form method="POST" action="casino_do.php">
<table class="tableinborder" width="250" cellspacing="4" cellpadding="2">
	<tr>
		<td colspan="2" align="center" class="tabletitle"><b>W&uuml;rfel (Craps)</b></td>
	</tr>
<?
// Wurde gewürfelt?
if (isset($_SESSION["casino_dice"]["round"]) && $_SESSION["casino_dice"]["round"] > 0) {
	echo "<tr><td align=\"center\" colspan=\"2\" class=\"tableb\" style=\"text-align: center\">";
	echo "<img src=\"img/casino/wurf".$_SESSION["casino_dice"]["zuf1"].".gif\" width=\"80\" height=\"80\">";
	echo "<img src=\"img/casino/wurf".$_SESSION["casino_dice"]["zuf2"].".gif\" width=\"80\" height=\"80\">";
	echo "<br>";
	if ($_SESSION["casino_dice"]["win"] == 1) {
		echo "<div class=\"c_win\">Du hast gewonnen!</div>";
	}
	elseif ($_SESSION["casino_dice"]["lost"] == 1) echo "<div class=\"c_lost\">leider verloren!</div>";
	echo "</td></tr>";
}
elseif ($played_type == 2) {
	echo "<tr><td align=\"center\" colspan=\"2\" class=\"tablea\" style=\"text-align: center\">";
	echo "Bitte eine Zahl auswählen!";
	echo "</td></tr>";
}
?>
	<tr>
		<td class="tabler">Runde:</td>
		<td class="tableb">
		<?=isset($_SESSION["casino_dice"]["round"])?$_SESSION["casino_dice"]["round"]:1?>
		</td>
	</tr>
	<tr>
		<td class="tabler">Point:</td>
		<td class="tableb">
			<?
			if (isset($_SESSION["casino_dice"]["point"]) && $_SESSION["casino_dice"]["point"] > 0) {
				echo $_SESSION["casino_dice"]["point"];
			}
			else echo "---";
			?>
		</td>
	</tr>
	<tr>
		<td class="tabler">Einsatz:</td>
		<td class="tableb">
		<?
		if ($_SESSION["casino_dice"]["stake"]) {
		$stake = Casino::getStake($_SESSION["casino_dice"]["stake"]);
		echo $stake["name"];
		?>
		<input type="hidden" name="c_stake" value="<?=$_SESSION["casino_dice"]["stake"]?>">
		<?
		}
		else {
		?>
			<select name="c_stake">
				<?=$stake_options?>
			</select>
		<?
		}
		?>
		</td>
	</tr>
	<tr>
		<td class="tableb" colspan="2" style="text-align: center; padding: 5px">
			<input type="submit" name="c_dice" value="<?=($_SESSION["casino_dice"]["lost"]||$_SESSION["casino_dice"]["win"]) || $_SESSION["casino_dice"]["round"]<1?"los":"nochmal würfeln"?>"><br />
		</td>
	</tr>
	<tr>
		<td class="tablec" colspan="2" align="center">
			<small>( Gewinnchance 1:3 )</small>
		</td>
	</tr>
</table>
</form>

		</td>
	</tr>
</table>
<?php

// Aufräum arbeiten ;)

$_SESSION["casino_bet"] = array();

//}
//else echo "<h2 align=\"center\">Casino ist noch nicht freigegeben!</h2>";

//stdfoot();
?>
</body>
</html>
