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
/
Copy pathmanagemarks.php
executable file
·192 lines (141 loc) · 6.11 KB
/
managemarks.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
<?php
session_start();
require("include/functions.php");
$config_file = 'config.php';
if (file_exists($config_file)) {
require("config.php");
} else {
header("Location: error.php?e=config");
die();
}
require("include/apply_config.php");
if (!isset($_GET["Token"])){
echo "<!DOCTYPE html>
<html>
<head>
<title>$app_custom_name - Manage Marks</title>";
#Get CSS
require("include/get_css3.php");
require("include/get_jqueryui.php");
if ($use_googleanalytics){
echo $googleanalytics_code;
}
#Execute custom code for head, if set
if (is_file("$absolute_dir/customhead.php")) {
include("customhead.php");
}
echo "
</head>
<body>
<div style = \"padding: 10px;\">";
echo "<div class=\"alert alert-danger\">The ID is not valid.</div>
<hr noshade>
<p><a href=\"#\" onClick=\"opener.location.reload();window.close();\">Close window</a>
</div>
</body>
</html>";
die();
}
$Token = filter_var($_GET["Token"], FILTER_SANITIZE_STRING);
$username = $_COOKIE["username"];
$UserID = query_one("SELECT UserID FROM Users WHERE UserName='$username'", $connection);
$valid_token = query_one("SELECT COUNT(*) FROM Tokens WHERE TokenID='$Token' AND UserID='$UserID'", $connection);
if ($valid_token==1) {
$soundfile_format = query_one("SELECT soundfile_format FROM Tokens WHERE TokenID='$Token' LIMIT 1", $connection);
$soundfile_duration = query_one("SELECT soundfile_duration FROM Tokens WHERE TokenID='$Token' LIMIT 1", $connection);
$soundfile_name = query_one("SELECT soundfile_name FROM Tokens WHERE TokenID='$Token' LIMIT 1", $connection);
$soundfile_wav = query_one("SELECT soundfile_wav FROM Tokens WHERE TokenID='$Token' LIMIT 1", $connection);
$soundfile_id = query_one("SELECT soundfile_id FROM Tokens WHERE TokenID='$Token' LIMIT 1", $connection);
$no_channels = query_one("SELECT no_channels FROM Tokens WHERE TokenID='$Token' LIMIT 1", $connection);
$soundfile_samplingrate = query_one("SELECT soundfile_samplingrate FROM Tokens WHERE TokenID='$Token' LIMIT 1", $connection);
$soundfile_samplingrateoriginal = query_one("SELECT soundfile_samplingrateoriginal FROM Tokens WHERE TokenID='$Token' LIMIT 1", $connection);
$random_cookie = query_one("SELECT random_cookie FROM Tokens WHERE TokenID='$Token' LIMIT 1", $connection);
$from_db = query_one("SELECT from_db FROM Tokens WHERE TokenID='$Token' LIMIT 1", $connection);
}
#Check if fft size is set
if (isset($_COOKIE["fft"])){
$fft_size = $_COOKIE["fft"];
}
else{
$fft_size = 2048;
}
#Check if user can edit files
$force_loggedin = TRUE;
require("include/check_login.php");
$SoundID = $soundfile_id;
if (isset($_GET["d"])){
$d = filter_var($_GET["d"], FILTER_SANITIZE_NUMBER_INT);
$mark_todel = filter_var($_GET["marks_id"], FILTER_SANITIZE_NUMBER_INT);
}
else{
$d = FALSE;
}
if ($d) {
$result = mysqli_query($connection, "DELETE FROM SoundsMarks WHERE marks_ID='$mark_todel' LIMIT 1")
or die (mysqli_error($connection));
}
echo "<!DOCTYPE html>
<html>
<head>
<title>$app_custom_name - Manage Marks</title>";
#Get CSS
require("include/get_css3.php");
require("include/get_jqueryui.php");
if ($use_googleanalytics){
echo $googleanalytics_code;
}
#Execute custom code for head, if set
if (is_file("$absolute_dir/customhead.php")) {
include("customhead.php");
}
?>
</head>
<body>
<div style="padding: 10px;">
<?php
$result = mysqli_query($connection, "SELECT SoundName FROM Sounds WHERE SoundID='$SoundID' LIMIT 1")
or die (mysqli_error($connection));
$row = mysqli_fetch_array($result);
extract($row);
echo "<h4>Marks in the database for the file $SoundName (ID: $SoundID):</h4>";
$resultm = mysqli_query($connection, "SELECT marks_ID FROM SoundsMarks WHERE SoundID='$SoundID' ORDER BY marks_ID")
or die (mysqli_error($connection));;
$nrowsm = mysqli_num_rows($resultm);
if ($nrowsm>0){
echo "<table>";
$nyquist = $soundfile_samplingrateoriginal/2;
exec('include/svt.py -s tmp/' . $random_cookie . '/marks-spectrogram.png -w 400 -h 180 -m ' . $nyquist . ' -f ' . $fft_size . ' -p ' . $spectrogram_palette . ' tmp/' . $random_cookie . '/' . $soundfile_wav, $lastline, $retval);
for ($w = 0; $w < $nrowsm; $w++){
$rowm = mysqli_fetch_array($resultm);
extract($rowm);
//Query for the last mark edit
$res = mysqli_query($connection, "SELECT marks_ID, SoundID AS mark_fileID, time_min AS mark_time_min, time_max AS mark_time_max, freq_min AS mark_freq_min, freq_max AS mark_freq_max, mark_tag FROM SoundsMarks WHERE marks_ID='$marks_ID' LIMIT 1");
$row = mysqli_fetch_array($res);
extract($row);
unset($row);
$viewport_box_low = round(180 - ((($mark_freq_min-10) / $nyquist) * 180));
$viewport_box_high = round((($nyquist-$mark_freq_max) / $nyquist) * 180);
$viewport_box_left = round(($mark_time_min/$soundfile_duration) * 400);
$viewport_box_right = round(($mark_time_max/$soundfile_duration) * 400);
$viewport_box_width = round($viewport_box_right-$viewport_box_left);
$viewport_box_height = round($viewport_box_low-$viewport_box_high);
//Mark
echo "<tr><td><a href=\"editmarks.php?Token=$Token&markID=$marks_ID\"><span title=\"Edit\" class=\"glyphicon glyphicon-pencil\" aria-hidden=\"true\"></span></a> $mark_tag_name: $mark_tag (ID:$marks_ID) | Time: $mark_time_min - $mark_time_max sec | Frequency: $mark_freq_min - $mark_freq_max Hz <a href=\"managemarks.php?Token=$Token&marks_id=$marks_ID&d=1\"><span class=\"glyphicon glyphicon-remove-circle\" title=\"Delete\" aria-hidden=\"true\"></a><br><br>\n";
exec("convert -stroke red -fill none -draw \"rectangle " . $viewport_box_left . "," . $viewport_box_high. " " . $viewport_box_right . "," . $viewport_box_low . "\" tmp/" . $random_cookie . "/marks-spectrogram.png tmp/" . $random_cookie . "/marks-spectrogram" . $w . ".png", $lastline, $retval);
if ($retval != 0) {
echo "<div class=\"error\">There was a problem with ImageMagick...</div>";
die();
}
echo "<img src=\"tmp/" . $random_cookie . "/marks-spectrogram" . $w . ".png\" style=\"margin-left: 20px;\"><br><br></td></tr>";
}
echo "</table>";
}
else{
echo "<p>This file has no marks.";
}
?>
<hr noshade>
<p><a href="#" onClick="opener.location.reload();window.close();">Close window</a>
</div>
</body>
</html>