Commit b1898ce8 authored by jkerr's avatar jkerr
Browse files

Massive Assignment 2 headway

parent 6f31cbf3
Pipeline #3077 failed with stage
in 0 seconds
This diff is collapsed.
{
"bookings": {
"booking": [
{
"number": "101",
"name": "Mr and Mrs Smith",
"checkin": {
"day": "15",
"month": "8",
"year": "2018"
},
"checkout": {
"day": "21",
"month": "8",
"year": "2018"
}
},
{
"number": "203",
"name": "Alice, Bob, and family",
"checkin": {
"day": "12",
"month": "8",
"year": "2018"
},
"checkout": {
"day": "17",
"month": "8",
"year": "2018"
}
},
{
"number": "204",
"name": "Alice, Bob, and family",
"checkin": {
"day": "12",
"month": "8",
"year": "2018"
},
"checkout": {
"day": "17",
"month": "8",
"year": "2018"
}
},
{
"number": "203",
"name": "Carol and Dave",
"checkin": {
"day": "17",
"month": "8",
"year": "2018"
},
"checkout": {
"day": "21",
"month": "8",
"year": "2018"
}
},
{
"number": "101",
"name": "Nick Meek",
"checkin": {
"day": "1",
"month": "10",
"year": "2018"
},
"checkout": {
"day": "10",
"month": "10",
"year": "2018"
}
},
{
"number": "203",
"name": "Stefanie Zollmann",
"checkin": {
"day": "1",
"month": "10",
"year": "2018"
},
"checkout": {
"day": "10",
"month": "10",
"year": "2018"
}
}
]
}
}
\ No newline at end of file
{
"campSites": {
"site": [
{
"number": "101",
"siteType": "Tent",
"description": "20 Square Meters",
"pricePerNight": "40.0"
},
{
"number": "102",
"siteType": "Tent",
"description": "25 Square Meters",
"pricePerNight": "40.0"
},
{
"number": "201",
"siteType": "Tent",
"description": "15 Square meters",
"pricePerNight": "40.0"
},
{
"number": "202",
"siteType": "Tent",
"description": "22 Square Meterse",
"pricePerNight": "40.0"
},
{
"number": "203",
"siteType": "Cabin",
"description": "Luxury Cabin for 2",
"pricePerNight": "195.00"
},
{
"number": "204",
"siteType": "Cabin",
"description": "Budget Cabin for 3",
"pricePerNight": "80.0"
},
{
"number": "205",
"siteType": "Cabin",
"description": "Budget Cabin for 3",
"pricePerNight": "80.0"
},
{
"number": "301",
"siteType": "Cabin",
"description": "Budget Cabin for 4",
"pricePerNight": "90.0"
},
{
"number": "302",
"siteType": "Van",
"description": "Powered Van Park",
"pricePerNight": "60.0"
},
{
"number": "303",
"siteType": "Van",
"description": "Large Un-powered Van Park",
"pricePerNight": "60.0"
}
]
}
}
{
"bookings": {
"booking": [
{
"number": "101",
"name": "Mr and Mrs Smith",
"checkin": {
"day": "15",
"month": "8",
"year": "2018"
},
"checkout": {
"day": "21",
"month": "8",
"year": "2018"
}
},
{
"number": "203",
"name": "Alice, Bob, and family",
"checkin": {
"day": "12",
"month": "8",
"year": "2018"
},
"checkout": {
"day": "17",
"month": "8",
"year": "2018"
}
},
{
"number": "204",
"name": "Alice, Bob, and family",
"checkin": {
"day": "12",
"month": "8",
"year": "2018"
},
"checkout": {
"day": "17",
"month": "8",
"year": "2018"
}
},
{
"number": "203",
"name": "Carol and Dave",
"checkin": {
"day": "17",
"month": "8",
"year": "2018"
},
"checkout": {
"day": "21",
"month": "8",
"year": "2018"
}
},
{
"number": "101",
"name": "Nick Meek",
"checkin": {
"day": "1",
"month": "10",
"year": "2018"
},
"checkout": {
"day": "10",
"month": "10",
"year": "2018"
}
},
{
"number": "203",
"name": "Stefanie Zollmann",
"checkin": {
"day": "1",
"month": "10",
"year": "2018"
},
"checkout": {
"day": "10",
"month": "10",
"year": "2018"
}
}
]
}
"bookings": {
"booking": [
{
"number": "101",
"name": "Mr and Mrs Smith",
"checkin": {
"day": "15",
"month": "8",
"year": "2018"
},
"checkout": {
"day": "21",
"month": "8",
"year": "2018"
}
},
{
"number": "203",
"name": "Alice, Bob, and family",
"checkin": {
"day": "12",
"month": "8",
"year": "2018"
},
"checkout": {
"day": "17",
"month": "8",
"year": "2018"
}
},
{
"number": "204",
"name": "Alice, Bob, and family",
"checkin": {
"day": "12",
"month": "8",
"year": "2018"
},
"checkout": {
"day": "17",
"month": "8",
"year": "2018"
}
},
{
"number": "203",
"name": "Carol and Dave",
"checkin": {
"day": "17",
"month": "8",
"year": "2018"
},
"checkout": {
"day": "21",
"month": "8",
"year": "2018"
}
},
{
"number": "101",
"name": "Nick Meek",
"checkin": {
"day": "1",
"month": "10",
"year": "2018"
},
"checkout": {
"day": "10",
"month": "10",
"year": "2018"
}
},
{
"number": "203",
"name": "Stefanie Zollmann",
"checkin": {
"day": "1",
"month": "10",
"year": "2018"
},
"checkout": {
"day": "10",
"month": "10",
"year": "2018"
}
}
]
}
}
\ No newline at end of file
<?php
$bookData = json_decode(file_get_contents("php://input"));
$siteId = $bookData->number;
$name = $bookData->name;
$checkIn = $bookData->checkin;
$checkOut = $bookData->checkout;
/* Add booking to file */
$allBookings = json_decode(file_get_contents("bookings.json", true));
array_push($allBookings->bookings->booking, $bookData);
file_put_contents("bookings.json", json_encode($allBookings, JSON_PRETTY_PRINT));
//echo var_dump($allBookings);
\ No newline at end of file
<?php
$data = json_decode(file_get_contents("php://input"));
$toEdit = $data->toEdit;
$number = $toRemove->number;
$siteType = $toRemove->name;
$description = $toRemove->checkin;
$pricePerNight = $toRemove->checkout;
$toBecome = $data->toBecome;
/* Add booking to file */
$allSites = json_decode(file_get_contents("campsites.json", true));
$indexToEdit = array_search($toEdit, $allSites->campSites->site);
$allSites->campSites->site[$indexToEdit] = $toBecome;
file_put_contents("campsites.json", json_encode($allBookings, JSON_PRETTY_PRINT));
if ($indexToEdit !== NULL) {
echo 1;
}
\ No newline at end of file
<?php
$toRemove = json_decode(file_get_contents("php://input"));
$number = $toRemove->number;
$name = $toRemove->name;
$checkin = $toRemove->checkin;
$checkout = $toRemove->checkout;
/* Add booking to file */
$allBookings = json_decode(file_get_contents("bookings.json", true));
$indexToRemove = array_search($toRemove, $allBookings->bookings->booking);
unset($allBookings->bookings->booking[$indexToRemove]);
$allBookings->bookings->booking = array_values($allBookings->bookings->booking);
file_put_contents("bookings.json", json_encode($allBookings, JSON_PRETTY_PRINT));
if ($indexToRemove !== NULL) {
echo 1;
}
<?php
$toRemove = json_decode(file_get_contents("php://input"));
$number = $toRemove->number;
$siteType = $toRemove->name;
$description = $toRemove->description;
$pricePerNight = $toRemove->pricePerNight;
echo json_encode($toRemove);
$toBecome = $data->toBecome;
/* Add booking to file */
$allSites = json_decode(file_get_contents("campsites.json", true));
$indexToRemove = array_search($toRemove, $allSites->campSites->site);
unset($allSites->campSites->site[$indexToRemove]);
$allSites->campSites->site = array_values($allSites->campSites->site);
file_put_contents("campsites.json", json_encode($allSites, JSON_PRETTY_PRINT));
if ($indexToRemove !== NULL) {
echo 1;
}
\ No newline at end of file
......@@ -4,7 +4,7 @@
<title>QuickCamp</title>
<link rel="stylesheet" href="style/style.css">
<script src="scripts/jquery-3.3.1.min.js"></script>
<script src="scripts/getbookings.js"></script>
<script src="scripts/admin.js"></script>
</head>
<body>
<header>
......@@ -17,6 +17,7 @@
</header>
<main id="admin">
<h3>Bookings:</h3>
<div id="bookingBox">
<table id="bookings">
<tr id="tableHead">
......@@ -27,4 +28,22 @@
</tr>
</table>
</div>
<h3>Sites:</h3>
<div id="siteBox">
<table id="sites">
<tr id="tableHead">
<th>Number</th>
<th>Type</th>
<th>Description</th>
<th>Price</th>
</tr>
</table>
<form id="siteEdit">
<label for="siteId"><span>Number:</span><input id="siteId" type="text"></label>
<label for="siteType"><span>Type:</span><input id="siteType" type="text"></label>
<label for="siteDesc"><span>Description:</span><input id="siteDesc" type="text"></label>
<label for="sitePrice"><span>Price Per Night:</span><input id="sitePrice" type="text"></label>
<input id="confirmEdit" type="button" value="Apply">
</form>
</div>
</main>
\ No newline at end of file
......@@ -4,7 +4,7 @@
<title>QuickCamp</title>
<link rel="stylesheet" href="style/style.css">
<script src="scripts/jquery-3.3.1.min.js"></script>
<script src="scripts/filterSites.js"></script>
<script src="scripts/bookings.js"></script>
<script src="scripts/switchbooking.js"></script>
<script src="scripts/reviews.js"></script>
......
/** Used on admin page */
var Admin = (function () {
"use strict";
var pub = [];
/** Called when a "Delete Booking button" is pressed, removes a booking on the
* server-side, and updates html **/
function deleteBooking() {
var currRow = $(this).parent().parent();
var rowData = currRow.find("td");
var checkin = rowData[2].textContent.split("-");
var checkout = rowData[3].textContent.split("-");
var toRemove = {};
/* Creates object for east search on server side */
toRemove.number = rowData[0].textContent;
toRemove.name = rowData[1].textContent;
toRemove.checkin = {};
toRemove.checkin.day = checkin[0];
toRemove.checkin.month = checkin[1];
toRemove.checkin.year = checkin[2];
toRemove.checkout = {};
toRemove.checkout.day = checkout[0];
toRemove.checkout.month = checkout[1];
toRemove.checkout.year = checkout[2];
$.ajax({
type: "POST",
url: "ServerStorage/removeBooking.php",
data: JSON.stringify(toRemove),
cache: false,
datatype: "JSON",
contentType: "application/json; charset=utf-8",
success: function (successful) {
if (successful) {
currRow.remove();
} else {
alert("Error: Failed to delete item");
}
},
error: function (data) {
alert("Ajax Failed: "+data);
}
});
}
function selectSite() {
console.log("Selected site: "+$(this).parent().find("td")[0].innerHTML);
//todo get site data and save as object
}
/** Called when the edit booking form is submit, replaces the selected site with
* a new one constructed using the data from the form's fields **/
function editSite() {
console.log("Edit confirmed");
}
/** Called when a "Delete Site button" is pressed, removes a site on the
* server-side, and updates html **/
function deleteSite() {
console.log("Delete site: "+$(this).parent().parent().find("td")[0].innerHTML);
var currRow = $(this).parent().parent();
var rowData = currRow.find("td");
var toRemove = {};
/* Creates object for east search on server side */
toRemove.number = rowData[0].textContent;
toRemove.siteType = rowData[1].textContent;
toRemove.description = rowData[2].textContent;
toRemove.pricePerNight = rowData[3].textContent;
$.ajax({
type: "POST",
url: "ServerStorage/removeSite.php",
data: JSON.stringify(toRemove),
cache: false,
datatype: "JSON",
contentType: "application/json; charset=utf-8",
success: function (successful) {
if (successful) {
currRow.remove();
} else {
alert("Error: Failed to delete item");
}
},
error: function (data) {
alert("Ajax Failed: "+data);
}
});
}
/** Adds a booking to the bokings table **/
function tableAddBooking(booking) {
var checkIn = booking.checkin.day + "-" + booking.checkin.month + "-" + booking.checkin.year;
var checkOut = booking.checkout.day + "-" + booking.checkout.month + "-" + booking.checkout.year;
$("#bookings").append("<tr class='resultRow'>" +
"<td>" + booking.number + "</td>" +
"<td>" + booking.name + "</td>" +
"<td>" + checkIn + "</td>" +
"<td>" + checkOut + "</td>" +
"<td><input value='Delete Booking' type='button' class='deleteBooking'>" +
"</tr>");
}
/** Adds a site to the site table **/
function tableAddSite(site) {
$("#sites").append("<tr class='resultRow'>" +
"<td>" + site.number + "</td>" +
"<td>" + site.siteType + "</td>" +
"<td>" + site.description + "</td>" +
"<td>" + site.pricePerNight + "</td>" +
"<td><input value='Edit Site' type='button' class='editSite'>" +
"<input value='Delete Site' type='button' class='deleteSite'>" +
"</tr>");
}
/** Setup Function **/
pub.setup = function() {
/** Get Bookings**/
$.ajax({
type: "GET",
url: "ServerStorage/bookings.json",
cache: false,
datatype: "JSON",
contentType: "application/json; charset=utf-8",
success: function (data) {
var i = 0;
var bookings = data.bookings.booking;
Object.keys(bookings).forEach(function(cBook) {
tableAddBooking(bookings[cBook]);
$($(".deleteBooking")[i]).click(deleteBooking);
i += 1;
});
},