init
This commit is contained in:
commit
7cd04e2a52
8
.idea/.gitignore
generated
vendored
Normal file
8
.idea/.gitignore
generated
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
||||
8
.idea/Web_Rippchen.iml
generated
Normal file
8
.idea/Web_Rippchen.iml
generated
Normal file
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="WEB_MODULE" version="4">
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$" />
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
||||
8
.idea/modules.xml
generated
Normal file
8
.idea/modules.xml
generated
Normal file
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/Web_Rippchen.iml" filepath="$PROJECT_DIR$/.idea/Web_Rippchen.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
||||
19
.idea/php.xml
generated
Normal file
19
.idea/php.xml
generated
Normal file
@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="MessDetectorOptionsConfiguration">
|
||||
<option name="transferred" value="true" />
|
||||
</component>
|
||||
<component name="PHPCSFixerOptionsConfiguration">
|
||||
<option name="transferred" value="true" />
|
||||
</component>
|
||||
<component name="PHPCodeSnifferOptionsConfiguration">
|
||||
<option name="highlightLevel" value="WARNING" />
|
||||
<option name="transferred" value="true" />
|
||||
</component>
|
||||
<component name="PhpStanOptionsConfiguration">
|
||||
<option name="transferred" value="true" />
|
||||
</component>
|
||||
<component name="PsalmOptionsConfiguration">
|
||||
<option name="transferred" value="true" />
|
||||
</component>
|
||||
</project>
|
||||
6
.idea/vcs.xml
generated
Normal file
6
.idea/vcs.xml
generated
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
46
add_restaurant.php
Normal file
46
add_restaurant.php
Normal file
@ -0,0 +1,46 @@
|
||||
<?php
|
||||
include 'db_connection.php';
|
||||
session_start();
|
||||
|
||||
if (!isset($_SESSION['username'])) {
|
||||
header("Location: login.php"); // Redirect if not logged in
|
||||
exit();
|
||||
}
|
||||
|
||||
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
||||
$name = sanitize_input($_POST['name']);
|
||||
$maps_link = sanitize_input($_POST['maps_link']);
|
||||
|
||||
$sql = "INSERT INTO Restaurant (name, maps_link) VALUES ('$name', '$maps_link')";
|
||||
|
||||
if ($conn->query($sql) === TRUE) {
|
||||
$restaurant_success = "Restaurant added successfully!";
|
||||
} else {
|
||||
$restaurant_error = "Error: " . $sql . "<br>" . $conn->error;
|
||||
}
|
||||
}
|
||||
|
||||
$conn->close();
|
||||
?>
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Add Restaurant</title>
|
||||
</head>
|
||||
<body>
|
||||
<h2>Add New Restaurant</h2>
|
||||
<?php if (isset($restaurant_error)): ?>
|
||||
<p style="color:red;"><?php echo $restaurant_error; ?></p>
|
||||
<?php endif; ?>
|
||||
<?php if (isset($restaurant_success)): ?>
|
||||
<p style="color:green;"><?php echo $restaurant_success; ?></p>
|
||||
<?php endif; ?>
|
||||
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>">
|
||||
Name: <input type="text" name="name" required><br><br>
|
||||
Maps Link: <input type="text" name="maps_link"><br><br>
|
||||
<input type="submit" value="Add Restaurant">
|
||||
</form>
|
||||
<p><a href="index.php">Back to Dashboard</a></p>
|
||||
</body>
|
||||
</html>
|
||||
70
add_review.php
Normal file
70
add_review.php
Normal file
@ -0,0 +1,70 @@
|
||||
<?php
|
||||
include 'db_connection.php';
|
||||
session_start();
|
||||
|
||||
if (!isset($_SESSION['username'])) {
|
||||
header("Location: login.php"); // Redirect if not logged in
|
||||
exit();
|
||||
}
|
||||
|
||||
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
||||
$fk_restaurant_id = sanitize_input($_POST['fk_restaurant_id']);
|
||||
$bewertung_int = sanitize_input($_POST['bewertung_int']);
|
||||
$bewertung_str = sanitize_input($_POST['bewertung_str']);
|
||||
$fk_user_id = $_SESSION['user_id']; // Get user ID from session
|
||||
|
||||
// Validate the rating (0-10)
|
||||
if ($bewertung_int < 0 || $bewertung_int > 10) {
|
||||
$review_error = "Rating must be between 0 and 10.";
|
||||
} else {
|
||||
$sql = "INSERT INTO Bewertung (fk_user_id, fk_restaurant_id, bewertung, bewertung_str) VALUES ($fk_user_id, $fk_restaurant_id, $bewertung_int, '$bewertung_str')";
|
||||
|
||||
if ($conn->query($sql) === TRUE) {
|
||||
$review_success = "Review added successfully!";
|
||||
} else {
|
||||
$review_error = "Error: " . $sql . "<br>" . $conn->error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Fetch restaurants for the dropdown
|
||||
$restaurants_sql = "SELECT id, name FROM Restaurant";
|
||||
$restaurants_result = $conn->query($restaurants_sql);
|
||||
$restaurants = [];
|
||||
if ($restaurants_result->num_rows > 0) {
|
||||
while ($row = $restaurants_result->fetch_assoc()) {
|
||||
$restaurants[$row['id']] = $row['name'];
|
||||
}
|
||||
}
|
||||
|
||||
$conn->close();
|
||||
?>
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Add Review</title>
|
||||
</head>
|
||||
<body>
|
||||
<h2>Add New Review</h2>
|
||||
<?php if (isset($review_error)): ?>
|
||||
<p style="color:red;"><?php echo $review_error; ?></p>
|
||||
<?php endif; ?>
|
||||
<?php if (isset($review_success)): ?>
|
||||
<p style="color:green;"><?php echo $review_success; ?></p>
|
||||
<?php endif; ?>
|
||||
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>">
|
||||
Restaurant:
|
||||
<select name="fk_restaurant_id" required>
|
||||
<option value="">Select Restaurant</option>
|
||||
<?php foreach ($restaurants as $id => $name): ?>
|
||||
<option value="<?php echo $id; ?>"><?php echo $name; ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select><br><br>
|
||||
Rating (0-10): <input type="number" name="bewertung_int" min="0" max="10" required><br><br>
|
||||
Review Text: <textarea name="bewertung_str"></textarea><br><br>
|
||||
<input type="submit" value="Add Review">
|
||||
</form>
|
||||
<p><a href="index.php">Back to Dashboard</a></p>
|
||||
</body>
|
||||
</html>
|
||||
136
central.css
Normal file
136
central.css
Normal file
@ -0,0 +1,136 @@
|
||||
/* central.css */
|
||||
|
||||
/* General Styles */
|
||||
body {
|
||||
font-family: sans-serif;
|
||||
margin: 20px;
|
||||
background-color: #f4f4f4;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
h1, h2, h3 {
|
||||
color: #337ab7;
|
||||
}
|
||||
|
||||
a {
|
||||
color: #337ab7;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
a:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
p {
|
||||
line-height: 1.6;
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
|
||||
/* Form Styles */
|
||||
form {
|
||||
background-color: #fff;
|
||||
padding: 20px;
|
||||
border: 1px solid #ddd;
|
||||
border-radius: 5px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
label {
|
||||
display: block;
|
||||
margin-bottom: 5px;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
input[type="text"],
|
||||
input[type="password"],
|
||||
input[type="number"],
|
||||
select,
|
||||
textarea {
|
||||
width: calc(100% - 12px); /* Adjust for padding */
|
||||
padding: 8px;
|
||||
margin-bottom: 10px;
|
||||
border: 1px solid #ccc;
|
||||
border-radius: 4px;
|
||||
box-sizing: border-box; /* Ensure padding and border are inside the element's total width and height */
|
||||
font-size: 1em;
|
||||
}
|
||||
|
||||
input[type="submit"] {
|
||||
background-color: #5cb85c;
|
||||
color: white;
|
||||
padding: 10px 15px;
|
||||
border: none;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
font-size: 1em;
|
||||
}
|
||||
|
||||
input[type="submit"]:hover {
|
||||
background-color: #4cae4c;
|
||||
}
|
||||
|
||||
.error {
|
||||
color: red;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.success {
|
||||
color: green;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
/* Navigation Styles (if you add a navigation later) */
|
||||
nav ul {
|
||||
list-style: none;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
background-color: #333;
|
||||
overflow: hidden;
|
||||
border-radius: 5px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
nav ul li {
|
||||
float: left;
|
||||
}
|
||||
|
||||
nav ul li a {
|
||||
display: block;
|
||||
color: white;
|
||||
text-align: center;
|
||||
padding: 14px 16px;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
nav ul li a:hover {
|
||||
background-color: #111;
|
||||
}
|
||||
|
||||
/* Table Styles (if you display data in tables) */
|
||||
table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
margin-bottom: 20px;
|
||||
border: 1px solid #ddd;
|
||||
}
|
||||
|
||||
th, td {
|
||||
border: 1px solid #ddd;
|
||||
padding: 8px;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
th {
|
||||
background-color: #f2f2f2;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
/* Specific elements for your pages */
|
||||
/* You can add more specific styles here as needed */
|
||||
|
||||
/* Example for the welcome message on index.php */
|
||||
.welcome-message {
|
||||
margin-bottom: 20px;
|
||||
font-size: 1.2em;
|
||||
font-weight: bold;
|
||||
}
|
||||
16
db_connection.php
Normal file
16
db_connection.php
Normal file
@ -0,0 +1,16 @@
|
||||
<?php
|
||||
$databaseFile = 'rippchen.db'; // Path to your SQLite database file
|
||||
|
||||
try {
|
||||
$db = new PDO("sqlite:" . $databaseFile);
|
||||
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||
} catch (PDOException $e) {
|
||||
die("Database connection failed: " . $e->getMessage());
|
||||
}
|
||||
|
||||
// Function to sanitize user input (remains the same)
|
||||
function sanitize_input($data) {
|
||||
$data = trim($data);
|
||||
$data = stripslashes($data);
|
||||
return htmlspecialchars($data);
|
||||
}
|
||||
13
index.php
Normal file
13
index.php
Normal file
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
session_start();
|
||||
|
||||
if (!isset($_SESSION['username'])) {
|
||||
header("Location: login.php"); // Redirect if not logged in
|
||||
exit();
|
||||
}
|
||||
|
||||
echo "Welcome, " . $_SESSION['username'] . "!";
|
||||
echo "<p><a href='add_restaurant.php'>Add Restaurant</a></p>";
|
||||
echo "<p><a href='add_review.php'>Add Review</a></p>";
|
||||
echo "<p><a href='logout.php'>Logout</a></p>";
|
||||
?>
|
||||
52
login.php
Normal file
52
login.php
Normal file
@ -0,0 +1,52 @@
|
||||
<?php
|
||||
include 'db_connection.php';
|
||||
session_start();
|
||||
|
||||
if (isset($_SESSION['username'])) {
|
||||
header("Location: index.php"); // Redirect to a logged-in page
|
||||
exit();
|
||||
}
|
||||
|
||||
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
||||
$username = sanitize_input($_POST['username']);
|
||||
$password = sanitize_input($_POST['password']);
|
||||
|
||||
$sql = "SELECT id, username, password FROM User WHERE username='$username'";
|
||||
$result = $conn->query($sql);
|
||||
|
||||
if ($result->num_rows == 1) {
|
||||
$row = $result->fetch_assoc();
|
||||
if (password_verify($password, $row['password'])) {
|
||||
$_SESSION['username'] = $row['username'];
|
||||
$_SESSION['user_id'] = $row['id'];
|
||||
header("Location: index.php"); // Redirect after successful login
|
||||
exit();
|
||||
} else {
|
||||
$login_error = "Invalid username or password.";
|
||||
}
|
||||
} else {
|
||||
$login_error = "Invalid username or password.";
|
||||
}
|
||||
}
|
||||
|
||||
$conn->close();
|
||||
?>
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Login</title>
|
||||
</head>
|
||||
<body>
|
||||
<h2>Login</h2>
|
||||
<?php if (isset($login_error)): ?>
|
||||
<p style="color:red;"><?php echo $login_error; ?></p>
|
||||
<?php endif; ?>
|
||||
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>">
|
||||
Username: <input type="text" name="username" required><br><br>
|
||||
Password: <input type="password" name="password" required><br><br>
|
||||
<input type="submit" value="Login">
|
||||
</form>
|
||||
<p>Don't have an account? <a href="register.php">Register here</a></p>
|
||||
</body>
|
||||
</html>
|
||||
6
logout.php
Normal file
6
logout.php
Normal file
@ -0,0 +1,6 @@
|
||||
<?php
|
||||
session_start();
|
||||
session_destroy();
|
||||
header("Location: login.php"); // Redirect to login page after logout
|
||||
exit();
|
||||
?>
|
||||
55
register.php
Normal file
55
register.php
Normal file
@ -0,0 +1,55 @@
|
||||
<?php
|
||||
include 'db_connection.php';
|
||||
|
||||
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
||||
$vorname = sanitize_input($_POST['vorname']);
|
||||
$nachname = sanitize_input($_POST['nachname']);
|
||||
$username = sanitize_input($_POST['username']);
|
||||
$password = sanitize_input($_POST['password']);
|
||||
|
||||
// Hash the password for security
|
||||
$hashed_password = password_hash($password, PASSWORD_DEFAULT);
|
||||
|
||||
// Check if the username already exists
|
||||
$check_sql = "SELECT username FROM User WHERE username='$username'";
|
||||
$check_result = $conn->query($check_sql);
|
||||
|
||||
if ($check_result->num_rows > 0) {
|
||||
$registration_error = "Username already exists. Please choose a different one.";
|
||||
} else {
|
||||
$sql = "INSERT INTO User (vorname, nachname, username, password) VALUES ('$vorname', '$nachname', '$username', '$hashed_password')";
|
||||
|
||||
if ($conn->query($sql) === TRUE) {
|
||||
$registration_success = "Registration successful! You can now <a href='login.php'>login</a>.";
|
||||
} else {
|
||||
$registration_error = "Error: " . $sql . "<br>" . $conn->error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$conn->close();
|
||||
?>
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Register</title>
|
||||
</head>
|
||||
<body>
|
||||
<h2>Register</h2>
|
||||
<?php if (isset($registration_error)): ?>
|
||||
<p style="color:red;"><?php echo $registration_error; ?></p>
|
||||
<?php endif; ?>
|
||||
<?php if (isset($registration_success)): ?>
|
||||
<p style="color:green;"><?php echo $registration_success; ?></p>
|
||||
<?php endif; ?>
|
||||
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>">
|
||||
Vorname: <input type="text" name="vorname" required><br><br>
|
||||
Nachname: <input type="text" name="nachname" required><br><br>
|
||||
Username: <input type="text" name="username" required><br><br>
|
||||
Password: <input type="password" name="password" required><br><br>
|
||||
<input type="submit" value="Register">
|
||||
</form>
|
||||
<p>Already have an account? <a href="login.php">Login here</a></p>
|
||||
</body>
|
||||
</html>
|
||||
Loading…
Reference in New Issue
Block a user