forked from CaroBaten/PHPprojectRestaurant
/
tafelindeling.php
192 lines (136 loc) · 4.43 KB
/
tafelindeling.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
<?php
include_once('classes/Restaurant.class.php');
include_once('classes/Tables.class.php');
session_start();
if($_SESSION['loggedin']==false)
{
header("Location: index.php");
exit();
}
$restaurant = new Restaurant();
$table = new Table();
$allTables = $table->getTables($_SESSION['restaurantId']);
if (isset($_POST['delete']))
{
$table->deleteItem($_POST['itemid']);
header('Location: '.$_SERVER['REQUEST_URI']);
}
?><html lang="en">
<head>
<meta charset="UTF-8">
<title>Restorapp</title>
<link rel="stylesheet" href="css/reset.css">
<link rel="stylesheet" href="css/screen.css">
</head>
<body>
<div id="login">
<a href="dashboard.php"><img src="images/logodik.png" alt="logoklein"> </a>
<a class="user" id="logout" href="logout.php">Log out</a>
<?php echo "<p class='user'> Welkom ". $_SESSION['ownerName'] . " </p>" ?>
</div> <!-- end div login-->
<div class="clearfix"> </div>
<div id="container">
<div id="restaurantselect">
<?php
echo "<h3>". $_SESSION['restaurantName'] . "</h3>";
?>
</div>
<div id="subnav">
<ul>
<li><a href="tafelindeling.php">Tafelindeling </a></li>
<li><a href="menus.php">Menu's </a>
<ul id="menusubmenu">
<li><a href="drank.php">Drankmenu</a></li>
<li><a href="eten.php">Gerechten</a></li>
</ul>
</li>
<li><a href="reservatie.php">Reservatie </a></li>
<li><a href="kiesrestaurant.php">Restaurants</a></li>
</ul>
</div> <!-- end subnav-->
<div class="content">
<div id="tablewrapper" class="content">
<div id="feedback">
</div>
<div id="addTable">
<form action="" method="post">
<input type="text" id ="name" name="name" placeholder="Naam" required/>
<input type="text" id ="numberOfSeats" name="numberOfSeats" placeholder="Aantal plaatsen" required/>
<?php echo "<input type='text' id='restaurantId' name='restaurantId' hidden value='". $_SESSION['restaurantId'] . "'/>"; ?>
<input class="voegtoebtn" id="btnAdd" type="submit" value="Tafel Toevoegen" name = "btnAdd">
</form>
</div> <!-- end tablewrapper-->
<div class="clearfix"> </div>
</div> <!-- end table -->
</div>
<div id="tables" class="content">
<h2>Overzicht van tafels</h2>
<section id="rows">
<table id='listTables'>
<tr>
<th> Naam </th>
<th> Aantal personen </th>
<th> Verwijderen</th>
</tr>
<?php
foreach ($allTables as $t){
echo "<tr class='highlight'>";
echo "<td> " . $t['Name'] . " </td>";
echo "<td> " . $t['NumberOfSeats'] . " </td>";
echo "<td> <form action='' method='post'><input type='text' name='itemid' value='".$t['Name']. "' hidden><input type='submit' id='delete' name ='delete' value='delete'></form></td>";
echo "</tr>";
}
?>
</table>
</section>
</div> <!-- end tables-->
</div>
</div> <!-- end div container -->
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="js/interaction.js"></script>
<script>
$(document).ready(function(){
console.log("ready");
$( "#btnAdd" ).click(function() {
console.log("clicked");
var name = $( "#name" ).val();
var numberOfSeats = $( "#numberOfSeats" ).val();
var restaurantId = $( "#restaurantId" ).val();
var dataString = "name="+name + "&numberOfSeats=" + numberOfSeats;
console.log(dataString);
//SUBMIT DATA USING AJAX CALL
$.ajax({
type: "POST",
url: "ajax/addtable.php", // ajax/facebook-status-update.php
data: {
'name': name,
'numberOfSeats': numberOfSeats,
'restaurantId': restaurantId
}, // values to submit
success: function(msg) {
// what to do when call succeeds
if (msg.status ==true){
var update = "";
update+= "<tr class='highlight'>"
update += "<td> " + name + "</td>" ;
update += "<td> " + numberOfSeats + "</td>" ;
update += "<td> <form action='' method='post'><input type='text' name='itemid' value='" + name +"' hidden><input type='submit' id='delete' name ='delete' value='delete'></form></td>";
update += "</tr>"
$( "#listTables" ).append(update);
$("#feedback").hide();
}else{
var feedback = "<p>" + msg.message + "</p>";
$( "#feedback" ).html(feedback);
}
},
error: function() {
// what to do when call fails
console.log("fail");
}
});
return(false); //AVOID PAGE RELOAD WHEN CLICKING ON SUBMIT BUTTON
});
});
</script>
</body>
</html>