-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexamflow_asynchronous.php
1149 lines (917 loc) · 40.6 KB
/
examflow_asynchronous.php
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
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
include_once 'examflow_classes.php';
#Begin creating a new exam by the examiner
if (isset($_POST['saveExam'])) {
if (empty($_POST['examTitle'])) {
$message1 = "<div class='alert alert-danger'>Exam title field is required</div>";
$errors[] = $message1;
}
if (empty($_POST['examCode'])) {
$message2 = "<div class='alert alert-danger'>Exam Code field is required</div>";
$errors[] = $message2;
}
if (empty($_POST['examSubject'])) {
$message3 = "<div class='alert alert-danger'>Exam Subject field is required</div>";
$errors[] = $message3;
}
if (isset($errors)) {
foreach ($errors as $key => $value) {
echo $value;
}
}
if (empty($errors)) {
$exam_code = strtoupper($_POST['examCode']);
$exam_title = ucwords(strtolower(trim($_POST['examTitle'])),' ');
$examiner_id = $_POST['examinerId'];
$exam_subject = $_POST['examSubject'];
//Instantiating object of class Examination for createNewExamination method
$objectCreateExamination = new Examination();
$output = $objectCreateExamination->createNewExamination($exam_code, $exam_title, $examiner_id, $exam_subject);
echo $output;
}
}
#End creating a new exam by the examiner
#Begin creating of new subject by admin
if (isset($_POST['subjectBtn'])) {
if (empty($_POST['subject'])) {
echo "<div class='alert alert-danger'>Field must not be empty to add a new subject</div>";
}else{
$subject_name = ucwords(strtolower(trim($_POST['subject'])), ' ');
//Instantiating object of class Subject for createNewSubject method
$objectAddSubject = new Subjects();
$output = $objectAddSubject->addNewSubject($subject_name);
echo $output;
}
}
#End creating a new subject by the by admin
#Begin Fetching all the subject to a table
if (isset($_POST['getSubjects'])) {
//Instantiating object of class Subject for createNewSubject method
$objectGetSubject = new Subjects();
$output = $objectGetSubject->getAllSubjects();
$getSubjects = '';
if (is_array($output)) {
$getSubjects .= "<table class='table table-hover table-striped table-light table-bordered'><thead class='bg-secondary text-light'><tr><th>S/N</th><th>Registered Examination Subject</th><th>Registration Date</th></tr></thead><tbody>";
foreach($output as $key => $value) {
$getSubjects .= "<tr><td>".++$key."</td><td>".$value['subject_name']."</td><td>".$value['subject_created_at']."</td>";
$getSubjects .= "</tr>";
}
$getSubjects .= "</tbody></table>";
echo $getSubjects;
}else{
echo $output;
}
}
#End Fetching all the subject to a table
#Begin searching for subject
if (isset($_POST['subjectSearch'])) {
$subject_name = $_POST['subjectSearch'];
//Istantiating object of class Subject for createNewSubject method
$objectGetSubject = new Subjects();
$output = $objectGetSubject->getSubjects();
if (is_array($output)) {
$subjects = '';
foreach ($output as $key => $value) {
$subjects .= "<option value = '".$value['subject_name']."'>";
$subjects .= $value['subject_name']."</option>";
}
echo $subjects;
}else{
echo $output;
}
}
#End searching for subject
#Begin fetching of all exams by examiner for update
if (isset($_POST['outputExam'])) {
$examinerId = $_POST['examinerId'];
//Istantiating object of class Examinations for getAllExamination method
$objectGetSubject = new Examination();
$output = $objectGetSubject->getAllExamination($examinerId);
$examination = '';
if (is_array($output)) {
$examination .= "<table class='table table-hover table-striped table-light table-bordered'><thead class='bg-secondary text-light'><tr><th>S/N</th><th>Examination code</th><th>Examination Title</th><th>Examination Subject</th><th>Action</th></tr></thead><tbody>";
foreach($output as $key => $value) {
$examination .= "<tr><td>".++$key."</td><td>".$value['exam_code']."</td><td>".$value['exam_title']."</td><td>".$value['subject_name']."</td><td>";
$examination .= "<a href='examflow_addquestion.php?";
$examination .= "exam_id=".$value['exam_id'];
$examination .= "' class='btn btn-primary btn-sm mt-1' id='addQuestion'>Add Questions</a> <a href='examflow_preview_exam.php?";
$examination .= "exam_title=".$value['exam_title']."&exam_id=".$value['exam_id'];
$examination .= "' class='btn btn-dark btn-sm mt-1' id='previewExamination'>Preview Exam</a> ";
$examination .= "<a href='examflow_update_exam.php?";
$examination .= "exam_title=".$value['exam_title']."&exam_code=".$value['exam_code']."&exam_subject=".$value['subject_name']."&exam_id=".$value['exam_id'];
$examination .= "'";
$examination .= " class='btn btn-info btn-sm mt-1' id='updateExamination'>Update</a>";
$examination .= " <a class='btn btn-danger btn-sm mt-1' id='deleteExamination' data-id='".$value['exam_id']."'>Delete</a></td></tr>";
}
$examination .= "</tbody></table>";
echo $examination;
}else{
echo $output;
}
}
#End fetching of all exams by examiner for update
#Begin Deleting an exams by examiner.
if (isset($_POST['deleteExamination'])) {
$exam_id = $_POST['exam_id'];
//Instantiating object of class Examinations for getAllExamination method
$objdeleteExamination = new Examination;
$output = $objdeleteExamination->deleteExamination($exam_id);
echo $output;
}
#End Deleting an exams by examiner.
#Begin fetching of all exams by examiner for update
if (isset($_POST['allExams'])) {
$examinerId = $_POST['examinerId'];
//Instantiating object of class Examinations for getAllExamination method
$objectGetSubject = new Examination();
$output = $objectGetSubject->getAllExaminationsByExaminer($examinerId);
$allExaminations = '';
if (is_array($output)) {
$allExaminations .= "<table class='table table-hover table-striped table-light table-bordered'><thead class='bg-secondary text-light'><tr><th>S/N</th><th>Examination code</th><th>Examination Title</th><th>Examination Subject</th><th>Start Time</th><th>End Time</th><th>Action</th></tr></thead><tbody>";
foreach($output as $key => $value) {
$allExaminations .= "<tr><td>".++$key."</td><td>".$value['exam_code']."</td><td>".$value['exam_title']."</td><td>".$value['subject_name']."</td>";
$allExaminations .= "<td>".$value['exam_start_time']."</td><td>".$value['exam_end_time']."</td><td><a href='#' data-id='".$value['exam_id']."' class='btn btn-dark btn-sm' id='viewMoreDetails' data-toggle='modal' data-target='#viewMoreDetailsModal'>More Details</a></td></tr>";
}
$allExaminations .= "</tbody></table>";
echo $allExaminations;
}else{
echo $output;
}
}
#End fetching of all exams by examiner for update
#Begin fetching of all exams for student registration
if (isset($_POST['registerStudentTable'])) {
$examinerId = $_POST['examinerId'];
//Instantiating object of class Examinations for getAllExamination method
$objectGetSubject = new Examination();
$output = $objectGetSubject->getAllExaminationForStudentRegistration($examinerId);
$examination = '';
if (is_array($output)) {
$examination .= "<table class='table table-hover table-striped table-light table-bordered'><thead class='bg-secondary text-light'><tr><th>S/N</th><th>Examination code</th><th>Examination Title</th><th>Examination Subject</th><th>Action</th></tr></thead><tbody>";
foreach($output as $key => $value) {
$examination .= "<tr><td>".++$key."</td><td data-id='exam_code'>".$value['exam_code']."</td><td>".$value['exam_title']."</td><td>".$value['subject_name']."</td><td>";
$examination .= "<a href='#'";
$examination .="data-id='".$value['exam_id']."' data-title='".$value['exam_title']."' data-code='".$value['exam_code']."' data-subject='exam_subject=".$value['subject_name'];
$examination .="' class='btn btn-primary btn-sm' id='getRegistrationForm".$value['exam_id'];
$examination .= "'>Register Student</a> <a href='#' class='btn btn-warning btn-sm' data-id='";
$examination .= $value['exam_id'];
$examination .="' data-toggle='modal' data-target='#listRegisteredStudentsModal' id='listRegisteredStudentsBtn'>List students</a></td></tr>";
}
$examination .= "</tbody></table>";
echo $examination;
}else{
echo $output;
}
}
#End fetching of all exams for student registration.
# Begin student registration
if (isset($_POST['getRegistrationForm'])) {
$exam_code = $_POST['exam_code'];
$exam_id = $_POST['exam_id'];
$exam_title = $_POST['exam_title'];
$getStudentRegistered = '';
$getStudentRegistered .= "<form method='post' name='registerStudent' id='studentRegistrationForm'><div class='row form-group'><div class='col'><label>Exam title / header</label><input type='text' name='examTitle'";
$getStudentRegistered .= "value='".$exam_title;
$getStudentRegistered .= "' class='form-control' placeholder='Human Anatomy' value='' disabled></div><div class='col'><label>Exam code</label><input type='text' name='examCode'";
$getStudentRegistered .= "value='".$exam_code;
$getStudentRegistered .= "' class='form-control' placeholder='ANA208' disabled></div></div>";
$getStudentRegistered .= "<div class='row form-group'><div class='col'><label>Student email</label><input type='text' name='studentEmail' class='form-control' placeholder='[email protected]' id='studentEmail'></div><div class='col'><label>Student name</label><input type='text' name='studentName' class='form-control' placeholder='Danladi Bako' id='studentName'></div></div><div class='row form-group'><input type='button' id='registerStudent' class='ml-3 btn btn-info btn-sm' value='Register'><input type='hidden' name='exam_id'";
$getStudentRegistered .= "value='".$exam_id;
$getStudentRegistered .= "'><input type='hidden' name='exam_title'";
$getStudentRegistered .= "value='".$exam_title;
$getStudentRegistered .="'><input type='hidden' name='registerStudentForm'></div><div id='registrationOutput'></div></form><input type='hidden' name='getStudentName'>";
echo $getStudentRegistered;
}
# End student registration form
# Begin fetch student name when registering student
if (isset($_POST['getStudentName'])) {
$student_email = $_POST['studentEmail'];
//Instantiating object of class Examination for
$objectgetStudentNam = new Examination();
$output = $objectgetStudentNam->getStudentName($student_email);
if (is_array($output)) {
foreach ($output as $key => $value) {
echo $value[0];
}
}else{
echo $output;
}
}
# End to fetch student name when registering email
# Begin registration of student to database
if (isset($_POST['registerStudentForm'])) {
//Validate the form
if (empty($_POST['studentEmail']) || empty($_POST['studentName'])) {
echo "<div class='alert alert-danger'>Both fields are required for registration</div>";
}else{
$studentEmail = $_POST['studentEmail'];
$studentName = $_POST['studentName'];
$exam_title = $_POST['exam_title'];
$exam_id = $_POST['exam_id'];
//Instantiating object of class Examination for
$object = new Examination;
$output = $object->registerStudent($studentEmail, $studentName, $exam_id, $exam_title);
echo $output;
}
}
# End registration of student to database
# Begin list of registered student
if (isset($_POST['listStudents'])) {
$exam_id = $_POST['exam_id'];
//Instantiating object of class Examinations for getAllExamination method
$objectListOfRegisteredStudents = new Examination();
$output = $objectListOfRegisteredStudents->getAllRegisteredStudent($exam_id);
/*echo "<pre>";
var_dump($output);
echo "</pre>";*/
$listStudents = '';
if (is_array($output)) {
$listStudents .= "<table class='table table-hover table-striped table-light table-bordered'><thead class='bg-secondary text-light'><tr><th>S/N</th><th>Student Name</th><th>Registration Date</th><th>Action</th></tr></thead><tbody>";
foreach($output as $key => $value) {
$listStudents .= "<tr><td>".++$key."</td><td>".$value['student_lname']." ".$value['student_fname']."</td><td>".$value['registered_at']."</td><td>";
$listStudents .= "<a href='#' class='btn btn-danger btn-sm' data-id='";
$listStudents .= $value['exam_id'];
$listStudents .="' data-toggle='modal' id='listRegisteredStudentsBtn'>Delete Student</a></td></tr>";
}
$listStudents .= "</tbody></table>";
echo $listStudents;
}else{
echo $output;
}
}
# End list of registered student
# Begin Adding new question to database
if (isset($_POST['addQuestion'])) {
/*echo "<pre>";
var_dump($_POST);
echo "</pre>";*/
if ($_POST['questionType'] == 'Objective Question' ) {
//Validation for Objective Question Form
if (empty($_POST['instruction']) || empty($_POST['question'])) {
$message1 = "<div class='alert alert-danger'>Instruction and Question fields are required for a new question to be saved</div>";
$errorObj[] = $message1;
}
foreach ($_POST["objOption"] as $key => $value) {
if (empty($value)){
$message = "<div class='alert alert-danger'>All Option fields are required</div>";
$errorObj[] = $message;
}
}
if (empty($_POST['questionMarkObj'])) {
$message6 = "<div class='alert alert-danger'>Please assign a mark to the question</div>";
$errorObj[] = $message6;
}
if (!isset($_POST['radioOptionObj'])) {
$radioOptionError = "<div class='alert alert-danger'>Please select the correct option with the radio button</div>";
$errorObj[] = $radioOptionError;
}
if (isset($errorObj)) {
foreach ($errorObj as $key => $value){
echo $value; }
}
if (empty($errorObj)) {
//Istantiating object of class Questions for insertQuestion method
$qstObj = new Questions;
$question = $qstObj->sanitizeInputs($_POST['question']);
$question_mark = $_POST["questionMarkObj"];
$question_type_name = $_POST["questionType"];
$exam_id = $_POST["exam_id"];
$instruction = $qstObj->sanitizeInputs($_POST["instruction"]);
$option_name = $_POST["objOption"];
$option_correct = $_POST['radioOptionObj'];
// calling a function of class class Questions
$output = $qstObj->insertQuestion($question, $question_mark, $question_type_name, $exam_id, $instruction, $option_name, $option_correct);
if (is_array($output)) {
foreach ($output as $key => $value) {
echo $value;
}
}else{
echo $output;
}
}
}elseif($_POST['questionType'] == 'Multichoice Question') {
//Validation for Multichoice Question Form
if (empty($_POST['instruction']) || empty($_POST['question'])) {
$message1 = "<div class='alert alert-danger'>Instruction and Question fields are required for a new question to be saved</div>";
$errorMcq[] = $message1;
}
foreach ($_POST["mcqOption"] as $key => $value) {
if (empty($value)){
$message = "<div class='alert alert-danger'>All Option fields are required</div>";
$errorMcq[] = $message;
}
}
if (empty($_POST['questionMarkMcq'])) {
$message3 = "<div class='alert alert-danger'>Please assign a positive mark to the question</div>";
$errorMcq[] = $message3;
}
if (empty($_POST['negativeQuestionMark'])) {
$message4 = "<div class='alert alert-danger'>Please assign a negative mark to the question</div>";
}
if (!isset($_POST['radioOptionMcq'])) {
$radioOptionError = "<div class='alert alert-danger'>Please select the correct option from the radio button</div>";
$errorMcq[] = $radioOptionError;
}
if (isset($errorMcq)) {
foreach ($errorMcq as $key => $value)
echo $value;
}
if (empty($errorMcq)) {
//Istantiating object of class Questions for insertQuestion method
$qstMcq = new Questions;
$question = $qstMcq->sanitizeInputs($_POST['question']);
$question_mark = $_POST["questionMarkFib"];
$question_type_name = $_POST["questionType"];
$exam_id = $_POST["exam_id"];
$instruction = $qstMcq->sanitizeInputs($_POST["instruction"]);
$option_name = $_POST["mcqOption"];
$option_correct = $_POST['radioOptionMcq'];
// calling a function of class class Questions
$output = $qstMcq->insertQuestion($question, $question_mark, $question_type_name, $exam_id, $instruction, $option_name, $option_correct);
if (is_array($output)) {
foreach ($output as $key => $value) {
echo $value;
}
}else{
echo $output;
}
}
}elseif($_POST['questionType'] == 'Fill in the blank') {
//Validation for Fill in the blank Question Form
if (empty($_POST['instruction']) || empty($_POST['question'])) {
$message1 = "<div class='alert alert-danger'>Instruction and Question fields are required for a new question to be saved</div>";
$errorFib[] = $message1;
}
if (empty($_POST['questionMarkFib'])){
$message2 = "<div class='alert alert-danger'>Please assign a mark to the question</div>";
$errorFib[] = $message2;
}
if (empty($_POST['fillInTheBlankAnswer'])) {
$message3 = "<div class='alert alert-danger'>Please fill in the correct answer in the field</div>";
$errorFib[] = $message3;
}
if (isset($errorFib)) {
foreach ($errorFib as $key => $value)
echo $value;
}
if (empty($errorFib)) {
//Instantiating object of class Questions for insertQuestion method
$qstFib = new Questions;
$question = $qstFib->sanitizeInputs($_POST['question']);
$question_mark = $_POST["questionMarkFib"];
$question_type_name = $_POST["questionType"];
$exam_id = $_POST["exam_id"];
$instruction = $qstFib->sanitizeInputs($_POST["instruction"]);
$option_name = $_POST["fillInTheBlankAnswer"];
$option_name = ucwords(strtolower(trim($option_name)));
$option_correct = 1;
$output = $qstFib->insertQuestion($question, $question_mark, $question_type_name, $exam_id, $instruction, $option_name, $option_correct);
if (is_array($output)) {
foreach ($output as $key => $value) {
echo $value;
}
}else{
echo $output;
}
}
}elseif($_POST['questionType'] == 'Theory Question') {
//Validation for Theory Question Form
if (empty($_POST['instruction']) || empty($_POST['question'])) {
$message1 = "<div class='alert alert-danger'>Instruction and Question fields are required for a new question to be saved</div>";
$errorThe[] = $message1;
}
if (empty($_POST['questionMarkThe'])) {
$message2 = "<div class='alert alert-danger'>Please assign a mark to the question</div>";
$errorThe[] = $message2;
}
if (isset($errorThe)) {
foreach ($errorThe as $key => $value)
echo $value;
}
if (empty($errorThe)) {
//Istantiating object of class Questions for insertQuestion method
$qstThe = new Questions;
$question = $qstThe->sanitizeInputs($_POST['question']);
$question_mark = $_POST["questionMarkThe"];
$question_type_name = $_POST["questionType"];
$exam_id = $_POST["exam_id"];
$instruction = $qstThe->sanitizeInputs($_POST["instruction"]);
$option_name = " ";
$option_correct = " ";
// calling a function of class class Questions
$output = $qstThe->insertQuestion($question, $question_mark, $question_type_name, $exam_id, $instruction, $option_name, $option_correct);
if (is_array($output)) {
foreach ($output as $key => $value) {
echo $value;
}
}else{
echo $output;
}
}
}else{
echo "<div class='alert alert-danger'>Please select a question type</div>";
}
}
#End Adding new qustion to database
#Begin Get all examination done by student for result
if (isset($_POST['studentViewResult'])) {
$student_id = $_POST['student_id'];
//Instantiating object of class Examination for getAllExamsByStudentForResults method
$objResult = new Examination;
$output = $objResult->getAllExamsByStudentForResults($student_id);
$studentExam = '';
if (is_array($output)) {
$studentExam .= "<table class='table table-hover table-striped table-light table-bordered'><thead class='bg-secondary text-light'><tr><th>S/N</th><th>Examination code</th><th>Examination Title</th><th>Examination Subject</th><td>Exam Date</td><th>Action</th></tr></thead><tbody>";
foreach($output as $key => $value) {
$studentExam .= "<tr><td>".++$key."</td><td>".$value['exam_code']."</td><td>".$value['exam_title']."</td><td>".$value['subject_name']."</td><td>".$value['exam_start_time']."</td><td>";
$studentExam .= "<a href='#'";
$studentExam .="data-id='".$value['exam_id']."' data-title='".$value['exam_title']."' data-code='".$value['exam_code']."' data-subject='".$value['subject_name']."' data-student='".$value['student_id']."' data-date='".$value['exam_start_time'];
$studentExam .= "' class='btn btn-primary btn-sm mt-1' id='studentviewResult' data-toggle='modal' data-target='#studentviewResultModal' >View Result</a>";
$studentExam .= "</td></tr>";
}
$studentExam .= "</tbody></table>";
echo $studentExam;
}else{
echo $output;
}
}
#End Get all examination done by student for result
#Begin fetching all examinations student have been registered for
if (isset($_POST['examInfo'])) {
$student_id = $_POST['student_id'];
//Instantiating object of class Examination for getExamInfoForStudent method
$objExamInfo = new Examination;
$output = $objExamInfo->getExamInfoForStudent($student_id);
$studentExamInfo = '';
if (is_array($output)) {
$studentExamInfo .= "<table class='table table-hover table-striped table-light table-bordered'><thead class='bg-secondary text-light'><tr><th>S/N</th><th>Examination code</th><th>Examination Title</th><th>Examination Subject</th><th>Start Time</th><th>End Time</th><th>Action</th></tr></thead><tbody>";
foreach($output as $key => $value) {
$studentExamInfo .= "<tr><td>".++$key."</td><td>".$value['exam_code']."</td><td>".$value['exam_title']."</td><td>".$value['subject_name']."</td>";
$studentExamInfo .= "<td>".$value['exam_start_time']."</td>";
$studentExamInfo .= "<td>".$value['exam_end_time']."</td>";
$studentExamInfo .= "<td><a href='#' class='btn btn-info btn-sm' data-student='".$student_id."' data-exam='".$value['exam_id']."' data-toggle='modal' data-target='#examPasscodeModal' id='studentViewPasscode'>View Passcode</a></td></tr>";
}
$studentExamInfo .= "</tbody></table>";
echo $studentExamInfo;
}else{
echo $output;
}
}
#End fetching all examinations student have been registered for
#Begin View Result by Student
if (isset($_POST['studentViewResultBtn'])) {
$exam_code = $_POST['exam_code'];
$exam_id = $_POST['exam_id'];
$exam_title = $_POST['exam_title'];
$student_id = $_POST['student_id'];
$exam_date = $_POST['exam_date'];
//Instantiating object of class Examination for getAllExamsByStudentForResults method
$objViewResult = new Examination;
$output = $objViewResult->studentViewResult($student_id, $exam_id);
/*echo "<pre>";
print_r($output);
echo "</pre>";*/
if (is_array($output)) {
//Calling getExamTotalMark method of class Examination
$output2 = $objViewResult->getExamTotalMark($exam_id);
foreach ($output2 as $key => $value) {
$totalScore = $value['totalMark'];
}
$score = array();
foreach ($output as $key => $value) {
if ($value['option_name'] == $value['student_answers'] AND $value['option_correct'] == 1 ) {
$score[] = $value['question_mark'];
//echo $value['question_mark']."<br>";
//echo $key."<br>";
}
}
$studentScore = array_sum($score);
echo "<div class='alert alert-info'>Your scored ".$studentScore." out of ".$totalScore." in ".$exam_title." that took place on ".$exam_date."</div>";
}else{
echo "<div class='alert alert-info'>You were Absent this examination.</div>";
}
/**/
}
#End View result by Student
#Begin view examination list to see exam result for examiner
if (isset($_POST['examinerViewResult'])) {
$examiner_id = $_POST['examinerId'];
//Instantiating object of class Examination for getAllExamsByExaminerForResults method
$objResult = new Examination;
$output = $objResult->getAllExamsByExaminerForResults($examiner_id);
$examinerExam = '';
if (is_array($output)) {
$examinerExam .= "<table class='table table-hover table-striped table-light table-bordered'><thead class='bg-secondary text-light'><tr><th>S/N</th><th>Examination code</th><th>Examination Title</th><th>Examination Subject</th><th>Exam Date</th><th>Action</th></tr></thead><tbody>";
foreach($output as $key => $value) {
$examinerExam .= "<tr><td>".++$key."</td><td data-id='exam_code'>".$value['exam_code']."</td><td>".$value['exam_title']."</td><td>".$value['subject_name']."</td><td>".$value['exam_start_time']."</td><td>";
$examinerExam .= "<a href='examflow_examiner_view_student_result.php?exam_id=";
$examinerExam .=$value['exam_id']."&exam_title=".$value['exam_title']."&exam_code=".$value['exam_code']."&exam_subject=".$value['subject_name']."'";
$examinerExam .= "' class='btn btn-primary btn-sm mt-1' id='examinerViewResult' >View Result</a>";
$examinerExam .="</td></tr>";
}
$examinerExam .= "</tbody></table>";
echo $examinerExam;
}else{
echo $output;
}
}
#End view examination list to see exam result for examiner
#Begin View Result by Examiner
if (isset($_POST['examinerViewResultPage'])) {
//echo "I got here";
$exam_id = $_POST['exam_id'];
$student_id = $_POST['student_id'];
$exam_title = $_POST['exam_title'];
$student_name = $_POST['student_name'];
//Instantiating object of class Examination for examinerViewResult method but the method used here is the student method because i am too lazy to do another one for the examiner afterall they are exactly the same thing
$objViewStudentResult = new Examination;
$output = $objViewStudentResult->studentViewResult($student_id, $exam_id);
/*echo "<pre>";
print_r($output);
echo "</pre>";*/
//echo "I got here";
if (is_array($output)) {
//Calling getExamTotalMark method of class Examination
$output2 = $objViewStudentResult->getExamTotalMark($exam_id);
foreach ($output2 as $key => $value) {
$totalScore = $value['totalMark'];
}
$score = array();
foreach ($output as $key => $value) {
if ($value['option_name'] == $value['student_answers'] AND $value['option_correct'] == 1 ) {
$score[] = $value['question_mark'];
//echo $value['question_mark']."<br>";
//echo $key."<br>";
}
}
$studentScore = array_sum($score);
echo "<div class='alert alert-info'>".$student_name." scored ".$studentScore." out of ".$totalScore." in ".$exam_title." exam</div>";
}else{
echo "<div class='alert alert-info'>".$student_name." was absent for ".$exam_title." examination</div>";
}
}
#End View Result by Examiner
#Begin fetching all examinations for admin view
if (isset($_POST['adminViewExam'])) {
//Instantiating object of class Examination for examinerViewResult method
$objResult = new Examination;
$output = $objResult->getAllExamForAdmin();
$adminViewExam = '';
if (is_array($output)) {
$adminViewExam .= "<table class='table table-hover table-striped table-light table-bordered'><thead class='bg-secondary text-light'><tr><th>S/N</th><th>Examination code</th><th>Examination Title</th><th>Examiner Name</th><th>Examination Subject</th><th>Start Time</th><th>End Time</th></tr></thead><tbody>";
foreach($output as $key => $value) {
$adminViewExam .= "<tr><td>".++$key."</td><td>".$value['exam_code']."</td><td>".$value['exam_title']."</td><td>".$value['examiner_lname']." ".$value['examiner_fname']."</td><td>".$value['subject_name']."</td>";
$adminViewExam .= "<td>".$value['exam_start_time']."</td><td>".$value['exam_end_time']."</td></tr>";
}
$adminViewExam .= "</tbody></table>";
echo $adminViewExam;
}else{
echo $output;
}
}
#End fetching all examinations for admin view
#Begin view examination list to see exam result for admin
if (isset($_POST['adminViewResult'])) {
//Instantiating object of class Examination for examinerViewResult method
$objResult = new Examination;
$output = $objResult->getAllExamForAdminForViewResult();
$adminViewResult = '';
if (is_array($output)) {
$adminViewResult .= "<table class='table table-hover table-striped table-light table-bordered'><thead class='bg-secondary text-light'><tr><th>S/N</th><th>Examination code</th><th>Examination Title</th><th>Examination Subject</th><th>Exam Date</th><th>Action</th></tr></thead><tbody>";
foreach($output as $key => $value) {
$adminViewResult .= "<tr><td>".++$key."</td><td>".$value['exam_code']."</td><td>".$value['exam_title']."</td><td>".$value['subject_name']."</td>";
$adminViewResult .= "<td>".$value['exam_start_time']."</td><td><a href='examflow_admin_view_student_result.php?exam_id=";
$adminViewResult .=$value['exam_id']."&exam_title=".$value['exam_title']."&exam_code=".$value['exam_code']."&exam_subject=".$value['subject_name']."'";
$adminViewResult .= "' class='btn btn-secondary btn-sm'>View Result</a></td></tr>";
}
$adminViewResult .= "</tbody></table>";
echo $adminViewResult;
}else{
echo $output;
}
}
#End view examination list to see exam result for admin
#Begin View Student's Result by Admin
if (isset($_POST['adminViewResultPage'])) {
//echo "I got here";
$exam_id = $_POST['exam_id'];
$student_id = $_POST['student_id'];
$exam_title = $_POST['exam_title'];
$student_name = $_POST['student_name'];
//Instantiating object of class Examination for adminViewResult method but the method used here is the student method because i am too lazy to do another one for the examiner afterall they are exactly the same thing
$objViewStudentResult = new Examination;
$output = $objViewStudentResult->studentViewResult($student_id, $exam_id);
/*echo "<pre>";
print_r($output);
echo "</pre>";*/
//echo "I got here";
if (is_array($output)) {
//Calling getExamTotalMark method of class Examination
$output2 = $objViewStudentResult->getExamTotalMark($exam_id);
foreach ($output2 as $key => $value) {
$totalScore = $value['totalMark'];
}
$score = array();
foreach ($output as $key => $value) {
if ($value['option_name'] == $value['student_answers'] AND $value['option_correct'] == 1 ) {
$score[] = $value['question_mark'];
//echo $value['question_mark']."<br>";
//echo $key."<br>";
}
}
$studentScore = array_sum($score);
echo "<div class='alert alert-info'>".$student_name." scored ".$studentScore." out of ".$totalScore." in ".$exam_title." exam</div>";
}else{
echo "<div class='alert alert-info'>Result is yet to be released, please check back in a while</div>";
}
}
#End View Student's Result by Admin
#Begin fetching all examiners for admin view
if (isset($_POST['adminViewExaminers'])) {
//Instantiating object of class Examination for examinerViewResult method
$objResult = new Examination;
$output = $objResult->getAllExaminersForAdmin();
$adminViewExaminers = '';
if (is_array($output)) {
$adminViewExaminers .= "<table class='table table-hover table-striped table-light table-bordered'><thead class='bg-secondary text-light'><tr><th>S/N</th><th>Examiner Name</th><th>Examiner Email</th><th>Phone Number</th></tr></thead><tbody>";
foreach($output as $key => $value) {
$adminViewExaminers .= "<tr><td>".++$key."</td><td>".$value['examiner_lname']." ".$value['examiner_fname']."</td><td>".$value['examiner_email']."</td>";
$adminViewExaminers .= "<td>".$value['examiner_phone']."</td></tr>";
}
$adminViewExaminers .= "</tbody></table>";
echo $adminViewExaminers;
}else{
echo $output;
}
}
#End fetching all examiners for admin view
#Begin fetching all students for admin view
if (isset($_POST['adminViewStudents'])) {
//Instantiating object of class Examination for examinerViewResult method
$objResult = new Examination;
$output = $objResult->getAllStudentsForAdmin();
$adminViewStudents = '';
if (is_array($output)) {
$adminViewStudents .= "<table class='table table-hover table-striped table-light table-bordered'><thead class='bg-secondary text-light'><tr><th>S/N</th><th>Examiner Name</th><th>Examiner Email</th><th>Phone Number</th></tr></thead><tbody>";
foreach($output as $key => $value) {
$adminViewStudents .= "<tr><td>".++$key."</td><td>".$value['student_lname']." ".$value['student_fname']."</td><td>".$value['student_email']."</td>";
$adminViewStudents .= "<td>".$value['student_phone']."</td></tr>";
}
$adminViewStudents .= "</tbody></table>";
echo $adminViewStudents;
}else{
echo $output;
}
}
#End fetching all students for admin view
#Begin add new Admin
if (isset($_POST['newAdmin'])) {
$firstname = ucfirst(strtolower(trim($_POST["adminFname"])));
$lastname = ucfirst(strtolower(trim($_POST["adminLname"])));
$email = strtolower(trim($_POST["adminEmail"]));
$confirm_email = strtolower(trim($_POST["adminCEmail"]));
$password = trim($_POST["adminPassword"]);
$confirm_password = trim($_POST["adminCPassword"]);
$countryCode = trim($_POST["countryCode"]);
$phone = trim($_POST["phone"]);
$phoneNumber = $countryCode.$phone;
$adminType = $_POST['adminType'];
//Validating each field
if (empty($firstname)) {
$message1 = "<div class='alert alert-danger'>Firstname is required</div>";
$errors[] = $message1;
}
if (empty($lastname)) {
$message2 = "<div class='alert alert-danger'>Lastname is required</div>";
$errors[] = $message2;
}
if (empty($email)) {
$message3 = "<div class='alert alert-danger'>Email is required</div>";
$errors[] = $message3;
}
if (empty($confirm_email)) {
$message4 = "<div class='alert alert-danger'>Confirm Email field is required</div>";
$errors[] = $message4;
}
if (empty($password)) {
$message5 = "<div class='alert alert-danger'>Password is required</div>";
$errors[] = $message5;
}
if (empty($confirm_password)) {
$message6 = "<div class='alert alert-danger'>Confirm password field is required</div>";
$errors[] = $message6;
}
if (empty($countryCode)) {
$message8 = "<div class='alert alert-danger'>Country code is required</div>";
$errors[] = $message8;
}
if (empty($phone)) {
$message9 = "<div class='alert alert-danger'>Phone number is required</div>";
$errors[] = $message9;
}
/*echo "<pre>";
var_dump($errors);
echo "</pre>";*/
//checking for mismatch in email and password field
if ($email <> $confirm_email) {
$message10 = "<div class='alert alert-danger'>Both Email and Confirm Email fields must match.</div>";
$errors[] = $message10;
}
if ($password != $confirm_password) {
$message11 = "<div class='alert alert-danger'>Both Password and Confirm Passwords fields must match.</div>";
$errors[] = $message11;
}
if (isset($errors)) {
foreach ($errors as $key => $value) {
echo $value;
}
}
if (empty($errors)) {
//Instantiating object of class User for registerUserAdmin method
$object = new Users;
$output = $object->registerUserAdmin($firstname, $lastname, $email, $password, $phoneNumber, $adminType);
echo $output;
}
}
#End add new Admin
#Begin submission of complain form
if (isset($_POST['complainCheck'])) {
$fullname = $_POST['fullname'];
$email = $_POST['email'];
$complain = $_POST['complain'];
if (!empty($complain)) {
$receiver_address = "[email protected]";
$subject = "Complain";
$message = $complain;
$headers ="From: ".$email;
@mail($receiver_address, $subject, $message, $headers);
echo "<div class='alert alert-info'>Thanks for lodging your complain to Us, Complain successfully sent your will recieve a feedback via your email</div>";
}else{
echo "<div class='alert alert-danger'>An empty message field can't be sent please, fill it appropiately. </div>";
}
}
#End submission of complain form
#Begin view more examination details by examiner
if (isset($_POST['examinerViewMoreDetails'])) {
$exam_id = $_POST['exam_id'];
//Instantiating object of class Examination
$objResult = new Examination;
//Calling totalRegisteredStudent method of class Examination
$output = $objResult->totalRegisteredStudent($exam_id);
if (is_array($output)) {
foreach ($output as $key => $value) {
$totalRegisteredStudent = $value['registeredStudents'];
}
}
//Calling totalNumberOfQuestion method of class Examination
$output2 = $objResult->totalNumberOfQuestion($exam_id);
if (is_array($output2)) {
foreach ($output2 as $key => $value) {
$totalNumberOfQuestion = $value['noOfQuestions'];
}
}
//I can also add the total mark for the examintion here
$viewMoreDetails = '';
$viewMoreDetails .= "<table class='table table-hover table-striped table-light table-bordered'><thead class='bg-secondary text-light'><tr><th>No of Registered Students</th><th>No of Questions</th></tr></thead><tbody>";
$viewMoreDetails .= "<tr><td>". $totalRegisteredStudent ."</td><td>". $totalNumberOfQuestion."</td>";
$viewMoreDetails .= "</tr>";
$viewMoreDetails .= "</tbody></table>";
echo $viewMoreDetails;
}
#End view more examination details by examiner
#Begin student to view thier exam passcode
if (isset($_POST['studentPasscode'])) {
$exam_id = $_POST['exam_id'];
$student_id = $_POST['student_id'];
//Instantiating object of class Examination
$objResult = new Examination;
$output = $objResult->getStudentPasscode($student_id, $exam_id);
if (is_array($output)) {
foreach ($output as $key => $value) {
$studentPasscode = $value['student_exam_passcode'].".".$value['registration_id'];
}
}
echo "<div class='alert alert-info btn-lg'>Your exam passcode for this is : '".$studentPasscode."'</div><div class='alert alert-danger'><ul><li>Do not reveal your examination passcode to anyone</li><li>You can only login once for this examination, please avoid logging in before the examination time else you will be disqualified from writing this examination</li></ul></div>";
}
#End student to view thier exam passcode
#Begin count of examination, question and student for admin dash board display