summaryrefslogtreecommitdiffstats
path: root/modules/lib.php
blob: 6e06d7f8818b54dc8a2a9667fbe75827dbb62cb0 (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
<?php
/*

 Copyright (c) 2004 ampache.org
 All rights reserved.

 All of the main functions for Ampache.
 FIXME: Remove this file... shouldn't be used anymore

*/

// This function makes baby vollmer cry, need to fix
//FIXME
function get_artist_info ($artist_id) {

	$dbh = dbh();

	$sql = "SELECT * FROM artist WHERE id = '$artist_id'";
	$db_result = mysql_query($sql, $dbh);
	if ($info = mysql_fetch_array($db_result)) {
		$sql = "SELECT COUNT(song.album) FROM song " .
			" WHERE song.artist = '$artist_id'" .
			" GROUP BY song.album";
		$db_result = mysql_query($sql, $dbh);

		$albums = 0;
		$songs = 0;
		while(list($song) = mysql_fetch_row($db_result)) {
			$songs += $song;
			$albums++;
		}
		$info['songs'] = $songs;
		$info['albums'] = $albums;
		//FIXME: Lame place to put this
		//if ($songs < conf('min_artist_songs') || $albums < conf('min_artist_albums')) { 
		//	return FALSE;
		//}
		return $info;
	}
	else {
		return FALSE;
	}
}


function get_album_name ($album, $dbh = 0) {

	$album = new Album($album);
	return $album->name;
} // get_album_name


function get_genre_info($genre_id) {

	global $settings;
	$dbh = dbh();

	$sql = "SELECT name FROM genre WHERE id = '$genre_id'";
	$db_result = mysql_query($sql, $dbh);

	// if its -1 then we're doing all songs
	if ( $genre_id < 0 ) {
		$sql = "SELECT count(*) FROM song";
	}
	else {
		$sql = "SELECT count(*) FROM song WHERE genre = '$genre_id'";
	}

	$genre_result = mysql_query($sql, $dbh);

	$genre_count = mysql_fetch_row($genre_result);

	$r = mysql_fetch_row($db_result);

        // Crude hack for non-standard genre types
	if ($genre_id == -1) {
		return array('All', $genre_count[0]);
	}
	elseif ($genre_id == 0) {
		return array('N/A', $genre_count[0]);
	}
	else {
		return array($r[0], $genre_count[0]);
	}
}


function get_genre($id) {

	global $settings;
	$dbh = dbh();

	$query = "SELECT * FROM genre WHERE id = '$id'";
	$db_result = mysql_query($query, $dbh);

	$r = mysql_fetch_object($db_result);
	return $r;
}


// Utility function to help move things along
function get_song_info ($song, $dbh = 0) {
	
	$song = new Song($song);
	return $song;
	
} // get_song_info


/*!
	@function show_albums
	@discussion show many albums, uses view class
*/
function show_albums ($albums,$view=0) {

	$dbh = libglue_param(libglue_param('dbh_name'));

	if (!$view) {
	        $view = new View($_SESSION['view_base_sql'], $_SESSION['script'], $total_items,$_SESSION['view_offset_limit']);
	}

	if ($albums) { 
		require (conf('prefix') . "/templates/show_albums.inc");
	}
	else {
		echo "<p><font color=\"red\">No Albums Found</font></p>";
	}

} // show_albums

// Used to show a form with confirm action button on it (for deleting playlists, users, etc)
/*!
	@function show_confirm_action
	@discussion shows a confirmation of an action, gives a YES/NO choice
*/
function show_confirm_action ($text, $script, $arg) {

	$web_path = conf('web_path');
	require (conf('prefix') . "/templates/show_confirm_action.inc.php");

} // show_confirm_action


function unhtmlentities ($string)  {

	$trans_tbl = get_html_translation_table (HTML_ENTITIES);
	$trans_tbl = array_flip ($trans_tbl);
	$ret = strtr ($string, $trans_tbl);
	return preg_replace('/&#(\d+);/me', "chr('\\1')",$ret);
}

?>