forked from k493r0/EqManage
-
Notifications
You must be signed in to change notification settings - Fork 0
/
manageEq.php
413 lines (350 loc) · 13.6 KB
/
manageEq.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
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
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
<?php
session_start();
if(!isset($_SESSION['loggedin'])){
header('Location: login.php');
exit();
}
if ($_SESSION['username'] != 'administrator'){
header('Location: index.php?adminonly=1');
}
?>
<!DOCTYPE html>
<html>
<?php
include('header.php')
?>
<body class="form-v8 loggedin" id="fade">
<div id="loader">
<div class="loader"><div></div><div></div><div></div><div></div></div>
</div>
<?php
if ($_SESSION['username'] == 'administrator'){
include ('adminNavbar.php');
} else{
include ('navbar.php');
}
include('serverconnect.php');
?>
<div class="content">
<div style="height: 63px; opacity: 0; padding: 0; margin: 0" ></div>
<div id="addAlert" style="color: green;" class="name">Equipment Added</div>
<div id="removeAlert" style="color: red;" class="name">Equipment Removed</div>
<div id="removeCatAlert" style="color: red;" class="name">Category Removed</div>
<div style="padding-top: 0;">
<h2 style="padding-bottom: 10px; margin-bottom: 20px">Manage Equipment</h2>
<!-- Trigger/Open The Modal -->
<h1 style="font-weight: bold; margin-top: 30px; margin-bottom: 10px; text-align: center"><u>Equipment</u></h1>
<div id="wrapper" style="box-shadow: none;"><button id="addEqBtn" class="btn">Add Equipment</button></div>
<!-- The Modal -->
<div id="addEqModal" class="modal">
<!-- Modal content -->
<div class="modal-content" style="width: fit-content">
<div onclick="hideEqModal()">
<span class="close" style="margin-bottom: 10px; float: left">×</span>
</div>
<?php
$resultset = mysqli_query($db, "select * from EqManage.categories");
?>
<div class="select-style" style="width:500px; margin: auto;" align="center">
<input type="text" name="name" placeholder="Equipment Name" id="name" required/>
Quantity: <input type="number" min="1" max="100" name="quantity" value="1" id="qty" style="margin-top: 5px;margin-bottom: 5px" required/>
<div id="categorySelect"></div>
<!-- <textarea type="text" id="purpose" name="purpose" placeholder="Purpose/Location/Date to be returned" style="padding: 10px 15px; border: 1px solid #ccc;-->
<!-- border-radius: 4px; margin-top: 10px"></textarea>-->
<div class="panel-body" align="center" id="upload-div">
<strong>Upload equipment image</strong><input type="file" name="upload_image" id="upload_image" onchange="imageCrop(this)" />
<br />
<div id="uploaded_image"></div>
</div>
<input id="add" name="request" type="submit" value="Add Equipment" style="width: 100%;">
</div>
</div>
</div>
<div id="uploadimageModal" class="modal" role="dialog" style="z-index: 10000">
<div class="modal-content" style="width:fit-content">
<h4 class="modal-title" style="float: left"></h4>
<div class="row">
<div class="col-md-7 text-center">
<div id="image" style="width:350px; margin-top:30px"></div>
</div>
</div>
<div class="modal-footer">
<button class="btn btn-info crop_image">Crop & Upload Image</button>
</div>
</div>
</div>
<?php $results = mysqli_query($db, "SELECT * FROM EqManage.equipment inner join EqManage.categories on equipment.category = categories.id"); ?>
<table width="100%" id="table">
<thead>
<tr>
<th scope="col">Item</th>
<th scope="col">Category</th>
<th scope="col">Total Qty</th>
<th scope="col">Left Qty</th>
<th scope="col">Availability</th>
<th scope="col">Last used user ID</th>
<th scope="col">Last log ID</th>
<th scope="col">Action</th>
</tr>
</thead>
<tbody id="table2">
</tbody>
</table>
<h1 style="font-weight: bold; margin-top: 30px;margin-bottom: 10px;text-align: center"><u>Categories</u></h1>
<table width="100%" id="table">
<thead>
<tr>
<th scope="col">Category Name</th>
<th scope="col">Number of equipment in this cateogry</th>
<th scope="col">Action</th>
</tr>
</thead>
<tbody id="cattable">
</tbody>
</table>
<!-- <table>-->
<!-- <thead>-->
<!-- <tr>-->
<!-- <th scope="col" colspan="2">Item</th>-->
<!-- <th scope="col">Qty</th>-->
<!-- <th scope="col">Price</th>-->
<!-- </tr>-->
<!-- </thead>-->
<!-- <tbody>-->
<!-- <tr>-->
<!-- <td>Don’t Make Me Think by Steve Krug</td>-->
<!-- <td>In Stock</td>-->
<!-- <td>1</td>-->
<!-- <td>$30.02</td>-->
<!-- </tr>-->
<!-- <tr>-->
<!-- <td>A Project Guide to UX Design by Russ Unger & Carolyn Chandler</td>-->
<!-- <td>In Stock</td>-->
<!-- <td>2</td>-->
<!-- <td>$52.94 ($26.47 × 2)</td>-->
<!-- </tr>-->
<!-- <tr>-->
<!-- <td>Introducing HTML5 by Bruce Lawson & Remy Sharp</td>-->
<!-- <td>Out of Stock</td>-->
<!-- <td>1</td>-->
<!-- <td>$22.23</td>-->
<!-- </tr>-->
<!-- <tr>-->
<!-- <td>Bulletproof Web Design by Dan Cederholm</td>-->
<!-- <td>In Stock</td>-->
<!-- <td>1</td>-->
<!-- <td>$30.17</td>-->
<!-- </tr>-->
<!-- </tbody>-->
<!-- <tfoot>-->
<!-- <tr>-->
<!-- <td colspan="3">Subtotal</td>-->
<!-- <td>$135.36</td>-->
<!-- </tr>-->
<!-- <tr>-->
<!-- <td colspan="3">Tax</td>-->
<!-- <td>$13.54</td>-->
<!-- </tr>-->
<!-- <tr>-->
<!-- <td colspan="3">Total</td>-->
<!-- <td>$148.90</td>-->
<!-- </tr>-->
<!-- </tfoot>-->
</table>
</div>
</div>
<?php
if ($_SESSION['username'] == 'administrator'){
include ('adminModal.php');
}
?>
<script>
// Get the modal
var addAlert = document.getElementById("addAlert");
addAlert.style.display = "none";
var removeAlert = document.getElementById("removeAlert");
removeAlert.style.display = "none";
var removeCatAlert = document.getElementById("removeCatAlert");
removeCatAlert.style.display = "none";
var addEqModal = document.getElementById("addEqModal");
// Get the button that opens the modal
var addEqBtn = document.getElementById("addEqBtn");
// Get the <span> element that closes the modal
// var span = document.getElementsByClassName("close")[0];
//
// // When the user clicks on <span> (x), close the modal
// span.onclick = function() {
// addEqModal.style.display = "none";
// };
// When the user clicks on the button, open the modal
addEqBtn.onclick = function() {
addEqModal.style.display = "block";
};
function hideEqModal(){
addEqModal.style.display = "none";
resetFields();
}
// When the user clicks anywhere outside of the modal, close it
window.onclick = function(event) {
if (event.target === modal) {
addEqModal.style.display = "none";
resetFields();
}
};
function selectOther(val){
var element=document.getElementById('other');
if(val==='Select the Category'||val==='Other')
element.style.display='block';
else
element.style.display='none';
}
$(document).ready(function(){
displayFromDatabase();
$("#categorySelect").load("fetchCategorySelect.php");
$("#add").click(function (e){
var name = document.getElementById("name").value;
var qty = document.getElementById("qty").value;
var e = document.getElementById("cat");
var cat = e.options[e.selectedIndex].value;
var ncat = document.getElementById("other").value;
var img = document.getElementById("eqImg").value;
$.ajax({
url: "editEq.php",
type: "POST",
async: false,
data:{
"add":1,
"name":name,
"quantity":qty,
"category_id":cat,
"other":ncat,
"img":img
},
success: function(data){
displayFromDatabase();
addEqModal.style.display = "none";
resetFields();
var element=document.getElementById('other');
element.style.display='none';
var addAlert = document.getElementById("addAlert");
addAlert.style.display = "block";
var removeAlert = document.getElementById("removeAlert");
removeAlert.style.display = "none";
var removeCatAlert = document.getElementById("removeCatAlert");
removeCatAlert.style.display = "none";
console.log(data);
}
});
});
});
function resetFields() {
document.getElementById("name").value = "";
document.getElementById("qty").value = "1";
document.getElementById("cat").value = "";
document.getElementById("other").value ="";
$("#upload-div").load(" #upload-div");
}
function displayFromDatabase(){
$.ajax({
url: "editEq.php",
type: "POST",
async: false,
data: {
"display": 1
},
success:function (data) {
$("#table2").html(data);
}
})
$("#cattable").load("fetchCategoryTable.php");
$("#categorySelect").load("fetchCategorySelect.php");
}
function removeEq(id) {
console.log("Pressed");
$.ajax({
url: "editEq.php",
type: "POST",
async: false,
data:{
"id":id,
"remove":1,
"type":1
},
success: function(data){
displayFromDatabase();
var removeAlert = document.getElementById("removeAlert");
removeAlert.style.display = "block";
var addAlert = document.getElementById("addAlert");
addAlert.style.display = "none";
var removeCatAlert = document.getElementById("removeCatAlert");
removeCatAlert.style.display = "none";
console.log(data);
}
});
}
function removeCat(id) {
$.ajax({
url: "editEq.php",
type: "POST",
async: false,
data:{
"id":id,
"remove":1,
"type":2
},
success: function(data){
displayFromDatabase();
var removeAlert = document.getElementById("removeCatAlert");
removeAlert.style.display = "block";
var addAlert = document.getElementById("addAlert");
addAlert.style.display = "none";
var removeAlert = document.getElementById("removeAlert");
removeAlert.style.display = "none";
console.log(data);
}
});
}
$image_crop = $('#image').croppie({ //Calling croppie api on image div to set parameters
//parameter setting
enableExif: true,
viewport: {
width:250,
height:250,
type:'square' //circle
},
boundary:{
width:310,
height:310
}
});
function imageCrop(image){ //Called when image uploaded with input
var reader = new FileReader();
reader.onload = function (event) {
$image_crop.croppie('bind', {//Binding jQuery
url: event.target.result
}).then(function(){
console.log('jQuery bind complete');
});
};
reader.readAsDataURL(image.files[0]);//Display the image as a preview
$('#uploadimageModal').modal('show');
}
$('.crop_image').click(function(event){ //When crop & upload image button pressed
$image_crop.croppie('result', { //Set croppie parameters
type: 'canvas',
size: 'original'
}).then(function(response){ //Send the cropped image to upload-image.php via ajax
$.ajax({
url:"upload-image.php",
type: "POST",
data:{"image": response},
success:function(data)
{
$('#uploadimageModal').modal('hide');
$('#uploaded_image').html(data); //Hide modal and display processed & uploaded image
//after processing done in upload-image.php
}
});
})
});
</script>