<?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";
// Include log
require_once "admin/log.php";
// Add request
if( isset($_POST['asksubmit']) ) {
// Parse song.ini - search for artist and title
if( $_FILES['song_ini']['name'] == "song.ini" )
{
$inifilename = $_FILES['song_ini']['tmp_name'];
$lines = file( $inifilename ) or die( "Can't open file" );
foreach ($lines as $line_num => $line)
{
list( $key, $val ) = split( "=", $line );
if ( strcasecmp( trim($key), "artist" ) == 0 ){
$artist = trim($val);
}
if ( strcasecmp( trim($key), "name" ) == 0 ){
$title = trim($val);
}
}
// Check if the artist and title is all right
if( isset($artist) && isset($title) && strcmp($artist,"") && strcmp($title,"") )
{
// Get the hash (sha1) of notes.mid
if( $_FILES['notes_mid']['name'] == "notes.mid" )
{
// Open the file
$midfilename = $_FILES['notes_mid']['tmp_name'];
if(($fh = fopen( $midfilename, 'rb' )))
{
$data = fread( $fh, filesize( $midfilename ) );
fclose( $fh );
// Calculate hash
$hash = sha1( $data );
// Set download link
$link = $_POST['link'];
// Check if the song is already present in the database
$query = "SELECT * FROM `contest_songs` WHERE `hash` = '$hash'";
if( !($res = mysql_query($query)) )
$info = 'SERVER ERROR:<br/>Cannot check if song is already present.<br/>('.$hash.')<br/>Please report this message to the administator.';
if( mysql_num_rows( $res ) != 0 ){
$info = "Song already present in database.";
}
else
{
$query = "INSERT INTO `contest_songs` (`hash`, `artist`, `title`, `link`, `request`)
VALUES ('$hash','" . addslashes($artist) . "','" . addslashes($title) . "','" . addslashes($link) . "', '1')";
mysql_query( $query ) or die ( "Cannot insert data in database: ".mysql_error() );
clog("Add song request: $artist - $title ($hash)");
$info = "Song requested.";
}
}
else
{
$info = 'SERVER ERROR:<br/>Cannot open midi file<br/>('.$_FILES['notes_mid']['name'].' - '.$midfilename.')<br/>Please report this message to the administator.';
}
}
else
{
$info = "Artist or title not found in song.ini";
}
}
else
{
$info = sprintf($lang['asksong_file_differs'] , 'notes.mid');
}
}
else
{
$info = sprintf($lang['asksong_file_differs'] , 'song.ini');
}
}
// Write header
print_header($lang['request_song']);
// Write info if needed
if(isset($info))
{
echo '<p align="center" class="info">'.$info.'</p>';
}
?>
<!-- The request-song form -->
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data">
<p align="center">Notes.mid: <input type="file" name="notes_mid" size="50"></p>
<p align="center">Song.ini: <input type="file" name="song_ini" size="50"></p>
<?php echo "<p align=\"center\">" . sprintf( $lang['download_link_is'] , "<input type=\"text\" name=\"link\" size=\"50\">" ) . "</p>"; ?>
<p align="center"><input type="submit" name="asksubmit" value="Add Song"></p>
</form>
<?
// Write footer
echo "</div>";
include "admin/pagefooter.php";
echo "
</div>
</body>
</html>";
// Close the database link
mysql_close( $db_link );
?>