<?php
////////////////////////////////
ob_start();
session_start(); /// initialize session
include("./inc/pw.php");
check_logged();
include("./inc/dirscan.php");
include("./inc/array_xml.php");
include("./inc/jscript.php");
$finale= xml2ary(file_get_contents('../component/music/music.xml'));
$musicsize=count($finale['data']['_c']['song']);
if (isset($_POST['save']))
{
$numdamod= $_POST['number'];
//cambio i dati
$finale['data']['_c']['song'][$numdamod]['_c']['title']['_v']= $_POST['title'];
$finale['data']['_c']['song'][$numdamod]['_c']['link']['_v']= $_POST['link'];
$last= ary2xml($finale);
//write();
$fh = fopen("../component/music/music.xml", "w");
if($fh==false)
die("unable to create file");
fwrite($fh, $last);
fclose($fh);
echo ("<h1>Song Edited!<br/><br/><br/><a href='music.php'>Back to Song List</a></h1>");
} else if (isset($_POST['savenew']))
{
$newdata=$finale['data']['_c']['song'][0];
//cambio i dati
$newdata['_c']['title']['_v']= $_POST['title'];
$newdata['_c']['link']['_v']= $_POST['link'];
ins2ary($finale['data']['_c']['song'],$newdata,$musicsize+1);
$last= ary2xml($finale);
//write();
$fh = fopen("../component/music/music.xml", "w");
if($fh==false)
die("unable to create file");
fwrite($fh, $last);
fclose($fh);
echo ("<h1>Song inserted!<br/><br/><br/><a href='music.php'>Back to Song List</a></h1>");
}
else if ($_GET['deletemusic']=='delete')
{
$selected= $_GET['itemnumber'];
if ($selected==0){
// echo("number 0");
array_shift($finale['data']['_c']['song']);
$last= ary2xml($finale);
}else{
unset($finale['data']['_c']['song'][$selected]);
$last= ary2xml($finale);
}
//write();
$fh = fopen("../component/music/music.xml", "w");
if($fh==false)
die("unable to create file");
fwrite($fh, $last);
fclose($fh);
echo ("<h1>Song deleted!!<br/><br/><br/><a href='music.php'>Back to Song List</a></h1>");
//////////////////////EDIT MUSIC/////////////////////////////
} else if (isset($_POST['edit']))
{
$selected= $_POST['itemnumber'];
$filemp3=scan_directory_recursively('../component/music','mp3');
// print_r($filemp3);
$filenumber= sizeof($filemp3);
// print_r($filenumber);
/////edit
echo "<table width='700' border='0' cellspacing='0' cellpadding='2'>" ;
echo "<form action='music.php' method='post'>";
//
echo "<tr>";
echo "<td align='center'><br/><h1>EDIT SONG</h1><br/></td>";
echo "</tr>";
//
echo "<tr>";
echo "<td><p>Title:</p> </td><td><input name='title' type='text' value='".$finale['data']['_c']['song'][$selected]['_c']['title']['_v']."' size='50' maxlength='50' /> </td>";
echo "</tr>";
echo "<td><p>Song: </p></td><td><select name='link' id='link'>";
echo "<option value='".$finale['data']['_c']['song'][$selected]['_c']['link']['_v']."'>".$finale['data']['_c']['song'][$selected]['_c']['link']['_v']."</option>";
for ($i=0;$i<$filenumber;$i++){
if ($filemp3[$i]['kind']=="file"){
echo "<option value='".$filemp3[$i]['path']."'>".$filemp3[$i]['path']."</option>";
}
}
echo "</select></td>" ;
echo "</tr>";
echo "<tr>";
echo "<input name='number' type='hidden' value='".$selected."' />";
echo "<td colspan='2' align='center'><input name='save' type='submit' value='save' /><input name='cancel' type='submit' value='cancel' ></td>";
echo "</form>";
echo "</tr>";
echo "</table>";
/////fine edit
//////////////////////ADD NEW/////////////////////////////
} else if (isset($_POST['new']))
{
$selected= $_POST['itemnumber'];
$filemp3=scan_directory_recursively('../component/music','mp3');
// print_r($filemp3);
$filenumber= sizeof($filemp3);
// print_r($filenumber);
/////edit
echo "<table width='700' border='0' cellspacing='0' cellpadding='2'>" ;
echo "<form action='music.php' method='post'>";
//
echo "<tr>";
echo "<td align='center'><br/><h1>ADD A SONG</h1><br/></td>";
echo "</tr>";
//
echo "<tr>";
echo "<td><p>Title:</p> </td><td><input name='title' type='text' value='inser_title' size='50' maxlength='50' /> </td>";
echo "</tr>";
echo "<td><p>Song: </p></td><td><select name='link' id='link'>";
for ($i=0;$i<$filenumber;$i++){
if ($filemp3[$i]['kind']=="file"){
echo "<option value='".$filemp3[$i]['path']."'>".$filemp3[$i]['path']."</option>";
}
}
echo "</select></td>" ;
echo "</tr>";
echo "<tr>";
echo "<input name='number' type='hidden' value='".$selected."' />";
echo "<td colspan='2' align='center'><input name='savenew' type='submit' value='save' /><input name='cancel' type='submit' value='cancel' ></td>";
echo "</form>";
echo "</tr>";
echo "</table>";
/////fine new
//////////////////////MOVE UP/////////////////////////////
}else if (isset($_POST['up']))
{
$selected= $_POST['itemnumber'];
$temp = $finale['data']['_c']['song'][$selected-1];
$finale['data']['_c']['song'][$selected-1] = $finale['data']['_c']['song'][$selected];
$finale['data']['_c']['song'][$selected] = $temp;
$last= ary2xml($finale);
//write();
$fh = fopen("../component/music/music.xml", "w");
if($fh==false)
die("unable to create file");
fwrite($fh, $last);
fclose($fh);
//echo ("edit effettuata<a href='news.php'> torna all'elenco</a>");
header("Location:music.php");
//////////////////////MOVE DOWN/////////////////////////////
}
else if (isset($_POST['down']))
{
// echo("up".$_POST['itemnumber']);
$selected= $_POST['itemnumber'];
$temp = $finale['data']['_c']['song'][$selected+1];
$finale['data']['_c']['song'][$selected+1] = $finale['data']['_c']['song'][$selected];
$finale['data']['_c']['song'][$selected] = $temp;
$last= ary2xml($finale);
//write();
$fh = fopen("../component/music/music.xml", "w");
if($fh==false)
die("unable to create file");
fwrite($fh, $last);
fclose($fh);
//echo ("edit effettuata<a href='news.php'> torna all'elenco</a>");
header("Location:music.php");
}
else
{
echo "<table width='700' border='0' cellspacing='0' cellpadding='2'>" ;
echo "<tr><td colspan='2'><h1>MUSIC ADMIN PANEL</h1></td><td colspan='2' align='center'><form action='music.php' method='post'>";
echo "<br/><input name='new' type='submit' value='ADD A SONG' /><br/><br/>" ;
echo "</form></td>";
for($i=0;$i<$musicsize;$i++){
echo "<form action='music.php' method='post'>";
echo "<tr>" ;
echo "<td width='100'><p>".$finale['data']['_c']['song'][$i]['_c']['title']['_v']."</p><input name='itemnumber' type='hidden' value='".$i."' /></td>" ;
echo "<td width='100'><p>".$finale['data']['_c']['song'][$i]['_c']['link']['_v']."</p></td>" ;
echo "<td align='center'><input name='edit' type='submit' value='edit' />";
if($musicsize>2){
echo"<input name='delete' onClick=\"submitFormMusic(".$i.",'music','delete');\" type='button' value='delete' /></td>";
}
echo "<td align='center'>";
if ($i!=0){
echo "<input name='up' type='submit' value='move up' />" ;
}
if ($i!=$musicsize-1){
echo "<input name='down' type='submit' value='move down' />" ;
}
echo "</td>";
echo "</tr> " ;
echo "</form>";
}
echo "</table> " ;
}
?>