-
Notifications
You must be signed in to change notification settings - Fork 1
/
eventbooking.php
244 lines (208 loc) · 9.47 KB
/
eventbooking.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
<?php
/*-----------------------------------------------------------------------------
| Bitsand - an online booking system for Live Role Play events
|
| File eventbooking.php
| Author: Russell Phillips
| Copyright: (C) 2006 - 2015 The Bitsand Project
| (http://github.com/PeteAUK/bitsand)
|
| Bitsand is free software; you can redistribute it and/or modify it under the
| terms of the GNU General Public License as published by the Free Software
| Foundation, either version 3 of the License, or (at your option) any later
| version.
|
| Bitsand is distributed in the hope that it will be useful, but WITHOUT ANY
| WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
| FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
| details.
|
| You should have received a copy of the GNU General Public License along with
| Bitsand. If not, see <http://www.gnu.org/licenses/>.
+---------------------------------------------------------------------------*/
include ('inc/inc_head_db.php');
include ('inc/inc_head_html.php');
include ('inc/inc_commonqueries.php');
function GetBookingTypeAvailability($eventid, $bookingtype, $spaces)
{
//Returns -1 if no booking allowed
//Returns 1 if booking allowed
//Returns 0 if booking will be placed in queue as speaces are full.
global $link, $today, $db_prefix;
$sql = "select count(itItemID) from {$db_prefix}items where itTicket = 1 and itAvailableFrom <= '$today' and itAvailableTo >= '$today' and itAvailability in ('All', '$bookingtype') and itEventID = $eventid";
$result = ba_db_query ($link, $sql);
$TicketTypeAvailable = ba_db_fetch_row($result);
$TicketTypeAvailableCount = $TicketTypeAvailable[0];
if ($TicketTypeAvailableCount == 0 && $bookingtype != "All") { return -1; }
$sql = "select count(bkID) as BookingCount from {$db_prefix}bookings where bkInQueue = 0 and bkEventID = $eventid ";
if ($bookingtype != "All") { $sql .= " and bkBookAs = '$bookingtype'"; }
$result = ba_db_query ($link, $sql);
$BookingCount = ba_db_fetch_assoc ($result);
$BookingCount = $BookingCount['BookingCount'];
if ($BookingCount >= $spaces) {
if (QUEUE_OVER_LIMIT) { return 0;}
else { return -1; }
}
return 1;
}
function GetBunkAvailability($eventid, $bookingtype, $bunks)
{
global $link, $today, $db_prefix;
$sql = "select ifnull(sum(bkBunkAllocated), 0) as BunksAllocated from {$db_prefix}bookings where bkEventID = $eventid ";
if ($bookingtype != "All") { $sql .= " and bkBookAs = '$bookingtype' "; }
$result = ba_db_query ($link, $sql);
$BookingTypeAvailable = ba_db_fetch_row($result);
$BookingTypeCount = $BookingTypeAvailable[0];
if ($BookingTypeCount >= $bunks ) { return false;}
return true;
}
$eventinfo = getEventDetails($_GET['EventID'], 1);
?>
<script type = 'text/javascript'>
<?php
if (GetBunkAvailability($eventinfo['evEventID'], "All", $eventinfo['evTotalBunks']))
{
if (GetBunkAvailability($eventinfo['evEventID'], "Player", $eventinfo['evPlayerBunks'])) {$playerbunks = 1;} else {$playerbunks = 0;}
if (GetBunkAvailability($eventinfo['evEventID'], "Monster", $eventinfo['evMonsterBunks'])) {$monsterbunks = 1;} else {$monsterbunks = 0;}
if (GetBunkAvailability($eventinfo['evEventID'], "Staff", $eventinfo['evStaffBunks'])) {$staffbunks = 1;} else {$staffbunks = 0;}
}
else
{
$playerbunks = $monsterbunks = $staffbunks = 0;
}
echo "var PlayerBunkAvailable = $playerbunks;";
echo "var MonsterBunkAvailable = $monsterbunks;";
echo "var StaffBunkAvailable = $staffbunks;";
?>
function changetotal()
{
var bookingtotal = 0;
$('.singleitem').each(function() {
var cost = $(this);
if (cost.attr('checked'))
{
bookingtotal += parseFloat(cost.attr('cost'));
if ($('#h' + cost.attr('id')).length > 0) { $('#h' + cost.attr('id')).val('on'); }
}
else
{
if ($('#h' + cost.attr('id')).length > 0) { $('#h' + cost.attr('id')).val('off'); }
}
}
);
$('.multipleitem').each(function() {
var cost = $(this);
bookingtotal += (parseFloat(cost.attr('cost')) * cost.val());
}
);
$('#bookingtotal').text(bookingtotal.toFixed(2));
}
function showitems()
{
var bookingtype = $('#cboBookAs').val();
$(".bookingitems tr").hide();
$('.singleitem').attr('checked', false);
$('.multipleitem').val(0);
$("#bookingtotal").innerHTML = '0';
$('.'+bookingtype).fadeTo("slow", 1.0);
$('.All').fadeTo("slow", 1.0);
$('.bookingitems tfoot tr').fadeTo("slow", 1.0);
var defaultSet = false;
$('.singleitem').each(function() {
var defaultItem = $(this);
if (defaultItem.attr('ticket') == 1 && defaultItem.is(":visible") && !defaultSet)
{
defaultItem.attr('checked', true);
defaultSet = true;
changetotal();
}
if (defaultItem.attr('bunk') == 1)
{
var bunkRow = $('#' + defaultItem.attr('id').replace('chk','row'));
if (bookingtype == 'Player' && !PlayerBunkAvailable) { bunkRow.hide(); }
if (bookingtype == 'Monster' && !MonsterBunkAvailable) { bunkRow.hide(); }
if (bookingtype == 'Staff' && !StaffBunkAvailable) { bunkRow.hide(); }
}
}
);
}
</script>
<h1><?php echo TITLE?></h1>
<h2>Book for event - <?php echo htmlentities (stripslashes ($eventinfo['evEventName'])); ?></h2>
<?php
//Check if player has entered IC data
$sql = "SELECT chName FROM {$db_prefix}characters WHERE chPlayerID = $PLAYER_ID";
$result = ba_db_query ($link, $sql);
$iIC = ba_db_num_rows ($result);
if ($iIC == 0)
{
echo "<p>Note that you cannot book as a player unless you enter your IC details</p>\n";
}
else
{
//Check skills cost is valid, expand in future to include a better check
$sql = "select sum(skCost) as pointsspent from {$db_prefix}skillstaken inner join {$db_prefix}skills on stSkillID = skID where stPlayerID = $PLAYER_ID";
$result = ba_db_query ($link, $sql);
$pointsspent = ba_db_fetch_assoc ($result);
if ($pointsspent['pointsspent'] > MAX_CHAR_PTS)
{
echo "<p>You must select fewer skills before you can book as a player</p>\n";
$iIC = 0;
}
}
if (GetBookingTypeAvailability($eventinfo['evEventID'], "All", $eventinfo['evTotalSpaces']) == 1)
{
$playerspaces = GetBookingTypeAvailability($eventinfo['evEventID'], "Player", $eventinfo['evPlayerSpaces']);
$monsterspaces = GetBookingTypeAvailability($eventinfo['evEventID'], "Monster", $eventinfo['evMonsterSpaces']);
$staffspaces = GetBookingTypeAvailability($eventinfo['evEventID'], "Staff", $eventinfo['evStaffSpaces']);
if ($playerspaces == 0 && $iIC) { echo "<p class='warning'>Player spaces are full, you may still book but your booking will be placed in a queue, and may not be accepted.</p>"; }
if ($monsterspaces == 0 && $eventinfo['evAllowMonsterBookings']) { echo "<p class='warning'>Monster spaces are full, you may still book but your booking will be placed in a queue, and may not be accepted.</p>"; }
if ($staffspaces == 0) { echo "<p class='warning'>$stafftext spaces are full, you may still book but your booking will be placed in a queue, and may not be accepted.</p>"; }
echo "\n<form action='eventbookingconfirm.php' method='post'>";
echo "<p>Please select your booking type: \n";
echo "<select id='cboBookAs' name='cboBookAs' onChange='showitems()'></p>\n";
if ($playerspaces >= 0 && $iIC) { echo "<option value='Player'>Player</option>";}
if ($monsterspaces >= 0 && $eventinfo['evAllowMonsterBookings']) { echo "<option value='Monster'>Monster</option>";}
if ($staffspaces >= 0) { echo "<option value='Staff'>".$stafftext."</option>";}
echo "</select>";
$sql = "SELECT * from {$db_prefix}items where itEventID = ".$eventinfo['evEventID']." and itAvailableFrom <= '$today' and itAvailableTo >= '$today' ";
$result = ba_db_query ($link, $sql);
echo "\n<input type='hidden' value='".$eventinfo['evEventID']."' name='eventid'/>";
echo "\n<table class='bookingitems'>\n";
while ($iteminfo = ba_db_fetch_assoc ($result))
{
echo "<tr class='".$iteminfo['itAvailability']."' id='row".$iteminfo['itItemID']."'><td class='description'>".$iteminfo['itDescription']."</td><td>£".$iteminfo['itItemCost']."</td><td>";
if ($iteminfo['itAllowMultiple']) {
echo "<select class='multipleitem' name='cbo".$iteminfo['itItemID']."' id='cbo".$iteminfo['itItemID']."' onChange='changetotal()' cost='".$iteminfo['itItemCost']."'>";
for($i=0; $i<31;$i++)
{
echo "<option value='$i'>$i</option>";
}
echo "</select>";
}
else {
echo "<input type='checkbox' class='singleitem' name='chk".$iteminfo['itItemID']."' id='chk".$iteminfo['itItemID']."' onClick='changetotal()' cost='".$iteminfo['itItemCost']."' ticket='".$iteminfo['itTicket']."' bunk='".$iteminfo['itBunk']."'";
if ($iteminfo['itMandatory'] == 1) {
echo " checked disabled='true' />";
echo "<input type=hidden id='hchk".$iteminfo['itItemID']."' name='chk".$iteminfo['itItemID']."' cost='".$iteminfo['itItemCost']."' ticket='".$iteminfo['itTicket']."' bunk='".$iteminfo['itBunk']."' value='on' />";
}
else
{
echo "/>";
}
}
echo "</td></tr>\n";
}
echo "<tfoot>";
echo "<tr class='total'><td class='totallabel' colspan=2>Total:</td><td>£<span id='bookingtotal'>0.00</span></td></tr>";
echo "<tr><td colspan=2></td><td><input type='submit' value='Make Booking' /></td></tr>";
echo "</tfoot>";
echo "\n</table>";
echo "\n</form>";
echo "\n<script>showitems();</script>";
}
else
{
echo "<p>There are no spaces left for this event</p>";
}
include ('inc/inc_foot.php');