-
Notifications
You must be signed in to change notification settings - Fork 2
/
_batchimport.php
71 lines (68 loc) · 2.86 KB
/
_batchimport.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
<?php
require 'lib/global.php';
if(isset($_POST['barcode']) && isset($_POST['filename'])) {
// Check user
$user=$USER->getUser($_POST['uid']);
if($user['user_auth']>1) {
$barcode=filter_var($_POST['barcode'],FILTER_SANITIZE_STRING);
$filename=filter_var($_POST['filename'],FILTER_SANITIZE_STRING);
$parts=explode(',',$barcode);
if(count($parts)>1) {
// Second part of data, should be position barcode
$position=parsePosition($parts[1]);
if($position['type']='position') {
// This is a position barcode
// Validate plate (again) and position!
$plate=parseQuery($parts[0]);
if($plate['name']) {
$rack=getRack($position['rack_id']);
if(!$rack['error']) {
// Write plate,position combo the the end of the file
$fp=fopen("temp/$filename",'a');
if(fputcsv($fp,$parts)) {
$html='<code>'.$plate['name'].'</code> @ rack '.$rack['data']['rack_name'].' in storage '.$rack['storage']['storage_name'].' <code>'.$parts[1].'</code><br>';
$results=array('error' => FALSE, 'plate' => $plate['name'], 'position' => $parts[1], 'html' => $html);
} else {
$results=array('error' => 'Could not write to file', 'plate' => FALSE, 'position' => FALSE, 'html' => FALSE);
}
fclose($fp);
} else {
// Invalid position
$results=array('error' => $rack['error'], 'plate' => FALSE, 'position' => FALSE, 'html' => FALSE);
}
} else {
// This does not seem to be a valid plate barcode
$results=array('error' => 'Invalid plate barcode', 'plate' => FALSE, 'position' => FALSE, 'html' => FALSE);
}
} else {
// Second part does not match position barcode format
$results=array('error' => 'Second scan must be a position barcode', 'plate' => FALSE, 'position' => FALSE, 'html' => FALSE);
}
} else {
// This is the first part of the data
if(preg_match("/R[0-9]{4}X[0-9]{2}Y[0-9]{2}/",$barcode)) {
// This is a position barcode
// Return error message, plate is scanned first
$results=array('error' => 'Please begin with scanning the plate', 'plate' => FALSE, 'position' => FALSE, 'html' => FALSE);
} else {
// This is a plate barcode
// Validate plate
$plate=parseQuery($barcode);
if($plate['name']) {
// Send back plate ID and wait for position barcode
// Add back to form field and append a comma
$results=array('error' => FALSE, 'plate' => $plate['name'].',', 'position' => FALSE, 'html' => FALSE);
} else {
// This does not seem to be a valid plate barcode
$results=array('error' => 'Invalid plate barcode', 'plate' => FALSE, 'position' => FALSE, 'html' => FALSE);
}
}
}
} else {
$results=array('error' => 'Not authorized', 'plate' => FALSE, 'position' => FALSE, 'html' => FALSE);
}
} else {
$results=array('error' => 'Missing data', 'plate' => FALSE, 'position' => FALSE, 'html' => FALSE);
}
echo json_encode($results);
?>