-
Notifications
You must be signed in to change notification settings - Fork 0
/
ItemManagement.php
370 lines (340 loc) · 18.8 KB
/
ItemManagement.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
<?php
session_start();
if($_SESSION["accountType"] != 'user' && $_SESSION["accountType"] != 'admin')
{
header('Location: index.php');
}
?>
<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
<head>
<script src="js/jquery-3.2.1.min.js"></script>
<script src="js/tether.min.js"></script>
<script src ="js/bootstrap.min.js"></script>
<script src="DataTables/datatables.min.js"></script>
<script src="js/customItemFilter.js"></script>
<script type="text/javascript">
$( document ).ready(function()
{
var table = $('#myDataTable').DataTable( {
ajax: "PhpScripts/ViewAllItems.php",
resposive: true,
columns: [
{ mData: 'item_id', visible: false, searchable: false},
{ mData: 'auction_id', searchable: true} ,
{ mData: 'description', searchable: true},
{ mData: 'description2', searchable: true },
{ mData: 'donated_by', searchable: true},
{ mData: 'value', searchable: false},
{ mData: null, searchable: false},
],
columnDefs: [
{
"render": function(data,type,row) {
var date = new Date(data.last_modified).toLocaleDateString();
return data.last_modified_by + ' on ' + date;
},
"targets":6
},
{
"render": function(data,type,row) {
return data == -1 ? "Priceless" : data;
},
"targets":5
},
{
"render": function(data,type,row) {
return data == null ? "Unassigned" : data;
},
"targets":1
}
],
order: [[1, "asc"]]
} );
$('.idFilter').click( function() {
table.draw();
} );
$('#myDataTable tbody').on('click', 'tr', function () {
if ( $(this).hasClass('selected') ) {
$(this).removeClass('selected');
}
else {
table.$('tr.selected').removeClass('selected');
$(this).addClass('selected');
}
switch (table.rows('.selected').data().length) {
case 0:
document.getElementById("btn-new").style.display = "inline";
document.getElementById("btn-edit").style.display = "none";
document.getElementById("btn-unassign").style.display = "none";
document.getElementById("btn-delete").style.display = "none";
break;
case 1:
document.getElementById("btn-new").style.display = "none";
if (table.rows('.selected').data()[0].item_id > -1)
document.getElementById("btn-edit").style.display = "inline";
else
document.getElementById("btn-edit").style.display = "none";
if (table.rows('.selected').data()[0].auction_id == null)
document.getElementById("btn-unassign").style.display = "none";
else
document.getElementById("btn-unassign").style.display = "inline";
document.getElementById("btn-delete").style.display = "inline";
break;
}
} );
$('input#noId').click( function () {
document.getElementById('auctionId').readOnly = document.getElementById('noId').checked;
document.getElementById("auctionId").value = document.getElementById('noId').checked || table.rows('.selected').data().length == 0 ?
null :
table.rows('.selected').data()[0].auction_id;
isValid();
} );
$('input#noValue').click( function () {
document.getElementById('value').readOnly = document.getElementById('noValue').checked;
document.getElementById("value").value = document.getElementById('noValue').checked || table.rows('.selected').data().length == 0 ?
null :
table.rows('.selected').data()[0].value;
isValid();
} );
$('button#btn-new').click( function () {
$("#title").text("New Item");
isValid();
})
$('button#btn-edit').click( function () {
if (table.rows('.selected').data()[0].auction_id) {
document.getElementById("auctionId").value = table.rows('.selected').data()[0].auction_id;
document.getElementById('noId').checked = false;
document.getElementById('auctionId').removeAttribute("readonly");
}
else{
document.getElementById("auctionId").value = null;
document.getElementById('auctionId').readonly = true;
document.getElementById('noId').checked = true;
}
document.getElementById("description").value = table.rows('.selected').data()[0].description;
document.getElementById("description2").value = table.rows('.selected').data()[0].description2;
document.getElementById("donatedBy").value = table.rows('.selected').data()[0].donated_by;
document.getElementById("value").value = table.rows('.selected').data()[0].value;
document.getElementById("itemId").value = table.rows('.selected').data()[0].item_id;
$("#title").text("Edit Item");
isValid();
} );
$('button#btn-unassign').click( function () {
var auctionId = table.rows('.selected').data()[0].auction_id;
$.ajax ( {
type: "Post",
url: "PhpScripts/UnassignAuctionItems.php",
data: {auctionId: auctionId },
success: function(data) {
$('#myDataTable').DataTable().ajax.reload();
document.getElementById("btn-new").style.display = "inline";
document.getElementById("btn-edit").style.display = "none";
document.getElementById("btn-unassign").style.display = "none";
document.getElementById("btn-delete").style.display = "none";
}
});
} );
$('button#btn-delete').click( function () {
if (table.rows('.selected').data()[0].auction_id == null) {
var id = table.rows('.selected').data()[0].item_id;
var isAssigned = false;
}
else {
var id = table.rows('.selected').data()[0].auction_id;
var isAssigned = true;
}
if (confirm("Are you sure you want to delete the selected item?")) {
$.ajax ( {
type: "POST",
url: "PhpScripts/DeleteAuctionItem.php",
data: {auctionId: id, isAssigned: isAssigned },
success: function(data) {
$('#myDataTable').DataTable().ajax.reload();
document.getElementById("btn-new").style.display = "inline";
document.getElementById("btn-edit").style.display = "none";
document.getElementById("btn-unassign").style.display = "none";
document.getElementById("btn-delete").style.display = "none";
}
});
}
} );
$("button#submit").click(function(){
var url = document.getElementById("itemId").value == ""
? "PhpScripts/AddItemDatabase.php"
: "PhpScripts/EditItemDatabase.php" ;
$.ajax( {
type: "POST",
url: url,
data: $('form.edit').serialize(),
success: function(data) {
console.log(data);
document.getElementById("edit").reset();
$('#myDataTable').DataTable().ajax.reload();
$("#edit-modal").modal('hide');
table.rows('.selected').remove();
document.getElementById("btn-new").style.display = "inline";
document.getElementById("btn-edit").style.display = "none";
document.getElementById("btn-unassign").style.display = "none";
document.getElementById("btn-delete").style.display = "none";
}
});
});
$('.modal').on('hidden.bs.modal', function(){
document.getElementById("edit").reset();
$(".error").removeClass("none");
});
});
function openCheckBoxDropdown() {
if (!document.getElementsByClassName("dropper")[0].classList.contains("auto-height")) document.getElementsByClassName("dropper")[0].classList.add("auto-height");
else document.getElementsByClassName("dropper")[0].classList.remove("auto-height");
}
function clickInput(id) {
document.getElementById(id).click();
}
function checkId () {
var id = document.getElementById('auctionId').value;
var idExists = document.getElementById('noId').checked;
if ((id > 99 && id < 400) || (id > 599 && id < 700) || idExists ) {
document.getElementById("auctionError").classList.add("none");
return true;
}
else {
document.getElementById("auctionError").classList.remove("none");
return false;
}
}
function checkDescription () {
var description = document.getElementById('description').value;
if (description == null || description == "" ) {
document.getElementById("descriptionError").classList.remove("none");
return false;
}
else {
document.getElementById("descriptionError").classList.add("none");
return true;
}
}
function checkDonatedBy () {
var donatedBy = document.getElementById('donatedBy').value;
if (donatedBy == null || donatedBy == "" ) {
document.getElementById("donatedByError").classList.remove("none");
return false;
}
else {
document.getElementById("donatedByError").classList.add("none");
return true;
}
}
function checkValue () {
var value = document.getElementById('value').value;
var priceless = document.getElementById('noValue').checked;
if (value !== "" || priceless ) {
document.getElementById("valueError").classList.add("none");
return true;
}
else {
document.getElementById("valueError").classList.remove("none");
return false;
}
}
function isValid () {
if (checkId() && checkDescription() && checkDonatedBy() && checkValue() )
document.getElementById("submit").removeAttribute('disabled');
else
document.getElementById("submit").disabled = true;
}
function closeAuction(number) {
if (confirm("Are you sure you would like to close the " + number + "'s auction?\n" +
"This will overwrite any items in the " + number + "'s auction that have already been sold!")) {
$.ajax( {
type: "POST",
url: "PhpScripts/CloseAuction.php",
data: {select: number}
});
}
}
</script>
<link href="css/bootstrap.min.css" text="text/css" rel="stylesheet">
<link href="DataTables/datatables.min.css" text="text/css" rel="stylesheet">
<link href="css/customStyles.css" text="text/css" rel="stylesheet">
<meta charset="UTF-8">
<title></title>
</head>
<body id="ItemManagementBody">
<?php include "PhpScripts/Templates/Nav.php";?>
<div style="width: 100% !important;" class="container body-content top">
<div>
<button type="button" id="btn-new" class="btn btn-info btn-primary" data-toggle="modal" data-target="#edit-modal" style="display: inline;">New Item</button>
<button type="button" id="btn-edit" class="btn btn-info btn-primary" data-toggle="modal" data-target="#edit-modal" style="display: none;">Edit Item</button>
<button type="button" id="btn-delete" class="btn btn-danger" style="display: none;">Delete Item</button>
<button type="button" id="btn-unassign" class="btn btn-warning" style="display: none;">Unassign Item</button>
<button type="button" id="close300" class="btn btn-danger float-right" onclick="closeAuction(300)">Close 300's</button>
<button type="button" id="close200" class="btn btn-danger float-right" onclick="closeAuction(200)">Close 200's</button>
<button type="button" id="close100" class="btn btn-danger float-right" onclick="closeAuction(100)">Close 100's</button>
</div>
<br />
<div onclick="openCheckBoxDropdown()" class="groups" data-toggle="dropdown">Select Groups ↓</div>
<div class="dropper" style="top: 98px !important">
<div onclick="clickInput('one')" class="dropdown">100's <input id="one" class="idFilter check-boxes" checked type="checkbox"></div>
<div onclick="clickInput('two')" class="dropdown">200's <input id="two" class="idFilter check-boxes" checked type="checkbox"></div>
<div onclick="clickInput('three')" class="dropdown">300's <input id="three" class="idFilter check-boxes" checked type="checkbox"></div>
<div onclick="clickInput('six')" class="dropdown">600's <input id="six" class="idFilter check-boxes" checked type="checkbox"></div>
<div onclick="clickInput('unassigned')" class="dropdown">Not Numbered<input id="unassigned" class="idFilter check-boxes" checked type="checkbox"></div>
</div>
<table id="myDataTable" class="display stripe" cellspacing="0" width="100%">
<thead>
<tr>
<td ></td>
<td class=" first head">AuctionId</td>
<td class="head">Description</td>
<td class="head">Optional Description</td>
<td class="head">Donated By</td>
<td class="head">Value</td>
<td class="last head">Last Edited By</td>
</tr>
</thead>
</table>
<div id="edit-modal" class="modal fade" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h3 id="title"></h3>
</div>
<div class="modal-body">
<form class="edit" name="edit" id="edit">
<input id="itemId", name="itemId" type="hidden">
<strong>AuctionId</strong>
<br />
<input id="auctionId" type="number" name="auctionId" class="input-xlarge" onkeyup=isValid() readonly>
<label><input type="checkbox" value="true" class="input-xlarge" name="noId" id="noId" checked>No AuctionId</label>
<br /><br /><strong>Description</strong><br />
<textarea id="description" name="description" class="input-xlarge" onkeyup="isValid()"></textarea>
<br /><br /><strong>Optional Description</strong><br />
<textarea id="description2" name="description2" class="input-xlarge"></textarea>
<br /><br /><strong>Donated By</strong><br />
<input id="donatedBy" name="donatedBy" type="text" class="input-xlarge" value="" onkeyup="isValid()">
<br /><br /> <strong>Value</strong><br />
<input id="value" type="number" name="value" step="0.01" class="input-xlarge" onkeyup="isValid()">
<label><input type="checkbox" value="true" class="input-xlarge" name="noValue" id="noValue">Priceless</label>
</form>
<div class="error none" id="auctionError">That Auction Number is invalid</div>
<div class="error none" id="descriptionError">Description is required</div>
<div class="error none" id="donatedByError">Donated By is required</div>
<div class="error none" id="valueError">Item value is required</div>
</div>
<div class="modal-footer">
<button class="btn btn-success" disabled id="submit">Save</button>
<a href="#" class="btn" data-dismiss="modal">Close</a>
</div>
</div>
</div>
</div>
<div id='response'></div>
</body>
</html>