-
Notifications
You must be signed in to change notification settings - Fork 13
/
playlistDel.php
320 lines (261 loc) · 14.7 KB
/
playlistDel.php
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
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
<?php
// +------------------------------------------------------------------------+
// | O!MPD, Copyright © 2015-2016 Artur Sierzant |
// | http://www.ompd.pl |
// | |
// | |
// | 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 3 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, see <http://www.gnu.org/licenses/>. |
// +------------------------------------------------------------------------+
require_once('include/initialize.inc.php');
$cfg['menu'] = 'playlist';
authenticate('access_playlist');
require_once('include/play.inc.php');
require_once('include/header.inc.php');
global $cfg, $db;
$index = (int) get('index');
mpd('delete ' . $index);
?>
<table cellspacing="0" cellpadding="0" class="border">
<tr class="header">
<td class="space left"></td>
<td class="trackNumber"> # </td>
<td>Title</td>
<td>Artist</td>
<td>Genre</td>
<td><?php if ($featuring) echo'Featuring'; ?></td><!-- optional featuring -->
<td<?php if ($featuring) echo' class="textspace"'; ?>></td>
<td class="icon"></td><!-- optional delete -->
<td class="space"></td>
<td align="right" class="time">Time</td>
<td class="space right"></td>
</tr>
<tr class="line"><td colspan="11"></td></tr>
<?php
$playtime = array();
$track_id = array();
for ($i=0; $i < $listlength; $i++)
{
$query = mysqli_query($db,'SELECT track.title, track.artist, track.track_artist, track.featuring, track.miliseconds, track.track_id, track.genre, album.genre_id, track.audio_dataformat, track.audio_bits_per_sample, track.audio_sample_rate, track.album_id, track.number FROM track, album WHERE track.album_id=album.album_id AND track.relative_file = "' . mysqli_real_escape_string($db,$file[$i]) . '"');
$table_track = mysqli_fetch_assoc($query);
$playtime[] = (int) $table_track['miliseconds'];
$track_id[] = (string) $table_track['track_id'];
$genre_id[] = (string) $table_track['genre_id'];
$number[] = (string) $table_track['number'];
if (!isset($table_track['artist'])) {
$table_track['artist'] = $file[$i];
$table_track['title'] = 'Unknown';
}
$query2 = mysqli_query($db,'SELECT album, year, image_id FROM album WHERE album_id="' . $table_track['album_id'] . '"');
$image_id = mysqli_fetch_assoc($query2);
?>
<tr class="<?php if ($i == $listpos) echo 'select'; else echo ($i & 1) ? 'even mouseover' : 'odd mouseover'; ?>" id="track<?php echo $i; ?>" style="display:table-row;">
<td class="small_cover">
<a id="track<?php echo $i; ?>_image" href="javascript:ajaxRequest('play.php?action=playIndex&index=<?php echo $i ?>&menu=playlist', evaluateListpos);"><img src="image.php?image_id=<?php echo $image_id['image_id'] ?>" alt="" width="50" height="50"></a></td>
<td><a class="trackNumber" href="javascript:ajaxRequest('play.php?action=playIndex&index=<?php echo $i ?>&menu=playlist', evaluateListpos);" id="track<?php echo $i; ?>_number"><div class="trackNumber"> <?php echo html($table_track['number']); ?> </div></a></td>
<td><a href="javascript:ajaxRequest('play.php?action=playIndex&index=<?php echo $i ?>&menu=playlist', evaluateListpos);" id="track<?php echo $i; ?>_title"><div class="playlist_title"><?php echo html($table_track['title']) ?></div>
<div class="playlist_title_album"><?php echo $image_id['album'] ?> (<?php echo $image_id['year'] ?>)</div>
</a></td>
<td>
<a href="index.php?action=view2&order=artist&sort=asc&artist=<?php echo html($table_track['track_artist']) ?>"> <?php echo html($table_track['track_artist']) ?> </a>
</td>
<td>
<a href="index.php?action=view2&order=artist&sort=asc&&genre_id=<?php echo $table_track['genre_id'] ?>"><?php echo $table_track['genre'] ?></a>
</td>
<td><?php if (isset($table_track['featuring'])) echo html($table_track['featuring']); ?></td>
<td></td>
<!-- <td id="track<?php echo $i; ?>_delete"><?php if ($cfg['access_play']) echo '<a href="javascript:delItemAjax(\'' . $i . '\');"><span class="typcn typcn-delete" style="font-size: 30px; color: #555555;"><span></a>'; ?></td> -->
<td id="track<?php echo $i; ?>_delete"><?php if ($cfg['access_play']) echo '<a href="javascript:ajaxRequest(\'play.php?action=deleteIndex&index=' . $i . '&menu=playlist\',deletePLitem);"><span class="typcn typcn-delete" style="font-size: 30px; color: #555555;"><span></a>'; ?></td>
<td></td>
<td align="right"><?php if (isset($table_track['miliseconds'])) echo formattedTime($table_track['miliseconds']); ?></td>
<td></td>
</tr>
<?php
}
?>
</table>
<script type="text/javascript">
<!--
var previous_hash = '<?php echo $hash; ?>';
var previous_listpos = <?php echo $listpos; ?>;
var previous_isplaying = -1; // force update
var previous_repeat = -1;
var previous_shuffle = -1;
var previous_gain = -1;
var previous_miliseconds = -1;
var previous_volume = -1;
var playtime = <?php echo safe_json_encode($playtime); ?>;
var track_id = <?php echo safe_json_encode($track_id); ?>;
var timer_id = 0;
var timer_function = 'ajaxRequest("play.php?action=playlistStatus&menu=playlist", evaluateStatus)';
//var timer_function = '';
var timer_delay = 1000;
var list_length = <?php echo $listlength;?>;
//console.trace();
function deletePLitem(data) {
//console.trace();
var idx = parseInt(data.index);
//var idx = parseInt(idx2del);
console.log ("idx: %s", idx)
var row2del = document.getElementById('track' + idx);
var newId = Date.parse(new Date());
row2del.id = 'track' + newId;
//$('#track' + newId).fadeOut(700, function(){ $('#track' + newId).remove();});
row2del.parentNode.removeChild(row2del);
//row2del.style.display='none';
list_length = list_length-1;
var i = idx+1;
//console.log("i= %s", i);
//console.log("list_length= %s", list_length);
for (i; i<=list_length; i++) {
var j = i-1;
document.getElementById('track' + i).id = 'track' + j;
document.getElementById('track' + i + '_image').id = 'track' + j + '_image';
document.getElementById('track' + i + '_number').id = 'track' + j + '_number';
document.getElementById('track' + i + '_title').id = 'track' + j + '_title';
document.getElementById('track' + i + '_delete').id = 'track' + j + '_delete';
var oldClassName = document.getElementById('track' + j).className;
var t = oldClassName.search('even');
//console.log("className: %s, 'even' pos: %s", oldClassName, t);
document.getElementById('track' + j).className = ((oldClassName.search('select') == 0 ) ? 'select' : ((oldClassName.search('even') < 0 ) ? 'even mouseover' : 'odd mouseover'));
var newHref = 'javascript:ajaxRequest(\'play.php?action=playIndex&index=' + j + '&menu=playlist\', evaluateListpos);';
document.getElementById('track' + j + '_image').href = newHref;
document.getElementById('track' + j + '_number').href = newHref;
document.getElementById('track' + j + '_title').href = newHref;
document.getElementById('track' + j + '_delete').innerHTML='<a href="javascript:ajaxRequest(\'play.php?action=deleteIndex&index=' + j + '&menu=playlist\',deletePLitem);"><span class="typcn typcn-delete" style="font-size: 30px; color: #555555;"><span></a>';
}
}
function initialize() {
ajaxRequest('play.php?action=playlistTrack&track_id=' + track_id[<?php echo $listpos; ?>] + '&menu=playlist', evaluateTrack);
ajaxRequest('play.php?action=playlistStatus&menu=playlist', evaluateStatus);
}
function evaluateStatus(data) {
// data.hash, data.miliseconds, data.listpos, data.volume
// data.isplaying, data.repeat, data.shuffle, data.gain
if (previous_hash != data.hash) {
//window.location.href="<?php echo NJB_HOME_URL ?>playlist.php";
location.reload(false);
}
data.max = playtime[data.listpos];
evaluateListpos(data.listpos);
evaluatePlaytime(data);
evaluateRepeat(data.repeat);
evaluateShuffle(data.shuffle);
evaluateIsplaying(data.isplaying);
evaluateVolume(data.volume);
evaluateGain(data.gain);
}
function evaluateListpos(listpos) {
if (previous_listpos != listpos) {
document.getElementById('track' + previous_listpos).className = (previous_listpos & 1) ? 'even mouseover' : 'odd mouseover';
document.getElementById('track' + listpos).className = 'select';
document.getElementById('time').innerHTML = formattedTime(0);
document.getElementById('timebar').style.width = 0;
ajaxRequest('play.php?action=playlistTrack&track_id=' + track_id[listpos] + '&menu=playlist', evaluateTrack);
previous_miliseconds = 0;
previous_listpos = listpos;
}
}
function evaluatePlaytime(data) {
// data.miliseconds, data.max, ....
if (previous_miliseconds != data.miliseconds) {
document.getElementById('time').innerHTML = formattedTime(data.miliseconds);
var width = 0;
if (data.max > 0) width = Math.round(data.miliseconds / data.max * 200);
if (width > 200) width = 200;
document.getElementById('timebar').style.width = width;
previous_miliseconds = data.miliseconds;
}
}
function evaluateVolume(volume) {
if (previous_volume != volume && volume >= 0) {
// Volume
var volume_percentage = Math.round(100 * volume / <?php echo $max_volume; ?>);
var width = Math.round(200 * volume / <?php echo $max_volume; ?>);
document.getElementById('volume').innerHTML = volume_percentage + '%';
document.getElementById('volumeimage').src = '<?php echo $cfg['img']; ?>playlist_bar_on.png';
document.getElementById('volumebar').style.width = width;
previous_volume = volume;
}
if (previous_volume != volume && volume < 0) {
// Mute volume
var mute_volume = -1 * volume;
var volume_percentage = Math.round(100 * mute_volume / <?php echo $max_volume; ?>);
var width = Math.round(200 * mute_volume / <?php echo $max_volume; ?>);
document.getElementById('volume').innerHTML = 'mute';
document.getElementById('volumeimage').src = '<?php echo $cfg['img']; ?>playlist_bar_off.png';
document.getElementById('volumebar').style.width = width;
previous_volume = volume;
}
}
function evaluateIsplaying(isplaying) {
if (previous_isplaying != isplaying) {
if (isplaying == 0) {
// stop
document.getElementById('play').src = '<?php echo $cfg['img']; ?>playlist_play_off.png';
document.getElementById('pause').src = '<?php echo $cfg['img']; ?>playlist_pause_off.png';
document.getElementById('time').innerHTML = formattedTime(0);
document.getElementById('timebar').style.width = 0;
previous_miliseconds = 0;
}
else if (isplaying == 1) {
// play
document.getElementById('play').src = '<?php echo $cfg['img']; ?>playlist_play_on.png';
document.getElementById('pause').src = '<?php echo $cfg['img']; ?>playlist_pause_off.png';
}
else if (isplaying == 3) {
// pause
document.getElementById('play').src = '<?php echo $cfg['img']; ?>playlist_play_off.png';
document.getElementById('pause').src = '<?php echo $cfg['img']; ?>playlist_pause_on.png';
}
previous_isplaying = isplaying
}
}
function evaluateRepeat(repeat) {
if (previous_repeat != repeat) {
if (repeat == 0) document.getElementById('repeat').src = '<?php echo $cfg['img']; ?>playlist_repeat_off.png';
if (repeat == 1) document.getElementById('repeat').src = '<?php echo $cfg['img']; ?>playlist_repeat_on.png';
previous_repeat = repeat;
}
}
function evaluateShuffle(shuffle) {
if (previous_shuffle != shuffle) {
if (shuffle == 0) document.getElementById('shuffle').src = '<?php echo $cfg['img']; ?>playlist_shuffle_off.png';
if (shuffle == 1) document.getElementById('shuffle').src = '<?php echo $cfg['img']; ?>playlist_shuffle_on.png';
previous_shuffle = shuffle;
}
}
function evaluateGain(gain) {
if (previous_gain != gain) {
if (gain == 'off') document.getElementById('gain').src = '<?php echo $cfg['img']; ?>playlist_gain_off.png';
if (gain == 'album') document.getElementById('gain').src = '<?php echo $cfg['img']; ?>playlist_gain_album.png';
if (gain == 'auto') document.getElementById('gain').src = '<?php echo $cfg['img']; ?>playlist_gain_auto.png';
if (gain == 'track') document.getElementById('gain').src = '<?php echo $cfg['img']; ?>playlist_gain_track.png';
previous_gain = gain;
}
}
function evaluateTrack(data) {
// data.artist, data.title, data.album, data.by, data.album_id, data.image_id
document.getElementById('artist').innerHTML = '<a href="index.php?action=view2&order=artist&sort=asc&artist=' + data.album_artist + '">' + data.track_artist + '</a>';
document.getElementById('title').innerHTML = data.number + '. ' + data.title;
document.getElementById('album').innerHTML = '<a href="index.php?action=view3&album_id=' + data.album_id + '">' + data.album + '</a>';
document.getElementById('year').innerHTML = '<a href="index.php?action=view2&order=artist&sort=asc&year=' + data.year + '">' + data.year + '</a>';
document.getElementById('genre').innerHTML = '<a href="index.php?action=view2&order=artist&sort=asc&&genre_id=' + data.genre_id + '">' + data.genre + '</a>';
document.getElementById('parameters').innerHTML = data.audio_dataformat + ' (' + data.audio_bits_per_sample + '/' + data.audio_sample_rate/1000 + ') [' + data.audio_profile + ']';
document.getElementById('lyrics').innerHTML = '<a href="ridirect.php?query_type=lyrics&q=' + data.track_artist + '+' + data.title + '+lyrics site:.pl" target="_blank"><img src="<?php echo $cfg['img'] ?>small_search.png" alt="" class="small space">Search</a>';
//document.getElementById('lyrics').innerHTML = '<a href="http://www.google.pl/search?q=' + data.track_artist + '+' + data.title + '+lyrics site:.pl" target="_blank"><img src="<?php echo $cfg['img'] ?>small_search.png" alt="" class="small space">Search</a>';
if (data.album_id) document.getElementById('image').innerHTML = '<a href="index.php?action=view3&album_id=' + data.album_id + '"><img src="' + data.image_front + '" alt="" width="250" height="250" onMouseOver="return overlib(\'Go to album\');" onMouseOut="return nd();"><\/a>';
else document.getElementById('image').innerHTML = '<img src="<?php echo $cfg['img']; ?>large_file_not_found.png" alt="" width="100" height="100">';
}
//-->
</script>