-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathadmin.html
More file actions
570 lines (536 loc) · 34.2 KB
/
Copy pathadmin.html
File metadata and controls
570 lines (536 loc) · 34.2 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
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
<!DOCTYPE html>
<html lang="am">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>የአስተዳዳሪ ፓነል – አወሊያ ወጣቶች</title>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: 'Inter', sans-serif; background: #f1f5f9; color: #0f172a; padding: 2rem; }
.container { max-width: 1200px; margin: 0 auto; }
.login-box { max-width: 400px; margin: 100px auto; background: white; padding: 2rem; border-radius: 1.5rem; box-shadow: 0 10px 25px -5px rgba(0,0,0,0.1); text-align: center; }
.login-box input { width: 100%; padding: 0.75rem; margin: 1rem 0; border: 1px solid #e2e8f0; border-radius: 2rem; }
.login-box button { background: #2dd4bf; color: white; border: none; padding: 0.75rem 1.5rem; border-radius: 2rem; cursor: pointer; }
.admin-panel { background: white; border-radius: 1.5rem; padding: 1.5rem; margin-top: 1.5rem; box-shadow: 0 4px 6px -1px rgba(0,0,0,0.1); }
.table-wrapper { overflow-x: auto; margin-top: 1rem; }
table { width: 100%; border-collapse: collapse; min-width: 850px; }
th, td { text-align: left; padding: 0.75rem; border-bottom: 1px solid #e2e8f0; vertical-align: middle; }
th { background: #f8fafc; }
.search-box { display: flex; gap: 0.5rem; margin-bottom: 1rem; }
.search-box input { flex: 1; padding: 0.5rem; border: 1px solid #e2e8f0; border-radius: 2rem; }
.favorite-star { cursor: pointer; font-size: 1.2rem; color: #fbbf24; background: none; border: none; }
.block-btn { background: #ef4444; color: white; border: none; padding: 0.2rem 0.6rem; border-radius: 2rem; cursor: pointer; font-size: 0.7rem; }
.unblock-btn { background: #10b981; }
.delete-btn { background: #dc2626; color: white; border: none; padding: 0.2rem 0.6rem; border-radius: 2rem; cursor: pointer; font-size: 0.7rem; margin-left: 0.3rem; }
.user-checkbox { width: 20px; height: 20px; cursor: pointer; }
.action-buttons { margin: 1rem 0; display: flex; gap: 1rem; flex-wrap: wrap; }
.send-to-selected { background: #3b82f6; }
.activity-log { max-height: 400px; overflow-y: auto; }
.send-notif { background: #f8fafc; padding: 1rem; border-radius: 1rem; margin-top: 1.5rem; }
textarea { width: 100%; padding: 0.75rem; border: 1px solid #e2e8f0; border-radius: 1rem; margin: 0.5rem 0; font-family: inherit; }
button { background: #2dd4bf; color: white; border: none; padding: 0.5rem 1rem; border-radius: 2rem; cursor: pointer; }
.logout-btn { background: #ef4444; float: right; }
.status { display: inline-block; padding: 0.25rem 0.75rem; border-radius: 2rem; font-size: 0.75rem; }
.status-online { background: #10b981; color: white; }
.status-offline { background: #64748b; color: white; }
.favorite-row { background-color: #fef3c7; }
.match-card { background: #f8fafc; padding: 1rem; border-radius: 1rem; margin-bottom: 1rem; border-left: 4px solid #2dd4bf; }
.match-header { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; margin-bottom: 0.5rem; }
.match-title { font-weight: bold; font-size: 1.1rem; color: #2dd4bf; }
.match-info { font-size: 0.85rem; color: #64748b; margin-bottom: 0.5rem; }
.comments-section { margin-top: 1rem; padding-top: 0.5rem; border-top: 1px dashed #e2e8f0; }
.comment-item { background: #f8fafc; padding: 0.5rem; border-radius: 0.5rem; margin-bottom: 0.5rem; display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; }
.comment-text { flex: 1; margin-right: 1rem; }
.comment-meta { font-size: 0.7rem; color: #64748b; }
.comment-actions button { margin-left: 0.3rem; font-size: 0.7rem; padding: 0.2rem 0.5rem; }
.add-comment-form { display: flex; gap: 0.5rem; margin-top: 0.5rem; }
.add-comment-form input { flex: 1; padding: 0.3rem; border: 1px solid #e2e8f0; border-radius: 2rem; font-size: 0.8rem; }
.add-comment-form button { padding: 0.2rem 0.6rem; font-size: 0.7rem; }
.add-admin-form, .add-user-form { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-bottom: 1rem; background: #f8fafc; padding: 0.8rem; border-radius: 1rem; align-items: center; }
.add-admin-form input, .add-user-form input { flex: 1; padding: 0.5rem; border: 1px solid #e2e8f0; border-radius: 2rem; }
.add-admin-form button, .add-user-form button { background: #10b981; padding: 0.4rem 1rem; }
.admin-users-section { margin-top: 1rem; }
.admin-user-card { background: #f8fafc; padding: 0.5rem; border-radius: 0.5rem; margin-bottom: 0.5rem; display: flex; justify-content: space-between; align-items: center; }
hr { margin: 1rem 0; }
</style>
</head>
<body>
<div class="container" id="app">
<div id="step1" class="login-box">
<h1>🔐 ደረጃ 1: ዓለም አቀፍ የአስተዳዳሪ ይለፍ ቃል</h1>
<input type="password" id="globalPassword" placeholder="ዓለም አቀፍ ይለፍ ቃል ያስገቡ">
<button onclick="checkGlobalPassword()">ቀጥል</button>
</div>
<div id="step2" style="display: none;" class="login-box">
<h1>👤 ደረጃ 2: የአስተዳዳሪ መግቢያ</h1>
<input type="text" id="adminUsername" placeholder="ሙሉ ስም">
<input type="password" id="adminUserPass" placeholder="የይለፍ ቃል">
<button onclick="verifyAdminUser()">ግባ</button>
<button onclick="backToStep1()" style="background:#64748b; margin-top:0.5rem;">ተመለስ</button>
<div id="loginError" style="color:#ef4444; font-size:0.8rem; margin-top:0.5rem;"></div>
</div>
<div id="adminView" style="display: none;">
<div style="display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap;">
<h1>📊 የአስተዳዳሪ ፓነል – <span id="currentAdminName"></span></h1>
<button class="logout-btn" onclick="logoutAdmin()">ውጣ</button>
</div>
<!-- Manage Admin Users (Separate) -->
<div class="admin-panel">
<h2>👑 አስተዳዳሪ ተጠቃሚዎችን ያስተዳድሩ</h2>
<div class="add-admin-form">
<input type="text" id="newAdminName" placeholder="አስተዳዳሪ ሙሉ ስም">
<input type="password" id="newAdminPass" placeholder="የይለፍ ቃል">
<button onclick="addAdminUser()">አስተዳዳሪ ጨምር</button>
</div>
<div id="adminUsersList"></div>
</div>
<!-- Manage Regular Users (Main Site) -->
<div class="admin-panel">
<h2>➕ አዲስ ተጠቃሚ (ዋና ጣቢያ) ይጨምሩ</h2>
<div class="add-user-form">
<input type="text" id="newUserName" placeholder="ሙሉ ስም">
<input type="password" id="newUserPass" placeholder="የይለፍ ቃል">
<button onclick="addNewUser()">ፍጠር</button>
</div>
</div>
<div class="admin-panel">
<h2>👥 የተመዘገቡ ተጠቃሚዎች (ዋና ጣቢያ)</h2>
<div class="search-box">
<input type="text" id="searchUser" placeholder="በስም ፈልግ..." onkeyup="filterUsers()">
<button onclick="filterUsers()">🔍 ፈልግ</button>
</div>
<div class="table-wrapper">
<table id="usersTable">
<thead>
<tr><th><input type="checkbox" id="selectAllCheckbox" onchange="toggleSelectAll()"></th><th>ሙሉ ስም</th><th>የተመዘገበበት ቀን</th><th>ሁኔታ</th><th>ተወዳጅ</th><th>እገዳ</th><th>ሰርዝ</th></tr>
</thead>
<tbody id="usersTableBody"></tbody>
</table>
</div>
<div class="action-buttons">
<button id="sendToSelectedBtn" class="send-to-selected">📨 ለተመረጡት ማሳወቂያ ላክ</button>
</div>
</div>
<div class="admin-panel">
<h2>⚽ ግጥሚያዎች እና አስተያየቶች አስተዳደር</h2>
<div class="add-match-form" style="display: flex; gap: 0.5rem; flex-wrap: wrap; margin-bottom: 1rem;">
<input type="text" id="matchTitle" placeholder="የግጥሚያ ርዕስ">
<input type="text" id="matchDate" placeholder="ቀን">
<input type="text" id="matchTime" placeholder="ሰዓት">
<input type="text" id="matchLocation" placeholder="ቦታ">
<button onclick="addMatch()">➕ ግጥሚያ ጨምር</button>
</div>
<div id="matchesList"></div>
</div>
<div class="admin-panel">
<h2>📜 የቅርብ ጊዜ እንቅስቃሴዎች</h2>
<div class="activity-log" id="activityLog"></div>
</div>
<div class="admin-panel send-notif">
<h2>📢 ለሁሉም ተጠቃሚዎች ማሳወቂያ ላክ</h2>
<textarea id="notifTitle" placeholder="ርዕስ"></textarea>
<textarea id="notifBody" placeholder="መልእክት"></textarea>
<button onclick="sendToAll()">ለሁሉም ላክ</button>
</div>
</div>
</div>
<script>
const GLOBAL_PASS = "admin123";
// Master admin is now stored in adminUsers list (will be added automatically)
let adminUsers = []; // { fullName, password }
let allUsers = [], allMatches = [], allComments = [], activityLog = [], currentFilter = '';
let currentLoggedAdmin = null;
let globalVerified = false;
function loadAllData() {
// Load admin users from localStorage
try { adminUsers = JSON.parse(localStorage.getItem('awolia_admins') || '[]'); } catch(e) { adminUsers = []; }
// Ensure master admin exists
if (!adminUsers.some(u => u.fullName === "AB Ahmed")) {
adminUsers.push({ fullName: "AB Ahmed", password: "2224633" });
saveAdminUsers();
}
allUsers = JSON.parse(localStorage.getItem('awolia_users') || '[]');
allMatches = JSON.parse(localStorage.getItem('awolia_matches') || '[]');
allComments = JSON.parse(localStorage.getItem('awolia_comments') || '[]');
activityLog = JSON.parse(localStorage.getItem('awolia_activity') || '[]');
renderAdminUsersList();
renderUsersTable();
renderMatchesWithComments();
renderActivityLog();
}
function saveAdminUsers() { localStorage.setItem('awolia_admins', JSON.stringify(adminUsers)); }
function saveMatches() { localStorage.setItem('awolia_matches', JSON.stringify(allMatches)); }
function saveComments() { localStorage.setItem('awolia_comments', JSON.stringify(allComments)); }
function saveUsers() { localStorage.setItem('awolia_users', JSON.stringify(allUsers)); }
function saveActivityLog() { localStorage.setItem('awolia_activity', JSON.stringify(activityLog)); }
function addActivity(userName, action) {
activityLog.unshift({ userName, action, timestamp: new Date().toISOString() });
if (activityLog.length > 500) activityLog.pop();
saveActivityLog();
}
function checkGlobalPassword() {
const pwd = document.getElementById('globalPassword').value;
if (pwd === GLOBAL_PASS) {
globalVerified = true;
document.getElementById('step1').style.display = 'none';
document.getElementById('step2').style.display = 'block';
document.getElementById('globalPassword').value = '';
document.getElementById('loginError').innerText = '';
} else {
alert("የዓለም አቀፍ የአስተዳዳሪ ይለፍ ቃል ትክክል አይደለም።");
}
}
function backToStep1() {
document.getElementById('step2').style.display = 'none';
document.getElementById('step1').style.display = 'block';
globalVerified = false;
}
function verifyAdminUser() {
if (!globalVerified) {
alert("እባክዎ መጀመሪያ ደረጃ 1 ያሟሉ።");
backToStep1();
return;
}
const username = document.getElementById('adminUsername').value.trim();
const password = document.getElementById('adminUserPass').value.trim();
const found = adminUsers.find(u => u.fullName === username && u.password === password);
if (found) {
currentLoggedAdmin = found;
document.getElementById('step2').style.display = 'none';
document.getElementById('adminView').style.display = 'block';
document.getElementById('currentAdminName').innerText = username;
loadAllData();
if (window.refreshInt) clearInterval(window.refreshInt);
window.refreshInt = setInterval(() => { loadAllData(); }, 5000);
addActivity(username, "🔓 ወደ አስተዳዳሪ ፓነል ገብቷል");
} else {
document.getElementById('loginError').innerText = "የአስተዳዳሪ ስም ወይም ይለፍ ቃል ትክክል አይደለም።";
}
}
function logoutAdmin() {
if (window.refreshInt) clearInterval(window.refreshInt);
document.getElementById('adminView').style.display = 'none';
document.getElementById('step1').style.display = 'block';
document.getElementById('step2').style.display = 'none';
document.getElementById('adminUsername').value = '';
document.getElementById('adminUserPass').value = '';
globalVerified = false;
currentLoggedAdmin = null;
addActivity("ስርዓት", "አስተዳዳሪ ወጥቷል");
}
// Admin user management
function renderAdminUsersList() {
const container = document.getElementById('adminUsersList');
if (!container) return;
if (adminUsers.length === 0) {
container.innerHTML = '<p>እስካሁን ምንም አስተዳዳሪ የለም።</p>';
return;
}
let html = '';
adminUsers.forEach((user, idx) => {
const isMaster = (user.fullName === "AB Ahmed");
const canDelete = (currentLoggedAdmin && currentLoggedAdmin.fullName !== user.fullName);
html += `<div class="admin-user-card">
<span><strong>${escapeHtml(user.fullName)}</strong> ${isMaster ? '(Master)' : ''}</span>
${canDelete ? `<button class="delete-btn" onclick="deleteAdminUser('${escapeHtml(user.fullName)}')">ሰርዝ</button>` : ''}
</div>`;
});
container.innerHTML = html;
}
function addAdminUser() {
const name = document.getElementById('newAdminName').value.trim();
const pass = document.getElementById('newAdminPass').value.trim();
if (!name || !pass) { alert("እባክዎ ሙሉ ስም እና የይለፍ ቃል ያስገቡ።"); return; }
if (adminUsers.some(u => u.fullName.toLowerCase() === name.toLowerCase())) { alert("ይህ አስተዳዳሪ ቀድሞ አለ።"); return; }
adminUsers.push({ fullName: name, password: pass });
saveAdminUsers();
renderAdminUsersList();
document.getElementById('newAdminName').value = '';
document.getElementById('newAdminPass').value = '';
addActivity(currentLoggedAdmin ? currentLoggedAdmin.fullName : "አስተዳዳሪ", `አዲስ አስተዳዳሪ ተጨምሯል: ${name}`);
alert(`አስተዳዳሪ "${name}" ተጨምሯል።`);
}
function deleteAdminUser(fullName) {
if (fullName === "AB Ahmed") {
alert("ዋናውን አስተዳዳሪ መሰረዝ አይቻልም።");
return;
}
if (confirm(`አስተዳዳሪ "${fullName}" ን መሰረዝ ይፈልጋሉ?`)) {
adminUsers = adminUsers.filter(u => u.fullName !== fullName);
saveAdminUsers();
renderAdminUsersList();
addActivity(currentLoggedAdmin ? currentLoggedAdmin.fullName : "አስተዳዳሪ", `አስተዳዳሪ ተሰርዟል: ${fullName}`);
alert(`አስተዳዳሪ "${fullName}" ተሰርዟል።`);
}
}
// Regular user management (main site users)
function addNewUser() {
const name = document.getElementById('newUserName').value.trim();
const pass = document.getElementById('newUserPass').value.trim();
if (!name || !pass) { alert("እባክዎ ሙሉ ስም እና የይለፍ ቃል ያስገቡ።"); return; }
if (allUsers.some(u => u.fullName.toLowerCase() === name.toLowerCase())) { alert("ይህ ተጠቃሚ ቀድሞ አለ።"); return; }
const newUser = { fullName: name, password: pass, createdAt: new Date().toISOString(), notifications: [], blocked: false, favorite: false };
allUsers.push(newUser);
saveUsers();
renderUsersTable();
document.getElementById('newUserName').value = '';
document.getElementById('newUserPass').value = '';
addActivity(currentLoggedAdmin ? currentLoggedAdmin.fullName : "አስተዳዳሪ", `አዲስ ተጠቃሚ ተጨምሯል: ${name}`);
alert(`ተጠቃሚ "${name}" ተጨምሯል።`);
}
function deleteUser(fullName) {
if (confirm(`ተጠቃሚ "${fullName}" ን መሰረዝ ይፈልጋሉ? ይህ እርምጃ ሊቀለበስ አይችልም።`)) {
allUsers = allUsers.filter(u => u.fullName !== fullName);
saveUsers();
renderUsersTable();
addActivity(currentLoggedAdmin ? currentLoggedAdmin.fullName : "አስተዳዳሪ", `ተጠቃሚ ተሰርዟል: ${fullName}`);
alert(`ተጠቃሚ "${fullName}" በስኬት ተሰርዟል።`);
}
}
function renderUsersTable() {
const tbody = document.getElementById('usersTableBody');
if (!tbody) return;
let filtered = allUsers.filter(u => u.fullName.toLowerCase().includes(currentFilter.toLowerCase()));
tbody.innerHTML = '';
filtered.forEach(user => {
const isOnline = false;
const rowClass = user.favorite ? 'favorite-row' : '';
const tr = document.createElement('tr');
tr.className = rowClass;
tr.innerHTML = `
<td><input type="checkbox" class="user-checkbox" data-name="${escapeHtml(user.fullName)}" ${user.blocked ? 'disabled' : ''}></td>
<td>${escapeHtml(user.fullName)}</td>
<td>${new Date(user.createdAt).toLocaleString()}</td>
<td><span class="status ${isOnline ? 'status-online' : 'status-offline'}">${isOnline ? 'መስመር ላይ' : 'ከመስመር ውጭ'}</span></td>
<td><button class="favorite-star" data-name="${escapeHtml(user.fullName)}">${user.favorite ? '⭐' : '☆'}</button></td>
<td><button class="block-btn ${user.blocked ? 'unblock-btn' : ''}" data-name="${escapeHtml(user.fullName)}">${user.blocked ? 'እገዳ አንሳ' : 'እገዳ'}</button></td>
<td><button class="delete-btn" onclick="deleteUser('${escapeHtml(user.fullName)}')">ሰርዝ</button></td>
`;
tbody.appendChild(tr);
});
document.querySelectorAll('.favorite-star').forEach(btn => btn.addEventListener('click', () => toggleFavorite(btn.getAttribute('data-name'))));
document.querySelectorAll('.block-btn').forEach(btn => btn.addEventListener('click', () => toggleBlock(btn.getAttribute('data-name'))));
const allCheck = document.querySelectorAll('.user-checkbox:not([disabled])');
const selectAll = document.getElementById('selectAllCheckbox');
if (selectAll) selectAll.checked = allCheck.length > 0 && Array.from(allCheck).every(cb => cb.checked);
}
function toggleFavorite(name) { const u = allUsers.find(u => u.fullName === name); if (u) { u.favorite = !u.favorite; saveUsers(); renderUsersTable(); } }
function toggleBlock(name) { const u = allUsers.find(u => u.fullName === name); if (u) { u.blocked = !u.blocked; saveUsers(); renderUsersTable(); addActivity(currentLoggedAdmin ? currentLoggedAdmin.fullName : "አስተዳዳሪ", `${u.blocked ? 'ታግዷል' : 'እገዳ ተንስቷል'}: ${name}`); alert(`${name} ${u.blocked ? 'ታግዷል' : 'እገዳ ተንስቷል'}`); } }
function filterUsers() { currentFilter = document.getElementById('searchUser').value; renderUsersTable(); }
function toggleSelectAll() { const selectAll = document.getElementById('selectAllCheckbox'); document.querySelectorAll('.user-checkbox:not([disabled])').forEach(cb => cb.checked = selectAll.checked); }
function getSelectedUsers() { const selected = []; document.querySelectorAll('.user-checkbox:checked').forEach(cb => selected.push(cb.getAttribute('data-name'))); return selected; }
function sendToSelected() {
const selected = getSelectedUsers();
if (selected.length === 0) { alert("እባክዎ ቢያንስ አንድ ተጠቃሚ ይምረጡ።"); return; }
const title = prompt("የማሳወቂያ ርዕስ ያስገቡ:"); if (!title) return;
const body = prompt("የማሳወቂያ መልእክት ያስገቡ:"); if (!body) return;
const users = JSON.parse(localStorage.getItem('awolia_users') || '[]');
let count = 0;
users.forEach(user => {
if (selected.includes(user.fullName)) {
if (!user.notifications) user.notifications = [];
user.notifications.unshift({ id: Date.now() + '_' + Math.random().toString(36).substr(2,8), title, body, timestamp: new Date().toISOString(), read: false });
count++;
}
});
localStorage.setItem('awolia_users', JSON.stringify(users));
alert(`ማሳወቂያ ለ${count} ተጠቃሚ(ዎች) ተልኳል።`);
loadAllData();
}
function sendToAll() {
const title = document.getElementById('notifTitle').value.trim();
const body = document.getElementById('notifBody').value.trim();
if (!title || !body) { alert("እባክዎ ርዕስ እና መልእክት ያስገቡ።"); return; }
const users = JSON.parse(localStorage.getItem('awolia_users') || '[]');
users.forEach(user => {
if (!user.notifications) user.notifications = [];
user.notifications.unshift({ id: Date.now() + '_' + Math.random().toString(36).substr(2,8), title, body, timestamp: new Date().toISOString(), read: false });
});
localStorage.setItem('awolia_users', JSON.stringify(users));
alert(`ማሳወቂያ ለሁሉም ተልኳል።`);
document.getElementById('notifTitle').value = '';
document.getElementById('notifBody').value = '';
loadAllData();
}
// Match and comment management (same as before)
function addComment(matchId) {
const inputField = document.getElementById(`admin-comment-input-${matchId}`);
if (!inputField) return;
const text = inputField.value.trim();
if (!text) return;
const newComment = {
id: Date.now() + '_' + Math.random().toString(36).substr(2,6),
matchId: matchId,
userName: currentLoggedAdmin ? currentLoggedAdmin.fullName : "አስተዳዳሪ",
text: text,
timestamp: new Date().toISOString()
};
allComments.push(newComment);
saveComments();
const commentsContainer = document.getElementById(`admin-comments-container-${matchId}`);
if (commentsContainer) {
const noCommentsDiv = commentsContainer.querySelector('.no-comments');
if (noCommentsDiv) noCommentsDiv.remove();
const commentDiv = document.createElement('div');
commentDiv.className = 'comment-item';
commentDiv.innerHTML = `<div class="comment-text"><strong>${escapeHtml(newComment.userName)}</strong>: ${escapeHtml(newComment.text)}<div class="comment-meta">${new Date(newComment.timestamp).toLocaleString()}</div></div>
<div class="comment-actions"><button onclick="editComment('${newComment.id}')">✏️ አርትዕ</button><button onclick="deleteComment('${newComment.id}')" style="background:#ef4444;">🗑 ሰርዝ</button></div>`;
commentsContainer.prepend(commentDiv);
const countSpan = document.getElementById(`admin-comment-count-${matchId}`);
if (countSpan) countSpan.innerText = allComments.filter(c => c.matchId === matchId).length;
}
inputField.value = '';
inputField.focus();
}
function editComment(commentId) {
const comment = allComments.find(c => c.id === commentId);
if (!comment) return;
const newText = prompt("አስተያየት አርትዕ:", comment.text);
if (newText === null || newText.trim() === "") return;
comment.text = newText.trim();
comment.editedAt = new Date().toISOString();
saveComments();
renderCommentsForMatch(comment.matchId);
addActivity(currentLoggedAdmin ? currentLoggedAdmin.fullName : "አስተዳዳሪ", `አስተያየት አርትዕ ተደርጓል ${commentId}`);
}
function deleteComment(commentId) {
if (!confirm("ይህን አስተያየት መሰረዝ ይፈልጋሉ?")) return;
const comment = allComments.find(c => c.id === commentId);
if (!comment) return;
allComments = allComments.filter(c => c.id !== commentId);
saveComments();
renderCommentsForMatch(comment.matchId);
addActivity(currentLoggedAdmin ? currentLoggedAdmin.fullName : "አስተዳዳሪ", `አስተያየት ተሰርዟል ${commentId}`);
}
function renderCommentsForMatch(matchId) {
const container = document.getElementById(`admin-comments-container-${matchId}`);
if (!container) return;
const comments = allComments.filter(c => c.matchId === matchId);
const countSpan = document.getElementById(`admin-comment-count-${matchId}`);
if (countSpan) countSpan.innerText = comments.length;
if (comments.length === 0) {
container.innerHTML = '<div class="no-comments" style="font-size:0.8rem; color:#64748b;">እስካሁን ምንም አስተያየት የለም።</div>';
} else {
let html = '';
comments.slice().reverse().forEach(c => {
html += `<div class="comment-item">
<div class="comment-text">
<strong>${escapeHtml(c.userName)}</strong>: ${escapeHtml(c.text)}
<div class="comment-meta">${new Date(c.timestamp).toLocaleString()}${c.editedAt ? ' (ተስተካክሏል)' : ''}</div>
</div>
<div class="comment-actions">
<button onclick="editComment('${c.id}')">✏️ አርትዕ</button>
<button onclick="deleteComment('${c.id}')" style="background:#ef4444;">🗑 ሰርዝ</button>
</div>
</div>`;
});
container.innerHTML = html;
}
}
function renderMatchesWithComments() {
const container = document.getElementById('matchesList');
if (!container) return;
if (allMatches.length === 0) { container.innerHTML = '<p>እስካሁን ምንም ግጥሚያ የለም። ከላይ ይጨምሩ።</p>'; return; }
let html = '';
allMatches.forEach(match => {
const comments = allComments.filter(c => c.matchId === match.id);
html += `<div class="match-card" id="match-${match.id}">
<div class="match-header">
<span class="match-title">${escapeHtml(match.title)}</span>
<div><button onclick="editMatch('${match.id}')" style="font-size:0.7rem; padding:0.2rem 0.5rem;">✏️ ግጥሚያ አርትዕ</button><button onclick="deleteMatch('${match.id}')" style="background:#ef4444; font-size:0.7rem; padding:0.2rem 0.5rem;">🗑 ግጥሚያ ሰርዝ</button></div>
</div>
<div class="match-info">📅 ${escapeHtml(match.date)} | ⏰ ${escapeHtml(match.time)} | 📍 ${escapeHtml(match.location)}</div>
<div class="comments-section">
<div style="font-weight:600; margin-bottom:0.3rem;">💬 አስተያየቶች (<span id="admin-comment-count-${match.id}">${comments.length}</span>)</div>
<div id="admin-comments-container-${match.id}">`;
if (comments.length === 0) html += `<div class="no-comments" style="font-size:0.8rem; color:#64748b;">እስካሁን ምንም አስተያየት የለም።</div>`;
else comments.slice().reverse().forEach(c => {
html += `<div class="comment-item">
<div class="comment-text"><strong>${escapeHtml(c.userName)}</strong>: ${escapeHtml(c.text)}<div class="comment-meta">${new Date(c.timestamp).toLocaleString()}${c.editedAt ? ' (ተስተካክሏል)' : ''}</div></div>
<div class="comment-actions"><button onclick="editComment('${c.id}')">✏️ አርትዕ</button><button onclick="deleteComment('${c.id}')" style="background:#ef4444;">🗑 ሰርዝ</button></div>
</div>`;
});
html += `</div>
<div class="add-comment-form">
<input type="text" id="admin-comment-input-${match.id}" placeholder="እንደ አስተዳዳሪ አስተያየት ይጻፉ...">
<button onclick="addComment('${match.id}')">ለጥፍ</button>
</div>
</div>
</div>`;
});
container.innerHTML = html;
}
function addMatch() {
let title = document.getElementById('matchTitle').value.trim(), date = document.getElementById('matchDate').value.trim(), time = document.getElementById('matchTime').value.trim(), location = document.getElementById('matchLocation').value.trim();
if (!title || !date || !time || !location) { alert("ሁሉም መስኮች መሞላት አለባቸው።"); return; }
allMatches.push({ id: Date.now() + '_' + Math.random().toString(36).substr(2,8), title, date, time, location });
saveMatches();
renderMatchesWithComments();
document.getElementById('matchTitle').value = ''; document.getElementById('matchDate').value = ''; document.getElementById('matchTime').value = ''; document.getElementById('matchLocation').value = '';
addActivity(currentLoggedAdmin ? currentLoggedAdmin.fullName : "አስተዳዳሪ", `አዲስ ግጥሚያ ተጨምሯል: ${title}`);
}
function editMatch(matchId) {
const match = allMatches.find(m => m.id === matchId);
if (!match) return;
let newTitle = prompt("ርዕስ አርትዕ:", match.title); if (!newTitle) return;
let newDate = prompt("ቀን አርትዕ:", match.date); if (!newDate) return;
let newTime = prompt("ሰዓት አርትዕ:", match.time); if (!newTime) return;
let newLoc = prompt("ቦታ አርትዕ:", match.location); if (!newLoc) return;
match.title = newTitle; match.date = newDate; match.time = newTime; match.location = newLoc;
saveMatches();
renderMatchesWithComments();
addActivity(currentLoggedAdmin ? currentLoggedAdmin.fullName : "አስተዳዳሪ", `ግጥሚያ ተስተካክሏል: ${newTitle}`);
}
function deleteMatch(matchId) {
if (confirm("ይህን ግጥሚያ እና ሁሉንም አስተያየቶች መሰረዝ ይፈልጋሉ?")) {
const match = allMatches.find(m => m.id === matchId);
allMatches = allMatches.filter(m => m.id !== matchId);
allComments = allComments.filter(c => c.matchId !== matchId);
saveMatches(); saveComments();
renderMatchesWithComments();
addActivity(currentLoggedAdmin ? currentLoggedAdmin.fullName : "አስተዳዳሪ", `ግጥሚያ ተሰርዟል: ${match.title} (ከአስተያየቶች ጋር)`);
}
}
function renderActivityLog() {
const container = document.getElementById('activityLog');
if (!container) return;
if (activityLog.length === 0) { container.innerHTML = '<p>እስካሁን ምንም እንቅስቃሴ የለም።</p>'; return; }
let html = '<ul style="list-style:none;">';
activityLog.slice(0,50).forEach(entry => {
html += `<li style="padding:0.5rem; border-bottom:1px solid #e2e8f0;">
<strong>${escapeHtml(entry.userName)}</strong> – ${escapeHtml(entry.action)}<br>
<small>${new Date(entry.timestamp).toLocaleString()}</small>
</li>`;
});
html += '</ul>';
container.innerHTML = html;
}
function escapeHtml(str) { return String(str).replace(/[&<>]/g, m => ({ '&':'&', '<':'<', '>':'>' }[m])); }
// Expose functions globally
window.addAdminUser = addAdminUser;
window.deleteAdminUser = deleteAdminUser;
window.addNewUser = addNewUser;
window.deleteUser = deleteUser;
window.toggleFavorite = toggleFavorite;
window.toggleBlock = toggleBlock;
window.filterUsers = filterUsers;
window.toggleSelectAll = toggleSelectAll;
window.sendToSelected = sendToSelected;
window.sendToAll = sendToAll;
window.addMatch = addMatch;
window.editMatch = editMatch;
window.deleteMatch = deleteMatch;
window.addComment = addComment;
window.editComment = editComment;
window.deleteComment = deleteComment;
window.checkGlobalPassword = checkGlobalPassword;
window.verifyAdminUser = verifyAdminUser;
window.backToStep1 = backToStep1;
window.logoutAdmin = logoutAdmin;
document.getElementById('sendToSelectedBtn')?.addEventListener('click', sendToSelected);
document.getElementById('selectAllCheckbox')?.addEventListener('change', toggleSelectAll);
loadAllData();
</script>
</body>
</html>