<?php
/*
* @package Easy MusicBox
* @author Kevin Pentiah <hide@address.com>
* @copyright 2006 3scriptz
* @license PHP License
* @version Release: 1.0.0
* @link http://www.3scriptz.com
* @since Class available since Release 1.0.0
* @desc edit, add and delete from playlist
*/
error_reporting(E_ALL);
//cookies playlist
class playlist {
var $count;
var $total;
var $limit;
//add to playlist
function add_to_pls($pick) {
$j = count($pick);
if (isset($_COOKIE['3z'])) {
$this->count = count($_COOKIE['3z']);
$this->total = $this->count + $j;
for($i=$this->count; $i<$this->total; $i++) {
$p = $i-$this->count;
setcookie("3z[$i]", $pick[$p], time()+3600);
}
}
else {
for($i=0; $i<$j; $i++) {
setcookie("3z[$i]", $pick[$i], time()+3600);
}
}
}
//fetch playlist cookie
function get_pls($array_num,$limit,$type) {
if (isset($_COOKIE['3z'])) {
$this->count = count($_COOKIE['3z']);
$this->total = $array_num + $limit;
if ($this->total > $this->count) {
$this->total = $this->count;
}
echo "<b>$this->count items</b><br />";
for ($i = $array_num; $i<$this->total; $i++) {
if ($type == 1)
$this->checkbox($i);
else
$this->leftbox($i);
//echo '<input type="checkbox" name="pick[]" value="'.$_COOKIE['3z'][$i].'" />'.$_COOKIE['3z'][$i].'<br />';
}
$this->limit = $limit;
}
else {
echo 'Your playlist is empty!!<br />Either you have not added any songs or cookies are disabled';
}
}
function checkbox($i) {
echo '<input type="checkbox" name="unpick[]" value="'.$i.'" />'.stripslashes(file_details::song_name($_COOKIE['3z'][$i])).'<br />';
}
function leftbox($i) {
echo ''.($i+1).'-'.file_details::song_name($_COOKIE['3z'][$i]).'<br />';
}
//paginate
function paginate_pls($page) {
if (isset($_COOKIE['3z'])) {
$next_page = $this->total/$this->limit + 1;
if ($this->total > $this->limit) {
echo '<a href="?act=pls&page='.($page-1).'"><<</a>';
}
if ($this->total < $this->count) {
echo '<a href="?act=pls&page='.$next_page.'">>></a>';
}
}
}
//remove from to playlist
function remove_from_pls($unpick,$page,$limit) {
foreach ($unpick as $u) {
unset($_COOKIE['3z'][$u]);
setcookie("3z[$u]", "", time()-3600);
}
$cookie_values = array_values($_COOKIE['3z']);
foreach ($_COOKIE['3z'] as $key=>$val) {
if (isset ($_COOKIE['3z'][$key])) {
setcookie("3z[$key]", "", time()-3600);
}
}
for ($c = 0; $c < count($cookie_values); $c++) {
setcookie("3z[$c]","$cookie_values[$c]",time()+3600);
}
}
}
?>