Location: PHPKode > projects > Fretsweb > fretsweb-1.2/fretsweb/admin/delplayer.php
<?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>Delete players</title>
<link href="../css.php" rel="stylesheet" type="text/css" />
<link href="../images/favicon.png" rel="icon">
</head>
<body><center>
<h2>Remove players</h2>
<!-- code to handle the submissions - del the player! -->
<?php
include_once "log.php";

if (!function_exists("htmlspecialchars_decode")) {
    function htmlspecialchars_decode($string, $quote_style = ENT_COMPAT) {
        return strtr($string, array_flip(get_html_translation_table(HTML_SPECIALCHARS, $quote_style)));
    }
}

// called after a form submission?
if( array_key_exists('_submit_check', $_POST) ) {
	while ( $player = current( $_POST ) ) {   
		if ( strpos ( key($_POST), "player" ) !== false ){
			if( get_magic_quotes_gpc() ) { $player = stripslashes($player); }
			$player = htmlspecialchars_decode($player);
			$res1 = mysql_query( "DELETE FROM `contest_players` WHERE `name` = '" . addslashes($player) . "'" );
			$res2 = mysql_query( "DELETE FROM `contest_scores`  WHERE `name` = '" . addslashes($player) . "'" );
			if( ! ($res1 && $res2) )
				echo "<p class=\"info\">Cannot delete player " . htmlspecialchars($player) . "</p>";
			else{
				echo "<p class=\"info\">Deleted player " . htmlspecialchars($player) . ".</p>";
				clog("Del player: $player");
				cfeed("Player $player deleted", "Player $player is deleted from Fretsweb, $player is not allowed to play anymore.", 'playerchange');
			}
		}
		next( $_POST );
	}
	echo "";
}
?>

<!-- The del-player form -->
<form name="delplayerform" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
	<?php
		$query = "SELECT * FROM `contest_players` WHERE `joinrequest`='0' ORDER BY name";
		$players = mysql_query( $query ) or die( "Cannot find players in database" );
		$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><input type=\"checkbox\" name=\"player" . $i . "\" value=\"" . htmlspecialchars(mysql_result($players, $i, "name")) . "\"></td>";
			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=\"editplayer.php?name=" . mysql_result($players, $i, "name" ) . "\"><img src=\"../images/pencil_go.png\"></a></td>";
			echo "</tr>";
		}
		echo '</table>';
	?>
	<p><input type="hidden" name="_submit_check" value="1"/> 
	<input type="submit" value="Delete players"></p>
</form>
<p><b><a href="index.php">Back to main administration panel</a></b><p>
</center></body>
</html>

<?php
	// close DB
	mysql_close( $db_link );
?>

Return current item: Fretsweb