diff options
author | Karl 'vollmerk' Vollmer <vollmer@ampache.org> | 2007-12-31 03:20:29 +0000 |
---|---|---|
committer | Karl 'vollmerk' Vollmer <vollmer@ampache.org> | 2007-12-31 03:20:29 +0000 |
commit | 748e50ade1b0c7034eddaadbe2285e5bf3a20fc6 (patch) | |
tree | 759b02a66ea840abc91419c9d7d00a08b2fceb8c /lib | |
parent | 4e716204e84fc7546372bdae79121e47b92412bc (diff) | |
download | ampache-748e50ade1b0c7034eddaadbe2285e5bf3a20fc6.tar.gz ampache-748e50ade1b0c7034eddaadbe2285e5bf3a20fc6.tar.bz2 ampache-748e50ade1b0c7034eddaadbe2285e5bf3a20fc6.zip |
added ability to do add new on other elements of song edit (Thx picasso) added export catalog to csv
Diffstat (limited to 'lib')
-rw-r--r-- | lib/class/catalog.class.php | 88 | ||||
-rw-r--r-- | lib/class/song.class.php | 13 | ||||
-rw-r--r-- | lib/javascript-base.js | 9 | ||||
-rw-r--r-- | lib/ui.lib.php | 51 |
4 files changed, 93 insertions, 68 deletions
diff --git a/lib/class/catalog.class.php b/lib/class/catalog.class.php index 0320c1d6..fffcb302 100644 --- a/lib/class/catalog.class.php +++ b/lib/class/catalog.class.php @@ -2362,11 +2362,11 @@ class Catalog { } // remove_songs - /*! - @function exports the catalog - @discussion it exports all songs in the database to the given export type. - */ - function export($type){ + /** + * exports the catalog + * it exports all songs in the database to the given export type. + */ + public function export($type) { // Select all songs in catalog if($this->id) { @@ -2375,43 +2375,49 @@ class Catalog { $sql = "SELECT id FROM song ORDER BY album,track"; } $db_results = Dba::query($sql); - - if ($type=="itunes"){ - - echo xml_get_header('itunes'); - - while ($results = Dba::fetch_assoc($db_results)) { - $song = new Song($results['id']); - $song->format(); - - $xml = array(); - $xml['key']= $results['id']; - $xml['dict']['Track ID']= intval($results['id']); - $xml['dict']['Name'] = $song->title; - $xml['dict']['Artist'] = $song->f_artist_full; - $xml['dict']['Album'] = $song->f_album_full; - $xml['dict']['Genre'] = $song->f_genre; - $xml['dict']['Total Time'] = intval($song->time) * 1000; // iTunes uses milliseconds - $xml['dict']['Track Number'] = intval($song->track); - $xml['dict']['Year'] = intval($song->year); - $xml['dict']['Date Added'] = date("Y-m-d\TH:i:s\Z",$song->addition_time); - $xml['dict']['Bit Rate'] = intval($song->bitrate/1000); - $xml['dict']['Sample Rate'] = intval($song->rate); - $xml['dict']['Play Count'] = intval($song->played); - $xml['dict']['Track Type'] = "URL"; - $xml['dict']['Location'] = $song->get_url(); - - echo xml_from_array($xml,1,'itunes'); - - // flush output buffer - ob_flush(); - flush(); - } // while result - - echo xml_get_footer('itunes'); - - } // itunes + switch ($type) { + case 'itunes': + echo xml_get_header('itunes'); + + while ($results = Dba::fetch_assoc($db_results)) { + $song = new Song($results['id']); + $song->format(); + + $xml = array(); + $xml['key']= $results['id']; + $xml['dict']['Track ID']= intval($results['id']); + $xml['dict']['Name'] = $song->title; + $xml['dict']['Artist'] = $song->f_artist_full; + $xml['dict']['Album'] = $song->f_album_full; + $xml['dict']['Genre'] = $song->f_genre; + $xml['dict']['Total Time'] = intval($song->time) * 1000; // iTunes uses milliseconds + $xml['dict']['Track Number'] = intval($song->track); + $xml['dict']['Year'] = intval($song->year); + $xml['dict']['Date Added'] = date("Y-m-d\TH:i:s\Z",$song->addition_time); + $xml['dict']['Bit Rate'] = intval($song->bitrate/1000); + $xml['dict']['Sample Rate'] = intval($song->rate); + $xml['dict']['Play Count'] = intval($song->played); + $xml['dict']['Track Type'] = "URL"; + $xml['dict']['Location'] = $song->get_url(); + echo xml_from_array($xml,1,'itunes'); + // flush output buffer + } // while result + echo xml_get_footer('itunes'); + + break; + case 'csv': + echo "ID,Title,Artist,Album,Genre,Length,Track,Year,Date Added,Bitrate,Played,File\n"; + while ($results = Dba::fetch_assoc($db_results)) { + $song = new Song($results['id']); + $song->format(); + echo '"' . $song->id . '","' . $song->title . '","' . $song->artist_full . '","' . $song->album_full . + '","' . $song->f_genre . '","' . $song->f_time . '","' . $song->f_track . '","' . $song->year . + '","' . date("Y-m-d\TH:i:s\Z",$song->addition_time) . '","' . $song->f_bitrate . + '","' . $song->played . '","' . $song->file . "\n"; + } + break; + } // end switch } // export diff --git a/lib/class/song.class.php b/lib/class/song.class.php index 19c5c0cf..62054464 100644 --- a/lib/class/song.class.php +++ b/lib/class/song.class.php @@ -395,9 +395,6 @@ class Song { foreach ($data as $key=>$value) { switch ($key) { case 'title': - #case 'album': - case 'artist': - case 'genre': case 'track': // Check to see if it needs to be updated if ($value != $this->$key) { @@ -407,14 +404,18 @@ class Song { $updated = 1; } break; + case 'artist': case 'album': + case 'genre': if ($value != $this->$key) { if ($value == -1) { - // Add new album based on album_name - $value = Catalog::check_album($data['album_name']); + // Add new data + $fn = "check_$key"; + $value = Catalog::$fn($data["{$key}_name"]); } if ($value) { - self::update_album($value, $this->id); + $fn = "update_$key"; + self::$fn($value, $this->id); $this->$key = $value; $updated = 1; } diff --git a/lib/javascript-base.js b/lib/javascript-base.js index b6000238..a89f06d7 100644 --- a/lib/javascript-base.js +++ b/lib/javascript-base.js @@ -76,12 +76,11 @@ function popup_art(url) { if (window.focus) {newwindow.focus()} } -// In-line album editing helper function -function checkAlbum(song) { - if ($('album_select_'+song).options[$('album_select_'+song).selectedIndex].value == -1) { - $('album_select_song_'+song).innerHTML = '<input type="textbox" name="album_name" value="New Album" />'; +function check_inline_song_edit(type, song) { + if ($(type+'_select_'+song).options[$(type+'_select_'+song).selectedIndex].value == -1) { + $(type+'_select_song_'+song).innerHTML = '<input type="textbox" name="'+type+'_name" value="New '+type+'" />'; } else { - $('album_select_song_'+song).innerHTML = ''; + $(type+'_select_song_'+song).innerHTML = ''; } } diff --git a/lib/ui.lib.php b/lib/ui.lib.php index 691e8f7d..b27124fc 100644 --- a/lib/ui.lib.php +++ b/lib/ui.lib.php @@ -614,18 +614,13 @@ function show_playlist_import() { * by the Edit page, it takes a $name and a $album_id */ function show_album_select($name='album',$album_id=0,$allow_add=0,$song_id=0) { - // Probably superfluous code to ensure we never generate two album_select - // elements with the same ID on the same page. - static $id_inc; - static $keys; - if (!isset($keys)) $keys = array(); - if (!isset($id_inc)) $id_inc = 1; - else $id_inc++; - $key = "album_select_$song_id"; - if (!empty($keys[$key])) $key = "album_select_$name"; - if (!empty($keys[$key])) $key = "album_select_x$id_inc"; - if (!empty($keys[$key])) $key = "album_select_{$name}_x{$id_inc}"; - $keys[$key] = true; + // Generate key to use for HTML element ID + static $id_cnt; + if ($song_id) { + $key = "album_select_$song_id"; + } else { + $key = "album_select_c" . ++$id_cnt; + } // Added ID field so we can easily observe this element echo "<select name=\"$name\" id=\"$key\">\n"; @@ -657,9 +652,16 @@ function show_album_select($name='album',$album_id=0,$allow_add=0,$song_id=0) { * show_artist_select * This is the same as the album select except it's *gasp* for artists how inventive! */ -function show_artist_select($name='artist', $artist_id=0) { +function show_artist_select($name='artist', $artist_id=0, $allow_add=0, $song_id=0) { + // Generate key to use for HTML element ID + static $id_cnt; + if ($song_id) { + $key = "artist_select_$song_id"; + } else { + $key = "artist_select_c" . ++$id_cnt; + } - echo "<select name=\"$name\">\n"; + echo "<select name=\"$name\" id=\"$key\">\n"; $sql = "SELECT `id`, `name`, `prefix` FROM `artist` ORDER BY `name`"; $db_results = Dba::query($sql); @@ -675,6 +677,11 @@ function show_artist_select($name='artist', $artist_id=0) { } // end while + if ($allow_add) { + // Append additional option to the end with value=-1 + echo "\t<option value=\"-1\">Add New...</option>\n"; + } + echo "</select>\n"; } // show_artist_select @@ -684,13 +691,20 @@ function show_artist_select($name='artist', $artist_id=0) { * It's amazing we have three of these funtions now, this one shows a select of genres and take s name * and a selected genre... Woot! */ -function show_genre_select($name='genre',$genre_id=0,$size='') { +function show_genre_select($name='genre',$genre_id=1,$size='', $allow_add=0, $song_id=0) { + // Generate key to use for HTML element ID + static $id_cnt; + if ($song_id) { + $key = "genre_select_$song_id"; + } else { + $key = "genre_select_c" . ++$id_cnt; + } if ($size > 0) { $multiple_txt = " multiple=\"multiple\" size=\"$size\""; } - echo "<select name=\"$name\"$multiple_txt>\n"; + echo "<select name=\"$name\"$multiple_txt id=\"$key\">\n"; $sql = "SELECT `id`, `name` FROM `genre` ORDER BY `name`"; $db_results = Dba::query($sql); @@ -706,6 +720,11 @@ function show_genre_select($name='genre',$genre_id=0,$size='') { } // end while + if ($allow_add) { + // Append additional option to the end with value=-1 + echo "\t<option value=\"-1\">Add New...</option>\n"; + } + echo "</select>\n"; } // show_genre_select |