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

if(isset($_POST['add']))
{
	$addsongs = array();
	foreach($_POST as $postname => $postvalue)
	{
		if(strlen($postname) > 3)
		//So only the song checkboxes (hashes (40 digits)), the rest is 3 digits ('add' and 'del')
		{
			$addsongs[count($addsongs)] = $postname;
		}
	}
	if(count($addsongs) > 0)
	{
		sort($addsongs);
		$thesongs = '';
		foreach($addsongs as $addsong)
		{
			$sql = "UPDATE `contest_songs` SET `request` = '0' WHERE `hash` = '{$addsong}'";
			$query = mysql_query($sql);
			$thesongs .= " $addsong ";
			$sql = "SELECT `artist`, `title` FROM `contest_songs` WHERE `hash`='$addsong'";
			$query = mysql_query($sql);
			$song = mysql_fetch_assoc($query);
			cfeed("Added song", "The song: {$song['artist']} - {$song['title']} has been added to Fretsweb after it was requested.", 'songchange');
		}
		$info = "Added songs ($thesongs)";
	}
	else
		$info = "First select songs before pressing the button!";
}


if(isset($_POST['del']))
{
	$delnames = array();
	foreach($_POST as $postname => $postvalue)
	{
		if(strlen($postname) > 3)
		//So only the song checkboxes (hashes (40 digits)), the rest is 3 digits ('add' and 'del')
		{
			$delsongs[count($delsongs)] = $postname;
		}
	}
	if(count($delsongs) > 0)
	{
		sort($delsongs);
		$thesongs = '';
		foreach($delsongs as $delsong)
		{
			$sql = "DELETE FROM `contest_songs` WHERE `hash` = '$delsong'";
			$query = mysql_query($sql);
			$thesongs .= " $delsong ";
		}
		$info = "Deleted songs ($thesongs)";
	}
	else
		$info = "First select songs before pressing the button!";
}

?>
<html>
 <head>
  <title>Song requests</title>
  <link href="../css.php" rel="stylesheet" type="text/css" />
  <link href="../images/favicon.png" rel="icon">
 </head>
 <body>
<center>
<h2>Song requests</h2>
<?php

if(isset($info))
	echo "<p class=\"info\">$info</p>";

$sql = "SELECT `hash`, `artist`, `title` FROM `contest_songs` WHERE `request`='1'";
$query = mysql_query($sql) or
	die('Query failed.');
if(mysql_num_rows($query) > 0)
{
	echo "<form action=\"{$_SERVER['PHP_SELF']}\" method=\"post\"><table class=\"regular\"><tr><th/><th>Artist</th><th>Title</th></tr>";
	while($row = mysql_fetch_assoc($query))
	{
		echo "<tr>";
		echo "<td><input type=\"checkbox\" name=\"{$row['hash']}\" value=\"1\" /></td>";
		echo "<td>{$row['artist']}</td>";
		echo "<td>{$row['title']}</td>";
		echo "</tr>";
	}
	echo "</table>";
	echo "
<p>
<input type=\"submit\" name=\"add\" value=\"Add selected songs\" />
<input type=\"submit\" name=\"del\" value=\"Remove selected songs\" />
</p></form>
";
}
else
	echo "<p>No song requests at the moment.</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