<?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 "common.php";
// Include log
include_once "log.php";
//Login Test
session_start();
if($_SESSION['in'] < 2)
{
header('location: login.php?need=admin');
die();
}
// Do if install is set
if(isset($_GET['install']))
{
if($sql = @fread(@fopen('../songdir/'.$_GET['install'].'/pack.sql', 'r'), @filesize('../songdir/'.$_GET['install'].'/pack.sql')))
{
foreach(explode(';', $sql) as $newsql)
{
mysql_query($newsql);
}
$info = "Succesful.";
clog('Added song pack: '.$_GET['install']);
cfeed('New song pack', 'A new song pack is installed on Fretsweb: ' . $_GET['install'] . "\n".'You can play all of the songs in that song pack now.', 'configchange');
}
else
{
$info = "Failed: ".mysql_error();
clog('Failed to add song pack: '.$_GET['install']);
}
$php_self = explode('?', $_SERVER['PHP_SELF']);
header('location: '.$php_self[0].'?info='.$info);
}
// Do if install is set
if(isset($_GET['delete']))
{
if($sql = @fread(@fopen('../songdir/'.$_GET['delete'].'/del.sql', 'r'), @filesize('../songdir/'.$_GET['delete'].'/del.sql')))
{
foreach(explode(';', $sql) as $newsql)
{
mysql_query($newsql);
}
$info = "Succesful.";
clog('Deleted all songs from song pack: '.$_GET['install']);
cfeed('Deleted songpack', 'A song pack is removed from Fretsweb: ' . $_GET['install'] . "\n".'You cannot play the songs from that song pack anymore.', 'configchange');
}
else
{
$info = "Failed: ".mysql_error();
clog('Failed to locate songpack: '.$_GET['delete']);
}
$php_self = explode('?', $_SERVER['PHP_SELF']);
header('location: '.$php_self[0].'?info='.$info);
}
?>
<html>
<head>
<title>Add songpack</title>
<link href="../css.php" rel="stylesheet" type="text/css" />
<link href="../images/favicon.png" rel="icon">
<script type="text/javascript" language="javascript">
function installsure(loc)
// This function is to make someone confirm an unchangable movement
{
var yea = confirm('Are you sure you want to install this songpack?');
if(yea)
{
window.location.href = loc
}
}
function deletesure(loc)
// This function is to make someone confirm an unchangable movement
{
var yea = confirm('Are you sure you want to delete this songpack?');
if(yea)
{
window.location.href = loc
}
}
</script>
</head>
<body><center>
<h2>Add songpack</h2>
<?php
// Write $info if needed
if(isset($_GET['info']))
{
echo '<p class="info">'.$_GET['info'].'</p>';
}
?>
<p>With this application you add several songs at once, these are songpacks.</p>
<?php
// Scan songdir for songpacks and write them
$dirs = scandir('../songdir');
foreach($dirs as $dirv)
{
if(file_exists('../songdir/'.$dirv.'/pack.sql'))
{
$dirs2[count($dirs2)] = $dirv;
}
}
if(count($dirs2) > 0)
{
echo '<ul>';
foreach($dirs2 as $pack)
{
echo "<li>$pack ";
echo "<a onclick=\"javascript:installsure('{$_SERVER['PHP_SELF']}?install=$pack')\">Install</a> / ";
echo "<a onclick=\"javascript:deletesure('{$_SERVER['PHP_SELF']}?delete=$pack')\">Remove</a></li>";
}
echo '</ul>';
}
// Close database link
mysql_close( $db_link );
?>
<p><b><a href="index.php">Back to main administration panel</a></b><p>
</center></body>
</html>