/
index.php
247 lines (241 loc) · 7.33 KB
/
index.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
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
<?php
function __autoload($class_name) {
require_once $class_name . '.php';
}
$user = new User();
$connection = new Connection();
$webpage = new Webpage("ConAsset inventory management system");
//$asset = new Asset($connection);
try{
if(isset($_GET['action']) && isset($_GET['type'])) {
if($_GET['type'] == 'asset') {
$asset = new Asset($connection);
if(isset($_POST['submit'])) {
if($_GET['action'] == 'add') {
$asset->loadFromPage();
$asset->insert();
} else if($_GET['action'] == 'edit'){
$asset->loadFromPage();
$asset->update();
} else if ($_GET['action'] == 'checkout') {
if(User::exists($_POST['checkoutTo'],$connection)){
$asset->loadEntry($_POST['barcode']);
$asset->setCheckoutTo($_POST['checkoutTo']);
$asset->update();
$asset->printForm('checkout');
}else{
echo "User {$_POST['checkoutTo']} does not exist";
}
} else if ($_GET['action'] == 'batchcheckout'){
if(User::exists($_POST['checkoutTo'],$connection)){
$barcodes = $_POST['barcodes'];
foreach ($barcodes as $barcode){
$asset->loadEntry($barcode);
$asset->setCheckoutTo($_POST['checkoutTo']);
$asset->update();
}
$asset->printForm('batchcheckout');
}else{
echo "User {$_POST['checkoutTo']} does not exist";
}
} else if($_GET['action'] == 'find') {
$asset->findAsset($_POST['barcode']);
} else if($_GET['action'] == 'checkin') {
$asset->loadEntry($_POST['barcode']);
$asset->printForm('checkin2');
} else if($_GET['action'] == 'checkin2'){
$asset->loadEntry($_POST['barcode']);
$asset->loadEntry($_POST['barcode']);
$asset->setCheckoutTo('');
$asset->setBox($_POST['box']);
$asset->update();
$asset->printForm('checkin');
}
} else {
if($_GET['action'] == 'find') {
$asset->printFindForm();
} else if($_GET['action'] == 'delete') {
if(isset($_GET['confirm'])) {
$asset->deleteAsset($_GET['barcode']);
} else {
$barcode = $_GET['barcode'];
echo "<br><center>Are you sure?<br>
<a href=\"index.php?action=delete&type=asset&barcode=$barcode&confirm=yes\">Yes</a>
<a href=\"index.php\">No</a>
</center>";
}
} else if($_GET['action'] == 'edit') {
$asset->loadEntry($_GET['barcode']);
$asset->printForm($_GET['action']);
} else {
$asset->printForm($_GET['action']);
}
}
}
if($_GET['type'] == 'assettype') {
$assettype = new AssetType($connection);
if(isset($_POST['submit'])) {
if($_GET['action'] == 'add') {
$assettype->loadFromPage();
$assettype->insert();
} else if($_GET['action'] == 'edit') {
$assettype->loadFromPage();
$assettype->update();
}
} else {
if($_GET['action'] == 'list') {
$assettype->listAll();
} else if($_GET['action'] == 'delete') {
if(isset($_GET['confirm'])) {
$assettype->deleteAssetType($_GET['index']);
} else {
$index = $_GET['index'];
echo "<br><center>Are you sure?<br>
<a href=\"index.php?action=delete&type=assettype&index=$index&confirm=yes\">Yes</a>
<a href=\"index.php\">No</a>
</center>";
}
} else if($_GET['action'] == 'use') {
$_SESSION['itemtype'] = $_GET['index'];
} else if($_GET['action'] == 'edit') {
$assettype->loadEntry($_GET['index']);
$assettype->printForm($_GET['action']);
} else if($_GET['action'] == 'listByType') {
$assettype->listByType($_GET['index']);
} else {
$assettype->printForm($_GET['action']);
}
}
}
if($_GET['type'] == 'box') {
$box = new Box($connection);
/*echo '<pre>';
nl2br(var_dump($_POST));
echo '</pre>';
*/
if(isset($_POST['submit']))
{
if($_GET['action'] == 'add') {
$box->loadFromPage();
$box->insert();
} else if($_GET['action'] == 'edit') {
$box->loadFromPage();
$box->update();
} else if($_GET['action'] == 'find') {
$box->findBox($_POST['barcode']);
} else if($_GET['action'] == 'checkout') {
$connection->query("SELECT a_barcode FROM assets WHERE a_box = '{$_POST['barcode']}' and a_checkout_to = ''");
if($connection->result_size() <= 0){
throw new Exception('no assets or all assets checked out inside box with barcode: ' .$_POST['barcode']);
}
$barcodes = array();
while($row = $connection->fetch_row()) {
$barcodes[] = $row[0];
}
foreach($barcodes as $barcode){
$the_asset = new Asset($connection);
$the_asset->loadEntry($barcode);
$the_asset->setCheckoutTo($connection->validate_string($_POST['checkoutTo']));
$the_asset->update();
}
} else if($_GET['action'] == 'batchmove'){
$location = new Location($connection);
$location->loadEntry($_POST['location']);
$barcodes = $_POST['barcodes'];
foreach ($barcodes as $barcode){
$box->loadEntry($barcode);
$box->setLocation($location->getIndex());
$box->update();
}
$box->printForm('batchmove');
}
} else {
if($_GET['action'] == 'find') {
$box->printFindForm();
} else if($_GET['action'] == 'delete') {
if(isset($_GET['confirm'])) {
$box->deleteBox($_GET['barcode']);
} else {
$barcode = $_GET['barcode'];
echo "<br><center>Are you sure?<br>
<a href=\"index.php?action=delete&type=box&barcode=$barcode&confirm=yes\">Yes</a>
<a href=\"index.php\">No</a>
</center>";
}
} else if($_GET['action'] == 'list'){
$box->listBoxes();
} else if($_GET['action'] == 'view'){
$box->loadEntry($_GET['barcode']);
$box->printForm($_GET['action']);
} else if($_GET['action'] == 'edit') {
$box->loadEntry($_GET['barcode']);
$box->printForm($_GET['action']);
} else {
$box->printForm($_GET['action']);
}
}
}
if($_GET['type'] == 'location') {
$location = new Location($connection);
if(isset($_POST['submit'])) {
if($_GET['action'] == 'add') {
$location->loadFromPage();
$location->insert();
} else if($_GET['action'] == 'edit') {
$location->loadFromPage();
$location->update();
}
} else {
if($_GET['action'] == 'edit') {
$location->loadEntry($_GET['index']);
}
$location->printForm($_GET['action']);
}
}
}
}catch(Exception $e){
echo "ERROR: " . $e->getMessage();
}
echo "
<center>
<br><br>";
$webpage->addURL("index.php?action=add&type=asset",
"Add a new asset");
echo "<br>";
$webpage->addURL("index.php?action=find&type=asset",
"Search for an Assest by barcode");
echo "<br>";
$webpage->addURL("index.php?action=add&type=assettype",
"Create new asset type");
echo "<br>";
$webpage->addURL("index.php?action=list&type=assettype",
"List avalible asset types");
echo "<br>";
$webpage->addURL("index.php?action=add&type=box",
"Create new box entry");
echo "<br>";
$webpage->addURL("index.php?action=list&type=box",
"List Boxes");
echo "<br>";
$webpage->addURL("index.php?action=find&type=box",
"Search for a box by barcode");
echo "<br>";
$webpage->addURL("index.php?action=add&type=location",
"Add a new location");
echo "<br>";
$webpage->addURL("index.php?action=checkout&type=asset",
"Checkout an Asset");
echo "<br>";
$webpage->addURL("index.php?action=batchcheckout&type=asset",
"Batch checkout Assets");
echo "<br>";
$webpage->addURL("index.php?action=checkout&type=box",
"Checkout all items in Box");
echo "<br>";
$webpage->addURL("index.php?action=batchmove&type=box",
"Move multiple Boxes to one location (Batch move)");
echo "<br>";
$webpage->addURL("index.php?action=checkin&type=asset",
"Checkin an Asset");
echo "</center>";
?>