-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprocess_data.php
1868 lines (1798 loc) · 136 KB
/
process_data.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
session_start();
$jsonString = file_get_contents('php://input');
$data = json_decode($jsonString, true);
if ($data['request'] == "request_username") {
echo $_SESSION["username"];
} else if ($data['request'] == "user_status") {
if (!isset($_SESSION["loggedin"]) || $_SESSION["loggedin"] !== true) {
echo "false";
} else if ($_SESSION["role"] == "admin") {
echo "admin";
}
} else if ($data["request"] == "username_change" && isset($_SESSION["loggedin"]) && $_SESSION["loggedin"] == true) {
require_once "old_config.php";
$new_username = $data['username'];
$sql = "SELECT username FROM user WHERE username = ?";
if ($stmt = mysqli_prepare($conn, $sql)) {
mysqli_stmt_bind_param($stmt, "s", $new_username);
if (mysqli_stmt_execute($stmt)) {
mysqli_stmt_store_result($stmt);
if (mysqli_stmt_num_rows($stmt) == 1) {
echo "Username Unavailable!";
mysqli_stmt_close($stmt);
} else {
mysqli_stmt_close($stmt);
$sql = "SELECT id, username, password, role FROM user WHERE username = ?";
if ($stmt = mysqli_prepare($conn, $sql)) {
mysqli_stmt_bind_param($stmt, "s", $_SESSION['username']);
if (mysqli_stmt_execute($stmt)) {
mysqli_stmt_store_result($stmt);
if (mysqli_stmt_num_rows($stmt) == 1) {
mysqli_stmt_bind_result($stmt, $id, $username, $hashed_password, $role);
if (mysqli_stmt_fetch($stmt)) {
if (password_verify($data['password'], $hashed_password)) {
mysqli_stmt_close($stmt);
$sql = "UPDATE user SET username = ? WHERE id = ?";
if ($stmt = mysqli_prepare($conn, $sql)) {
// Bind variables to the prepared statement as parameters
mysqli_stmt_bind_param($stmt, "si", $data['username'], $_SESSION['id']);
// Attempt to execute the prepared statement
if (mysqli_stmt_execute($stmt)) {
// Username updated successfully. Destroy the session, and redirect to login page
$_SESSION["username"] = $data['username'];
echo "Success";
} else {
echo "Oops! Something went wrong. Please try again later.";
}
// Close statement
mysqli_stmt_close($stmt);
}
} else {
echo "Incorrect Password!";
}
}
}
}
}
}
} else {
echo "Oops! Something went wrong. Please try again later.";
}
// Close statement
mysqli_close($conn);
}
} else if ($data["request"] == "password_change" && isset($_SESSION["loggedin"]) && $_SESSION["loggedin"] == true) {
require_once "old_config.php";
$sql = "SELECT password FROM user WHERE username = ?";
if ($stmt = mysqli_prepare($conn, $sql)) {
mysqli_stmt_bind_param($stmt, "s", $_SESSION['username']);
if (mysqli_stmt_execute($stmt)) {
mysqli_stmt_store_result($stmt);
if (mysqli_stmt_num_rows($stmt) == 1) {
mysqli_stmt_bind_result($stmt, $hashed_password);
if (mysqli_stmt_fetch($stmt)) {
if (password_verify($data['current_password'], $hashed_password)) {
mysqli_stmt_close($stmt);
$sql = "UPDATE user SET password = ? WHERE id = ?";
if ($stmt = mysqli_prepare($conn, $sql)) {
mysqli_stmt_bind_param($stmt, "si", $param_password, $_SESSION['id']);
$param_password = password_hash($data["new_password"], PASSWORD_DEFAULT);
if (mysqli_stmt_execute($stmt)) {
echo "Success";
} else {
echo "Oops! Something went wrong. Please try again later.";
}
// Close statement
mysqli_stmt_close($stmt);
}
} else {
echo "Incorrect Password!";
}
}
}
}
} else {
echo "Oops! Something went wrong. Please try again later.";
}
// Close statement
mysqli_close($conn);
} else if ($data['request'] == "upload_post_data" && isset($_SESSION["loggedin"]) && $_SESSION["loggedin"] == true) {
require_once "new_config.php";
$post_text = $data['question'];
$poll_type = $data['poll_choice'];
date_default_timezone_set('Europe/Athens');
$param_date = date('Y/m/d H:i:s', time());
if ($poll_type == "yes-no") {
$param_poll_type = 1;
} elseif ($poll_type == "rating") {
$param_poll_type = 2;
} elseif ($poll_type == "approval") {
$param_poll_type = 3;
} elseif ($poll_type == "ranking") {
$param_poll_type = 4;
}
if ($data['time_limiter'] == "") {
$data['time_limiter'] = null;
}
if (!isset($data['event_lat'])) {
$data['event_lat'] = null;
$data['event_long'] = null;
}
if (count($data['poll_choices_options']) > 0) {
$poll_choices_options = $data['poll_choices_options'];
for ($i = 0; $i < 20; $i++) {
if ($i + 1 > count($data['poll_choices_options'])) {
array_push($poll_choices_options, null);
}
}
$stmt = $conn->prepare("INSERT INTO posts (user_id, poll_type, post_category, post_text, post_date, post_expiration_date, event_lat, event_long, event_radius,
choice_one_name, choice_two_name, choice_three_name, choice_four_name, choice_five_name, choice_six_name, choice_seven_name, choice_eight_name, choice_nine_name,
choice_ten_name, choice_eleven_name, choice_twelve_name, choice_thirteen_name, choice_fourteen_name, choice_fifteen_name, choice_sixteen_name,
choice_seventeen_name, choice_eighteen_name, choice_nineteen_name, choice_twenty_name)
VALUES (:users_id, :poll_type, :post_category, :post_text, :post_date, :post_expiration_date, :event_lat, :event_long, :event_radius, :choice_one, :choice_two,
:choice_three, :choice_four, :choice_five, :choice_six, :choice_seven, :choice_eight, :choice_nine, :choice_ten, :choice_eleven, :choice_twelve, :choice_thirteen,
:choice_fourteen, :choice_fifteen, :choice_sixteen, :choice_seventeen, :choice_eighteen, :choice_nineteen, :choice_twenty)");
$stmt->execute([
":users_id" => $_SESSION["id"], ":poll_type" => $param_poll_type, ":post_category" => $data['post_category'], ":post_text" => $post_text,
":post_date" => $param_date, ":post_expiration_date" => $data['time_limiter'], ":event_lat" => $data['event_lat'], ":event_long" => $data['event_long'],
":event_radius" => $data['event_rad'], ":choice_one" => $poll_choices_options[0], ":choice_two" => $poll_choices_options[1],
":choice_three" => $poll_choices_options[2], ":choice_four" => $poll_choices_options[3], ":choice_five" => $poll_choices_options[4],
":choice_six" => $poll_choices_options[5], ":choice_seven" => $poll_choices_options[6], ":choice_eight" => $poll_choices_options[7],
":choice_nine" => $poll_choices_options[8], ":choice_ten" => $poll_choices_options[9], ":choice_eleven" => $poll_choices_options[10],
":choice_twelve" => $poll_choices_options[11], ":choice_thirteen" => $poll_choices_options[12], ":choice_fourteen" => $poll_choices_options[13],
":choice_fifteen" => $poll_choices_options[14], ":choice_sixteen" => $poll_choices_options[15], ":choice_seventeen" => $poll_choices_options[16],
":choice_eighteen" => $poll_choices_options[17], ":choice_nineteen" => $poll_choices_options[18], ":choice_twenty" => $poll_choices_options[19]
]);
} else {
$stmt = $conn->prepare("INSERT INTO posts (user_id, poll_type, post_category, post_text, post_date, post_expiration_date, event_lat, event_long, event_radius)
VALUES (:users_id, :poll_type, :post_category, :post_text, :post_date, :post_expiration_date, :event_lat, :event_long, :event_radius)");
$stmt->execute([
":users_id" => $_SESSION["id"], ":poll_type" => $param_poll_type, ":post_category" => $data['post_category'], ":post_text" => $post_text,
":post_date" => $param_date, ":post_expiration_date" => $data['time_limiter'], ":event_lat" => $data['event_lat'], ":event_long" => $data['event_long'],
":event_radius" => $data['event_rad']
]);
}
$stmt = $conn->prepare("SELECT posts.post_number AS post_number, user.username AS username, polls.poll_id AS poll_id, categories.category_name AS category_name,
posts.post_text AS post_text, sum(chevron_vote.chevron_result) AS chevron_result, posts.post_date AS post_date,
COALESCE((SELECT chevron_vote.chevron_result FROM chevron_vote WHERE chevron_vote.user_id=:id AND chevron_vote.post_id=posts.post_number),0) AS user_chevron_result,
COALESCE((SELECT yes_no.answer_yes FROM yes_no WHERE yes_no.user_id=:id AND yes_no.post_id=posts.post_number),0) AS user_yes_answer,
COALESCE((SELECT yes_no.answer_no FROM yes_no WHERE yes_no.user_id=:id AND yes_no.post_id=posts.post_number),0) AS user_no_answer,
COALESCE((SELECT bookmarks.user_bookmark FROM bookmarks WHERE bookmarks.user_id=:id AND bookmarks.post_id=posts.post_number),0) AS user_bookmark,
posts.post_expiration_date AS post_expiration_date, posts.event_lat AS event_lat, posts.event_long AS event_long, posts.event_radius AS event_radius,
(posts_yes_no_info.number_of_yes-posts_yes_no_info.number_of_no) AS post_vote_result
FROM posts join user on posts.user_id = user.id join polls on posts.poll_type = polls.poll_id join categories
on posts.post_category = categories.category_id join chevron_vote ON posts.post_number = chevron_vote.post_id
join posts_yes_no_info ON posts.post_number=posts_yes_no_info.post_number
WHERE posts.user_id = :id AND posts.post_date = :post_date");
$stmt->execute([":id" => $_SESSION["id"], "post_date" => $param_date]);
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
$new_data =
array(
$row["post_number"], $row["username"], $row["poll_id"], $row["category_name"], $row["post_text"], $row["chevron_result"],
$row["post_date"], $row["user_chevron_result"], $row["user_yes_answer"], $row["user_no_answer"], $row["user_bookmark"], $row["post_expiration_date"],
$row["event_lat"], $row["event_long"], $row["event_radius"], $row["post_vote_result"], $_SESSION["username"], "0", "0", "0", "0"
);
}
echo json_encode($new_data);
} else if ($data['request'] == "get_post_data") {
require "new_config.php";
$post_data = array();
if (!isset($data["user_search"])) {
$user_search = "%";
} else {
$user_search = str_replace(["=", "%", "_"], ["==", "=%", "=_"], $data["user_search"]);
}
if (!isset($data["filter_preferred_categories"])) {
$filter_preferred_categories = ".";
} else {
for ($i = 0; $i < count($data["filter_preferred_categories"]); $i++) {
if ($i == 0 && count($data["filter_preferred_categories"]) == 1) {
$filter_preferred_categories = "[[:<:]]" . $data["filter_preferred_categories"][$i] . "[[:>:]]";
} else if ($i == 0 && count($data["filter_preferred_categories"]) > 1) {
$filter_preferred_categories = "[[:<:]]" . $data["filter_preferred_categories"][$i] . "[[:>:]]|";
} else if (count($data["filter_preferred_categories"]) > 1 && $i < count($data["filter_preferred_categories"]) - 1) {
$filter_preferred_categories .= "[[:<:]]" . $data["filter_preferred_categories"][$i] . "[[:>:]]|";
} else if (count($data["filter_preferred_categories"]) > 1 && $i == count($data["filter_preferred_categories"]) - 1) {
$filter_preferred_categories .= "[[:<:]]" . $data["filter_preferred_categories"][$i] . "[[:>:]]";
}
}
}
if (!isset($data["filter_search"])) {
$filter_search = "%";
} else {
$filter_search = str_replace(["=", "%", "_"], ["==", "=%", "=_"], $data["filter_search"]);
$filter_search = "%" . $filter_search . "%";
}
if (!isset($data["filter_filter"][0])) {
$filter_filter_time = array("2020-01-01 00:00", "2090-01-01 00:00");
} else {
$filter_filter_time = explode(",", $data["filter_filter"][0]);
}
if (!isset($data["filter_filter"][1])) {
$filter_filter_poll_type = ".";
} else {
for ($i = 0; $i < count($data["filter_filter"][1]); $i++) {
if ($i == 0) {
$filter_filter_poll_type = $data["filter_filter"][1][$i];
} else {
$filter_filter_poll_type .= "|" . $data["filter_filter"][1][$i];
}
}
}
if (!isset($data["filter_filter"][2])) {
$filter_filter_user = "%";
} else {
$filter_filter_user = str_replace(["=", "%", "_"], ["==", "=%", "=_"], $data["filter_filter"][2]);
$filter_filter_user = "%" . $filter_filter_user . "%";
}
date_default_timezone_set('Europe/Athens');
$current_datetime = date('Y-m-d H:i:s', time());
if (!isset($data["filter_filter"][3])) {
$filter_filter_poll_status = "1=1";
} else if ($data["filter_filter"][3] == "1") {
$filter_filter_poll_status = "(posts.post_expiration_date IS NULL OR posts.post_expiration_date > " . "'" . $current_datetime . "')";
} else if ($data["filter_filter"][3] == "2") {
$filter_filter_poll_status = "posts.post_expiration_date < " . "'" . $current_datetime . "'";
}
if (!isset($data["radius_filter"])) {
$filter_radius_filter = "1=1";
} else {
$filter_radius_filter = "(posts.event_radius IS NULL OR FLOOR(ST_Distance_Sphere(point(:user_long, :user_lat),point(posts.event_long, posts.event_lat)))<=posts.event_radius)";
}
if (!isset($data["posts_in_region_filter"])) {
$posts_in_region_filter = ".";
} else {
if (count($data["posts_in_region_filter"]) == 0) {
$posts_in_region_filter = "zero";
} else if (count($data["posts_in_region_filter"]) > 0) {
$posts_in_region_filter = "";
for ($i = 0; $i < count($data["posts_in_region_filter"]); $i++) {
if (count($data["posts_in_region_filter"]) == 1) {
$posts_in_region_filter .= "[[:<:]]" . $data["posts_in_region_filter"][$i] . "[[:>:]]";
} else if (count($data["posts_in_region_filter"]) > 1 && $i < count($data["posts_in_region_filter"]) - 1) {
$posts_in_region_filter .= "[[:<:]]" . $data["posts_in_region_filter"][$i] . "[[:>:]]|";
} else if (count($data["posts_in_region_filter"]) > 1 && $i == count($data["posts_in_region_filter"]) - 1) {
$posts_in_region_filter .= "[[:<:]]" . $data["posts_in_region_filter"][$i] . "[[:>:]]";
}
}
}
}
if (isset($_SESSION['id'])) {
if ($data["bookmarks_only"] == false) {
if (isset($data["filter_hot"]) && $data["filter_hot"] == "hot") {
$stmt = $conn->prepare("SELECT posts.post_number AS post_number, user.username AS username, polls.poll_id AS poll_id, categories.category_name AS category_name,
posts.post_text AS post_text, (SELECT sum(chevron_vote.chevron_result) FROM chevron_vote WHERE chevron_vote.post_id=posts.post_number) AS chevron_result,
posts.post_date AS post_date,
COALESCE((SELECT chevron_vote.chevron_result FROM chevron_vote WHERE chevron_vote.user_id=:id AND chevron_vote.post_id=posts.post_number),0) AS user_chevron_result,
COALESCE((SELECT yes_no.answer_yes FROM yes_no WHERE yes_no.user_id=:id AND yes_no.post_id=posts.post_number),0) AS user_yes_answer,
COALESCE((SELECT yes_no.answer_no FROM yes_no WHERE yes_no.user_id=:id AND yes_no.post_id=posts.post_number),0) AS user_no_answer,
COALESCE((SELECT bookmarks.user_bookmark FROM bookmarks WHERE bookmarks.user_id=:id AND bookmarks.post_id=posts.post_number),0) AS user_bookmark,
posts.post_expiration_date AS post_expiration_date, posts.event_lat AS event_lat, posts.event_long AS event_long, posts.event_radius AS event_radius,
(posts_yes_no_info.number_of_yes-posts_yes_no_info.number_of_no) AS post_vote_result,
(SELECT COUNT(yes_no.user_id) AS total_votes FROM yes_no WHERE yes_no.post_id=posts.post_number AND
(yes_no.answer_yes > 0 OR yes_no.answer_no > 0)) AS total_yes_no_votes,
(SELECT COUNT(rating.user_id) AS total_votes FROM rating WHERE rating.post_id=posts.post_number AND
(rating.choice_one IS NOT NULL OR rating.choice_two IS NOT NULL OR rating.choice_three IS NOT NULL OR rating.choice_four IS NOT NULL OR rating.choice_five IS NOT NULL
OR rating.choice_six IS NOT NULL OR rating.choice_seven IS NOT NULL OR rating.choice_eight IS NOT NULL OR rating.choice_nine IS NOT NULL OR rating.choice_ten IS NOT NULL
OR rating.choice_eleven IS NOT NULL OR rating.choice_twelve IS NOT NULL OR rating.choice_thirteen IS NOT NULL OR rating.choice_fourteen IS NOT NULL OR rating.choice_fifteen IS NOT NULL
OR rating.choice_sixteen IS NOT NULL OR rating.choice_seventeen IS NOT NULL OR rating.choice_eighteen IS NOT NULL OR rating.choice_nineteen IS NOT NULL OR rating.choice_twenty IS NOT NULL))
AS total_rating_votes,
(SELECT COUNT(approval.user_id) AS total_votes FROM approval WHERE approval.post_id=posts.post_number AND
((approval.choice_one IS NOT NULL AND approval.choice_one!=0) OR
(approval.choice_two IS NOT NULL AND approval.choice_two!=0) OR
(approval.choice_three IS NOT NULL AND approval.choice_three!=0) OR
(approval.choice_four IS NOT NULL AND approval.choice_four!=0) OR
(approval.choice_five IS NOT NULL AND approval.choice_five!=0) OR
(approval.choice_six IS NOT NULL AND approval.choice_six!=0) OR
(approval.choice_seven IS NOT NULL AND approval.choice_seven!=0) OR
(approval.choice_eight IS NOT NULL AND approval.choice_eight!=0) OR
(approval.choice_nine IS NOT NULL AND approval.choice_nine!=0) OR
(approval.choice_ten IS NOT NULL AND approval.choice_ten!=0) OR
(approval.choice_eleven IS NOT NULL AND approval.choice_eleven!=0) OR
(approval.choice_twelve IS NOT NULL AND approval.choice_twelve!=0) OR
(approval.choice_thirteen IS NOT NULL AND approval.choice_thirteen!=0) OR
(approval.choice_fourteen IS NOT NULL AND approval.choice_fourteen!=0) OR
(approval.choice_fifteen IS NOT NULL AND approval.choice_fifteen!=0) OR
(approval.choice_sixteen IS NOT NULL AND approval.choice_sixteen!=0) OR
(approval.choice_seventeen IS NOT NULL AND approval.choice_seventeen!=0) OR
(approval.choice_eighteen IS NOT NULL AND approval.choice_eighteen!=0) OR
(approval.choice_nineteen IS NOT NULL AND approval.choice_nineteen!=0) OR
(approval.choice_twenty IS NOT NULL AND approval.choice_twenty!=0)))
AS total_approval_votes,
(SELECT COUNT(ranking.user_id) AS total_votes FROM ranking WHERE ranking.post_id=posts.post_number AND
(ranking.choice_one IS NOT NULL OR
ranking.choice_two IS NOT NULL OR
ranking.choice_three IS NOT NULL OR
ranking.choice_four IS NOT NULL OR
ranking.choice_five IS NOT NULL OR
ranking.choice_six IS NOT NULL OR
ranking.choice_seven IS NOT NULL OR
ranking.choice_eight IS NOT NULL OR
ranking.choice_nine IS NOT NULL OR
ranking.choice_ten IS NOT NULL OR
ranking.choice_eleven IS NOT NULL OR
ranking.choice_twelve IS NOT NULL OR
ranking.choice_thirteen IS NOT NULL OR
ranking.choice_fourteen IS NOT NULL OR
ranking.choice_fifteen IS NOT NULL OR
ranking.choice_sixteen IS NOT NULL OR
ranking.choice_seventeen IS NOT NULL OR
ranking.choice_eighteen IS NOT NULL OR
ranking.choice_nineteen IS NOT NULL OR
ranking.choice_twenty IS NOT NULL))
AS total_ranking_votes
FROM posts join user on posts.user_id = user.id join polls on posts.poll_type = polls.poll_id join categories
on posts.post_category = categories.category_id join chevron_vote ON posts.post_number = chevron_vote.post_id
join posts_yes_no_info ON posts.post_number=posts_yes_no_info.post_number
WHERE user.username LIKE :username ESCAPE '=' AND posts.post_category RLIKE :category_id AND posts.post_text LIKE :filter_search ESCAPE '='
AND (posts.post_date BETWEEN :first_date AND :second_date) AND polls.poll_id RLIKE :filter_poll_type AND user.username LIKE :filter_username ESCAPE '='
AND $filter_filter_poll_status AND $filter_radius_filter AND posts.post_number RLIKE :posts_in_region_filter
GROUP BY posts.post_number ORDER BY chevron_result DESC, posts.post_date DESC");
} else {
$stmt = $conn->prepare("SELECT posts.post_number AS post_number, user.username AS username, polls.poll_id AS poll_id, categories.category_name AS category_name,
posts.post_text AS post_text, (SELECT sum(chevron_vote.chevron_result) FROM chevron_vote WHERE chevron_vote.post_id=posts.post_number) AS chevron_result,
posts.post_date AS post_date,
COALESCE((SELECT chevron_vote.chevron_result FROM chevron_vote WHERE chevron_vote.user_id=:id AND chevron_vote.post_id=posts.post_number),0) AS user_chevron_result,
COALESCE((SELECT yes_no.answer_yes FROM yes_no WHERE yes_no.user_id=:id AND yes_no.post_id=posts.post_number),0) AS user_yes_answer,
COALESCE((SELECT yes_no.answer_no FROM yes_no WHERE yes_no.user_id=:id AND yes_no.post_id=posts.post_number),0) AS user_no_answer,
COALESCE((SELECT bookmarks.user_bookmark FROM bookmarks WHERE bookmarks.user_id=:id AND bookmarks.post_id=posts.post_number),0) AS user_bookmark,
posts.post_expiration_date AS post_expiration_date, posts.event_lat AS event_lat, posts.event_long AS event_long, posts.event_radius AS event_radius,
(posts_yes_no_info.number_of_yes-posts_yes_no_info.number_of_no) AS post_vote_result,
(SELECT COUNT(yes_no.user_id) AS total_votes FROM yes_no WHERE yes_no.post_id=posts.post_number AND
(yes_no.answer_yes > 0 OR yes_no.answer_no > 0)) AS total_yes_no_votes,
(SELECT COUNT(rating.user_id) AS total_votes FROM rating WHERE rating.post_id=posts.post_number AND
(rating.choice_one IS NOT NULL OR rating.choice_two IS NOT NULL OR rating.choice_three IS NOT NULL OR rating.choice_four IS NOT NULL OR rating.choice_five IS NOT NULL
OR rating.choice_six IS NOT NULL OR rating.choice_seven IS NOT NULL OR rating.choice_eight IS NOT NULL OR rating.choice_nine IS NOT NULL OR rating.choice_ten IS NOT NULL
OR rating.choice_eleven IS NOT NULL OR rating.choice_twelve IS NOT NULL OR rating.choice_thirteen IS NOT NULL OR rating.choice_fourteen IS NOT NULL OR rating.choice_fifteen IS NOT NULL
OR rating.choice_sixteen IS NOT NULL OR rating.choice_seventeen IS NOT NULL OR rating.choice_eighteen IS NOT NULL OR rating.choice_nineteen IS NOT NULL OR rating.choice_twenty IS NOT NULL))
AS total_rating_votes,
(SELECT COUNT(approval.user_id) AS total_votes FROM approval WHERE approval.post_id=posts.post_number AND
((approval.choice_one IS NOT NULL AND approval.choice_one!=0) OR
(approval.choice_two IS NOT NULL AND approval.choice_two!=0) OR
(approval.choice_three IS NOT NULL AND approval.choice_three!=0) OR
(approval.choice_four IS NOT NULL AND approval.choice_four!=0) OR
(approval.choice_five IS NOT NULL AND approval.choice_five!=0) OR
(approval.choice_six IS NOT NULL AND approval.choice_six!=0) OR
(approval.choice_seven IS NOT NULL AND approval.choice_seven!=0) OR
(approval.choice_eight IS NOT NULL AND approval.choice_eight!=0) OR
(approval.choice_nine IS NOT NULL AND approval.choice_nine!=0) OR
(approval.choice_ten IS NOT NULL AND approval.choice_ten!=0) OR
(approval.choice_eleven IS NOT NULL AND approval.choice_eleven!=0) OR
(approval.choice_twelve IS NOT NULL AND approval.choice_twelve!=0) OR
(approval.choice_thirteen IS NOT NULL AND approval.choice_thirteen!=0) OR
(approval.choice_fourteen IS NOT NULL AND approval.choice_fourteen!=0) OR
(approval.choice_fifteen IS NOT NULL AND approval.choice_fifteen!=0) OR
(approval.choice_sixteen IS NOT NULL AND approval.choice_sixteen!=0) OR
(approval.choice_seventeen IS NOT NULL AND approval.choice_seventeen!=0) OR
(approval.choice_eighteen IS NOT NULL AND approval.choice_eighteen!=0) OR
(approval.choice_nineteen IS NOT NULL AND approval.choice_nineteen!=0) OR
(approval.choice_twenty IS NOT NULL AND approval.choice_twenty!=0)))
AS total_approval_votes,
(SELECT COUNT(ranking.user_id) AS total_votes FROM ranking WHERE ranking.post_id=posts.post_number AND
(ranking.choice_one IS NOT NULL OR
ranking.choice_two IS NOT NULL OR
ranking.choice_three IS NOT NULL OR
ranking.choice_four IS NOT NULL OR
ranking.choice_five IS NOT NULL OR
ranking.choice_six IS NOT NULL OR
ranking.choice_seven IS NOT NULL OR
ranking.choice_eight IS NOT NULL OR
ranking.choice_nine IS NOT NULL OR
ranking.choice_ten IS NOT NULL OR
ranking.choice_eleven IS NOT NULL OR
ranking.choice_twelve IS NOT NULL OR
ranking.choice_thirteen IS NOT NULL OR
ranking.choice_fourteen IS NOT NULL OR
ranking.choice_fifteen IS NOT NULL OR
ranking.choice_sixteen IS NOT NULL OR
ranking.choice_seventeen IS NOT NULL OR
ranking.choice_eighteen IS NOT NULL OR
ranking.choice_nineteen IS NOT NULL OR
ranking.choice_twenty IS NOT NULL))
AS total_ranking_votes
FROM posts join user on posts.user_id = user.id join polls on posts.poll_type = polls.poll_id join categories
on posts.post_category = categories.category_id join chevron_vote ON posts.post_number = chevron_vote.post_id
join posts_yes_no_info ON posts.post_number=posts_yes_no_info.post_number
WHERE user.username LIKE :username ESCAPE '=' AND posts.post_category RLIKE :category_id AND posts.post_text LIKE :filter_search ESCAPE '='
AND (posts.post_date BETWEEN :first_date AND :second_date) AND polls.poll_id RLIKE :filter_poll_type AND user.username LIKE :filter_username ESCAPE '='
AND $filter_filter_poll_status AND $filter_radius_filter AND posts.post_number RLIKE :posts_in_region_filter
GROUP BY posts.post_number ORDER BY posts.post_date DESC");
}
} else if ($data["bookmarks_only"] == true) {
if (isset($data["filter_hot"]) && $data["filter_hot"] == "hot") {
$stmt = $conn->prepare("SELECT posts.post_number AS post_number, user.username AS username, polls.poll_id AS poll_id, categories.category_name AS category_name,
posts.post_text AS post_text, (SELECT sum(chevron_vote.chevron_result) FROM chevron_vote WHERE chevron_vote.post_id=posts.post_number) AS chevron_result,
posts.post_date AS post_date,
COALESCE((SELECT chevron_vote.chevron_result FROM chevron_vote WHERE chevron_vote.user_id=:id AND chevron_vote.post_id=posts.post_number),0) AS user_chevron_result,
COALESCE((SELECT yes_no.answer_yes FROM yes_no WHERE yes_no.user_id=:id AND yes_no.post_id=posts.post_number),0) AS user_yes_answer,
COALESCE((SELECT yes_no.answer_no FROM yes_no WHERE yes_no.user_id=:id AND yes_no.post_id=posts.post_number),0) AS user_no_answer,
COALESCE((SELECT bookmarks.user_bookmark FROM bookmarks WHERE bookmarks.user_id=:id AND bookmarks.post_id=posts.post_number),0) AS user_bookmark,
posts.post_expiration_date AS post_expiration_date, posts.event_lat AS event_lat, posts.event_long AS event_long, posts.event_radius AS event_radius,
(posts_yes_no_info.number_of_yes-posts_yes_no_info.number_of_no) AS post_vote_result,
(SELECT COUNT(yes_no.user_id) AS total_votes FROM yes_no WHERE yes_no.post_id=posts.post_number AND
(yes_no.answer_yes > 0 OR yes_no.answer_no > 0)) AS total_yes_no_votes,
(SELECT COUNT(rating.user_id) AS total_votes FROM rating WHERE rating.post_id=posts.post_number AND
(rating.choice_one IS NOT NULL OR rating.choice_two IS NOT NULL OR rating.choice_three IS NOT NULL OR rating.choice_four IS NOT NULL OR rating.choice_five IS NOT NULL
OR rating.choice_six IS NOT NULL OR rating.choice_seven IS NOT NULL OR rating.choice_eight IS NOT NULL OR rating.choice_nine IS NOT NULL OR rating.choice_ten IS NOT NULL
OR rating.choice_eleven IS NOT NULL OR rating.choice_twelve IS NOT NULL OR rating.choice_thirteen IS NOT NULL OR rating.choice_fourteen IS NOT NULL OR rating.choice_fifteen IS NOT NULL
OR rating.choice_sixteen IS NOT NULL OR rating.choice_seventeen IS NOT NULL OR rating.choice_eighteen IS NOT NULL OR rating.choice_nineteen IS NOT NULL OR rating.choice_twenty IS NOT NULL))
AS total_rating_votes,
(SELECT COUNT(approval.user_id) AS total_votes FROM approval WHERE approval.post_id=posts.post_number AND
((approval.choice_one IS NOT NULL AND approval.choice_one!=0) OR
(approval.choice_two IS NOT NULL AND approval.choice_two!=0) OR
(approval.choice_three IS NOT NULL AND approval.choice_three!=0) OR
(approval.choice_four IS NOT NULL AND approval.choice_four!=0) OR
(approval.choice_five IS NOT NULL AND approval.choice_five!=0) OR
(approval.choice_six IS NOT NULL AND approval.choice_six!=0) OR
(approval.choice_seven IS NOT NULL AND approval.choice_seven!=0) OR
(approval.choice_eight IS NOT NULL AND approval.choice_eight!=0) OR
(approval.choice_nine IS NOT NULL AND approval.choice_nine!=0) OR
(approval.choice_ten IS NOT NULL AND approval.choice_ten!=0) OR
(approval.choice_eleven IS NOT NULL AND approval.choice_eleven!=0) OR
(approval.choice_twelve IS NOT NULL AND approval.choice_twelve!=0) OR
(approval.choice_thirteen IS NOT NULL AND approval.choice_thirteen!=0) OR
(approval.choice_fourteen IS NOT NULL AND approval.choice_fourteen!=0) OR
(approval.choice_fifteen IS NOT NULL AND approval.choice_fifteen!=0) OR
(approval.choice_sixteen IS NOT NULL AND approval.choice_sixteen!=0) OR
(approval.choice_seventeen IS NOT NULL AND approval.choice_seventeen!=0) OR
(approval.choice_eighteen IS NOT NULL AND approval.choice_eighteen!=0) OR
(approval.choice_nineteen IS NOT NULL AND approval.choice_nineteen!=0) OR
(approval.choice_twenty IS NOT NULL AND approval.choice_twenty!=0)))
AS total_approval_votes,
(SELECT COUNT(ranking.user_id) AS total_votes FROM ranking WHERE ranking.post_id=posts.post_number AND
(ranking.choice_one IS NOT NULL OR
ranking.choice_two IS NOT NULL OR
ranking.choice_three IS NOT NULL OR
ranking.choice_four IS NOT NULL OR
ranking.choice_five IS NOT NULL OR
ranking.choice_six IS NOT NULL OR
ranking.choice_seven IS NOT NULL OR
ranking.choice_eight IS NOT NULL OR
ranking.choice_nine IS NOT NULL OR
ranking.choice_ten IS NOT NULL OR
ranking.choice_eleven IS NOT NULL OR
ranking.choice_twelve IS NOT NULL OR
ranking.choice_thirteen IS NOT NULL OR
ranking.choice_fourteen IS NOT NULL OR
ranking.choice_fifteen IS NOT NULL OR
ranking.choice_sixteen IS NOT NULL OR
ranking.choice_seventeen IS NOT NULL OR
ranking.choice_eighteen IS NOT NULL OR
ranking.choice_nineteen IS NOT NULL OR
ranking.choice_twenty IS NOT NULL))
AS total_ranking_votes
FROM posts join user on posts.user_id = user.id join polls on posts.poll_type = polls.poll_id join categories
on posts.post_category = categories.category_id join chevron_vote ON posts.post_number = chevron_vote.post_id
join posts_yes_no_info ON posts.post_number=posts_yes_no_info.post_number
WHERE COALESCE((SELECT bookmarks.user_bookmark FROM bookmarks WHERE bookmarks.user_id=:id AND bookmarks.post_id=posts.post_number),0) = 1
AND user.username LIKE :username ESCAPE '=' AND posts.post_category RLIKE :category_id AND posts.post_text LIKE :filter_search ESCAPE '='
AND (posts.post_date BETWEEN :first_date AND :second_date) AND polls.poll_id RLIKE :filter_poll_type AND user.username LIKE :filter_username ESCAPE '='
AND $filter_filter_poll_status AND $filter_radius_filter AND posts.post_number RLIKE :posts_in_region_filter
GROUP BY posts.post_number ORDER BY chevron_result DESC, posts.post_date DESC");
} else {
$stmt = $conn->prepare("SELECT posts.post_number AS post_number, user.username AS username, polls.poll_id AS poll_id, categories.category_name AS category_name,
posts.post_text AS post_text, (SELECT sum(chevron_vote.chevron_result) FROM chevron_vote WHERE chevron_vote.post_id=posts.post_number) AS chevron_result,
posts.post_date AS post_date,
COALESCE((SELECT chevron_vote.chevron_result FROM chevron_vote WHERE chevron_vote.user_id=:id AND chevron_vote.post_id=posts.post_number),0) AS user_chevron_result,
COALESCE((SELECT yes_no.answer_yes FROM yes_no WHERE yes_no.user_id=:id AND yes_no.post_id=posts.post_number),0) AS user_yes_answer,
COALESCE((SELECT yes_no.answer_no FROM yes_no WHERE yes_no.user_id=:id AND yes_no.post_id=posts.post_number),0) AS user_no_answer,
COALESCE((SELECT bookmarks.user_bookmark FROM bookmarks WHERE bookmarks.user_id=:id AND bookmarks.post_id=posts.post_number),0) AS user_bookmark,
posts.post_expiration_date AS post_expiration_date, posts.event_lat AS event_lat, posts.event_long AS event_long, posts.event_radius AS event_radius,
(posts_yes_no_info.number_of_yes-posts_yes_no_info.number_of_no) AS post_vote_result,
(SELECT COUNT(yes_no.user_id) AS total_votes FROM yes_no WHERE yes_no.post_id=posts.post_number AND
(yes_no.answer_yes > 0 OR yes_no.answer_no > 0)) AS total_yes_no_votes,
(SELECT COUNT(rating.user_id) AS total_votes FROM rating WHERE rating.post_id=posts.post_number AND
(rating.choice_one IS NOT NULL OR rating.choice_two IS NOT NULL OR rating.choice_three IS NOT NULL OR rating.choice_four IS NOT NULL OR rating.choice_five IS NOT NULL
OR rating.choice_six IS NOT NULL OR rating.choice_seven IS NOT NULL OR rating.choice_eight IS NOT NULL OR rating.choice_nine IS NOT NULL OR rating.choice_ten IS NOT NULL
OR rating.choice_eleven IS NOT NULL OR rating.choice_twelve IS NOT NULL OR rating.choice_thirteen IS NOT NULL OR rating.choice_fourteen IS NOT NULL OR rating.choice_fifteen IS NOT NULL
OR rating.choice_sixteen IS NOT NULL OR rating.choice_seventeen IS NOT NULL OR rating.choice_eighteen IS NOT NULL OR rating.choice_nineteen IS NOT NULL OR rating.choice_twenty IS NOT NULL))
AS total_rating_votes,
(SELECT COUNT(approval.user_id) AS total_votes FROM approval WHERE approval.post_id=posts.post_number AND
((approval.choice_one IS NOT NULL AND approval.choice_one!=0) OR
(approval.choice_two IS NOT NULL AND approval.choice_two!=0) OR
(approval.choice_three IS NOT NULL AND approval.choice_three!=0) OR
(approval.choice_four IS NOT NULL AND approval.choice_four!=0) OR
(approval.choice_five IS NOT NULL AND approval.choice_five!=0) OR
(approval.choice_six IS NOT NULL AND approval.choice_six!=0) OR
(approval.choice_seven IS NOT NULL AND approval.choice_seven!=0) OR
(approval.choice_eight IS NOT NULL AND approval.choice_eight!=0) OR
(approval.choice_nine IS NOT NULL AND approval.choice_nine!=0) OR
(approval.choice_ten IS NOT NULL AND approval.choice_ten!=0) OR
(approval.choice_eleven IS NOT NULL AND approval.choice_eleven!=0) OR
(approval.choice_twelve IS NOT NULL AND approval.choice_twelve!=0) OR
(approval.choice_thirteen IS NOT NULL AND approval.choice_thirteen!=0) OR
(approval.choice_fourteen IS NOT NULL AND approval.choice_fourteen!=0) OR
(approval.choice_fifteen IS NOT NULL AND approval.choice_fifteen!=0) OR
(approval.choice_sixteen IS NOT NULL AND approval.choice_sixteen!=0) OR
(approval.choice_seventeen IS NOT NULL AND approval.choice_seventeen!=0) OR
(approval.choice_eighteen IS NOT NULL AND approval.choice_eighteen!=0) OR
(approval.choice_nineteen IS NOT NULL AND approval.choice_nineteen!=0) OR
(approval.choice_twenty IS NOT NULL AND approval.choice_twenty!=0)))
AS total_approval_votes,
(SELECT COUNT(ranking.user_id) AS total_votes FROM ranking WHERE ranking.post_id=posts.post_number AND
(ranking.choice_one IS NOT NULL OR
ranking.choice_two IS NOT NULL OR
ranking.choice_three IS NOT NULL OR
ranking.choice_four IS NOT NULL OR
ranking.choice_five IS NOT NULL OR
ranking.choice_six IS NOT NULL OR
ranking.choice_seven IS NOT NULL OR
ranking.choice_eight IS NOT NULL OR
ranking.choice_nine IS NOT NULL OR
ranking.choice_ten IS NOT NULL OR
ranking.choice_eleven IS NOT NULL OR
ranking.choice_twelve IS NOT NULL OR
ranking.choice_thirteen IS NOT NULL OR
ranking.choice_fourteen IS NOT NULL OR
ranking.choice_fifteen IS NOT NULL OR
ranking.choice_sixteen IS NOT NULL OR
ranking.choice_seventeen IS NOT NULL OR
ranking.choice_eighteen IS NOT NULL OR
ranking.choice_nineteen IS NOT NULL OR
ranking.choice_twenty IS NOT NULL))
AS total_ranking_votes
FROM posts join user on posts.user_id = user.id join polls on posts.poll_type = polls.poll_id join categories
on posts.post_category = categories.category_id join chevron_vote ON posts.post_number = chevron_vote.post_id
join posts_yes_no_info ON posts.post_number=posts_yes_no_info.post_number
WHERE COALESCE((SELECT bookmarks.user_bookmark FROM bookmarks WHERE bookmarks.user_id=:id AND bookmarks.post_id=posts.post_number),0) = 1
AND user.username LIKE :username ESCAPE '=' AND posts.post_category RLIKE :category_id AND posts.post_text LIKE :filter_search ESCAPE '='
AND (posts.post_date BETWEEN :first_date AND :second_date) AND polls.poll_id RLIKE :filter_poll_type AND user.username LIKE :filter_username ESCAPE '='
AND $filter_filter_poll_status AND $filter_radius_filter AND posts.post_number RLIKE :posts_in_region_filter
GROUP BY posts.post_number ORDER BY posts.post_date DESC");
}
}
if (!isset($data["radius_filter"])) {
$stmt->execute([
":id" => $_SESSION["id"], ":username" => $user_search, ":category_id" => $filter_preferred_categories, ":filter_search" => $filter_search,
":first_date" => $filter_filter_time[0], ":second_date" => $filter_filter_time[1], ":filter_poll_type" => $filter_filter_poll_type,
":filter_username" => $filter_filter_user, ":posts_in_region_filter" => $posts_in_region_filter
]);
} else {
$stmt->execute([
":id" => $_SESSION["id"], ":username" => $user_search, ":category_id" => $filter_preferred_categories, ":filter_search" => $filter_search,
":first_date" => $filter_filter_time[0], ":second_date" => $filter_filter_time[1], ":filter_poll_type" => $filter_filter_poll_type,
":filter_username" => $filter_filter_user, ":user_long" => $data["radius_filter"][0], ":user_lat" => $data["radius_filter"][1],
":posts_in_region_filter" => $posts_in_region_filter
]);
}
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
$tmp = array(
$row["post_number"], $row["username"], $row["poll_id"], $row["category_name"], $row["post_text"], $row["chevron_result"],
$row["post_date"], $row["user_chevron_result"], $row["user_yes_answer"], $row["user_no_answer"], $row["user_bookmark"], $row["post_expiration_date"],
$row["event_lat"], $row["event_long"], $row["event_radius"], $row["post_vote_result"], $_SESSION["username"], $row["total_yes_no_votes"],
$row["total_rating_votes"], $row["total_approval_votes"], $row["total_ranking_votes"]
);
array_push($post_data, $tmp);
}
$stmt = $conn->prepare("SELECT language AS user_language FROM user WHERE id=:id");
$stmt->execute([":id" => $_SESSION["id"]]);
if ($stmt->rowCount() > 0) {
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
array_push($post_data, [$row["user_language"]]);
}
}
echo json_encode($post_data);
} else {
if (isset($data["filter_hot"]) && $data["filter_hot"] == "hot") {
$stmt = $conn->prepare("SELECT posts_info.post_number AS post_number,posts_info.username AS username,poll_id,posts_info.category_name AS category_name,
posts_info.post_text AS post_text,chevron_result,posts_info.post_date AS post_date,posts_info.post_expiration_date,
(posts_yes_no_info.number_of_yes-posts_yes_no_info.number_of_no) AS post_vote_result, posts.event_lat AS event_lat, posts.event_long AS event_long,
posts.event_radius AS event_radius,
(SELECT COUNT(yes_no.user_id) AS total_votes FROM yes_no WHERE yes_no.post_id=posts_info.post_number AND
(yes_no.answer_yes > 0 OR yes_no.answer_no > 0)) AS total_yes_no_votes,
(SELECT COUNT(rating.user_id) AS total_votes FROM rating WHERE rating.post_id=posts_info.post_number AND
(rating.choice_one IS NOT NULL OR rating.choice_two IS NOT NULL OR rating.choice_three IS NOT NULL OR rating.choice_four IS NOT NULL OR rating.choice_five IS NOT NULL
OR rating.choice_six IS NOT NULL OR rating.choice_seven IS NOT NULL OR rating.choice_eight IS NOT NULL OR rating.choice_nine IS NOT NULL OR rating.choice_ten IS NOT NULL
OR rating.choice_eleven IS NOT NULL OR rating.choice_twelve IS NOT NULL OR rating.choice_thirteen IS NOT NULL OR rating.choice_fourteen IS NOT NULL OR rating.choice_fifteen IS NOT NULL
OR rating.choice_sixteen IS NOT NULL OR rating.choice_seventeen IS NOT NULL OR rating.choice_eighteen IS NOT NULL OR rating.choice_nineteen IS NOT NULL OR rating.choice_twenty IS NOT NULL))
AS total_rating_votes,
(SELECT COUNT(approval.user_id) AS total_votes FROM approval WHERE approval.post_id=posts_info.post_number AND
((approval.choice_one IS NOT NULL AND approval.choice_one!=0) OR
(approval.choice_two IS NOT NULL AND approval.choice_two!=0) OR
(approval.choice_three IS NOT NULL AND approval.choice_three!=0) OR
(approval.choice_four IS NOT NULL AND approval.choice_four!=0) OR
(approval.choice_five IS NOT NULL AND approval.choice_five!=0) OR
(approval.choice_six IS NOT NULL AND approval.choice_six!=0) OR
(approval.choice_seven IS NOT NULL AND approval.choice_seven!=0) OR
(approval.choice_eight IS NOT NULL AND approval.choice_eight!=0) OR
(approval.choice_nine IS NOT NULL AND approval.choice_nine!=0) OR
(approval.choice_ten IS NOT NULL AND approval.choice_ten!=0) OR
(approval.choice_eleven IS NOT NULL AND approval.choice_eleven!=0) OR
(approval.choice_twelve IS NOT NULL AND approval.choice_twelve!=0) OR
(approval.choice_thirteen IS NOT NULL AND approval.choice_thirteen!=0) OR
(approval.choice_fourteen IS NOT NULL AND approval.choice_fourteen!=0) OR
(approval.choice_fifteen IS NOT NULL AND approval.choice_fifteen!=0) OR
(approval.choice_sixteen IS NOT NULL AND approval.choice_sixteen!=0) OR
(approval.choice_seventeen IS NOT NULL AND approval.choice_seventeen!=0) OR
(approval.choice_eighteen IS NOT NULL AND approval.choice_eighteen!=0) OR
(approval.choice_nineteen IS NOT NULL AND approval.choice_nineteen!=0) OR
(approval.choice_twenty IS NOT NULL AND approval.choice_twenty!=0)))
AS total_approval_votes,
(SELECT COUNT(ranking.user_id) AS total_votes FROM ranking WHERE ranking.post_id=posts_info.post_number AND
(ranking.choice_one IS NOT NULL OR
ranking.choice_two IS NOT NULL OR
ranking.choice_three IS NOT NULL OR
ranking.choice_four IS NOT NULL OR
ranking.choice_five IS NOT NULL OR
ranking.choice_six IS NOT NULL OR
ranking.choice_seven IS NOT NULL OR
ranking.choice_eight IS NOT NULL OR
ranking.choice_nine IS NOT NULL OR
ranking.choice_ten IS NOT NULL OR
ranking.choice_eleven IS NOT NULL OR
ranking.choice_twelve IS NOT NULL OR
ranking.choice_thirteen IS NOT NULL OR
ranking.choice_fourteen IS NOT NULL OR
ranking.choice_fifteen IS NOT NULL OR
ranking.choice_sixteen IS NOT NULL OR
ranking.choice_seventeen IS NOT NULL OR
ranking.choice_eighteen IS NOT NULL OR
ranking.choice_nineteen IS NOT NULL OR
ranking.choice_twenty IS NOT NULL))
AS total_ranking_votes
FROM posts_info INNER JOIN posts_yes_no_info ON posts_info.post_number=posts_yes_no_info.post_number INNER JOIN posts ON posts_info.post_number=posts.post_number
WHERE posts_info.username LIKE :username ESCAPE '=' AND posts.post_category RLIKE :category_id AND posts_info.post_text LIKE :filter_search ESCAPE '='
AND (posts_info.post_date BETWEEN :first_date AND :second_date) AND poll_id RLIKE :filter_poll_type AND posts_info.username LIKE :filter_username ESCAPE '='
AND $filter_filter_poll_status AND $filter_radius_filter AND posts.post_number RLIKE :posts_in_region_filter ORDER BY chevron_result DESC, posts.post_date DESC");
} else {
$stmt = $conn->prepare("SELECT posts_info.post_number AS post_number,posts_info.username AS username,poll_id,posts_info.category_name AS category_name,
posts_info.post_text AS post_text,chevron_result,posts_info.post_date AS post_date,posts_info.post_expiration_date,
(posts_yes_no_info.number_of_yes-posts_yes_no_info.number_of_no) AS post_vote_result, posts.event_lat AS event_lat, posts.event_long AS event_long,
posts.event_radius AS event_radius,
(SELECT COUNT(yes_no.user_id) AS total_votes FROM yes_no WHERE yes_no.post_id=posts_info.post_number AND
(yes_no.answer_yes > 0 OR yes_no.answer_no > 0)) AS total_yes_no_votes,
(SELECT COUNT(rating.user_id) AS total_votes FROM rating WHERE rating.post_id=posts_info.post_number AND
(rating.choice_one IS NOT NULL OR rating.choice_two IS NOT NULL OR rating.choice_three IS NOT NULL OR rating.choice_four IS NOT NULL OR rating.choice_five IS NOT NULL
OR rating.choice_six IS NOT NULL OR rating.choice_seven IS NOT NULL OR rating.choice_eight IS NOT NULL OR rating.choice_nine IS NOT NULL OR rating.choice_ten IS NOT NULL
OR rating.choice_eleven IS NOT NULL OR rating.choice_twelve IS NOT NULL OR rating.choice_thirteen IS NOT NULL OR rating.choice_fourteen IS NOT NULL OR rating.choice_fifteen IS NOT NULL
OR rating.choice_sixteen IS NOT NULL OR rating.choice_seventeen IS NOT NULL OR rating.choice_eighteen IS NOT NULL OR rating.choice_nineteen IS NOT NULL OR rating.choice_twenty IS NOT NULL))
AS total_rating_votes,
(SELECT COUNT(approval.user_id) AS total_votes FROM approval WHERE approval.post_id=posts_info.post_number AND
((approval.choice_one IS NOT NULL AND approval.choice_one!=0) OR
(approval.choice_two IS NOT NULL AND approval.choice_two!=0) OR
(approval.choice_three IS NOT NULL AND approval.choice_three!=0) OR
(approval.choice_four IS NOT NULL AND approval.choice_four!=0) OR
(approval.choice_five IS NOT NULL AND approval.choice_five!=0) OR
(approval.choice_six IS NOT NULL AND approval.choice_six!=0) OR
(approval.choice_seven IS NOT NULL AND approval.choice_seven!=0) OR
(approval.choice_eight IS NOT NULL AND approval.choice_eight!=0) OR
(approval.choice_nine IS NOT NULL AND approval.choice_nine!=0) OR
(approval.choice_ten IS NOT NULL AND approval.choice_ten!=0) OR
(approval.choice_eleven IS NOT NULL AND approval.choice_eleven!=0) OR
(approval.choice_twelve IS NOT NULL AND approval.choice_twelve!=0) OR
(approval.choice_thirteen IS NOT NULL AND approval.choice_thirteen!=0) OR
(approval.choice_fourteen IS NOT NULL AND approval.choice_fourteen!=0) OR
(approval.choice_fifteen IS NOT NULL AND approval.choice_fifteen!=0) OR
(approval.choice_sixteen IS NOT NULL AND approval.choice_sixteen!=0) OR
(approval.choice_seventeen IS NOT NULL AND approval.choice_seventeen!=0) OR
(approval.choice_eighteen IS NOT NULL AND approval.choice_eighteen!=0) OR
(approval.choice_nineteen IS NOT NULL AND approval.choice_nineteen!=0) OR
(approval.choice_twenty IS NOT NULL AND approval.choice_twenty!=0)))
AS total_approval_votes,
(SELECT COUNT(ranking.user_id) AS total_votes FROM ranking WHERE ranking.post_id=posts_info.post_number AND
(ranking.choice_one IS NOT NULL OR
ranking.choice_two IS NOT NULL OR
ranking.choice_three IS NOT NULL OR
ranking.choice_four IS NOT NULL OR
ranking.choice_five IS NOT NULL OR
ranking.choice_six IS NOT NULL OR
ranking.choice_seven IS NOT NULL OR
ranking.choice_eight IS NOT NULL OR
ranking.choice_nine IS NOT NULL OR
ranking.choice_ten IS NOT NULL OR
ranking.choice_eleven IS NOT NULL OR
ranking.choice_twelve IS NOT NULL OR
ranking.choice_thirteen IS NOT NULL OR
ranking.choice_fourteen IS NOT NULL OR
ranking.choice_fifteen IS NOT NULL OR
ranking.choice_sixteen IS NOT NULL OR
ranking.choice_seventeen IS NOT NULL OR
ranking.choice_eighteen IS NOT NULL OR
ranking.choice_nineteen IS NOT NULL OR
ranking.choice_twenty IS NOT NULL))
AS total_ranking_votes
FROM posts_info INNER JOIN posts_yes_no_info ON posts_info.post_number=posts_yes_no_info.post_number INNER JOIN posts ON posts_info.post_number=posts.post_number
WHERE posts_info.username LIKE :username ESCAPE '=' AND posts.post_category RLIKE :category_id AND posts_info.post_text LIKE :filter_search ESCAPE '='
AND (posts_info.post_date BETWEEN :first_date AND :second_date) AND poll_id RLIKE :filter_poll_type AND posts_info.username LIKE :filter_username ESCAPE '='
AND $filter_filter_poll_status AND $filter_radius_filter AND posts.post_number RLIKE :posts_in_region_filter ORDER BY posts.post_date DESC");
}
if (!isset($data["radius_filter"])) {
$stmt->execute([
":username" => $user_search, ":category_id" => $filter_preferred_categories, ":filter_search" => $filter_search,
":first_date" => $filter_filter_time[0], ":second_date" => $filter_filter_time[1], ":filter_poll_type" => $filter_filter_poll_type,
":filter_username" => $filter_filter_user, ":posts_in_region_filter" => $posts_in_region_filter
]);
} else {
$stmt->execute([
":username" => $user_search, ":category_id" => $filter_preferred_categories, ":filter_search" => $filter_search,
":first_date" => $filter_filter_time[0], ":second_date" => $filter_filter_time[1], ":filter_poll_type" => $filter_filter_poll_type,
":filter_username" => $filter_filter_user, ":user_long" => $data["radius_filter"][0], ":user_lat" => $data["radius_filter"][1],
":posts_in_region_filter" => $posts_in_region_filter
]);
}
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
$tmp = array(
$row["post_number"], $row["username"], $row["poll_id"], $row["category_name"], $row["post_text"], $row["chevron_result"], $row["post_date"], $row["post_expiration_date"],
$row["post_vote_result"], $row["event_lat"], $row["event_long"], $row["event_radius"], $row["total_yes_no_votes"], $row["total_rating_votes"], $row["total_approval_votes"],
$row["total_ranking_votes"]
);
array_push($post_data, $tmp);
}
echo json_encode($post_data);
}
} else if ($data['request'] == "chevron_vote" && isset($_SESSION["loggedin"]) && $_SESSION["loggedin"] == true) {
require_once "new_config.php";
if ($data['direction'] == "up" && $data['previous_vote'] == "up") {
$stmt = $conn->prepare("UPDATE chevron_vote SET chevron_result = 0 WHERE post_id=:post_id AND user_id=:id");
$stmt->execute([":post_id" => $data["post_id"], ":id" => $_SESSION["id"]]);
echo "Success";
} else if ($data['direction'] == "up" && $data['previous_vote'] == "down") {
$stmt = $conn->prepare("UPDATE chevron_vote SET chevron_result = 1 WHERE post_id=:post_id AND user_id=:id");
$stmt->execute([":post_id" => $data["post_id"], ":id" => $_SESSION["id"]]);
echo "Success";
} else if ($data['direction'] == "up" && $data['previous_vote'] == "no") {
$stmt = $conn->prepare("SELECT post_id,user_id FROM chevron_vote WHERE post_id=:post_id AND user_id=:id");
$stmt->execute([":post_id" => $data["post_id"], ":id" => $_SESSION["id"]]);
if ($stmt->rowCount() > 0) {
$stmt = $conn->prepare("UPDATE chevron_vote SET chevron_result = 1 WHERE post_id=:post_id AND user_id=:id");
$stmt->execute([":post_id" => $data["post_id"], ":id" => $_SESSION["id"]]);
echo "Success";
} else if ($stmt->rowCount() == 0) {
$stmt = $conn->prepare("INSERT INTO chevron_vote(post_id,user_id,chevron_result) VALUES (:post_id,:id,1)");
$stmt->execute([":post_id" => $data["post_id"], ":id" => $_SESSION["id"]]);
echo "Success";
}
} else if ($data['direction'] == "down" && $data['previous_vote'] == "down") {
$stmt = $conn->prepare("UPDATE chevron_vote SET chevron_result = 0 WHERE post_id=:post_id AND user_id=:id");
$stmt->execute([":post_id" => $data["post_id"], ":id" => $_SESSION["id"]]);
echo "Success";
} else if ($data['direction'] == "down" && $data['previous_vote'] == "up") {
$stmt = $conn->prepare("UPDATE chevron_vote SET chevron_result = -1 WHERE post_id=:post_id AND user_id=:id");
$stmt->execute([":post_id" => $data["post_id"], ":id" => $_SESSION["id"]]);
echo "Success";
} else if ($data['direction'] == "down" && $data['previous_vote'] == "no") {
$stmt = $conn->prepare("SELECT post_id,user_id FROM chevron_vote WHERE post_id=:post_id AND user_id=:id");
$stmt->execute([":post_id" => $data["post_id"], ":id" => $_SESSION["id"]]);
if ($stmt->rowCount() > 0) {
$stmt = $conn->prepare("UPDATE chevron_vote SET chevron_result = -1 WHERE post_id=:post_id AND user_id=:id");
$stmt->execute([":post_id" => $data["post_id"], ":id" => $_SESSION["id"]]);
echo "Success";
} else if ($stmt->rowCount() == 0) {
$stmt = $conn->prepare("INSERT INTO chevron_vote(post_id,user_id,chevron_result) VALUES (:post_id,:id,-1)");
$stmt->execute([":post_id" => $data["post_id"], ":id" => $_SESSION["id"]]);
echo "Success";
}
}
} else if ($data['request'] == "yes_no_vote" && isset($_SESSION["loggedin"]) && $_SESSION["loggedin"] == true) {
require_once "new_config.php";
if ($data['current_vote'] == "yes" && $data['previous_vote'] == "yes") {
$stmt = $conn->prepare("UPDATE yes_no SET answer_yes = 0 WHERE post_id=:post_id AND user_id=:id");
$stmt->execute([":post_id" => $data["post_id"], ":id" => $_SESSION["id"]]);
$stmt = $conn->prepare("SELECT number_of_yes, number_of_no FROM posts_yes_no_info WHERE post_number=:post_id");
$stmt->execute([":post_id" => $data["post_id"]]);
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
$yes_no_tmp = array($row["number_of_yes"], $row["number_of_no"], "Success");
}
echo json_encode($yes_no_tmp);
} else if ($data['current_vote'] == "yes" && $data['previous_vote'] == "no") {
$stmt = $conn->prepare("UPDATE yes_no SET answer_yes = 1, answer_no=0 WHERE post_id=:post_id AND user_id=:id");
$stmt->execute([":post_id" => $data["post_id"], ":id" => $_SESSION["id"]]);
$stmt = $conn->prepare("SELECT number_of_yes, number_of_no FROM posts_yes_no_info WHERE post_number=:post_id");
$stmt->execute([":post_id" => $data["post_id"]]);
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
$yes_no_tmp = array($row["number_of_yes"], $row["number_of_no"], "Success");
}
echo json_encode($yes_no_tmp);
} else if ($data['current_vote'] == "yes" && $data['previous_vote'] == "nothing") {
$stmt = $conn->prepare("SELECT post_id,user_id FROM yes_no WHERE post_id=:post_id AND user_id=:id");
$stmt->execute([":post_id" => $data["post_id"], ":id" => $_SESSION["id"]]);
if ($stmt->rowCount() > 0) {
$stmt = $conn->prepare("UPDATE yes_no SET answer_yes = 1 WHERE post_id=:post_id AND user_id=:id");
$stmt->execute([":post_id" => $data["post_id"], ":id" => $_SESSION["id"]]);
$stmt = $conn->prepare("SELECT number_of_yes, number_of_no FROM posts_yes_no_info WHERE post_number=:post_id");
$stmt->execute([":post_id" => $data["post_id"]]);
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
$yes_no_tmp = array($row["number_of_yes"], $row["number_of_no"], "Success");
}
echo json_encode($yes_no_tmp);
} else if ($stmt->rowCount() == 0) {
$stmt = $conn->prepare("INSERT INTO yes_no(post_id,user_id,poll_type,answer_yes,answer_no) VALUES (:post_id,:id,1,1,0)");
$stmt->execute([":post_id" => $data["post_id"], ":id" => $_SESSION["id"]]);
$stmt = $conn->prepare("SELECT number_of_yes, number_of_no FROM posts_yes_no_info WHERE post_number=:post_id");
$stmt->execute([":post_id" => $data["post_id"]]);
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
$yes_no_tmp = array($row["number_of_yes"], $row["number_of_no"], "Success");
}
echo json_encode($yes_no_tmp);
}
} else if ($data['current_vote'] == "no" && $data['previous_vote'] == "no") {
$stmt = $conn->prepare("UPDATE yes_no SET answer_no = 0 WHERE post_id=:post_id AND user_id=:id");
$stmt->execute([":post_id" => $data["post_id"], ":id" => $_SESSION["id"]]);
$stmt = $conn->prepare("SELECT number_of_yes, number_of_no FROM posts_yes_no_info WHERE post_number=:post_id");
$stmt->execute([":post_id" => $data["post_id"]]);
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
$yes_no_tmp = array($row["number_of_yes"], $row["number_of_no"], "Success");
}
echo json_encode($yes_no_tmp);
} else if ($data['current_vote'] == "no" && $data['previous_vote'] == "yes") {
$stmt = $conn->prepare("UPDATE yes_no SET answer_yes = 0, answer_no=1 WHERE post_id=:post_id AND user_id=:id");
$stmt->execute([":post_id" => $data["post_id"], ":id" => $_SESSION["id"]]);
$stmt = $conn->prepare("SELECT number_of_yes, number_of_no FROM posts_yes_no_info WHERE post_number=:post_id");
$stmt->execute([":post_id" => $data["post_id"]]);
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
$yes_no_tmp = array($row["number_of_yes"], $row["number_of_no"], "Success");
}
echo json_encode($yes_no_tmp);
} else if ($data['current_vote'] == "no" && $data['previous_vote'] == "nothing") {
$stmt = $conn->prepare("SELECT post_id,user_id FROM yes_no WHERE post_id=:post_id AND user_id=:id");
$stmt->execute([":post_id" => $data["post_id"], ":id" => $_SESSION["id"]]);
if ($stmt->rowCount() > 0) {
$stmt = $conn->prepare("UPDATE yes_no SET answer_no = 1 WHERE post_id=:post_id AND user_id=:id");
$stmt->execute([":post_id" => $data["post_id"], ":id" => $_SESSION["id"]]);
$stmt = $conn->prepare("SELECT number_of_yes, number_of_no FROM posts_yes_no_info WHERE post_number=:post_id");
$stmt->execute([":post_id" => $data["post_id"]]);
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
$yes_no_tmp = array($row["number_of_yes"], $row["number_of_no"], "Success");
}
echo json_encode($yes_no_tmp);
} else if ($stmt->rowCount() == 0) {
$stmt = $conn->prepare("INSERT INTO yes_no(post_id,user_id,poll_type,answer_yes,answer_no) VALUES (:post_id,:id,1,0,1)");
$stmt->execute([":post_id" => $data["post_id"], ":id" => $_SESSION["id"]]);
$stmt = $conn->prepare("SELECT number_of_yes, number_of_no FROM posts_yes_no_info WHERE post_number=:post_id");
$stmt->execute([":post_id" => $data["post_id"]]);
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
$yes_no_tmp = array($row["number_of_yes"], $row["number_of_no"], "Success");
}
echo json_encode($yes_no_tmp);
}
}
} else if ($data['request'] == "bookmark" && isset($_SESSION["loggedin"]) && $_SESSION["loggedin"] == true) {
require_once "new_config.php";
if ($data['current_state'] == "checked" && $data['previous_state'] == "checked") {
$stmt = $conn->prepare("UPDATE bookmarks SET user_bookmark = 0 WHERE post_id=:post_id AND user_id=:id");
$stmt->execute([":post_id" => $data["post_id"], ":id" => $_SESSION["id"]]);
echo "Success";
} else if ($data['current_state'] == "checked" && $data['previous_state'] == "not_checked") {
$stmt = $conn->prepare("SELECT post_id,user_id FROM bookmarks WHERE post_id=:post_id AND user_id=:id");
$stmt->execute([":post_id" => $data["post_id"], ":id" => $_SESSION["id"]]);
if ($stmt->rowCount() > 0) {
$stmt = $conn->prepare("UPDATE bookmarks SET user_bookmark = 1 WHERE post_id=:post_id AND user_id=:id");
$stmt->execute([":post_id" => $data["post_id"], ":id" => $_SESSION["id"]]);
echo "Success";
} else if ($stmt->rowCount() == 0) {
$stmt = $conn->prepare("INSERT INTO bookmarks(post_id,user_id,user_bookmark) VALUES (:post_id,:id,1)");
$stmt->execute([":post_id" => $data["post_id"], ":id" => $_SESSION["id"]]);
echo "Success";
}
}
} else if ($data['request'] == "yes_no_data") {
require_once "new_config.php";
$stmt = $conn->prepare("SELECT number_of_yes,number_of_no FROM posts_yes_no_info WHERE post_number=:post_id");
$stmt->execute([":post_id" => $data["post_id"]]);
if ($stmt->rowCount() > 0) {
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
$tmp = array($row["number_of_yes"], $row["number_of_no"]);
}
}
echo json_encode($tmp);
} else if ($data['request'] == "location_responses_data") {
require_once "new_config.php";
$location_responses_data = array();
$post_ids_string = "";
if (!isset($data["post_ids"])) {
$post_ids_string = ".";
} else {
if (count($data["post_ids"]) == 0) {
$post_ids_string = "zero";
} else if (count($data["post_ids"]) > 0) {
$post_ids_string = "";
for ($i = 0; $i < count($data["post_ids"]); $i++) {
if (count($data["post_ids"]) == 1) {
$post_ids_string .= "[[:<:]]" . $data["post_ids"][$i] . "[[:>:]]";
} else if (count($data["post_ids"]) > 1 && $i < count($data["post_ids"]) - 1) {
$post_ids_string .= "[[:<:]]" . $data["post_ids"][$i] . "[[:>:]]|";
} else if (count($data["post_ids"]) > 1 && $i == count($data["post_ids"]) - 1) {
$post_ids_string .= "[[:<:]]" . $data["post_ids"][$i] . "[[:>:]]";
}
}
}
}
$stmt = $conn->prepare("SELECT posts.post_loc_lat AS post_latitude, posts.post_loc_long AS post_longitude, (SELECT COUNT(post_number) FROM posts WHERE posts.post_loc_lat=post_latitude
AND post_loc_long=post_longitude AND posts.post_number RLIKE :post_ids GROUP BY post_loc_lat,post_loc_long) AS number_of_posts_in_location,(SELECT COUNT(yes_no.post_id) FROM yes_no
INNER JOIN posts ON yes_no.post_id=posts.post_number WHERE (yes_no.answer_yes=1 OR yes_no.answer_no=1) AND posts.post_loc_lat=post_latitude
AND posts.post_loc_long=post_longitude AND posts.post_number RLIKE :post_ids) + (SELECT COUNT(rating.post_id) FROM rating
INNER JOIN posts ON rating.post_id=posts.post_number WHERE (rating.choice_one IS NOT NULL OR rating.choice_two IS NOT NULL OR rating.choice_three IS NOT NULL
OR rating.choice_four IS NOT NULL OR rating.choice_five IS NOT NULL) AND posts.post_loc_lat=post_latitude
AND posts.post_loc_long=post_longitude AND posts.post_number RLIKE :post_ids) + (SELECT COUNT(approval.post_id) FROM approval
INNER JOIN posts ON approval.post_id=posts.post_number WHERE (approval.choice_one IS NOT NULL OR approval.choice_two IS NOT NULL OR approval.choice_three IS NOT NULL
OR approval.choice_four IS NOT NULL OR approval.choice_five IS NOT NULL) AND posts.post_loc_lat=post_latitude
AND posts.post_loc_long=post_longitude AND posts.post_number RLIKE :post_ids) AS number_of_responses_in_location
FROM posts INNER JOIN yes_no ON posts.post_number=yes_no.post_id WHERE posts.post_number RLIKE :post_ids GROUP BY post_loc_lat,post_loc_long");
$stmt->execute([":post_ids" => $post_ids_string]);
if ($stmt->rowCount() > 0) {
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
$tmp = array($row["post_latitude"], $row["post_longitude"], $row["number_of_posts_in_location"], $row["number_of_responses_in_location"]);
array_push($location_responses_data, $tmp);
}
}
echo json_encode($location_responses_data);
} else if ($data['request'] == "get_admin_analytics_data" && isset($_SESSION["loggedin"]) && $_SESSION["loggedin"] == true) {
require_once "new_config.php";
$admin_chart_data = array();
if (!isset($data["admin_time_filter"])) {
$admin_time_filter = array("2020-01-01 00:00", "2090-01-01 00:00");
$stmt = $conn->prepare("SELECT COUNT(post_number) AS number_of_posts, CAST(post_date AS DATE) AS date_only FROM posts
WHERE post_date BETWEEN :first_date AND :second_date GROUP BY date_only");
$stmt->execute([":first_date" => $admin_time_filter[0], ":second_date" => $admin_time_filter[1]]);
if ($stmt->rowCount() > 0) {
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
$tmp = array($row["number_of_posts"], $row["date_only"]);
array_push($admin_chart_data, $tmp);
}
}
echo json_encode($admin_chart_data);
} else if (strpos($data["admin_time_filter"], ",") == true && $data["filter_type"] == "different_days_with_range") {
$admin_time_filter = explode(",", $data["admin_time_filter"]);
$stmt = $conn->prepare("SELECT COUNT(post_number) AS number_of_posts, CAST(post_date AS DATE) AS date_only FROM posts
WHERE post_date BETWEEN :first_date AND :second_date GROUP BY date_only");
$stmt->execute([":first_date" => $admin_time_filter[0], ":second_date" => $admin_time_filter[1]]);
if ($stmt->rowCount() > 0) {
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
$tmp = array("different_days_with_range", $row["number_of_posts"], $row["date_only"]);
array_push($admin_chart_data, $tmp);
}
}
echo json_encode($admin_chart_data);
} else if (strpos($data["admin_time_filter"], ",") == true && $data["filter_type"] == "same_day_with_range") {
$admin_time_filter = explode(",", $data["admin_time_filter"]);
$stmt = $conn->prepare("SELECT CAST(post_date AS TIME) AS time_only FROM posts WHERE post_date BETWEEN :first_date AND :second_date");
$stmt->execute([":first_date" => $admin_time_filter[0], ":second_date" => $admin_time_filter[1]]);
if ($stmt->rowCount() > 0) {
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
$tmp = array("same_day_with_range", $row["time_only"]);
array_push($admin_chart_data, $tmp);
}
}
echo json_encode($admin_chart_data);
}
} else if ($data['request'] == "get_geolocation_data") {
require_once "new_config.php";