-
Notifications
You must be signed in to change notification settings - Fork 0
/
peopleMenu.html
366 lines (340 loc) · 13.4 KB
/
peopleMenu.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>People Menu</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
text-align: center;
padding: 50px;
position: relative;
margin: 0;
padding-bottom: 100px; /* Reserve space at the bottom for the footer */
}
input[type="text"], input[type="password"] {
padding: 10px;
font-size: 16px;
margin-right: 10px;
}
button {
padding: 10px 20px;
font-size: 16px;
cursor: pointer;
background-color: #4CAF50;
color: white;
border: none;
border-radius: 5px;
}
button:active {
background-color: #45a049;
}
button:hover {
opacity: 0.9;
}
h1, h2 {
color: #333;
}
#display-suggestions {
max-height: 400px;
overflow-y: auto;
text-align: center;
display: flex;
flex-direction: column;
align-items: center;
}
.QandA-container {
text-align: left;
width: 100%;
max-width: 600px;
display: flex;
justify-content: space-between;
padding: 5px;
border-bottom: 1px solid #ddd;
box-sizing: border-box;
}
.delete-button {
display: none; /* Hidden by default */
background-color: red;
color: white;
border: none;
cursor: pointer;
padding: 5px;
}
.plus-button {
position: absolute;
top: 10px;
left: 10px;
width: 40px;
height: 40px;
border: none;
background: url('black-question-mark-icon-clip-art-10.png') no-repeat center center;
background-size: cover;
cursor: pointer;
}
.admin-button {
position: absolute;
top: 10px;
right: 10px;
width: 40px;
height: 40px;
border: none;
background: url('admin-3d-illustration-icon-png-ezgif.com-webp-to-png-converter.png') no-repeat center center;
background-size: cover;
cursor: pointer;
}
.addPeople-button {
position: absolute;
top: 50px;
right: 10px;
width: 40px;
height: 40px;
border: none;
background: url('plus.png') no-repeat center center;
background-size: cover;
cursor: pointer;
display: none;
}
.QandA-modal, .Admin-modal, .AddPeople-modal {
display: none;
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
padding: 20px;
background: white;
border: 1px solid #ddd;
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.1);
z-index: 1000;
}
.QandA-modal input[type="text"], .Admin-modal input[type="text"], .AddPeople-modal input[type="text"] {
width: 100%;
}
.QandA-modal button, .Admin-modal button, .AddPeople-modal button {
background-color: #007BFF;
}
</style>
<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/4.0.0/crypto-js.min.js"></script>
</head>
<body>
<h1>People Menu</h1>
<button class="plus-button"></button>
<button class="admin-button"></button>
<button class="addPeople-button" id="addPeople-button"></button>
<div id="display-suggestions">Loading people</div>
<!-- Suggestion Modal -->
<div class="QandA-modal" id="QandA-modal">
<h2>Q and A</h2>
<form id="QandA-form">
<p>Questions and Answers</p>
<p>Q: What is this?</p>
<p>A: It's an area where I will document people.</p>
<hr>
<p>Q: Will my personal info be here?</p>
<p>A: Yes, but more confidential stuff will be hidden and only visible in admin mode.</p>
<hr>
<p>Q: Will you fix this goofy AI?</p>
<p>A: Yes.</p>
</form>
<button id="close-QandA">Close</button>
</div>
<!-- Admin Modal -->
<div class="Admin-modal" id="Admin-modal">
<h2>Enter password to access admin mode</h2>
<form id="Admin-form">
<input type="text" id="admin-password" placeholder="Enter Admin Password">
<button id="enteradmin">Enter Admin Mode</button>
</form>
<button id="close-Admin">Close</button>
</div>
<!-- Add people Modal -->
<div class="AddPeople-modal" id="AddPeople-modal">
<h2>add people to the system here</h2>
<form id="AddPeople-form">
<input type="text" id="addPeople-name" placeholder="Enter person's name">
<input type="text" id="addPeople-Bd" placeholder="Enter person's Birthday">
<input type="text" id="addPeople-id" placeholder="Enter person's id">
<input type="text" id="addPeople-address" placeholder="Enter person's address">
<button id="enteraddPeople">Add someone</button>
</form>
<button id="close-AddPeople">Close</button>
</div>
<script type="module">
import { initializeApp } from "https://www.gstatic.com/firebasejs/9.1.1/firebase-app.js";
import { getDatabase, ref, set, remove, onValue, get, child } from "https://www.gstatic.com/firebasejs/9.1.1/firebase-database.js";
// Your web app's Firebase configuration
const firebaseConfig = {
apiKey: "AIzaSyBzxQgwD_gBuylhdqlRck_PEVzueWccvTM",
authDomain: "messengerformewebsite.firebaseapp.com",
databaseURL: "https://messengerformewebsite-default-rtdb.firebaseio.com/",
projectId: "messengerformewebsite",
storageBucket: "messengerformewebsite.appspot.com",
messagingSenderId: "317747468617",
appId: "1:317747468617:web:66a9ca6c51b6cbf0f12298",
measurementId: "G-NVFGPSVEDT"
};
// Initialize Firebase
const app = initializeApp(firebaseConfig);
const database = getDatabase(app);
let isAdmin = false; // Declare this globally
const encryptedPassword = "zl5zU6x3hxU7HT2eN+3qyw=="; // The encrypted admin password
const aesKey = "password12345678"; // The AES key used to encrypt/decrypt
// Function to decrypt the password
function decryptPassword(encryptedText, key) {
let decrypted = CryptoJS.AES.decrypt(encryptedText, CryptoJS.enc.Utf8.parse(key), {
mode: CryptoJS.mode.ECB,
padding: CryptoJS.pad.Pkcs7
});
return decrypted.toString(CryptoJS.enc.Utf8);
}
// Check admin password
function checkAdmin(event) {
event.preventDefault();
let enteredPassword = document.getElementById('admin-password').value;
let decryptedPassword = decryptPassword(encryptedPassword, aesKey);
if (enteredPassword === decryptedPassword) {
isAdmin = true;
alert('Password correct!');
document.getElementById('addPeople-button').style.display = 'inline';
} else {
alert('Incorrect password');
}
}
// Add a person to Firebase
function addperson(event) {
event.preventDefault(); // Prevent form submission
let name = document.getElementById('addPeople-name').value;
let bd = document.getElementById('addPeople-Bd').value;
let id = document.getElementById('addPeople-id').value;
let address = document.getElementById('addPeople-address').value;
if (name.trim() === "") {
alert("Please enter a name");
return;
}
// Firebase database reference and set operation
set(ref(database, 'people/' + name), {
name: name,
Bd: bd,
id: id,
address: address
})
.then(() => {
alert('Person added successfully!');
document.getElementById('AddPeople-modal').style.display = 'none'; // Close the modal
document.getElementById('addPeople-name').value = ''; // Clear the input field
document.getElementById('addPeople-Bd').value = ''; // Clear the input field
})
.catch((error) => {
alert('Error adding person: ' + error);
});
}
// Log all people when Alt+D is pressed
function logAllPeople() {
const peopleRef = ref(database, 'people');
get(peopleRef).then((snapshot) => {
if (snapshot.exists()) {
const peopleData = snapshot.val();
console.log('All people:', peopleData);
} else {
console.log('No people found.');
}
}).catch((error) => {
console.error('Error retrieving people:', error);
});
}
// Add event listener for Alt+D
window.addEventListener('keydown', (event) => {
if (event.altKey && event.key === 'd') {
logAllPeople();
}
});
// Function to display list of people
function displayPeople() {
const peopleRef = ref(database, 'people');
onValue(peopleRef, (snapshot) => {
const displayDiv = document.getElementById('display-suggestions');
displayDiv.innerHTML = ''; // Clear existing content
if (snapshot.exists()) {
const peopleData = snapshot.val();
for (const personKey in peopleData) {
const person = peopleData[personKey];
const personLink = document.createElement('a');
personLink.href = `person.html?id=${personKey}`;
personLink.innerText = person.name;
personLink.style.display = 'block';
displayDiv.appendChild(personLink);
}
} else {
displayDiv.innerText = 'No people found.';
}
});
}
// Function to delete a person by name
function deletePersonByName() {
if (!isAdmin) {
alert('You must be in admin mode to delete people.');
return;
}
const personName = prompt('Enter the name of the person to delete:');
if (personName) {
const personRef = ref(database, 'people/' + personName);
// Check if the person exists
get(personRef).then((snapshot) => {
if (snapshot.exists()) {
if (confirm(`Are you sure you want to delete ${personName}?`)) {
remove(personRef)
.then(() => {
alert(`${personName} was deleted successfully!`);
displayPeople(); // Refresh the list after deletion
})
.catch((error) => {
alert('Error deleting person: ' + error);
});
}
} else {
alert(`${personName} does not exist in the system.`);
}
}).catch((error) => {
alert('Error fetching person: ' + error);
});
} else {
alert('No name entered. Deletion cancelled.');
}
}
// Add event listener for Shift+D
window.addEventListener('keydown', (event) => {
if (event.shiftKey && event.key.toLowerCase() === 'd') {
deletePersonByName();
}
});
// Call displayPeople on page load
displayPeople();
// Open and close the Q&A modal
document.querySelector('.plus-button').addEventListener('click', () => {
document.getElementById('QandA-modal').style.display = 'block';
});
document.getElementById('close-QandA').addEventListener('click', () => {
document.getElementById('QandA-modal').style.display = 'none';
});
// Open and close the Admin modal
document.querySelector('.admin-button').addEventListener('click', () => {
document.getElementById('Admin-modal').style.display = 'block';
});
document.getElementById('close-Admin').addEventListener('click', () => {
document.getElementById('Admin-modal').style.display = 'none';
});
// Open and close the AddPeople modal
document.querySelector('.addPeople-button').addEventListener('click', () => {
document.getElementById('AddPeople-modal').style.display = 'block';
});
document.getElementById('close-AddPeople').addEventListener('click', () => {
document.getElementById('AddPeople-modal').style.display = 'none';
});
// Event listeners
document.getElementById('enteradmin').addEventListener('click', checkAdmin);
document.getElementById('enteraddPeople').addEventListener('click', addperson);
</script>
</body>
</html>