-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.js
647 lines (616 loc) · 18.1 KB
/
main.js
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
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
$(document).ready(function(){
console.log("no prblem in jquery");
$('#addstudenterror').html('');
$("#facultyloginbutton").click(function(){
var facultyform =$("#facultyloginform");
if(!facultyform[0].checkValidity()){
facultyform[0].reportValidity();
return;
}
var dataString = 'action=facultylogin&' + $("#facultyloginform").serialize();
$.ajax({
type:"POST",
url:"ajax.php",
data : dataString,
success : function(result){
if (result=="success") {
window.location.href="faculty.php";
}else{
$('#facultyloginalert').html(result);
window.setTimeout(givedealy, 2000);
function givedealy(){
$('#facultyloginalert').html('');
}
}
document.getElementById('facultyloginform').reset();
}
});
});
$("#adminloginbutton").click(function(){
var adminform =$("#adminloginform");
if(!adminform[0].checkValidity()){
adminform[0].reportValidity();
return;
}
var dataString = 'action=adminlogin&' + $("#adminloginform").serialize();
$.ajax({
type:"POST",
url:"ajax.php",
data : dataString,
success : function(result){
if (result=="success") {
window.location.href="admin.php"
}else{
$('#adminloginalert').html(result);
window.setTimeout(givedealy, 2000);
function givedealy(){
$('#adminloginalert').html('');
}
}
document.getElementById('adminloginform').reset();
}
});
});
$('#addstudentbutton').click(function(){
$('#addstudenterror').html('');
var studentname =$('#studentname').val();
var studentyear =$('#studentyear').val();
var studentbranch =$('#studentbranch').val();
var studentrollno =$('#studentrollno').val();
// console.log(studentname+studentyear+studentbranch+studentrollno);
if(studentname =='' || studentyear =='default' || studentrollno =='' || studentbranch =='default'){
$('#addstudenterror').html('<br><p class="text-danger">All fields are mandetory</p>');
var studentform =$("#addstudentform");
if(!studentform[0].checkValidity()){
studentform[0].reportValidity();
return;
}
window.setTimeout(givedealy, 2000);
function givedealy(){
$('#addstudenterror').html('');
}
return;
}
var studentform =$("#addstudentform");
if(!studentform[0].checkValidity()){
studentform[0].reportValidity();
return;
}
var dataString = 'action=addstudent&' + $("#addstudentform").serialize();
$.ajax({
type:"POST",
url:"ajax.php",
data: dataString,
success:function(result){
$('#addstudenterror').html(result);
document.getElementById('addstudentform').reset();
window.setTimeout(givedealy, 2000);
function givedealy(){
$('#addstudenterror').html('');
}
}
});
});
$("#addfacultybutton").click(function(){
$('#addfacultyerror').html('');
var facultyname =$('#facultyname').val();
var facultyemailid =$('#facultyemailid').val();
var facultyid =$('#facultyid').val();
var password =$('#facultyassignpassword').val();
if (facultyname=='' || facultyemailid =='' || facultyid=='' || password =='') {
$('#addfacultyerror').html('<br><p class="text-danger">All fields are mandetory</p>');
var facultyform =$("#addfacultyform");
if(!facultyform[0].checkValidity()){
facultyform[0].reportValidity();
return;
}
window.setTimeout(givedealy, 2000);
function givedealy(){
$('#addfacultyerror').html('');
}
return;
}
var facultyform =$("#addfacultyform");
if(!facultyform[0].checkValidity()){
facultyform[0].reportValidity();
return;
}
var dataString = 'action=addfaculty&' + $('#addfacultyform').serialize();
$.ajax({
type:"POST",
url:"ajax.php",
data : dataString,
success:function(result){
// console.log(result);
$('#addfacultyerror').html(result);
document.getElementById('addfacultyform').reset();
window.setTimeout(givedealy, 2000);
function givedealy(){
$('#addfacultyerror').html('');
}
}
})
});
function printElement(elem) {
var domClone = elem.cloneNode(true);
var $printSection = document.getElementById("printSection");
if (!$printSection) {
var $printSection = document.createElement("div");
$printSection.id = "printSection";
document.body.appendChild($printSection);
}
$printSection.innerHTML = "";
$printSection.appendChild(domClone);
window.print();
}
$("#attendanceyear").on("change",function(){
var year =$("#attendanceyear").val();
if(year =="First"){
console.log("First year");
$("#attendancesem").html('<option value="default" selected>Select Semester</option><option value="First">First</option><option value="Second">Second</option>');
}else{
if(year =="Second"){
$("#attendancesem").html('<option value="default" selected>Select Semester</option><option value="Third">Third</option><option value="Fourth">Fourth</option>');
}else{
if(year =="Third"){
$("#attendancesem").html('<option value="default" selected>Select Semester</option><option value="Fifth">Fifth</option><option value="Sixth">Sixth</option>');
}else{
if(year =="Fourth"){
$("#attendancesem").html('<option value="default" selected>Select Semester</option><option value="Seventh">Seventh</option><option value="Eighth">Eighth</option>');
}
}
}
}
});
$("#attendancebranch").on("change",function(){
var branch = $("#attendancebranch").val();
var year =$("#attendanceyear").val();
var sem =$("#attendancesem").val();
var dataString = 'action=selectinput&'+'year='+year+'&branch='+branch+'&sem='+sem;
// console.log(dataString);
$.ajax({
type:"POST",
url:"ajax.php",
data : dataString,
success : function(result){
// console.log(result);
$("#attendancesubject").html(result);
}
});
});
$("#attendancebutton").click(function(){
var year = $("#attendanceyear").val();
var sem = $("#attendancesem").val();
var branch =$("#attendancebranch").val();
var subject =$("#attendancesubject").val();
if (year == "default" || sem == "default" || branch =="default" || subject =="default") {
$("#attendanceerror").html('<p class="text-danger">Select appropiate option</p>');
window.setTimeout(givedealy,2000);
function givedealy(){
$("#attendanceerror").html('');
}
return;
}
$("#markattendancemodaltitle").html(branch+' '+year+' Year');
var dataString = 'action=attendance&' + $("#facultypageform").serialize();
// console.log(dataString);
$.ajax({
type:"POST",
url:"ajax.php",
data:dataString,
success:function(result){
$("#markattendancemodal").modal('show');
$("#getstudentsrollno").html(result);
}
});
});
$("#addmarksbutton").click(function(){
var year = $("#attendanceyear").val();
var sem = $("#attendancesem").val();
var branch =$("#attendancebranch").val();
var subject =$("#attendancesubject").val();
if (year == "default" || sem == "default" || branch =="default" || subject =="default") {
$("#attendanceerror").html('<p class="text-danger">Select appropiate option</p>');
window.setTimeout(givedealy,2000);
function givedealy(){
$("#attendanceerror").html('');
}
return;
}
$("#addmarksmodaltitle").html(branch+' '+year+' Year '+subject+' marks');
var dataString = 'action=addmarks&' + $("#facultypageform").serialize();
$.ajax({
type:"POST",
url:"ajax.php",
data:dataString,
success:function(result){
$("#addmarksmodal").modal('show');
$("#addmarksdiv").html(result);
$("#savemarks").val(subject);
}
});
});
$('#viewattendancebutton').click(function(){
var year = $('#recordyear').val();
var branch =$("#recordbranch").val();
if (year == 'default' || branch =='default') {
$('#viewrecorderror').html('<br><p class="text-danger">Selcet appropiate option</p>');
window.setTimeout(givedealy, 2000);
function givedealy(){
$('#viewrecorderror').html('');
}
return;
}else{
var action="getsubjects";
$.ajax({
type:"POST",
url:"ajax.php",
data:{action:action,year:year,branch:branch},
success:function(result){
$("#subselect").html(result);
}
});
}
var action="showattendance";
$.ajax({
type:"POST",
url:"ajax.php",
data:{action:action,year:year,branch:branch},
success:function(result){
$('#attendancemodal').modal('show');
$("#attendancedatadiv").html(result);
$("#filteryear").val(year);
$("#filterbranch").val(branch);
document.getElementById('viewrecordform').reset();
}
});
});
$("#subselect").on("change",function(){
var branch = $("#subfilterbranch").val();
var year =$("#subfilteryear").val();
var subject =$("#subselect").val();
if (subject=='default' ) {
var action="showmarks";
var action="showattendance";
$.ajax({
type:"POST",
url:"ajax.php",
data:{action:action,year:year,branch:branch},
success:function(result){
$('#attendancemodal').modal('show');
$("#attendancedatadiv").html(result);
}
});
}
var action ="thissubject";
$.ajax({
type:"POST",
url:"ajax.php",
data:{action:action,branch:branch,year:year,subject:subject},
success:function(result){
$("#attendancedatadiv").html(result);
}
});
});
$("#viewmarksbutton").click(function(){
var year = $('#recordyear').val();
var branch =$("#recordbranch").val();
if (year == 'default' || branch =='default') {
$('#viewrecorderror').html('<br><p class="text-danger">Selcet appropiate option</p>');
window.setTimeout(givedealy, 2000);
function givedealy(){
$('#viewrecorderror').html('');
}
return;
}else{
$('#marksmodal').modal('show');
var action="getsubjects";
$.ajax({
type:"POST",
url:"ajax.php",
data:{action:action,year:year,branch:branch},
success:function(result){
$("#sbjectselect").html(result);
// console.log(result);
}
});
}
var action="showmarks";
$.ajax({
type:"POST",
url:"ajax.php",
data:{action:action,year:year,branch:branch},
success:function(result){
$("#marksdiv").html(result);
document.getElementById('viewrecordform').reset();
}
});
});
$("#sbjectselect").on("change",function(){
var branch= $("#branchmarks").val();
var year =$("#yearmarks").val();
var subject = $("#sbjectselect").val();
var action ="showthismuch";
$.ajax({
type:"POST",
url:"ajax.php",
data:{action:action,branch:branch,year:year,subject:subject},
success:function(result){
$("#marksdiv").html(result);
}
});
});
$("#filterbutton").click(function(){
var firstdate = $("#firstdate").val();
var lastdate = $("#seconddate").val();
var threshold = $("#percent").val();
var filterform= $("#filterform");
var dataString ="action=filter&" + $("#filterform").serialize();
if(!filterform[0].checkValidity()){
filterform[0].reportValidity();
return;
}
$.ajax({
type:"POST",
url:"ajax.php",
data:dataString,
success:function(result){
$("#attendancedatadiv").html(result);
}
});
});
$("#feedsubmit").click(function(){
var feedform= $("#feedbackform");
if(!feedform[0].checkValidity()){
feedform[0].reportValidity();
return;
}
var feedback ="action=feedback&"+ $("#feedbackform").serialize();
$.ajax({
type:"POST",
url:"ajax.php",
data: feedback,
success:function(result){
alert(result);
document.getElementById("feedbackform").reset();
}
});
});
$("#saveattendance").click(function(){
var rollno= [];
var absent =[];
$(':checkbox:checked').each(function(i){
rollno[i]=$(this).val();
});
$("input:checkbox:not(:checked)").each(function(j){
absent[j]=$(this).val();
});
// console.log(absent);
var action="saveattendance";
// var attendancevalue=$("#submitattendance").serialize();
// console.log(rollno+attendancevalue);
var subjectcodeattendance =$("#subjectcodeattendance").val();
var yearattendance =$("#yearattendance").val();
var semattendance = $("#semattendance").val();
var branchattendance =$("#branchattendance").val();
var dateattendance = $("#dateattendance").val();
$.ajax({
type:"POST",
url:"ajax.php",
data:{action:action,absent:absent,rollno:rollno,subjectcodeattendance:subjectcodeattendance,yearattendance:yearattendance,semattendance:semattendance,branchattendance:branchattendance,dateattendance:dateattendance},
success:function(result){
$("#getstudentsrollno").html("<p>Thank you for submiting attendance</p>");
window.setTimeout(givedealy, 2000);
function givedealy(){
$("#markattendancemodal").modal("toggle");
document.getElementById('facultypageform').reset();
}
}
});
});
$("#savemarks").click(function(){
var subject = $("#savemarks").val();
var branch = $("#marksbranch").val();
var year =$("#marksyear").val();
var whattodo = document.getElementsByName('dothis')[0].value;
// console.log(whattodo);
var ctonemarks=[];
var cttwomarks=[];
var assignmarks=[];
var rollno=[];
// console.log(subject);
$("input[name='ctonemarks']").each(function(){
ctonemarks.push($(this).val());
});
$("input[name='cttwomarks']").each(function(){
cttwomarks.push($(this).val());
});
$("input[name='assignmarks']").each(function(){
assignmarks.push($(this).val());
});
$("input[name='rollno']").each(function(){
rollno.push($(this).val());
});
var action ="savemarks";
$.ajax({
type:"POST",
url:"ajax.php",
data:{action:action,cttwomarks:cttwomarks,ctonemarks:ctonemarks,assignmarks:assignmarks,subject:subject,rollno:rollno,branch:branch,year:year,whattodo:whattodo},
success:function(result){
$("#addmarksdiv").html('<p class="text-success">Records have been updated successfully</p>');
window.setTimeout(givedealy,2000);
function givedealy(){
$("#addmarksmodal").modal("toggle");
document.getElementById('facultypageform').reset();
}
}
});
});
$(".reply").click(function(){
console.log("text");
var msgid = $(this).val();
var action = "getfeedbackdata";
$.ajax({
type:"POST",
url:"ajax.php",
data:{action:action,msgid:msgid},
success:function(result){
var data=result.split(",");
$("#adminsettings").modal("toggle");
$("#replymodal").modal("show");
$("#sendersubject").val(data[1]);
$("#senderemail").val(data[0]);
$("#sendername").val(data[2]);
$("#msgid").val(data[3]);
// console.log(data[3]);
}
});
});
$("#reply").click(function(){
var replyform = $("#replyform");
if (!replyform[0].checkValidity()) {
replyform[0].reportValidity();
return;
}
var dataString = 'action=sendrply&' + $("#replyform").serialize();
console.log(dataString);
$.ajax({
type:"POST",
url:"ajax.php",
data:dataString,
success:function(result){
$("#replymodalmsg").html(result);
document.getElementById('replyform').reset();
getfeedback();
}
});
});
function getfeedback(){
var action = "showmsgs";
$.ajax({
type:"POST",
url:"ajax.php",
data: {action:action},
success:function(result){
// console.log(result);
document.getElementById("feedbacks").innerHTML=result;
}
});
}
$("#recoverpass").click(function(){
var passform =$("#passwordrecoveryform");
if (!passform[0].checkValidity()) {
passform[0].reportValidity();
return;
}
var dataString = 'action=recoverpass&' + $("#passwordrecoveryform").serialize();
$.ajax({
type:"POST",
url:"ajax.php",
data:dataString,
success:function(result){
$("#passwordrecoveryerror").html(result);
}
});
});
$("#changeadminpass").click(function(){
var changepassform =$("#changeadminpassform");
if (!changepassform[0].checkValidity()) {
changepassform[0].reportValidity();
return;
}
var dataString = 'action=changeadminpassword&' + $("#changeadminpassform").serialize();
$.ajax({
type: "POST",
url:"ajax.php",
data:dataString,
success:function(result) {
$("#adminchangepassmsg").html(result);
document.getElementById('changeadminpassform').reset();
window.setTimeout(givedealy,2000);
function givedealy(){
$('#adminchangepassmsg').html('');
}
}
});
});
$("#changefacultypass").click(function(){
var changepassform =$("#changefacultypassform");
if (!changepassform[0].checkValidity()) {
changepassform[0].reportValidity();
return;
}
var dataString = 'action=changefacultypassword&' + $("#changefacultypassform").serialize();
$.ajax({
type: "POST",
url:"ajax.php",
data:dataString,
success:function(result) {
$("#facultychangepassmsg").html(result);
document.getElementById('changefacultypassform').reset();
window.setTimeout(givedealy,2000);
function givedealy(){
$('#facultychangepassmsg').html('');
}
}
});
});
$("#endofsession").click(function(){
var action ="endofsession";
if (confirm("Are you sure !!")) {
$.ajax({
type:"POST",
url:"ajax.php",
data:{action:action},
success:function(result){
$("#adminchangepassmsg").html(result);
window.setTimeout(givedealy,2000);
function givedealy(){
$("#adminchangepassmsg").html('');
$("#adminsettings").modal("toggle");
}
}
});
} else {
$("#adminsettings").modal("toggle");
}
});
$("#updatepass").click(function(){
var newpassword =$("#newpass").val();
var oldpassword =$("#confrmpass").val();
var recoverform =$("#changerecoverform");
if (!recoverform[0].checkValidity()) {
recoverform[0].reportValidity();
return;
}
if (newpassword===oldpassword) {
var dataString = 'action=recover&' + $("#changerecoverform").serialize();
$.ajax({
type:"POST",
url:"ajax.php",
data:dataString,
success:function(result){
$("#recoverpageerror").html(result);
window.setTimeout(givedealy,2000);
function givedealy(){
$("#recoverpageerror").html('');
document.getElementById('changerecoverform').reset();
}
}
});
}else{
$("#recoverpageerror").html('<p class="text-danger">Please write the same password in both the fields</p>');
window.setTimeout(givedealy,2000);
function givedealy(){
$("#recoverpageerror").html('');
document.getElementById('changerecoverform').reset();
}
}
});
$("#printstatus").click(function(){
printElement(document.getElementById("attendancediv"));
});
$("#printmarksstatus").click(function () {
printElement(document.getElementById("marksdiv"));
});
});