Location: PHPKode > projects > Fretsweb > fretsweb-1.2/fretsweb/admin/joinrequests.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();
}

$sql = "SELECT `name` FROM `contest_players` WHERE `joinrequest`='1'";
$query = mysql_query($sql);
$names = array();
while($row = mysql_fetch_row($query))
{
	$names[count($names)] = $row[0];
}

if(isset($_POST['add']))
{
	$addnames = array();
	foreach($_POST as $postname => $postvalue)
	{
		if(strlen($postname) > 3)
		//So only the player checkboxes, the rest is 2 or 3 digits
		{
			$addnames[count($addnames)] = $postname;
		}
	}
	sort($addnames);
	if(count($addnames) > 0)
	//If a player is set
	{
		foreach(array('az', 'md', 'es', 'se') as $diffcode)
		{
			if($_POST[$diffcode] == 1)
				$diff[$diffcode] = 1;
			else
				$diff[$diffcode] = 0;
		}
		if(in_array(1 , $diff))
		//If a difficulty is set
		{
			foreach($addnames as $addname)
			{
				$sql = "UPDATE `contest_players` SET `joinrequest` = '0', `Amazing` = '{$diff['az']}', `Medium` = '{$diff['md']}', `Easy` = '{$diff['es']}', `Supaeasy` = '{$diff['se']}' WHERE `name` = '$addname'";
				mysql_query($sql);
				$thenames .= " $addname ";
			}
			$info = "Players added ($thenames)";
			cfeed("Players added", "Players have been added to Fretsweb by request. The playernames are $thenames.", 'playerchange');
		}
		else
			$info = "Select difficulties before pressing the button!";
	}
	else
		$info = "First select players before pressing the button!";
}

if(isset($_POST['del']))
{
	$delnames = array();
	foreach($_POST as $postname => $postvalue)
	{
		if(strlen($postname) > 3)
		//So only the player checkboxes, the rest is 2 or 3 digits
		{
			$delnames[count($delnames)] = $postname;
		}
	}
	sort($delnames);
	if(count($delnames) > 0)
	{
		foreach($delnames as $delname)
		{
			$sql = "DELETE FROM `contest_players` WHERE `name`='$delname'";
			mysql_query($sql);
			$thenames .= " $delname ";
		}
		$info = "Players deleted ($thenames)";
	}
	else
		$info = "First select players before pressing the button!";
}

?>
<html>
 <head>
  <title>Join requests</title>
  <link href="../css.php" rel="stylesheet" type="text/css" />
  <link href="../images/favicon.png" rel="icon">
 </head>
 <body>
<center>
<h2>Join requests</h2>
<?php
if(isset($info))
	echo "<p class=\"info\">".$info."</p>";
if($allowjoinrequests)
	echo "<p>Join requests are allowed.</p>";
else
	echo "<p>Join requests are not allowed.</p>";

$sql = "SELECT `name` FROM `contest_players` WHERE `joinrequest`='1'";
$query = mysql_query($sql);
$names = array();
while($row = mysql_fetch_row($query))
{
	$names[count($names)] = $row[0];
}
if(count($names) > 0)
{
	sort($names);
	echo "<h3>Open requests</h3>";
	echo "<form action=\"{$_SERVER['PHP_SELF']}\" method=\"post\">";
	echo "<table class=\"regular\">";
	$i = 1;
	foreach($names as $name)
		echo "<tr><td><input type=\"checkbox\" name=\"$name\" value=\"1\" /></td><td>$name</td></tr>";
	echo "</table>";
	//Name is "add" and "del" because the join request names can't be smaller than 4 digists (so the names can't be double)
	echo "
<p>
<input type=\"checkbox\" name=\"az\" value=\"1\" />Amazing /
<input type=\"checkbox\" name=\"md\" value=\"1\" />Medium /
<input type=\"checkbox\" name=\"es\" value=\"1\" />Easy /
<input type=\"checkbox\" name=\"se\" value=\"1\" />Supaeasy
</p>
<p>
<input type=\"submit\" name=\"add\" value=\"Accept (add players)\" />
<input type=\"submit\" name=\"del\" value=\"Decline (remove players)\" />
</p>";
	echo "</form>";
}
else
	echo "<p>No requests in database.</p>";



?>
<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