-
Notifications
You must be signed in to change notification settings - Fork 0
/
waitlist.php
executable file
·161 lines (158 loc) · 4.38 KB
/
waitlist.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
<?php
/**
* Created by PhpStorm.
* User: karti
* Date: 30-Oct-17
* Time: 9:21 PM
*/
include "dbconfig.php";
if (isset($_POST['name'])){
addCustomerToList($_POST['name']);
exit();
}
if (isset($_POST['dis'])){
showWaitList();
exit();
}
if (isset($_POST['remId'])){
removeCustomerFromList($_POST['remId']);
exit();
}
function addCustomerToList($name){
global $mysqli;
if (!($mysqli->query("INSERT INTO waitlist(Name) VALUES ('$name')"))){
echo $mysqli->error;
}
}
function showWaitList(){
global $mysqli;
if ($res = $mysqli->query("SELECT * FROM waitlist")){
if ($res->num_rows == 0) {
echo "no customers in waitlist";
return;
}
else {
while ($row = $res->fetch_assoc()){
echo <<<EOT
<div class = "col-xs-12 card">
<table class="table">
<tbody>
<tr>
<th><h1 class="nav-heading">{$row['Name']}</h1></th>
<th><button class="btn btn-done remove" value="{$row['cust_id']}"><i class="material-icons">remove</i> </button> </th>
</tr>
</tbody>
</table>
</div>
EOT;
}
}
}
}
function removeCustomerFromList($id){
global $mysqli;
if ($mysqli->query("DELETE FROM waitlist WHERE cust_id = $id")){
echo "customer reserved";
}
else
echo $mysqli->error;
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Manage entries in your menu</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="./js/lib/jquery.min.js"></script>
<link href="https://fonts.googleapis.com/css?family=Chela+One|Fira+Sans|Lato|Roboto|Ubuntu|Pacifico" rel="stylesheet">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="./css/lib/bootstrap.min.css">
<!-- Optional theme -->
<link rel="stylesheet" href="./css/lib/bootstrap-theme.min.css">
<!-- Latest compiled and minified JavaScript -->
<script src="./js/lib/bootstrap.min.js"></script>
<!-- GreenSock JS -->
<script src="./js/lib/TweenMax.min.js"></script>
<link rel="stylesheet" href="css/edits.css">
<script>
function add() {
var name = $('#custName').val();
console.log(name);
$.ajax({
method: 'POST',
url: 'waitlist.php',
data: {'name':name}
}).done(function (data) {
console.log("done");
show();
});
}
function remove(id) {
console.log(id);
$.ajax({
method: 'POST',
url: 'waitlist.php',
data: {'remId':id}
}).done(function (data) {
console.log("done");
show();
});
}
function show() {
console.log("getting data...");
$.ajax({
method: 'POST',
url: 'waitlist.php',
data: {'dis':1}
}).done(function (data) {
$('.target').html(data);
console.log("done");
});
}
$(document).ready(function () {
show();
$('#add').click(add);
$('.target').on('click', '.remove', function () {
var id = $(this).val();
remove(id);
});
});
</script>
<style>
legend {
padding:10px;
}
</style>
</head>
<body>
<div id="main">
<nav class="navbar alliedNav">
<div class="container-fluid">
<div class="row">
<h1 class="col-md-12 col-sm-12 nav-heading">WaitList</h1>
</div>
</div>
</nav>
<!--------------------------------END OF NAVBAR ---------------------------------------->
</div>
<br>
<br>
<br>
<div class="container-fluid">
<div class="row">
<div class="col-xs-8">
<input type="text" class="form-control" placeholder="name..." name="cust-name" id="custName" required />
</div>
<div class="col-xs-4">
<button class="btn btn-done" id="add">Add</button>
</div>
</div>
<br>
<div class="row">
<legend>Customers</legend>
<div class="target"></div>
</div>
</div>
</body>
</html>