summaryrefslogtreecommitdiffstats
path: root/modules/catalog.php
blob: 9b9c089af502a14510071be53a37fcacbc2e0c36 (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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
<?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.

 Contains all of the catalog (local & remote) functions.

 DEAD FILE (Old Crap)

*/

/*
 * get_catalogs()
 *
 * return an array of catalog objects
 *
 */

function get_catalogs () {
	global $dbh, $settings;

    $sql       = "SELECT * FROM catalog";
	$db_result = mysql_query($sql, $dbh);

	$catalogs  = array();
	while ( $catalog = mysql_fetch_object($db_result) ) {
		$catalogs[] = $catalog;
	}

	return ($catalogs);
} // get_catalogs()


/*
 * update_artist_info()
 *
 * this will update the song and album counters for the artist
 */

function update_artist_info($artist_id) {
  GLOBAL $dbh, $settings;

  // get the count of songs
  $query = "SELECT count(id) FROM song WHERE artist='$artist_id'";
  $db_result = mysql_query($query, $dbh);

  $r = mysql_fetch_row($db_result);
  $artist->songs = $r[0];

  // get the count of albums
  $query = "SELECT count(DISTINCT album) FROM song WHERE artist='$artist_id'";
  $db_result = mysql_query($query, $dbh);

  $r = mysql_fetch_row($db_result);
  $artist->albums = $r[0];

  // now update the artist table
  $query = "UPDATE artist SET songs='$artist->songs',albums='$artist->albums' WHERE id='$artist_id'";
  $db_result = mysql_query($query, $dbh);
} // update_artist_info()


/*
 * select_artist()
 *
 * given an artist name (string) it will return:
 *  false: if the artist name doesn't exist
 *  true : if the artist name does exist
 * in the database
 *
 */

function select_artist($artist) {
  GLOBAL $dbh, $settings;

  $artist = sql_escape($artist);

  $sql       = "SELECT id FROM artist WHERE name = '$artist'";
  $db_result = mysql_query( $sql, $dbh );
  $r         = mysql_fetch_row( $db_result );

  if ( $r[0] ) {
    return ($r[0]);
  }
  else {
    return 0;
  }
} // select_artist()


/*
 * insert_artist()
 *
 * given an artist name (string) it will insert an entry
 * into the database, defaulting the catalog to 0
 *
 */

/*
function insert_artist($artist, $catalog = 0) {
  GLOBAL $dbh, $settings;

  $artist = sql_escape($artist);

  $sql = "INSERT INTO artist (name,catalog) VALUES ('$artist', $catalog)";
  $db_result = mysql_query($sql, $dbh);

  return (mysql_insert_id($dbh));
} // insert_artist()
*/

/*
 * update_artist_name()
 *
 * let's change the album name
 *
 */

function update_artist_name ($artist, $new_name) {
        global $dbh, $settings;
  
        $query = "UPDATE artist SET name='$new_name' WHERE id='$artist'";
        $db_result = mysql_query($query, $dbh);
} // update_artist_name()


/*
 * delete_artist()
 *
 * given an artist id (int) this will delete the associated
 * entry from the database
 *
 */

function delete_artist($artist) {
  GLOBAL $dbh, $settings;

  $sql       = "DELETE FROM artist WHERE id = $artist";
  $db_result = mysql_query($sql, $dbh);
} // delete_artist()


/*
 * select_album()
 *
 * given an album name and artist id, this will return:
 *  false: if the album name and artist id don't match
 *  id   : of the album name and artist id match 
 */

function select_album($album, $artist) {
  GLOBAL $dbh, $settings;

  $album = sql_escape($album);

  $sql       = "SELECT id FROM album 
                WHERE name = '$album' AND artist = $artist";
  $db_result = mysql_query($sql, $dbh);

  $r = mysql_fetch_row($db_result);

  if ( $r[0] ) {
    return ($r[0]);
  }
  else {
    return 0;
  }
} // select_album()


/*
 * update_album_name()
 *
 * let's change the album name
 *
 */

function update_album_name ($album, $new_name) {
	global $dbh, $settings;

	$sql       = "UPDATE album SET name='$new_name' WHERE id='$album'";
	$db_result = mysql_query($sql, $dbh);
} // update_album_name()


/*
 * update_local_mp3($name, $type, $songs)
 *
 * This will update all of the $songs with a new name of type $type.  Used
 *   mostly for updating artist/album names for your _local_ mp3s.  This
 *   will write out new ID3 tags.
 */

function update_local_mp3($name, $type, $songs) {
	// THIS IS DEAD!!!
	//FIXME: I'm dead Jim!
} // update_local_mp3



/*
 * get_check_array()
 *
 * returns a single dimension array of the md5 hashes
 * for all songs in local catalogs
 *
 */

function get_check_array ( ) {
	global $settings, $dbh;
    
	$check_array = array();

	$sql       = "SELECT md5 FROM song";
	$db_result = mysql_query($sql, $dbh );

	while ( $md5 = mysql_fetch_object( $db_result ) )
	{
		$check_array[] = $md5->md5;
	}

	return $check_array;
} // get_check_array()

?>