<?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();
}
//If a player is edditted
if(isset($_POST['edit']))
{
$name = addslashes($_POST['name']);
foreach(array('amazing','medium','easy','supaeasy') as $diff)
{
if($_POST[$diff] == 1)
$diffi[$diff] = 1;
else
$diffi[$diff] = 0;
}
$sql = "UPDATE `contest_players` SET `Amazing` = '{$diffi['amazing']}', `Medium` = '{$diffi['medium']}', `Easy` = '{$diffi['easy']}', `Supaeasy` = '{$diffi['supaeasy']}' WHERE `name` = '$name'";
mysql_query($sql);
$info = "Editted $name";
}
?><html>
<head>
<title>Edit player</title>
<link href="../css.php" rel="stylesheet" type="text/css" />
<link href="../images/favicon.png" rel="icon">
</head>
<body><center>
<h2>Edit player</h2>
<?php
include_once "log.php";
if(isset($info))
echo '<p class="info">' . $info . '</p>';
if(isset($_GET['name']))
{
//Show the editing form
$sql = "SELECT `name`, `Amazing`, `Medium`, `Easy`, `Supaeasy` FROM `contest_players` WHERE `name` = '{$_GET['name']}'";
$query = mysql_query($sql);
$player = mysql_fetch_assoc($query);
foreach(array('Amazing','Medium','Easy','Supaeasy') as $diff)
{
if($player[$diff] == 1)
$checked[$diff] = " checked";
else
$checked[$diff] = '';
}
echo "<form action=\"{$_SERVER['PHP_SELF']}\" method=\"post\">".
"<p>Name: <b>{$player['name']}</b></p>".
"<p>Amazing: <input type=\"checkbox\" name=\"amazing\" value=\"1\"{$checked['Amazing']}> / ".
"Medium: <input type=\"checkbox\" name=\"medium\" value=\"1\"{$checked['Medium']}> / ".
"Easy: <input type=\"checkbox\" name=\"easy\" value=\"1\"{$checked['Easy']}> / ".
"Supaeasy: <input type=\"checkbox\" name=\"supaeasy\" value=\"1\"{$checked['Supaeasy']}></p>".
"<input type=\"hidden\" name=\"name\" value=\"{$player['name']}\">".
"<p><input type=\"submit\" name=\"edit\" value=\"Edit player\" /></p>".
"</form>";
}
else
{
//Show the songs 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 "<th>" . htmlspecialchars(mysql_result($players, $i, "name")) . "</th>";
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=\"{$_SERVER['PHP_THIS']}?name=" . mysql_result($players, $i, "name" ) . "\"><img src=\"../images/pencil_go.png\"></a></td>";
echo "</tr>";
}
echo "</table>";
}
?>
<p><b><a href="index.php">Back to main administration panel</a></b><p>
</center></body>
<?php
// close DB
mysql_close( $db_link );
?>