-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexamflow_classes.php
1432 lines (1216 loc) · 60 KB
/
examflow_classes.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
date_default_timezone_set('Africa/Lagos');
/**********************************************/
/***** Author: Oyekola Toheeb ****************/
/***** Program: examflow Class Definition ****/
/***** Date: August/20/2021 ******************/
/*********************************************/
include_once 'examflow_constants.php';
# Begin Users class definition
class Users{
//member variable
public $dbcon;
//member construct functions/methods
function __construct(){
//connect to database
$this->dbcon = new mysqli(DB_HOST, DB_USERNAME, DB_PASSWORD, DB_DATABASENAME);
if ($this->dbcon->connect_error) {
//logging of error into a file
$connection_errors = 'connection_errors.txt';
$error_msg = "Connection Error of class Users ".$this->dbcon->connect_error."\n";
file_put_contents($connection_errors, $error_msg, FILE_APPEND);
die("Conneciton Failure: the reason for is ".$this->dbcon->connect_error);
}
}
//method for user registration as students
function registerUserStudent($fname, $lname, $email, $password, $phoneNumber){
$pwd = md5(md5($password));
$sql = "INSERT INTO students SET student_fname = '$fname', student_lname = '$lname', student_email = '$email', student_password ='$pwd', student_phone = '$phoneNumber'";
$result = $this->dbcon->query($sql);
if ($this->dbcon->error) {
//logging of error into a file
$registrationFile = 'registration_error.txt';
$error_msg = $this->dbcon->error." for registration ".$fname.' '.$lname." as a student on ".date('l F Y h:i:s A')."."."\n";
file_put_contents($registrationFile, $error_msg, FILE_APPEND);
return "<div class='alert alert-danger'>"."There is an error: ".$this->dbcon->error."</div>";
}else{
$message = "<div class='alert alert-primary'>Registration successful, You will recieve a link in your email for authentication. Click <a href='examflow_login_signup.php?message=login'>here</a> to login </div>";
header("Location: examflow_registration_success.php?msg=$message");
exit;
}
}
//method for student login
function studentLogin($email, $password){
$pwd = md5(md5($password));
$sql = "SELECT * FROM students WHERE student_email ='$email' AND student_password = '$pwd'";
$result = $this->dbcon->query($sql);
if ($this->dbcon->error) {
//logging of error into a file
$loginFile = 'login_error.txt';
$error_msg = $this->dbcon->error." for login of student with email".$email." on ".date('l F Y h:i:s A')."."."\n";
file_put_contents($loginFile, $error_msg, FILE_APPEND);
return "<div class='alert alert-danger'>"."There is an error: ".$this->dbcon->error."</div>";
}elseif($result->num_rows > 0){
$studentData = $result->fetch_assoc();
return $studentData;
}else{
return "<div class='alert alert-danger'>You don't have an account on Examflow as a Student. Please click <a href='examflow_login_signup.php'>here</a> to register.</div>";
}
}
//method for user registration as examiner
function registerUserExaminer($fname, $lname, $email, $password, $phoneNumber){
$pwd = md5(md5($password));
$sql = "INSERT INTO examiners(examiner_fname, examiner_lname, examiner_email, examiner_password, examiner_phone) VALUES('$fname', '$lname', '$email', '$pwd', '$phoneNumber')";
$result = $this->dbcon->query($sql);
if ($this->dbcon->error) {
//logging of error into a file
$registrationFile = 'registration_error.txt';
$error_msg = $this->dbcon->error." for registration of ".$fname.' '.$lname." as an examiner on ".date('l F Y h:i:s A')."."."\n";
file_put_contents($registrationFile, $error_msg, FILE_APPEND);
return "<div class='alert alert-danger'>"."There is an error ".$this->dbcon->error."</div>";
}else{
$message = "<div class='alert alert-primary'>Registration successful, Please check your email you will recieve a link to sign up.</div>";
header("Location: examflow_registration_success.php?msg=$message");
exit;
}
}
//method for examiner login
function examinerLogin($email, $password){
$pwd = md5(md5($password));
$sql = "SELECT * FROM examiners WHERE examiner_email ='$email' AND examiner_password = '$pwd'";
$result = $this->dbcon->query($sql);
if ($this->dbcon->error) {
//logging of error into a file
$loginFile = 'login_error.txt';
$error_msg = $this->dbcon->error." for login of ".$email." as an examiner on ".date('l F Y h:i:s A')."."."\n";
file_put_contents($loginFile, $error_msg, FILE_APPEND);
return "<div class='alert alert-danger'>"."There is an error ".$this->dbcon->error."</div>";
}elseif($result->num_rows > 0){
$examinerData = $result->fetch_assoc();
return $examinerData;
}else{
return "<div class='alert alert-danger'>You don't have an account on Examflow as an Examiner. Please click <a href='examflow_login_signup.php'>here</a> to register.</div>";
}
}
//method for admin creation
function registerUserAdmin($fname, $lname, $email, $password, $phoneNumber, $adminType){
$pwd = md5(md5($password));
$sql = "INSERT INTO admins SET admin_fname = '$fname', admin_lname = '$lname', admin_email = '$email', admin_password ='$pwd', admin_phone = '$phoneNumber', admin_type = (SELECT admin_type_id FROM admin_type WHERE admin_type = '$adminType')";
$result = $this->dbcon->query($sql);
if ($this->dbcon->error) {
//logging of error into a file
$registrationFile = 'admin_reg_error.txt';
$error_msg = $this->dbcon->error." for creation of ".$fname.' '.$lname." as an admin on ".date('l F Y h:i:s A')."."."\n";
file_put_contents($registrationFile, $error_msg, FILE_APPEND);
return "<div class='alert alert-danger'>"."New Admin creation failed, please try again later. ".$this->dbcon->error."</div>";
}else{
$message = "<div class='alert alert-primary'>New Admin successfully created, an authenticaton email will be sent to the new admin.</div>";
exit;
}
}
//method for admin login
function adminLogin($email, $password){
$pwd = md5(md5($password));
$sql = "SELECT * FROM admins WHERE admin_email ='$email' AND admin_password = '$pwd'";
$result = $this->dbcon->query($sql);
if ($this->dbcon->error) {
//logging of error into a file
$loginFile = 'login_error.txt';
$error_msg = $this->dbcon->error." for login of ".$email." as an admin on ".date('l F Y h:i:s A')."."."\n";
file_put_contents($loginFile, $error_msg, FILE_APPEND);
//return "<div class='alert alert-danger'>"."There is an error ".$this->dbcon->error."</div>";
}elseif($result->num_rows > 0){
$adminData = $result->fetch_assoc();
return $adminData;
}else{
return "<div class='alert alert-danger'>You don't have an account as an Admin on Examflow. Please click <a href='examflow_login_signup.php'>here</a> to register as an Examiner or Student.</div>";
}
}
//method to upload profile picture for examiner
function examinerUpdateProfilePicture($filetemp, $file_ext_lowerCase, $examiner_id){
$profilePictureName = rand().time()."."."$file_ext_lowerCase";
$destination = "examflow_profilepictures/".$profilePictureName;
move_uploaded_file($filetemp, $destination);
//update category table based on catid
$sql = "UPDATE examiners SET examiner_image = '$profilePictureName' WHERE examiner_id = '$examiner_id'";
$result = $this->dbcon->query($sql);
if ($this->dbcon->error) {
//logging of error into a file
$profilepicture_upload_errors = 'profilepicture_upload_errors.txt';
$error_msg = "Examiner with id ".$examiner_id." is unable to upload profile picture because ".$this->dbcon->error." on ".date('l F Y h:i:s A')."."."\n";
file_put_contents($profilepicture_upload_errors, $error_msg, FILE_APPEND);
}elseif($this->dbcon->affected_rows == 1) {
$msg = "<div class='alert alert-success'>Profile picture successfully uploaded</div>";
//redirect to listcategory.php page
header("Location: examflow_dashboard_examiner.php?pictureMsg=$msg");
exit;
}else{
return "<div class='alert alert-danger' id='error_msg'>Unable to upload profile picture, please try again later</div>";
}
}
//method to upload profile picture for student
function studentUpdateProfilePicture($filetemp, $file_ext_lowerCase, $student_id){
$profilePictureName = rand().time()."."."$file_ext_lowerCase";
$destination = "examflow_profilepictures/".$profilePictureName;
move_uploaded_file($filetemp, $destination);
//update category table based on catid
$sql = "UPDATE students SET student_image = '$profilePictureName' WHERE student_id = '$student_id'";
$result = $this->dbcon->query($sql);
if ($this->dbcon->error) {
//logging of error into a file
$profilepicture_upload_errors = 'profilepicture_upload_errors.txt';
$error_msg = "Student with id ".$student_id." is unable to upload profile picture because ".$this->dbcon->error." on ".date('l F Y h:i:s A')."."."\n";
file_put_contents($profilepicture_upload_errors, $error_msg, FILE_APPEND);
}elseif($this->dbcon->affected_rows == 1) {
$msg = "<div class='alert alert-success'>Profile picture successfully uploaded</div>";
//redirect to listcategory.php page
header("Location: examflow_dashboard_student.php?pictureMsg=$msg");
exit;
}else{
return "<div class='alert alert-danger'>Unable to upload profile picture, please try again later</div>";
}
}
//method to upload profile picture for admin
function adminUpdateProfilePicture($filetemp, $file_ext_lowerCase, $admin_id){
$profilePictureName = rand().time()."."."$file_ext_lowerCase";
$destination = "examflow_profilepictures/".$profilePictureName;
move_uploaded_file($filetemp, $destination);
//update category table based on catid
$sql = "UPDATE admins SET admin_image = '$profilePictureName' WHERE admin_id = '$admin_id'";
$result = $this->dbcon->query($sql);
if ($this->dbcon->error) {
//logging of error into a file
$profilepicture_upload_errors = 'profilepicture_upload_errors.txt';
$error_msg = "Admin with id ".$admin_id." is unable to upload profile picture because ".$this->dbcon->error." on ".date('l F Y h:i:s A')."."."\n";
file_put_contents($profilepicture_upload_errors, $error_msg, FILE_APPEND);
}elseif($this->dbcon->affected_rows == 1) {
$msg = "<div class='alert alert-success'>Profile picture successfully uploaded</div>";
//redirect to listcategory.php page
header("Location: examflow_dashboard_admin.php?pictureMsg=$msg");
exit;
}else{
return "<div class='alert alert-danger' id='error_msg'>Unable to upload profile picture, please try again later</div>";
}
}
//method for admin to update password
function adminUpdatePassword($admin_id, $password){
$pwd = md5(md5($password));
//write sql
$sql= "UPDATE admins SET admin_password = '$pwd' WHERE admin_id = '$admin_id'";
$result = $this->dbcon->query($sql);
if ($this->dbcon->error) {
//logging of error into a file
$update_password_errors = 'update_password_errors.txt';
$error_msg = "Admin with id ".$admin_id." is unable to upload password because ".$this->dbcon->error." on ".date('l F Y h:i:s A')."."."\n";
file_put_contents($update_password_errors, $error_msg, FILE_APPEND);
}elseif($this->dbcon->affected_rows == 1) {
return "<div class='alert alert-success'> Password successfully uploaded</div>";
}elseif($this->dbcon->affected_rows == 0){
return "<div class='alert alert-info'>No change made</div>";
}else{
return "<div class='alert alert-danger'>Unable to update password, please try again later.</div>";
}
}
//method for examiner to update password
function examinerUpdatePassword($examiner_id, $password){
$pwd = md5(md5($password));
//write sql
$sql= "UPDATE examiners SET examiner_password = '$pwd' WHERE examiner_id = '$examiner_id'";
$result = $this->dbcon->query($sql);
if ($this->dbcon->error) {
//logging of error into a file
$update_password_errors = 'update_password_errors.txt';
$error_msg = "Examiner with id ".$examiner_id." is unable to upload password because ".$this->dbcon->error." on ".date('l F Y h:i:s A')."."."\n";
file_put_contents($update_password_errors, $error_msg, FILE_APPEND);
}elseif($this->dbcon->affected_rows == 1) {
return "<div class='alert alert-success'> Password successfully uploaded</div>";
}elseif($this->dbcon->affected_rows == 0){
return "<div class='alert alert-info'>No change made</div>";
}else{
return "<div class='alert alert-danger'>Unable to update password, please try again later.</div>";
}
}
//method for student to update password
function studentUpdatePassword($student_id, $password){
$pwd = md5(md5($password));
//write sql
$sql= "UPDATE students SET student_password = '$pwd' WHERE student_id = '$student_id'";
$result = $this->dbcon->query($sql);
if ($this->dbcon->error) {
//logging of error into a file
$update_password_errors = 'update_password_errors.txt';
$error_msg = "Studnet with id ".$student_id." is unable to upload password because ".$this->dbcon->error." on ".date('l F Y h:i:s A')."."."\n";
file_put_contents($update_password_errors, $error_msg, FILE_APPEND);
}elseif($this->dbcon->affected_rows == 1) {
return "<div class='alert alert-success'> Password successfully uploaded</div>";
}elseif($this->dbcon->affected_rows == 0){
return "<div class='alert alert-info'>No change made</div>";
}else{
return "<div class='alert alert-danger'>Unable to update password, please try again later.</div>";
}
}
}
# End of Users class definition
# Begin Examination class definition
class Examination{
//member variable
public $dbcon;
public $subject_id;
//member construct functions/methods
function __construct(){
//connect to database
$this->dbcon = new mysqli(DB_HOST, DB_USERNAME, DB_PASSWORD, DB_DATABASENAME);
if ($this->dbcon->connect_error) {
//logging of error into a file
$connection_errors = 'connection_errors.txt';
$error_msg = "Connection Error of class Examination ".$this->dbcon->connect_error." on ".date('l F Y h:i:s A')."."."\n";
file_put_contents($connection_errors, $error_msg, FILE_APPEND);
die("Connection Failure: the reason for is ".$this->dbcon->connect_error);
}
}
//method for new examination creation
function createNewExamination($exam_code, $exam_title, $examiner_id, $subject_name){
//write sql query
$sql = "INSERT INTO examinations SET examiner_id = '$examiner_id', subject_id = (SELECT subject_id FROM subjects WHERE subject_name = '$subject_name'), exam_code = '$exam_code', exam_title = '$exam_title'";
//execute the query
$result = $this->dbcon->query($sql);
if ($this->dbcon->error) {
//logging of error into a file
$examination_creation_errors = 'examination_creation_errors.txt';
$error_msg = "Unable to create new examination because ".$this->dbcon->error." on ".date('l F Y h:i:s A')."."."\n";
file_put_contents($examination_creation_errors, $error_msg, FILE_APPEND);
//return "<div class='alert alert-danger'>Oops! Unable to create new examination. Please try again later.</div>";
}elseif($this->dbcon->affected_rows > 0) {
return "<div class='alert alert-success'> Examination successfully created, check Saved Exams to add questions and update examination</div>";
}else{
return "<div class='alert alert-danger'>Oops! Unable to create new examination. Please try again later.</div>";
}
}
//method to update examination
function updateExamination($exam_start_time, $exam_end_time, $exam_result_date, $exam_instruction, $exam_duration, $exam_id){
//write sql query
$sql = "UPDATE examinations SET exam_start_time = '$exam_start_time', exam_end_time = '$exam_end_time', exam_result_date = '$exam_result_date', exam_instruction = '$exam_instruction', exam_duration = '$exam_duration' WHERE exam_id = '$exam_id'";
//execute sql query
$result = $this->dbcon->query($sql);
if ($this->dbcon->affected_rows == 1) {
$msg = "<div class='alert alert-success'>Examination have been successfully updated.</div>";
//redirect to examiner dashboard page
header("Location: examflow_dashboard_examiner.php?updateMsg=$msg");
}elseif($this->dbcon->affected_rows == 0){
return "Oops! Examination was not updated, Please try again.";
}else{
$examination_creation_errors = 'examination_creation_errors.txt';
$error_msg = "Unable update examination because ".$this->dbcon->error." on ".date('l F Y h:i:s A')."."."\n";
file_put_contents($examination_creation_errors, $error_msg, FILE_APPEND);
return "Could not update examination ".$this->dbcon->error;
}
}
//method for fetch all examination created by an examiner
function registerStudent($student_email, $student_name, $exam_id, $exam_title){
$student_passcode = rand();
$sql = "INSERT INTO registered_students(student_id, exam_id, student_exam_passcode) VALUES((SELECT student_id FROM students WHERE student_email = '$student_email'), (SELECT exam_id FROM examinations WHERE exam_id = '$exam_id'), '$student_passcode')";
$result = $this->dbcon->query($sql);
if ($this->dbcon->error){
//logging of error into a file
$student_registration_errors = 'student_registration_errors.txt';
$error_msg = "Unable to Register student with email ".$student_email ." for examination with exam id ".$exam_id." because ".$this->dbcon->error." on ".date('l F Y h:i:s A')."."."\n";
file_put_contents($student_registration_errors, $error_msg, FILE_APPEND);
return "<div class='alert alert-danger'>Unable to register student, please try again.</div>";
}elseif($this->dbcon->affected_rows > 0) {
return "<div class='alert alert-success'>".$student_name." has been successfully registered for ".$exam_title ." examination</div>";
$registration_id = $this->dbcon->insert_id;
$exampasscode = $student_passcode.".".$registration_id;
$student_email_passcode = $student_passcode.".".$registration_id;
$receiver_address = $student_email;
$subject = "Examination on examflow";
$message = "You have been registered to sit for ".$exam_title." and your examination passcode is ".$exampasscode." Please check your dashboard for the examination date, Wish you all the best. ";
$headers ="From: [email protected]";
mail($receiver_address, $subject, $message, $headers);
}else{
return "<div class='alert alert-info'>No record of student found, please inform student to register on Examflow platform inorder to sit for this examination.</div>";
}
}
//method to fetch student name when registering email
function getStudentName($student_email){
//write sql query
$sql = "SELECT CONCAT(student_lname,' ',student_fname) AS fullname FROM students WHERE student_email = '$student_email'";
//execute the query
$result = $this->dbcon->query($sql);
$rows = array();
if ($this->dbcon->error){
//logging of error into a file
$student_registration_errors = 'student_registration_errors.txt';
$error_msg = "Unable to fetch name of student with email ".$student_email ." because ".$this->dbcon->error." on ".date('l F Y h:i:s A')."."."\n";
file_put_contents($student_registration_errors, $error_msg, FILE_APPEND);
}elseif($this->dbcon->affected_rows > 0) {
return $result->fetch_all();
/*while ($row = $result->fetch_array()) {
$rows[] = $row;
}
return $rows;*/
}else{
return 'No record found';
}
}
//method to fetch student all registered student form an examination
//method for student to login for an examination an examination
function studentExamLogin($student_exam_passcode, $registration_id, $student_email){
$exam_status = 0;
$sql="SELECT students.*, registered_students.*, examinations.* FROM students JOIN registered_students ON students.student_id = registered_students.student_id JOIN examinations ON registered_students.exam_id = examinations.exam_id WHERE student_exam_passcode = '$student_exam_passcode' AND registration_id = '$registration_id' AND exam_status = '$exam_status' AND student_email = (SELECT student_email FROM students WHERE student_email = '$student_email') /*AND exam_start_time <= NOW() AND exam_end_time >= NOW()*/";
$result = $this->dbcon->query($sql);
if ($this->dbcon->error) {
$exam_login_errors = 'exam_login_errors.txt';
$error_msg = "Student with the email '".$student_email."' is unable to login because ".$this->dbcon->error." on ".date('l F Y h:i:s A')."."."\n";
file_put_contents($exam_login_errors, $error_msg, FILE_APPEND);
//return $error_msg;
return "<div class='alert alert-danger'>Oops! Something went wrong, please try to login again.</div>";
}elseif($this->dbcon->affected_rows == 1) {
while ($row = $result->fetch_assoc()) {
$examLoginData[] = $row;
}
return $examLoginData;
}else{
return "<div class='alert alert-danger'><ul>You are not eligible to sit for this examination for one of these reason:<li>Wrong email or exam passcode.</li><li>Exam duration exceeded</li><li>Previously logged in for the examination</li><ul></div>";
}
}
//method to fetch all examination created by an examiner for updating
function getAllExaminationsByExaminer($examiner_id){
//write sql query
$sql = "SELECT examinations.*, subjects.subject_name FROM examinations LEFT JOIN subjects ON examinations.subject_id = subjects.subject_id WHERE examiner_id = (SELECT examiner_id FROM examiners WHERE examiner_id = '$examiner_id') ORDER BY exam_created_at DESC;";
//execute the query
$result = $this->dbcon->query($sql);
$rows = array();
if ($this->dbcon->error) {
$examination_creation_errors = 'examination_creation_errors.txt';
$error_msg = "Unable to get all examinations by examiner with examiner id ".$examiner_id." because ".$this->dbcon->error." on ".date('l F Y h:i:s A')."."."\n";
file_put_contents($examination_creation_errors, $error_msg, FILE_APPEND);
return "<div class='alert alert-danger'>Oops! Something went wrong, please refresh your browser or try again later.</div>";
}elseif($this->dbcon->affected_rows > 0) {
while ($row = $result->fetch_assoc()) {
$rows[] = $row;
/* $rows = $result->fetch_all(MYSQLI_ASSOC);
return $rows;*/
}
return $rows;
}else{
return "<div class='alert alert-danger'>Oops! Something went wrong, unable to fetch data, please refresh your browser or try again later.</div>";
}
}
//method to fetch all examiner for admin viewing
function getAllExaminersForAdmin(){
//write sql query
$sql = "SELECT * FROM examiners ORDER BY examiner_lname DESC;";
//execute the query
$result = $this->dbcon->query($sql);
$rows = array();
if ($this->dbcon->error) {
$examiner_details_errors = 'examiner_details_errors.txt';
$error_msg = "Unable to get all examiner details because ".$this->dbcon->error." on ".date('l F Y h:i:s A')."."."\n";
file_put_contents($examiner_details_errors, $error_msg, FILE_APPEND);
return "<div class='alert alert-danger'>Oops! Something went wrong, please refresh your browser or try again later.</div>";
//return $error_msg;
}elseif($this->dbcon->affected_rows > 0) {
while ($row = $result->fetch_assoc()) {
$rows[] = $row;
/* $rows = $result->fetch_all(MYSQLI_ASSOC);
return $rows;*/
}
return $rows;
}else{
return "<div class='alert alert-danger'>Oops! Something went wrong, unable to fetch data, please refresh your browser or try again later.</div>";
}
}
//method to fetch all examiner for admin viewing
function getAllStudentsForAdmin(){
//write sql query
$sql = "SELECT * FROM students ORDER BY student_lname DESC;";
//execute the query
$result = $this->dbcon->query($sql);
$rows = array();
if ($this->dbcon->error) {
$student_details_errors = 'student_details_errors.txt';
$error_msg = "Unable to get all students details because ".$this->dbcon->error." on ".date('l F Y h:i:s A')."."."\n";
file_put_contents($student_details_error, $error_msg, FILE_APPEND);
return "<div class='alert alert-danger'>Oops! Something went wrong, please refresh your browser or try again later.</div>";
return $error_msg;
}elseif($this->dbcon->affected_rows > 0) {
while ($row = $result->fetch_assoc()) {
$rows[] = $row;
/* $rows = $result->fetch_all(MYSQLI_ASSOC);
return $rows;*/
}
return $rows;
}else{
return "<div class='alert alert-danger'>Oops! Something went wrong, unable to fetch data, please refresh your browser or try again later.</div>";
}
}
//method to fetch all examination for admin viewing
function getAllExamForAdmin(){
//write sql query
$sql = "SELECT examiners.*, examinations.*, subjects.subject_name FROM examiners JOIN examinations ON examiners.examiner_id = examinations.examiner_id LEFT JOIN subjects ON examinations.subject_id = subjects.subject_id ORDER BY exam_created_at DESC;";
//execute the query
$result = $this->dbcon->query($sql);
$rows = array();
if ($this->dbcon->error) {
$examination_creation_errors = 'examination_creation_errors.txt';
$error_msg = "Unable to get all examinations because ".$this->dbcon->error." on ".date('l F Y h:i:s A')."."."\n";
file_put_contents($examination_creation_errors, $error_msg, FILE_APPEND);
return "<div class='alert alert-danger'>Oops! Something went wrong, please refresh your browser or try again later.</div>";
}elseif($this->dbcon->affected_rows > 0) {
while ($row = $result->fetch_assoc()) {
$rows[] = $row;
/* $rows = $result->fetch_all(MYSQLI_ASSOC);
return $rows;*/
}
return $rows;
}else{
return "<div class='alert alert-danger'>Oops! Something went wrong, unable to fetch data, please refresh your browser or try again later wefubioubef.</div>";
}
}
//method to fetch all examination for admin viewing
function getAllExamForAdminForViewResult(){
//write sql query
$sql = "SELECT examiners.*, examinations.*, subjects.subject_name FROM examiners JOIN examinations ON examiners.examiner_id = examinations.examiner_id LEFT JOIN subjects ON examinations.subject_id = subjects.subject_id WHERE NOW() >= exam_result_date ORDER BY exam_created_at DESC;";
//execute the query
$result = $this->dbcon->query($sql);
$rows = array();
if ($this->dbcon->error) {
$result_view_errors = 'result_view_errors.txt';
$error_msg = "Unable to get all examinations because ".$this->dbcon->error." on ".date('l F Y h:i:s A')."."."\n";
file_put_contents($result_view_errors, $error_msg, FILE_APPEND);
return "<div class='alert alert-danger'>Oops! Something went wrong, please refresh your browser or try again later.</div>";
}elseif($this->dbcon->affected_rows > 0) {
while ($row = $result->fetch_assoc()) {
$rows[] = $row;
/* $rows = $result->fetch_all(MYSQLI_ASSOC);
return $rows;*/
}
return $rows;
}else{
return "<div class='alert alert-info'>No result has been released yet, please check back in a while.</div>";
}
}
//method to fetch all examination created by an examiner for updating
function getAllExamination($examiner_id){
//write sql query
$sql = "SELECT examinations.*, subjects.subject_name FROM examinations LEFT JOIN subjects ON examinations.subject_id = subjects.subject_id WHERE examiner_id = (SELECT examiner_id FROM examiners WHERE examiner_id = '$examiner_id') AND exam_created_at = exam_updated_at ORDER BY exam_created_at DESC;";
//execute the query
$result = $this->dbcon->query($sql);
$rows = array();
if ($this->dbcon->error) {
$examination_creation_errors = 'examination_creation_errors.txt';
$error_msg = "Unable to get all examinations because ".$this->dbcon->error." on ".date('l F Y h:i:s A')."."."\n";
file_put_contents($examination_creation_errors, $error_msg, FILE_APPEND);
return "<div class='alert alert-danger'>Oops! Something went wrong, please refresh your browser or try again later.</div>";
}elseif($this->dbcon->affected_rows > 0) {
while ($row = $result->fetch_assoc()) {
$rows[] = $row;
/* $rows = $result->fetch_all(MYSQLI_ASSOC);
return $rows;*/
}
return $rows;
}else{
return "<div class='alert alert-info'>No saved examination currently for addition of questions, updating examination and examination preview.</div>";
}
}
//method to fetch all examination sitted by student;
function getExamInfoForStudent($student_id){
//write sql query
$sql = "SELECT registered_students.*, examinations.*, subjects.subject_name FROM registered_students RIGHT JOIN examinations ON registered_students.exam_id = examinations.exam_id JOIN subjects ON examinations.subject_id = subjects.subject_id WHERE student_id = (SELECT student_id FROM students WHERE student_id = '$student_id') AND NOW() < exam_end_time ORDER BY exam_created_at DESC ;";
//execute the query
$result = $this->dbcon->query($sql);
$rows = array();
if ($this->dbcon->error) {
$examination_fetch_errors = 'examination_fetch_errors.txt';
$error_msg = "Unable get all examinations by student_id with id ".$student_id." because ".$this->dbcon->error." on ".date('l F Y h:i:s A')."."."\n";
file_put_contents($examination_fetch_errors, $error_msg, FILE_APPEND);
return "<div class='alert alert-danger'>Oops! Something went wrong, unable to fetch examinations or try again later.</div>";
}elseif($this->dbcon->affected_rows > 0) {
while ($row = $result->fetch_assoc()) {
$rows[] = $row;
}
return $rows;
}else{
return "<div class='alert alert-info'>No examination coming up soon </div>";
}
}
//method to fetch all examination sitted by student;
function getAllExamsByStudentForResults($student_id){
//write sql query
$sql = "SELECT registered_students.*, examinations.*, subjects.subject_name FROM registered_students RIGHT JOIN examinations ON registered_students.exam_id = examinations.exam_id JOIN subjects ON examinations.subject_id = subjects.subject_id WHERE student_id = (SELECT student_id FROM students WHERE student_id = '$student_id') AND NOW() >= exam_result_date ORDER BY exam_created_at DESC ;";
//execute the query
$result = $this->dbcon->query($sql);
$rows = array();
if ($this->dbcon->error) {
$examination_fetch_errors = 'examination_fetch_errors.txt';
$error_msg = "Unable get all examinations by student_id with id ".$student_id." because ".$this->dbcon->error." on ".date('l F Y h:i:s A')."."."\n";
file_put_contents($examination_fetch_errors, $error_msg, FILE_APPEND);
return "<div class='alert alert-danger'>Oops! Something went wrong, unable to fetch examinations or try again later.</div>";
}elseif($this->dbcon->affected_rows > 0) {
while ($row = $result->fetch_assoc()) {
$rows[] = $row;
}
return $rows;
}else{
return "<div class='alert alert-info'>No result has been released yet, please check back in a while.</div>";
}
}
//method for fetch all examination created by an examiner
function getAllExaminationForStudentRegistration($examiner_id){
//write sql query
$sql = "SELECT examinations.*, subjects.subject_name FROM examinations LEFT JOIN subjects ON examinations.subject_id = subjects.subject_id WHERE examiner_id = (SELECT examiner_id FROM examiners WHERE examiner_id = '$examiner_id') AND exam_start_time IS NOT NULL AND exam_start_time > NOW() ORDER BY exam_created_at DESC;";
//execute the query
$result = $this->dbcon->query($sql);
$rows = array();
if ($this->dbcon->error) {
$examination_creation_errors = 'examination_creation_errors.txt';
$error_msg = "Unable to get all examinations because ".$this->dbcon->error." on ".date('l F Y h:i:s A')."."."\n";
file_put_contents($examination_creation_errors, $error_msg, FILE_APPEND);
return "<div class='alert alert-danger'>Oops! Something went wrong, please refresh your browser or try again later.</div>";
}elseif($this->dbcon->affected_rows > 0) {
while ($row = $result->fetch_assoc()) {
$rows[] = $row;
}
return $rows;
}else{
return "<div class='alert alert-info'>No new examination for student registration</div>";
/*"<div class='alert alert-danger'>Please make sure you have updated examination.</div>"*/
}
}
//method to get the list of all registered student fo an examination
function getAllRegisteredStudent($exam_id){
$sql = "SELECT students.*, registered_students.* FROM students JOIN registered_students ON students.student_id = registered_students.student_id WHERE exam_id = (SELECT exam_id FROM examinations WHERE exam_id = '$exam_id')";
$result = $this->dbcon->query($sql);
if ($this->dbcon->error){
//logging of error into a file
$student_registration_errors = 'student_registration_errors.txt';
$error_msg = "Unable to get list of registered students because ".$this->dbcon->error." on ".date('l F Y h:i:s A')."."."\n";
file_put_contents($student_registration_errors, $error_msg, FILE_APPEND);
}elseif($result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
$rows[] = $row;
}
return $rows;
}elseif($result->num_rows == 0){
return "<div class='alert alert-info'>No student registered for this examination yet.</div>";
}else{
return "<div class='alert alert-danger'>Oops! Something went wrong, unable to get all examinations, please try again later.</div>";
}
}
//method to start examination after reading general instruction
function startExamination($registration_id, $student_id, $exam_id){
$exam_status = 1;
$sql = "UPDATE registered_students SET exam_status = '$exam_status' WHERE registration_id = '$registration_id' AND student_id = '$student_id' AND exam_id = '$exam_id' ";
$result = $this->dbcon->query($sql);
if ($this->dbcon->error){
//logging of error into a file
$exam_start_errors = 'exam_start_errors.txt';
$error_msg = "Student with the id ".$student_id." is unable to start exam because".$this->dbcon->error." on ".date('l F Y h:i:s A')."."."\n";
return $error_msg;
file_put_contents($exam_login_errors, $error_msg, FILE_APPEND);
}elseif($this->dbcon->affected_rows == 1){
return "success";
}else{
return "<div class='alert alert-info'>You can't continue with this examination because you have previously login for this examination.</div>";
}
}
//method to submit student Examination option
function studentExamOptions($studentAnswers, $student_id, $exam_id){
foreach ($studentAnswers as $key => $value) {
echo $key."<br>";
$sql = "INSERT INTO student_answer SET exam_id = (SELECT exam_id FROM examinations WHERE exam_id = '$exam_id'), student_id=(SELECT student_id FROM students WHERE student_id = '$student_id'), question_id=(SELECT question_id FROM questions WHERE question_id = '$key'), student_answers = '$value'";
$result = $this->dbcon->query($sql);
}
if ($this->dbcon->error) {
//logging of error into a file
$examination_submission_errors = 'examination_submission_errors.txt';
$error_msg = "Student with the student id ".$student_id." is unable to submit examination because ".$this->dbcon->error." on ".date('l F Y h:i:s A')."."."\n";
file_put_contents($examination_submission_errors, $error_msg, FILE_APPEND);
}else{
$sql2 = "SELECT student_answers FROM student_answer WHERE exam_id = (SELECT exam_id FROM examinations WHERE exam_id = '$exam_id') AND student_id = (SELECT student_id FROM students WHERE student_id = '$student_id') ";
$sql3 = "SELECT question FROM questions WHERE exam_id = (SELECT exam_id FROM examinations WHERE exam_id = '$exam_id') ";
$result2 = $this->dbcon->query($sql2);
$result3 = $this->dbcon->query($sql3);
if ($this->dbcon->error) {
//logging of error into a file
$examination_submission_errors = 'examination_submission_errors.txt';
$error_msg = "Unable to get total or attempted questions is because ".$this->dbcon->error." on ".date('l F Y h:i:s A')."."."\n";
file_put_contents($examination_submission_errors, $error_msg, FILE_APPEND);}
/*aQ = attemptedQuestions
tQ = totalQuestions */
$aQ = $result2->num_rows;
$tQ = $result3->num_rows;
$success = "Examination successfully submitted";
header("Location: examflow_examlogout.php?msg=$success&aQ=$aQ&tQ=$tQ");
exit;
}
}
//method to view result of an examination by student
function studentViewResult($student_id, $exam_id){
//write sql query
$sql = "SELECT options.*, questions.*, student_answer.* FROM options LEFT JOIN questions ON options.question_id = questions.question_id JOIN student_answer ON questions.question_id = student_answer.question_id WHERE student_id = (SELECT student_id FROM students WHERE student_id = '$student_id') AND questions.exam_id = (SELECT exam_id FROM examinations WHERE exam_id = '$exam_id')";
//execute the query
$result = $this->dbcon->query($sql);
if ($this->dbcon->error) {
//logging of error into a file
$result_view_errors = 'result_view_errors.txt';
$error_msg = "Student with id ".$student_id." is unable to view result because ".$this->dbcon->error." on ".date('l F Y h:i:s A')."."."\n";
file_put_contents($result_view_errors, $error_msg, FILE_APPEND);
}elseif($result->num_rows > 0){
while ($row = $result->fetch_assoc()) {
$rows[] = $row;
}
return $rows;
}else{
return "<div class='alert alert-info'>Result is not available, please checkback in while</div>";
}
}
//method to get total mark of an examination
function getExamTotalMark($exam_id){
//write sql query
$sql="SELECT SUM(question_mark) AS totalMark FROM questions WHERE exam_id = (SELECT exam_id FROM examinations WHERE exam_id = '$exam_id')";
//execute the query
$result = $this->dbcon->query($sql);
if ($this->dbcon->error) {
//logging of error into a file
$exam_score_errors = 'result_view_errors.txt';
$error_msg = "Unable to fetch total mark of examination with id ".$exam_id." because ".$this->dbcon->error." on ".date('l F Y h:i:s A')."."."\n";
file_put_contents($exam_score_errors, $error_msg, FILE_APPEND);
}elseif($result->num_rows > 0){
while ($row = $result->fetch_assoc()) {
$rows[] = $row;
}
return $rows;
}
}
//method for fetch all examination created by an examiner
function getAllExamsByExaminerForResults($examiner_id){
//write sql query
$sql = "SELECT examinations.*, subjects.subject_name FROM examinations LEFT JOIN subjects ON examinations.subject_id = subjects.subject_id WHERE examiner_id = (SELECT examiner_id FROM examiners WHERE examiner_id = '$examiner_id') AND NOW() >= exam_result_date ORDER BY exam_created_at DESC;";
//execute the query
$result = $this->dbcon->query($sql);
$rows = array();
if ($this->dbcon->error) {
$examination_creation_errors = 'examination_creation_errors.txt';
$error_msg = "Unable to get all examinations because ".$this->dbcon->error." on ".date('l F Y h:i:s A')."."."\n";
file_put_contents($examination_creation_errors, $error_msg, FILE_APPEND);
return "<div class='alert alert-danger'>Oops! Something went wrong, please refresh your browser or try again later.</div>";
}elseif($this->dbcon->affected_rows > 0) {
while ($row = $result->fetch_assoc()) {
$rows[] = $row;
}
return $rows;
}else{
return "<div class='alert alert-info'>Result is not available, please checkback in while</div>";
}
}
//method to get total number of registered student for an examination
function totalRegisteredStudent($exam_id){
//write sql
$sql = "SELECT COUNT(registration_id) AS registeredStudents FROM registered_students WHERE exam_id = (SELECT exam_id FROM examinations WHERE exam_id = '$exam_id')";
$rows = array();
//execute $sql;
$result = $this->dbcon->query($sql);
if ($this->dbcon->error){
//logging of error into a file
$count_registered_student_errors = 'count_registered_student_errors.txt';
$error_msg = "Unable to fetch total number of registered student of examination with id ".$exam_id." because ".$this->dbcon->error." on ".date('l F Y h:i:s A')."."."\n";
file_put_contents($count_registered_student_errors, $error_msg, FILE_APPEND);
}elseif($result->num_rows > 0){
while ($row = $result->fetch_assoc()) {
$rows[] = $row;
}
return $rows;
}
}
//method to get total number of questions for an examination
function totalNumberOfQuestion($exam_id){
//write sql
$sql = "SELECT COUNT(question) AS noOfQuestions FROM questions WHERE exam_id = (SELECT exam_id FROM examinations WHERE exam_id = '$exam_id')";
$rows = array();
//execute $sql;
$result = $this->dbcon->query($sql);
if ($this->dbcon->error){
//logging of error into a file
$count_questions_errors = 'count_questions_errors.txt';
$error_msg = "Unable to fetch total number of questions for examination with id ".$exam_id." because ".$this->dbcon->error." on ".date('l F Y h:i:s A')."."."\n";
file_put_contents($count_questions_errors, $error_msg, FILE_APPEND);
}elseif($result->num_rows > 0){
while ($row = $result->fetch_assoc()) {
$rows[] = $row;
}
return $rows;
}
}
//method to get student passcode for an examination
function getStudentPasscode($student_id, $exam_id){
//wriet sql
$sql = "SELECT student_exam_passcode, registration_id FROM registered_students WHERE student_id = (SELECT student_id FROM students WHERE student_id = '$student_id') AND exam_id = (SELECT exam_id FROM examinations WHERE exam_id = '$exam_id')";
$rows = array();
//execute $sql;
$result = $this->dbcon->query($sql);
if ($this->dbcon->error){
//logging of error into a file
$get_passcode_errors = 'get_passcode_errors.txt';
$error_msg = "Unable to go the passcode of student with id of ".$student_id." in exam with id".$exam_id." because ".$this->dbcon->error." on ".date('l F Y h:i:s A')."."."\n";
file_put_contents($get_passcode_errors, $error_msg, FILE_APPEND);
}elseif($result->num_rows > 0){
while ($row = $result->fetch_assoc()) {
$rows[] = $row;
}
return $rows;
}
}
//method to mark student examination
function examinerViewResult($exam_id){
//write sql
$sql = "SELECT students.*, registered_students.* FROM students JOIN registered_students ON students.student_id = registered_students.student_id WHERE registered_students.exam_id = (SELECT exam_id FROM examinations WHERE exam_id = '$exam_id') ORDER BY student_lname";
$rows = array();
//execute $sql;
$result = $this->dbcon->query($sql);
if ($this->dbcon->error){
//logging of error into a file
$result_view_errors = 'result_view_errors.txt';
$error_msg = "Examiner unable to view result of examination with id ".$exam_id." because ".$this->dbcon->error." on ".date('l F Y h:i:s A')."."."\n";
file_put_contents($result_view_errors, $error_msg, FILE_APPEND);
}elseif($result->num_rows > 0){
while ($row = $result->fetch_assoc()) {
$rows[] = $row;
}
return $rows;
}
}
//method to delete an examination
function deleteExamination($exam_id){
//write sql
$sql = "DELETE FROM examinations WHERE exam_id = '$exam_id'";
//execute $sql;
$result = $this->dbcon->query($sql);
if ($this->dbcon->error){
//logging of error into a file
$exam_delete_errors = 'exam_delete_errors.txt';
$error_msg = "Examiner unable to delete an examination with id ".$exam_id." because ".$this->dbcon->error." on ".date('l F Y h:i:s A')."."."\n";
file_put_contents($exam_delete_errors, $error_msg, FILE_APPEND);
}elseif($this->dbcon->affected_rows == 1){
return "Examination successfully deleted";
}elseif($this->dbcon->affected_rows == 0){
return "Oop! Something went wrong unable to delete examination";
}
}
//method to count all examinations for admin dashboard
function adminCountTotalExams(){
//write sql
$sql = "SELECT COUNT(exam_id) AS totalExams FROM examinations";
//execute $sql;
$result = $this->dbcon->query($sql);
if ($this->dbcon->error){
//logging of error into a file
$exam_count_errors = 'exam_count_errors.txt';
$error_msg = "Unable to count all examination for admin dashboard display because ".$exam_id." because ".$this->dbcon->error." on ".date('l F Y h:i:s A')."."."\n";
file_put_contents($exam_count_errors, $error_msg, FILE_APPEND);
}elseif($result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
$rows[] = $row;
}
return $rows;
}
}
//method to count all students for admin dashboard
function adminCountTotalStudents(){
//write sql
$sql = "SELECT COUNT(student_id) AS totalStudents FROM students";
//execute $sql;
$result = $this->dbcon->query($sql);
if ($this->dbcon->error){
//logging of error into a file
$student_count_errors = 'student_count_errors.txt';
$error_msg = "Unable to count all student for admin dashboard display because ".$exam_id." because ".$this->dbcon->error." on ".date('l F Y h:i:s A')."."."\n";
file_put_contents($student_count_errors, $error_msg, FILE_APPEND);
}elseif($result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
$rows[] = $row;
}
return $rows;
}
}
//method to count all questions for admin dashboard
function adminCountTotalQuestions(){
//write sql
$sql = "SELECT COUNT(question_id) AS totalQuestions FROM questions";
//execute $sql;
$result = $this->dbcon->query($sql);
if ($this->dbcon->error){
//logging of error into a file
$question_count_errors = 'question_count_errors.txt';
$error_msg = "Unable to count all questions for admin dashboard display because ".$exam_id." because ".$this->dbcon->error." on ".date('l F Y h:i:s A')."."."\n";
file_put_contents($question_count_errors, $error_msg, FILE_APPEND);
}elseif($result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
$rows[] = $row;
}
return $rows;
}
}