-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupload.php
More file actions
367 lines (291 loc) · 9.22 KB
/
upload.php
File metadata and controls
367 lines (291 loc) · 9.22 KB
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
<?php
$basedir = "/opt/gsw/faceval/archives";
if($_POST['check'] == 1) {
process_form();
} else {
print_form(array());
}
function process_form() {
include('inc/getperms.php');
include('inc/functions.php');
$basedir = $GLOBALS['basedir'];
$lock = $GLOBALS['lock'];
$timestamp = time();
$highperm = 0;
foreach($permissions as $perm) {
if($perm > $highperm) {
$highperm = $perm;
}
}
$errors = array();
if($highperm < 3) {
array_push($errors, "You don't have permission to upload data");
}
if($_POST['oo'] == 1) {
$classtype = 'online';
} else if($_POST['oo'] == 2) {
$classtype = 'regular';
} else {
array_push($errors, "You didn't select a class type");
$classtype = '';
}
if($_POST['semester'] == '') {
array_push($errors, "You didn't select a semester");
}
$file_errors = array();
foreach($_FILES as $key => $file) {
if($file['error'] != 0) {
$fname = $file['name'];
$ferror = $file['error'];
array_push($errors, "Error uploading $fname ($key): $ferror");
if(file_exists($lock)) { unlink($lock); }
}
}
if(count($errors) > 0) {
print_error($errors);
return;
}
include_once('inc/mysql.php');
if($_POST['semester'] == 'existing') {
$semid = $_POST['sem_id'];
$cesm_sql = ""
. "SELECT *"
. " FROM semesters"
. " WHERE semester_id = $semid"
;
$cesm_res = mysql_query($cesm_sql);
if(!$cesm_res) {
die("Database error (semester check): " . mysql_error());
}
$row = mysql_fetch_assoc($cesm_res);
$semname = $row['semester_name'];
$semyear = $row['semester_year'];
} else {
$semname = $_POST['sem_name'];
$semyear = $_POST['sem_year'];
$semorder = $_POST['sem_order'];
$semyear = preg_replace('/[^0-9]/', "", $semyear);
$csem_sql = ""
. "SELECT *"
. " FROM semesters"
. " WHERE semester_name LIKE '$semname'"
. " AND semester_year = $semyear"
;
$csem_res = mysql_query($csem_sql);
if(!$csem_res) {
die("Database error (semester check): " . mysql_error());
}
if(mysql_num_rows($csem_res) == 0) {
$sidsql = ""
. "SHOW TABLE STATUS LIKE 'semesters'"
;
$sidres = mysql_query($sidsql);
if(!$sidres) {
die("Database error (semester id): " . mysql_error());
}
$row = mysql_fetch_assoc($sidres);
$semid = $row['Auto_increment'];
$nsem_sql = ""
. "INSERT INTO semesters"
. " (sem_order, semester_name, semester_year, active)"
. " VALUES ($semorder, '$semname', $semyear, 0)"
;
$nsem_res = mysql_query($nsem_sql);
if(!$nsem_res) {
die("Database error (insert semester): " . mysql_error());
}
} else {
$row = mysql_fetch_assoc($csem_res);
$semid = $row['semester_id'];
$semname = $row['semester_name'];
$semyear = $row['semester_year'];
}
}
$folder = ""
. $timestamp
. "_" . $semname
. "_" . $semyear
. "_" . $classtype
;
$workdir = "$basedir/$folder";
if(!is_dir($workdir)) {
mkdir($workdir, 0777, true);
}
foreach($_FILES as $key => $file) {
if($key == 'surveys') {
$ext = ".zip";
} else {
$ext = ".txt";
}
move_uploaded_file($file['tmp_name'], "$workdir/$key$ext");
}
include('inc/insidehead.php');
print <<<CONTENT
<h1>Success!</h1>
<p>
Your survey data files for <strong>$classtype</strong> classes in <strong>$semname of $semyear</strong> have been uploaded.
</p>
<p>
If the above information (semester and class type) is correct, <a href='verify.php?sid=$semid&ct=$classtype&ts=$timestamp'>click here</a> to verify the integrity of the data.
</p>
<p>
If anything is incorrect, <a onclick="history.go(-1);return false;" href="#">click here</a> to go back and make sure you filled in the form correctly.
</p>
CONTENT;
include('inc/insidefoot.php');
}
function print_form($errors) {
include('inc/insidehead.php');
print "<div id='content'>\n";
$highperm = 0;
foreach($permissions as $perm) {
if($perm > $highperm) {
$highperm = $perm;
}
}
if($highperm < 3) {
print "<h4>You don't have permission to upload data</h4>\n";
include("inc/insidefoot.php");
return;
}
$updir = $GLOBALS['updir'];
$lock = $GLOBALS['lock'];
$thisdoc = $_SERVER['PHP_SELF'];
$semopt = "";
$semsql = ""
. "SELECT *"
. " FROM semesters"
. " ORDER BY sem_order DESC"
;
include_once('inc/mysql.php');
$semres = mysql_query($semsql);
if(!$semres) {
die("Database error (semesters): " . mysql_error());
}
$semorder = 0;
$semcount = 0;
while($row = mysql_fetch_assoc($semres)) {
$opttxt = $row['semester_name'] . " " . $row['semester_year'];
$optvalue = $row['semester_id'];
$sodb = $row['sem_order'];
if($semorder < ($sodb + 1)) {
$semorder = $sodb + 1;
}
if($semcount == 0) {
$selected = " selected='true'";
} else {
$selected = "";
}
$semcount++;
$semopt .= "\n<option value='$optvalue'$selected>$opttxt</option>";
}
print <<<FORM
<h1>Upload files</h1>
<p>
After <a href="#prep">preparing your files</a>, use this form to upload them.
</p>
<p>
<form enctype='multipart/form-data' action='$thisdoc' method='post'>
<input type='hidden' name='check' value='1'/>
<input type='hidden' name='sem_order' value='$semorder'/>
<input type='hidden' name='MAX_FILE_SIZE' value='5242880'/>
Teachers Table: <input name='ttable' type='file'/><br/>
CRN-Course table: <input name='cctable' type='file'/><br/>
Surveys zip: <input name='surveys' type='file'/><br/>
Class type: <select name='oo'>
<option disabled='true' selected='true'>Select</option>
<option value='1'>Online</option>
<option value='2'>Regular</option>
</select><br/>
<input type='radio' name='semester' value='existing' id='sem_exist'/>Existing semester:
<select name='sem_id' onchange="document.getElementById('sem_exist').checked = true;">$semopt
</select><br/>
<input type='radio' name='semester' value='new' id='sem_new'/>New Semester:
<select name='sem_name' onchange="document.getElementById('sem_new').checked = true;">
<option value='Fall'>Fall</option>
<option value='Spring'>Spring</option>
</select>
<input name='sem_year' value='$thisyear' size='5' onchange="document.getElementById('sem_new').checked = true;"/><br/>
<input type='submit' value='upload'/>
</form>
</p>
<hr width='50%'/>
<a name='prep'/>
<h1>File preparation</h1>
<div class='left'>
<h2>Teachers table</h2>
<p>
The teachers table is a plain text file of <strong>tab-delimited</strong> information about the class instructors. The first line of this file should <strong>not contain field names</strong>, but should instead contain actual data. The fields are:
<ul>
<li>
<em>Instructor ID</em> - The instructor's GSW ID number
</li>
<li>
<em>Department ID</em> - The ID number of the department under which the course was taught
</li>
<li>
<em>Instructor name</em> - The name of the instructor <strong>in "lastname, firstname" format</strong>.
</li>
</ul>
Note that if an instructor taught classes for more than one department, there may be more than one row in the teachers table file attributed to that instructor. Here's an example of a teachers table file:
</p>
<p>
<img src='img/teachers.png'/>
</p>
<h2>CRN-Course table</h3>
<p>
The CRN-Course table is a plain text file of <strong>tab-delimted</strong> info about a the classes taught in a given semester. Just like the teachers table, the first line of this file should <strong>not contain field names</strong>. The fields in this file are:
<ul>
<li>
<em>Course CRN</em> - The CRN for the course
</li>
<li>
<em>Department ID</em> - The ID number for the department under which the course was taught
</li>
<li>
<em>Instructor ID</em> - The ID number for the instructor that taught the course
</li>
<li>
<em>Class name</em> - The shortened form of the name of the class, like "CIS 1000".
</li>
</ul>
Note that if a class was taught by more than one instructor, that CRN may be in the table more than once. Also, if an instructor taught more than one class (as they often do), there will be more than one entry in the table for that instructor. Here's an example of the CRN-Course table file:
</p>
<p>
<img src='img/crn-course.png'/>
</p>
<h2>Surveys zip file</h2>
<p>
The surveys zip file contains plain text files, which in turn contain information about the surveys taken for each class. Each text file should be named with the CRN of the class and have a ".txt" extension.
</p>
<p>
Here's how to create the zip file:
<ol>
<li>
Install a zip compression utility like <a href='http://www.7-zip.org/'>7-Zip</a> or <a href='http://www.winzip.com/'>WinZip</a>. I personally prefer 7-Zip because it's completely free and it's easy to use.
</li>
<li>
Open the directory that has the survey files. Make sure this directory contains <em>only survey text files</em>, and not either of the table files or any other foreign files. Hit ctrl-A to select all the files:
<p>
<img src='img/zipit-1.png'/>
</p>
</li>
<li>
Right-click on any one of the selected files. From the "7-Zip" submenu, click "Add to '<filename>.zip'" (note that "<filename>" will be replaced with the name of your current directory). If you're using WinZip, the menu items have different names, but the functionality is the same:
<p>
<img src='img/zipit-2.png'/>
</p>
</li>
<li>
You're done! There should be a file in your current directory that ends in ".zip"; that's the file you need to upload:
<p>
<img src='img/zipit-3.png'/>
</p>
</li>
</p>
</div>
FORM;
print "</div>";
include("inc/insidefoot.php");
}
?>