forked from SaiyamTuteja/Faculty_Evaluation_System
-
Notifications
You must be signed in to change notification settings - Fork 0
/
admin_class.php
690 lines (660 loc) · 19 KB
/
admin_class.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
<?php
session_start();
ini_set('display_errors', 1);
Class Action {
private $db;
public function __construct() {
ob_start();
include 'db_connect.php';
$this->db = $conn;
}
function __destruct() {
$this->db->close();
ob_end_flush();
}
function login(){
extract($_POST);
$type = array("","users","faculty_list","student_list");
$type2 = array("","admin","faculty","student");
$qry = $this->db->query("SELECT *,concat(firstname,' ',lastname) as name FROM {$type[$login]} where email = '".$email."' and password = '".md5($password)."' ");
if($qry->num_rows > 0){
foreach ($qry->fetch_array() as $key => $value) {
if($key != 'password' && !is_numeric($key))
$_SESSION['login_'.$key] = $value;
}
$_SESSION['login_type'] = $login;
$_SESSION['login_view_folder'] = $type2[$login].'/';
$academic = $this->db->query("SELECT * FROM academic_list where is_default = 1 ");
if($academic->num_rows > 0){
foreach($academic->fetch_array() as $k => $v){
if(!is_numeric($k))
$_SESSION['academic'][$k] = $v;
}
}
return 1;
}else{
return 2;
}
}
function logout(){
session_destroy();
foreach ($_SESSION as $key => $value) {
unset($_SESSION[$key]);
}
header("location:login.php");
}
function login2(){
extract($_POST);
$qry = $this->db->query("SELECT *,concat(lastname,', ',firstname,' ',middlename) as name FROM students where student_code = '".$student_code."' ");
if($qry->num_rows > 0){
foreach ($qry->fetch_array() as $key => $value) {
if($key != 'password' && !is_numeric($key))
$_SESSION['rs_'.$key] = $value;
}
return 1;
}else{
return 3;
}
}
function save_user(){
extract($_POST);
$data = "";
foreach($_POST as $k => $v){
if(!in_array($k, array('id','cpass','password')) && !is_numeric($k)){
if(empty($data)){
$data .= " $k='$v' ";
}else{
$data .= ", $k='$v' ";
}
}
}
if(!empty($password)){
$data .= ", password=md5('$password') ";
}
$check = $this->db->query("SELECT * FROM users where email ='$email' ".(!empty($id) ? " and id != {$id} " : ''))->num_rows;
if($check > 0){
return 2;
exit;
}
if(isset($_FILES['img']) && $_FILES['img']['tmp_name'] != ''){
$fname = strtotime(date('y-m-d H:i')).'_'.$_FILES['img']['name'];
$move = move_uploaded_file($_FILES['img']['tmp_name'],'assets/uploads/'. $fname);
$data .= ", avatar = '$fname' ";
}
if(empty($id)){
$save = $this->db->query("INSERT INTO users set $data");
}else{
$save = $this->db->query("UPDATE users set $data where id = $id");
}
if($save){
return 1;
}
}
function signup(){
extract($_POST);
$data = "";
foreach($_POST as $k => $v){
if(!in_array($k, array('id','cpass')) && !is_numeric($k)){
if($k =='password'){
if(empty($v))
continue;
$v = md5($v);
}
if(empty($data)){
$data .= " $k='$v' ";
}else{
$data .= ", $k='$v' ";
}
}
}
$check = $this->db->query("SELECT * FROM users where email ='$email' ".(!empty($id) ? " and id != {$id} " : ''))->num_rows;
if($check > 0){
return 2;
exit;
}
if(isset($_FILES['img']) && $_FILES['img']['tmp_name'] != ''){
$fname = strtotime(date('y-m-d H:i')).'_'.$_FILES['img']['name'];
$move = move_uploaded_file($_FILES['img']['tmp_name'],'assets/uploads/'. $fname);
$data .= ", avatar = '$fname' ";
}
if(empty($id)){
$save = $this->db->query("INSERT INTO users set $data");
}else{
$save = $this->db->query("UPDATE users set $data where id = $id");
}
if($save){
if(empty($id))
$id = $this->db->insert_id;
foreach ($_POST as $key => $value) {
if(!in_array($key, array('id','cpass','password')) && !is_numeric($key))
$_SESSION['login_'.$key] = $value;
}
$_SESSION['login_id'] = $id;
if(isset($_FILES['img']) && !empty($_FILES['img']['tmp_name']))
$_SESSION['login_avatar'] = $fname;
return 1;
}
}
function update_user(){
extract($_POST);
$data = "";
$type = array("","users","faculty_list","student_list");
foreach($_POST as $k => $v){
if(!in_array($k, array('id','cpass','table','password')) && !is_numeric($k)){
if(empty($data)){
$data .= " $k='$v' ";
}else{
$data .= ", $k='$v' ";
}
}
}
$check = $this->db->query("SELECT * FROM {$type[$_SESSION['login_type']]} where email ='$email' ".(!empty($id) ? " and id != {$id} " : ''))->num_rows;
if($check > 0){
return 2;
exit;
}
if(isset($_FILES['img']) && $_FILES['img']['tmp_name'] != ''){
$fname = strtotime(date('y-m-d H:i')).'_'.$_FILES['img']['name'];
$move = move_uploaded_file($_FILES['img']['tmp_name'],'assets/uploads/'. $fname);
$data .= ", avatar = '$fname' ";
}
if(!empty($password))
$data .= " ,password=md5('$password') ";
if(empty($id)){
$save = $this->db->query("INSERT INTO {$type[$_SESSION['login_type']]} set $data");
}else{
echo "UPDATE {$type[$_SESSION['login_type']]} set $data where id = $id";
$save = $this->db->query("UPDATE {$type[$_SESSION['login_type']]} set $data where id = $id");
}
if($save){
foreach ($_POST as $key => $value) {
if($key != 'password' && !is_numeric($key))
$_SESSION['login_'.$key] = $value;
}
if(isset($_FILES['img']) && !empty($_FILES['img']['tmp_name']))
$_SESSION['login_avatar'] = $fname;
return 1;
}
}
function delete_user(){
extract($_POST);
$delete = $this->db->query("DELETE FROM users where id = ".$id);
if($delete)
return 1;
}
function save_system_settings(){
extract($_POST);
$data = '';
foreach($_POST as $k => $v){
if(!is_numeric($k)){
if(empty($data)){
$data .= " $k='$v' ";
}else{
$data .= ", $k='$v' ";
}
}
}
if($_FILES['cover']['tmp_name'] != ''){
$fname = strtotime(date('y-m-d H:i')).'_'.$_FILES['cover']['name'];
$move = move_uploaded_file($_FILES['cover']['tmp_name'],'../assets/uploads/'. $fname);
$data .= ", cover_img = '$fname' ";
}
$chk = $this->db->query("SELECT * FROM system_settings");
if($chk->num_rows > 0){
$save = $this->db->query("UPDATE system_settings set $data where id =".$chk->fetch_array()['id']);
}else{
$save = $this->db->query("INSERT INTO system_settings set $data");
}
if($save){
foreach($_POST as $k => $v){
if(!is_numeric($k)){
$_SESSION['system'][$k] = $v;
}
}
if($_FILES['cover']['tmp_name'] != ''){
$_SESSION['system']['cover_img'] = $fname;
}
return 1;
}
}
function save_image(){
extract($_FILES['file']);
if(!empty($tmp_name)){
$fname = strtotime(date("Y-m-d H:i"))."_".(str_replace(" ","-",$name));
$move = move_uploaded_file($tmp_name,'assets/uploads/'. $fname);
$protocol = strtolower(substr($_SERVER["SERVER_PROTOCOL"],0,5))=='https'?'https':'http';
$hostName = $_SERVER['HTTP_HOST'];
$path =explode('/',$_SERVER['PHP_SELF']);
$currentPath = '/'.$path[1];
if($move){
return $protocol.'://'.$hostName.$currentPath.'/assets/uploads/'.$fname;
}
}
}
function save_subject(){
extract($_POST);
$data = "";
foreach($_POST as $k => $v){
if(!in_array($k, array('id','user_ids')) && !is_numeric($k)){
if(empty($data)){
$data .= " $k='$v' ";
}else{
$data .= ", $k='$v' ";
}
}
}
$chk = $this->db->query("SELECT * FROM subject_list where code = '$code' and id != '{$id}' ")->num_rows;
if($chk > 0){
return 2;
}
if(empty($id)){
$save = $this->db->query("INSERT INTO subject_list set $data");
}else{
$save = $this->db->query("UPDATE subject_list set $data where id = $id");
}
if($save){
return 1;
}
}
function delete_subject(){
extract($_POST);
$delete = $this->db->query("DELETE FROM subject_list where id = $id");
if($delete){
return 1;
}
}
function save_class(){
extract($_POST);
$data = "";
foreach($_POST as $k => $v){
if(!in_array($k, array('id','user_ids')) && !is_numeric($k)){
if(empty($data)){
$data .= " $k='$v' ";
}else{
$data .= ", $k='$v' ";
}
}
}
$chk = $this->db->query("SELECT * FROM class_list where (".str_replace(",",'and',$data).") and id != '{$id}' ")->num_rows;
if($chk > 0){
return 2;
}
if(isset($user_ids)){
$data .= ", user_ids='".implode(',',$user_ids)."' ";
}
if(empty($id)){
$save = $this->db->query("INSERT INTO class_list set $data");
}else{
$save = $this->db->query("UPDATE class_list set $data where id = $id");
}
if($save){
return 1;
}
}
function delete_class(){
extract($_POST);
$delete = $this->db->query("DELETE FROM class_list where id = $id");
if($delete){
return 1;
}
}
function save_academic(){
extract($_POST);
$data = "";
foreach($_POST as $k => $v){
if(!in_array($k, array('id','user_ids')) && !is_numeric($k)){
if(empty($data)){
$data .= " $k='$v' ";
}else{
$data .= ", $k='$v' ";
}
}
}
$chk = $this->db->query("SELECT * FROM academic_list where (".str_replace(",",'and',$data).") and id != '{$id}' ")->num_rows;
if($chk > 0){
return 2;
}
$hasDefault = $this->db->query("SELECT * FROM academic_list where is_default = 1")->num_rows;
if($hasDefault == 0){
$data .= " , is_default = 1 ";
}
if(empty($id)){
$save = $this->db->query("INSERT INTO academic_list set $data");
}else{
$save = $this->db->query("UPDATE academic_list set $data where id = $id");
}
if($save){
return 1;
}
}
function delete_academic(){
extract($_POST);
$delete = $this->db->query("DELETE FROM academic_list where id = $id");
if($delete){
return 1;
}
}
function make_default(){
extract($_POST);
$update= $this->db->query("UPDATE academic_list set is_default = 0");
$update1= $this->db->query("UPDATE academic_list set is_default = 1 where id = $id");
$qry = $this->db->query("SELECT * FROM academic_list where id = $id")->fetch_array();
if($update && $update1){
foreach($qry as $k =>$v){
if(!is_numeric($k))
$_SESSION['academic'][$k] = $v;
}
return 1;
}
}
function save_criteria(){
extract($_POST);
$data = "";
foreach($_POST as $k => $v){
if(!in_array($k, array('id','user_ids')) && !is_numeric($k)){
if(empty($data)){
$data .= " $k='$v' ";
}else{
$data .= ", $k='$v' ";
}
}
}
$chk = $this->db->query("SELECT * FROM criteria_list where (".str_replace(",",'and',$data).") and id != '{$id}' ")->num_rows;
if($chk > 0){
return 2;
}
if(empty($id)){
$lastOrder= $this->db->query("SELECT * FROM criteria_list order by abs(order_by) desc limit 1");
$lastOrder = $lastOrder->num_rows > 0 ? $lastOrder->fetch_array()['order_by'] + 1 : 0;
$data .= ", order_by='$lastOrder' ";
$save = $this->db->query("INSERT INTO criteria_list set $data");
}else{
$save = $this->db->query("UPDATE criteria_list set $data where id = $id");
}
if($save){
return 1;
}
}
function delete_criteria(){
extract($_POST);
$delete = $this->db->query("DELETE FROM criteria_list where id = $id");
if($delete){
return 1;
}
}
function save_criteria_order(){
extract($_POST);
$data = "";
foreach($criteria_id as $k => $v){
$update[] = $this->db->query("UPDATE criteria_list set order_by = $k where id = $v");
}
if(isset($update) && count($update)){
return 1;
}
}
function save_question(){
extract($_POST);
$data = "";
foreach($_POST as $k => $v){
if(!in_array($k, array('id','user_ids')) && !is_numeric($k)){
if(empty($data)){
$data .= " $k='$v' ";
}else{
$data .= ", $k='$v' ";
}
}
}
if(empty($id)){
$lastOrder= $this->db->query("SELECT * FROM question_list where academic_id = $academic_id order by abs(order_by) desc limit 1");
$lastOrder = $lastOrder->num_rows > 0 ? $lastOrder->fetch_array()['order_by'] + 1 : 0;
$data .= ", order_by='$lastOrder' ";
$save = $this->db->query("INSERT INTO question_list set $data");
}else{
$save = $this->db->query("UPDATE question_list set $data where id = $id");
}
if($save){
return 1;
}
}
function delete_question(){
extract($_POST);
$delete = $this->db->query("DELETE FROM question_list where id = $id");
if($delete){
return 1;
}
}
function save_question_order(){
extract($_POST);
$data = "";
foreach($qid as $k => $v){
$update[] = $this->db->query("UPDATE question_list set order_by = $k where id = $v");
}
if(isset($update) && count($update)){
return 1;
}
}
function save_faculty(){
extract($_POST);
$data = "";
foreach($_POST as $k => $v){
if(!in_array($k, array('id','cpass','password')) && !is_numeric($k)){
if(empty($data)){
$data .= " $k='$v' ";
}else{
$data .= ", $k='$v' ";
}
}
}
if(!empty($password)){
$data .= ", password=md5('$password') ";
}
$check = $this->db->query("SELECT * FROM faculty_list where email ='$email' ".(!empty($id) ? " and id != {$id} " : ''))->num_rows;
if($check > 0){
return 2;
exit;
}
$check = $this->db->query("SELECT * FROM faculty_list where school_id ='$school_id' ".(!empty($id) ? " and id != {$id} " : ''))->num_rows;
if($check > 0){
return 3;
exit;
}
if(isset($_FILES['img']) && $_FILES['img']['tmp_name'] != ''){
$fname = strtotime(date('y-m-d H:i')).'_'.$_FILES['img']['name'];
$move = move_uploaded_file($_FILES['img']['tmp_name'],'assets/uploads/'. $fname);
$data .= ", avatar = '$fname' ";
}
if(empty($id)){
$save = $this->db->query("INSERT INTO faculty_list set $data");
}else{
$save = $this->db->query("UPDATE faculty_list set $data where id = $id");
}
if($save){
return 1;
}
}
function delete_faculty(){
extract($_POST);
$delete = $this->db->query("DELETE FROM faculty_list where id = ".$id);
if($delete)
return 1;
}
function save_student(){
extract($_POST);
$data = "";
foreach($_POST as $k => $v){
if(!in_array($k, array('id','cpass','password')) && !is_numeric($k)){
if(empty($data)){
$data .= " $k='$v' ";
}else{
$data .= ", $k='$v' ";
}
}
}
if(!empty($password)){
$data .= ", password=md5('$password') ";
}
$check = $this->db->query("SELECT * FROM student_list where email ='$email' ".(!empty($id) ? " and id != {$id} " : ''))->num_rows;
if($check > 0){
return 2;
exit;
}
if(isset($_FILES['img']) && $_FILES['img']['tmp_name'] != ''){
$fname = strtotime(date('y-m-d H:i')).'_'.$_FILES['img']['name'];
$move = move_uploaded_file($_FILES['img']['tmp_name'],'assets/uploads/'. $fname);
$data .= ", avatar = '$fname' ";
}
if(empty($id)){
$save = $this->db->query("INSERT INTO student_list set $data");
}else{
$save = $this->db->query("UPDATE student_list set $data where id = $id");
}
if($save){
return 1;
}
}
function delete_student(){
extract($_POST);
$delete = $this->db->query("DELETE FROM student_list where id = ".$id);
if($delete)
return 1;
}
function save_task(){
extract($_POST);
$data = "";
foreach($_POST as $k => $v){
if(!in_array($k, array('id')) && !is_numeric($k)){
if($k == 'description')
$v = htmlentities(str_replace("'","’",$v));
if(empty($data)){
$data .= " $k='$v' ";
}else{
$data .= ", $k='$v' ";
}
}
}
if(empty($id)){
$save = $this->db->query("INSERT INTO task_list set $data");
}else{
$save = $this->db->query("UPDATE task_list set $data where id = $id");
}
if($save){
return 1;
}
}
function delete_task(){
extract($_POST);
$delete = $this->db->query("DELETE FROM task_list where id = $id");
if($delete){
return 1;
}
}
function save_progress(){
extract($_POST);
$data = "";
foreach($_POST as $k => $v){
if(!in_array($k, array('id')) && !is_numeric($k)){
if($k == 'progress')
$v = htmlentities(str_replace("'","’",$v));
if(empty($data)){
$data .= " $k='$v' ";
}else{
$data .= ", $k='$v' ";
}
}
}
if(!isset($is_complete))
$data .= ", is_complete=0 ";
if(empty($id)){
$save = $this->db->query("INSERT INTO task_progress set $data");
}else{
$save = $this->db->query("UPDATE task_progress set $data where id = $id");
}
if($save){
if(!isset($is_complete))
$this->db->query("UPDATE task_list set status = 1 where id = $task_id ");
else
$this->db->query("UPDATE task_list set status = 2 where id = $task_id ");
return 1;
}
}
function delete_progress(){
extract($_POST);
$delete = $this->db->query("DELETE FROM task_progress where id = $id");
if($delete){
return 1;
}
}
function save_restriction(){
extract($_POST);
$filtered = implode(",",array_filter($rid));
if(!empty($filtered))
$this->db->query("DELETE FROM restriction_list where id not in ($filtered) and academic_id = $academic_id");
else
$this->db->query("DELETE FROM restriction_list where academic_id = $academic_id");
foreach($rid as $k => $v){
$data = " academic_id = $academic_id ";
$data .= ", faculty_id = {$faculty_id[$k]} ";
$data .= ", class_id = {$class_id[$k]} ";
$data .= ", subject_id = {$subject_id[$k]} ";
if(empty($v)){
$save[] = $this->db->query("INSERT INTO restriction_list set $data ");
}else{
$save[] = $this->db->query("UPDATE restriction_list set $data where id = $v ");
}
}
return 1;
}
function save_evaluation(){
extract($_POST);
$data = " student_id = {$_SESSION['login_id']} ";
$data .= ", academic_id = $academic_id ";
$data .= ", subject_id = $subject_id ";
$data .= ", class_id = $class_id ";
$data .= ", restriction_id = $restriction_id ";
$data .= ", faculty_id = $faculty_id ";
$save = $this->db->query("INSERT INTO evaluation_list set $data");
if($save){
$eid = $this->db->insert_id;
foreach($qid as $k => $v){
$data = " evaluation_id = $eid ";
$data .= ", question_id = $v ";
$data .= ", rate = {$rate[$v]} ";
$ins[] = $this->db->query("INSERT INTO evaluation_answers set $data ");
}
if(isset($ins))
return 1;
}
}
function get_class(){
extract($_POST);
$data = array();
$get = $this->db->query("SELECT c.id,concat(c.curriculum,' ',c.level,' - ',c.section) as class,s.id as sid,concat(s.code,' - ',s.subject) as subj FROM restriction_list r inner join class_list c on c.id = r.class_id inner join subject_list s on s.id = r.subject_id where r.faculty_id = {$fid} and academic_id = {$_SESSION['academic']['id']} ");
while($row= $get->fetch_assoc()){
$data[]=$row;
}
return json_encode($data);
}
function get_report(){
extract($_POST);
$data = array();
$get = $this->db->query("SELECT * FROM evaluation_answers where evaluation_id in (SELECT evaluation_id FROM evaluation_list where academic_id = {$_SESSION['academic']['id']} and faculty_id = $faculty_id and subject_id = $subject_id and class_id = $class_id ) ");
$answered = $this->db->query("SELECT * FROM evaluation_list where academic_id = {$_SESSION['academic']['id']} and faculty_id = $faculty_id and subject_id = $subject_id and class_id = $class_id");
$rate = array();
while($row = $get->fetch_assoc()){
if(!isset($rate[$row['question_id']][$row['rate']]))
$rate[$row['question_id']][$row['rate']] = 0;
$rate[$row['question_id']][$row['rate']] += 1;
}
// $data[]= $row;
$ta = $answered->num_rows;
$r = array();
foreach($rate as $qk => $qv){
foreach($qv as $rk => $rv){
$r[$qk][$rk] =($rate[$qk][$rk] / $ta) *100;
}
}
$data['tse'] = $ta;
$data['data'] = $r;
return json_encode($data);
}
}