Location: PHPKode > projects > Fretsweb > fretsweb-1.2/fretsweb/song.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/>.
*/


// Include the common file
require_once "admin/common.php";

// Send headers for content-type
header('Content-Type: text/html; charset=utf-8');

// Include the language
require_once "lang/$language.php";


function is_valid($mixed)
/*
bool is_valid(mixed $mixed)
	checks if $mixed is valid information
*/
{
	if(is_numeric($mixed))
	{
		if($mixed > 0)
		{
			return True;
		}
		else
		{
			return False;
		}
	}
	else
	{
		if($mixed == 'None')
		{
			return False;
		}
		elseif(strlen($mixed) > 0)
		{
			return True;
		}
		else
		{
			return False;
		}
	}
}


// Control if $_GET['hash'] is set
// The page can't work without hash
if(!isset($_GET['hash']))
{
	header('location: songs.php');
	die();
}
elseif(mysql_num_rows(mysql_query("SELECT * FROM `contest_songs` WHERE `hash`='{$_GET['hash']}'")) == 0)
{
	header('location: songs.php');
	die();
}


//G et information from the database
$sql = "SELECT `hash`,`artist`,`title`,`link` FROM `contest_songs` WHERE `hash`='{$_GET['hash']}'";
$query = mysql_query($sql);
$song = mysql_fetch_assoc($query);


// Write header
print_header($lang["song"], stripslashes($song['artist'] . ' - ' . $song['title']));


// Write download link
// Download link must be longer than 3 otherwise it's no real download link
if(strlen($song['link']) >= 4)
{
	// Check if it's a link for it must be treated with <a>
	if(substr($song['link'], 0, 4) == 'http' || substr($song['link'], 0, 4) == 'ftp:' || substr($song['link'], 0, 8) == 'songdir/')
	{
		echo sprintf("<h5>{$lang["download_link_is"]}</h5>" , "<a href=\"{$song['link']}\">{$song['link']}</a>");
	}
	else
	{
		echo addslashes("<h5>{$song['link']}</h5>");
	}
}
else
{
	echo "<h5>{$lang["no_download_link"]}</h5>";
}


// Show scores
$sql = "SELECT `hash`, `difficulty`, `name`, `score`, `stars`, `notes_hit`, `notes_all`, `note_streak`, `original_score` FROM `contest_scores` WHERE `hash`='{$song['hash']}' ORDER BY `score` DESC";
$query = mysql_query($sql);
if(mysql_num_rows($query) > 0)
{
	echo "<h2>{$lang['scores']}</h2>";
}
while($row = mysql_fetch_assoc($query))
{
	$scores[$row['difficulty']][$row['name']] = $row;
}
foreach(array("Amazing","Medium","Easy","Supaeasy") as $difficulty)
{
	if(isset($scores[$difficulty]))
	{
		echo "<h3>$difficulty</h3>";
		echo "<table class=\"regular\"><tr><td>";
		// Make a small table
		echo "<table>";
		$counter = 1;
		foreach($scores[$difficulty] as $name => $score)
		{
			echo "<tr>";
			// Change (1,2,3) into medals
			// Write rank
			if($counter == 1)
			{
				echo "<th class=\"amiddle\"><img src=\"images/gold-small.png\" alt=\"G\"></th>";
			}
			elseif($counter == 2)
			{
				echo "<th class=\"amiddle\"><img src=\"images/silver-small.png\" alt=\"S\"></th>";
			}
			elseif($counter == 3)
			{
				echo "<th class=\"amiddle\"><img src=\"images/bronze-small.png\" alt=\"B\"></th>";
			}
			else
			{
				echo "<th class=\"amiddle\">$counter</th>";
			}
			
			
			// Score
			echo "<td class=\"amiddle\">" . $score['score'] . "</td>";
			// Percent and streak
			if(is_valid($score['notes_hit']) && is_valid($score['notes_all']))
			{
				$percent = round(100 / $score['notes_all'] * $score['notes_hit'], 1);
			}
			else
			{
				$percent = False;
			}
			if(is_valid($score['note_streak']))
			{
				$note_streak = $score['note_streak'];
			}
			else
			{
				$note_streak = False;
			}
			if($percent && $note_streak)
			{
				echo "<td class=\"amiddle\">$percent% ($note_streak)</td>";
			}
			else
			{
				echo "<td>";
			}
			// Stars
			if(is_valid($score['stars']))
			{
				if($score['stars'] == 6)
				{
					$stars = "<img src=\"images/star3-small.png\"><img src=\"images/star3-small.png\"><img src=\"images/star3-small.png\"><img src=\"images/star3-small.png\"><img src=\"images/star3-small.png\">";
				}
				else
				{
					$i = 1;
					$stars = "";
					while($i <= 5)
					{
						if($score['stars'] >= $i)
						{
							$stars .= "<img src=\"images/star2-small.png\">";
						}
						else
						{
							$stars .= "<img src=\"images/star1-small.png\">";
						}
						$i++;
					}
				}
				echo "<td class=\"amiddle\">$stars</td>";
			}
			else
			{
				echo "<td>";
			}
			// Player name
			echo "<td class=\"amiddle\"><a href=\"player.php?name=$name\">$name</a></td>";
			
			echo "</tr>\n";
			$counter++;
		}
		echo "</table>";
		echo "</td></tr></table>";
	}
}


// Write footer
echo "</div>";
include "admin/pagefooter.php";
echo "
  </div>
 </body>
</html>";


// Close database link
mysql_close( $db_link );

?>
Return current item: Fretsweb