-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathomrfireadmin.html
174 lines (152 loc) · 5.07 KB
/
omrfireadmin.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Questions Submission</title>
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css" rel="stylesheet">
<style>
body {
font-family: Arial, sans-serif;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
background-color: #f4f4f4;
}
.container {
text-align: center;
padding: 20px;
width: 100%;
}
h1 {
margin-bottom: 20px;
}
textarea {
width: 80%;
height: 100px;
margin-bottom: 20px;
padding: 10px;
font-size: 16px;
border-radius: 8px;
border: 1px solid #ddd;
}
input[type="text"] {
width: 80%;
padding: 10px;
font-size: 16px;
border-radius: 8px;
border: 1px solid #ddd;
margin-bottom: 20px;
}
button {
padding: 10px 20px;
background-color: #4CAF50;
color: white;
font-size: 16px;
border: none;
border-radius: 5px;
cursor: pointer;
}
button:hover {
background-color: #45a049;
}
.message {
margin-top: 20px;
color: #28a745;
}
.error {
margin-top: 20px;
color: #e74c3c;
}
</style>
</head>
<body>
<div class="container">
<h1>Submit Your Questions</h1>
<input type="text" id="testNameInput" placeholder="Enter Test Name">
<textarea id="questionInput" placeholder="Enter your questions (e.g., ABCDABC)"></textarea>
<br>
<button id="submitBtn">Submit Questions</button>
<div class="message" id="message"></div>
<div class="error" id="error"></div>
</div>
<!-- Firebase SDK -->
<script src="https://www.gstatic.com/firebasejs/8.10.0/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.10.0/firebase-database.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.10.0/firebase-auth.js"></script>
<script>
// Firebase configuration
const firebaseConfig = {
apiKey: "AIzaSyAW-_UpVNHCZhjiMy8k9mdbC63KOvwEWiY",
authDomain: "answer-e8d1d.firebaseapp.com",
databaseURL: "https://answer-e8d1d-default-rtdb.asia-southeast1.firebasedatabase.app",
projectId: "answer-e8d1d",
storageBucket: "answer-e8d1d.firebasestorage.app",
messagingSenderId: "102395650845",
appId: "1:102395650845:web:1df470ced8f1a6fb6377f4",
measurementId: "G-2LTL67DFHS"
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
const database = firebase.database();
// DOM Elements
const submitBtn = document.getElementById('submitBtn');
const questionInput = document.getElementById('questionInput');
const testNameInput = document.getElementById('testNameInput');
const messageDiv = document.getElementById('message');
const errorDiv = document.getElementById('error');
// Function to submit questions
submitBtn.addEventListener('click', () => {
const inputText = questionInput.value.trim();
const testName = testNameInput.value.trim();
if (inputText === "" || testName === "") {
errorDiv.textContent = "Please enter a test name and some questions.";
return;
}
// Split the input by each character
const questions = inputText.split('').map(q => q.trim()).filter(q => q !== "");
if (questions.length === 0) {
errorDiv.textContent = "Please enter at least one question.";
return;
}
// Get the current date and time
const currentDate = new Date();
const date = currentDate.toLocaleDateString(); // e.g., "1/28/2025"
const time = currentDate.toLocaleTimeString(); // e.g., "12:30:45 PM"
// Generate a unique keyid for the group of questions
const keyid = database.ref().child('questions').push().key;
// Prepare data structure to save with "answer" instead of "content"
const questionsData = {};
questions.forEach((question, index) => {
const qKey = `q${index + 1}`;
questionsData[qKey] = {
answer: question
};
});
// Prepare the additional metadata (date, time, and test name)
const testMetadata = {
testName: testName,
date: date,
time: time
};
// Save questions and metadata to Firebase
database.ref(`answerkeys/${keyid}`).set({
metadata: testMetadata,
questions: questionsData
})
.then(() => {
messageDiv.textContent = "Questions submitted successfully!";
errorDiv.textContent = "";
questionInput.value = ""; // Clear input
testNameInput.value = ""; // Clear test name input
})
.catch((error) => {
errorDiv.textContent = "Error submitting questions: " + error.message;
messageDiv.textContent = "";
});
});
</script>
</body>
</html>