forked from imabutahersiddik/CodeStore
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcategory.php
More file actions
319 lines (295 loc) · 13.7 KB
/
category.php
File metadata and controls
319 lines (295 loc) · 13.7 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
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
<?php
session_start();
require_once 'config.php';
require_once 'functions.php';
$category = $_GET['category'] ?? '';
if (empty($category)) {
header('Location: index.php');
exit;
}
$sortBy = $_GET['sort'] ?? 'popular';
$platform = $_GET['platform'] ?? 'all';
// Build query conditions
$where = ["status = 'active' AND category = ?"];
$params = [$category];
if ($platform !== 'all') {
$where[] = "web_platform = ?";
$params[] = $platform;
}
$whereClause = implode(' AND ', $where);
// Sorting
$orderBy = match($sortBy) {
'downloads' => 'downloads_count DESC',
'rating' => 'total_rating DESC',
'newest' => 'submitted_at DESC',
'oldest' => 'submitted_at ASC',
default => 'views_count DESC' // popular
};
// Pagination
$page = max(1, $_GET['page'] ?? 1);
$perPage = 12;
$offset = ($page - 1) * $perPage;
// Get total count
$countStmt = $pdo->prepare("SELECT COUNT(*) FROM apps WHERE $whereClause");
$countStmt->execute($params);
$totalApps = $countStmt->fetchColumn();
$totalPages = ceil($totalApps / $perPage);
// Get apps
$query = "
SELECT a.*,
COUNT(DISTINCT ar.id) as review_count,
AVG(ar.rating) as avg_rating
FROM apps a
LEFT JOIN app_ratings ar ON a.id = ar.app_id
WHERE $whereClause
GROUP BY a.id
ORDER BY $orderBy
LIMIT ? OFFSET ?
";
$params[] = $perPage;
$params[] = $offset;
$stmt = $pdo->prepare($query);
$stmt->execute($params);
$apps = $stmt->fetchAll();
// Get available platforms for this category
$platformsStmt = $pdo->prepare("
SELECT DISTINCT web_platform
FROM apps
WHERE status = 'active'
AND category = ?
ORDER BY web_platform
");
$platformsStmt->execute([$category]);
$platforms = $platformsStmt->fetchAll(PDO::FETCH_COLUMN);
// Get category statistics
$statsStmt = $pdo->prepare("
SELECT
COUNT(DISTINCT id) as total_apps,
SUM(downloads_count) as total_downloads,
SUM(views_count) as total_views,
AVG(total_rating) as avg_rating
FROM apps
WHERE status = 'active'
AND category = ?
");
$statsStmt->execute([$category]);
$stats = $statsStmt->fetch();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><?php echo htmlspecialchars($category); ?> Apps - Web Apps Platform</title>
<meta name="description" content="Browse and download <?php echo htmlspecialchars($category); ?> web applications.">
<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">
<style>
.category-header {
background: linear-gradient(135deg, #6f42c1, #007bff);
color: white;
padding: 3rem 0;
margin-bottom: 2rem;
}
.stats-card {
background: rgba(255, 255, 255, 0.1);
border-radius: 10px;
padding: 1rem;
text-align: center;
}
.app-card {
transition: transform 0.2s;
}
.app-card:hover {
transform: translateY(-5px);
}
.rating-stars {
color: #ffc107;
}
</style>
</head>
<body>
<?php include 'header.php'; ?>
<!-- Category Header -->
<div class="category-header">
<div class="container">
<h1 class="display-4"><?php echo htmlspecialchars($category); ?> Apps</h1>
<div class="row mt-4">
<div class="col-md-3">
<div class="stats-card">
<h3><?php echo number_format($stats['total_apps']); ?></h3>
<p class="mb-0">Total Apps</p>
</div>
</div>
<div class="col-md-3">
<div class="stats-card">
<h3><?php echo number_format($stats['total_downloads']); ?></h3>
<p class="mb-0">Downloads</p>
</div>
</div>
<div class="col-md-3">
<div class="stats-card">
<h3><?php echo number_format($stats['total_views']); ?></h3>
<p class="mb-0">Views</p>
</div>
</div>
<div class="col-md-3">
<div class="stats-card">
<h3><?php echo number_format($stats['avg_rating'], 1); ?></h3>
<p class="mb-0">Average Rating</p>
</div>
</div>
</div>
</div>
</div>
<div class="container">
<!-- Filters -->
<div class="row mb-4">
<div class="col-md-8">
<div class="btn-group">
<button type="button" class="btn btn-outline-primary dropdown-toggle" data-bs-toggle="dropdown">
Platform: <?php echo $platform === 'all' ? 'All' : htmlspecialchars($platform); ?>
</button>
<ul class="dropdown-menu">
<li>
<a class="dropdown-item <?php echo $platform === 'all' ? 'active' : ''; ?>"
href="?category=<?php echo urlencode($category); ?>&platform=all&sort=<?php echo $sortBy; ?>">
All Platforms
</a>
</li>
<?php foreach ($platforms as $p): ?>
<li>
<a class="dropdown-item <?php echo $platform === $p ? 'active' : ''; ?>"
href="?category=<?php echo urlencode($category); ?>&platform=<?php echo urlencode($p); ?>&sort=<?php echo $sortBy; ?>">
<?php echo htmlspecialchars($p); ?>
</a>
</li>
<?php endforeach; ?>
</ul>
</div>
</div>
<div class="col-md-4 text-end">
<div class="btn-group">
<button type="button" class="btn btn-outline-primary dropdown-toggle" data-bs-toggle="dropdown">
Sort by: <?php echo ucfirst($sortBy); ?>
</button>
<ul class="dropdown-menu dropdown-menu-end">
<li>
<a class="dropdown-item <?php echo $sortBy === 'popular' ? 'active' : ''; ?>"
href="?category=<?php echo urlencode($category); ?>&platform=<?php echo $platform; ?>&sort=popular">
Most Popular
</a>
</li>
<li>
<a class="dropdown-item <?php echo $sortBy === 'downloads' ? 'active' : ''; ?>"
href="?category=<?php echo urlencode($category); ?>&platform=<?php echo $platform; ?>&sort=downloads">
Most Downloads
</a>
</li>
<li>
<a class="dropdown-item <?php echo $sortBy === 'rating' ? 'active' : ''; ?>"
href="?category=<?php echo urlencode($category); ?>&platform=<?php echo $platform; ?>&sort=rating">
Highest Rated
</a>
</li>
<li>
<a class="dropdown-item <?php echo $sortBy === 'newest' ? 'active' : ''; ?>"
href="?category=<?php echo urlencode($category); ?>&platform=<?php echo $platform; ?>&sort=newest">
Newest First
</a>
</li>
</ul>
</div>
</div>
</div>
<!-- Apps Grid -->
<?php if (empty($apps)): ?>
<div class="alert alert-info">
No apps found in this category with the selected filters.
</div>
<?php else: ?>
<div class="row">
<?php foreach ($apps as $app): ?>
<div class="col-md-4 mb-4">
<div class="card app-card h-100">
<div class="card-body">
<div class="d-flex align-items-center mb-3">
<img src="<?php echo htmlspecialchars($app['icon_path']); ?>"
alt="<?php echo htmlspecialchars($app['app_name']); ?>"
class="rounded me-3" style="width: 64px; height: 64px; object-fit: cover;">
<div>
<h5 class="card-title mb-0">
<a href="view_app.php?id=<?php echo $app['id']; ?>"
class="text-decoration-none text-dark">
<?php echo htmlspecialchars($app['app_name']); ?>
</a>
</h5>
<div class="text-muted small">
by <?php echo htmlspecialchars($app['developer_name']); ?>
</div>
</div>
</div>
<p class="card-text small text-muted">
<?php echo substr(htmlspecialchars($app['description']), 0, 100) . '...'; ?>
</p>
<div class="d-flex justify-content-between align-items-center">
<div class="rating-stars">
<?php for ($i = 1; $i <= 5; $i++): ?>
<i class="bi bi-star<?php echo $i <= $app['avg_rating'] ? '-fill' : ''; ?>"></i>
<?php endfor; ?>
<small class="text-muted ms-1">
(<?php echo number_format($app['review_count']); ?>)
</small>
</div>
<span class="badge bg-primary">
<?php echo htmlspecialchars($app['web_platform']); ?>
</span>
</div>
<div class="mt-3 text-muted small d-flex justify-content-between">
<span>
<i class="bi bi-download"></i>
<?php echo number_format($app['downloads_count']); ?>
</span>
<span>
<i class="bi bi-eye"></i>
<?php echo number_format($app['views_count']); ?>
</span>
<span>
<i class="bi bi-clock"></i>
<?php echo date('M d, Y', strtotime($app['submitted_at'])); ?>
</span>
</div>
</div>
</div>
</div>
<?php endforeach; ?>
</div>
<!-- Pagination -->
<?php if ($totalPages > 1): ?>
<nav aria-label="Category pages" class="mt-4">
<ul class="pagination justify-content-center">
<li class="page-item <?php echo $page <= 1 ? 'disabled' : ''; ?>">
<a class="page-link" href="?category=<?php echo urlencode($category); ?>&page=<?php echo $page - 1; ?>&platform=<?php echo $platform; ?>&sort=<?php echo $sortBy; ?>">Previous</a>
</li>
<?php for ($i = 1; $i <= $totalPages; $i++): ?>
<?php if ($i == 1 || $i == $totalPages || ($i >= $page - 2 && $i <= $page + 2)): ?>
<?php if ($i != 1 && $i != $page - 2): ?>
<li class="page-item disabled"><span class="page-link">...</span></li>
<?php endif; ?>
<li class="page-item <?php echo $page == $i ? 'active' : ''; ?>">
<a class="page-link" href="?category=<?php echo urlencode($category); ?>&page=<?php echo $i; ?>&platform=<?php echo $platform; ?>&sort=<?php echo $sortBy; ?>"><?php echo $i; ?></a>
</li>
<?php endif; ?>
<?php endfor; ?>
<li class="page-item <?php echo $page >= $totalPages ? 'disabled' : ''; ?>">
<a class="page-link" href="?category=<?php echo urlencode($category); ?>&page=<?php echo $page + 1; ?>&platform=<?php echo $platform; ?>&sort=<?php echo $sortBy; ?>">Next</a>
</li>
</ul>
</nav>
<?php endif; ?>
<?php endif; ?>
</div>
<?php include 'footer.php'; ?>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>