diff options
-rw-r--r-- | lib/class/playlist.class.php | 44 | ||||
-rw-r--r-- | server/ajax.server.php | 4 | ||||
-rw-r--r-- | server/playlist.ajax.php | 49 | ||||
-rw-r--r-- | templates/show_playlist_song_row.inc.php | 3 | ||||
-rw-r--r-- | templates/show_playlist_songs.inc.php | 4 |
5 files changed, 87 insertions, 17 deletions
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 @@ -85,6 +85,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 @@ +<?php +/* + + Copyright (c) 2001 - 2007 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 v2 + as published by the Free Software Foundation. + + 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. + +*/ + +/** + * Sub-Ajax page, requires AJAX_INCLUDE as one + */ +if (AJAX_INCLUDE != '1') { exit; } + +switch ($_REQUEST['action']) { + case 'delete_track': + // Create the object and remove the track + $playlist = new Playlist($_REQUEST['playlist_id']); + $playlist->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 @@ <?php echo get_user_icon('download',_('Download')); ?> </a> <?php } ?> + <?php if ($playlist->has_access()) { ?> + <?php echo Ajax::button('?page=playlist&action=delete_track&playlist_id=' . $playlist->id . '&track=' . $object['track_id'],'delete',_('Delete'),'track_del_' . $object['track_id']); ?> + <?php } ?> </td> 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'); </tr> <tr class="table-header"> <th><?php echo _('Track'); ?></th> - <th onclick="ajaxPut('<?php echo $ajax_url; ?>?action=browse&sort=title');return true;" style="cursor:pointer;"> - <?php echo _('Song Title'); ?> - </th> + <th><?php echo _('Song Title'); ?></th> <th><?php echo _('Artist'); ?></th> <th><?php echo _('Album'); ?></th> <th><?php echo _('Genre'); ?></th> |