2025-06-06 17:31:03 +08:00

175 lines
8.2 KiB
PHP

<?php
session_start();
if (!isset($_SESSION['usertype']) || $_SESSION['usertype'] !== "seller") {
header('Location: ../../index.php');
exit();
}
?>
<html>
<head>
<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="../user/home.css?version=1" type="text/css" />
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
td{padding:3px;}
table{background-color:rgb(255, 255, 255,0.5);}
#div_ground {
position: absolute;
top: 100px;
left: 0px;
width: 100%;
height: 100%;
background-color:rgb(225, 240, 255);
}
#div_add {
position: absolute;
top: 25%;
left: 25%;
width: 50%;
height: 50%;
}
</style>
</head>
<body>
<header>
<div class="logo">
<a href="home.php"><img src="../../icon/favicon/logo_white.svg" alt="RoamEase"></a>
</div>
<div class="nav-links">
<a href="../seller/home.php">Back To Home</a>
</div>
</header>
<header>
<nav>
<a href="stays.php">
<img src="../../icon/header/stays.svg" alt="Stays">
</a>
<a href="foods.php">
<img src="../../icon/header/foods.svg" alt="foods">
</a>
<a href="attractions.php">
<img src="../../icon/header/attractions.svg" alt="Attractions">
</a>
</nav>
</header>
<div id="div_ground"></div>
<div id="div_add">
<form method="POST" action="">
<table style="text-align: right;border:black '1';width: 100%;height: 100%;" align="center">
<tr>
<td colspan="2"><p style="text-align: center;font-size: 30px;"><b>Add Restaurant</p></td>
</tr>
<tr>
<td><label for="restaurant_name">Restaurant name:</label></td>
<td style="text-align: left"><input type="text" id="restaurant_name" name="restaurant_name" required></td>
</tr>
<tr>
<td><label for="city_id">City id:</label></td>
<td style="text-align: left"><input type="number" min="1" max="151335" id="city_id" name="city_id" required></td>
</tr>
<tr>
<td><label for="location">Location:</label></td>
<td style="text-align: left"><input type="text" id="location" name="location" required></td>
</tr>
<tr>
<td><label for="open_day">Open day:</label></td>
<td style="text-align: left"><select id="open_day" name="open_day">
<option value="Monday">Monday</option>
<option value="Tuesday">Tuesday</option>
<option value="Wednesday">Wednesday</option>
<option value="Thursday">Thursday</option>
<option value="Friday">Friday</option>
<option value="Saturday">Saturday</option>
<option value="Sunday">Sunday</option>
</select></td>
</tr>
<tr>
<td><label for="close_day">Close day:</label></td>
<td style="text-align: left"><select id="close_day" name="close_day">
<option value="Monday">Monday</option>
<option value="Tuesday">Tuesday</option>
<option value="Wednesday">Wednesday</option>
<option value="Thursday">Thursday</option>
<option value="Friday">Friday</option>
<option value="Saturday">Saturday</option>
<option value="Sunday">Sunday</option>
</select></td>
</tr>
<tr>
<td><label for="open_time">Open time:</label></td>
<td style="text-align: left"><input type="time" id="open_time" name="open_time" required></td>
</tr>
<tr>
<td><label for="close_time">Close time:</label></td>
<td style="text-align: left"><input type="time" id="close_time" name="close_time" required></td>
</tr>
<tr>
<td><label for="style">Restaurant style:</label></td>
<td style="text-align: left"><input type="number" id="style" name="style" required></td>
</tr>
<tr>
<td><label for="description">Description:</label></td>
<td style="text-align: left"><textarea id="description" name="description" required></textarea></td>
</tr>
<tr>
<td><label for="fee">fee(CNY):</label></td>
<td style="text-align: left"><input type="fee" id="fee" name="fee" required></td>
</tr>
<tr>
<td colspan="2" style="text-align: center"><button type="submit">Add Restaurant</button></td>
</tr>
</table>
</form>
<?php
include "../ConnectDB.php";
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
//echo "Connected successfully";
// Process form submission
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Get form data
$restaurant_name = $_POST["restaurant_name"];
$city_id = $_POST["city_id"];
$location = $_POST["location"];
$open_day = $_POST["open_day"];
$close_day = $_POST["close_day"];
$open_time = $_POST["open_time"];
$close_time = $_POST["close_time"];
$style = $_POST["style"];
$description = $_POST["description"];
$fee = $_POST["fee"];
$seller_id = $_SESSION['uid'];
$start=microtime(true);
// Insert data into the database
$sql = "INSERT INTO restaurant ( name, city_id, location, seller_id, open_day, close_day, open_time, close_time, restaurant_style_id, descrip, fee) VALUES ('$restaurant_name', '$city_id', '$location', '$seller_id', '$open_day', '$close_day', '$open_time', '$close_time', '$style', '$description', '$fee')";
if ($conn->query($sql) === TRUE) {
$end = microtime(true);
$execution_time = $end - $start;
$phpVariable = "Add restaurant success. Running time: ". $execution_time."s";
echo '<script>';
echo 'var jsVariable = "' . $phpVariable . '";';
echo 'alert(jsVariable);';
echo '</script>';
} else {
$end = microtime(true);
$execution_time = $end - $start;
echo "Error: " . $sql . "<br>" . $conn->error;
}
}
// close the database
$conn->close();
?>
</div>
</body>
</html>