$name\n";
echo "
\n";
reset( $array );
while( list($k,$v) = each( $array ) )
{
echo "$k = $v\n";
}
echo "
\n";
}
function printheader()
{
echo "\n";
echo "\n";
echo "IceS2 Web\n";
echo "\n";
?>\n";
echo "\n";
echo "\n";
}
function printfooter( $footerlinks )
{
if( $footerlinks != 0 )
{
echo "\n";
}
echo "\n";
echo "\n";
}
function mainmenu()
{
echo "Main Menu
\n";
echo "\n";
echo "- Show playlist
\n";
echo "- Recently played
\n";
echo "- Browse files
\n";
echo "\n";
// echo "
\n";
}
function create_song_info( $row )
{
$i = 0;
$n = 0;
$str = "";
$pfx = "";
while( $i < 8 )
{
switch( $i )
{
case 0:
$colname = "iof_title";
$text = "Title";
$format = 0;
break;
case 1:
$colname = "iof_artist";
$text = "Artist";
$format = 0;
break;
case 2:
$colname = "iof_album";
$text = "Album";
$format = 0;
break;
case 3:
$colname = "iof_track_nr";
$text = "Track";
$format = 0;
break;
case 4:
$colname = "iof_genre";
$text = "Genre";
$format = 0;
break;
case 5:
$colname = "iof_length";
$text = "Length";
$format = 1;
break;
case 6:
$colname = "iof_bitrate";
$text = "Bitrate";
$format = 2;
break;
case 7:
$colname = "iof_filesize";
$text = "Filesize";
$format = 3;
break;
default:
$varname = "";
break;
}
if( isset( $row[$colname] ) )
{
$n++;
$var = $row[$colname];
switch( $format )
{
case 1:
$var = sprintf( "%d:%02d", $var / 60, $var % 60 );
break;
case 2:
$var .= "kbps";
break;
case 3:
$digits = strlen($var);
if( $digits > 12 )
{
$u = "TB";
$s = $digits - 12;
}
else if( $digits > 9 )
{
$u = "GB";
$s = $digits - 9;
}
else if( $digits > 6 )
{
$u = "MB";
$s = $digits - 6;
}
else if( $digits > 3 )
{
$u = "kB";
$s = $digits - 3;
}
else
{
$var .= "B";
break;
}
$v1 = substr( $var, 0, $s );
if( $s < 3 )
{
$v2 = "." . substr( $var, $s, 3-$s );
}
else
{
$v2 = "";
}
$var = $v1 . $v2 . $u;
break;
}
$str .= $pfx . $text . ": " . htmlentities($var);
$pfx = "
";
}
$i++;
}
if( $n == 0 )
{
$str = "no info available";
}
return $str;
}
function playlist( $conn )
{
$datefmt = $GLOBALS["datefmt"];
echo "\n";
$sql = "select " .
"to_char( ipl_date_ins, $datefmt ) as ipl_date_ins, " .
"ipl_seq_nr, " .
"ipl_directory, " .
"ipl_name, " .
"extract( epoch from ipl_date_start ) as ipl_date_start, " .
"iof_title, iof_artist, iof_album, iof_track_nr, " .
"iof_genre, iof_length, iof_bitrate, iof_filesize " .
"from " .
"ices2_playlist, ices2_oggfiles " .
"where " .
"ipl_date_end is null and " .
"ipl_directory = iof_directory and " .
"ipl_name = iof_name " .
"order by " .
"ipl_date_ins, " .
"ipl_seq_nr";
// echo "$sql
\n";
$rs = pg_exec( $conn, $sql );
if( $rs )
{
echo "\n";
echo "\n";
echo "Name | \n";
echo "Playing | \n";
echo "Skip/Delete | \n";
echo "
\n";
$i = 0;
$n = 0;
$time = time();
$tottime = 0;
while( $row = pg_fetch_array( $rs ) )
{
$date = $row["ipl_date_ins"];
$seqnr = $row["ipl_seq_nr"];
$name = $row["ipl_name"];
$start = $row["ipl_date_start"];
$info = create_song_info( $row );
$length = $row["iof_length"];
if( $length == "" )
{
$length = 180;
}
if( $start == "" )
{
if( ($i % 2) )
{
echo "\n";
}
else
{
echo "
\n";
}
echo "$name" .
" ";
echo $info;
echo "
| \n";
echo "" .
strftime( $GLOBALS["strftimefmt"], $time ) . " | \n";
echo "delete | \n";
$i++;
}
else
{
$time = $start;
$tottime = $start - time();
echo "
\n";
echo "$name" .
" ";
echo $info;
echo "
| \n";
echo "now... | \n";
echo "skip | \n";
}
echo "
\n";
$time += $length;
$tottime += $length;
$n++;
}
$tot = "Total time: ";
if( $tottime >= 86400 )
{
$tot .= sprintf( "%dd %02d:%02d:%02d", $tottime/86400,
($tottime/3600)%24, ($tottime/60)%60, $tottime%60 );
}
else
{
$tot .= sprintf( "%2d:%02d:%02d",
($tottime/3600)%24, ($tottime/60)%60, $tottime%60 );
}
$n = 40 - strlen($tot);
while( $n > 0 )
{
$tot .= " ";
$n--;
}
echo "\n";
echo "$tot | \n";
echo "" .
strftime( $GLOBALS["strftimefmt"], $time ) . " | \n";
echo "UTC" . strftime( "%z", 0 ) . " | \n";
echo "
\n";
echo "
\n";
}
}
function recentlyplayed( $conn )
{
$datefmt = $GLOBALS["datefmt"];
echo "Recently Played Music
\n";
$sql = "select " .
"to_char( ipl_date_start, $datefmt ) as ipl_date_start, " .
"to_char( ipl_date_end, $datefmt ) as ipl_date_end, " .
"ipl_directory, " .
"ipl_name, " .
"iof_title, iof_artist, iof_album, iof_track_nr, " .
"iof_genre, iof_length, iof_bitrate, iof_filesize " .
"from " .
"ices2_playlist, ices2_oggfiles " .
"where " .
"ipl_date_start is not null and " .
"ipl_directory = iof_directory and " .
"ipl_name = iof_name " .
"order by " .
"ipl_date_start desc";
// echo "$sql
\n";
$rs = pg_exec( $conn, $sql );
if( $rs )
{
echo "\n";
echo "\n";
echo "Name | \n";
echo "Started | \n";
echo "Ended | \n";
echo "Add | \n";
echo "
\n";
$n = 0;
while( $row = pg_fetch_array( $rs ) )
{
$dates = $row["ipl_date_start"];
$datee = $row["ipl_date_end"];
$name = $row["ipl_name"];
$info = create_song_info( $row );
if( $datee == "" )
{
echo "\n";
echo "$name" .
" ";
echo $info;
echo "
| \n";
echo "$dates | \n";
echo "playing... | \n";
echo " | \n";
} else {
if( ($n % 2) )
{
echo "
\n";
}
else
{
echo "
\n";
}
echo "$name" .
" ";
echo $info;
echo "
| \n";
echo "$dates | \n";
echo "$datee | \n";
echo "Add | \n";
}
echo "
\n";
$n++;
if( $n > $GLOBALS["recent_count"] )
{
break;
}
}
echo "
\n";
}
}
function browse( $conn )
{
if( isset( $_REQUEST["curdir"] ) )
{
// $curdir = str_replace( "\\'", "'", $_REQUEST["curdir"] );
$curdir = $_REQUEST["curdir"];
$_SESSION["curdir"] = $curdir;
}
else
{
$curdir = $_SESSION["curdir"];
}
if( $curdir == "" )
{
$curdir = "/";
$dirprefix = "";
}
else
{
$dirprefix = $curdir . "/";
}
$curdirenc = pg_escape_string( $curdir );
$sql = "select " .
"iof_name, " .
"iof_is_file, " .
"iof_title, iof_artist, iof_album, iof_track_nr, " .
"iof_genre, iof_length, iof_bitrate, iof_filesize " .
"from " .
"ices2_oggfiles " .
"where " .
"iof_directory = '$curdirenc' " .
"order by " .
"lower(iof_name)";
// echo "$sql
\n";
$rs = pg_exec( $conn, $sql );
if( $rs )
{
$links = "root/";
if( $curdir != "/" )
{
$d = split( "/", $curdir );
$n = count($d);
$i = 0;
$name = $d[0];
while( $i < $n )
{
$links .= " > " . $d[$i] . "/";
$i++;
$name .= "/" . $d[$i];
}
}
echo "" . $links . "
\n";
while( $row = pg_fetch_array( $rs ) )
{
if( $row["iof_is_file"] == "t" )
{
$info = create_song_info( $row );
$song = array( "name" => $row["iof_name"], "info" => $info );
$oggs[] = $song;
}
else
{
$dirs[] = $row["iof_name"];
}
}
?>\n";
echo "\n";
echo "\n";
echo "\n";
echo "";
echo "\n";
}
}
function browse_add( $conn )
{
$curdir = $_REQUEST["curdir"];
$cbcnt = $_REQUEST["cbcnt"];
$n = 0;
$i = 0;
while( $i < $cbcnt )
{
$cbnmae = "cb" . $i;
if( isset( $_REQUEST[$cbnmae] ) )
{
$n++;
$name = $_REQUEST[$cbnmae];
if( $curdir != "" && $curdir != "/" )
{
$listname = $curdir . "/" . $name;
}
else
{
$listname = $name;
}
$listdirenc = pg_escape_string( $curdir );
$listnameenc = pg_escape_string( $name );
$fullname = $GLOBALS["music_dir"] . "/" . $listname;
if( is_file( $fullname ) )
{
$sql = "insert into ices2_playlist ( " .
"ipl_date_ins, ipl_seq_nr, " .
"ipl_directory, ipl_name " .
") values ( " .
"current_timestamp, $n, " .
"'$listdirenc', '$listnameenc' " .
")";
pg_exec( $conn, $sql );
}
}
$i++;
}
}
function delete_song( $conn )
{
$datefmt = $GLOBALS["datefmt"];
$seqnr = $_REQUEST["seqnr"];
$date = $_REQUEST["date"];
$sql = "delete from ices2_playlist " .
"where to_char(ipl_date_ins, $datefmt ) = '$date' " .
"and ipl_seq_nr = $seqnr";
pg_exec( $conn, $sql );
}
function delete_song_all( $conn )
{
$sql = "delete from ices2_playlist where ipl_date_start is null";
pg_exec( $conn, $sql );
}
function skip_song( $conn )
{
$sig = 1;
$pid = file( $GLOBALS["ices2_pid_file"] );
posix_kill( $pid[0], $sig );
}
$conn = db_connect();
$cmd = $_REQUEST["cmd"];
switch( $cmd )
{
case "br_add":
printheader();
browse_add( $conn );
$cmd = "br";
break;
case "pl_del":
printheader();
delete_song( $conn );
$cmd = "pl";
break;
case "pl_del_all":
printheader();
delete_song_all( $conn );
$cmd = "pl";
break;
case "pl_skip":
skip_song( $conn );
header( "Location: " . $_SERVER["HTTP_REFERER"] );
printheader();
sleep(4);
$cmd = "pl";
break;
case "pl_readd":
printheader();
browse_add( $conn );
$cmd = "rp";
break;
default:
printheader();
break;
}
// $mainmenulink = 1;
// $playlistlink = 1;
$footerlinks = 1;
switch( $cmd )
{
case "pl":
playlist( $conn );
// $playlistlink = 0;
break;
case "rp":
recentlyplayed( $conn );
break;
case "br":
browse( $conn );
break;
default:
mainmenu();
$footerlinks = 0;
// $mainmenulink = 0;
// $playlistlink = 0;
break;
}
/*
if( $mainmenulink != 0 )
{
echo "
\n";
echo "Main Menu
";
}
if( $playlistlink != 0 )
{
echo "Playlist
\n";
}
*/
// printarray( "_SERVER", $_SERVER );
printfooter( $footerlinks );
?>