summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKarl 'vollmerk' Vollmer <vollmer@ampache.org>2007-12-31 03:20:29 +0000
committerKarl 'vollmerk' Vollmer <vollmer@ampache.org>2007-12-31 03:20:29 +0000
commit748e50ade1b0c7034eddaadbe2285e5bf3a20fc6 (patch)
tree759b02a66ea840abc91419c9d7d00a08b2fceb8c
parent4e716204e84fc7546372bdae79121e47b92412bc (diff)
downloadampache-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
-rw-r--r--admin/export.php31
-rwxr-xr-xdocs/CHANGELOG4
-rw-r--r--lib/class/catalog.class.php88
-rw-r--r--lib/class/song.class.php13
-rw-r--r--lib/javascript-base.js9
-rw-r--r--lib/ui.lib.php51
-rw-r--r--templates/show_edit_song_row.inc.php10
-rw-r--r--templates/show_export.inc.php25
-rw-r--r--templates/sidebar_admin.inc.php2
-rw-r--r--themes/classic/templates/default.css4
-rw-r--r--themes/greysme/templates/default.css4
11 files changed, 152 insertions, 89 deletions
diff --git a/admin/export.php b/admin/export.php
index f5301643..1b9ce4ed 100644
--- a/admin/export.php
+++ b/admin/export.php
@@ -26,6 +26,8 @@ if (!Access::check('interface','100')) {
exit;
}
+show_header();
+
/* Switch on Action */
switch ($_REQUEST['action']) {
case 'export':
@@ -35,22 +37,35 @@ switch ($_REQUEST['action']) {
$catalog = new Catalog($_REQUEST['export_catalog']);
+ // Clear everything we've done so far
+ ob_end_clean();
+ ob_start();
header("Content-Transfer-Encoding: binary");
header("Cache-control: public");
+ $date = date("d/m/Y",time());
+
switch($_REQUEST['export_format']) {
- case 'itunes':
- header("Content-Type: application/itunes+xml; charset=utf-8");
- header("Content-Disposition: attachment; filename=\"itunes.xml\"");
- $catalog->export('itunes');
- break;
- }
+ case 'itunes':
+ header("Content-Type: application/itunes+xml; charset=utf-8");
+ header("Content-Disposition: attachment; filename=\"ampache-itunes-$date.xml\"");
+ $catalog->export('itunes');
+ break;
+ case 'csv':
+ header("Content-Type: application/vnd.ms-excel");
+ header("Content-Disposition: filename=\"ampache-export-$date.csv\"");
+ $catalog->export('csv');
+ break;
+ } // end switch on format
+
+ // We don't want the footer so we're done here
+ exit;
break;
default:
- show_header();
require_once Config::get('prefix') . '/templates/show_export.inc.php';
- show_footer();
break;
} // end switch on action
+
+show_footer();
?>
diff --git a/docs/CHANGELOG b/docs/CHANGELOG
index d717be3b..bb4fb0ae 100755
--- a/docs/CHANGELOG
+++ b/docs/CHANGELOG
@@ -4,6 +4,8 @@
--------------------------------------------------------------------------
v.3.4-Beta2
+ - Added Export Catalog to CSV
+ - Added 'Add New...' option to other fields on Song Edit (Thx picasso)
- Fixed incorrect index on localplay playlist after track deletion
- Fixed lack of high-light of current playing item on localplay
playlist
@@ -14,7 +16,7 @@
- Fixed downsample remote so that is downsamples those not in the
network def rather then those inside the network def
- Fixed issue with page-a-nation on show catalogs page
- - Fixed removal of rating from db when 'unrating' the object
+ - Fixed removal of rating from db when 'unrating' the object (Thx flashk)
- Fixed Itunes Export (Thx flashk)
- Fixed session start failure when use_auth is off and you have
no pre-existing cookie
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
diff --git a/templates/show_edit_song_row.inc.php b/templates/show_edit_song_row.inc.php
index dcd41750..cbab7739 100644
--- a/templates/show_edit_song_row.inc.php
+++ b/templates/show_edit_song_row.inc.php
@@ -26,15 +26,19 @@
<input type="textbox" name="name" value="<?php echo scrub_out($song->title); ?>" />
</td>
<td>
- <?php show_artist_select('artist',$song->artist); ?>
+ <?php show_artist_select('artist',$song->artist,true,$song->id); ?>
+ <div id="artist_select_song_<?php echo $song->id ?>"></div>
+<?php echo Ajax::observe('artist_select_'.$song->id,'change','check_inline_song_edit("artist", '.$song->id.')'); ?>
</td>
<td>
<?php show_album_select('album',$song->album,true,$song->id); ?>
<div id="album_select_song_<?php echo $song->id ?>"></div>
-<?php echo Ajax::observe('album_select_'.$song->id,'change','checkAlbum('.$song->id.')'); ?>
+<?php echo Ajax::observe('album_select_'.$song->id,'change','check_inline_song_edit("album", '.$song->id.')'); ?>
</td>
<td>
- <?php show_genre_select('genre',$song->genre); ?>
+ <?php show_genre_select('genre',$song->genre,'',true,$song->id); ?>
+ <div id="genre_select_song_<?php echo $song->id ?>"></div>
+<?php echo Ajax::observe('genre_select_'.$song->id,'change','check_inline_song_edit("genre", '.$song->id.')'); ?>
</td>
<td>
<input type="textbox" name="track" size="3" value="<?php echo scrub_out($song->track); ?>" />
diff --git a/templates/show_export.inc.php b/templates/show_export.inc.php
index eece02f2..16ffc716 100644
--- a/templates/show_export.inc.php
+++ b/templates/show_export.inc.php
@@ -19,20 +19,28 @@
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
+
+$name = 'export_' . $_REQUEST['export_format'];
+${$name} = ' selected="selected"';
+$name = 'catalog_' . $_REQUEST['export_catalog'];
+${$name} = ' selected="selected"';
+
show_box_top(_('Export Catalog')); ?>
<form name="duplicates" action="<?php echo Config::get('web_path'); ?>/admin/export.php?action=export" method="post" enctype="multipart/form-data" >
-<table cellspacing="0" cellpadding="3">
+<table class="tableform" cellspacing="0" cellpadding="3">
<tr>
<td valign="top"><strong><?php echo _('Catalog'); ?>:</strong></td>
<td>
- <select id="export_catalog" name="export_catalog" width="150" style="width: 150px">
- <option value="">(all)</option>
+ <select id="export_catalog" name="export_catalog">
+ <option value=""><?php echo _('All'); ?></option>
<?php
$catalog_ids = Catalog::get_catalogs();
- foreach ($catalog_ids as $cat_id) {
- $cat = new Catalog($cat_id);
+ foreach ($catalog_ids as $catalog_id) {
+ $catalog = new Catalog($catalog_id);
+ $current_name = 'catalog_' . $catalog->id;
+
?>
- <option value="<?php echo $cat->id; ?>" <?php if($_REQUEST['export_catalog']==$cat->id) echo "selected=\"selected\"" ?>><?php echo $cat->name; ?></option>
+ <option value="<?php echo $catalog->id; ?>"<?php echo ${$current_name}; ?>><?php echo scrub_out($catalog->name); ?></option>
<?php
}
?>
@@ -42,8 +50,9 @@ show_box_top(_('Export Catalog')); ?>
<tr>
<td valign="top"><strong><?php echo _('Format'); ?>:</strong></td>
<td>
- <select id="export_format" name="export_format" width="150" style="width: 150px">
- <option value="itunes" <?php if($_REQUEST['export_format']=='itunes') echo "selected=\"selected\"" ?>>iTunes</option>
+ <select id="export_format" name="export_format">
+ <option value="csv" <?php echo $export_csv; ?>>CSV</option>
+ <option value="itunes" <?php echo $export_itunes; ?>>iTunes</option>
</select>
</td>
</tr>
diff --git a/templates/sidebar_admin.inc.php b/templates/sidebar_admin.inc.php
index 0f0411ab..9ad1154e 100644
--- a/templates/sidebar_admin.inc.php
+++ b/templates/sidebar_admin.inc.php
@@ -24,8 +24,8 @@
<li id="sb_admin_ot_Mail"><a href="<?php echo $web_path; ?>/admin/mail.php"><?php echo _('Mail Users'); ?></a></li>
<li id="sb_admin_ot_ClearNowPlaying"><a href="<?php echo $web_path; ?>/admin/catalog.php?action=clear_now_playing"><?php echo _('Clear Now Playing'); ?></a></li>
<li id="sb_admin_ot_ClearCatStats"><a href="<?php echo $web_path; ?>/admin/catalog.php?action=clear_stats"><?php echo _('Clear Stats'); ?></a></li>
+ <li id="sb_admin_ot_ExportCatalog"><a href="<?php echo $web_path; ?>/admin/export.php"><?php echo _('Export Catalog'); ?></a></li>
<li id="sb_admin_ot_ManageFlagged"><a href="<?php echo $web_path; ?>/admin/flag.php"><?php echo _('Manage Flagged'); ?></a></li>
- <li id="sb_admin_ot_Export"><a href="<?php echo $web_path; ?>/admin/export.php"><?php echo _('Export'); ?></a></li>
<?php if (Config::get('shoutbox')) { ?>
<li id="sb_admin_ot_ManageShoutbox"><a href="<?php echo $web_path; ?>/shout.php?action=show_manage"><?php echo _('Manage Shoutbox'); ?></a></li>
<?php } ?>
diff --git a/themes/classic/templates/default.css b/themes/classic/templates/default.css
index e81a94f5..535889f7 100644
--- a/themes/classic/templates/default.css
+++ b/themes/classic/templates/default.css
@@ -505,6 +505,10 @@ a.button{padding:1px 3px;}
text-align:center;
}
+.tableform select {
+ width: 150px;
+}
+
/* table rows */
.odd, .odd td,
.even, .even td, .row-highlight {
diff --git a/themes/greysme/templates/default.css b/themes/greysme/templates/default.css
index 204c3dde..be2a3603 100644
--- a/themes/greysme/templates/default.css
+++ b/themes/greysme/templates/default.css
@@ -556,6 +556,10 @@ input[type=checkbox] { border:0;background:none; }
background-image:url(../images/sort_on.gif);
}
+.tableform select {
+ width: 150px;
+}
+
/* table rows */
.odd, .even, .row-highlight { background: url(../images/list_back.png) 0 50% repeat-x !important; background-image: none;}
.odd { background-color: #111 !important;}