<?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/>.
*/
// Include the common file
require_once 'admin/common.php';
// Send headers for content-type
header('Content-Type: text/html; charset=utf-8');
// Include language
require_once "lang/$language.php";
// If the join button has been clicked
if(isset($_POST['join_submit']))
{
// Check if the join name is long enough, needed for the admin's page
if(strlen($_POST['join_name']) > 3 )
{
if(strlen($_POST['join_name']) < 13 )
{
$sql = 'SELECT `name` FROM `contest_players`';
$query = mysql_query($sql);
$names = array();
while($row = mysql_fetch_row($query))
{
$names[count($names)] = $row[0];
}
// Check if this name already exists
if(!in_array($_POST['join_name'] , $names))
{
$sql = "INSERT INTO `contest_players` (`name` , `Supaeasy` , `Easy` , `Medium` , `Amazing` , `joinrequest`)
VALUES ('{$_POST['join_name']}', '0', '0', '0', '0', '1');";
mysql_query($sql);
setcookie('fretsweb_joined', $_POST['join_name'], 0 , '/');
$info = sprintf( $lang['join_request_succes'], $_POST['join_name'] );
$added = true;
}
else
{
$info = sprintf( $lang['join_name_exists'], $_POST['join_name'] );
}
}
else
{
$info = sprintf( $lang['join_name_shorter'], $_POST['join_name'] );
}
}
else
{
$info = sprintf( $lang['join_name_longer'], $_POST['join_name'] );
}
}
// Write header
print_header($lang['join']);
// Write $info if needed
if(isset($info))
{
echo "<p align=\"center\" class=\"info\">" . $info . "</p>";
}
// Write the form if the person has not requested a name yet
if(!$added)
{
// Check if joining is allowed
if($allowjoinrequests)
{
// Did person join already
if(!isset($_COOKIE['fretsweb_joined']))
{
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<p align="center"><?php echo $lang['name:']; ?> <input type="text" name="join_name"></p>
<p align="center"><input type="submit" name="join_submit" value="<?php echo $lang['send_request']; ?>"></p>
</form>
<?php
}
else
{
echo sprintf( "<p align=\"center\">{$lang['already_joined']}</p>" , $_COOKIE['fretsweb_joined'] );
}
}
else
{
echo "<p align=\"center\">{$lang['joining_disabled']}</p>";
}
}
// Write footer
echo "</div>";
include "admin/pagefooter.php";
echo "
</div>
</body>
</html>";
// Close database link
mysql_close( $db_link );
?>