-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadmin.php
More file actions
183 lines (172 loc) · 7.1 KB
/
admin.php
File metadata and controls
183 lines (172 loc) · 7.1 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
<?php
session_start();
require_once 'includes/dbh.inc.php';
require_once 'includes/admin-functions.inc.php';
// Check if user is logged in and has appropriate role
if (!isset($_SESSION["userid"]) || !in_array($_SESSION["role"], ["admin", "editor"])) {
header("location: login.php");
exit();
}
// Fetch overview statistics
$stats = getDashboardStats($pdo);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Admin Dashboard - Blog CMS</title>
<link rel="stylesheet" href="css/admin-style.css">
<link rel="stylesheet" href="/style.css">
</head>
<body>
<div class="admin-container">
<?php include 'admin-header.php'; ?>
<main class="admin-main">
<section id="overview" class="dashboard-section">
<h2>Dashboard Overview</h2>
<div class="stats-grid">
<div class="stat-card">
<h3>Total Posts</h3>
<p><?php echo $stats['totalPosts']; ?></p>
</div>
<div class="stat-card">
<h3>Total Users</h3>
<p><?php echo $stats['totalUsers']; ?></p>
</div>
<div class="stat-card">
<h3>Total Comments</h3>
<p><?php echo $stats['totalComments']; ?></p>
</div>
<div class="stat-card">
<h3>Pending Comments</h3>
<p><?php echo $stats['pendingComments']; ?></p>
</div>
</div>
</section>
<section id="users" class="dashboard-section">
<div class="dashboard-section-header">
<h2>User Management</h2>
<div class="action-bar">
<button onclick="showUserModal()" class="btn btn-primary">Add New User</button>
</div>
</div>
<div class="table-responsive">
<table id="usersTable">
<thead>
<tr>
<th>Username</th>
<th>Email</th>
<th>Role</th>
<th>Created At</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<!-- Populated via AJAX -->
</tbody>
</table>
</div>
</section>
<section id="posts" class="dashboard-section">
<div class="dashboard-section-header">
<h2>Post Management</h2>
<div class="action-bar">
<button onclick="window.location.href='create-post.php'" class="btn btn-primary">Create New Post</button>
</div>
</div>
<div class="table-responsive">
<table id="postsTable">
<thead>
<tr>
<th>Title</th>
<th>Author</th>
<th>Status</th>
<th>Created</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<!-- Populated via AJAX -->
</tbody>
</table>
</div>
</section>
<section id="categories" class="dashboard-section">
<div class="dashboard-section-header">
<h2>Category Management</h2>
<div class="action-bar">
<button onclick="showCategoryModal()" class="btn btn-primary">Add New Category</button>
</div>
</div>
<div class="table-responsive">
<table id="categoriesTable">
<thead>
<tr>
<th>Name</th>
<th>Slug</th>
<th>Created At</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<!-- Populated via AJAX -->
</tbody>
</table>
</div>
</section>
</main>
</div>
<!-- User Modal -->
<div id="userModal" class="modal">
<div class="modal-content">
<span class="close">×</span>
<h2>User Details</h2>
<form id="userForm">
<input type="hidden" id="userId" name="userId">
<div class="form-group">
<label for="username">Username</label>
<input type="text" id="username" name="username" required>
</div>
<div class="form-group">
<label for="email">Email</label>
<input type="email" id="email" name="email" required>
</div>
<div class="form-group">
<label for="role">Role</label>
<select id="role" name="role">
<option value="user">User</option>
<option value="editor">Editor</option>
<option value="admin">Admin</option>
</select>
</div>
<button type="submit" class="btn btn-primary">Save User</button>
</form>
</div>
</div>
<!-- Category Modal -->
<div id="categoryModal" class="modal">
<div class="modal-content">
<span class="close">×</span>
<h2>Category Details</h2>
<form id="categoryForm">
<input type="hidden" id="categoryId" name="categoryId">
<div class="form-group">
<label for="categoryName">Name</label>
<input type="text" id="categoryName" name="name" required maxlength="50">
<small class="form-text">Maximum 50 characters allowed</small>
</div>
<div class="form-group">
<label for="categorySlug">Slug (optional)</label>
<input type="text" id="categorySlug" name="slug" pattern="[a-z0-9_\-]*">
<small>Leave blank to auto-generate from name. Only lowercase letters, numbers, hyphens, and underscores allowed.</small>
</div>
<button type="submit" class="btn btn-primary">Save Category</button>
</form>
</div>
</div>
<script src="js/user-management.js"></script>
<script src="js/post-management.js"></script>
<script src="js/category-management.js"></script>
</body>
</html>