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 pathadd_manager.php
executable file
·204 lines (161 loc) · 5.82 KB
/
add_manager.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
<?php
session_start();
#ignore_user_abort(true);
set_time_limit(0);
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");
$force_loggedin = TRUE;
require("include/check_login.php");
$dir=filter_var($_POST["dir"], FILTER_SANITIZE_URL);
$ColID=filter_var($_POST["ColID"], FILTER_SANITIZE_NUMBER_INT);
$SiteID=filter_var($_POST["SiteID"], FILTER_SANITIZE_NUMBER_INT);
$SensorID=filter_var($_POST["SensorID"], FILTER_SANITIZE_NUMBER_INT);
$codedyear=filter_var($_POST["codedyear"], FILTER_SANITIZE_STRING);
$codedmonth=filter_var($_POST["codedmonth"], FILTER_SANITIZE_STRING);
$codedday=filter_var($_POST["codedday"], FILTER_SANITIZE_STRING);
$codedhour=filter_var($_POST["codedhour"], FILTER_SANITIZE_STRING);
$codedminutes=filter_var($_POST["codedminutes"], FILTER_SANITIZE_STRING);
$codedseconds=filter_var($_POST["codedseconds"], FILTER_SANITIZE_STRING);
$sm=filter_var($_POST["sm"], FILTER_SANITIZE_NUMBER_INT);
$files_to_process_counter=filter_var($_POST["files_to_process_counter"], FILTER_SANITIZE_NUMBER_INT);
if ($dir=="") {
die("The server did not get which directory to use. Please go back and try again.");
}
#Make sure the path ends in a slash
if (substr($dir, -1) != "/") {
$dir = $dir . "/";
}
echo "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">
<html>
<head>
<title>$app_custom_name - Add files from the field</title>";
require("include/get_css.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>
<!--Blueprint container-->
<div class="container">
<?php
require("include/topbar.php");
?>
<div class="span-24 last">
<hr noshade>
</div>
<div class="span-24 last">
</div>
<div class="span-24 last">
<?php
if (is_dir($dir) && opendir($dir)) {
$handle = opendir($dir);
$files_to_process = array();
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
array_push($files_to_process, $file);
}
}
closedir($handle);
}
$cookie_to_test = $_COOKIE["usercookie"];
$cookie_to_testa = explode(".", $cookie_to_test);
$UserID = $cookie_to_testa['0'];
$query_1="INSERT INTO FilesToAdd (UserID, StartTime, FilesPath) VALUES ('$UserID', NOW(), '$dir')";
$result_1 = mysqli_query($connection, $query_1)
or die (mysqli_error($connection));
$ToAddID=mysqli_insert_id($connection);
if ($sm==1) {
$handle = opendir($dir);
$cc=1;
while (false !== ($file = readdir($handle)) && $cc==1) {
if ($file != "." && $file != "..") {
$afile=$file;
$cc=2;
}
}
closedir($handle);
$bfile=explode(".",$afile);
$ext_offset=strlen($bfile[1]);
#WA format: YYYMMDD_HHMMSS
}
else {
$codedyear1=explode(":",$codedyear);
$codedmonth1=explode(":",$codedmonth);
$codedday1=explode(":",$codedday);
$codedhour1=explode(":",$codedhour);
$codedminutes1=explode(":",$codedminutes);
$codedseconds1=explode(":",$codedseconds);
}
require("include/sox_formats_list.php");
$kk = 0;
for ($k=0;$k<$files_to_process_counter;$k++) {
$this_file=$files_to_process[$k];
if ($sm==1) {
$yearcoded = substr($this_file, -16 - $ext_offset, 4);
$monthcoded = substr($this_file, -12 - $ext_offset, 2);
$daycoded = substr($this_file, -10 - $ext_offset, 2);
$hourcoded = substr($this_file, -7 - $ext_offset, 2);
$minutescoded = substr($this_file, -5 - $ext_offset, 2);
$secondscoded = substr($this_file, -3 - $ext_offset, 2);
}
else {
$yearcoded = substr($this_file, $codedyear1[0]-1, $codedyear1[1]-$codedyear1[0]+1);
$monthcoded = substr($this_file, $codedmonth1[0]-1, $codedmonth1[1]-$codedmonth1[0]+1);
$daycoded = substr($this_file, $codedday1[0]-1, $codedday1[1]-$codedday1[0]+1);
$hourcoded = substr($this_file, $codedhour1[0]-1, $codedhour1[1]-$codedhour1[0]+1);
$minutescoded = substr($this_file, $codedminutes1[0]-1, $codedminutes1[1]-$codedminutes1[0]+1);
$secondscoded = substr($this_file, $codedseconds1[0]-1, $codedseconds1[1]-$codedseconds1[0]+1);
}
$datecoded=$yearcoded . "-" . $monthcoded . "-" . $daycoded;
$timecoded=$hourcoded . ":" . $minutescoded . ":" . $secondscoded;
$DirID = rand(1,100);
$file_path = $dir . $this_file;
#Check that the extension is a valid sound file
#Quick check to avoid adding non-sound files
$ext = pathinfo($this_file, PATHINFO_EXTENSION);
if (in_array(strtolower($ext), $sox_formats)){
$query_to_insert="INSERT INTO FilesToAddMembers (FilesToAddID, FullPath, OriginalFilename, Date, Time, SiteID, ColID, DirID, SensorID)
VALUES ('$ToAddID', '$file_path', '$this_file', '$datecoded', '$timecoded', '$SiteID', '$ColID', '$DirID', '$SensorID')";
#echo "Query: $query_to_insert<br>";
$result = mysqli_query($connection, $query_to_insert)
or die (mysqli_error($connection));
$kk = $kk+1;
}
}
$CollectionName=query_one("SELECT CollectionName from Collections WHERE ColID='$ColID'", $connection);
echo "<br><div class=\"success\">$kk sound files were scheduled to be added to the collection $CollectionName.</div>
<p><a href=\"add.php\">Add more files</a> or <a href=\"file_manager.php\">check file status</a>.";
?>
</div>
<div class="span-24 last">
</div>
<div class="span-24 last">
<?php
require("include/bottom.php");
?>
</div>
</div>
<?php
session_write_close();
flush(); @ob_flush();
if ($special_noprocess == FALSE){
add_in_background($absolute_dir, $connection);
}
?>
</body>
</html>