<?

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

if (get_user_class() <= UC_ADMINISTRATOR)
stderr("Sorry ".$CURUSER["username"], "The ADMINISTRATOR do not allow your class to edit the casino play");

$result = mysql_query("select * from casino where userid = '".$userid."'") or die(mysql_error());
if (mysql_num_rows($result) == 0)
stderr("Sorry","No players with the userid $userid</b></p>\n");
else
{
$row = mysql_fetch_array($result);
$user_win = $row["win"];
$user_lost = $row["lost"];
$user_trys = $row["trys"];
$user_date = $row["date"];
$user_enableplay = $row["enableplay"];
stdhead();

if($_POST["userid"]!=NULL&&$_POST["won"]!=NULL&&$_POST["lost"]!=NULL&&$_POST["trys"]!=NULL&&$_POST["date"]!=NULL&&$_POST["enableplay"]!=NULL)
{
$dif_win = $won - $user_win; ///// this is tricky
$dif_lost = $lost - $user_lost; ///// this is tricky
$up = $dif_win - $dif_lost; ///// this is tricky
mysql_query("UPDATE users SET uploaded = uploaded + ".$up." WHERE id=".$userid) or sqlerr();
mysql_query("UPDATE casino SET date = '".$date."', trys = ".$trys." ,lost = ".$lost.",win = ".$won.",enableplay= '".$enableplay."' WHERE userid=".$userid) or sqlerr();

stdmsg("Stats for user ".$userid." are now updated" ,"sorry but no problems occured :-)");

}
else
{
if ($user_win > 0)
$casino_ratio_user = number_format($user_lost / $user_win, 2);
else
if ($user_lost > 0)
$casino_ratio_user = 999;
else
$casino_ratio_user = 0;

if($user_enableplay=="yes")
{
$select="<option value=yes checked >yes</option>";
$select.="<option value=no>no</option>";
}
else
{
$select="<option value=yes >yes</option>";
$select.="<option value=no checked>no</option>";
}


print("<h1>Welcome, you are now able to edit user nr. <a href=userdetails.php?id=$userid>$userid</a>!</h1>\n");
print("<p align=center><a href=casino.php>Back</a></p>\n");
print("<form name=edit-player method=post action=$phpself><input type=hidden name=userid value=$userid>");
print("<table cellspacing=0 cellpadding=3 width=400>\n");
tr("user ratio:",$casino_ratio_user,1);
tr("user won:","<input type=text name=won value='$user_win' >&nbsp;&nbsp;".mksize($user_win),1);
tr("user lost:","<input type=text name=lost value='$user_lost' >&nbsp;&nbsp;".mksize($user_lost),1);
tr("user play ","<input type=text name=trys value='$user_trys' >&nbsp;&nbsp;<b>games</b>",1);
tr("last access:","<input type=text name=date value='$user_date' >",1);
tr("allow user to play:",'<select name="enableplay">'.$select.'</select> ',1);
print("<tr><td colspan=2 align=center><input type=submit value='change user stats'></td></tr>");
print("</table>\n");
print("</form>");
}
}
stdfoot();
?>