-
Notifications
You must be signed in to change notification settings - Fork 0
/
BidderManagement.php
176 lines (161 loc) · 7.96 KB
/
BidderManagement.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
<?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 type="text/javascript">
$( document ).ready(function()
{
var table = $('#myDataTable').DataTable( {
ajax: "PhpScripts/ViewBidders.php",
resposive: true,
columns: [
{ mData: 'bidder_id', searchable: true},
{ mData: 'name', searchable: true} ,
{ mData: 'phone', searchable: false},
{ mData: 'address', searchable: false}
],
order: [[0, "asc"]]
} );
$('#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-delete").style.display = "none";
break;
case 1:
document.getElementById("btn-new").style.display = "none";
document.getElementById("btn-edit").style.display = "inline";
document.getElementById("btn-delete").style.display = "inline";
break;
}
} );
$('button#btn-new').click( function () {
$("#title").text("New Bidder");
document.getElementById("lbl-bidder").style.display = "none";
})
$('button#btn-edit').click( function () {
document.getElementById("lbl-bidder").style.display = "block";
$("#bidder").text(table.rows('.selected').data()[0].bidder_id);
document.getElementById("bidderId").value = table.rows('.selected').data()[0].bidder_id;
document.getElementById("phone").value = table.rows('.selected').data()[0].phone;
document.getElementById("address").value = table.rows('.selected').data()[0].address;
document.getElementById("name").value = table.rows('.selected').data()[0].name;
$("#title").text("Edit Bidder");
} );
$('button#btn-delete').click( function () {
var bidderId = table.rows('.selected').data()[0].bidder_id;
if (confirm("Are you sure you want to delete the selected item?")) {
$.ajax ( {
type: "POST",
url: "PhpScripts/DeleteBidder.php",
data: {bidderId: bidderId},
success: function(data) {
$('#myDataTable').DataTable().ajax.reload();
document.getElementById("btn-new").style.display = "inline";
document.getElementById("btn-edit").style.display = "none";
document.getElementById("btn-delete").style.display = "none";
}
});
}
} );
$("button#submit").click(function(){
var url = document.getElementById("bidderId").value == ""
? "PhpScripts/RegisterBidderDatabase.php"
: "PhpScripts/EditBidder.php" ;
$.ajax( {
type: "POST",
url: url,
data: $('form.edit').serialize(),
success: function(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-delete").style.display = "none";
}
});
});
$('.modal').on('hidden.bs.modal', function(){
document.getElementById("edit").reset();
$("#bidder").text("");
});
});
</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="BidderManagementBody">
<?php include "PhpScripts/Templates/Nav.php";?>
<div 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 Bidder</button>
<button type="button" id="btn-edit" class="btn btn-info btn-primary" data-toggle="modal" data-target="#edit-modal" style="display: none;">Edit Bidder</button>
<button type="button" id="btn-delete" class="btn btn-danger" style="display: none;">Delete Bidder</button>
</div>
<br />
<table id="myDataTable" class="display stripe" cellspacing="0" width="100%">
<thead>
<tr>
<td class=" first head">BidderId</td>
<td class="head">Name</td>
<td class="head">Phone Number</td>
<td class="last head">Address</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">
<strong id="lbl-bidder">BidderId</strong>
<p id="bidder" name="bidder" type="text"></p>
<input id="bidderId", name="bidderId" type="hidden">
<strong>Name</strong><br />
<input id="name" name="name" class="input-xlarge" type="text">
<br /><br /><strong>Phone Number</strong><br />
<input id="phone" name="phone" type="tel" class="input-xlarge">
<br /><br /> <strong>Address</strong><br />
<textarea id="address" name="address" class="input-xlarge"></textarea>
</form>
</div>
<div class="modal-footer">
<button class="btn btn-success" id="submit">Save</button>
<a href="#" class="btn" data-dismiss="modal">Close</a>
</div>
</div>
</div>
</div>
</body>
</html>