forked from jrie/sqstorage
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcategories.php
More file actions
118 lines (102 loc) · 8.52 KB
/
categories.php
File metadata and controls
118 lines (102 loc) · 8.52 KB
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
<?php require('login.php'); ?>
<!DOCTYPE html>
<html>
<?php include_once('head.php'); ?>
<body>
<?php include_once('nav.php'); ?>
<div class="content">
<?php
if ($_SERVER['REQUEST_METHOD'] == 'GET') {
if (isset($_GET['setCategoryId']) && !empty($_GET['setCategoryId']) && isset($_GET['to']) && !empty($_GET['to'])) {
DB::update('subCategories', array('headcategory' => intVal($_GET['to'])), 'id=%d', intVal($_GET['setCategoryId']));
header("location: categories.php");
die();
} else if (isset($_GET['resetSubcategoryId']) && !empty($_GET['resetSubcategoryId'])) {
DB::update('subCategories', array('headcategory' => NULL), 'id=%d', intVal($_GET['resetSubcategoryId']));
header("location: categories.php");
die();
} else if (isset($_GET['to']) && !empty($_GET['to']) && (isset($_GET['headCategory']) || isset($_GET['subCategory']))) {
if (isset($_GET['headCategory']) && !empty($_GET['headCategory'])) {
DB::update('headCategories', array('name' => $_GET['to']), 'id=%d', intVal($_GET['headCategory']));
if (DB::affectedRows() === 1) echo '<div class="alert alert-info" role="alert"><p>' . gettext('Kategorie umbenannt.') . '</p></div>';
} else {
DB::update('subCategories', array('name' => $_GET['to']), 'id=%d', intVal($_GET['subCategory']));
if (DB::affectedRows() === 1) echo '<div class="alert alert-info" role="alert"><p>' . gettext('Unterkategorie umbenannt.') . '</p></div>';
}
} else if (isset($_GET['removeCategory']) && !empty($_GET['removeCategory'])) {
DB::delete('headCategories', "id=%d", intVal($_GET['removeCategory']));
if (DB::affectedRows() === 1) echo '<div class="alert alert-info" role="alert"><p>' . gettext('Kategorie entfernt.') . '</p></div>';
} else if (isset($_GET['removeSubcategory']) && !empty($_GET['removeSubcategory'])) {
DB::delete('subCategories', "id=%d", intVal($_GET['removeSubcategory']));
if (DB::affectedRows() === 1) echo '<div class="alert alert-info" role="alert"><p>' . gettext('Unterkategorie entfernt.') . '</p></div>';
}
$headCategories = DB::query('SELECT id, name, amount FROM headCategories ORDER BY name ASC');
$subCategories = DB::query('SELECT id, name, amount, headcategory FROM subCategories ORDER BY name ASC');
echo '<hr/><ul class="categories list-group"><li class="alert alert-info"><span class="list-span">' . gettext('Kategorien') . '</span><span class="list-span">' . gettext('Anzahl') . '</span><span class="list-span">' . gettext('Aktionen') . '</span></li>';
foreach ($headCategories as $category) {
printf('<li class="list-group-item"><a name="removeCategory" data-name="%s" href="categories.php?removeCategory=%d" class="removalButton fas fa-times-circle btn"></a><a class="list-span" data-name="%s" href="inventory.php?category=%d">%s</a><span class="list-span">%d %s</span><a class="fas fa-edit editCategory" href="#" name="editCategory" data-name="%s" data-id="%d"></a></li>', $category['name'], $category['id'], $category['name'], $category['id'], $category['name'], $category['amount'], $category['amount'] == 1 ? gettext('Gegenstand') : gettext('Gegenstände'), $category['name'], $category['id']);
}
echo '</ul><hr/>';
echo '<ul class="categories list-group"><li class="alert alert-info"><span class="list-span">' . gettext('Unterkategorien') . '</span><span class="list-span">' . gettext('Anzahl') . '</span><span class="list-span">' . gettext('Aktionen') . '</span><span class="list-span">' . gettext('Oberkategorie') . '</span></li>';
foreach ($subCategories as $category) {
printf('<li class="list-group-item"><a name="removeSubcategory" data-name="%s" href="categories.php?removeSubcategory=%d" class="removalButton fas fa-times-circle btn"></a><a class="list-span" data-name="%s" href="inventory.php?subcategory=%d">%s</a><span class="list-span">%d %s</span><a class="fas fa-edit editCategory" href="#" name="editSubcategory" data-name="%s" data-id="%d"></a>', $category['name'], $category['id'], $category['name'], $category['id'], $category['name'], $category['amount'], $category['amount'] == 1 ? gettext('Gegenstand') : gettext('Gegenstände'), $category['name'], $category['id']);
?>
<div class="dropdown list-span">
<select class="btn btn-secondary dropdown-toggle categoryDropdowns" type="button" data-originid="<?php echo $category['id'] ?>" tabindex="-1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" autocomplete="off">
<?php
if ($category['headcategory'] != 0) echo '<option value="-1">' . gettext('Keine') . '</option>';
else echo '<option value="-1" selected="selected">' . gettext('Keine') . '</option>';
foreach ($headCategories as $headCategory) {
if ($headCategory['id'] == $category['headcategory']) {
printf('<option value="%d" selected="selected">%s</option>', $headCategory['id'], $headCategory['name']);
} else {
printf('<option value="%d">%s</option>', $headCategory['id'], $headCategory['name']);
}
}
?>
</select>
</div>
<?php
echo '</li>';
}
echo '</ul>';
}
?>
</div>
<?php include_once('footer.php'); ?>
<script type="text/javascript">
let removalButtons = document.querySelectorAll('.removalButton')
for (let button of removalButtons) {
button.addEventListener('click', function (evt) {
let targetType = evt.target.name === 'removeCategory' ? '<?php echo gettext('Kategorie wirklich entfernen?') ?>' : '<?php echo gettext('Unterkategorie wirklich entfernen?') ?>'
if (!window.confirm(targetType + ' "' + evt.target.dataset['name'] +'"')) {
evt.preventDefault()
}
})
}
let editCategoryButtons = document.querySelectorAll('.editCategory')
for (let button of editCategoryButtons) {
button.addEventListener('click', function (evt) {
let targetType = evt.target.name === 'editCategory' ? '<?php echo gettext('Kategorie umbenennen?') ?>' : '<?php echo gettext('Unterkategorie umbenennen?') ?>'
let newName = window.prompt(targetType + ' "' + evt.target.dataset['name'] + '"', '')
if (newName !== null && newName.length !== 0) {
if (evt.target.name === 'editCategory') window.location.href = 'categories.php?headCategory=' + evt.target.dataset['id'] + '&to=' + encodeURIComponent(newName)
else window.location.href = 'categories.php?subCategory=' + evt.target.dataset['id'] + '&to=' + encodeURIComponent(newName)
}
return false
})
}
let categoryDropdowns = document.querySelectorAll('.categoryDropdowns')
for (let dropDown of categoryDropdowns) {
dropDown.addEventListener('change', function (evt) {
let subcategoryId = evt.target.dataset['originid']
if (evt.target.value === -1) {
window.location.href = 'categories.php?resetSubcategoryId=' + subcategoryId
return
}
window.location.href = 'categories.php?setCategoryId=' + subcategoryId + '&to=' + encodeURIComponent(evt.target.value)
})
}
</script>
</body>
</html>