init
This commit is contained in:
@@ -1,3 +1,15 @@
|
||||
# Wunschliste
|
||||
|
||||
Eine simple PHP Wunschliste
|
||||
Dies ist eine einfache Wunschliste gemacht mit PHP!
|
||||
|
||||
|
||||
## Installation
|
||||
|
||||
Du installierst es einfach in dem du die ZIP Datei von den Releases Herunterlädst und es in dein Webserver mit PHP Hochlädst.
|
||||
|
||||
Du kannst außerdem in der config.php deinen Namen angeben der Dan überall steht.
|
||||
|
||||
Mit in /admin befindet sich das Admin Panel wo die die einträge verwalten kanst.
|
||||
|
||||
> [!Warning]
|
||||
> Die /admin Seite ist Standardmäßig nicht geschützt! Bitte schütze diese mit z.b. einem Login über den Webserver
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
$requestMethod = $_SERVER['REQUEST_METHOD'] ?? '';
|
||||
if ($requestMethod !== 'POST') {
|
||||
header("Location: /admin/");
|
||||
exit;
|
||||
}
|
||||
|
||||
$name = $_POST["name"] ?? '';
|
||||
$link = $_POST["link"] ?? '';
|
||||
$price = $_POST["price"] ?? '';
|
||||
|
||||
$jsonFile = '../wishes.json';
|
||||
|
||||
$wishes = [];
|
||||
if (file_exists($jsonFile)) {
|
||||
$jsonData = file_get_contents($jsonFile);
|
||||
$decodedData = json_decode($jsonData, true);
|
||||
if (is_array($decodedData)) {
|
||||
$wishes = $decodedData;
|
||||
}
|
||||
}
|
||||
|
||||
$newId = 1;
|
||||
if (!empty($wishes)) {
|
||||
$ids = array_column($wishes, 'id');
|
||||
$newId = max($ids) + 1;
|
||||
}
|
||||
|
||||
$newWish = [
|
||||
'id' => $newId,
|
||||
'name' => $name,
|
||||
'link' => $link,
|
||||
'price' => $price
|
||||
];
|
||||
|
||||
$wishes[] = $newWish;
|
||||
|
||||
if (file_put_contents($jsonFile, json_encode($wishes, JSON_PRETTY_PRINT)) !== false) {
|
||||
header("Location: .");
|
||||
} else {
|
||||
header("Location: .?error=write_failed");
|
||||
}
|
||||
exit;
|
||||
?>
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
$id = intval($_GET["id"]);
|
||||
|
||||
$jsonFile = '../wishes.json';
|
||||
|
||||
if (file_exists($jsonFile)) {
|
||||
$wishes = json_decode(file_get_contents($jsonFile), true);
|
||||
|
||||
$wishes = array_filter($wishes, function($wish) use ($id) {
|
||||
return $wish['id'] != $id;
|
||||
});
|
||||
|
||||
$wishes = array_values($wishes);
|
||||
|
||||
if (file_put_contents($jsonFile, json_encode($wishes, JSON_PRETTY_PRINT))) {
|
||||
header("Location: .");
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
header("Location: .?error=true");
|
||||
exit;
|
||||
?>
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
$name = $_POST["name"];
|
||||
$link = $_POST["link"];
|
||||
$price = $_POST["price"];
|
||||
$id = intval($_POST["id"]);
|
||||
|
||||
$jsonFile = '../wishes.json';
|
||||
|
||||
if (file_exists($jsonFile)) {
|
||||
$wishes = json_decode(file_get_contents($jsonFile), true);
|
||||
$found = false;
|
||||
|
||||
foreach ($wishes as $key => $wish) {
|
||||
if ($wish['id'] == $id) {
|
||||
$wishes[$key]['name'] = $name;
|
||||
$wishes[$key]['link'] = $link;
|
||||
$wishes[$key]['price'] = $price;
|
||||
$found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($found && file_put_contents($jsonFile, json_encode($wishes, JSON_PRETTY_PRINT))) {
|
||||
header("Location: .");
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
header("Location: .?error=true");
|
||||
exit;
|
||||
?>
|
||||
@@ -0,0 +1,67 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="de">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>Wunschliste von <?php include '../config.php'; echo $page_name; ?> [ADMIN]</title>
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
</head>
|
||||
<body>
|
||||
<?php
|
||||
if (isset($_GET["error"])) {
|
||||
echo '<div class="alert alert-danger" role="alert">
|
||||
Dateisystem Fehler (Schreibrechte prüfen!).
|
||||
</div>';
|
||||
}
|
||||
?>
|
||||
<div class="container py-5">
|
||||
<div class="row row-cols-1 row-cols-md-2 row-cols-lg-3 g-4">
|
||||
<?php
|
||||
ini_set("display_errors", 1);
|
||||
error_reporting(E_ALL);
|
||||
|
||||
$jsonFile = '../wishes.json';
|
||||
$wishes = [];
|
||||
|
||||
if (file_exists($jsonFile)) {
|
||||
$jsonData = file_get_contents($jsonFile);
|
||||
$wishes = json_decode($jsonData, true);
|
||||
if (!$wishes) $wishes = [];
|
||||
}
|
||||
|
||||
foreach ($wishes as $row) {
|
||||
echo '
|
||||
<div class="col">
|
||||
<div class="card link-card h-100">
|
||||
<div class="card-body">
|
||||
<form action="edit.php" method="post">
|
||||
<input type="hidden" name="id" value="' . $row["id"] . '">
|
||||
<input type="text" name="name" class="form-control mb-2" value="' . htmlspecialchars($row["name"]) . '">
|
||||
<input type="text" name="link" class="form-control mb-2" value="' . htmlspecialchars($row["link"]) . '">
|
||||
<input type="text" name="price" class="form-control mb-2" value="' . htmlspecialchars($row["price"]) . '">
|
||||
<button type="submit" class="btn btn-primary">Speichern</button>
|
||||
<a href="delete.php?id=' . $row["id"] . '" class="btn btn-danger float-end">Löschen</a>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>';
|
||||
}
|
||||
?>
|
||||
<div class="col">
|
||||
<div class="card link-card h-100">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">Neuer Wunsch</h5>
|
||||
<form action="add.php" method="post">
|
||||
<input type="text" name="name" class="form-control mb-2" placeholder="Name">
|
||||
<input type="text" name="link" class="form-control mb-2" placeholder="URL">
|
||||
<input type="text" name="price" class="form-control mb-2" placeholder="Preis">
|
||||
<button type="submit" class="btn btn-primary">Hinzufügen</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
// _ __ __ _ _ _
|
||||
// | |/ / / _(_) | | (_)
|
||||
// | ' / ___ _ __ | |_ _ __ _ _ _ _ __ __ _| |_ _ ___ _ __
|
||||
// | < / _ \| '_ \| _| |/ _` | | | | '__/ _` | __| |/ _ \| '_ \
|
||||
// | . \ (_) | | | | | | | (_| | |_| | | | (_| | |_| | (_) | | | |
|
||||
// |_|\_\___/|_| |_|_| |_|\__, |\__,_|_| \__,_|\__|_|\___/|_| |_|
|
||||
// __/ |
|
||||
// |___/
|
||||
|
||||
|
||||
// DEIN NAME HIER:
|
||||
$page_name = 'Jakob';
|
||||
@@ -0,0 +1,69 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="de">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>Wunschliste von <?php include 'config.php'; echo $page_name; ?></title>
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
<style>
|
||||
body {
|
||||
transition: background-color 0.3s, color 0.3s;
|
||||
margin: 100px;
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: dark) {
|
||||
|
||||
body {
|
||||
background-color: #1a1a1a;
|
||||
color: #f0f0f0;
|
||||
}
|
||||
|
||||
|
||||
a {
|
||||
color: #8ab4f8;
|
||||
}
|
||||
}
|
||||
@media (max-whidth: 600px) {
|
||||
body {
|
||||
margin: 8px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body">
|
||||
<h1 style="margin: 15px;">Wunschliste von <?php include 'config.php'; echo $page_name; ?> 🎁</h1>
|
||||
<div class="content">
|
||||
<?php
|
||||
$jsonFile = 'wishes.json';
|
||||
|
||||
$wishes = [];
|
||||
if (file_exists($jsonFile)) {
|
||||
$jsonData = file_get_contents($jsonFile);
|
||||
$wishes = json_decode($jsonData, true);
|
||||
if (!$wishes) $wishes = [];
|
||||
}
|
||||
|
||||
foreach ($wishes as $row) {
|
||||
$id = $row["id"] ?? uniqid();
|
||||
$name = $row["name"] ?? '';
|
||||
$link = $row["link"] ?? '';
|
||||
$price = $row["price"] ?? '';
|
||||
|
||||
echo '<div class="accordion accordion-flush" id="accordionFlushExample">
|
||||
<div class="accordion-item">
|
||||
<h2 class="accordion-header">
|
||||
<button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#collapse-' . $id . '" aria-expanded="false" aria-controls="flush-collapseOne">
|
||||
' . htmlspecialchars($name) . '
|
||||
</button>
|
||||
</h2>
|
||||
<div id="collapse-' . $id . '" class="accordion-collapse collapse" data-bs-parent="#accordionFlushExample">
|
||||
<div class="accordion-body"><a href="' . htmlspecialchars($link) . '" target="_blank">Zum Produkt</a>, ' . htmlspecialchars($price) . '</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>';
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
[
|
||||
{
|
||||
"id": 1,
|
||||
"name": "Wunsch 1",
|
||||
"link": "https:\/\/jakob48.de",
|
||||
"price": "10 EUR"
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"name": "Wunsch 1",
|
||||
"link": "https:\/\/jakob48.de",
|
||||
"price": "12 EUR"
|
||||
}
|
||||
]
|
||||
Reference in New Issue
Block a user