-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadmin.php
More file actions
73 lines (63 loc) · 2.04 KB
/
Copy pathadmin.php
File metadata and controls
73 lines (63 loc) · 2.04 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
<?php
require_once '../src/db.php';
require_once '../src/ImageRepository.php';
session_start();
// Check if the user is logged in as admin
if (!isset($_SESSION['user_id']) || $_SESSION['user_role'] !== 'admin') {
header('Location: login.php');
exit();
}
$imageRepo = new ImageRepository();
// Handle image deletion
if (isset($_POST['delete_image'])) {
$imageId = $_POST['image_id'];
$imageRepo->deleteImage($imageId);
}
// Fetch all images from the database
$images = $imageRepo->getAllImages();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Admin - FramedSoul</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<?php include '../templates/header.php'; ?>
<?php include '../templates/menu.php'; ?>
<main>
<h1>Admin Panel</h1>
<h2>Manage Images</h2>
<h3>Add New Image</h3>
<form action="add_image.php" method="POST" enctype="multipart/form-data">
<input type="file" name="image" required>
<button type="submit">Upload Image</button>
</form>
<h3>Existing Images</h3>
<table>
<thead>
<tr>
<th>Image</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php foreach ($images as $image): ?>
<tr>
<td><img src="uploads/<?php echo htmlspecialchars($image['path']); ?>" alt="Image" width="100"></td>
<td>
<form action="" method="POST">
<input type="hidden" name="image_id" value="<?php echo $image['id']; ?>">
<button type="submit" name="delete_image">Delete</button>
</form>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</main>
<?php include '../templates/footer.php'; ?>
</body>
</html>