-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuserData.php
950 lines (800 loc) · 35.9 KB
/
userData.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
<?php
/**
* Created by PhpStorm.
* User: alihamza
* Date: 5/22/18
* Time: 5:26 PM
*/
function getMonth($month)
{
$monthArray = array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
return $monthArray[$month];
}
function getDateInFormat($date)
{
$d = $date[8].$date[9]." ".getMonth(($date[5])*10+($date[6]))." ".$date[0].$date[1].$date[2].$date[3];
return $d;
}
function getTimeFormat($date)
{
$t = $date[11].$date[12].$date[13].$date[14].$date[15];
return $t;
}
function getFisrtAndLastName($rollNo,$conn)
{
$query = "SELECT firstName,lastName from userInfo where lower(rollNo)='".strtolower($rollNo)."'";
$resultOfQuery = mysqli_query($conn,$query);
$getResult = $resultOfQuery->fetch_assoc();
return $getResult;
}
function getUserPicAddress($rollNo,$conn)
{
$getPicQuery = "SELECT userPic from userInfo where lower(rollNo) = '".strtolower($rollNo)."'";
$resultPicQuery = mysqli_query($conn,$getPicQuery);
$userPic = $resultPicQuery->fetch_assoc();
return $userPic;
}
function getSubjectId($subjectName,$conn)
{
$query = "SELECT subjectId from subjects where lower(subjectName)='".strtolower($subjectName)."'";
$resultOfQuery = mysqli_query($conn,$query);
$getResult = $resultOfQuery->fetch_assoc();
return $getResult;
}
function getQuestionDetail($questionId,$conn)
{
$query = "SELECT heading,description, dateOfQuestion,timeOfQuestion,subjectId,rollNo from questions where questionId=".$questionId;
$resultOfQuery = mysqli_query($conn,$query);
$getResult = $resultOfQuery->fetch_assoc();
return $getResult;
}
function getSubjectName($subjectId,$conn)
{
$query = "SELECT subjectName from subjects where lower(subjectId)='".strtolower($subjectId)."'";
$resultOfQuery = mysqli_query($conn,$query);
$getResult = $resultOfQuery->fetch_assoc();
return $getResult['subjectName'];
}
function getQuestionsId($rollNo,$limit,$offset,$conn)
{
$q = "SELECT questionId from questions where lower(rollNo)= '".strtolower($rollNo)."'
order by dateOfQuestion,timeOfQuestion DESC LIMIT $limit OFFSET $offset";
$res = mysqli_query($conn,$q);
return $res;
}
function postComment($rollNo,$questionId,$commentData,$conn)
{
date_default_timezone_set("Asia/Karachi");
$timeOfComment=date("h:i:sa");
$dateOfComment=date("y/m/d",time());
$insertQuery = "INSERT INTO comments(rollNo,questionId,commentData,timeOfComment,dateOfComment)
VALUES ('".$rollNo."',".$questionId.",'".$commentData."','".$timeOfComment."','".$dateOfComment."')";
$res=mysqli_query($conn,$insertQuery);
}
function getCommentData($commentId,$conn)
{
$getQuery = "SELECT rollNo,timeOfComment,dateOfComment,commentData from comments where commentId = ".$commentId;
$res = mysqli_query($conn,$getQuery);
$resu = $res->fetch_assoc();
return $resu;
}
function displayComment($commentId,$conn)
{
$commentData = getCommentData($commentId,$conn);
$rollNo = $commentData['rollNo'];
$userPic = getUserPicAddress($rollNo,$conn);
$userName = getFisrtAndLastName($rollNo,$conn);
$commentDescription = $commentData['commentData'];
$commentTime = $commentData['timeOfComment'];
$commentTime = $commentTime[0].$commentTime[1].$commentTime[2].$commentTime[3].$commentTime[4];
$commentDate = $commentData['dateOfComment'];
date_default_timezone_set("Asia/Karachi");
$d = date('Y-M-d',time());
$date = date_create($d);
$date2 = date_create($commentDate);
$diff=date_diff($date2,$date);
if($diff->format("%R%a days")<1)
{
$commentDate = "Today";
}
else if($diff->format("%R%a days")==1)
{
$commentDate = "Yesterday";
}
echo "<div class='card-comment'>
<img class='img-circle img-sm' src='".$userPic['userPic']."' alt='User Image'>
<div class='comment-text'>
<span class='username'>".$userName['firstName']." ".$userName['lastName']."
<span class='text-muted float-right'>".$commentTime." ".$commentDate."</span>
</span><!-- /.username -->
".$commentDescription."
</div>
</div>";
}
function getCommentsId($questionId,$conn)
{
$getQuery = "SELECT commentId from comments where questionId = ".$questionId." ORDER BY dateOfComment,timeOfComment";
$res = mysqli_query($conn,$getQuery);
return $res;
}
function addToYourFeedOne($rollNo,$conn)
{
$userPic = getUserPicAddress($rollNo,$conn);
$userName = getFisrtAndLastName($rollNo,$conn);
echo "<div class='row'>
<div class='col-md-2'>
<img class='img-circle' width='100%' src='".$userPic['userPic']."' alt='User Image'>
</div>
<div class='col-md-6'>
<a href='profile.php?id=".$rollNo."' style='font-size: 14px;'>".$userName['firstName']." ".$userName['lastName']."</a>
</div>
<div class='col-md-2'>
<a href='#' class='btn btn-primary btn-sm' style='font-size: 12px;'><i class='fa fa-plus'></i> Follow</a>
</div>
</div>
<p></p>";
}
function getCampus($rollNo)
{
if($rollNo[7]=='0')
{
return "Old Campus";
}
return "New Campus";
}
function getDegree($rollNo)
{
if($rollNo[1]=='S')
{
return "Software Engineering";
}
if($rollNo[1]=='C')
{
return "Computer Science";
}
return "Information Technology";
}
function getNoOfQuestionAsked($rollNo,$conn)
{
$getQuery = "SELECT questionId from questions where rollNo = '".$rollNo."'";
$res = mysqli_query($conn,$getQuery);
return mysqli_num_rows($res);
}
function getUserData($rollNo,$conn)
{
$getQuery = "SELECT * from userInfo where rollNo = '".$rollNo."'";
$res = mysqli_query($conn,$getQuery);
return $res->fetch_assoc();
}
function postAnswer($rollNo,$questionId,$description,$conn)
{
date_default_timezone_set("Asia/Karachi");
$timeOfAnswer=date("h:i:sa");
$dateOfAnswer=date("y/m/d",time());
$insertQuery = "INSERT INTO answers (rollNo,questionId,description,timeOfAnswer,dateOfAnswer) VALUES
('".$rollNo."',".$questionId.",'".$description."','".$timeOfAnswer."','".$dateOfAnswer."');";
$res = mysqli_query($conn,$insertQuery);
}
function getAnswerDetail($questionId,$conn)
{
$getQuery = "SELECT * FROM answers WHERE questionId = ".$questionId;
$res = mysqli_query($conn,$getQuery);
return $res;
}
function getAnswerVoteType($rollNo,$answerId,$conn)
{
$quer = "SELECT voteType from voteAnswer WHERE rollNo = '".$rollNo."' AND answerId = ".$answerId;
$res = mysqli_query($conn,$quer);
return $res;
}
function displayAnswer($roll,$rollNo,$desc,$time,$date1,$answerId,$conn)
{
$getUserDetail = getUserData($rollNo,$conn);
date_default_timezone_set("Asia/Karachi");
$d = date('Y-M-d',time());
$date = date_create($d);
$date2 = date_create($date1);
$diff=date_diff($date2,$date);
if($diff->format("%R%a days")<1)
{
$date1 = "Today";
}
else if($diff->format("%R%a days")==1)
{
$date1 = "Yesterday";
}
$voteType = getAnswerVoteType($roll,$answerId,$conn);
$resultVote = mysqli_fetch_assoc($voteType);
echo " <div class='card-header'>
<div class='user-block'>
<img class='img-circle' src='".$getUserDetail['userPic']."' alt='User Image'>
<form>
<span class='username'><a href='profile.php?id=".$rollNo."'>".$getUserDetail['firstName']." ".$getUserDetail['lastName']." </a> </span>
</form>
<span class='description' >answerd at -".$time." ".$date1."</span>
</div>";
if($roll==$rollNo)
{
echo "
<div class='card-tools'>
<button type='button' class='btn btn-tool' data-toggle='modal' data-target='#exampleModalCenter'
id='".$answerId."' onclick='deleteAnswer(this.id)'
><i class='fa fa-times'></i>
</button>
</div>";
}
echo "
</div>
<div class='card-body' style='border: 0px solid black;;'>
<p >".$desc."</p>";
if($resultVote=='')
{
echo "<button type='button' class='btn btn-default btn-sm ' id='".$answerId."l' onclick='likeAnswer(this.id)'><i class='fa fa-thumbs-o-up' ></i> Like</button>
<button type='button' class='btn btn-default btn-sm ' id='".$answerId."d' onclick='disLikeAnswer(this.id)'><i class='fa fa-thumbs-o-down' ></i> Dislike</button>";
}
else if($resultVote['voteType']==1)
{
echo "<button type='button' class='btn btn-default btn-sm ' id='".$answerId."l' onclick='likeAnswer(this.id)'
style='color:blue'><i class='fa fa-thumbs-o-up' ></i> Like</button>
<button type='button' class='btn btn-default btn-sm ' id='".$answerId."d' onclick='disLikeAnswer(this.id)'><i class='fa fa-thumbs-o-down' ></i> Dislike</button>";
}
else if($resultVote['voteType']==-1)
{
echo "<button type='button' class='btn btn-default btn-sm ' id='".$answerId."l' onclick='likeAnswer(this.id)'
><i class='fa fa-thumbs-o-up' ></i> Like</button>
<button type='button' class='btn btn-default btn-sm ' id='".$answerId."d' onclick='disLikeAnswer(this.id)'
style='color:red'><i class='fa fa-thumbs-o-down'></i> Dislike</button>";
}
echo " </div>
<br>";
}
function noOfComments($questionId,$conn)
{
$quer = "SELECT commentId from comments where questionId = ".$questionId;
$res = mysqli_query($conn,$quer);
return mysqli_num_rows($res);
}
function getSearchResults($search,$conn)
{
$search1 = mysqli_real_escape_string($conn,$search);
$searchQuery = "SELECT rollNo,firstName,lastName,userPic from userInfo where rollNo LIKE '%".$search1."%' OR firstName LIKE '%".$search1."%' OR lastName LIKE '%".$search1."%'";
$getResult = mysqli_query($conn,$searchQuery);
return $getResult;
}
function getQuestionSearchResults($search,$conn)
{
$search1 = mysqli_real_escape_string($conn,$search);
$searchQuery = "SELECT rollNo,heading,questionId from questions where heading LIKE '%".$search1."%'";
$getResult = mysqli_query($conn,$searchQuery);
return $getResult;
}
function follow($rollNoToFollow,$myRollNo,$conn)
{
$insertQuery = "INSERT INTO followers (rollNo,followerId) VALUES
('".$rollNoToFollow."','".$myRollNo."');";
$res = mysqli_query($conn,$insertQuery);
}
function getFollowers($rollNo,$conn)
{
$searchQuery = "SELECT followerId from followers where rollNo ='".$rollNo."'";
$getResult = mysqli_query($conn,$searchQuery);
return $getResult;
}
function getFollowing($rollNo,$conn)
{
$searchQuery = "SELECT rollNo from followers where followerId ='".$rollNo."'";
$getResult = mysqli_query($conn,$searchQuery);
return $getResult;
}
function isFollowing($frollNo,$rollNo,$conn)
{
$getQuery = "SELECT followerId from followers where rollNo = '".$rollNo."' AND followerId = '".$frollNo."'";
$res = mysqli_query($conn,$getQuery);
return mysqli_num_rows($res)==1;
}
function searchDisplay($fRollNo,$rollNo,$name,$userPic,$conn)
{
echo "<div class='row' style='margin-left: 10px;margin-top: 15px;'>
<div class='col-md-2'>
<img class='img-circle' style='height: 70%;width:70%;'; src='".$userPic."' alt=''>
</div>
<div class='col-md-8'>
<span class='username'><a href='profile.php?id=".$rollNo."'><b>".$name."</b></a> </span><br>
".getDegree($rollNo)."<br>
<i class='fa fa-map-marker mr-1'></i> <span class='description' style='color: rgba(0,0,0,.6);'>".getCampus($rollNo)."</span>
<hr size='90'>
</div>
<div class='col-md-2' id='".$rollNo."'>";
if($fRollNo!=$rollNo)
{
if (isFollowing($fRollNo, $rollNo, $conn) == 1)
{
echo "<button type='submit' class='btn btn-outline-primary btn-sm' id='" . $rollNo . "fol' onclick='followS(this.id)' style='font-size: 17px';>unfollow</button>";
echo " <hr size='30' style='margin-top: 53px;margin-left: -15px;'>";
}
else
{
echo "
<button type='submit' name='submit' id='" . $rollNo . "fol' class='btn btn-primary btn-sm' onclick='followS(this.id)' style='font-size: 17px;'>Follow</button>
";
echo " <hr size='30' style='margin-top: 53px;margin-left: -15px;'>";
}
}
echo"
</div>
</div>";
}
function searchQuestionDisplay($rollNo,$questionId,$heading,$conn)
{
$userName = getFisrtAndLastName($rollNo,$conn);
echo "<div class='row' style='margin-left: 5px;margin-top: 10px;'>
<div class='col-md-8' style='margin-top: 2px;'>
<a href='completequery.php?qid=".$questionId."' style='color: black;'><h3><b>".$heading."</b></h3></a>
<span style='color: rgba(0,0,0,.6);font-size: 12px;';>asked by</span> <a href='profile.php?id=".$rollNo."'><b>".$userName['firstName']." ".$userName['lastName']."</b></a>
</div>
<div class='col-md-2 ' >
<p></p>
<span class='bg-info' style='padding: 18px 18px 18px 18px;border-radius: 50%;color: white;'>".noOfAnswers($questionId,$conn)."</span><br><p></p><span style='font-size: 12px;'>Answers</span>
</div>
<div class='col-md-2 ' >
<p></p>
<span style='padding: 18px 10px 18px 10px;border-radius: 50%;background-color: #D57108;color:white;'>122</span><br><p></p><span style='font-size: 12px;'><span style='color: white;'>h</span>Votes </span>
</div>
</div>
<div class='row'>
<div class='col-md-2'>
</div>
<div class='col-md-10'>
<hr size='30'>
</div>
</div>";
}
function noOfAnswers($questionId,$conn)
{
$quer = "SELECT answerId from answers where questionId = ".$questionId;
$res = mysqli_query($conn,$quer);
return mysqli_num_rows($res);
}
function displaySingleQuery($roll,$picAddress,$questionId,$conn)
{
$questionDetail = getQuestionDetail($questionId,$conn);
$headingOfQuestion = $questionDetail['heading'];
$descriptionOfQuestion = $questionDetail['description'];
$res = getCommentsId($questionId,$conn);
$numOfComments = mysqli_num_rows($res);
$votes =countQueryVotes($questionId,$conn);
if($votes=='')
{
$votes="No vote";
}
else if($votes==1)
{
$votes="1 vote";
}
else
{
$votes = $votes." votes";
}
$voteType = getQueryVote($roll,$questionId,$conn);
$resultVote = mysqli_fetch_assoc($voteType);
echo "<div class='card card-widget'>
<!-- /.card-header -->
<div class='card-body'>
<div class='row'>
<div class='col-md-11'>
<h2><b>".$headingOfQuestion."</b></h2>
</div>
";
if($roll==$questionDetail['rollNo'])
{
echo "
<div class='card-tools col-md-1'>
<button type='button' class='btn btn-tool' data-toggle='modal' data-target='#exampleModalCenterQuery'
id='".$questionId."' onclick='deleteQuery(this.id)'
><i class='fa fa-times'></i>
</button>
</div>";
}
echo "
</div>
<p>".$descriptionOfQuestion."</p>";
if($resultVote=='')
{
echo "<button type='button' class='btn btn-default btn-sm ' id='".$questionId."l' onclick='likeQuery(this.id)'><i class='fa fa-thumbs-o-up' id='".$questionId."y'></i> Like</button>
<button type='button' class='btn btn-default btn-sm ' id='".$questionId."d' onclick='disLikeQuery(this.id)'><i class='fa fa-thumbs-o-down' id='".$questionId."n'></i> Dislike</button>";
}
else if($resultVote['voteType']==1)
{
echo "<button type='button' class='btn btn-default btn-sm ' id='".$questionId."l' onclick='likeQuery(this.id)'
style='color:blue'><i class='fa fa-thumbs-o-up' ></i> Like</button>
<button type='button' class='btn btn-default btn-sm ' id='".$questionId."d' onclick='disLikeQuery(this.id)'><i class='fa fa-thumbs-o-down' ></i> Dislike</button>";
}
else if($resultVote['voteType']==-1)
{
echo "<button type='button' class='btn btn-default btn-sm ' id='".$questionId."l' onclick='likeQuery(this.id)'
><i class='fa fa-thumbs-o-up' ></i> Like</button>
<button type='button' class='btn btn-default btn-sm ' id='".$questionId."d' onclick='disLikeQuery(this.id)'
style='color:red'><i class='fa fa-thumbs-o-down'></i> Dislike</button>";
}
echo" <span class='float-right text-muted'> ".$votes." - ".$numOfComments." Comments - ".noOfAnswers($questionId,$conn)." Answers</span>
</div>
<!-- /.card-body -->
<div class='card-footer card-comments' id='".$questionId."comment'>";
if($numOfComments)
{
while($row = mysqli_fetch_assoc($res))
{
displayComment($row['commentId'],$conn);
}
}
echo " <!-- /.card-comment -->
</div>
<!-- /.card-footer -->
<div class='card-footer'>
<img class='img-fluid img-circle img-sm' src='".getUserPicAddress($roll,$conn)['userPic']."' alt='Alt Text'>
<div class='img-push'>
<input type='hidden' name='questionId' value='".$questionId."'>
<input type='text' name='commentData' id='".$questionId."c' onkeypress='postComment(this.id,event)' class='form-control form-control-sm' placeholder='Press enter to post comment'>
</div>
</div>
</div>";
}
function getTimelineQuestionId($rollNo,$limit,$offset,$conn)
{
$q = "SELECT questionId from questions where rollNo= '".$rollNo."' OR rollNo In (SELECT rollNo from followers where followerId = '".$rollNo."')
LIMIT $limit OFFSET $offset";
$res = mysqli_query($conn,$q);
return $res;
}
function getQueryVote($rollNo,$questionId,$conn)
{
$quer = "SELECT voteType from voteQuery WHERE rollNo = '".$rollNo."' AND questionId = ".$questionId;
$res = mysqli_query($conn,$quer);
return $res;
}
function countQueryVotes($questionId,$conn)
{
$quer = "SELECT voteType from voteQuery WHERE questionId = ".$questionId." AND voteType = 1";
$res = mysqli_query($conn,$quer);
$querN = "SELECT voteType from voteQuery WHERE questionId = ".$questionId." AND voteType = -1";
$resN = mysqli_query($conn,$querN);
return mysqli_num_rows($res)-mysqli_num_rows($resN);
}
function displayQuery($roll,$questionId,$conn)
{
$questionDetail = getQuestionDetail($questionId,$conn);
$rollNo = $questionDetail['rollNo'];
$questionFrom = $rollNo;
$userName = getFisrtAndLastName($rollNo,$conn);
$userPic = getUserPicAddress($rollNo,$conn);
$headingOfQuestion = $questionDetail['heading'];
$descriptionOfQuestion = $questionDetail['description'];
$timeOfQuery = $questionDetail['timeOfQuestion'];
$dateOfQuery = $questionDetail['dateOfQuestion'];
$subject = getSubjectName($questionDetail['subjectId'],$conn);
$noOfAnswers = noOfAnswers($questionId,$conn);
if($noOfAnswers==0)
{
$noOfAnswers = "No";
}
$res = getCommentsId($questionId,$conn);
$numOfComments = mysqli_num_rows($res);
$comm = $numOfComments;
if($comm==0)
{
$comm = "No";
}
$votes =countQueryVotes($questionId,$conn);
if($votes=='')
{
$votes="No vote";
}
else if($votes==1)
{
$votes="1 vote";
}
else
{
$votes = $votes." votes";
}
$voteType = getQueryVote($roll,$questionId,$conn);
$resultVote = mysqli_fetch_assoc($voteType);
echo "<div class='card card-widget' id='".$questionId."'>
<div class='card-header'>
<div class='user-block'>
<img class='img-circle' src='".$userPic['userPic']."' alt='User Image'>
<form>
<span class='username'><a href='profile.php?id=".$rollNo."'>".$userName['firstName']." ".$userName['lastName']."</a> asked for <span style='color:#007bff;'>".$subject."</span> </span>
</form>
<span class='description' >posted at - ".$timeOfQuery." ".$dateOfQuery."</span>
</div>
";
if($roll==$rollNo)
{
echo "
<div class='card-tools'>
<button type='button' class='btn btn-tool' data-toggle='modal' data-target='#exampleModalCenter'
id='".$questionId."' onclick='deleteQuery(this.id)'
><i class='fa fa-times'></i>
</button>
</div>";
}
echo "
</div>
<!-- /.card-header -->
<div class='card-body'>
<h4><b>".$headingOfQuestion."</b></h4>
<p>".$descriptionOfQuestion."<a href='completequery.php?qid=".$questionId."'>more...</a></p>
";
if($resultVote=='')
{
echo "<button type='button' class='btn btn-default btn-sm ' id='".$questionId."l' onclick='likeQuery(this.id)'><i class='fa fa-thumbs-o-up' id='".$questionId."y'></i> Like</button>
<button type='button' class='btn btn-default btn-sm ' id='".$questionId."d' onclick='disLikeQuery(this.id)'><i class='fa fa-thumbs-o-down' id='".$questionId."n'></i> Dislike</button>";
}
else if($resultVote['voteType']==1)
{
echo "<button type='button' class='btn btn-default btn-sm ' id='".$questionId."l' onclick='likeQuery(this.id)'
style='color:blue'><i class='fa fa-thumbs-o-up' ></i> Like</button>
<button type='button' class='btn btn-default btn-sm ' id='".$questionId."d' onclick='disLikeQuery(this.id)'><i class='fa fa-thumbs-o-down' ></i> Dislike</button>";
}
else if($resultVote['voteType']==-1)
{
echo "<button type='button' class='btn btn-default btn-sm ' id='".$questionId."l' onclick='likeQuery(this.id)'
><i class='fa fa-thumbs-o-up' ></i> Like</button>
<button type='button' class='btn btn-default btn-sm ' id='".$questionId."d' onclick='disLikeQuery(this.id)'
style='color:red'><i class='fa fa-thumbs-o-down'></i> Dislike</button>";
}
echo " <span class='float-right text-muted'> ".$votes." - ".$comm." Comments - ".$noOfAnswers." Answers</span>
</div>
<!-- /.card-body -->
<div class='card-footer card-comments' id='".$questionId."comment'>";
if($numOfComments==1)
{
$row = mysqli_fetch_assoc($res);
displayComment($row['commentId'],$conn);
}
else if($numOfComments>=2)
{
$row = mysqli_fetch_assoc($res);
displayComment($row['commentId'],$conn);
$row = mysqli_fetch_assoc($res);
displayComment($row['commentId'],$conn);
}
echo " <!-- /.card-comment -->
</div>
<!-- /.card-footer -->
<div class='card-footer'>
<img class='img-fluid img-circle img-sm' src='".getUserPicAddress($roll,$conn)['userPic']."' alt='Alt Text'>
<div class='img-push'>
<input type='hidden' name='questionFrom' value='".$questionFrom."'>
<input type='hidden' name='questionId' value='".$questionId."'>
<input type='text' name='commentData' id='".$questionId."c' onkeypress='postComment(this.id,event)' class='form-control form-control-sm' placeholder='Press enter to post comment'>
</div>
</div>
</div>";
}
function sendMessage($rollNo,$messageTo,$messageData,$conn)
{
date_default_timezone_set("Asia/Karachi");
$timeOfMessage=date("h:i:sa");
$dateOfMessage=date("y/m/d",time());
$insertQuery = "INSERT INTO messages (messageFrom,messageTo,timeOfMessage,dateOfMesssage,messageData) VALUES
('".$rollNo."','".$messageTo."','".$timeOfMessage."','".$dateOfMessage."','".$messageData."');";
$res = mysqli_query($conn,$insertQuery);
}
function leftMessageDisplay($message,$date,$time)
{
$date = getDateInFormat($date);
$time = $time[0].$time[1].$time[2].$time[3].$time[4];
echo "<div class='direct-chat-msg'>
<!-- /.direct-chat-info -->
<!-- /.direct-chat-img -->
<div class='direct-chat-text' data-toggle='tooltip' data-placement='left' title='".$date." ".$time."' style='font-size: 14px;'>".
$message
."</div>
<!-- /.direct-chat-text -->
</div>";
}
function isEmoji($message)
{
if($message[0]=='&')
{
return 1;
}
return 0;
}
function rightMessageDisplay($userDataOfMessageTo,$userName,$message,$date,$time)
{
$dateExact = getDateInFormat($date);
$timeExact = $time[0].$time[1].$time[2].$time[3].$time[4];
echo "<div class='direct-chat-msg right'>
<div class='direct-chat-info clearfix'>
<span class='direct-chat-name float-right'>".$userName."</span>
</div>
<!-- /.direct-chat-info -->
<img class='direct-chat-img' src='".$userDataOfMessageTo['userPic']."' alt='Message User Image'>
<!-- /.direct-chat-img -->
<div class='direct-chat-text' title='".$dateExact." ".$timeExact."' style='font-size: 14px;'>".
$message
."</div>
<!-- /.direct-chat-text -->
</div>
<!-- /.direct-chat-msg -->
";
}
function getMessageData($rollNo,$messageTo,$conn)
{
$getQuery = "SELECT messageFrom,messageTo,dateOfMesssage,timeOfMessage,messageData from messages WHERE
(lower(messageFrom) ='".strtolower($rollNo)."' and lower(messageTo) ='".strtolower($messageTo)."') OR
(lower(messageFrom) ='".strtolower($messageTo)."' and lower(messageTo) ='".strtolower($rollNo)."')
ORDER BY dateOfMesssage,timeOfMessage";
$result = mysqli_query($conn,$getQuery);
return $result;
}
function getMessageDataOfUnseen($rollNo,$messageTo,$conn)
{
$getQuery = "SELECT * from messages WHERE
lower(messageFrom) ='".strtolower($messageTo)."' and lower(messageTo) ='".strtolower($rollNo)."' and seen=0
ORDER BY dateOfMesssage,timeOfMessage";
$result = mysqli_query($conn,$getQuery);
return $result;
}
function makeUnseenSeen($rollNo,$messageTo,$conn)
{
$getQuery = "UPDATE messages set seen =1 WHERE seen=0 AND
((lower(messageFrom) ='".strtolower($rollNo)."' and lower(messageTo) ='".strtolower($messageTo)."') OR
(lower(messageFrom) ='".strtolower($messageTo)."' and lower(messageTo) ='".strtolower($rollNo)."'));";
mysqli_query($conn,$getQuery);
}
function displayMessageBox($rollNo,$messageTo,$conn)
{
$userData = getUserData($rollNo,$conn);
$userDataOfMessageTo = getUserData($messageTo,$conn);
$userDataOfMessageToName = $userDataOfMessageTo['firstName']." ".$userDataOfMessageTo['lastName'];
echo "
<div class='chatbox' >
<div class='card card-primary direct-chat direct-chat-primary' style='border-radius: 0px;margin-bottom: 0px !important;'>
<div class='card-header' style='border-radius: 0px;padding: .4rem 1.25rem;'>
<h3 class='card-title'>Direct Chat</h3>
<div class='card-tools'>
<span data-toggle='tooltip' title='3 New Messages' class='badge bg-primary'>3</span>
<button type='button' class='btn btn-tool' data-widget='collapse'><i class='fa fa-minus'></i>
</button>
<button type='button' class='btn btn-tool' data-toggle='tooltip' title='Contacts' data-widget='chat-pane-toggle'>
<i class='fa fa-comments'></i></button>
<button type='button' class='btn btn-tool' data-widget='remove'><i class='fa fa-times'></i>
</button>
</div>
</div>
<!-- /.card-header -->
<div class='card-body'>
<!-- Conversations are loaded here -->
<div class='direct-chat-messages' id='directMessage'>
<!-- Message. Default to the left -->
";
echo "<!--/.direct-chat-messages-->
</div>
<!-- Contacts are loaded here -->
<div class='direct-chat-contacts'>
<!-- /.contatcts-list -->
</div>
<!-- /.direct-chat-pane -->
</div>
<!-- /.card-body -->
<div class='card-footer'>
<form action='ajax/messageSend.php' method='post' _lpchecked='1'>
<div class='input-group'>
<input type='text' id='message' placeholder='Type a message ...' class='form-control'>
<input type='hidden' value='".$messageTo."' id='messageTo'>
<span class='input-group-append'>
<button id='submit' class='btn btn-primary'>Send</button>
</span>
</div>
</form>
</div>
<!-- /.card-footer-->
</div>
</div>";
}
function singlePersonMessage($rollNo,$conn)
{
$userData = getUserData($rollNo,$conn);
echo "<div class='card-header chat' id = '".$rollNo."' onclick='showMessageBox(this.id)'
style='cursor: pointer;height: 47px;width: 300px;margin-left: -7px;border-bottom: 1px solid #f4f5f9;'>
<div class='user-block'>
<input type='hidden' value='".$rollNo."' id='rollNo'>
<img class='img-circle' src='".$userData['userPic']."' style='margin-top:-10px;' alt='User Image'>
<span style='font-size: 17px;margin-left: 10px;'>".$userData['firstName']." ".$userData['lastName']."</span>
</div>
</div>";
}
function followedNotification($rollNo,$dateTime,$conn)
{
$d = getDateInFormat($dateTime);
$t = getTimeFormat($dateTime);
$name = getFisrtAndLastName($rollNo,$conn);
echo "<li>
<i class='fa fa-user bg-info'></i>
<div class='timeline-item'>
<span class='time'><i class='fa fa-clock-o'></i>".$t."</span>
<h3 class='timeline-header no-border'><a href='profile.php?id=".$rollNo."'>".$name['firstName']." ".$name['lastName']."</a> followed you</h3>
</div>
</li>";
}
function commentNotification($rollNo,$questionId,$dateTime,$commentData,$conn)
{
$d = getDateInFormat($dateTime);
$t = getTimeFormat($dateTime);
$name = getFisrtAndLastName($rollNo,$conn);
echo "
<li>
<i class='fa fa-comments bg-warning'></i>
<div class='timeline-item'>
<span class='time'><i class='fa fa-clock-o'></i> ".$t."</span>
<h3 class='timeline-header'><a href='profile.php?id=".$rollNo."'>".$name['firstName']." ".$name['lastName']."</a> commented on your post</h3>
<div class='timeline-body'>
".$commentData."
</div>
<div class='timeline-footer'>
<a href='completequery.php?qid=".$questionId."' class='btn btn-warning btn-flat btn-sm'>View comment</a>
</div>
</div>
</li>";
}
function queryNotification($rollNo,$questionId,$dateTime,$heading,$conn)
{
$d = getDateInFormat($dateTime);
$t = getTimeFormat($dateTime);
$name = getFisrtAndLastName($rollNo,$conn);
echo "
<li>
<i class='fa fa-envelope bg-primary'></i>
<div class='timeline-item'>
<span class='time'><i class='fa fa-clock-o'></i>".$t."</span>
<h3 class='timeline-header'><a href='profile.php?id=".$rollNo."'>".$name['firstName']." ".$name['lastName']."</a> aksed a question</h3>
<div class='timeline-body'>
".$heading."
</div>
<div class='timeline-footer'>
<a href='completequery.php?qid=".$questionId."' class='btn btn-primary btn-sm'>Read more</a>
</div>
</div>
</li>
";
}
function insertCommentNotification($rollNo,$whomeDid,$questionId,$commentData,$conn)
{
date_default_timezone_set("Asia/Karachi");
$dateOfNotification=date("Y-m-d h:i:sa",time());
$insertQuery = "INSERT INTO notifications (rollNo,notificationFrom,notificationLink,dateTimeOfNotification,notificationHeading,seen,
notificationType) VALUES
('".$rollNo."','".$whomeDid."',".$questionId.",'".$dateOfNotification."','".$commentData."',0,1)";
echo $insertQuery;
$res = mysqli_query($conn,$insertQuery);
}
function insertQueryNotification($rollNo,$whomeDid,$questionId,$heading,$conn)
{
date_default_timezone_set("Asia/Karachi");
$dateOfNotification=date("Y-m-d h:i:sa",time());
$insertQuery = "INSERT INTO notifications (rollNo,notificationFrom,notificationLink,dateTimeOfNotification,notificationHeading,seen,
notificationType) VALUES
('".$rollNo."','".$whomeDid."',".$questionId.",'".$dateOfNotification."','".$heading."',0,3)";
// echo $insertQuery;
$res = mysqli_query($conn,$insertQuery);
}
function insertFollowNotification($rollNo,$whomeDid,$conn)
{
date_default_timezone_set("Asia/Karachi");
$dateOfNotification=date("Y-m-d h:i:sa",time());
$insertQuery = "INSERT INTO notifications (rollNo,notificationFrom,dateTimeOfNotification,seen,
notificationType) VALUES
('".$rollNo."','".$whomeDid."','". $dateOfNotification."',0,2)";
$res = mysqli_query($conn,$insertQuery);
}
function getNotificationData($rollNo,$conn)
{
$getQuery = "SELECT * from notifications where rollNo = '".$rollNo."'ORDER BY dateTimeOfNotification DESC" ;
$res = mysqli_query($conn,$getQuery);
return $res;
}
?>