-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadmin.php
More file actions
252 lines (224 loc) · 10.5 KB
/
Copy pathadmin.php
File metadata and controls
252 lines (224 loc) · 10.5 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
<?php
require __DIR__ . '/config.php';
require_login('index.php');
try {
refresh_identity_context();
} catch (Exception $e) {
error_log('[earthpol-refresh] ' . $e->getMessage());
set_flash('error', 'Could not refresh your EarthPol roles right now.');
app_redirect('index.php');
}
require_admin('index.php');
$csrf = ensure_csrf_token();
$flashMessages = pull_flash();
$user = current_user_context();
$nationCatalog = fetch_entity_catalog('nation');
$townCatalog = fetch_entity_catalog('town');
$nationEntities = $nationCatalog['entities'];
$townEntities = $townCatalog['entities'];
$nationFlagsLive = count(array_filter($nationEntities, function ($entity) {
return !empty($entity['hasFlag']);
}));
$townFlagsLive = count(array_filter($townEntities, function ($entity) {
return !empty($entity['hasFlag']);
}));
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>EarthPol Admin Dashboard</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="assets/app.css">
</head>
<body>
<div class="backdrop backdrop--one"></div>
<div class="backdrop backdrop--two"></div>
<main class="shell">
<header class="topbar">
<div>
<p class="eyebrow">EarthPol Asset Control</p>
<h1>Admin dashboard</h1>
</div>
<nav class="nav">
<a class="btn btn--ghost" href="index.php">Main dashboard</a>
<a class="btn btn--ghost" href="logout.php">Logout</a>
</nav>
</header>
<?php foreach ($flashMessages as $flash): ?>
<div class="alert alert--<?php echo e($flash['type'] === 'success' ? 'success' : ($flash['type'] === 'neutral' ? 'neutral' : 'error')); ?>">
<?php echo e($flash['message'] ?? ''); ?>
</div>
<?php endforeach; ?>
<section class="panel identity-panel">
<div>
<p class="eyebrow">Approved operator</p>
<h2><?php echo e($user['playerName'] ?: $user['discordUsername'] ?: 'Unknown user'); ?></h2>
<p class="meta-line">UUID: <?php echo e($user['uuid'] ?: 'Unknown'); ?></p>
</div>
<div class="badge-row">
<span class="badge badge--warning">Admin approved</span>
<span class="badge <?php echo !empty($user['linked']) ? 'badge--success' : 'badge--muted'; ?>">
<?php echo !empty($user['linked']) ? 'EarthPol linked' : 'Link missing'; ?>
</span>
<?php if (!empty($user['nation'])): ?>
<span class="badge badge--muted"><?php echo e($user['nation']); ?></span>
<?php endif; ?>
<?php if (!empty($user['town'])): ?>
<span class="badge badge--muted"><?php echo e($user['town']); ?></span>
<?php endif; ?>
</div>
</section>
<section class="section">
<div class="section-heading">
<div>
<p class="eyebrow">Overview</p>
<h2>Coverage</h2>
</div>
</div>
<div class="card-grid card-grid--four">
<article class="panel metric-card">
<p class="card-label">Nations in catalog</p>
<h3><?php echo e((string) count($nationEntities)); ?></h3>
</article>
<article class="panel metric-card">
<p class="card-label">Nation flags live</p>
<h3><?php echo e((string) $nationFlagsLive); ?></h3>
</article>
<article class="panel metric-card">
<p class="card-label">Towns in catalog</p>
<h3><?php echo e((string) count($townEntities)); ?></h3>
</article>
<article class="panel metric-card">
<p class="card-label">Town flags live</p>
<h3><?php echo e((string) $townFlagsLive); ?></h3>
</article>
</div>
</section>
<?php if ($nationCatalog['error']): ?>
<div class="alert alert--error">Nation catalog fallback active: <?php echo e($nationCatalog['error']); ?></div>
<?php endif; ?>
<?php if ($townCatalog['error']): ?>
<div class="alert alert--error">Town catalog fallback active: <?php echo e($townCatalog['error']); ?></div>
<?php endif; ?>
<section class="section">
<div class="section-heading">
<div>
<p class="eyebrow">Nation management</p>
<h2>All nation flags</h2>
</div>
<div class="search-box">
<label for="nation-search">Search nations</label>
<input id="nation-search" class="search-input" type="search" placeholder="Find a nation or UUID" data-search-target="nation-list">
</div>
</div>
<div class="entity-list" id="nation-list">
<?php foreach ($nationEntities as $entity): ?>
<article class="panel entity-row" data-search="<?php echo e(strtolower($entity['name'] . ' ' . ($entity['uuid'] ?? ''))); ?>">
<div class="entity-row__main">
<p class="card-label">Nation</p>
<h3><?php echo e($entity['name']); ?></h3>
<p class="meta-line">UUID: <?php echo e($entity['uuid'] ?: 'Unknown'); ?></p>
<p class="meta-line">Last update: <?php echo e(format_timestamp($entity['updatedAt'])); ?></p>
</div>
<div class="entity-row__preview">
<?php if (!empty($entity['hasFlag'])): ?>
<img src="<?php echo e($entity['publicUrl']); ?>" alt="<?php echo e($entity['name']); ?> flag preview">
<?php else: ?>
<div class="flag-preview__empty">No upload</div>
<?php endif; ?>
</div>
<div class="entity-row__actions">
<form action="upload.php" method="post" enctype="multipart/form-data" class="stack-form">
<input type="hidden" name="csrf" value="<?php echo e($csrf); ?>">
<input type="hidden" name="entity_type" value="nation">
<input type="hidden" name="entity_name" value="<?php echo e($entity['name']); ?>">
<input type="hidden" name="redirect_to" value="admin.php">
<label for="nation-<?php echo e($entity['filename']); ?>">Replace image</label>
<input id="nation-<?php echo e($entity['filename']); ?>" type="file" name="flag" accept="image/png" required>
<button class="btn btn--primary" type="submit"><?php echo !empty($entity['hasFlag']) ? 'Replace flag' : 'Upload flag'; ?></button>
</form>
<?php if (!empty($entity['hasFlag'])): ?>
<form action="delete_flag.php" method="post" class="stack-form stack-form--compact">
<input type="hidden" name="csrf" value="<?php echo e($csrf); ?>">
<input type="hidden" name="entity_type" value="nation">
<input type="hidden" name="entity_name" value="<?php echo e($entity['name']); ?>">
<input type="hidden" name="redirect_to" value="admin.php">
<button class="btn btn--danger" type="submit">Remove flag</button>
</form>
<?php endif; ?>
</div>
</article>
<?php endforeach; ?>
</div>
</section>
<section class="section">
<div class="section-heading">
<div>
<p class="eyebrow">Town management</p>
<h2>All town flags</h2>
</div>
<div class="search-box">
<label for="town-search">Search towns</label>
<input id="town-search" class="search-input" type="search" placeholder="Find a town or UUID" data-search-target="town-list">
</div>
</div>
<div class="entity-list" id="town-list">
<?php foreach ($townEntities as $entity): ?>
<article class="panel entity-row" data-search="<?php echo e(strtolower($entity['name'] . ' ' . ($entity['uuid'] ?? ''))); ?>">
<div class="entity-row__main">
<p class="card-label">Town</p>
<h3><?php echo e($entity['name']); ?></h3>
<p class="meta-line">UUID: <?php echo e($entity['uuid'] ?: 'Unknown'); ?></p>
<p class="meta-line">Last update: <?php echo e(format_timestamp($entity['updatedAt'])); ?></p>
</div>
<div class="entity-row__preview">
<?php if (!empty($entity['hasFlag'])): ?>
<img src="<?php echo e($entity['publicUrl']); ?>" alt="<?php echo e($entity['name']); ?> flag preview">
<?php else: ?>
<div class="flag-preview__empty">No upload</div>
<?php endif; ?>
</div>
<div class="entity-row__actions">
<form action="upload.php" method="post" enctype="multipart/form-data" class="stack-form">
<input type="hidden" name="csrf" value="<?php echo e($csrf); ?>">
<input type="hidden" name="entity_type" value="town">
<input type="hidden" name="entity_name" value="<?php echo e($entity['name']); ?>">
<input type="hidden" name="redirect_to" value="admin.php">
<label for="town-<?php echo e($entity['filename']); ?>">Replace image</label>
<input id="town-<?php echo e($entity['filename']); ?>" type="file" name="flag" accept="image/png" required>
<button class="btn btn--primary" type="submit"><?php echo !empty($entity['hasFlag']) ? 'Replace flag' : 'Upload flag'; ?></button>
</form>
<?php if (!empty($entity['hasFlag'])): ?>
<form action="delete_flag.php" method="post" class="stack-form stack-form--compact">
<input type="hidden" name="csrf" value="<?php echo e($csrf); ?>">
<input type="hidden" name="entity_type" value="town">
<input type="hidden" name="entity_name" value="<?php echo e($entity['name']); ?>">
<input type="hidden" name="redirect_to" value="admin.php">
<button class="btn btn--danger" type="submit">Remove flag</button>
</form>
<?php endif; ?>
</div>
</article>
<?php endforeach; ?>
</div>
</section>
</main>
<script>
document.querySelectorAll('.search-input').forEach(function (input) {
input.addEventListener('input', function () {
var targetId = input.getAttribute('data-search-target');
var list = document.getElementById(targetId);
if (!list) {
return;
}
var query = input.value.trim().toLowerCase();
list.querySelectorAll('.entity-row').forEach(function (row) {
var haystack = row.getAttribute('data-search') || '';
row.style.display = haystack.indexOf(query) !== -1 ? '' : 'none';
});
});
});
</script>
</body>
</html>