-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
280 lines (252 loc) · 14.5 KB
/
index.php
File metadata and controls
280 lines (252 loc) · 14.5 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
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
<?php
session_start();
require_once "db.php";
?>
<!DOCTYPE html>
<html lang="pl">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
<script src="https://kit.fontawesome.com/988d321f51.js" crossorigin="anonymous"></script>
<link rel="stylesheet" href="style/indexStyle.css">
<title>Handmade</title>
</head>
<body>
<!-- modal na dodawanie kategorii -->
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Dodaj nową kategorię!</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<form method="POST" enctype="multipart/form-data" action="addNewCategory.php" name="addCategoryForm">
<div class="modal-body">
<div class="mb-3">
<label for="name" class="form-label">Nazwa</label>
<input type="text" class="form-control" id="name" name="name">
</div>
<div class="mb-3">
<label for="description" class="form-label">Opis</label>
<input type="text" class="form-control" id="description" name="description">
</div>
<div class="mb-3 form-switch">
<input type="checkbox" class="form-check-input" id="addFileCheck" name="addFileCheck">
<label class="form-check-label" for="addFileCheck"> Nie dodawaj tytułowego zdjęcia do kategorii</label>
<p class="text-muted small">Dodane zostanie domyślne zdjęcie</p>
</div>
<div class="mb-3 fileDiv visually-hidden">
<label for="file" class="form-label">Załącznik</label>
<input type="file" class="form-control" id="file" name="file">
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Anuluj</button>
<button type="submit" class="btn btn-primary" name="save_data">Dodaj</button>
</div>
</form>
</div>
</div>
</div>
<!-- modal na edycje kategorii -->
<div class="modal fade" id="editmodal" tabindex="-1" role="dialog" aria-labelledby="editModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="editModalLabel">Edytowanie kategorii</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<form method="POST" enctype="multipart/form-data" action="update.php" name="editCategoryForm">
<input type="hidden" id="edit_id" name="id">
<div class="modal-body">
<div class="mb-3">
<label for="edit_name" class="form-label">Nazwa</label>
<input type="text" class="form-control" id="edit_name" name="name">
</div>
<div class="mb-3">
<label for="edit_description" class="form-label">Opis</label>
<input type="text" class="form-control" id="edit_description" name="description">
</div>
<div class="mb-3 form-checkbox">
<input type="checkbox" class="form-check-input" id="deleteCategoryImg" name="deleteCategoryImg">
<label class="form-check-label" for="deleteCategoryImg"> Usuń zdjęcie tytułowe kategorii</label>
<p class="text-muted small">Dodane zostanie domyślne zdjęcie</p>
</div>
<div class="mb-3 editDiv">
<label for="edit_file" class="form-label">Załącznik</label>
<input type="file" class="form-control" id="edit_file" name="file">
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Anuluj</button>
<button type="submit" class="btn btn-primary" name="save_data">Wprowadź zmiany</button>
</div>
</form>
</div>
</div>
</div>
<!-- Modal dodawania nowego produktu -->
<div class="modal fade" id="addProductModal" tabindex="-1" aria-labelledby="addProductModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="addProductModalLabel">Dodaj nowy produkt</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<form method="POST" enctype="multipart/form-data" action="addNewProduct.php">
<div class="modal-body">
<div class="mb-3">
<label for="productName" class="form-label">Nazwa produktu</label>
<input type="text" class="form-control" id="productName" name="name">
</div>
<div class="mb-3">
<label for="productDescription" class="form-label">Opis produktu</label>
<input type="text" class="form-control" id="productDescription" name="description">
</div>
<div class="mb-3">
<label for="tags" class="form-label">Tagi: </label>
<input type="text" class="form-control" id="tags" name="tags">
<p class="text-muted small">Wprowadź tagi z '#'</p>
</div>
<div class="mb-3">
<label for="category" class="form-label">Kategoria</label>
<select class="form-control" id="category" name="category">
<?php
$sqlQueryCategories = "SELECT * FROM handmade.categories";
$result = $conn->query($sqlQueryCategories);
if ($result->num_rows > 0) {
while ($category = $result->fetch_assoc()) {
echo '<option value="' . $category['id'] . '">' . htmlspecialchars($category['category_name']) . '</option>';
}
} else {
echo '<option disabled>Brak dostępnych kategorii</option>';
}
?>
</select>
</div>
<div class="mb-3">
<label for="productFile" class="form-label">Załącznik</label>
<input type="file" class="form-control" id="productFile" name="file">
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Anuluj</button>
<button type="submit" class="btn btn-primary" name="addNewProduct">Dodaj</button>
</div>
</form>
</div>
</div>
</div>
<header>
<div class="navbar navbar-dark bg-dark shadow-sm sticky-top">
<div class="container">
<a href="#" class="navbar-brand d-flex align-items-center">
<strong>Handmade</strong>
</a>
<div>
<a class="btn btn-secondary" href="logout.php">Wyloguj</a>
</div>
</div>
</div>
</header>
<main>
<section class="py-5 text-center container">
<div class="row py-lg-5">
<div class="col-lg-6 col-md-8 mx-auto">
<h1 class="fw-light">Utrwalaj to co masz w głowie</h1>
<p class="lead text-muted">Lepiej bez celu iść naprzód niż bez celu stać w miejscu, a z pewnością o niebo lepiej, niż bez celu się cofać.</p>
<p>
<a href="#" class="btn btn-primary my-2" data-bs-toggle="modal" data-bs-target="#exampleModal">Dodaj nową kategorie</a>
<a href="addNewProduct.php" class="btn btn-secondary my-2" data-bs-toggle="modal" data-bs-target="#addProductModal">Dodaj nowy produkt</a>
</p>
</div>
</div>
</section>
<div class="album py-5 bg-light">
<div class="container">
<div class="row row-cols-1 row-cols-sm-2 row-cols-md-3 g-3">
<?php
$sqlQueryCategories = "SELECT * FROM handmade.categories";
$result = $conn->query($sqlQueryCategories);
while ($row = $result->fetch_assoc()) {
$modalId = "deleteModal" . $row['id'];
$imagePath = "images/category/" . $row['category_name'] . "/" . $row['file'];
if (!file_exists($imagePath)) {
$svg = '
<svg class="bd-placeholder-img card-img-top" width="100%" height="200" xmlns="http://www.w3.org/2000/svg" role="img" aria-label="' . htmlspecialchars($row['category_name']) . '" preserveAspectRatio="xMidYMid slice" focusable="false">
<title>' . htmlspecialchars($row['category_name']) . '</title>
<rect width="100%" height="100%" fill="#55595c"/>
<text x="50%" y="50%" fill="#eceeef" dy=".3em" text-anchor="middle">' . $row['category_name'] . '</text>
</svg>';
} else {
$svg = '<img class="card-img-top img-fluid" src="' . $imagePath . '" alt="' . $row['category_name'] . '" style="height: 200px; object-fit: cover;">';
}
echo '
<div class="col">
<div class="card shadow-sm">
' . $svg . '
<div class="card-body d-flex flex-column">
<h5 class="card-title">' . $row['category_name'] . '</h5>
<p class="card-text flex-grow-1">' . $row['description'] . '</p>
<div class="d-flex justify-content-between align-items-center">
<div class="btn-group">
<a href="categories.php?id_category=' . $row['id'] . '" class="btn btn-sm btn-outline-secondary">Przejdź</a>
<button type="button" class="btn btn-sm btn-outline-secondary" data-bs-toggle="modal" data-bs-target="#editmodal" data-id="' . $row['id'] . '" data-name="' . htmlspecialchars($row['category_name']) . '" data-description="' . htmlspecialchars($row['description']) . '"><i class="fa-solid fa-pen-to-square"></i></button>
<button type="button" class="btn btn-sm btn-outline-secondary" data-bs-toggle="modal" data-bs-target="#' . $modalId . '"><i class="fa-solid fa-trash"></i></button>
</div>
<small class="text-body-secondary">Główne tagi: </small>
</div>
</div>
</div>
</div>
<div class="modal fade" id="' . $modalId . '" tabindex="-1" aria-labelledby="exampleModalLabel' . $row['id'] . '" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel' . $row['id'] . '">Usuwasz kategorię!</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
Czy na pewno chcesz usunąć kategorię ' . $row['category_name'] . ' i jej wszystkie elementy?
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Anuluj</button>
<button type="button" class="btn btn-danger"><a href="delete.php?deleteid=' . $row['id'] . '" class="text-light">Tak, usuń!</a></button>
</div>
</div>
</div>
</div>';
}
?>
</div>
</div>
</div>
</main>
<footer class="text-muted py-5">
<div class="container">
<p class="float-end mb-1">
<a class="link-secondary link-offset-2 link-offset-3-hover link-underline link-underline-opacity-0 link-underline-opacity-75-hover" href="#">Powrót do góry</a>
</p>
<p class="mb-1">Album example is © Bootstrap</p>
</div>
</footer>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
$(document).ready(function() {
$('.btn-outline-secondary[data-bs-target="#editmodal"]').on('click', function() {
var id = $(this).data('id');
var name = $(this).data('name');
var description = $(this).data('description');
console.log(id, name, description);
$('#edit_id').val(id);
$('#edit_name').val(name);
$('#edit_description').val(description);
});
});
</script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz" crossorigin="anonymous"></script>
<script src="https://kit.fontawesome.com/988d321f51.js" crossorigin="anonymous"></script>
<script src="script/script.js"></script>
</body>
</html>