<?

require "include/bittorrent.php";
dbconn();
loggedinorreturn();

if (get_user_class() < UC_SYSOP)
stdmsg("Sorry", "Access denied.");

stdhead("Lotterie");

begin_main_frame();

if ($_POST['lottery'] == 'config')
{

$res = mysql_query("SELECT * FROM lottery_config") or sqlerr(__FILE__, __LINE__);
while ($arr = mysql_fetch_assoc($res))
{
$name = $arr['name'];

if ($name != 'class_allowed')
$new_data = $_POST[$name];
else
$new_data = implode("|", $_POST['class_allowed']);

if (($name != 'lottery_winners') && ($name != 'lottery_winners_amount') && ($name != 'lottery_winners_time'))
mysql_query("UPDATE lottery_config SET value = '$new_data' WHERE name = '$name'") or sqlerr(__FILE__, __LINE__);
}
stdmsg("Einstellungen geändert", "Die Einstellungen wurden geändert und übernommen.<br /><br /><a href=index.php>Zurück</a>");
}

?>
<form action="lottery_config.php" method=post>

<?

print("<table width=\"100%\">\n");

$res = mysql_query("SELECT * FROM lottery_config") or sqlerr(__FILE__, __LINE__);
while ($arr = mysql_fetch_assoc($res))
$arr_config[$arr['name']] = $arr['value'];

if (!$arr_config["enable"])
begin_frame("Lotterie Konfiguration:", true);

if ($arr_config["enable"])
{
begin_frame("Lotterie gestartet", true);
print("Die Lotterie ist zurzeit gestartet, deswegen ist die konfigurationsseite geschlossen.<br /><br />Es Spielen diesmal folgende Userklassen: ");
$class = explode("|", $arr_config['class_allowed']);
$classes_playing = '';
for ($x = 0; $x < count($class); $x++)
{
$classes_playing = (!$classes_playing) ? get_user_class_name($class[$x]) : ', ' . get_user_class_name($class[$x]);
print($classes_playing);
}
die;
}

if ($arr_config["ticket_amount_type"] != 'GB')
$selected2 = ' selected';
else
$selected = ' selected';

$use_prize_fund_yes = ($arr_config['use_prize_fund']) ? 'checked="checked"' : '';
$use_prize_fund_no = (!$arr_config['use_prize_fund']) ? 'checked="checked"' : '';

$enable_yes = ($arr_config['enable'] == 1) ? 'checked="checked"' : '';
$enable_no = ($arr_config['enable'] == 0) ? 'checked="checked"' : '';

print("<tr><td width=50% class=\"tableb\" align=left>Starte die Lotterie</td><td class=\"tableb\" align=left>Ja <input class=\"tableb\" type=radio name=enable value=\"1\" $enable_yes /> Nein <input class=\"tableb\" type=radio name=enable value=\"0\" $enable_no /></td></tr>");
print("<tr><td width=50% class=\"tableb\" align=left>Nur um den Pot spielen den wir stellen (Die Einsätze von den Usern werden nicht dazugezählt)</td><td class=\"tableb\" align=left>Ja <input class=\"tableb\" type=radio name=use_prize_fund value=\"1\" $use_prize_fund_yes /> Nein <input class=\"tableb\" type=radio name=use_prize_fund value=\"0\" $use_prize_fund_no /></td></tr>");
print("<tr><td width=50% class=\"tableb\" align=left>Gewinn in MB</td><td class=\"tableb\" align=left><input type=text name=prize_fund value=\"$arr_config[prize_fund]\" /></td></tr>");
print("<tr><td width=50% class=\"tableb\" align=left>Ticket kosten</td><td class=\"tableb\" align=left><input type=text name=ticket_amount value=\"$arr_config[ticket_amount]\" /></td></tr>");
print("<tr><td width=50% class=\"tableb\" align=left>Ticket kosten in</td><td class=\"tableb\" align=left><select name=ticket_amount_type><option value=\"GB\"$selected>GB</option><option value=\"MB\"$selected2>MB</option></select></td></tr>");
print("<tr><td width=50% class=\"tableb\" align=left>Wieviele Tickets darf jeder User kaufen</td><td class=\"tableb\" align=left><input type=text name=user_tickets value=\"$arr_config[user_tickets]\" /></td></tr>");
print("<tr><td width=50% class=\"tableb\" align=left>Userklassen die spielen dürfen</td><td class=\"tableb\" align=left><ul class=\"checklist\">");

$maxclass = UC_SYSOP + 1;
for ($i = 0; $i < $maxclass; $i++)
{
$class_allowed = array_map('trim', @explode('|', $arr_config["class_allowed"]));
if (in_array($i, $class_allowed))
{
if ($c = get_user_class_name($i))
print("<li><label for=\"$i\"><input id=\"$i\" name=\"class_allowed[]\" type=\"checkbox\" checked=\"checked\" value=\"$i\" />$c</label></li>\n");
}
else
{
if ($c = get_user_class_name($i))
print("<li><label for=\"$i\"><input id=\"$i\" name=\"class_allowed[]\" type=\"checkbox\" value=\"$i\" />$c</label></li>\n");
}
}

print("</ul></td><tr><td width=50% class=\"tableb\" align=left>Wieviele Gewinner soll es geben</td><td class=\"tableb\" align=left><input type=text name=total_winners value=\"$arr_config[total_winners]\" /></td></tr>");
print("<tr><td width=50% class=\"tableb\" align=left>Jetzige(r) Tag/Zeit</td><td class=\"tableb\" align=left>" . get_date_time() . "</td></tr>");
print("<tr><td width=50% class=\"tableb\" align=left>Anfangs Tag</td><td class=\"tableb\" align=left><input type=text name=start_date value=\"$arr_config[start_date]\" /></td></tr>");
print("<tr><td width=50% class=\"tableb\" align=left>End Tag</td><td class=\"tableb\" align=left><input type=text name=end_date value=\"$arr_config[end_date]\" /></td></tr>");
if (get_user_class() >= UC_MODERATOR)
{
?>
<tr>
<td class="tableb" colspan="4" align="center">
<input type="hidden" name="lottery" value="config"><input type="submit" name="submit" value="Änderungen Übernehmen">
</td>
</tr>
</table></form>
<?
}

end_frame();
end_main_frame();
stdfoot();
die;

?>