save current state
This commit is contained in:
parent
c2c1ee7b9b
commit
64d4eeb85d
9 changed files with 116 additions and 97 deletions
59
rank.php
59
rank.php
|
|
@ -1,19 +1,22 @@
|
|||
<?php
|
||||
//Create player statistics
|
||||
$query = mysql_query("SELECT * FROM `player`",DB);
|
||||
$user_min_bill=-1*user_min_bill();
|
||||
while ($data=mysql_fetch_array($query)) {
|
||||
$cnt_games = user_count_games($data['id']);
|
||||
$cnt_point_games = user_count_point_games($data['id']);
|
||||
$cnt_first = user_count_place($data['id'],"first");
|
||||
$cnt_second = user_count_place($data['id'],"second");
|
||||
$cnt_third = user_count_place($data['id'],"third");
|
||||
$points = 3*$cnt_first + 2*$cnt_second + $cnt_third;
|
||||
$rate = ($cnt_games) ? (1000 * $points)/ ($cnt_games):0;
|
||||
$bill = user_count_bill($data['id']);
|
||||
$missed_games = user_count_last_missed_games($data['id']);
|
||||
$rank = calculate_rank($rate,$bill+$user_min_bill,$missed_games);
|
||||
mysql_query("UPDATE `player` SET `rank` = '$rank', `cnt_games` = '$cnt_games', `cnt_first` = '$cnt_first', `cnt_second` = '$cnt_second', `cnt_third` = '$cnt_third', `points` = '$points', `rate` = '$rate', `bill` = '$bill' WHERE `id` =".$data['id']." LIMIT 1 ;",DB);
|
||||
|
||||
// Update player statistics (only when someone is logged in)
|
||||
if (LOGIN!="" && TO_DO == "update_rank") {
|
||||
$query = mysqli_query($db, "SELECT * FROM `player`");
|
||||
$user_min_bill=-1*user_min_bill();
|
||||
while ($data=mysqli_fetch_array($query)) {
|
||||
$cnt_games = user_count_games($data['id']);
|
||||
$cnt_point_games = user_count_point_games($data['id']);
|
||||
$cnt_first = user_count_place($data['id'],"first");
|
||||
$cnt_second = user_count_place($data['id'],"second");
|
||||
$cnt_third = user_count_place($data['id'],"third");
|
||||
$points = 3*$cnt_first + 2*$cnt_second + $cnt_third;
|
||||
$rate = ($cnt_games) ? (1000 * $points)/ ($cnt_games):0;
|
||||
$bill = user_count_bill($data['id']);
|
||||
$missed_games = user_count_last_missed_games($data['id']);
|
||||
$rank = calculate_rank($rate,$bill+$user_min_bill,$missed_games);
|
||||
mysqli_query($db, "UPDATE `player` SET `rank` = '$rank', `cnt_games` = '$cnt_games', `cnt_first` = '$cnt_first', `cnt_second` = '$cnt_second', `cnt_third` = '$cnt_third', `points` = '$points', `rate` = '$rate', `bill` = '$bill' WHERE `id` =".$data['id']." LIMIT 1 ;");
|
||||
}
|
||||
}
|
||||
|
||||
//Determine Sort Order
|
||||
|
|
@ -32,12 +35,12 @@ if (TO_DO=="insert_player" && LOGIN!="") {
|
|||
$failure="";
|
||||
if (!($alias=$_POST['alias'])) $failure.="Spitznamen angeben!<br>";
|
||||
if (!$failure) {
|
||||
$query=mysql_query("SELECT `alias` FROM `player` WHERE `alias` = '$alias' LIMIT 0 , 30",DB);
|
||||
$data=mysql_fetch_array($query);
|
||||
if ($data['alias']==$alias) $failure.="Spitzname existiert bereits!<br>";
|
||||
$query=mysqli_query($db, "SELECT `alias` FROM `player` WHERE `alias` = '$alias' LIMIT 0 , 30");
|
||||
$data=mysqli_fetch_array($query);
|
||||
if ($data!==NULL && $data!==False && $data['alias']==$alias) $failure.="Spitzname existiert bereits!<br>";
|
||||
}
|
||||
if (!$failure) {
|
||||
mysql_query("INSERT INTO `player` ( `alias` ) VALUES ( '$alias' );",DB);
|
||||
mysqli_query($db, "INSERT INTO `player` ( `alias`, `password`, `cnt_games`, `cnt_first`, `cnt_second`, `cnt_third`, `points`, `rate`, `bill`, `rank`) VALUES ( '$alias', '', '0', '0', '0', '0', '0', '0', '0', '0');");
|
||||
}
|
||||
else {
|
||||
$value_ip_alias = $alias;
|
||||
|
|
@ -49,12 +52,12 @@ if (TO_DO=="save_edit_player" && LOGIN!="" && ($player=$_GET['player'])) {
|
|||
$failure="";
|
||||
if (!($alias=$_POST['alias'])) $failure.="Spitznamen angeben!<br>";
|
||||
if (!$failure) {
|
||||
$query=mysql_query("SELECT `id`,`alias` FROM `player` WHERE `alias` = '$alias' LIMIT 0 , 30",DB);
|
||||
while ($data=mysql_fetch_array($query))
|
||||
$query=mysqli_query($db, "SELECT `id`,`alias` FROM `player` WHERE `alias` = '$alias' LIMIT 0 , 30");
|
||||
while ($data=mysqli_fetch_array($query))
|
||||
if ($data['id']!=$player) $failure.="Spitzname existiert bereits!<br>";
|
||||
}
|
||||
if (!$failure) {
|
||||
mysql_query("UPDATE `player` SET `alias` = '$alias' WHERE `id` = '$player' LIMIT 1 ;",DB);
|
||||
mysqli_query($db, "UPDATE `player` SET `alias` = '$alias' WHERE `id` = '$player' LIMIT 1 ;");
|
||||
}
|
||||
$ERROR.=$failure;
|
||||
}
|
||||
|
|
@ -62,6 +65,7 @@ if (TO_DO=="save_edit_player" && LOGIN!="" && ($player=$_GET['player'])) {
|
|||
$BODY.='
|
||||
<table class="list">
|
||||
<tr>
|
||||
<th>#</th>
|
||||
<th> </th>
|
||||
<th><a href="index.php?page=rank&sortby=alias&sortorder='.$SORTNOORD.'">'.(($SORTBY=="alias") ? add_icon($SORTORDER):"").'Spitzname</a></th>
|
||||
<th><a href="index.php?page=rank&sortby=cnt_games&sortorder='.$SORTNOORD.'">'.(($SORTBY=="cnt_games") ? add_icon($SORTORDER):"").'Spiele</a></th>
|
||||
|
|
@ -74,19 +78,20 @@ $BODY.='
|
|||
<th><a href="index.php?page=rank&sortby=rank&sortorder='.$SORTNOORD.'">'.(($SORTBY=="rank") ? add_icon($SORTORDER):"").'Rang</a></th>
|
||||
</tr>';
|
||||
|
||||
$query=mysql_query("SELECT * FROM `player` $SORTSTRING",DB);
|
||||
while ($data=mysql_fetch_array($query)) {
|
||||
$query=mysqli_query($db, "SELECT * FROM `player` $SORTSTRING");
|
||||
$position = 1;
|
||||
while ($data=mysqli_fetch_array($query)) {
|
||||
$id = $data['id'];
|
||||
$alias = $data['alias'];
|
||||
if (TO_DO=="edit_player" && LOGIN!="" && $_GET['player']==$alias) {
|
||||
$BODY.="<form action=\"index.php?page=rank&to_do=save_edit_player&player=$id\" method=\"post\">";
|
||||
$BODY.="<tr><td></td>";
|
||||
$BODY.="<tr><td></td><td></td>";
|
||||
$BODY.="<td><input type=\"text\" size=\"8\" name=\"alias\" value=\"$alias\"></td>\n";
|
||||
$BODY.="<td><input type=\"submit\" value=\"\" class=\"submit_save\"></td>\n";
|
||||
$BODY.="</form>";
|
||||
}
|
||||
else {
|
||||
$BODY.="<tr><td>";
|
||||
$BODY.="<tr><td>$position</td><td>";
|
||||
if (LOGIN!="")
|
||||
$BODY.="<a href=\"index.php?page=rank&to_do=edit_player&player=$alias\" target=\"_top\">".add_icon("pencil")."</a>";
|
||||
$BODY.="</td><td>$alias</td>";
|
||||
|
|
@ -101,6 +106,8 @@ while ($data=mysql_fetch_array($query)) {
|
|||
$BODY.="<td>".$data['rank']."</td>";
|
||||
$BODY.="</tr>\n";
|
||||
}
|
||||
|
||||
++$position;
|
||||
}
|
||||
|
||||
if (LOGIN!="") {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue