-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadmin.html
More file actions
355 lines (333 loc) · 21.5 KB
/
Copy pathadmin.html
File metadata and controls
355 lines (333 loc) · 21.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
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
<!DOCTYPE html>
<html lang="vi">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Admin Dashboard</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Be+Vietnam+Pro:wght@400;500;700&display=swap" rel="stylesheet">
<script src="https://unpkg.com/@phosphor-icons/web"></script>
<style>
body { font-family: 'Be Vietnam Pro', sans-serif; color: #e0e0e0; margin: 0; padding: 25px; display: flex; justify-content: center; align-items: flex-start; min-height: 100vh; background: #121828; overflow-y: auto; }
.container { width: 100%; max-width: 1400px; padding: 10px;}
h1, h2 { text-align: center; color: #ffffff; font-weight: 700; text-shadow: 2px 2px 8px rgba(0, 0, 0, 0.5); }
h1 { font-size: 2.8em; margin-bottom: 30px; }
h2 { font-size: 2em; margin-top: 50px; border-top: 1px solid rgba(255,255,255,0.1); padding-top: 40px;}
.card { background: rgba(20, 26, 44, 0.6); backdrop-filter: blur(15px); -webkit-backdrop-filter: blur(15px); border-radius: 20px; border: 1px solid rgba(255, 255, 255, 0.1); box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37); padding: 30px; margin-bottom: 30px;}
table { width: 100%; border-collapse: collapse; margin-top: 20px; border-radius: 15px; overflow: hidden; }
th, td { border: 1px solid rgba(255, 255, 255, 0.1); padding: 8px; text-align: center; }
th { background: rgba(255, 255, 255, 0.15); padding: 15px; font-size: 1.1em; }
input[type="text"], input[type="password"], select { width: 100%; background-color: rgba(0, 0, 0, 0.3); border: 1px solid rgba(255, 255, 255, 0.2); border-radius: 8px; padding: 12px; box-sizing: border-box; color: #fff; font-family: 'Be Vietnam Pro', sans-serif; font-size: 1em; transition: all 0.3s ease; }
input[type="text"]:focus, input[type="password"]:focus, select:focus { outline: none; border-color: #A5B4FC; box-shadow: 0 0 15px rgba(165, 180, 252, 0.3); background-color: rgba(0, 0, 0, 0.5); }
select option { background: #1e2840; }
button { display: block; width: 100%; padding: 15px; background: linear-gradient(90deg, #4F46E5, #7C3AED); color: white; border: none; border-radius: 50px; cursor: pointer; margin-top: 25px; font-size: 1.1em; font-weight: 700; letter-spacing: 1px; transition: all 0.3s ease; box-shadow: 0 4px 15px rgba(0,0,0,0.2); }
button:hover { transform: translateY(-3px); box-shadow: 0 8px 25px rgba(99, 102, 241, 0.4); }
.view-link { text-align: center; margin-top: 30px; } .view-link a { color: #A5B4FC; text-decoration: none; font-weight: 500; font-size: 1.1em; transition: color 0.3s; } .view-link a:hover { color: #fff; }
.settings-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 25px; align-items: flex-start; }
.form-group { display: flex; flex-direction: column; } .form-group label { margin-bottom: 8px; font-weight: 500; }
.color-picker-group { display: flex; align-items: center; gap: 15px; }
input[type="color"] { -webkit-appearance: none; width: 50px; height: 50px; border: none; border-radius: 50%; cursor: pointer; background-color: transparent; } input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; } input[type="color"]::-webkit-color-swatch { border-radius: 50%; border: 2px solid rgba(255, 255, 255, 0.5); }
.times-tables-container { display: grid; grid-template-columns: 1fr 1fr; gap: 30px; }
.times-editor-card h3 { display: flex; justify-content: center; align-items: center; gap: 15px; font-size: 1.5em; margin-top: 0; }
.action-btn { background: rgba(255, 255, 255, 0.1); border: 1px solid rgba(255, 255, 255, 0.2); color: #fff; border-radius: 50%; width: 30px; height: 30px; font-size: 1.2em; cursor: pointer; transition: background-color 0.3s, transform 0.3s; padding: 0; margin: 0; line-height: 30px; }
.action-btn:hover { transform: scale(1.1); }
.add-btn { background-color: rgba(74, 222, 128, 0.2); } .add-btn:hover { background-color: rgba(74, 222, 128, 0.5); }
.delete-btn { background-color: rgba(239, 68, 68, 0.2); } .delete-btn:hover { background-color: rgba(239, 68, 68, 0.5); }
#login-section { display: flex; justify-content: center; align-items: center; min-height: 80vh; }
.login-card { width: 100%; max-width: 400px; text-align: center; }
.login-card h1 { font-size: 2.2em; }
.login-card input { margin-bottom: 15px; }
.login-card button { width: auto; padding: 12px 40px; margin: 15px auto 0; }
#auth-error { text-align: center; padding: 15px; border-radius: 8px; margin-top: 20px; background-color: rgba(239, 68, 68, 0.2); border: 1px solid rgba(239, 68, 68, 0.5); color: #FCA5A5; display: none; }
#admin-content { display: none; }
#toast-notification { position: fixed; bottom: 25px; left: 50%; transform: translateX(-50%) translateY(100px); background: rgba(16, 185, 129, 0.8); backdrop-filter: blur(10px); color: white; padding: 15px 30px; border-radius: 50px; border: 1px solid rgba(255,255,255,0.2); box-shadow: 0 4px 20px rgba(0,0,0,0.3); z-index: 1000; opacity: 0; transition: transform 0.5s ease, opacity 0.5s ease; font-weight: 500; }
#toast-notification.show { transform: translateX(-50%) translateY(0); opacity: 1; }
@media (max-width: 992px) { .times-tables-container { grid-template-columns: 1fr; } }
</style>
</head>
<body>
<div class="container">
<div id="login-section">
<div class="login-card card">
<h1><i class="ph-fill ph-lock"></i> Admin Login</h1>
<input type="text" id="username-input" placeholder="Tên đăng nhập...">
<input type="password" id="password-input" placeholder="Nhập mật khẩu...">
<button onclick="attemptLogin()">Đăng Nhập</button>
<div id="auth-error">Tài khoản hoặc mật khẩu không đúng. Vui lòng thử lại.</div>
</div>
</div>
<div id="admin-content">
<h1><i class="ph-fill ph-gauge"></i> Admin Dashboard </h1>
<div class="card">
<h2>Chỉnh Sửa Thời Khóa Biểu</h2>
<div id="history-select" style="display: none;"><label for="history-dropdown">Xem phiên bản cũ:</label><select id="history-dropdown" onchange="renderAdmin()"></select></div>
<table id="admin-table"><thead id="admin-thead"></thead><tbody id="admin-tbody"></tbody></table>
<button onclick="saveSchedule()">Lưu Thay Đổi Thời Khóa Biểu</button>
</div>
<div class="card">
<h2>Chỉnh Sửa Thời Gian Tiết Học</h2>
<div class="form-group">
<label for="times-title">Tiêu đề (VD: Năm học 2025-2026)</label>
<input type="text" id="times-title" placeholder="Nhập tiêu đề">
</div>
<div class="times-tables-container">
<div>
<h3>Buổi Sáng <button class="action-btn add-btn" onclick="addRow('morning-times-tbody')">+</button></h3>
<table id="morning-times-table">
<thead><tr><th>Thời gian</th><th>Thời lượng</th><th>Nội dung</th><th>Giải lao?</th><th>Xóa</th></tr></thead>
<tbody id="morning-times-tbody"></tbody>
</table>
</div>
<div>
<h3>Buổi Chiều <button class="action-btn add-btn" onclick="addRow('afternoon-times-tbody')">+</button></h3>
<table id="afternoon-times-table">
<thead><tr><th>Thời gian</th><th>Thời lượng</th><th>Nội dung</th><th>Giải lao?</th><th>Xóa</th></tr></thead>
<tbody id="afternoon-times-tbody"></tbody>
</table>
</div>
</div>
<button onclick="saveTimes()">Lưu Thay Đổi Thời Gian</button>
</div>
<div class="card">
<h2>Bảng Điều Khiển</h2>
<div class="settings-grid">
<div class="form-group"><label for="new-password">Đổi Mật Khẩu Admin:</label><input type="password" id="new-password" placeholder="Để trống nếu không đổi"></div>
<div class="form-group"><label for="page-title">Đổi Tên Trang:</label><input type="text" id="page-title" placeholder="Tên mới cho TKB"></div>
<div class="form-group"><label>Đổi Màu Nền:</label><div class="color-picker-group"><input type="color" id="background-color" value="#f0f8ff"><span>Chọn màu</span></div></div>
<div class="form-group">
<label for="favicon-url">Favicon (URL ảnh .ico/.png):</label>
<input type="text" id="favicon-url" placeholder="Nhập URL favicon">
</div>
<div class="form-group">
<label for="og-title">OG Title:</label>
<input type="text" id="og-title" placeholder="Tiêu đề chia sẻ mạng xã hội">
</div>
<div class="form-group">
<label for="og-description">OG Description:</label>
<input type="text" id="og-description" placeholder="Mô tả chia sẻ mạng xã hội">
</div>
<div class="form-group">
<label for="canonical-url">Canonical URL:</label>
<input type="text" id="canonical-url" placeholder="https://mavrixdev.vercel.app/">
</div>
<div class="form-group">
<label for="meta-keywords">Keywords:</label>
<input type="text" id="meta-keywords" placeholder="ntmdz,tkbntmdz,ntmdztkb,Mavrixdev,...">
</div>
</div>
<button onclick="saveSettings()">Lưu Cài Đặt</button>
</div>
<div class="view-link"><a href="/">Quay Về Trang Xem <i class="ph ph-arrow-right"></i></a></div>
</div>
</div>
<div id="toast-notification"></div>
<script src="/socket.io/socket.io.js"></script>
<script>
let socket;
let history = [];
let currentSchedule = [];
const loginSection = document.getElementById('login-section');
const adminContent = document.getElementById('admin-content');
const passwordInput = document.getElementById('password-input');
const authError = document.getElementById('auth-error');
function saveSettings() {
const newSettings = {};
const newPassword = document.getElementById('new-password').value;
if (newPassword) newSettings.adminPassword = newPassword;
const pageTitle = document.getElementById('page-title').value;
if (pageTitle) newSettings.pageTitle = pageTitle;
newSettings.backgroundColor = document.getElementById('background-color').value;
// Thêm các trường meta mới
newSettings.favicon = document.getElementById('favicon-url').value;
newSettings.ogTitle = document.getElementById('og-title').value;
newSettings.ogDescription = document.getElementById('og-description').value;
newSettings.canonical = document.getElementById('canonical-url').value;
newSettings.keywords = document.getElementById('meta-keywords').value;
if (Object.keys(newSettings).length > 1 || (Object.keys(newSettings).length === 1 && !newSettings.hasOwnProperty('backgroundColor'))) {
socket.emit('saveSettings', newSettings);
showToast('Đã lưu cài đặt!');
document.getElementById('new-password').value = '';
// KHÔNG xóa các trường khác
} else if (Object.keys(newSettings).length === 1 && newSettings.hasOwnProperty('backgroundColor')) {
socket.emit('saveSettings', newSettings);
showToast('Đã lưu màu nền!');
} else {
showToast('Không có thay đổi nào để lưu.');
}
}
function attemptLogin() {
const username = document.getElementById('username-input').value;
const password = document.getElementById('password-input').value;
if (!username || !password) {
alert('Vui lòng nhập đầy đủ tên đăng nhập và mật khẩu.');
return;
}
if (socket) {
socket.disconnect();
}
// ĐÃ SỬA: Xóa bỏ "transports: ['polling']"
socket = io('/admin', {
auth: { username, password }
});
socket.on('authSuccess', () => {
console.log("Xác thực thành công! Đang tải bảng điều khiển.");
authError.style.display = 'none';
loginSection.style.display = 'none';
adminContent.style.display = 'block';
initializeAdminPanel();
});
socket.on('connect_error', (err) => {
console.error("Xác thực thất bại:", err.message);
// Hiển thị lỗi thật từ server thay vì lỗi chung chung
authError.textContent = 'Lỗi: ' + err.message;
authError.style.display = 'block';
if (socket) {
socket.disconnect();
}
});
}
passwordInput.addEventListener('keypress', (e) => {
if (e.key === 'Enter') attemptLogin();
});
function initializeAdminPanel() {
socket.on('updateHistory', (newHistory) => {
history = newHistory;
updateDropdown();
});
socket.on('updateSettings', (newSettings) => {
document.title = (newSettings.pageTitle || 'Admin') + ' - Dashboard';
document.getElementById('page-title').placeholder = `Tên hiện tại: ${newSettings.pageTitle || 'Chưa đặt'}`;
document.getElementById('background-color').value = newSettings.backgroundColor || '#f0f8ff';
document.getElementById('favicon-url').value = newSettings.favicon || '';
document.getElementById('og-title').value = newSettings.ogTitle || '';
document.getElementById('og-description').value = newSettings.ogDescription || '';
document.getElementById('canonical-url').value = newSettings.canonical || '';
document.getElementById('meta-keywords').value = newSettings.keywords || '';
});
socket.on('updateTimes', (timesData) => {
renderTimesEditor(timesData);
});
}
function showToast(message) {
const toast = document.getElementById('toast-notification');
toast.textContent = message;
toast.classList.add('show');
setTimeout(() => {
toast.classList.remove('show');
}, 3000);
}
function addRow(tbodyId) {
const tbody = document.getElementById(tbodyId);
const tr = document.createElement('tr');
tr.innerHTML = `<td><input type="text" value=""></td><td><input type="text" value=""></td><td><input type="text" value=""></td><td><input type="checkbox"></td><td><button class="action-btn delete-btn" onclick="deleteRow(this)">🗑️</button></td>`;
tbody.appendChild(tr);
}
function deleteRow(btn) {
btn.parentNode.parentNode.remove();
}
function renderTimesEditor(timesData) {
if (!timesData) return;
document.getElementById('times-title').value = timesData.title || '';
const renderBody = (tbodyId, data) => {
const tbody = document.getElementById(tbodyId);
tbody.innerHTML = '';
(data || []).forEach(row => {
const tr = document.createElement('tr');
tr.innerHTML = `
<td><input type="text" value="${row.time || ''}"></td>
<td><input type="text" value="${row.duration || ''}"></td>
<td><input type="text" value="${row.content || ''}"></td>
<td><input type="checkbox" ${row.isBreak ? 'checked' : ''}></td>
<td><button class="action-btn delete-btn" onclick="deleteRow(this)">🗑️</button></td>
`;
tbody.appendChild(tr);
});
};
renderBody('morning-times-tbody', timesData.morning);
renderBody('afternoon-times-tbody', timesData.afternoon);
}
function saveTimes() {
const getDataFromTable = (tbodyId) => {
const data = [];
document.querySelectorAll(`#${tbodyId} tr`).forEach(tr => {
const inputs = tr.querySelectorAll('input');
data.push({
time: inputs[0].value,
duration: inputs[1].value,
content: inputs[2].value,
isBreak: inputs[3].checked
});
});
return data;
};
const newTimesData = {
title: document.getElementById('times-title').value,
morning: getDataFromTable('morning-times-tbody'),
afternoon: getDataFromTable('afternoon-times-tbody')
};
socket.emit('saveTimes', newTimesData);
showToast('Đã lưu thay đổi thời gian!');
}
const templateSchedule = [
{ day: 'Thứ 2', periods: Array(10).fill('') }, { day: 'Thứ 3', periods: Array(10).fill('') },
{ day: 'Thứ 4', periods: Array(10).fill('') }, { day: 'Thứ 5', periods: Array(10).fill('') },
{ day: 'Thứ 6', periods: Array(10).fill('') }, { day: 'Thứ 7', periods: Array(10).fill('') }
];
function renderAdmin() {
if (history.length === 0) {
currentSchedule = JSON.parse(JSON.stringify(templateSchedule));
} else {
const selectedIndex = document.getElementById('history-dropdown').value;
currentSchedule = JSON.parse(JSON.stringify(history[selectedIndex].schedule));
currentSchedule.forEach(item => {
while (item.periods.length < 10) item.periods.push('');
});
}
const thead = document.getElementById('admin-thead');
thead.innerHTML = ` <tr> <th rowspan="2">Thứ</th> <th colspan="5">Buổi Sáng</th> <th colspan="5">Buổi Chiều</th> </tr> <tr> ${Array.from({length: 5}, (_, i) => `<th>Tiết ${i+1}</th>`).join('')}${Array.from({length: 5}, (_, i) => `<th>Tiết ${i+1}</th>`).join('')} </tr> `;
const tbody = document.getElementById('admin-tbody');
tbody.innerHTML = '';
currentSchedule.forEach((item, rowIndex) => {
const row = document.createElement('tr');
let cellsHTML = `<td>${item.day}</td>`;
item.periods.forEach((period, colIndex) => {
cellsHTML += `<td><input type="text" value="${period || ''}" data-row="${rowIndex}" data-col="${colIndex}"></td>`;
});
row.innerHTML = cellsHTML;
tbody.appendChild(row);
});
}
function saveSchedule() {
const inputs = document.querySelectorAll('#admin-table input[type="text"]');
const newSchedule = JSON.parse(JSON.stringify(currentSchedule));
inputs.forEach(input => {
const row = input.dataset.row;
const col = input.dataset.col;
newSchedule[row].periods[col] = input.value;
});
socket.emit('saveSchedule', newSchedule);
showToast('Đã lưu TKB và tạo phiên bản mới!');
}
function updateDropdown() {
const dropdown = document.getElementById('history-dropdown');
const selectDiv = document.getElementById('history-select');
dropdown.innerHTML = '';
if (history.length === 0) {
selectDiv.style.display = 'none';
} else {
selectDiv.style.display = 'block';
history.forEach((entry, index) => {
const date = new Date(entry.timestamp).toLocaleString('vi-VN');
const option = document.createElement('option');
option.value = index;
option.textContent = `Phiên bản lúc: ${date}`;
dropdown.appendChild(option);
});
dropdown.value = history.length - 1;
}
renderAdmin();
}
</script>
</body>
</html>