From eeeece05dbbcee311d9909d73a3f0b7c9bcecad4 Mon Sep 17 00:00:00 2001 From: Karl 'vollmerk' Vollmer Date: Mon, 3 Sep 2007 06:26:44 +0000 Subject: added the ability to delete songs from a playlist, now if you could only add them --- lib/class/playlist.class.php | 44 +++++++++++++++++++--------- server/ajax.server.php | 4 +++ server/playlist.ajax.php | 49 ++++++++++++++++++++++++++++++++ templates/show_playlist_song_row.inc.php | 3 ++ templates/show_playlist_songs.inc.php | 4 +-- 5 files changed, 87 insertions(+), 17 deletions(-) create mode 100644 server/playlist.ajax.php diff --git a/lib/class/playlist.class.php b/lib/class/playlist.class.php index fcc7f028..0daff266 100644 --- a/lib/class/playlist.class.php +++ b/lib/class/playlist.class.php @@ -84,6 +84,24 @@ class Playlist { } // format + /** + * has_access + * This function returns true or false if the current user + * has access to this playlist + */ + public function has_access() { + + if ($this->user == $GLOBALS['user']->id) { + return true; + } + else { + return $GLOBALS['user']->has_access('100'); + } + + return false; + + } // has_access + /** * get_track * Takes a playlist_data.id and returns the current track value for said entry @@ -108,7 +126,7 @@ class Playlist { $results = array(); - $sql = "SELECT `object_id`,`object_type`,`dynamic_song`,`track` FROM `playlist_data` WHERE `playlist`='" . Dba::escape($this->id) . "' ORDER BY `track`"; + $sql = "SELECT `id`,`object_id`,`object_type`,`dynamic_song`,`track` FROM `playlist_data` WHERE `playlist`='" . Dba::escape($this->id) . "' ORDER BY `track`"; $db_results = Dba::query($sql); while ($row = Dba::fetch_assoc($db_results)) { @@ -117,7 +135,7 @@ class Playlist { // Do something here FIXME! } - $results[] = array('type'=>$row['object_type'],'object_id'=>$row['object_id'],'track'=>$row['track']); + $results[] = array('type'=>$row['object_type'],'object_id'=>$row['object_id'],'track'=>$row['track'],'track_id'=>$row['id']); } // end while return $results; @@ -437,22 +455,20 @@ class Playlist { } // check_type /** - * 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 + * delete_track + * this deletes a single track, you specify the playlist_data.id here */ - function remove_songs($data) { + public function delete_track($id) { - foreach ($data as $value) { - - $id = sql_escape($value); - - $sql = "DELETE FROM playlist_data WHERE id='$id'"; - $db_results = mysql_query($sql, dbh()); + $this_id = Dba::escape($this->id); + $id = Dba::escape($id); + + $sql = "DELETE FROM `playlist_data` WHERE `playlist_data`.`playlist`='$this_id' AND `playlist_data`.`id`='$id' LIMIT 1"; + $db_results = Dba::query($sql); - } // end foreach dead songs + return true; - } // remove_songs + } // delete_track /** * delete diff --git a/server/ajax.server.php b/server/ajax.server.php index 37b97a2e..9ea93b3c 100644 --- a/server/ajax.server.php +++ b/server/ajax.server.php @@ -49,6 +49,10 @@ switch ($_REQUEST['page']) { require_once Config::get('prefix') . '/server/random.ajax.php'; exit; break; + case 'playlist': + require_once Config::get('prefix') . '/server/playlist.ajax.php'; + exit; + break; default: // A taste of compatibility break; diff --git a/server/playlist.ajax.php b/server/playlist.ajax.php new file mode 100644 index 00000000..f2198faa --- /dev/null +++ b/server/playlist.ajax.php @@ -0,0 +1,49 @@ +format(); + if ($playlist->has_access()) { + $playlist->delete_track($_REQUEST['track']); + } + + $object_ids = $playlist->get_items(); + ob_start(); + require_once Config::get('prefix') . '/templates/show_playlist_songs.inc.php'; + $results['browse_content'] = ob_get_contents(); + ob_end_clean(); + break; + default: + $results['rfc3514'] = '0x1'; + break; +} // switch on action; + +// We always do this +echo xml_from_array($results); +?> diff --git a/templates/show_playlist_song_row.inc.php b/templates/show_playlist_song_row.inc.php index 354f8419..50af6dec 100644 --- a/templates/show_playlist_song_row.inc.php +++ b/templates/show_playlist_song_row.inc.php @@ -32,4 +32,7 @@ + has_access()) { ?> + id . '&track=' . $object['track_id'],'delete',_('Delete'),'track_del_' . $object['track_id']); ?> + diff --git a/templates/show_playlist_songs.inc.php b/templates/show_playlist_songs.inc.php index d1479a90..3e8918aa 100644 --- a/templates/show_playlist_songs.inc.php +++ b/templates/show_playlist_songs.inc.php @@ -31,9 +31,7 @@ $ajax_url = Config::get('ajax_url'); - - - + -- cgit