-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase.html
More file actions
239 lines (200 loc) · 7.96 KB
/
database.html
File metadata and controls
239 lines (200 loc) · 7.96 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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/material-design-icons/3.0.1/iconfont/material-icons.min.css"
integrity="sha256-x8PYmLKD83R9T/sYmJn1j3is/chhJdySyhet/JuHnfY=" crossorigin="anonymous" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/tailwindcss/1.4.0/tailwind.min.css"
integrity="sha256-CAI/7ThhltsmP2L2zKBYa7FknB3ZwFbD0nqL8FCdxdc=" crossorigin="anonymous" />
<link rel="icon" type="x-icon" href="img/16724987557358.png">
<title>Database</title>
<link rel="stylesheet" href="style.css">
<style>
body {
font-family: Arial, sans-serif;
background-color: #f2f2f2;
margin: 0;
padding: 0;
}
.container {
max-width: 400px;
margin: 0 auto;
background-color: #fff;
padding: 50px;
border-radius: 5px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}
h2 {
text-align: center;
margin-top: 0;
color: #333;
}
h1 {
text-align: center;
margin-top: 0;
color: #333;
}
label {
display: block;
margin-bottom: 10px;
font-weight: bold;
color: #555;
}
input[type="text"],
input[type="password"],
select,
input[type="submit"] {
width: 100%;
padding: 10px;
border: 1px solid #ccc;
border-radius: 4px;
font-size: 16px;
margin-bottom: 15px;
box-sizing: border-box;
}
input[type="submit"] {
color: white;
cursor: pointer;
}
.error {
color: red;
margin-top: 10px;
text-align: center;
}
#appointmentsContainer {
max-width: 600px;
margin: 30px auto;
padding: 20px;
}
#appointmentsTable th,
#appointmentsTable td {
padding: 8px;
text-align: left;
}
.deleteButton {
background-color: #f44336;
color: white;
border: none;
padding: 6px 10px;
border-radius: 4px;
cursor: pointer;
}
.deleteButton:hover {
background-color: #d32f2f;
}
</style>
</head>
<body>
<div class="container" id="inputform" style="display: block;">
<h2 class="font-bold text-2xl">Database Access </h2>
<form id="loginForm">
<label for="username">Username:</label>
<input type="text" id="username" name="username" required>
<label for="password">Password:</label>
<input type="password" id="password" name="password" required>
<input class="bg-orange-500" type="submit" value="Login">
</form>
<p id="errorMessage" class="error"></p>
</div>
<div id="appointmentsContainer" style="display: none;">
<div class="container-name">
<h1 class="text-xl font-semibold underline">Contact Form Data</h1>
<table id="appointmentsTable">
<thead>
<tr>
<th>Name</th>
<th>Email</th>
<th>Phone</th>
<th>Subject</th>
<th>Message</th>
<th></th>
</tr>
</thead>
<tbody id="appointmentsBody"></tbody>
</table>
</div>
</div>
<script src="https://www.gstatic.com/firebasejs/8.6.8/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.6.8/firebase-auth.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.6.8/firebase-database.js"></script>
<script>
// Firebase configuration
var firebaseConfig = {
apiKey: "AIzaSyCH-f84ScAh46rzknhykqGM5hjDCQgreIw",
authDomain: "anubhav-wc-f8796.firebaseapp.com",
databaseURL: "https://anubhav-wc-f8796-default-rtdb.asia-southeast1.firebasedatabase.app",
projectId: "anubhav-wc-f8796",
storageBucket: "anubhav-wc-f8796.appspot.com",
messagingSenderId: "879844841720",
appId: "1:879844841720:web:2e122c6c37e3493376030d",
measurementId: "G-LVK4XMVB4R"
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
// Get a reference to the authentication and database services
var auth = firebase.auth();
var database = firebase.database();
// Handle login form submission
document.getElementById("loginForm").addEventListener("submit", function (event) {
event.preventDefault();
var username = document.getElementById("username").value;
var password = document.getElementById("password").value;
// Sign in the doctor with the provided username and password
auth.signInWithEmailAndPassword(username, password)
.then(function (userCredential) {
// Clear form and display appointments
document.getElementById("loginForm").reset();
document.getElementById("errorMessage").textContent = "";
showAppointments();
})
.catch(function (error) {
console.error(error);
document.getElementById("errorMessage").textContent = "Invalid username or password.";
});
});
// Show appointments if the doctor is authenticated
function showAppointments() {
var user = auth.currentUser;
if (user) {
// Show the appointments container
document.getElementById("appointmentsContainer").style.display = "block";
document.getElementById("inputform").style.display = "none";
// Retrieve and display the appointments from the database
var appointmentsRef = database.ref("forms");
appointmentsRef.on("value", function (snapshot) {
var appointments = snapshot.val();
var appointmentsBody = document.getElementById("appointmentsBody");
appointmentsBody.innerHTML = "";
if (appointments) {
Object.keys(appointments).forEach(function (key) {
var appointment = appointments[key];
var row = document.createElement("tr");
row.innerHTML = "<td>" + appointment.name + "</td>" +
"<td>" + appointment.email + "</td>" +
"<td>" + appointment.phone + "</td>" +
"<td>" + appointment.subject + "</td>" +
"<td>" + appointment.message + "</td>" +
"<td><button class='deleteButton' onclick='deleteAppointment(\"" + key + "\")'>Delete</button></td>";
appointmentsBody.appendChild(row);
});
}
});
}
}
// Delete an appointment from the database
function deleteAppointment(appointmentId) {
var appointmentRef = database.ref("forms/" + appointmentId);
appointmentRef.remove()
.then(function () {
console.log("Appointment deleted successfully");
})
.catch(function (error) {
console.error("Error deleting appointment:", error);
});
}
</script>
</body>
</html>