summaryrefslogtreecommitdiffstats
path: root/albums.php
blob: 051485a118d6a32c9c29c0581f9928da0f5f4171 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
<?php
/*

 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.

*/

/*

 Do most of the dirty work of displaying the mp3 catalog

*/

require_once("modules/init.php");

// We'll set any input parameters here
if(!isset($_REQUEST['match'])) { $_REQUEST['match'] = "Browse"; }
if(isset($_REQUEST['match'])) $match = scrub_in($_REQUEST['match']);
if(isset($_REQUEST['album'])) $album = scrub_in($_REQUEST['album']);
if(isset($_REQUEST['artist'])) $artist = scrub_in($_REQUEST['artist']);
$_REQUEST['artist_id'] = scrub_in($_REQUEST['artist_id']);

show_template('header');
show_menu_items('Browse');
show_browse_menu('Albums');
show_clear();

if ($_REQUEST['action'] === 'clear_art') { 
	if (!$user->has_access('25')) { access_denied(); } 
	$album = new Album($_REQUEST['album_id']);
	$album->clear_art();
	show_confirmation(_("Album Art Cleared"),_("Album Art information has been removed form the database"),"/albums.php?action=show&amp;album=" . $album->id);

} // clear_art
// if we have album
elseif (isset($album)) { 
	$album = new Album($album);
	$album->format_album();

	$artist_obj = new Artist($artist_obj);

	require (conf('prefix') . "/templates/show_album.inc");
	
	if (isset($artist) && $artist_obj->name == "Unknown (Orphaned)" ) {
		$song_ids = get_song_ids_from_artist_and_album($artist, $album->id);
	}
	else {
		$song_ids = get_song_ids_from_album($album->id);
	}
	show_songs($song_ids,0,$album);
} // isset(album)

// Finds the Album art from amazon
elseif ($_REQUEST['action'] === 'find_art') {

	if (!$user->has_access('25')) { access_denied(); }

	/* Echo notice if no amazon token is found, but it's enabled */
	if (in_array('amazon',conf('album_art_order')) AND !conf('amazon_developer_key')) { 
		echo "<br /><div class=\"fatalerror\">Error: No Amazon Developer Key set, amazon album art searching will not work</div>";
	}

        $album = new Album($_REQUEST['album_id']);
	$result = $album->find_art($_REQUEST['cover']);
	if ($result) {
		show_confirmation(_("Album Art Located"),_("Album Art information has been located in Amazon. If incorrect, click \"Reset Album Art\" below to remove the artwork."),"/albums.php?action=show&amp;album=" . $album->id);
		echo "&nbsp;[ <a href=\"" . conf('web_path') . "/albums.php?action=clear_art&amp;album_id=" . $album->id . "\">Reset Album Art</a> ]";
		echo "<p align=left><img src=\"" . conf('web_path') . "/albumart.php?id=" . $album->id . "\" /></p>";
		echo "<form name=\"coverart\" method=\"get\" action=\"".$_SERVER['PHP_SELF']."\">";
		echo "Enter URL to album art ";
		echo "<input type=\"text\" size=\"40\" id=\"cover\" name=\"cover\" value=\"\" />\n";
		echo "<input type=\"hidden\" name=\"action\" value=\"find_art\" />\n";
		echo "<input type=\"hidden\" name=\"album_id\" value=\"$album->id\" />\n";
		echo "<input type=\"submit\" value=\"" . _("Get Art") . "\" />\n";
		echo "</form>"; 
	}
        else {
                show_confirmation(_("Album Art Not Located"),_("Album Art could not be located at this time. This may be due to Amazon being busy, or the album not being present in their collection."),"/albums.php?action=show&amp;album=" . $album->id);
                echo "<form name=\"coverart\" method=\"get\" action=\"".$_SERVER['PHP_SELF']."\">";
                echo "Enter URL to album art ";
                echo "<input type=\"text\" size=\"40\" id=\"cover\" name=\"cover\" value=\"\" />";
                echo "<input type=\"hidden\" name=\"action\" value=\"find_art\" />";
                echo "<input type=\"hidden\" name=\"album_id\" value=\"$album->id\" />&nbsp;&nbsp;&nbsp;";
		echo "<input type=\"submit\" value=\"" . _("Get Art") . "\" />\n";
                echo "</form>";
	}
} // find_art 

// Updates Album from tags
elseif ($_REQUEST['action'] === 'update_from_tags') {

	$album = new Album($_REQUEST['album_id']);

	echo "<br /><b>" . _("Starting Update from Tags") . ". . .</b><br />\n";

	$catalog = new Catalog();
	$catalog->update_single_item('album',$_REQUEST['album_id']);

	echo "<br /><b>" . _("Update From Tags Complete") . "</b> &nbsp;&nbsp;";
	echo "<a href=\"" . conf('web_path') . "/albums.php?action=show&amp;album=" . $_REQUEST['album_id'] . "\">[" . _("Return") . "]</a>";

} // update_from_tags

else {

	if (strlen($_REQUEST['match']) < '1') { $match = 'none'; }

	// Setup the View Ojbect
        $view = new View();
        $view->import_session_view();

	switch($match) {
		case 'Show_all':
			show_alphabet_list('albums','albums.php','show_all');
			show_alphabet_form('',_("Show Albums starting with"),"albums.php?action=match");
			$offset_limit = 99999;
			$sql = "SELECT id FROM album";
			break;
                case 'Show_missing_art':
                        show_alphabet_list('albums','albums.php','show_missing_art');
			show_alphabet_form('',_("Show Albums starting with"),"albums.php?action=match");
                        $offset_limit = 99999;
                        $sql = "SELECT id FROM album where art is null";
                        break; 
		case 'Browse':
		case 'show_albums':
			show_alphabet_list('albums','albums.php','browse');
			show_alphabet_form('',_("Show Albums starting with"),"albums.php?action=match");
			$sql = "SELECT id FROM album";
			break;
		case 'none':
			show_alphabet_list('albums','albums.php','a');
			show_alphabet_form('',_("Show Albums starting with"),"albums.php?action=match");
			$sql = "SELECT id FROM album WHERE name LIKE 'a%'";
			break;
		default:
			show_alphabet_list('albums','albums.php',$match);
			show_alphabet_form($match,_("Show Albums starting with"),"albums.php?action=match");
			echo "<br /><br />";
			$sql = "SELECT id FROM album WHERE name LIKE '$match%'";
	} // end switch

	// if we are returning
	if ($_REQUEST['keep_view']) { 
                $view->initialize();
	}

	// If we aren't keeping the view then initlize it
	elseif ($sql) {
		$db_results = mysql_query($sql, dbh());
		$total_items = mysql_num_rows($db_results);
		if ($match != "Show_all") { $offset_limit = $_SESSION['userdata']['offset_limit']; }
		$view = new View($sql, 'albums.php','name',$total_items,$offset_limit);	
	} 

	else { $view = false; }

	if ($view->base_sql) { 
		$albums = get_albums($view->sql);
		show_albums($albums,$view);	
	}

} // else no album

show_clear();
show_page_footer ('Albums', '',$user->prefs['display_menu']);
?>