-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadmin.php
122 lines (96 loc) · 4.34 KB
/
admin.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<?php
session_start();
if (!isset($_SESSION['user'])) {
header('Location: login.php');
}
require('core/conn.php');
$produkte = require('core/produkte.php');
$einstellungen = require('core/einstellungen.php');
if (!isset($_SESSION['warenkorb'])) {
$_SESSION['warenkorb'] = [];
}
$conn = getDatenbank();
if (isset($_POST['stornieren'])) {
if (isset($_POST['bestellnummer'])) {
$sql = 'DELETE FROM Bestellungen WHERE id = ' . $_POST['bestellnummer'];
try {
$conn->exec($sql);
$success = ['Bestellung wurde storniert.'];
} catch (PDOException $e) {
$errors = [$e->getMessage()];
}
}
}
$stmt = $conn->prepare("SELECT * FROM Bestellungen");
$stmt->execute();
$result = $stmt->setFetchMode(PDO::FETCH_ASSOC);
$bestellungen = $stmt->fetchAll();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><?= $einstellungen['firma'] ?> Mitarbeiter</title>
<?php include('includes/head.inc.php') ?>
</head>
<body class="font-mono">
<?php include('includes/header.inc.php') ?>
<main class="flex flex-col gap-8 px-6 py-16 mx-auto max-w-7xl">
<!-- Fehlermeldungen -->
<?php if (isset($errors)) echo Komponente::alert(true, $errors); ?>
<!-- Erfolgsmeldung -->
<?php if (isset($success)) echo Komponente::alert(false, $success); ?>
<section>
<h1 class="text-4xl">Mitarbeiterbereich</h1>
<p>Du bist jetzt als Mitarbeiter angemeldet. Du kannst jetzt Bestellungen stornieren.</p>
</section>
<section class="w-full p-4 mx-auto bg-white rounded-md shadow-xl">
<div class="flex flex-col py-8 px-6 mt-4 border-4">
<?php if (empty($bestellungen)) : ?>
<p class="mb-4">Es gibt noch keine Bestellungen!</p>
<?= Komponente::link('Zum Shop', 'shop.php') ?>
<?php else : ?>
<table class="w-full table-auto">
<thead class="bg-gray-200">
<tr>
<th>BestellNR.</th>
<th>KundenNR.</th>
<th>Summe</th>
<th>Datum</th>
<th>Aktionen</th>
</tr>
</thead>
<tbody class="divide-y">
<?php $counter = 0 ?>
<?php foreach ($bestellungen as $bestellung) : ?>
<?php
$summe = 0;
$summe += $bestellung['akazienhonig'] * $produkte['akazie']['preis'];
$summe += $bestellung['heidehonig'] * $produkte['heide']['preis'];
$summe += $bestellung['kleehonig'] * $produkte['klee']['preis'];
$summe += $bestellung['tannenhonig'] * $produkte['tannen']['preis'];
?>
<tr class="py-2 <?= ($counter % 2 == 0) ? 'bg-white' : 'bg-gray-200' ?>">
<th class="py-2"><?= $bestellung['id'] ?></th>
<th class="py-2"><?= $bestellung['kunde'] ?></th>
<th class="py-2"><?= sprintf('CHF %.2f', $summe) ?></th>
<th class="py-2"><?= $bestellung['erstellt_am'] ?></th>
<th class="py-2">
<form action="" method="POST">
<input type="number" name="bestellnummer" value="<?= $bestellung['id'] ?>" class="hidden">
<?= Komponente::button('Stornieren', 'stornieren', 'red') ?>
</form>
</th>
</tr>
<?php $counter++; ?>
<?php endforeach; ?>
</tbody>
</table>
<?php endif; ?>
</div>
</section>
</main>
</body>
</html>