<?php
/*
Fretsweb - A Frets on Fire chart server
Copyright (C) 2009, Daan Sprenkels
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
require_once "common.php";
//Login Test
session_start();
if($_SESSION['in'] < 1)
{
header('location: login.php?need=moderator');
die();
}
?>
<html>
<head>
<title>Add players</title>
<link href="../css.php" rel="stylesheet" type="text/css" />
<link href="../images/favicon.png" rel="icon">
</head>
<body>
<center>
<h2>Add players</h2>
<!-- code to handle the submissions - add the player! -->
<?php
include_once "log.php";
// called after a form submission?
if( array_key_exists('_submit_check', $_POST) )
{
$playername = get_magic_quotes_gpc() ? stripslashes($_POST['playername']) : $_POST['playername'];
$playername = trim($playername);
if( isset($playername) && strcmp($playername,"") )
{
$ds = isset($_POST['diffsupa']) ? 1 : 0;
$de = isset($_POST['diffeasy']) ? 1 : 0;
$dm = isset($_POST['diffmed']) ? 1 : 0;
$da = isset($_POST['diffamz']) ? 1 : 0;
if($ds || $de || $dm || $da)
{
$query = "SELECT * FROM contest_players WHERE name = '" . addslashes($playername) . "'";
( $res = mysql_query( $query ) ) or die( "Cannot check if player already present" );
if( mysql_num_rows( $res ) != 0 ){
$info = "Player already present in database.";
}
else
{
$query = "INSERT INTO contest_players (name,Supaeasy,Easy,Medium,Amazing)
VALUES ('". addslashes($playername) . "','$ds','$de','$dm','$da')";
mysql_query( $query ) or die ( "Cannot insert data in database" );
$allowedtoplayon = '';
if($da == 1)
$allowedtoplayon .= 'Amazing, ';
if($dm == 1)
$allowedtoplayon .= 'Medium, ';
if($de == 1)
$allowedtoplayon .= 'Easy, ';
if($ds == 1)
$allowedtoplayon .= 'Supaeasy, ';
// Delete the last ', '
$allowedtoplayon .= substr($allowedtoplayon, 0, -2);
cfeed("Added player $playername", "$playername is added to Fretsweb.\n$playername is allowed to play on $allowedtoplayon.", 'playerchange');
clog("Add player: $playername ($ds $de $dm $da)");
}
}
else
{
$info = "No difficulty selected!";
}
}
else
{
$info = "Invalid player name.";
}
}
// Write $info if needed
if(isset($info))
{
echo "<p class=\"info\" align=\"center\">$info</p>";
}
// Show the players currently in the database
$players = mysql_query( "SELECT * FROM `contest_players` WHERE `joinrequest`='0' ORDER BY `name`" );
$playersnum = mysql_numrows( $players );
echo "<p>$playersnum players currently in database:</p>";
echo "<table class=\"regular\">";
for( $i = 0; $i < $playersnum; $i++ ) {
echo "<tr>";
echo "<td>" . htmlspecialchars(mysql_result($players, $i, "name")) . "</td>";
if(mysql_result($players, $i, "Amazing") == 1)
echo "<td>Amazing</td>";
else
echo "<td/>";
if(mysql_result($players, $i, "Medium") == 1)
echo "<td>Medium</td>";
else
echo "<td/>";
if(mysql_result($players, $i, "Easy") == 1)
echo "<td>Easy</td>";
else
echo "<td/>";
if(mysql_result($players, $i, "Supaeasy") == 1)
echo "<td>Supaeasy</td>";
else
echo "<td/>";
echo "<td><a href=\"../player.php?name=" . mysql_result($players, $i, "name" ) . "\"><img src=\"../images/information.png\"></a>
<a href=\"editplayer.php?name=" . mysql_result($players, $i, "name" ) . "\"><img src=\"../images/pencil_go.png\"></a></td>";
echo "</tr>";
}
echo "</table>";
?>
<!-- The add-player form -->
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<p>Player name: <input type="text" name="playername" size="50" /></p><p>
<input type="checkbox" name="diffsupa" value="1" />Supaeasy /
<input type="checkbox" name="diffeasy" value="1" />Easy /
<input type="checkbox" name="diffmed" value="1" />Medium /
<input type="checkbox" name="diffamz" value="1" />Amazing
</p>
<p>
<input type="hidden" name="_submit_check" value="1"/>
<input type="submit" value="Add Player"></p>
</form>
<p><b><a href="index.php">Back to main administration panel</a></b><p>
</center>
</body>
</html>
<?php
// Close database link
mysql_close( $db_link );
?>