summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKarl 'vollmerk' Vollmer <vollmer@ampache.org>2006-01-03 09:21:29 +0000
committerKarl 'vollmerk' Vollmer <vollmer@ampache.org>2006-01-03 09:21:29 +0000
commitdfbe65e1bf0a4d7cff1e2d31a2ade18de6756196 (patch)
tree1036034cfcb8653f37b2e690f8b83068f98fe509
parenta2cf31f96cd9ba28b1f5e7090208312a9e5b7ca9 (diff)
downloadampache-dfbe65e1bf0a4d7cff1e2d31a2ade18de6756196.tar.gz
ampache-dfbe65e1bf0a4d7cff1e2d31a2ade18de6756196.tar.bz2
ampache-dfbe65e1bf0a4d7cff1e2d31a2ade18de6756196.zip
whole new playlists files new coolness supported but not implmented, playback works but playlist edit functions are still untested...
-rwxr-xr-xdocs/CHANGELOG3
-rw-r--r--lib/class/playlist.class.php568
-rw-r--r--lib/playlist.lib.php91
-rw-r--r--lib/song.php16
-rw-r--r--lib/ui.lib.php23
-rw-r--r--modules/init.php35
-rw-r--r--modules/lib.php135
-rw-r--r--playlist.php351
-rw-r--r--song.php13
-rw-r--r--templates/show_import_playlist.inc.php2
-rw-r--r--templates/show_playlists.inc.php (renamed from templates/show_playlists.php.inc)4
-rw-r--r--templates/show_songs.inc95
12 files changed, 593 insertions, 743 deletions
diff --git a/docs/CHANGELOG b/docs/CHANGELOG
index 2a750ec0..625b6f43 100755
--- a/docs/CHANGELOG
+++ b/docs/CHANGELOG
@@ -4,6 +4,9 @@
--------------------------------------------------------------------------
v.3.3.2-Beta1
+ - Rewrote entire Playlist class and document to use the new id
+ field in database, also added support for playlist tracks
+ that are based on search critera. NOT FINISHED!
- Fixed Album Art Search so that it doesn't include the artist
if there is more then one artist on the album
- Fixed Registration code so that it used existing functions and
diff --git a/lib/class/playlist.class.php b/lib/class/playlist.class.php
index 279134ee..f9cf0732 100644
--- a/lib/class/playlist.class.php
+++ b/lib/class/playlist.class.php
@@ -18,393 +18,375 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-
-*/
-/*!
- @header Playlist Class
- This class handles all actual work in regards to playlists.
*/
+/**
+ * Playlist Class
+ * This class handles playlists in ampache. it references the playlist* tables
+ */
+class Playlist {
-class Playlist {
-
- // Variables from DB
+ /* Variables from the Datbase */
var $id;
var $name;
var $user;
var $type;
- var $time;
- var $items;
+ var $date;
- /*!
- @function Playlist
- @discussion Playlist class
- @param $playlist_id The ID of the playlist
- */
- function Playlist($playlist_id = 0) {
+ /* Generated Elements */
+ var $items = array();
- /* If we have an id then do something */
- if ($playlist_id) {
- // Assign id
- $this->id = $playlist_id;
- // Get the information from the db
- $this->refresh_object();
- }
+ /**
+ * Constructor
+ * This takes a playlist_id as an optional argument and gathers the information
+ * if not playlist_id is passed returns false (or if it isn't found
+ */
+ function Playlist($playlist_id = 0) {
+
+ if (!$playlist_id) { return false; }
- }
+ $this->id = $playlist_id;
+ $info = $this->_get_info();
+ $this->name = $info['name'];
+ $this->user = $info['user'];
+ $this->type = $info['type'];
+ $this->date = $info['date'];
+
+ } // Playlist
+ /**
+ * _get_info
+ * This is an internal (private) function that gathers the information for this object from the
+ * playlist_id that was passed in.
+ */
+ function _get_info() {
+ $sql = "SELECT * FROM playlist WHERE id='" . sql_escape($this->id) . "'";
+ $db_results = mysql_query($sql, dbh());
- /*!
- @function refresh_object
- @discussion Reads playlist information from the db and updates the Playlist object with it
- */
- function refresh_object() {
+ $results = mysql_fetch_assoc($db_results);
- $dbh = dbh();
+ return $results;
- if ($this->id) {
- $sql = "SELECT name, user, type, date FROM playlist" .
- " WHERE id = '$this->id'";
- $db_results = mysql_query($sql, $dbh);
+ } // _get_info
- if ($r = mysql_fetch_object($db_results)) {
- $this->name = $r->name;
- $this->user = $r->user;
- $this->type = $r->type;
- $this->time = $r->date;
- $this->items = array();
+ /**
+ * get_items
+ * This returns an array of playlist songs that are in this playlist. Because the same
+ * song can be on the same playlist twice they are key'd by the uid from playlist_data
+ */
+ function get_items() {
- // Fetch playlist items
- $sql = "SELECT song, track FROM playlist_data" .
- " WHERE playlist = '$this->id'" .
- " ORDER BY track";
- $db_results = mysql_query($sql, $dbh);
+ $sql = "SELECT * FROM playlist_data WHERE playlist='" . sql_escape($this->id) . "'";
+ $db_results = mysql_query($sql, dbh());
- while ($r = mysql_fetch_object($db_results)) {
- $this->items[] = array("song_id" => $r->song, "track" => $r->track);
- }
- }
+ while ($r = mysql_fetch_assoc($db_results)) {
- return TRUE;
- }
+ $key = $r['id'];
+ $results[$key] = $r;
- return FALSE;
+ } // end while
- }
+ return $results;
+ } // get_items
- /*!
- @function create_playlist
- @discussion Creates an empty playlist, given a name, user_id, and type.
- */
- function create_playlist($name, $user, $type) {
+ /**
+ * get_songs
+ * This returns an array of song_ids accounting for any dyn_song entries this playlist
+ * may have. This is what should be called when trying to generate a m3u or other playlist
+ */
+ function get_songs() {
- $dbh = dbh();
+ $sql = "SELECT * FROM playlist_data WHERE playlist='" . sql_escape($this->id) . "'";
+ $db_results = mysql_query($sql, dbh());
- if (isset($name) && isset($user) && isset($type) && $this->check_type($type)) {
- $name = sql_escape($name);
- $user = sql_escape($user);
- $type = sql_escape($type);
-
- $sql = "INSERT INTO playlist (name, user, type)" .
- " VALUES ('$name', '$user', '$type')";
- $db_results = mysql_query($sql, $dbh);
-
- if ($this->id = mysql_insert_id($dbh)) {
- $this->refresh_object();
- return true;
- } // end if it created correctly
-
- } // end if this is a valid playlist entry
+ $results = array();
- if (conf('debug')) {
- log_event($GLOBALS['user']->username,'playlist_create',"Failed to Create Playlist of $type Type named $name for $user");
- }
+ while ($r = mysql_fetch_assoc($db_results)) {
- return false;
+ if ($r['dyn_song']) {
+ $array = $this->get_dyn_songs($r['dyn_song']);
+ $results = array_merge($array,$results);
+ }
+ else {
+ $results[] = $r['song'];
+ }
- } // create_playlist
+ } // end while
+ return $results;
- /*!
- @function delete
- @discussion Deletes the playlist.
- */
- function delete() {
+ } // get_songs
- $dbh = dbh();
+ /**
+ * get_random_songs
+ * This returns all of the songs in a random order, except those
+ * pulled from dyn_songs
+ */
+ function get_random_songs() {
- if ($this->id) {
- $sql = "DELETE FROM playlist_data" .
- " WHERE playlist = '$this->id'";
- $db_results = mysql_query($sql, $dbh);
+ $sql = "SELECT * FROM playlist_data WHERE playlist='" . sql_escape($this->id) . "'" .
+ " ORDER BY RAND()";
+ $db_results = mysql_query($sql, dbh());
- $sql = "DELETE FROM playlist" .
- " WHERE id = '$this->id'";
- $db_results = mysql_query($sql, $dbh);
+ $results = array();
- $sql = "DELETE FROM playlist_permission" .
- " WHERE playlist = '$this->id'";
- $db_results = mysql_query($sql, $dbh);
+ while ($r = mysql_fetch_assoc($db_results)) {
+ if ($r['dyn_song']) {
+ $array = $this->get_dyn_songs($r['dyn_song']);
+ $results = array_merge($array,$results);
+ }
+ else {
+ $results[] = $r['song'];
+ }
+ } // end while
- return true;
- } // if we've got a valid playlist
+ return $results;
- return false;
+ } // get_random_songs
- } // delete
+ /**
+ * get_dyn_songs
+ * This returns an array of song_ids for a single dynamic playlist entry
+ */
+ function get_dyn_songs($dyn_string) {
+ /* Ok honestly I know this is risky, so we have to be
+ * 100% sure that the user never got to touch this. This
+ * Query has to return id which must be a song.id
+ */
+ $db_results = mysql_query($dyn_string, dbh());
- /*!
- @function update_track_numbers
- @discussion Reads an array of song_ids and track numbers to update
- */
- function update_track_numbers($changes) {
-
- $dbh = dbh();
-
- if ($this->id && isset($changes) && is_array($changes)) {
- foreach ($changes as $change) {
- // Check for valid song_id
- $sql = "SELECT count(*) FROM song WHERE id = '" . $change['song_id'] . "'";
- $db_results = mysql_query($sql, $dbh);
- $r = mysql_fetch_row($db_results);
- if ($r[0] == 1) {
- $sql = "UPDATE playlist_data SET" .
- " track = '" . $change['track'] . "'" .
- " WHERE playlist = '$this->id'".
- " AND song = '" . $change['song_id'] . "'";
- $db_results = mysql_query($sql, $dbh);
- }
- }
+ $results = array();
- // Refresh the playlist object
- $this->refresh_object();
+ while ($r = mysql_fetch_assoc($db_results)) {
+ $results[] = $r['id'];
+ } // end while
- return TRUE;
- }
+ return $results;
- return FALSE;
-
- }
-
-
- /*!
- @function add_songs
- @discussion Reads an array of song_ids to add to the playlist
- @param $song_ids the array of song_ids
- @param $is_ordered boolean, if true insert in order submitted, not by track number
- */
- function add_songs($song_ids, $is_ordered = false) {
-
- $dbh = dbh();
-
- if ($this->id && isset($song_ids) && is_array($song_ids)) {
- $count = 0;
- foreach ($song_ids as $song_id) {
- if( $is_ordered ) {
- $track_num = $count++;
- } else {
- $track_num = $song->track;
- }
- $song = new Song($song_id);
- if (isset($song->id)) {
- $sql = "INSERT INTO playlist_data" .
- " (playlist, song, track)" .
- " VALUES ('$this->id', '$song->id', '$track_num')";
- $db_results = mysql_query($sql, $dbh);
- }
- }
+ } // get_dyn_songs
- // Refresh the playlist object
- $this->refresh_object();
+ /**
+ * get_song_count
+ * This simply returns a int of how many song elements exist in this playlist
+ * For now let's consider a dyn_song a single entry
+ */
+ function get_song_count() {
- return TRUE;
- }
+ $sql = "SELECT COUNT(id) FROM playlist_data WHERE playlist='" . sql_escape($this->id) . "'";
+ $db_results = mysql_query($sql, dbh());
- return FALSE;
+ $results = mysql_fetch_row($db_results);
- } // add_songs
+ return $results['0'];
+ } // get_song_count
- /*!
- @function remove_songs
- @discussion Reads an array of song_ids to remove from the playlist
- */
- function remove_songs($song_ids) {
+ /**
+ * update_type
+ * This updates the playlist type, it calls the generic update_item function
+ */
+ function update_type($new_type) {
- $dbh = dbh();
+ if ($this->_update_item('type',$new_type,'100')) {
+ $this->type = $new_type;
+ }
- if ($this->id && isset($song_ids) && is_array($song_ids)) {
- foreach ($song_ids as $song_id) {
- $sql = "DELETE FROM playlist_data" .
- " WHERE song = '$song_id'" .
- " AND playlist = '$this->id'";
- $db_results = mysql_query($sql, $dbh);
- }
+ } // update_type
- // Refresh the playlist object
- $this->refresh_object();
+ /**
+ * update_name
+ * This updates the playlist name, it calls the generic update_item function
+ */
+ function update_name($new_name) {
- return TRUE;
+ if ($this->_update_item('name',$new_name,'100')) {
+ $this->name = $new_name;
}
- return FALSE;
+ } // update_name
- }
+ /**
+ * update_item
+ * This is the generic update function, it does the escaping and error checking
+ */
+ function update_item($field,$value,$level) {
+ if ($GLOBALS['user']->username != $this->user AND !$GLOBALS['user']->has_access($level)) {
+ return false;
+ }
- /*!
- @function check_type
- @discussion Checks for a valid playlist type
- */
- function check_type($type) {
+ $value = sql_escape($value);
- if (isset($type)) {
- if ($type === 'public' || $type === 'private') {
- return TRUE;
- }
- }
+ $sql = "UPDATE playlist SET $field='$value' WHERE id='" . sql_escape($this->id) . "'";
+ $db_results = mysql_query($sql, dbh());
- return FALSE;
+ return $db_results;
- }
+ } // update_item
+ /**
+ * update_track_numbers
+
+ * This function takes an array of $array['song_id'] $array['track'] where song_id is really the
+ * playlist_data.id and updates them
+ */
+ function update_track_numbers($data) {
- /*!
- @function update_type
- @discussion Updates the playlist type
- */
- function update_type($type) {
+ foreach ($data as $change) {
+
+ $track = sql_escape($change['track']);
+ $id = sql_escape($change['song_id']);
- $dbh = dbh();
+ $sql = "UPDATE playlist_data SET track='$track' WHERE id='$id'";
+ $db_results = mysql_query($sql, dbh());
- if ($this->id && isset($type) && $this->check_type($type)) {
- $sql = "UPDATE playlist SET type = '$type'" .
- " WHERE id = '$this->id'";
- $db_results = mysql_query($sql, $dbh);
+ } // end foreach
- // Refresh the playlist object
- $this->refresh_object();
+ } // update_track_numbers
- return TRUE;
- }
+ /**
+ * add_songs
+ * This takes an array of song_ids and then adds it to the playlist
+ * if you want to add a dyn_song you need to use the one shot function
+ * add_dyn_song
+ */
+ function add_songs($song_ids=array()) {
- return FALSE;
+ foreach ($song_ids as $song_id) {
+ /* We need the songs track */
+ $song = new Song($song_id);
- }
+ $track = sql_escape($song->track);
+ $id = sql_escape($song->id);
+ $pl_id = sql_escape($this->id);
+ /* Don't insert dead songs */
+ if ($id) {
+ $sql = "INSERT INTO playlist_data (`playlist`,`song`,`track`) " .
+ " VALUES ('$pl_id','$id','$track')";
+ $db_results = mysql_query($sql, dbh());
+ } // if valid id
- /*!
- @function update_name
- @discussion Updates the playlist name
- */
- function update_name($name) {
+ } // end foreach songs
- $dbh = dbh();
+ } // add_songs
- if ($this->id && isset($name)) {
- $name = sql_escape($name);
- $sql = "UPDATE playlist SET name = '$name'" .
- " WHERE id = '$this->id'";
- $db_results = mysql_query($sql, $dbh);
+ /**
+ * create
+ * This function creates an empty playlist, gives it a name and type
+ * Assumes $GLOBALS['user']->username as the user
+ */
+ function create($name,$type) {
- // Refresh the playlist object
- $this->refresh_object();
+ $name = sql_escape($name);
+ $type = sql_escape($type);
+ $user = sql_escape($GLOBALS['user']->username);
+ $date = time();
- return TRUE;
- }
+ $sql = "INSERT INTO playlist (`name`,`user`,`type`,`date`) " .
+ " VALUES ('$name','$user','$type','$date')";
+ $db_results = mysql_query($sql, dbh());
- return FALSE;
+ $insert_id = mysql_insert_id(dbh());
- }
+ return $insert_id;
- /*!
- @function normalize_tracks
- @discussion this takes the crazy out of order tracks
- and numbers them in a liner fashion, not allowing for
- the same track # twice, this is an optional funcition
- */
- function normalize_tracks() {
+ } //create_paylist
- /* First get all of the songs in order of their tracks */
- $sql = "SELECT id FROM playlist_data WHERE playlist='$this->id' ORDER BY track ASC";
- $db_results = mysql_query($sql, dbh());
+ /**
+ * set_items
+ * This calles the get_items function and sets it to $this->items which is an array in this object
+ */
+ function set_items() {
- $i = 1;
+ $this->items = $this->get_items();
- while ($r = mysql_fetch_assoc($db_results)) {
- $new_data = array();
- $new_data['id'] = $r['id'];
- $new_data['track'] = $i;
- $results[] = $new_data;
- $i++;
- } // end while results
-
- foreach($results as $data) {
- $sql = "UPDATE playlist_data SET track='" . $data['track'] . "' WHERE" .
- " id='" . $data['id'] . "'";
- $db_results = mysql_query($sql, dbh());
- } // foreach re-ordered results
+ } // set_items
- return true;
+ /**
+ * normalize_tracks
+ * this takes the crazy out of order tracks
+ * and numbers them in a liner fashion, not allowing for
+ * the same track # twice, this is an optional funcition
+ */
+ function normalize_tracks() {
- } // normalize_tracks
-
+ /* First get all of the songs in order of their tracks */
+ $sql = "SELECT id FROM playlist_data WHERE playlist='" . sql_escape($this->id) . "' ORDER BY track ASC";
+ $db_results = mysql_query($sql, dbh());
- /*!
- @function get_songs
- @discussion Returns an array of song_ids for the playlist
- */
- function get_songs() {
+ $i = 1;
- $song_ids = array();
+ while ($r = mysql_fetch_assoc($db_results)) {
+ $new_data = array();
+ $new_data['id'] = $r['id'];
+ $new_data['track'] = $i;
+ $results[] = $new_data;
+ $i++;
+ } // end while results
- if ($this->id && is_array($this->items)) {
- foreach ($this->items as $item) {
- $song_ids[] = $item['song_id'];
- }
- }
+ foreach($results as $data) {
+ $sql = "UPDATE playlist_data SET track='" . $data['track'] . "' WHERE" .
+ " id='" . $data['id'] . "'";
+ $db_results = mysql_query($sql, dbh());
+ } // foreach re-ordered results
- return $song_ids;
+ return true;
- } // get_songs
+ } // normalize_tracks
+
+ /**
+ * check_type
+ * This validates a type to make sure it's legit
+ */
+ function check_type($type) {
- /*!
- @function get_random_songs
- @discussion gets a random set of the songs in this
- playlist
- */
- function get_random_songs() {
+ if ($type == 'public' || $type == 'private') { return true; }
+
+ return false;
- $sql = "SELECT COUNT(song) FROM playlist_data WHERE playlist = '$this->id'";
- $db_results = mysql_query($sql, dbh());
+ } // check_type
- $total_songs = mysql_fetch_row($db_results);
+ /**
+ * remove_songs
+ * This is the polar opposite of the add_songs function... with one little
+ * change. it works off of the playlist_data.id rather then song_id
+ */
+ function remove_songs($data) {
+
+ foreach ($data as $value) {
- // Fetch playlist items
- $sql = "SELECT song, track FROM playlist_data" .
- " WHERE playlist = '$this->id'" .
- " ORDER BY RAND()";
- $db_results = mysql_query($sql, dbh());
- while ($r = mysql_fetch_object($db_results)) {
- $song_ids[] = $r->song;
- }
+ $id = sql_escape($value);
+
+ $sql = "DELETE FROM playlist_data WHERE id='$id'";
+ $db_results = mysql_query($sql, dbh());
- return $song_ids;
- } // get_random_songs
+ } // end foreach dead songs
+
+ } // remove_songs
+
+ /**
+ * delete
+ * This deletes the current playlist and all assoicated data
+ */
+ function delete() {
- /*!
- @function show_import
- @discussion shows the import from file template
- */
- function show_import() {
+ $id = sql_escape($this->id);
- require (conf('prefix') . "/templates/show_import_playlist.inc.php");
+ $sql = "DELETE FROM playlist_data WHERE playlist = '$id'";
+ $db_results = mysql_query($sql, dbh());
- } // show_import
+ $sql = "DELETE FROM playlist WHERE id='$id'";
+ $db_results = mysql_query($sql, dbh());
-} //end of playlist class
+ $sql = "DELETE FROM playlist_permission WHERE playlist='$id'";
+ $db_results = mysql_query($sql, dbh());
+
+ return true;
+
+ } // delete
-?>
+} // class Playlist
diff --git a/lib/playlist.lib.php b/lib/playlist.lib.php
new file mode 100644
index 00000000..0d0e3fe6
--- /dev/null
+++ b/lib/playlist.lib.php
@@ -0,0 +1,91 @@
+<?php
+/*
+
+ Copyright (c) 2001 - 2006 Ampache.org
+ All Rights Reserved
+
+ 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 2
+ 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, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+*/
+/**
+ * Playlist Library
+ * This file should contain the functions that don't fit inside the object, but
+ * still are related to handling playlists
+ */
+
+/**
+ * show_playlists
+ * This shows all of the current playlists. Depending on your rights you may just
+ * get to see Public + Yours Private or if you're an admin then you get to see
+ * Public + Yours + Private
+ */
+function show_playlists() {
+
+ /* Always show yours first */
+ $playlists = get_playlists('private');
+ $type = 'Private';
+ require (conf('prefix') . '/templates/show_playlists.inc.php');
+
+ /* Now for some Admin? */
+ if ($GLOBALS['user']->has_access(100)) {
+ $playlists = get_playlists('adminprivate');
+ $type = 'Admin';
+ require (conf('prefix') . '/templates/show_playlists.inc.php');
+ }
+
+ /* Always Show Public */
+ $playlists = get_playlists('public');
+ $type = 'Public';
+ require (conf('prefix') . '/templates/show_playlists.inc.php');
+
+} // show_playlists
+
+/**
+ * get_playlists
+ * This function takes private,adminprivate or public and returns an array of playlist objects
+ * that match, it checks permission
+ */
+function get_playlists($type) {
+
+ switch ($type) {
+ case 'private':
+ $sql = "SELECT id FROM playlist WHERE user='" . sql_escape($GLOBALS['user']->username) . "'" .
+ " AND type='private'";
+ break;
+ case 'adminprivate':
+ if (!$GLOBALS['user']->has_access(100)) { return false; }
+ $sql = "SELECT id FROM playlist WHERE user!='" . sql_escape($GLOBALS['user']->username) . "'" .
+ " AND type='private'";
+ break;
+ default:
+ case 'public':
+ $sql = "SELECT id FROM playlist WHERE type='public'";
+ break;
+ } // end switch
+
+ $db_results = mysql_query($sql, dbh());
+
+ $results = array();
+
+ while ($r = mysql_fetch_assoc($db_results)) {
+ $playlist = new Playlist($r['id']);
+ $results[] = $playlist;
+ }
+
+ return $results;
+
+} // get_playlists
+
+?>
diff --git a/lib/song.php b/lib/song.php
index ba453d5c..b24c94db 100644
--- a/lib/song.php
+++ b/lib/song.php
@@ -19,12 +19,13 @@
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
-/*
- @header Song Library
- @discussion This library handles song related functions.... woohoo!
- This library is defunt, please try use the song class if possible
-*/
+/**
+ * Song Library
+ * This is for functions that don't make sense in the class because we aren't looking
+ * at a specific song... these should be general function that return arrays of songs
+ * and the like
+ */
/*!
@function get_songs
@@ -35,9 +36,6 @@ function get_songs($sql, $action=0) {
$db_results = mysql_query($sql, dbh());
while ($r = mysql_fetch_array($db_results)) {
-// $song_info = get_songinfo($r['id']);
-// if ($action === 'format') { $song = format_song($song_info); }
-// else { $song = $song_info; }
$results[] = $r['id'];
}
@@ -89,6 +87,4 @@ function get_popular_songs( $threshold, $type, $user_id = '' ) {
} // get_popular_songs()
-
-
?>
diff --git a/lib/ui.lib.php b/lib/ui.lib.php
index 6862ce57..2cf05a46 100644
--- a/lib/ui.lib.php
+++ b/lib/ui.lib.php
@@ -442,20 +442,20 @@ function show_edit_profile($username) {
} // show_edit_profile
/**
- * show_playlist
- * this shows the current playlist
+ * show_playlist
+ * This function takes a playlist object and calls show_songs after
+ * runing get_items()
*/
-function show_playlist($playlist_id) {
+function show_playlist($playlist) {
/* Create the Playlist */
- $playlist = new Playlist($playlist_id);
- $song_ids = $playlist->get_songs();
+ $song_ids = $playlist->get_items();
if (count($song_ids) > 0) {
show_songs($song_ids, $playlist->id);
}
else {
- echo "<p>" . _("No songs in this playlist.") . "</p>\n";
+ echo "<div class=\"text-box\">" . _("No songs in this playlist.") . "</div>\n";
}
} // show_playlist
@@ -1213,4 +1213,15 @@ function show_registration_agreement() {
} // show_registration_agreement
+
+/**
+ * show_playlist_import
+ * This shows the playlist import templates
+ */
+function show_playlist_import() {
+
+ require (conf('prefix') . '/templates/show_import_playlist.inc.php');
+
+} // show_playlist_import
+
?>
diff --git a/modules/init.php b/modules/init.php
index 0fc904c4..0facedb0 100644
--- a/modules/init.php
+++ b/modules/init.php
@@ -152,23 +152,24 @@ require_once(libglue_param('libglue_path') . "/session.php");
require_once(libglue_param('libglue_path') . "/dbh.php");
// Librarys
-require_once(conf('prefix') . "/lib/album.lib.php");
-require_once(conf('prefix') . "/lib/artist.lib.php");
-require_once(conf('prefix') . "/lib/song.php");
-require_once(conf('prefix') . "/lib/search.php");
-require_once(conf('prefix') . "/lib/preferences.php");
-require_once(conf('prefix') . "/lib/rss.php");
-require_once(conf('prefix') . "/lib/log.lib.php");
-require_once(conf('prefix') . "/lib/mpd.php");
-require_once(conf('prefix') . "/lib/ui.lib.php");
-require_once(conf('prefix') . "/lib/gettext.php");
-require_once(conf('prefix') . "/lib/batch.lib.php");
-require_once(conf('prefix') . "/lib/themes.php");
-require_once(conf('prefix') . "/lib/stream.lib.php");
-require_once(conf('prefix') . "/modules/lib.php");
-require_once(conf('prefix') . "/modules/admin.php");
-require_once(conf('prefix') . "/modules/catalog.php");
-require_once(conf('prefix') . "/lib/upload.php");
+require_once(conf('prefix') . '/lib/album.lib.php');
+require_once(conf('prefix') . '/lib/artist.lib.php');
+require_once(conf('prefix') . '/lib/song.php');
+require_once(conf('prefix') . '/lib/search.php');
+require_once(conf('prefix') . '/lib/preferences.php');
+require_once(conf('prefix') . '/lib/rss.php');
+require_once(conf('prefix') . '/lib/log.lib.php');
+require_once(conf('prefix') . '/lib/mpd.php');
+require_once(conf('prefix') . '/lib/ui.lib.php');
+require_once(conf('prefix') . '/lib/gettext.php');
+require_once(conf('prefix') . '/lib/batch.lib.php');
+require_once(conf('prefix') . '/lib/themes.php');
+require_once(conf('prefix') . '/lib/stream.lib.php');
+require_once(conf('prefix') . '/lib/playlist.lib.php');
+require_once(conf('prefix') . '/modules/lib.php');
+require_once(conf('prefix') . '/modules/admin.php');
+require_once(conf('prefix') . '/modules/catalog.php');
+require_once(conf('prefix') . '/lib/upload.php');
// Modules (These are conditionaly included depending upon config values)
require_once(conf('prefix') . "/modules/id3/audioinfo.class.php");
diff --git a/modules/lib.php b/modules/lib.php
index e887ac54..b1eda672 100644
--- a/modules/lib.php
+++ b/modules/lib.php
@@ -539,141 +539,6 @@ function show_albums ($albums,$view=0) {
} // show_albums
-
-// Had to tweak this so it would show both public and private playlists
-// Defaults to showing both although you could pass type=private|adminprivate|public
-// to see only those
-function show_playlists ($type = 'all') {
-
- $dbh = dbh();
-
- $user = $GLOBALS['user'];
-
- $web_path = conf('web_path');
-
- // mapping of types to pretty names
- $typemap = array( "public" => _("Public"),
- "private" => _("Your Private"),
- "adminprivate" => _("Other Private")
- );
-
- if ($type == 'all') {
- show_playlists('private');
- if ( $user->access === 'admin' ) {
- show_playlists('adminprivate');
- }
- show_playlists('public');
- return true;
- }
- elseif ($type == 'public') {
- $sql = "SELECT id,name,user,date ".
- " FROM playlist ".
- " WHERE type='public'".
- " ORDER BY name";
- }
- elseif ($type == 'private') {
- $sql = "SELECT id,name,user,date ".
- " FROM playlist ".
- " WHERE type='private'" .
- " AND user = '$user->username'" .
- " AND name <> 'Temporary'".
- " ORDER BY name";
- }
- elseif ($type == 'adminprivate') {
- if ( $user->access === 'admin' ) {
- $sql = "SELECT id,name,user,date ".
- " FROM playlist ".
- " WHERE type='private'" .
- " AND username != '$user->username'" .
- " AND name <> 'Temporary'".
- " ORDER BY name";
- }
- else {
- // No admin access
- $sql = 'SELECT 1+1';
- }
- }
- else {
- echo "** Error ** Call to show_playlists with unknown type $type ".
- "in file ".$_SERVER['PHP_SELF']." ** <br />\n";
- $sql = 'SELECT 1+1';
- }
-
- $db_result = mysql_query($sql, $dbh);
-
- print <<<ECHO
-<h3>$typemap[$type] Playlists</h3>
-
-<table class="tabledata" cellspacing="0" cellpadding="0" border="0">
- <tr class="table-header">
- <th>Playlist Name</th>
- <th># Songs</th>
- <th>Owner</th>
- <th colspan="6">Actions</th>
- </tr>
-
-ECHO;
-
- flip_class(array('even','odd'));
-
- if ( mysql_num_rows($db_result) ) {
- while ( $r = mysql_fetch_array($db_result) ) {
- $plname = $r['name'];
- $plid = $r['id'];
- $pluser = new User($r['user']);
- $plfullname = $pluser->fullname;
- $plowner = $pluser->username;
-
- // find out how many songs in this playlist
- $count_query = "SELECT count(*) ".
- " FROM playlist_data ".
- " WHERE playlist = '$plid'";
- $count_result = mysql_query($count_query, $dbh);
- list($count) = mysql_fetch_row($count_result);
- $class = flip_class();
- echo " <tr class=\"$class\">\n";
- echo " <td><a href=\"$web_path/playlist.php?playlist_id=$plid&amp;action=view_list\">$plname</a></td>\n";
- echo " <td>$count</td>\n";
- echo " <td>$plfullname</td>\n";
- echo " <td><a href=\"$web_path/playlist.php?playlist_id=$plid&amp;action=view_list\">" . _("View") . "</a></td>\n";
-
- if ($user->username == $pluser->username || $user->has_access(100)) {
- echo " <td><a href=\"$web_path/playlist.php?playlist_id=$plid&amp;action=edit\">" . _("Edit") . "</a></td>\n";
- echo " <td><a href=\"$web_path/playlist.php?playlist_id=$plid&amp;action=delete_playlist\">" . _("Delete") . "</a></td>\n";
- }
- else {
- echo " <td>&nbsp;</td>\n";
- echo " <td>&nbsp;</td>\n";
- }
-
- if ( $count[0] ) {
- echo " <td><a href=\"$web_path/song.php?action=m3u&amp;playlist_id=$plid\">" . _("Play") . "</a> | " .
- "<a href=\"$web_path/song.php?action=random&amp;playlist_id=$plid\">" . _("Random") . "</a></td>\n";
- }
- else {
- echo " <td>&nbsp;</td>\n";
- }
- if( batch_ok() ) {
- echo" <td><a href=\"$web_path/batch.php?action=pl&amp;id=$plid\">" . _("Download") . "</a></td>\n";
- } else {
- echo" <td>&nbsp;</td>\n";
- }
-
- echo " </tr>\n";
- }
- echo "\n";
- } //if rows in result
- else {
- echo " <tr class=\"even\">\n";
- echo " <td colspan=\"7\">" . _("There are no playlists of this type") . "</td>\n";
- echo " </tr>\n";
- }
-
- echo "</table>\n";
- echo "<br />\n";
-
-}
-
function get_playlist_track_from_song ( $playlist_id, $song_id ) {
$dbh = dbh();
diff --git a/playlist.php b/playlist.php
index 4f99293c..975e2ec8 100644
--- a/playlist.php
+++ b/playlist.php
@@ -2,7 +2,7 @@
/*
Copyright (c) 2001 - 2006 Ampache.org
- All Rights Reserved
+ All rights reserved.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
@@ -19,269 +19,146 @@
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
-
-/*
-
- Playlist mojo for adding, viewing, deleting, etc.
-
-*/
+/**
+ * Playlist Document
+ * This is the playlist document, it handles all things playlist.
+ */
require_once("modules/init.php");
-// Get user object for later
-
-if (isset($_REQUEST['action'])) {
- $action = scrub_in($_REQUEST['action']);
-}
-
-$type = scrub_in($_REQUEST['type']);
-
-if (isset($_REQUEST['results'])) {
- $results = scrub_in($_REQUEST['results']);
-}
-else {
- $results = array();
-}
-if (isset($_REQUEST['artist_id'])) {
- $artist_id = scrub_in($_REQUEST['artist_id']);
-}
-
-if (isset($_REQUEST['playlist_name'])) {
- $playlist_name = scrub_in($_REQUEST['playlist_name']);
-}
-
-if (isset($_REQUEST['new_playlist_name'])) {
- $new_playlist_name = scrub_in($_REQUEST['new_playlist_name']);
-}
-
-if (isset($_REQUEST['playlist_id'])) {
- $playlist_id = scrub_in($_REQUEST['playlist_id']);
-}
-
-if (isset($_REQUEST['confirm'])) {
- $confirm = scrub_in($_REQUEST['confirm']);
-}
-
-if (isset($_REQUEST['song'])) {
- $song_ids = scrub_in($_REQUEST['song']);
-}
+show_template('header');
-/* Prepare the Variables */
-$playlist = new Playlist(scrub_in($_REQUEST['playlist_id']));
+/* Get the Vars we need for later cleaned up */
+$action = strtolower(scrub_in($_REQUEST['action']));
+$playlist = new Playlist(scrub_in($_REQUEST['playlist_id']));
-/* First Switch */
-// Have to handle this here, since we use this file
-// for playback of the "Play Selected Stuff" and display (for now)
-// and this has to be done with a header redirection before the actuall top
-// of the page is shown
+/* Switch on the action passed in */
switch ($action) {
- case _("Flag Selected"):
- require_once(conf('prefix').'/lib/flag.php');
- $flags = scrub_in($_REQUEST['song']);
- set_flag_value($flags, 'badid3','');
- header("Location:" . conf('web_path')."/admin/flags.php" );
- break;
- case _("Edit Selected"):
- require_once(conf('prefix').'/lib/flag.php');
- $flags = scrub_in($_REQUEST['song']);
- set_flag_value($flags, 'badid3','');
- $count = add_to_edit_queue($flags);
- session_write_close();
- header( 'Location: '.conf('web_path').'/admin/flags.php?action='.urlencode($action) );
- exit();
+ case 'delete_playlist':
+ /* Make sure they have the rights */
+ if (!$GLOBALS['user']->has_access(100) AND $GLOBALS['user']->username != $playlist->user) {
+ access_denied();
+ break;
+ }
+ /* Go for it! */
+ $playlist->delete();
+ show_confirmation(_('Playlist Deleted'),_('The Requested Playlist has been deleted'),'/playlist.php');
break;
- default:
+ case 'show_delete_playlist':
+ /* Make sure they have the rights */
+ if (!$GLOBALS['user']->has_access(100) AND $GLOBALS['user']->username != $playlist->user) {
+ access_denied();
+ break;
+ }
+
+ /* Show Confirmation Question */
+ $message = _('Are you sure you want to delete this playlist') . " " . $playlist->name . "?";
+ show_confirm_action(_('Confirm Delete Request'),$message,'playlist.php','action=delete_playlist&amp;playlist_id=' . $playlist->id);
break;
-} // end first action switch
-
-show_template('header');
-
-$playlist = new Playlist($playlist_id);
-
-if ( isset($playlist_id) && ($playlist_id != 0) && $_REQUEST['action'] != 'delete_playlist' ) {
- // Get the playlist and check access
- $pluser = new User($playlist->user);
-
- if (! isset($playlist->id)) {
- show_playlist_access_error($playlist_id, $pluser->username);
- }
-
- echo "<div style=\"width:50%;\" class=\"text-box\">\n";
- echo "<span class=\"header2\">$playlist->name</span><br />";
- echo "&nbsp;&nbsp;&nbsp;" . _("owned by") . " $pluser->fullname ($pluser->username)<br />";
- echo "<ul>";
- if ($pluser->username == $user->username || $user->access === 'admin') {
- echo "<li><a href=\"" . conf('web_path') . "/playlist.php?action=edit&amp;playlist_id=$playlist->id\">" . _("Edit Playlist") . "</a></li>\n";
- }
- if (count($playlist->get_songs()) > 0) {
- echo "<li><a href=\"" . conf('web_path') . "/song.php?action=m3u&amp;playlist_id=$playlist->id\">" . _("Play Full Playlist") . "</a></li>\n";
- echo "<li><a href=\"" . conf('web_path') . "/song.php?action=random&amp;playlist_id=$playlist->id\">" . _("Play Random") . "</a></li>\n";
- }
- echo "</ul>";
- echo "</div>";
-}
-
-
-switch($action) {
- // Add to a playlist
- case 'Add to':
case 'add_to':
- if ($playlist_id == 0) {
- // Creating a new playlist
- $playlist_name = _("New Playlist") . " - " . date("m/j/y, g:i a");
- $playlist->create_playlist($playlist_name, $user->username, 'private');
+ case 'add to':
+ /* Check to make sure they've got rights */
+ if (!$GLOBALS['user']->has_access(25)) {
+ access_denied();
+ break;
+ }
+ /* If we don't already have a playlist */
+ if (!$playlist->id) {
+ $playlist_name = _('New Playlist') . " - " . date('m/j/y, g:i a');
+ $id = $playlist->create($playlist_name, 'private');
+ $playlist = new Playlist($id);
}
- if ($type === 'album') {
- if ($song_ids = get_songs_from_type($type, $song_ids, $artist_id)) {
- $playlist->add_songs($song_ids);
- }
+ /* Must be admin or person who created this playlist */
+ if ($GLOBALS['user']->username != $playlist->user && !$GLOBALS['user']->has_access(100)) {
+ access_denied();
}
- else {
- if (isset($song_ids) && is_array($song_ids)) {
- $playlist->add_songs($song_ids);
- }
- }
- show_playlist($playlist->id);
- break;
- case 'Create':
- $playlist->create_playlist($playlist_name, $user->username, $type);
- show_playlists();
- break;
-
- case 'delete_playlist':
- if ($_REQUEST['confirm'] === 'Yes') {
-
- $playlist->playlist($_REQUEST['playlist_id']);
- $playlist->delete();
- show_confirmation("Playlist Deleted","The $playlist->name Playlist has been deleted","playlist.php");
- }
- elseif ($_REQUEST['confirm'] === 'No') {
- show_songs($playlist->get_songs(), $_REQUEST['playlist_id']);
+ if ($_REQUEST['type'] == 'album') {
+ $song_ids = get_songs_from_type($_REQUEST['type'],$_REQUEST['song_ids'],$_REQUEST['artist_id']);
}
- else {
- show_confirm_action("Are you sure you want to delete '$playlist->name' playlist?",
- "playlist.php",
- "action=delete_playlist&amp;playlist_id=$playlist_id");
- }
- break;
+ else {
+ $song_ids = $_REQUEST['song_ids'];
+ }
+
+ /* Add the songs */
+ $playlist->add_songs($song_ids);
+
+ /* Show the Playlist */
+ show_playlist($playlist);
+ break;
+ case 'create_playlist':
+ case 'create':
+ /* Check rights */
+ if (!$GLOBALS['user']->has_access(25)) {
+ access_denied();
+ break;
+ }
+
+ $playlist_name = scrub_in($_REQUEST['playlist_name']);
+ $playlist_type = scrub_in($_REQUEST['type']);
+ $playlist->create($playlist_name,$playlist_type);
+ show_confirmation(_('Playlist Created'),$playlist_name . ' (' . $playlist_type . ') ' . _(' has been created'),'playlist.php');
+ break;
case 'edit':
- case 'Edit':
- show_playlist_edit($playlist);
- break;
+ show_playlist_edit($playlist);
+ break;
case 'new':
show_playlist_create();
- break;
-
+ break;
case 'remove_song':
- case 'Remove Selected Tracks':
- $playlist->remove_songs($song_ids);
- show_songs($playlist->get_songs(), $playlist_id);
- break;
-
- case 'Update':
- $playlist->update_type($type);
- $playlist->update_name($new_playlist_name);
- echo _("Playlist updated.");
- break;
+ case _('Remote Selected Tracks'):
+ /* Check em for rights */
+ if (!$GLOBALS['user']->has_access(100) && $GLOBALS['user']->username != $playlist->user) {
+ access_denied();
+ break;
+ }
+ $playlist->remove_songs($_REQUEST['song_ids']);
+ show_playlist($playlist);
+ break;
+ case 'update':
+ /* Make sure they've got thems rights */
+ if (!$GLOBALS['user']->has_access(100) && $GLOBALS['user']->username != $playlist->user) {
+ access_denied();
+ break;
+ }
- case 'Update Selected':
- pl_update_selected();
- break;
- case 'import_playlist':
- $filename = scrub_in($_REQUEST['filename']);
- $catalog = new Catalog();
- if ($catalog->import_m3u($filename)) {
- show_confirmation($_REQUEST['playlist_type'] . " Imported",$filename . " was imported as a playlist","playlist.php");
- } // it worked
- else {
- show_confirmation("Import Failure",$filename . " failed to import correctly, this can be because the file wasn't found or no songs were matched","playlist.php");
- } // it didnt' work
- break;
- case 'view_list':
- case 'view':
- case 'View':
- show_playlist($playlist->id);
- break;
+ $playlist->update_type($_REQUEST['type']);
+ $playlist->update_name($_REQUEST['new_playlist_name']);
+ show_confirmation(_('Playlist Updated'),$playlist_name . ' (' . $playlist_type . ') ' . _(' has been updated'),'playlist.php?action=show_playlist&amp;playlist_id=' . $playlist->id);
+ break;
+ //FIXME: WTF Mate?
+ case _('Update Selected'):
+
+ break;
+ case 'show_playlist':
+ show_playlist($playlist);
+ break;
case 'show_import_playlist':
- $playlist->show_import();
- break;
+ show_import_playlist();
+ break;
case 'set_track_numbers':
- case 'Set Track Numbers':
- $song_ids = scrub_in($_REQUEST['song']);
- foreach ($song_ids as $song_id) {
- $track = scrub_in($_REQUEST['tr_' . $song_id]);
- $changes[] = array('song_id' => $song_id, 'track' => $track);
+ /* Make sure they have permission */
+ if (!$GLOBALS['user']->has_access(100) && $GLOBALS['user']->username != $playlist->user) {
+ access_denied();
+ break;
}
+ $song_ids = scrub_in($_REQUEST['song']);
+ foreach ($song_ids as $song_id) {
+ $track = scrub_in($_REQUEST['tr_' . $song_id]);
+ $changes[] = array('song_id' => $song_id, 'track' => $track);
+ }
- $playlist->update_track_numbers($changes);
- show_playlist($playlist->id);
- break;
+ $playlist->update_track_numbers($changes);
+ show_playlist($playlist);
+ break;
default:
show_playlists();
+ break;
+} // switch on the action
-} //switch on action
-
-show_footer();
-
-/* Function definitions for this file */
-/* GET THIS OUTTA HERE!!!! FIXME */
-/*************************/
-function pl_update_selected() {
-
- $username = scrub_in($_SESSION['userdata']['id']);
- if ($user->has_access(100)) {
- // we have to update the current numbers for the artist these were
- // for and who they will become
- $artists_to_update = array();
- $artists_to_update[] = $artist;
-
- while ( list($index, $s) = each($song) ) {
- $info = get_song_info($s);
- $artists_to_update[] = $info->artist;
-
- if ( $update_artist ) {
- $info->artist = $artist;
- }
-
- if ( $update_album ) {
- $info->album = $album;
- }
-
- if ( $update_genre ) {
- $info->genre = $genre;
- }
-
- // now just update the song in the db and you're good to go
- update_song($info->id, $info->title,
- $info->artist, $info->album, $info->genre);
-
- // let's update the local file (if we can)
- if ( is_writable($info->file) ) {
- $id3 = new id3( $info->file );
- $id3->artists = get_artist_name($info->artist);
- $id3->album = get_album_name($info->album);
- $genre_info = get_genre($info->genre);
- $id3->genre = $genre_info->name;
- $id3->genreno = $genre_info->id;
- $id3->write();
- }
- }
-
- $artists_to_update = array_unique($artists_to_update);
-
- foreach ($artists_to_update as $art) {
- update_artist_info($art);
- }
-
- header("Location:" . $HTTP_REFERER );
- }//admin access
- else {
- header("Location:" . conf('web_path') . "/index.php?access=denied" );
- }
-} //function pl_update_selected
+show_footer();
?>
diff --git a/song.php b/song.php
index 2a88a523..43758d44 100644
--- a/song.php
+++ b/song.php
@@ -1,7 +1,7 @@
<?php
/*
- Copyright (c) 2001 - 2005 ampache.org
+ Copyright (c) 2001 - 2006 ampache.org
All rights reserved.
This program is free software; you can redistribute it and/or
@@ -26,6 +26,7 @@
a bunch of id's.
Special thanx goes to Mike Payson and Jon Disnard for the means
to do this.
+ FIXME: don't get me started... :(
*/
require('modules/init.php');
@@ -64,9 +65,17 @@ switch ($action) {
$song_ids = $genre->get_random_songs();
$_REQUEST['action'] = 'm3u';
break;
+ case 'playlist':
+ $playlist = new Playlist($_REQUEST['playlist_id']);
+ $song_ids = $playlist->get_songs();
+ $_REQUEST['action'] = 'm3u';
+ case 'playlist_random':
+ $playlist = new Playlist($_REQUEST['playlist_id']);
+ $song_ids = $playlist->get_random_songs();
+ $_REQUEST['action'] = 'm3u';
+ break;
default:
break;
-
} // end action switch
if ($_REQUEST['album']) {
diff --git a/templates/show_import_playlist.inc.php b/templates/show_import_playlist.inc.php
index 3ea6c8fb..1b5b979b 100644
--- a/templates/show_import_playlist.inc.php
+++ b/templates/show_import_playlist.inc.php
@@ -1,7 +1,7 @@
<?php
/*
- Copyright (c) 2001 - 2005 Ampache.org
+ Copyright (c) 2001 - 2006 Ampache.org
All rights reserved.
This program is free software; you can redistribute it and/or
diff --git a/templates/show_playlists.php.inc b/templates/show_playlists.inc.php
index 9bb54c29..34667734 100644
--- a/templates/show_playlists.php.inc
+++ b/templates/show_playlists.inc.php
@@ -25,7 +25,7 @@
* /playlists.php $type is always passed
*/
?>
-<h3><?php echo $type; . ' ' . _('Playlists'); ?></h3>
+<h3><?php echo $type . ' ' . _('Playlists'); ?></h3>
<table class="tabledata" cellspacing="0" cellpadding="0" border="0">
<tr class="table-header">
<th><?php echo _('Playlist Name'); ?></th>
@@ -45,7 +45,7 @@
</a>
</td>
<td><?php echo $count; ?></td>
- <td><?php echo scrub_out($playlist_user->name); ?></td>
+ <td><?php echo scrub_out($playlist_user->fullname); ?></td>
<td>
| <a href="<?php echo conf('web_path'); ?>/playlist.php?action=show_playlist&amp;playlist_id=<?php echo $playlist->id; ?>">
<?php echo _('View'); ?>
diff --git a/templates/show_songs.inc b/templates/show_songs.inc
index e3d1cae5..21c69525 100644
--- a/templates/show_songs.inc
+++ b/templates/show_songs.inc
@@ -1,7 +1,7 @@
<?php
/*
- Copyright (c) 2001 - 2005 Ampache.org
+ Copyright (c) 2001 - 2006 Ampache.org
All rights reserved.
This program is free software; you can redistribute it and/or
@@ -21,38 +21,53 @@
*/
$web_path = conf('web_path');
-show_clear();
-
// Need to set the username for the song ratings.
-$username=$GLOBALS['user']->username;
+$username = $GLOBALS['user']->username;
+
+/* If it's a playlist and they've got rights */
+if (isset($playlist_id) && ($GLOBALS['user']->username == $playlist->user || $GLOBALS['user']->has_access('100'))) {
+ $tab = 1;
+ $playlist_owner = true;
+}
?>
-<form name="songs" method="post" enctype="multipart/form-data" action="#">
-<table border="0">
- <tr><td colspan="2">
- <table class="border" cellspacing="0" cellpadding="0" border="0">
- <tr class="table-header">
- <th>&nbsp;&nbsp;<a href="#" onclick="check_songs(); return false;">Select</a></th>
- <?php if (isset($playlist_id) && $playlist_id != 0 && ($user->username == $pluser->username || $user->has_access('100'))) { $tab = 1; ?> <th><?php echo _("Track"); ?></th> <?php } ?>
- <th><?php echo _("Song title"); ?></th>
- <th><?php echo _("Artist"); ?></th>
- <th><?php echo _("Album"); ?></th>
- <th><?php echo _("Track"); ?></th>
- <th><?php echo _("Time"); ?></th>
- <th><?php echo _("Size"); ?></th>
- <th><?php echo _("Bitrate"); ?></th>
- <th><?php echo _("Genre"); ?></th>
- <th><?php echo _("Flag"); ?></th>
- <th><?php echo _("Action"); ?></th>
- <?php if (conf('ratings') || conf('ratings')=="false") { ?>
- <th><?php echo _("Rating"); ?></th>
- <? } ?>
- </tr>
- <?php
- /* FIXME: don't even get me started with how many things are wrong with this code */
+<form name="songs" method="post" enctype="multipart/form-data" action="#" style="Display:inline;">
+<table class="border" cellspacing="0" cellpadding="0" border="0">
+<tr class="table-header">
+ <th>&nbsp;&nbsp;<a href="#" onclick="check_songs(); return false;">Select</a></th>
+ <?php if ($playlist_owner) { ?>
+ <th><?php echo _("Track"); ?></th>
+ <?php } ?>
+ <th><?php echo _("Song title"); ?></th>
+ <th><?php echo _("Artist"); ?></th>
+ <th><?php echo _("Album"); ?></th>
+ <th><?php echo _("Track"); ?></th>
+ <th><?php echo _("Time"); ?></th>
+ <th><?php echo _("Size"); ?></th>
+ <th><?php echo _("Bitrate"); ?></th>
+ <th><?php echo _("Genre"); ?></th>
+ <th><?php echo _("Flag"); ?></th>
+ <th><?php echo _("Action"); ?></th>
+ <?php if (conf('ratings') || conf('ratings')=="false") { ?>
+ <th><?php echo _("Rating"); ?></th>
+ <? } ?>
+</tr>
+<?php
+ /* FIXME: don't even get me started with how many things are wrong with this code */
foreach ($song_ids as $song_id) {
-
- if (!is_object($song_id)) {
+
+ /* Arr matey crapy code abounds! */
+ if ($playlist_owner) {
+ if ($song_id['song']) {
+ $song = new Song($song_id['song']);
+ }
+ else {
+ $song = new Song();
+ $song->title = 'Dynamic Song';
+ }
+ $song_id = $song_id['id'];
+ } // end if playlist
+ elseif (!is_object($song_id)) {
unset($text_class);
$song = new Song($song_id);
}
@@ -60,16 +75,18 @@ $username=$GLOBALS['user']->username;
$song = $song_id;
}
+
$song->format_song();
- // Still needed crap
- $totalsize += $song->size;
- $totaltime += $song->time;
- if ($song->status == "disabled") { $text_class = "class=\"disabled\""; }
- ?>
- <tr class="<?php echo flip_class(); ?>">
- <td align="center">
- <input type="checkbox" name="song[]" value="<?php echo $song->id; ?>" id="song_<?php echo $song->id; ?>" />
- </td>
+ // Still needed crap
+ $totalsize += $song->size;
+ $totaltime += $song->time;
+ /* If it's disabled */
+ if ($song->status == "disabled") { $text_class = "class=\"disabled\""; }
+?>
+<tr class="<?php echo flip_class(); ?>">
+ <td align="center">
+ <input type="checkbox" name="song[]" value="<?php echo $song->id; ?>" id="song_<?php echo $song->id; ?>" />
+ </td>
<?php
if (isset($playlist_id) && $playlist_id != 0 && ($user->username == $pluser->username || $user->has_access('100'))) {
$tracknum = get_playlist_track_from_song($playlist_id, $song->id);
@@ -158,8 +175,6 @@ $username=$GLOBALS['user']->username;
<td colspan="2"></td>
</tr>
</table>
-</td></tr>
-</table>
<br />
<?php show_play_selected(); ?>
</form>