PHP Page
<!-- Booking JavaScript -->
<script type="text/javascript" src="js/seat-charts.min.js"></script>
<script type="text/javascript" src="js/booking.js"></script>
<script type="text/javascript">
<?php
//Fetch all rows for each booking
echo " $(document).ready(function(){";
while ($row = mysqli_fetch_array ($result, MYSQLI_ASSOC)) {
extract ($row);
echo "sc.get(['".$BOOKING_SEAT."']).status('unavailable');
";
}
echo "});";
?>
</script>
js/booking.js this is a variant by Adrian Vazquez of jq seat chart (github) It works.
var price = 10; //price
var $cart = $('#selected-seats'); //Sitting Area
var $counter = $('#counter'); //Votes
var $total = $('#total'); //Total money
var sc = $('#seat-map').seatCharts({
map: [ //Seating chart
'aaaaaaaaaa',
'aaaaaaaaaa',
'aaaaaaaaaa',
'aaaaaaaaaa',
'aaaaaaaaaa'
],
naming : {
top : false,
getLabel : function (character, row, column) {
return column;
}
},
legend : { //Definition legend
node : $('#legend'),
items : [
[ 'a', 'available', 'Option' ],
[ 'a', 'unavailable', 'Sold']
]
},
click: function () { //Click event
if (this.status() == 'available') { //optional seat
var maxSeats = 3;
var ms = sc.find('selected').length;
//alert(ms);
if (ms < maxSeats) {
$('<option selected>R'+(this.settings.row+1)+' S'+this.settings.label+'</option>')
.attr('id', 'cart-item-'+this.settings.id)
.attr('value', (this.settings.row+1)+'_'+this.settings.label)
.data('seatId', this.settings.id)
.appendTo($cart);
$counter.text(sc.find('selected').length+1);
$counter.attr('value', sc.find('selected').length+1);
$total.text(recalculateTotal(sc)+price);
$total.attr('value', recalculateTotal(sc)+price);
return 'selected';
}
alert('You can only choose '+ maxSeats + ' seats.');
return 'available';
} else if (this.status() == 'selected') { //Checked
//Update Number
$counter.text(sc.find('selected').length-1);
$counter.attr('value', sc.find('selected').length-1);
//update totalnum
$total.text(recalculateTotal(sc)-price);
$total.attr('value', recalculateTotal(sc)-price);
//Delete reservation
$('#cart-item-'+this.settings.id).remove();
//optional
return 'available';
} else if (this.status() == 'unavailable') { //sold
return 'unavailable';
} else {
return this.style();
}
}
});
// Add total money
function recalculateTotal(sc) {
var total = 0;
sc.find('selected').each(function () {
total += price;
});
return total;
}
But if I try to customize it by inserting some functions of JqSeatChart, the script does not work anymore. for example:
naming : {
top : false,
rows: ['A', 'B', 'C', 'C', 'D'],
getLabel : function (character, row, column) {
return column;
}
The letters are printed to the left of the map but the reservation is not recorded. That is, the reservation is registered in the DB (eg 1_10) but not return to the map to the next reservation. I think the problem is in these lines:
click: function () { //Click event
if (this.status() == 'available') { //optional seat
/* queste righe limitano il numero di posti prenotabili
* var maxSeats = 3;
* var ms = sc.find('selected').length;
* //alert(ms);
* if (ms < maxSeats) { */
$('<option selected>R'+(this.settings.row+1)+' S'+this.settings.label+'</option>')
.attr('id', 'cart-item-'+this.settings.id)
.attr('value', (this.settings.row+1)+'_'+this.settings.label)
.data('seatId', this.settings.id)
.appendTo($cart);
$counter.text(sc.find('selected').length+1);
$counter.attr('value', sc.find('selected').length+1);
$total.text(recalculateTotal(sc)+price);
$total.attr('value', recalculateTotal(sc)+price);
return 'selected';
That are different from the original
click: function () {
if (this.status() == 'available') {
//let's create a new <li> which we'll add to the cart items
$('<li>'+this.data().category+' Seat # '+this.settings.label+': <b>$'+this.data().price+'</b> <a href="#" class="cancel-cart-item">[cancel]</a></li>')
.attr('id', 'cart-item-'+this.settings.id)
.data('seatId', this.settings.id)
.appendTo($cart);
/*
* Lets update the counter and total
*
* .find function will not find the current seat, because it will change its stauts only after return
* 'selected'. This is why we have to add 1 to the length and the current seat price to the total.
*/
$counter.text(sc.find('selected').length+1);
$total.text(recalculateTotal(sc)+this.data().price);
return 'selected';
I've tried to test some changes but without results So I ask suggestions to someone more experienced than me.