-
Notifications
You must be signed in to change notification settings - Fork 7
/
hod.html
331 lines (288 loc) · 12.6 KB
/
hod.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-4bw+/aepP/YC94hEpVNVgiZdgIC5+VKNBQNGCHeKRQN+PtmoHDEXuppvnDJzQIu9" crossorigin="anonymous">
<title>HOD</title>
</head>
<style>
body{
background-color: rgb(216, 216, 216) ;
}
#profilebtn,#logoutbtn{
padding:10px;
margin:10px;
margin-top:20px;
border-color: gray;
color:white;
}
#profilebtn:hover,#logoutbtn:hover{
background-color:transparent;
box-shadow: 3px 3px 3px #545959;
transition: 0.2s;
}
.bg{
background: rgb(2,0,36);
background: linear-gradient(90deg, rgba(2,0,36,1) 0%, rgba(0,212,255,1) 94%);
color:white;
}
.btn:active{
transform: scale(.95);
border-color: black;
}
.login-card.card.w-75.mb-3.shadow.p-3.mb-5.bg-body-tertiary.rounded{
margin:auto;
position: relative;
top:2rem;
background-color: #f4f4f4;
display: none;
}
.login-card.card.w-75.mb-3.shadow.p-3.mb-5.bg-body-tertiary.rounded.view{
display: block;
}
</style>
<body>
<div class="collapse bg" id="navbarToggleExternalContent" data-bs-theme="dark">
<div class="bg p-4" >
<h5 class="text-body-emphasis h4"><span><svg style="position:relative; bottom:4px; margin-right:10px;" xmlns="http://www.w3.org/2000/svg" width="25" height="25" fill="currentColor" class="bi bi-person-fill" viewBox="0 0 16 16">
<path d="M3 14s-1 0-1-1 1-4 6-4 6 3 6 4-1 1-1 1H3Zm5-6a3 3 0 1 0 0-6 3 3 0 0 0 0 6Z"/>
</svg></span></h5>
</div>
</div>
<nav class="navbar bg">
<div class="container-fluid">
<button id="profilebtn" class="btn navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarToggleExternalContent" aria-controls="navbarToggleExternalContent" aria-expanded="false" aria-label="Toggle navigation">
<span>Profile</span>
</button>
<button id="logoutbtn" class="navbar-toggler " type="button">
<span style="font-weight: 400;" onclick="window.location.href='login.html'">Logout</span>
</button>
</div>
</nav>
<div>
<h2 style="text-align:center;margin-top:15px;">OD REQUESTS</h2>
<div id="oddetails" class="card m-5 w-75 mb-4 mx-auto shadow p-3 mb-5 bg-body-tertiary rounded">
<div class="card-body">
<table class="table">
<thead>
<tr>
<th scope="col">Roll No</th>
<th scope="col">Name</th>
<th scoper="col">Subject</th>
<th scope="col">From-To Date</th>
<th scope="col">Actions</th>
</tr>
</thead>
<tbody id="studentReq">
</tbody>
</table>
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-HwwvtgBNo3bZJJLYd8oVXjrBZt8cqVSpeBNS5n7C8IVInixGAoxmnlMuBnhbgrkm" crossorigin="anonymous"></script>
<script src="mentor.js"></script>
<script type="module">
import { initializeApp } from "https://www.gstatic.com/firebasejs/9.0.1/firebase-app.js";
import { getAnalytics } from "https://www.gstatic.com/firebasejs/9.0.1/firebase-analytics.js";
import { getAuth } from "https://www.gstatic.com/firebasejs/9.0.1/firebase-auth.js";
import {
getFirestore,
collection,
addDoc,
doc,
getDocs,
} from "https://www.gstatic.com/firebasejs/9.0.1/firebase-firestore.js";
import { getDoc } from "https://www.gstatic.com/firebasejs/9.0.1/firebase-firestore.js";
import {setDoc } from "https://www.gstatic.com/firebasejs/9.0.1/firebase-firestore.js";
const firebaseConfig = {
apiKey: "AIzaSyCb5rHQgaeYJgHFapU_KkpSobPoWCezFhA",
authDomain: "od-project-b00da.firebaseapp.com",
projectId: "od-project-b00da",
storageBucket: "od-project-b00da.appspot.com",
messagingSenderId: "309156647421",
appId: "1:309156647421:web:ae8a858791f279acf14994",
measurementId: "G-6YBET1MVLK",
};
const app = initializeApp(firebaseConfig);
const analytics = getAnalytics(app);
const auth = getAuth();
let reqtable=document.getElementById("studentReq")
window.addEventListener('load', async (event) => {
try {
const db = getFirestore(app);
const data = await getDocs(collection(db, "users"));
let bodyInsert = document.getElementById("studentReq");
// let login = document.cookie.split(",");
// let loginusername=login[0].toLocaleUpperCase()
const userDetails = getUserDetails()
let loginusername=userDetails.userName.toLocaleUpperCase()
if(loginusername.includes("CSE")){
var reqDept="cse"
}else if(loginusername.includes("IT")){
var reqDept="it"
}else if(loginusername.includes("ECE")){
var reqDept="ece"
}else if(loginusername.includes("AIDS")){
var reqDept="aids"
}else if(loginusername.includes("MECH")){
var reqDept="mech"
}else if(loginusername.includes("CSBS")){
var reqDept="csbs"
}
data.forEach(async (info) => {
let dataset = info.data();
// Assuming your Firestore collection is named "odlist"
let odlist = dataset.odlist;
console.log(odlist);
for (const odRequest of odlist) {
if (odRequest.mentor == "accepted" && odRequest.hod=="pending" && odRequest.dept==reqDept) {
const rollno = odRequest.RollNo;
const name = odRequest.StudentName;
const subject = odRequest.Reason;
const fromdate = odRequest.OdFrom;
const todate = odRequest.To;
const docid = info.id; // Use info.id for the document ID
// Use unique class names for the buttons
let temp = `<tr>
<td>${name}</td>
<td>${rollno}</td>
<td>${subject}</td>
<td>${fromdate} to ${todate}</td>
<td>
<button class="btn-outline-success btn accept" data-id="${docid}">Accept</button>
<button class="btn-outline-danger btn reject" data-id="${docid}">Reject</button>
</td>
</tr>`;
bodyInsert.innerHTML += temp;
}
}
});
const studentReq = document.getElementById("studentReq");
studentReq.addEventListener('click', async function (event) {
const target = event.target;
// Check if the clicked element is a button with the class "accept"
if (target.classList.contains('accept')) {
// Get the data-id attribute value for the specific button clicked
const reqid = target.getAttribute('data-id');
const parentRow = target.closest('tr');
const tablesubject = parentRow.cells[2].textContent;
const tabledate=parentRow.cells[3].textContent;
console.log('Accepted ID:', reqid);
// Now, you can use the reqid to retrieve data from Firestore and update the 'mentor' value to 'accepted'
try {
const docRef = doc(db, "users", reqid);
const docSnapshot = await getDoc(docRef);
console.log(docSnapshot);
if (docSnapshot.exists()) {
// Document exists, retrieve its data
const data = docSnapshot.data();
let name = data.username;
let password = data.password;
let odlist = data.odlist;
const updatedOdlist = [];
for (const odRequest of odlist) {
const rollno = odRequest.RollNo;
const name = odRequest.StudentName;
const subject = odRequest.Reason;
const fromdate = odRequest.OdFrom;
const todate = odRequest.To;
// Check if the subject matches the given value
if (subject === tablesubject && tabledate==`${fromdate} to ${todate}`) {
// If the subject matches, update the 'mentor' value to 'accepted'
odRequest.mentor = "accepted";
odRequest.hod="accepted"
}
// Push the modified or unmodified odRequest into the updatedOdlist array
updatedOdlist.push(odRequest);
}
// Now 'updatedOdlist' contains the modified 'odlist' with 'mentor' values updated as needed.
console.log(updatedOdlist);
// Update the Firestore document with the modified 'odlist'
await setDoc(docRef, { username: name, password: password, odlist: updatedOdlist }, { merge: true });
console.log('Document updated successfully');
parentRow.remove()
} else {
console.log('Document does not exist.');
}
} catch (error) {
console.error('Error retrieving or updating document:', error);
}
} else if (target.classList.contains('reject')) {
// Get the data-id attribute value for the specific button clicked
const reqid = target.getAttribute('data-id');
const parentRow = target.closest('tr');
const tablesubject = parentRow.cells[2].textContent;
const tabledate=parentRow.cells[3].textContent;
console.log('Rejected ID:', reqid);
// Now, you can use the reqid to retrieve data from Firestore and update the 'mentor' value to 'reject'
try {
const docRef = doc(db, "users", reqid);
const docSnapshot = await getDoc(docRef);
console.log(docSnapshot);
if (docSnapshot.exists()) {
// Document exists, retrieve its data
const data = docSnapshot.data();
let name = data.username;
let password = data.password;
let odlist = data.odlist;
const updatedOdlist = [];
for (const odRequest of odlist) {
const rollno = odRequest.RollNo;
const name = odRequest.StudentName;
const subject = odRequest.Reason;
const fromdate = odRequest.OdFrom;
const todate = odRequest.To;
// Check if the subject matches the given value
if (subject === tablesubject && tabledate==`${fromdate} to ${todate}`) {
// If the subject matches, update the 'mentor' value to 'rejected'
odRequest.mentor = "rejected";
odRequest.hod="rejected"
odRequest.principal="rejected by hod"
}
// Push the modified or unmodified odRequest into the updatedOdlist array
updatedOdlist.push(odRequest);
}
// Now 'updatedOdlist' contains the modified 'odlist' with 'mentor' values updated as needed.
console.log(updatedOdlist);
// Update the Firestore document with the modified 'odlist'
await setDoc(docRef, { username: name, password: password, odlist: updatedOdlist }, { merge: true });
console.log('Document updated successfully');
parentRow.remove()
} else {
console.log('Document does not exist.');
}
} catch (error) {
console.error('Error retrieving or updating document:', error);
}
}
});
// Add your code to handle the "Reject" button click here if needed
} catch (error) {
console.log("retrieve error:", error);
}
});
const profile=document.getElementById("profilebtn")
profile.addEventListener("click",(event)=>{
event.preventDefault()
// let loginusername=document.cookie.split(",");
// let userloginname=loginusername[0]
const userDetails = getUserDetails()
document.querySelector(".text-body-emphasis.h4").innerText=userDetails.userName
})
function getUserDetails()
{
var cookies = document.cookie.split(";"); // Split the cookies string into an array
var myCookieValue = null;
for (var i = 0; i < cookies.length; i++) {
var cookie = cookies[i].trim();
if (cookie.startsWith("myCookie=")) {
myCookieValue = cookie.substring("myCookie=".length);
break; // Exit the loop once we find the myCookie
}
}
return JSON.parse(myCookieValue)
}
</script>
</body>
</html>