-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfaction.php
More file actions
142 lines (110 loc) · 3.47 KB
/
Copy pathfaction.php
File metadata and controls
142 lines (110 loc) · 3.47 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
<?php
require_once 'includes/bootstrap.php';
require_login();
$pdo = db();
$char = get_character();
if (!$char) {
redirect('character-create.php');
}
/**
* Pagination
*/
$page = max(1, (int)($_GET['page'] ?? 1));
$limit = 25;
$offset = ($page - 1) * $limit;
/**
* Total members
*/
$stmtCount = $pdo->prepare("
SELECT COUNT(*)
FROM characters
WHERE faction_id = ? AND city_id = ?
");
$stmtCount->execute([$char['faction_id'], current_city_id()]);
$total = (int)$stmtCount->fetchColumn();
$totalPages = max(1, ceil($total / $limit));
/**
* Fetch members
*/
$stmtMembers = $pdo->prepare("
SELECT
c.id,
c.name,
c.level,
c.turf_id,
t.name AS turf_name
FROM characters c
LEFT JOIN turfs t ON t.id = c.turf_id
WHERE c.faction_id = ? AND c.city_id = ?
ORDER BY c.level DESC, c.xp DESC
LIMIT ? OFFSET ?
");
$stmtMembers->bindValue(1, (int)$char['faction_id'], PDO::PARAM_INT);
$stmtMembers->bindValue(2, current_city_id(), PDO::PARAM_INT);
$stmtMembers->bindValue(3, $limit, PDO::PARAM_INT);
$stmtMembers->bindValue(4, $offset, PDO::PARAM_INT);
$stmtMembers->execute();
$members = $stmtMembers->fetchAll();
require_once 'templates/header.php';
?>
<div class="max-w-6xl mx-auto p-6">
<!-- HEADER -->
<div class="panel p-5 rounded-xl mb-6">
<h1 class="text-2xl font-bold">
👥 <?= e($char['faction_name']) ?>
</h1>
<p class="text-zinc-400 text-sm">
<?= $total ?> members
</p>
</div>
<!-- MEMBER LIST -->
<div class="panel p-4 rounded-xl">
<?php if (empty($members)): ?>
<p class="text-zinc-400 text-sm">No members found.</p>
<?php endif; ?>
<div class="space-y-2">
<?php foreach ($members as $i => $member): ?>
<?php
$isYou = $member['id'] == $char['id'];
?>
<div class="flex justify-between items-center p-3 rounded
<?= $isYou ? 'bg-zinc-800 border border-orange-500' : 'bg-zinc-900' ?>">
<div>
<div class="font-semibold text-white">
<?= e($member['name']) ?>
</div>
<div class="text-xs text-zinc-500">
<?= $member['turf_name'] ? e($member['turf_name']) : 'No Turf' ?>
</div>
</div>
<div class="text-right">
<div class="text-orange-400 font-bold">
Lv <?= $member['level'] ?>
</div>
</div>
</div>
<?php endforeach; ?>
</div>
</div>
<!-- PAGINATION -->
<div class="flex justify-between mt-6 text-sm">
<div>
Page <?= $page ?> / <?= $totalPages ?>
</div>
<div class="flex gap-2">
<?php if ($page > 1): ?>
<a href="?page=<?= $page - 1 ?>"
class="px-3 py-1 bg-zinc-800 rounded hover:bg-zinc-700">
Prev
</a>
<?php endif; ?>
<?php if ($page < $totalPages): ?>
<a href="?page=<?= $page + 1 ?>"
class="px-3 py-1 bg-zinc-800 rounded hover:bg-zinc-700">
Next
</a>
<?php endif; ?>
</div>
</div>
</div>
<?php require_once 'templates/footer.php'; ?>