-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplaylists.php
258 lines (255 loc) · 11.4 KB
/
playlists.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
<?php
include "include.php";
function search() {
echo '<div class="row box"><div class="col-xs-12"><div class="row" style="margin-top:10px;"><div class="col-xs-7"><form id="searchform" method="post" action="search.php"><input class="form-control" type="text" id="searchstring" name="searchstring"/></div><div class="col-xs-1 searchbutton"><input class="btn btn-primary" type="button" id="searchbuttonplaylist" value="Search"/></div><div class="col-xs-1 searchprogress"><img width="20" height="20" class="img-fluid progress" src="pix/progress.gif"></form></div></div>';
echo '<div class="row searchresultbuttons" style="margin-top:10px;display:none;margin-bottom:10px;"><div class="col-xs-12"><input class="btn btn-primary" type="button" name="addall" value="Add All" style="margin-right:10px;"><img width="20" height="20" style="display:none;margin-left:-5px;margin-right:5px;" class="img-fluid addallprogress" src="pix/progress.gif"><input class="btn btn-primary" type="button" name="clearall" value="Clear"></div></div><div class="row"><div class="col-xs-12" style="margin-left:10px;" id="displaytext"></div></div></div></div>';
}
if (isset($_REQUEST["addtoplaylist"])) {
$target=base64_decode($_REQUEST["target"]);
foreach($shares as $share=>$info) {
if (startWith($target, $share)) {
$result=$mysql->select("files",["ID","Filename"],"`Path`='".$mysql->conn->real_escape_string(substr($target,strlen($share)))."' AND `Share`='".$info["ID"]."'");
if (count($result)!=0) {
if ($mysql->insert("playlistentries",["Playlist"=>$_REQUEST["addtoplaylist"],"File"=>$result[0]["ID"],"Weight"=>0])) {
echo $mysql->insert_id." ".$result[0]["Filename"]."<BR>";
} else
echo "Error: ".$mysql->error;
} else
echo "Error: File not found in database, run scan again";
}
}
} else if (isset($_REQUEST["removeplaylist"])) {
if ($mysql->delete("playlist","`ID`='".$mysql->conn->real_escape_string($_REQUEST["removeplaylist"])."'")) {
echo "OK";
} else {
echo $mysql->error;
}
} else if (isset($_REQUEST["addplaylist"])) {
if ($mysql->insert("playlist",["Name"=>$_REQUEST["addplaylist"]])) {
echo '<span><img class="delete" target="' . $mysql->insert_id . '" src="pix/delete.png"/><a href="#'.$mysql->insert_id .'" class="showplaylist">' . $_REQUEST["addplaylist"] . '</a><form action="'.$base.'/showplaylist.php" method="POST" style="display:inline;margin-left:5px;position:relative;top:7px;"><input type="hidden" name="playlist" value="'.$mysql->insert_id .'"><input type="submit" style="font-size:26px;background-color:transparent;border-style:none;position:relative;top:-4px;" Value="►"/></form><BR></span>';
echo '<div style="display:none;" id="playlist_'.$mysql->insert_id.'">';
} else {
echo "Error: ".$mysql->error;
}
} else {
include "head.php";
show_nav();
search();
echo '<div class="modal fade" id="playlistselect" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
<h5 class="modal-title" id="exampleModalLabel">Choose Playlist</h5>
</div>
<div class="modal-body" id="playlistslist">';
$result = $mysql->select("playlist", ["*"]);
$first=true;
foreach($result as $row) {
if ($first) {
$first=false;
echo '<div class="radio"><label><input type="radio" name="playlist" checked value="'.$row["ID"].'">'.$row["Name"].'</label></div>';
} else {
echo '<div class="radio"><label><input type="radio" name="playlist" value="'.$row["ID"].'">'.$row["Name"].'</label></div>';
}
}
echo '</div>
<div class="modal-footer">
<button type="button" id="btnaddtoplaylist" class="btn btn-primary" data-dismiss="modal">Ok</button>
</div>
</div>
</div>
</div>';
echo '<script>
var file;
function addToPlaylist(playlist) {
$.ajax({
url: "'.$base.'/playlists.php",
method: "POST",
data: {addtoplaylist:playlist,target:file}
}).done(function (data) {
if (data.substr(0,5)=="Error") {
alert(data);
} else {
$("#playlist_"+playlist).html($("#playlist_"+playlist).html()+data);
}
});
}
function registershowpl() {
$(".showplaylist").click(function(e) {
e.preventDefault();
if ($("#"+"playlist_"+$(this).attr("href").substring(1)).is(":visible")) {
$("#"+"playlist_"+$(this).attr("href").substring(1)).hide();
} else {
$("#"+"playlist_"+$(this).attr("href").substring(1)).show();
}
});
}
function registerdelete() {
$(".delete").click(function() {
target=$(this);
$.ajax({
url: "'.$base.'/playlists.php",
method: "POST",
data: {removeplaylist:$(this).attr("target")}
}).done(function(data) {
if (data!="OK") {
alert(data);
} else {
var pid=target.attr("target");
target.parent().remove();
$("#playlist_"+pid).remove();
$(":radio[value="+pid+"]").parent().parent().remove();
$(":radio").first().prop("checked", true);
}
});
});
}
$("#btnaddtoplaylist").click(function() {
if (addall) {
var playlist=$("input[name=playlist]:checked").val();
var spread=0;
var lastone=$(".singlesearchresult").length;
var count=0;
$(".addallprogress").show();
$(".singlesearchresult").each(function() {
var plentry=$(this).attr("href").substring($(this).attr("href").lastIndexOf("/")+1);
setTimeout(function() {
$.ajax({
url: "'.$base.'/playlists.php",
method: "POST",
data: {addtoplaylist:playlist,target:plentry}
}).done(function (data) {
count++;
if (data.substr(0,5)=="Error") {
alert(data);
} else {
$("#playlist_"+playlist).html($("#playlist_"+playlist).html()+data);
}
if (count==lastone) {
$(".addallprogress").hide();
}
});
},spread);
spread+=100;
});
addall=false;
} else {
addToPlaylist($("input[name=playlist]:checked").val());
}
});
var addall=false;
$(document).ready(function() {
$(".close").click(function() {
addall=false;
});
registerdelete();
$("#searchbuttonplaylist").click(function (event) {
$(".progress").show();
event.preventDefault();
lastsize = 0;
xhr.abort();
$("#displaytext").html("");
searchresults = $.ajax({
url: "'.$base.'/search.php",
method: "POST",
data: {searchstring: $("#searchstring").val(),playlist:"1"},
context: document.body,
xhr: xhrProvider,
beforeSend: function () {
setTimeout(iteratethroughresults, 10);
}
}).done(function () {
$(".progress").hide();
setTimeout(function() {
$(".searchresultbuttons").show();
$("input[name=\'addall\']").click(function() {
if (document.getElementById("playlistslist").childElementCount!=0) {
addall=true;
$("#playlistselect").modal("show");
} else {
alert("Create a playlist first");
}
});
$("input[name=\'clearall\']").click(function() {
$("#displaytext").html("");
$(".searchresultbuttons").hide();
});
$(".addtoplaylist").click(function() {
if (document.getElementById("playlistslist").childElementCount!=0) {
file=document.getElementById($(this).attr("target"));
file=file.href.substring(file.href.lastIndexOf("/")+1);
$("#playlistselect").modal("show");
} else {
alert("Create a playlist first");
}
});
},100);
});
});
registershowpl();
$("input[name=\'addplaylist\']").click(function() {
$.ajax({
url: "'.$base.'/playlists.php",
method: "POST",
data: {addplaylist:$("input[name=\'playlistname\']").val()}
}).done(function(data) {
if (data.substr(0,5)=="Error") {
alert(data);
} else {
var pid=data.substring(data.indexOf("target=")+8,data.indexOf(\'"\',data.indexOf("target=")+8));
var dat=data.substring(0,data.indexOf("</a>"));
var pna=dat.substring(dat.lastIndexOf(\'">\')+2);
var pll=document.getElementById("playlistslist");
var r = document.createElement("INPUT");
var att = document.createAttribute("value");
att.value = pid;
r.setAttributeNode(att);
if (pll.childElementCount==0) {
var att = document.createAttribute("checked");
r.setAttributeNode(att);
}
att = document.createAttribute("type");
att.value = "radio";
r.setAttributeNode(att);
att = document.createAttribute("name");
att.value = "playlist";
r.setAttributeNode(att);
var l = document.createElement("LABEL");
var d = document.createElement("DIV");
var att = document.createAttribute("class");
att.value = "radio";
d.setAttributeNode(att);
var n = document.createTextNode(pna);
l.appendChild(r);
l.appendChild(n);
d.appendChild(l);
pll.appendChild(d);
$(".playlists").html($(".playlists").html()+data);
setTimeout(registerdelete,100);
setTimeout(registershowpl,100);
}
});
});
});</script>';
echo '<div class="row box"><div class="col-xs-12">';
echo '<div class="row" style="margin-top:10px;"><div class="col-xs-6">';
echo '<input class="form-control" type="text" value="" name="playlistname">';
echo '</div><div class="col-xs-1">';
echo '<input class="btn btn-primary" type="button" value="Add" name="addplaylist">';
echo '</div></div><div class="row"><div class="playlists col-xs-12">';
foreach ($result as $row) {
echo '<span><img class="delete" target="' . $row["ID"] . '" src="pix/delete.png" style="margin-right:10px;"/><a href="#'.$row["ID"].'" class="showplaylist">' . $row["Name"] . '</a><form action="'.$base.'/showplaylist.php" method="POST" style="display:inline;margin-left:5px;position:relative;top:7px;"><input type="hidden" name="playlist" value="'.$row["ID"] .'"><input type="submit" style="font-size:26px;background-color:transparent;border-style:none;position:relative;top:-4px;" Value="►"/></form><BR></span>';
echo '<div style="display:none;" id="playlist_'.$row["ID"].'">';
$plresult = $mysql->select("playlistentries", ["*"],"`Playlist`='".$row["ID"]."'");
foreach($plresult as $plrow) {
$plentry=$mysql->select("files",["*"],"`ID`='".$plrow["File"]."'");
echo $plrow["ID"]." ".$plentry[0]["Filename"]."<BR>";
}
echo '</div>';
}
echo '</div></div>';
echo '</div></div></div></body></html>';
}