-
Notifications
You must be signed in to change notification settings - Fork 6
/
barcodeTerminalAsync.php
executable file
·180 lines (161 loc) · 5.81 KB
/
barcodeTerminalAsync.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
<?php
/*
Copyright 2006-2018 Felix Rudolphi and Lukas Goossen
open enventory is distributed under the terms of the GNU Affero General Public License, see COPYING for details. You can also find the license under http://www.gnu.org/licenses/agpl.txt
open enventory is a registered trademark of Felix Rudolphi and Lukas Goossen. Usage of the name "open enventory" or the logo requires prior written permission of the trademark holders.
This file is part of open enventory.
open enventory is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
open enventory is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with open enventory. If not, see <http://www.gnu.org/licenses/>.
*/
require_once "lib_global_funcs.php";
require_once "lib_global_settings.php";
require_once "lib_db_query.php";
require_once "lib_db_manip.php";
require_once "lib_formatting.php";
require_once "lib_constants_barcode.php";
// print_r($_REQUEST);
$page_type="async";
$barcodeTerminal=true;
$success=false;
$barcodeData=array();
$output=$message="";
pageHeader();
function getSound($obj_name) {
global $g_settings;
if ($g_settings["barcode_sound"]) {
return
script."
parent.$(\"snd_".$obj_name."\").Play();
"._script;
}
}
echo script."
if (parent && parent!=self) {
";
// fake request for barcodeUser
$person_id=$_REQUEST["person_id"]??null;
$db_user=$_REQUEST["username"]??null;
list($own_data)=array_pad(mysql_select_array(array(
"table" => "person",
"filterDisabled" => true,
"filter" => "person.username=".fixStrSQL($db_user),
"dbs" => "-1",
"limit" => 1,
"noErrors" => true,
)),1,null);
if (is_array($own_data)) { // does the active user have sufficient privileges? Restrictions for user barcode remain in place. Does not work somehow...
$permissions=(($own_data["permissions"]??0) & $permissions)|_barcode_user;
} // no active user: use barcode user's rights to display info
$_REQUEST["table"]="chemical_storage";
$_REQUEST["db_id"]=-1;
// parameter: barcode=, table=
if (in_array($_REQUEST["desired_action"]??null,array("inventory","del"))) {
// => handleDesiredAction
}
elseif (!empty($_REQUEST["barcode"]??"")) {
$barcodeData=interpretBarcode($_REQUEST["barcode"],1);
//~ print_r($barcodeData);die();
$_REQUEST["pk"]=$barcodeData["pk"]??null;
switch ($barcodeData["table"]??null) {
case "mpi_order":
$url="edit.php?db_id=".$barcodeData["db_id"]."&".getSelfRef(array("~script~","table","db_id","pk","cached_query","no_cache"))."table=chemical_storage&mpi_order_id=".$barcodeData["pk"];
echo "window.open(".fixStr($url).");\n";
break;
case "person":
if (arrCount($barcodeData["result"])) {
echo "parent.setActivePerson(".json_encode($barcodeData["result"]).");\n"; // may also come from other db
$output.=getSound("login");
}
else {
echo "parent.setActivePerson();\n";
$output.=getSound("error");
}
break;
case "chemical_storage":
if ($_REQUEST["desired_action"]!="loadDataForInventory" && !empty($barcodeData["pk"])) {
$_REQUEST["desired_action"]="borrow";
if (!empty($barcodeData["result"]["borrowed_by_person_id"])) { // rückgabe
if (empty($person_id)) { // automatisches login auslösen für die person zum inventarisieren
list($person_result)=mysql_select_array(array(
"table" => "person",
"dbs" => "-1",
"filter" => "person.person_id=".fixNull($barcodeData["result"]["borrowed_by_person_id"]),
"limit" => 1,
));
$person_id=$person_result["person_id"];
$db_user=$person_result["username"];
$permissions=$person_result["permissions"]|_barcode_user;
echo "parent.setActivePerson(".json_encode($person_result).");\n";
}
$output.=getSound("zurueckgeben");
}
elseif ($_REQUEST["person_id"]) { // ausleihe
$_REQUEST["borrowed_by_db_id"]=$_REQUEST["person_db_id"];
$_REQUEST["borrowed_by_person_id"]=$_REQUEST["person_id"];
$output.=getSound("ausleihen");
}
else { // do nothing
$output.=getSound("error");
}
}
if (filter_var($_REQUEST["storage_permanent"]??false, FILTER_VALIDATE_BOOLEAN)) {
// just do not overwrite values in form
unset($barcodeData["result"]["storage_id"]);
unset($barcodeData["result"]["compartment"]);
}
break;
case "storage":
echo "parent.setStorage(".fixNull($barcodeData["pk"]??null).");
parent.doInventar();\n";
break;
default:
$_REQUEST["desired_action"]="";
}
}
else {
$_REQUEST["desired_action"]="";
}
// request vorbereitet
setGlobalVars();
/* echo "/*";
print_r($barcodeData);
print_r($_REQUEST);
echo "* /\n"; */
if (!empty($_REQUEST["desired_action"])) {
list($success,$message,$pks_added)=handleDesiredAction(); // schreiboperation durchführen
}
if (isEmptyStr($message) && !arrCount($barcodeData["result"]??null)) {
$message=s("no_results");
}
if ($_REQUEST["barcode"]??null) {
switch ($barcodeData["table"]??null) {
case "chemical_storage":
if ($success==SUCCESS && $_REQUEST["desired_action"]=="borrow") { // erspart erneute abfrage
$barcodeData["result"]["borrowed_by_person_id"]=$_REQUEST["borrowed_by_person_id"]??null;
}
echo "parent.setActiveChemicalStorage(".json_encode($barcodeData["result"]).");\n";
break;
}
}
if (!isEmptyStr($message)) {
echo "parent.showMessage(".fixStr($message).");\n";
}
echo "
}
"._script."
</head>
<body>
".
$output."
</body>
</html>";
completeDoc();
?>