173 lines
7.4 KiB
PHP
173 lines
7.4 KiB
PHP
<html>
|
|
<title>RoamEase</title>
|
|
<link rel="shortcut icon" href="../../../icon/favicon/favicon.ico" type="image/x-icon" />
|
|
<link rel="icon" href="../../../icon/favicon/favicon.ico" type="image/x-icon" />
|
|
<link rel="stylesheet" href="../home.css?version=1" type="text/css" />
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<header>
|
|
<style>
|
|
.pagebutton{
|
|
background-color: #ADD8FF;
|
|
border: none;
|
|
color: white;
|
|
text-decoration: none;
|
|
display: inline-block;
|
|
font-size: 13px;
|
|
width:10%;
|
|
border-radius: 10px;
|
|
font-size:17px;
|
|
transition:background-color 0.3s ease;
|
|
}
|
|
</style>
|
|
<div class="logo">
|
|
<a href="../home.php"><img src="../../../icon/favicon/logo_white.svg" alt="RoamEase"></a>
|
|
</div>
|
|
|
|
<div class="nav-links">
|
|
<?php
|
|
session_start();
|
|
if (isset($_SESSION['loggedin'])) {
|
|
echo '<a href="../process/cart.php">Cart</a>
|
|
<a href="../../../login/login.php">Account</a>';
|
|
}
|
|
else {
|
|
echo '<a href="../../../login/register.php">Sign up</a>
|
|
<a href="../../../login/username.php">Log in</a>';
|
|
}
|
|
?>
|
|
</div>
|
|
</header>
|
|
|
|
<header>
|
|
<nav>
|
|
<a href="../stays.php">
|
|
<img src="../../../icon/header/stays.svg" alt="Stays">
|
|
</a>
|
|
<a href="../transport.php">
|
|
<img src="../../../icon/header/transportations.svg" alt="Transportations">
|
|
</a>
|
|
<a href="../foods.php">
|
|
<img src="../../../icon/header/foods.svg" alt="Foods">
|
|
</a>
|
|
<a href="../attractions.php" style="border-color: white;">
|
|
<img src="../../../icon/header/attractions.svg" alt="Attractions">
|
|
</a>
|
|
<a href="../guiding.php">
|
|
<img src="../../../icon/header/guiding.svg" alt="Guiding">
|
|
</a>
|
|
<a href="../plans.php">
|
|
<img src="../../../icon/header/plans.svg" alt="Plans">
|
|
</a>
|
|
</nav>
|
|
</header>
|
|
|
|
<style>
|
|
table tr td:first-child {
|
|
width: 160px;
|
|
}
|
|
</style>
|
|
<script>
|
|
var attractionDetail; // Declare globally
|
|
var aid; // Declare globally
|
|
|
|
function GoodFunction(){
|
|
var urlParams = new URLSearchParams(window.location.search);
|
|
aid = urlParams.get('id');
|
|
var xmlhttp = new XMLHttpRequest();
|
|
xmlhttp.onreadystatechange = function() {
|
|
if (this.readyState == 4 && this.status == 200) {
|
|
attractionDetail = JSON.parse(this.responseText);
|
|
console.log(attractionDetail);
|
|
var detailHtml = '<table style="border-collapse: collapse; width:100%; height:70%; margin-top:-0.1%;">';
|
|
detailHtml += '<tr><td>Name</td><td>' + attractionDetail[0].train_code + '</td></tr>';
|
|
detailHtml += '<tr><td>Departure</td><td>' + attractionDetail[0].from_name +'<td>Station: ' +attractionDetail[0].departure_station_name+'</td></tr>';
|
|
detailHtml += '<tr><td>Destination</td><td>' + attractionDetail[0].dest_name +'<td>Station: ' +attractionDetail[0].arrival_station_name+'</td></tr>';
|
|
detailHtml += '<tr><td>Week routine</td><td>' + attractionDetail[0].week_routine + '</td></tr>';
|
|
detailHtml += '<tr><td>Strat time</td><td>' + attractionDetail[0].start_time + '</td></tr>';
|
|
detailHtml += '<tr><td>Arrive time</td><td>' + attractionDetail[0].arrive_time + '</td></tr>';
|
|
for (var i = 0; i < attractionDetail.length; i++) {
|
|
detailHtml += '<tr>';
|
|
detailHtml += '<td><input type="radio" id="train_seat_id" name="train_seat_id" value="' + attractionDetail[i].train_seat_id + '">';
|
|
detailHtml += attractionDetail[i].class + '</td>';
|
|
detailHtml += '<td>' + attractionDetail[i].fee + 'RMB</td>';
|
|
detailHtml += '<td><div style="padding: 10px 20px;background-color: #1E90FF;color: white;cursor: pointer;" onclick="addToPlan(' + attractionDetail[i].train_seat_id + ')">Add to Plan</div></td>';
|
|
if (i==0){
|
|
detailHtml += '<tr><td><button id="add_cart">Add cart</button></td></tr>';
|
|
}
|
|
detailHtml += '</tr>';
|
|
}
|
|
|
|
detailHtml += '<tr><td><div class="input-field with button"><input type="date" id="start_date" class="edit-button" name="start_date" style="border:none;" onchange="setMinEndDate()" onkeydown="return false" required><label for="start_date">Visit date</label></td>';
|
|
detailHtml += '<td><div class="input-field"><input type="number" id="quantity" name="quantity" placeholder=" " required value=""><label for="quantity">Quantity</label></div></td></tr>';
|
|
|
|
|
|
detailHtml += '</table>';
|
|
detailHtml +='<a href="../railway.php" style="text-decoration:none;"><button class="pageButton">Go back</button></a>';
|
|
document.getElementById("detail").innerHTML = detailHtml;
|
|
}
|
|
document.getElementById('add_cart').addEventListener('click', add_cart);
|
|
}
|
|
xmlhttp.open("GET", "getRaInfo.php?id=" + aid, true);
|
|
xmlhttp.send();
|
|
}
|
|
|
|
function add_cart() {
|
|
let start_date = document.getElementById("start_date").value;
|
|
let quantity = document.getElementById("quantity").value;
|
|
let price = attractionDetail[0].price; // Now accessible
|
|
let product_id = document.getElementById("train_seat_id").value;
|
|
|
|
window.location.href = '../addcart.php?target_id=' + product_id + '&start_date=' + start_date + '&end_date=NULL&quantity=' + quantity + '&table=6&price=' + price;
|
|
}
|
|
|
|
GoodFunction();
|
|
|
|
function addToPlan(trainClassId) {
|
|
var startDate = prompt("Select visit_date:", formatDate(new Date()));
|
|
if (startDate) {
|
|
var url = `../plans_do.php?trainClassId=${trainClassId}&visit_date=${startDate}`;
|
|
|
|
fetch(url)
|
|
.then(response => {
|
|
if (!response.ok) {
|
|
throw new Error(`Error adding to the plan. Status code: ${response.status}`);
|
|
}
|
|
return response.json();
|
|
})
|
|
.then(data => {
|
|
if (data.code === 0) {
|
|
alert(data.msg)
|
|
} else {
|
|
console.error(`Error adding to the plan. Message: ${data.message}`);
|
|
}
|
|
})
|
|
.catch(error => {
|
|
console.error("Fetch error:", error);
|
|
});
|
|
}
|
|
}
|
|
|
|
function formatDate(date) {
|
|
var year = date.getFullYear();
|
|
var month = (date.getMonth() + 1).toString().padStart(2, '0');
|
|
var day = date.getDate().toString().padStart(2, '0');
|
|
return year + '-' + month + '-' + day;
|
|
}
|
|
</script>
|
|
<div id="detail"></div><br><br><br>
|
|
<footer>
|
|
<div class="logo">
|
|
<a href="../../../index.php"><img src="../../../icon/favicon/textlogo.svg" alt="RoamEase" height="50px"></a>
|
|
<p style="font-size:10%;">©2023 COMP3013 Group10</p>
|
|
</div>
|
|
|
|
<div class="nav-links" style="font-size: 80%;">
|
|
<a href="#" style="color: white; margin: 0 10px;">About us</a>
|
|
<a href="#" style="color: white; margin: 0 10px;">Privacy Policy</a>
|
|
<a href="#" style="color: white; margin: 0 10px;">Terms For Usage</a>
|
|
</div>
|
|
|
|
</footer>
|
|
</html>
|