Location: PHPKode > scripts > AmaroK Web Frontend > obsidianmusic-2.3.0/pages/playlist.php
<?php

//
//  ObsidianMusic
//   a.k.a. amaroK Web Frontend 2.0
//
//  Created 1/3/06
//   Copyright (C) Ryan Loebs (ObsidianX) 2005/2006
//   See LICENSE for GPL
//
//  playlist.php - Manages the playlist in the current SESSION
//
///////////////////////////////////////

if(eregi("playlist.php", $_SERVER['PHP_SELF'])){
	die("Cannot access directly.");
}


$tpl->setAttribute("songs", "src", "playlist.tpl");
$tpl->loadTemplate("songs");

$tpl->addVar("songs", "page", _PG_PLIST);
$tpl->addVar("root", "title", _PG_PLIST);
$tpl->addVar("songs", "song", _SONG);
$tpl->addVar("songs", "length", _LENGTH);
$tpl->addVar("songs", "totallength", _PLAYTIME);

if(isset($_POST['plaction']) && strlen($_POST['plaction']) > 0) {
	$subact = $_POST['plaction'];
}
// At this moment we need support GET method for order managing
elseif(isset($_GET['plaction'])) {
	$subact = $_GET['plaction'];
}
else {
	$subact = '';
}

if(!@$_SESSION['plist']){
	$_SESSION['plist'] = array();
}

switch($subact) {
	case "add":
		foreach($_POST['plist'] as $track_id){
			$_SESSION['plist'][] = (int)$track_id;
		}
		break;
	case "remove":
		if(count($_POST['plist']) > 0){
			foreach($_POST['plist'] as $key=>$value){
				unset($_SESSION['plist'][$key]);
			}
			// remove gap in keys created by unset
			$_SESSION['plist'] = array_values($_SESSION['plist']);
		}
		break;
	case "move":
		
		if(!isset($_GET['dir']) || !isset($_GET['key'])){
			break;
		}
		switch($_GET['dir']){
			case "up":
				if(!isset($_SESSION['plist'][$_GET['key']]) || (int)$_GET['key'] === 0 ){
					break;
				}
				$tmp = $_SESSION['plist'][$_GET['key']-1];
				$_SESSION['plist'][$_GET['key']-1] = $_SESSION['plist'][$_GET['key']];
				$_SESSION['plist'][$_GET['key']] = $tmp;
				break;
			
			case "dn":
				if(!isset($_SESSION['plist'][$_GET['key']], $_SESSION['plist'][$_GET['key']+1]) ) {
					break;
				}
				$tmp = $_SESSION['plist'][$_GET['key']+1];
				$_SESSION['plist'][$_GET['key']+1] = $_SESSION['plist'][$_GET['key']];
				$_SESSION['plist'][$_GET['key']] = $tmp;
				break;
		}
		break;
	case "clear":
		$_SESSION['plist'] = array();
		break;
	case "play":
		header("Location: ?action=play&type=list&SID=".SID);
		break;
}

$sessionlist = @$_SESSION['plist'];

if(count($sessionlist) == 0){
	$tpl->setAttribute("list", "visibility", "hidden");
	$tpl->setAttribute("nosongs", "visibility", "visible");
	$tpl->addVar("nosongs", "nosongs", _PL_NOSONGS);
	$length = 0;
}
else{
	$length = 0;
	
	$tracks = array();
	if(isset($_SESSION['plist']) && sizeof($_SESSION['plist']) > 0) {
		$res = query(getquery('tracks', $sort, $_SESSION['plist']));
		while($track = fetch_assoc($res)) {
			$tracks[$track['id']] = $track;
		}
	}
	
	foreach($_SESSION['plist'] as $key => $track_id){
		$tpl->clearTemplate("arrows");
		$tpl->addVar("list", "num", $key);
		$tpl->addVar("list", "songid", $tracks[$track_id]['id']);
		$tpl->addVar("list", "song", $tracks[$track_id]['artistN'].' - '.$tracks[$track_id]['title']);
		$tpl->addVar("list", "length", sec2min($tracks[$track_id]['length']));
		if(sizeof($_SESSION['plist']) == 1){
			$tpl->addVar("arrows", "arr", "n");
		} else if($key == 0) {
			$tpl->addVar("arrows", "arr", "d");
		} else if(!isset($_SESSION['plist'][$key+1])){
			$tpl->addVar("arrows", "arr", "u");
		} else{
			$tpl->addVar("arrows", "arr", "b");
		}
		$tpl->addVar("arrows", "last", ($key == 0 ? 'f' : $key-1));
		$tpl->addVar("arrows", "num", $key);
		$tpl->parseTemplate("arrows", "a");
		$tpl->parseTemplate("list", "a");
		
		$length += $tracks[$track_id]['length'];
	}
}

$tpl->addVar("songs", "totallen", sec2min($length));
$tpl->addVar("buttons", "plistbuttons", "plist");
Return current item: AmaroK Web Frontend