forked from imabutahersiddik/CodeStore
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadmin_dashboard.php
More file actions
220 lines (209 loc) · 9.76 KB
/
admin_dashboard.php
File metadata and controls
220 lines (209 loc) · 9.76 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
<?php
session_start();
require_once 'config.php';
require_once 'admin_auth.php'; // This will handle authentication
// Fetch statistics
$stats = [
'total_apps' => $pdo->query("SELECT COUNT(*) FROM apps")->fetchColumn(),
'total_downloads' => $pdo->query("SELECT SUM(downloads_count) FROM apps")->fetchColumn(),
'total_views' => $pdo->query("SELECT SUM(views_count) FROM apps")->fetchColumn(),
'average_rating' => $pdo->query("SELECT AVG(total_rating) FROM apps WHERE ratings_count > 0")->fetchColumn(),
'pending_apps' => $pdo->query("SELECT COUNT(*) FROM apps WHERE status = 'pending'")->fetchColumn()
];
// Fetch most viewed apps
$mostViewedApps = $pdo->query("
SELECT app_name, views_count, downloads_count, total_rating
FROM apps
ORDER BY views_count DESC
LIMIT 5
")->fetchAll();
// Fetch latest submissions
$latestSubmissions = $pdo->query("
SELECT app_name, developer_name, status, submitted_at
FROM apps
ORDER BY submitted_at DESC
LIMIT 5
")->fetchAll();
// Handle password change
$passwordMessage = '';
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['new_password'])) {
$newPassword = $_POST['new_password'];
$confirmPassword = $_POST['confirm_password'];
if ($newPassword === $confirmPassword) {
$passwordHash = password_hash($newPassword, PASSWORD_DEFAULT);
$stmt = $pdo->prepare("UPDATE admin_users SET password_hash = ? WHERE id = ?");
$stmt->execute([$passwordHash, $_SESSION['admin_id']]);
$passwordMessage = 'Password updated successfully!';
} else {
$passwordMessage = 'Passwords do not match!';
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Admin Dashboard - Web App Platform</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.8.1/font/bootstrap-icons.css" rel="stylesheet">
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<div class="container-fluid">
<a class="navbar-brand" href="#">Admin Dashboard</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link" href="admin_apps.php">Manage Apps</a>
</li>
<li class="nav-item">
<a class="nav-link" href="admin_settings.php">Settings</a>
</li>
</ul>
<ul class="navbar-nav ms-auto">
<li class="nav-item">
<a class="nav-link" href="admin_logout.php">Logout</a>
</li>
</ul>
</div>
</div>
</nav>
<div class="container-fluid py-4">
<div class="row">
<!-- Statistics Cards -->
<div class="col-md-4 mb-4">
<div class="card bg-primary text-white h-100">
<div class="card-body">
<h5 class="card-title">Total Apps</h5>
<h2><?php echo number_format($stats['total_apps']); ?></h2>
</div>
</div>
</div>
<div class="col-md-4 mb-4">
<div class="card bg-success text-white h-100">
<div class="card-body">
<h5 class="card-title">Total Downloads</h5>
<h2><?php echo number_format($stats['total_downloads']); ?></h2>
</div>
</div>
</div>
<div class="col-md-4 mb-4">
<div class="card bg-info text-white h-100">
<div class="card-body">
<h5 class="card-title">Total Views</h5>
<h2><?php echo number_format($stats['total_views']); ?></h2>
</div>
</div>
</div>
</div>
<div class="row">
<!-- Most Viewed Apps -->
<div class="col-md-6 mb-4">
<div class="card">
<div class="card-header">
<h5 class="card-title mb-0">Most Viewed Apps</h5>
</div>
<div class="card-body">
<div class="table-responsive">
<table class="table">
<thead>
<tr>
<th>App Name</th>
<th>Views</th>
<th>Downloads</th>
<th>Rating</th>
</tr>
</thead>
<tbody>
<?php foreach ($mostViewedApps as $app): ?>
<tr>
<td><?php echo htmlspecialchars($app['app_name']); ?></td>
<td><?php echo number_format($app['views_count']); ?></td>
<td><?php echo number_format($app['downloads_count']); ?></td>
<td><?php echo number_format($app['total_rating'], 1); ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div>
</div>
</div>
<!-- Latest Submissions -->
<div class="col-md-6 mb-4">
<div class="card">
<div class="card-header">
<h5 class="card-title mb-0">Latest Submissions</h5>
</div>
<div class="card-body">
<div class="table-responsive">
<table class="table">
<thead>
<tr>
<th>App Name</th>
<th>Developer</th>
<th>Status</th>
<th>Submitted</th>
</tr>
</thead>
<tbody>
<?php foreach ($latestSubmissions as $submission): ?>
<tr>
<td><?php echo htmlspecialchars($submission['app_name']); ?></td>
<td><?php echo htmlspecialchars($submission['developer_name']); ?></td>
<td>
<span class="badge bg-<?php
echo match($submission['status']) {
'active' => 'success',
'pending' => 'warning',
'rejected' => 'danger',
default => 'secondary'
};
?>">
<?php echo ucfirst($submission['status']); ?>
</span>
</td>
<td><?php echo date('Y-m-d H:i', strtotime($submission['submitted_at'])); ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
<!-- Change Password Section -->
<div class="row">
<div class="col-md-6 mb-4">
<div class="card">
<div class="card-header">
<h5 class="card-title mb-0">Change Admin Password</h5>
</div>
<div class="card-body">
<?php if ($passwordMessage): ?>
<div class="alert alert-info"><?php echo htmlspecialchars($passwordMessage); ?></div>
<?php endif; ?>
<form method="POST">
<div class="mb-3">
<label for="new_password" class="form-label">New Password</label>
<input type="password" class="form-control" id="new_password" name="new_password" required>
</div>
<div class="mb-3">
<label for="confirm_password" class="form-label">Confirm Password</label>
<input type="password" class="form-control" id="confirm_password" name="confirm_password" required>
</div>
<button type="submit" class="btn btn-primary">Change Password</button>
</form>
</div>
</div>
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>