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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
|
/* The AJAX stuff */
var xmlHttp;
var requestType="";
var ret_songid=0;
function createXMLHttpRequest() {
if (window.ActiveXObject) {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
else if (window.XMLHttpRequest) {
xmlHttp = new XMLHttpRequest();
}
}
function startRequest(params) {
createXMLHttpRequest();
xmlHttp.onreadystatechange = handleStateChange;
xmlHttp.open("GET", web_path + "/server/ajax.server.php?"+params+"&player="+player, true);
/* xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); */
xmlHttp.send(null);
}
function timestuff() {
alert ("mpd_elapsed ="+fmt_time(mpd_elapsed)+"; nowtime - starttime ="+fmt_time(Math.floor ((nowtime - starttime)/1000))+"; secondssinceloaded ="+fmt_time(secondssinceloaded));
}
function handleStateChange() {
if (xmlHttp.readyState == 4) {
if (xmlHttp.status == 200) {
/* alert ("responseText = " + xmlHttp.responseText); */
var props = xmlHttp.responseXML.getElementsByTagName("properties")[0].childNodes;
for (var i=1; i< props.length; i++) {
el = props[i];
/* alert ("i="+i+"; "+el.tagName); */
switch (el.tagName) {
case 'action' : break;
case 'volume' :
var vol = el.firstChild.data;
if (player == 'mpd') document.getElementById ('volume').firstChild.data = vol;
break;
case 'mpd_cur_track_pos' :
mpd_elapsed = Math.floor(el.firstChild.data);
/* alert ('mpd_elapsed ='+mpd_elapsed); */
starttime = new Date();
starttime=starttime.getTime()
break;
case 'state' :
var new_state = el.firstChild.data;
/* alert ('state = '+new_state+'; player_state = '+player_state); */
if ((player == 'mpd') && (player_state != new_state)) {
document.getElementById (player_state+'_button').className = "";
document.getElementById (new_state+'_button').className = "selected_button";
player_state = new_state;
if (player_state == "stop" || player_state == "pause") {
if (document.getElementById ('mpd_np'))
document.getElementById ('mpd_np').className = "nodisplay";
} else
{
if (document.getElementById ('mpd_np'))
document.getElementById ('mpd_np').className = "";
} // end if else
} // end if mpd changed player_state
break;
case 'now_playing' :
ret_songid = Math.round(el.getElementsByTagName ('songid')[0].firstChild.data);
if (player == 'mpd' && player_state != 'stop') {
mpd_song_length = el.getElementsByTagName ('songlength')[0].firstChild.data;
if (document.getElementById ('mpd_npinfo')) {
document.getElementById ('mpd_npinfo').firstChild.data =
1+ret_songid + ". " +
el.getElementsByTagName ('songartist')[0].firstChild.data + " - " +
el.getElementsByTagName ('songtitle')[0].firstChild.data + " - " +
el.getElementsByTagName ('songalbum')[0].firstChild.data + " - " +
fmt_time(mpd_song_length);
}
}
if (ret_songid != mpd_songid) {
if (document.getElementById ('mpd_row'+mpd_songid)) {
if ((mpd_songid - mpdpl_first) %2 == 1) {
document.getElementById ('mpd_row'+mpd_songid).className = 'even';
} else {
document.getElementById ('mpd_row'+mpd_songid).className = 'odd';
}
}
if (player_state != 'stop') {
if ((document.getElementById ('mpd_row'+ret_songid) != null) && (player_state != 'stop')) {
document.getElementById ('mpd_row'+ret_songid).className = 'npsong';
}
}
mpd_songid = ret_songid;
}
break;
case 'now_playing_display' :
// fix for pages where now playing data doesnt exist
if (document.getElementById('np_songid_0_holder')) {
show_now_playing_display(el);
}
break;
default :
alert ('Unknown XML reply :"'+el.tagName+'"');
} // end switch
} // end for
}
else
{ alert ('status = ' + xmlHttp.status);
} // end if status else
} //end if ready status
}
// the actual function that checks and updates the now playing data.
function show_now_playing_display (el) {
for (var i=0; i<el.childNodes.length; i++) {
now_playing = el.childNodes[i];
// check if we need to update
if (document.getElementById('np_songid_'+i+'_holder').innerHTML ==
now_playing.getElementsByTagName('songid')[0].firstChild.data) { } else {
// set the songid holder, so we only update if nessicary... (no album art flashing)
document.getElementById('np_songid_'+i+'_holder').innerHTML =
now_playing.getElementsByTagName('songid')[0].firstChild.data;
// output the fullname of the person, may be blank
document.getElementById('np_fullname_'+i).innerHTML =
now_playing.getElementsByTagName('fullname')[0].firstChild.data;
// output the song name and link tag
document.getElementById('np_song_'+i).innerHTML =
'<a href="song.php?action=single_song&song_id=' +
now_playing.getElementsByTagName('songid')[0].firstChild.data + '">' +
now_playing.getElementsByTagName('songtitle')[0].firstChild.data + '</a>';
// output the artist / album and link tags
document.getElementById('np_albumartist_'+i).innerHTML =
'<a href="albums.php?action=show&album=' +
now_playing.getElementsByTagName('albumid')[0].firstChild.data + '">' +
now_playing.getElementsByTagName('songalbum')[0].firstChild.data +
'</a> / <a href="artists.php?action=show&artist=' +
now_playing.getElementsByTagName('artistid')[0].firstChild.data + '">' +
now_playing.getElementsByTagName('songartist')[0].firstChild.data + '</a>';
// output the album art, and the link for it
document.getElementById('np_img_'+i).innerHTML =
'<a target="_blank" href="albumart.php?id=' +
now_playing.getElementsByTagName('albumid')[0].firstChild.data +
'&type=popup" onclick="popup_art(\'albumart.php?id=' +
now_playing.getElementsByTagName('albumid')[0].firstChild.data +
'&type=popup\'); return false;">' +
'<img align="middle" border="0" src="albumart.php?id=' +
now_playing.getElementsByTagName('albumid')[0].firstChild.data +
'&fast=1&thumb=1" alt="Album Art" height="75" /></a>';
// make sure its visible.
document.getElementById('np_container_'+i).style.display = 'block';
} // end if holder = songid
} // for ecah record we get
// fill in the rest with blank data and hide them.
while (i<5) {
document.getElementById('np_container_'+i).style.display = 'none';
document.getElementById('np_songid_'+i+'_holder').innerHTML = '';
i++;
} // end while i<5
} // end show_now_playing_display function
function disableField(element) {
var element_id = document.getElementById(element);
element_id.disabled=true;
element_id.value='';
element_id.checked=false;
}
function enableField(element) {
var element_id = document.getElementById(element);
element_id.disabled=false;
}
function flipField(element) {
var element_id = document.getElementById(element);
if (element_id.disabled == false) {
element_id.disabled=true;
}
else {
element_id.disabled=false;
}
}
function selectField(element)
{
var element_id = document.getElementById(element);
element_id.focus();
}
var checkflag_song = "false";
function check_songs() {
if (checkflag_song == "false") {
if (document.forms.songs.elements["song[]"].length == undefined) {
document.forms.songs.elements["song[]"].checked = true;
}
else {
for (i = 0; i < document.forms.songs.elements["song[]"].length; i++) {
document.forms.songs.elements["song[]"][i].checked = true;
}
}
checkflag_song = "true";
return "Unselect All";
}
else {
if (document.forms.songs.elements["song[]"].length == undefined) {
document.forms.songs.elements["song[]"].checked = false;
}
else {
for (i = 0; i < document.forms.songs.elements["song[]"].length; i++) {
document.forms.songs.elements["song[]"][i].checked = false;
}
}
checkflag_song = "false";
return "Select All";
}
}
function invert_songs() {
for( i = 0; i < document.forms.songs.elements["song[]"].length; ++i ) {
document.forms.songs.elements["song[]"][i].checked = !document.forms.songs.elements["song[]"][i].checked
}
}
var checkflag_results = "false";
function check_results() {
if (checkflag_results == "false") {
if (document.results.elements["results[]"].length == undefined) {
document.results.elements["results[]"].checked = true;
}
else {
for (i = 0; i < document.results.elements["results[]"].length; i++) {
document.results.elements["results[]"][i].checked = true;
}
}
checkflag_results = "true";
return "Unselect All";
}
else {
if (document.results.elements["results[]"].length == undefined) {
document.results.elements["results[]"].checked = false;
}
else {
for (i = 0; i < document.results.elements["results[]"].length; i++) {
document.results.elements["results[]"][i].checked = false;
}
}
checkflag_results = "false";
return "Select All";
}
}
// function for the catalog mojo fluf
function update_txt(value,field) {
document.getElementById(field).innerHTML=value;
}
// SubmitToPage this function specificaly submits the form to the specified page
function SubmitToPage(form_id,action) {
document.getElementById(form_id).action = action;
document.getElementById(form_id).submit();
return true;
}
function popup_art(url) {
var newwindow;
newwindow=window.open(url, "ampache_art", "menubar=no,toolbar=no,location=no,directories=no");
if (window.focus) {newwindow.focus()}
}
// function needed for IE. attaches mouseover/out events to give/remove css class .sfhover (fake hover)
sfHover = function(navlist) {
var sfEls = document.getElementById("navlist").getElementsByTagName("LI");
for (var i=0; i <sfEls.length; i++) {
sfEls[i].onmouseover=function() {
this.className+=" sfhover";
}
sfEls[i].onmouseout=function() {
this.className=this.className.replace(new RegExp("sfhover\\b"), "");
}
} // end for
} // end function for sfHover
if (window.attachEvent) window.attachEvent("onload", sfHover);
|