This repository has been archived by the owner on Oct 29, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
browse_site.php
executable file
·482 lines (378 loc) · 12.1 KB
/
browse_site.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
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
<?php
session_start();
header( 'Content-type: text/html; charset=utf-8' );
require("include/functions.php");
$config_file = 'config.php';
if (file_exists($config_file)) {
require($config_file);
}
else {
header("Location: error.php?e=config");
die();
}
require("include/apply_config.php");
require("include/check_login.php");
use \DByte\DB;
DB::$c = $pdo;
#Sanitize inputs
$SiteID=filter_var($_GET["SiteID"], FILTER_SANITIZE_NUMBER_INT);
#Check if site has files or is valid
$valid_id = DB::column('SELECT COUNT(*) FROM `Sounds` WHERE SiteID = ' . $SiteID);
if ($valid_id == 0) {
echo "<!DOCTYPE html>
<html lang=\"en\">
<head>
<title>$app_custom_name - Error</title>\n";
require("include/get_css3.php");
echo "<body>
<div class=\"alert alert-danger\"><span class=\"glyphicon glyphicon-alert\" aria-hidden=\"true\"></span> The site requested does not exists or it has no recordings. Please go back and try your query again.</div>
</body>
</html>";
die();
}
#Display type saved as a cookie
#NOW only gallery
/*if (isset($_GET["display_type"])){
$display_type = filter_var($_GET["display_type"], FILTER_SANITIZE_STRING);
}
else{
$display_type = "gallery";
}
*/
$display_type = "gallery";
if (isset($_GET["startid"])){
$startid=filter_var($_GET["startid"], FILTER_SANITIZE_NUMBER_INT);
}
else{
$startid=1;
}
if (isset($_GET["order_by"])){
$order_by=filter_var($_GET["order_by"], FILTER_SANITIZE_STRING);
}
else{
$order_by = "Date";
}
if (isset($_GET["order_dir"])){
$order_dir=filter_var($_GET["order_dir"], FILTER_SANITIZE_STRING);
}
else{
$order_dir = "ASC";
}
if ($order_by=="Date"){
$order_byq = "Date $order_dir, Time $order_dir ";
}
elseif ($order_by=="SoundName"){
$order_byq = "SoundName $order_dir";
}
#If user is not logged in, add check for QF
if ($pumilio_loggedin==FALSE) {
$qf_check = "AND Sounds.QualityFlagID>='$default_qf'";
}
else {
$qf_check = "";
}
echo "<!DOCTYPE html>
<html lang=\"en\">
<head>
<title>$app_custom_name - Browse Sounds at a Site</title>";
require("include/get_css3.php");
require("include/get_jqueryui.php");
#require("include/nocache.php");
#Multiple delete script to select all
echo "
<SCRIPT language=\"javascript\">
$(function(){
// add multiple select / deselect functionality
$(\"#selectall\").click(function () {
$('.case').attr('checked', this.checked);
});
// if all checkbox are selected, check the selectall checkbox
// and viceversa
$(\".case\").click(function(){
if($(\".case\").length == $(\".case:checked\").length) {
$(\"#selectall\").attr(\"checked\", \"checked\");
} else {
$(\"#selectall\").removeAttr(\"checked\");
}
});
});
</SCRIPT>";
?>
<?php
$query_all_tags = "SELECT DISTINCT Tag FROM Tags";
$result_all_tags=query_several($query_all_tags, $connection);
$nrows_all_tags = mysqli_num_rows($result_all_tags);
if ($nrows_all_tags>0) {
/*
#Deprecated
echo "
<!-- JQuery Autocomplete http://docs.jquery.com/Plugins/Autocomplete -->
<script type=\"text/javascript\" src=\"$app_url/js/jquery/jquery.autocomplete.pack.js\"></script>";
*/
echo "<script type=\"text/javascript\">
$(function() {
var mytags = [ ";
for ($a=0; $a<($nrows_all_tags - 1); $a++) {
$row_all_tags = mysqli_fetch_array($result_all_tags);
extract($row_all_tags);
echo "\"$Tag\", ";
}
for ($a=$nrows_all_tags - 1; $a<$nrows_all_tags; $a++) {
$row_all_tags = mysqli_fetch_array($result_all_tags);
extract($row_all_tags);
echo "\"$Tag\"";
}
echo "];
$( \"#newtag\" ).autocomplete({
source: mytags
});
});
</script>
";
}
?>
<!--jquery form-->
<!-- http://jquery.malsup.com/form/ -->
<?php
echo "<script type=\"text/javascript\" src=\"$app_url/js/jquery.form.js\"></script>\n";
for ($ajaxi = 0; $ajaxi < 10; $ajaxi++) {
echo "
<script type=\"text/javascript\">
$(document).ready(function() {
var options = {
target: '#tagspace$ajaxi', // target element(s) to be updated with server response
// beforeSubmit: showRequest, // pre-submit callback
// success: showResponse, // post-submit callback
clearForm: true,
resetForm: true
};
// bind form using 'ajaxForm'
$('#addtags$ajaxi').ajaxForm(options);
});
</script>
";
}
?>
<?php
if ($use_googleanalytics){
echo $googleanalytics_code;
}
?>
<!-- Hide success messages -->
<script type="text/javascript">
$(function() {
// setTimeout() function will be fired after page is loaded
// it will wait for 5 sec. and then will fire
// $("#successMessage").hide() function
setTimeout(function() {
$("#md").hide('blind', {}, 500)
}, 5000);
});
</script>
<?php
#Execute custom code for head, if set
if (is_file("$absolute_dir/customhead.php")) {
include("customhead.php");
}
#Leaflet
echo "\n<link rel=\"stylesheet\" href=\"libs/leaflet/leaflet.css\" />\n
<style>
#map { height: 220px;
width: 320px;
}
</style>";
?>
</head>
<body>
<?php
echo "<!--Blueprint container-->
<div class=\"container\">";
require("include/topbar.php");
#Loading... message
require("include/loadingtop.php");
$query = "SELECT * from Sites WHERE SiteID=$SiteID";
$result = mysqli_query($connection, $query)
or die (mysqli_error($connection));
$row = mysqli_fetch_array($result);
extract($row);
//How many sounds associated with that source
$no_sounds=query_one("SELECT COUNT(*) as no_sounds FROM Sounds WHERE SiteID='$SiteID'
AND Sounds.SoundStatus!='9' $qf_check", $connection);
if ($startid < 1) {
$startid = 1;
}
$startid_q = $startid - 1;
if ($display_type == "summary"){
$how_many_to_show = 10;}
elseif ($display_type == "gallery"){
$how_many_to_show = 36;}
$endid = $how_many_to_show;
$endid_show = $startid_q + $endid;
if ($startid_q + $how_many_to_show >= $no_sounds) {
$endid_show = $no_sounds;}
$sql_limit = "$startid_q, $endid";
echo "
<div class=\"page-header\">
<div class=\"row\">
<div class=\"col-lg-8\">
<h2>Sounds at the Site: $SiteName</h2>
<p>Coordinates: $SiteLat, $SiteLon</p>
<p>$no_sounds sounds at this site</p>
</div>
<div class=\"col-lg-4\">
<div id=\"map\"></div>
</div>
</div>
</div>
<div class=\"row\">
<div class=\"col-lg-4\">";
/*if (sessionAuthenticate($connection) || !$hide_latlon_guests) {
#echo "Coordinates: $SiteLat, $SiteLon | <a href=\"viewsite_map.php?SiteID=$SiteID\" title=\"View site in a map\"><strong>Map</strong></a>";
echo "Coordinates: $SiteLat, $SiteLon";
}
else {
#echo "<a href=\"viewsite_map.php?SiteID=$SiteID\" title=\"View site in a map\"><strong>Map</strong></a>";
}*/
if (sessionAuthenticate($connection) && is_user_admin2($username, $connection)) {
echo "<br><a href=\"edit_site.php?SiteID=$SiteID\" title=\"Edit this Site\">[edit site]</a>";
}
#Select particular date
/*$query_dates = "SELECT DISTINCT DATE_FORMAT(Date,'%d-%b-%Y') AS Date_f, Date FROM Sounds
WHERE Date IS NOT NULL AND SiteID='$SiteID' AND Sounds.SoundStatus!='9' $qf_check ORDER BY Date";
$result_dates=query_several($query_dates, $connection);
$nrows_dates = mysqli_num_rows($result_dates);
if ($nrows_dates>0) {
if ($special_wrapper==TRUE){
echo "<form action=\"$wrapper\" method=\"GET\">
<input type=\"hidden\" name=\"page\" value=\"browse_site_date\">";
}
else {
echo "<form action=\"browse_site_date.php\" method=\"GET\">";
}
echo "Filter by date:
<select name=\"Date\" class=\"ui-state-default ui-corner-all\">
<option value=\"\">All dates</option>";
for ($d=0;$d<$nrows_dates;$d++) {
$row_dates = mysqli_fetch_array($result_dates);
extract($row_dates);
echo "\n<option value=\"$Date\">$Date_f</option>";
}
echo "</select>
<input type=\"hidden\" name=\"SiteID\" value=\"$SiteID\">
<input type=submit value=\" Select \" class=\"fg-button ui-state-default ui-corner-all\">
</form>";
}*/
?>
</div>
<div class="col-lg-6">
<?php
#count and next
echo "<dl class=\"dl-horizontal\"><dt>Results</dt><dd>$startid to $endid_show of $no_sounds</dd></dl>";
?>
</div>
<div class="col-lg-1 center">
<?php
#Order by sound name
echo "Name<br><a href=\"browse_site.php?SiteID=$SiteID&order_by=SoundName&order_dir=ASC\"><span class=\"glyphicon glyphicon-triangle-bottom\" aria-hidden=\"true\"></span></a> <a href=\"browse_site.php?SiteID=$SiteID&order_by=SoundName&order_dir=DESC\"><span class=\"glyphicon glyphicon-triangle-top\" aria-hidden=\"true\"></span></a>";
?>
</div>
<div class="col-lg-1 center">
<?php
#Order by sound date
echo "Date<br><a href=\"browse_site.php?SiteID=$SiteID&order_by=Date&order_dir=ASC\"><span class=\"glyphicon glyphicon-triangle-bottom\" aria-hidden=\"true\"></span></a> <a href=\"browse_site.php?SiteID=$SiteID&order_by=Date&order_dir=DESC\"><span class=\"glyphicon glyphicon-triangle-top\" aria-hidden=\"true\"></span></a>";
?>
</div>
</div>
<?php
#Confirm delete
if (isset($_GET["md"])){
$md=filter_var($_GET["md"], FILTER_SANITIZE_NUMBER_INT);
if ($md == 1){
echo "<div <div class=\"success\" id=\"md\">One file was deleted.</div>";
}
else{
echo "<div <div class=\"success\" id=\"md\">$md files were deleted.</div>";
}
}
$query = "SELECT *, DATE_FORMAT(Date, '%d-%b-%Y') AS Date_h FROM Sounds WHERE SiteID='$SiteID'
AND Sounds.SoundStatus!='9' $qf_check ORDER BY $order_byq LIMIT $sql_limit";
#print $query;
$result=query_several($query, $connection);
$nrows = mysqli_num_rows($result);
$check_result=query_several($query, $connection);
if ($nrows>0) {
if ($display_type=="summary") {
require("include/view_summary.php");
}
elseif ($display_type=="gallery") {
require("include/view_gallery.php");
}
}
echo "<div class=\"row\"><div class=\"col-lg-12\"><hr noshade></div></div>";
#Pagination
if ($startid < 1){
$prev = -1;
$startid = 1;
$next = $startid + $how_many_to_show;
}
else{
$prev = $startid - $how_many_to_show;
$next = $startid + $how_many_to_show;
}
if ($next > $no_sounds){
$next = $no_sounds;
}
if (($startid + $how_many_to_show) > $no_sounds){
$next = "NA";
}
echo "<nav class=\"text-center\">
<ul class=\"pagination pagination-sm\">";
if ($prev > -1){
echo "<li>
<a href=\"browse_site.php?SiteID=$SiteID&startid=$prev\" aria-label=\"Previous\">
<span aria-hidden=\"true\">«</span>
</a>
</li>\n";
}
$prevellipsis = FALSE;
$nextellipsis = FALSE;
$pages = ceil($no_sounds / $how_many_to_show);
for ($p=1; $p < ($pages + 1); $p++) {
$this_page = ($p - 1) * $how_many_to_show + 1;
if ($this_page == $startid){
echo "<li class=\"active\"><a href=\"browse_site.php?SiteID=$SiteID&startid=$this_page\">$p <span class=\"sr-only\">(current)</span></a></li>";
}
else{
if ($this_page < ($startid - 120)){
if ($prevellipsis == FALSE){
echo "<li><span aria-hidden=\"true\">...</span></li>";
$prevellipsis = TRUE;
}
}
elseif ($this_page > ($startid + 120)){
if ($nextellipsis == FALSE){
echo "<li><span aria-hidden=\"true\">...</span></li>";
$nextellipsis = TRUE;
}
}
else{
echo "<li><a href=\"browse_site.php?SiteID=$SiteID&startid=$this_page\">$p</a></li>";
}
}
}
if ($next != "NA"){
echo "<li>
<a href=\"browse_site.php?SiteID=$SiteID&startid=$next\" aria-label=\"Next\">
<span aria-hidden=\"true\">»</span>
</a>
</li>\n";
}
echo "</ul></nav>";
#}
require("include/bottom.php");
#Loading... message
require("include/loadingbottom.php");
require("include/leaflet1.php");
?>
</body>
</html>