-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsettings.php
325 lines (303 loc) · 15.3 KB
/
settings.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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
<?php
session_start();
require_once 'config/config.php';
if (!isLoggedIn() || !isAdmin()) {
header("Location: login.php");
exit;
}
$message = '';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (isset($_POST['category_action'])) {
$category_action = $_POST['category_action'];
if ($category_action === 'add_category') {
$cat_name = trim($_POST['cat_name'] ?? '');
if ($cat_name !== '') {
$stmt = $pdo->prepare("INSERT INTO categories (name) VALUES (?)");
$stmt->execute([$cat_name]);
$message = "Kategorie '$cat_name' wurde hinzugefügt.";
} else {
$message = "Bitte einen gültigen Kategorienamen angeben.";
}
} elseif ($category_action === 'delete_category') {
$cat_id = (int)$_POST['cat_id'];
try {
$stmt = $pdo->prepare("DELETE FROM categories WHERE id=?");
$stmt->execute([$cat_id]);
$message = "Kategorie wurde gelöscht.";
} catch (Exception $e) {
$message = "Fehler beim Löschen der Kategorie. Sie wird möglicherweise von Produkten verwendet.";
}
}
}
if (isset($_POST['action'])) {
$action = $_POST['action'];
if ($action === 'add') {
$name = trim($_POST['name']);
$price = (float)$_POST['price'];
$category_id = (int)$_POST['category_id'];
$barcode_val = trim($_POST['barcode']);
$tax_rate = (int)$_POST['tax_rate'];
$image_url = trim($_POST['image_url'] ?? '');
if ($name === '' || $price <= 0 || $category_id <= 0 || $barcode_val === '') {
$message = "Bitte korrekte Produktdaten angeben (Name, Preis, gültige Kategorie, Barcode).";
} else {
$stmt = $pdo->prepare("INSERT INTO products (name, price, category_id, image_url, barcode, tax_rate) VALUES (?,?,?,?,?,?)");
$stmt->execute([$name, $price, $category_id, $image_url, $barcode_val, $tax_rate]);
$message = "Produkt hinzugefügt.";
}
} elseif ($action === 'edit') {
$id = (int)$_POST['id'];
$name = trim($_POST['name']);
$price = (float)$_POST['price'];
$category_id = (int)$_POST['category_id'];
$barcode_val = trim($_POST['barcode']);
$tax_rate = (int)$_POST['tax_rate'];
$image_url = trim($_POST['image_url'] ?? '');
if ($name === '' || $price <= 0 || $category_id <= 0 || $barcode_val === '') {
$message = "Bitte korrekte Produktdaten angeben.";
} else {
$stmt = $pdo->prepare("UPDATE products SET name=?, price=?, category_id=?, image_url=?, barcode=?, tax_rate=? WHERE id=?");
$stmt->execute([$name, $price, $category_id, $image_url, $barcode_val, $tax_rate, $id]);
$message = "Produkt aktualisiert.";
}
} elseif ($action === 'delete') {
$id = (int)$_POST['id'];
$stmt = $pdo->prepare("DELETE FROM products WHERE id=?");
$stmt->execute([$id]);
$message = "Produkt gelöscht.";
}
}
if (isset($_POST['user_settings'])) {
$message = "Nutzerverwaltung aktualisiert (Beispiel).";
}
if (isset($_POST['tax_settings'])) {
$message = "Steuereinstellungen gespeichert (Beispiel).";
}
if (isset($_POST['receipt_settings'])) {
$_SESSION['receipt_config']['company_name'] = $_POST['company_name'];
$_SESSION['receipt_config']['company_address'] = $_POST['company_address'];
$_SESSION['receipt_config']['system_serial'] = $_POST['system_serial'];
$_SESSION['receipt_config']['signature_counter'] = $_POST['signature_counter'];
$_SESSION['receipt_config']['check_value'] = $_POST['check_value'];
$_SESSION['receipt_config']['previous_order_start'] = $_POST['previous_order_start'];
$message = "Boneinstellungen gespeichert.";
}
if (isset($_POST['translation_settings'])) {
$newLang = $_POST['language_select'] ?? 'de';
$_SESSION['lang'] = $newLang;
$message = "Sprache wurde geändert.";
}
}
$categories = $pdo->query("SELECT id, name FROM categories ORDER BY name")->fetchAll();
$products = $pdo->query("SELECT p.id, p.name, p.price, p.image_url, p.barcode, p.tax_rate, c.name as cat_name
FROM products p
JOIN categories c ON p.category_id=c.id
ORDER BY p.name")->fetchAll();
$tab = $_GET['tab'] ?? 'categories';
?>
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><?php echo t('settings'); ?> - <?php echo t('app_name'); ?></title>
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;500;700&display=swap" rel="stylesheet">
<link href="assets/css/settings.css" rel="stylesheet">
</head>
<body>
<header>
<h1><?php echo t('app_name'); ?> - <?php echo t('settings'); ?></h1>
<nav>
<a href="index.php"><?php echo t('app_name'); ?></a>
</nav>
</header>
<div class="container">
<?php if($message): ?>
<div class="message"><?php echo htmlspecialchars($message); ?></div>
<?php endif; ?>
<div class="tabs">
<a href="?tab=categories" class="<?php echo ($tab=='categories'?'active':''); ?>"><?php echo t('categories'); ?></a>
<a href="?tab=products" class="<?php echo ($tab=='products'?'active':''); ?>">Produkte</a>
<a href="?tab=users" class="<?php echo ($tab=='users'?'active':''); ?>">Nutzer</a>
<a href="?tab=tax" class="<?php echo ($tab=='tax'?'active':''); ?>">Steuern</a>
<a href="?tab=receipt" class="<?php echo ($tab=='receipt'?'active':''); ?>">Bon</a>
<a href="?tab=translations" class="<?php echo ($tab=='translations'?'active':''); ?>">Übersetzungen</a>
</div>
<?php if ($tab == 'categories'): ?>
<h2>Kategorien verwalten</h2>
<div class="form-section">
<h3>Neue Kategorie hinzufügen</h3>
<form method="post">
<input type="hidden" name="category_action" value="add_category">
<input type="text" name="cat_name" placeholder="Kategoriename" required>
<button type="submit">Hinzufügen</button>
</form>
</div>
<h3>Alle Kategorien</h3>
<table>
<thead>
<tr>
<th>ID</th><th>Name</th><th>Aktionen</th>
</tr>
</thead>
<tbody>
<?php foreach($categories as $c): ?>
<tr>
<td><?php echo $c['id']; ?></td>
<td><?php echo htmlspecialchars($c['name']); ?></td>
<td class="actions">
<form method="post" onsubmit="return confirm('Kategorie wirklich löschen?');">
<input type="hidden" name="category_action" value="delete_category">
<input type="hidden" name="cat_id" value="<?php echo $c['id']; ?>">
<button type="submit" class="delete">Löschen</button>
</form>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php elseif($tab=='products'): ?>
<h2>Produkte verwalten</h2>
<div class="form-section">
<h3>Neues Produkt hinzufügen</h3>
<form method="post">
<input type="hidden" name="action" value="add">
<input type="text" name="name" placeholder="Produktname" required>
<input type="number" step="0.01" name="price" placeholder="Preis (€)" required>
<select name="category_id" required>
<option value="">-- Kategorie wählen --</option>
<?php foreach($categories as $cat): ?>
<option value="<?php echo $cat['id']; ?>"><?php echo htmlspecialchars($cat['name']); ?></option>
<?php endforeach; ?>
</select>
<input type="text" name="barcode" placeholder="Barcode" required>
<select name="tax_rate">
<option value="19">19%</option>
<option value="7">7%</option>
</select>
<input type="text" name="image_url" placeholder="Bild-URL (optional)">
<button type="submit">Hinzufügen</button>
</form>
</div>
<h3>Alle Produkte</h3>
<table>
<thead>
<tr>
<th>ID</th><th>Name</th><th>Preis</th><th>Kategorie</th><th>Barcode</th><th>Steuer</th><th>Bild</th><th>Aktionen</th>
</tr>
</thead>
<tbody>
<?php foreach($products as $p): ?>
<tr>
<td><?php echo $p['id']; ?></td>
<td><?php echo htmlspecialchars($p['name']); ?></td>
<td><?php echo number_format($p['price'],2,',','.'); ?> €</td>
<td><?php echo htmlspecialchars($p['cat_name']); ?></td>
<td><?php echo htmlspecialchars($p['barcode']); ?></td>
<td><?php echo $p['tax_rate']; ?>%</td>
<td>
<?php if($p['image_url']): ?>
<img src="<?php echo htmlspecialchars($p['image_url']); ?>" alt="Bild">
<?php else: ?>
-
<?php endif; ?>
</td>
<td class="actions">
<form method="post" onsubmit="return confirm('Produkt wirklich löschen?');">
<input type="hidden" name="action" value="delete">
<input type="hidden" name="id" value="<?php echo $p['id']; ?>">
<button type="submit" class="delete">Löschen</button>
</form>
<button type="button" onclick="toggleEditForm(<?php echo $p['id']; ?>)">Bearbeiten</button>
<div id="edit-form-<?php echo $p['id']; ?>" style="display:none; margin-top:10px;">
<form method="post">
<input type="hidden" name="action" value="edit">
<input type="hidden" name="id" value="<?php echo $p['id']; ?>">
<input type="text" name="name" value="<?php echo htmlspecialchars($p['name']); ?>" required>
<input type="number" step="0.01" name="price" value="<?php echo $p['price']; ?>" required>
<select name="category_id" required>
<option value="">-- Kategorie wählen --</option>
<?php foreach($categories as $cat): ?>
<option value="<?php echo $cat['id']; ?>" <?php if($p['cat_name']==$cat['name']) echo 'selected';?>><?php echo htmlspecialchars($cat['name']); ?></option>
<?php endforeach; ?>
</select>
<input type="text" name="barcode" value="<?php echo htmlspecialchars($p['barcode']); ?>" required>
<select name="tax_rate">
<option value="19" <?php if($p['tax_rate']==19) echo 'selected'; ?>>19%</option>
<option value="7" <?php if($p['tax_rate']==7) echo 'selected'; ?>>7%</option>
</select>
<input type="text" name="image_url" value="<?php echo htmlspecialchars($p['image_url']); ?>">
<button type="submit">Speichern</button>
</form>
</div>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php elseif($tab=='users'): ?>
<h2>Nutzerverwaltung</h2>
<div class="form-section">
<h3>Nutzer Einstellungen (Beispiel)</h3>
<form method="post">
<input type="hidden" name="user_settings" value="1">
<input type="text" name="new_username" placeholder="Neuer Nutzername (Bsp.)">
<input type="password" name="new_password" placeholder="Neues Passwort (Bsp.)">
<select name="new_role">
<option value="cashier">Kassierer</option>
<option value="admin">Admin</option>
</select>
<button type="submit">Speichern</button>
</form>
</div>
<?php elseif($tab=='tax'): ?>
<h2>Steuereinstellungen</h2>
<div class="form-section">
<h3>Steuersatz ändern (Beispiel)</h3>
<form method="post">
<input type="hidden" name="tax_settings" value="1">
<input type="number" step="0.01" name="tax_rate" placeholder="Steuersatz in %" value="19.00">
<button type="submit">Speichern</button>
</form>
</div>
<?php elseif($tab=='receipt'): ?>
<h2>Boneinstellungen</h2>
<div class="form-section">
<form method="post">
<input type="hidden" name="receipt_settings" value="1">
<input type="text" name="company_name" placeholder="Unternehmensname" value="<?php echo htmlspecialchars($_SESSION['receipt_config']['company_name'] ?? ''); ?>" required>
<input type="text" name="company_address" placeholder="Unternehmensadresse" value="<?php echo htmlspecialchars($_SESSION['receipt_config']['company_address'] ?? ''); ?>" required>
<input type="text" name="system_serial" placeholder="Seriennummer Kassensystem" value="<?php echo htmlspecialchars($_SESSION['receipt_config']['system_serial'] ?? ''); ?>" required>
<input type="text" name="signature_counter" placeholder="Signaturzähler" value="<?php echo htmlspecialchars($_SESSION['receipt_config']['signature_counter'] ?? ''); ?>" required>
<input type="text" name="check_value" placeholder="Prüfwert" value="<?php echo htmlspecialchars($_SESSION['receipt_config']['check_value'] ?? ''); ?>" required>
<input type="text" name="previous_order_start" placeholder="Startzeitpunkt vorherige Bestellung (YYYY-MM-DD HH:MM:SS)" value="<?php echo htmlspecialchars($_SESSION['receipt_config']['previous_order_start'] ?? ''); ?>">
<button type="submit">Speichern</button>
</form>
</div>
<?php elseif($tab=='translations'): ?>
<h2>Übersetzungen / Spracheinstellungen</h2>
<div class="form-section">
<h3>Sprache auswählen</h3>
<form method="post">
<input type="hidden" name="translation_settings" value="1">
<select name="language_select">
<option value="de" <?php if($_SESSION['lang']=='de') echo 'selected'; ?>>Deutsch</option>
<option value="en" <?php if($_SESSION['lang']=='en') echo 'selected'; ?>>English</option>
</select>
<button type="submit">Speichern</button>
</form>
</div>
<?php endif; ?>
</div>
<script>
function toggleEditForm(id) {
var form = document.getElementById('edit-form-' + id);
if (form.style.display === 'none' || form.style.display === '') {
form.style.display = 'block';
} else {
form.style.display = 'none';
}
}
</script>
</body>
</html>