-
Notifications
You must be signed in to change notification settings - Fork 0
/
covid_visit_backend_b.php
73 lines (43 loc) · 1.94 KB
/
covid_visit_backend_b.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
<?php
session_start();
include "Connector.php";
if($_SERVER["REQUEST_METHOD"] == "POST" && $_SESSION['loggedin'] == true){
$datetime = date('Y-m-d H:i:s');
$client_id = $_SESSION['client_id'];
$JSON = array();
$store_data = array();
$store_data_1 = array();
$common_stores = array();
$positive_id=mysqli_query($db,"SELECT id, Covid_date FROM covid_cases WHERE DATEDIFF('$datetime',Covid_date)<=7");//Last 7 days of positive users
while($row = mysqli_fetch_assoc($positive_id)){
if (in_array($row,$JSON) == false){
array_push($JSON,$row);
}
}
for($i=0;$i<sizeof($JSON);$i++){
$positive_id = $JSON[$i]['id'];
$covid_date = $JSON[$i]['Covid_date'];
$stores_user = mysqli_query($db,"SELECT id_store, Name, Date_of_upload FROM user_visits WHERE User_id='$client_id' ");//Stores that the user of the app visited at last 7 days
$stores_positive_b = mysqli_query($db,"SELECT id_store, Name, Date_of_upload FROM user_visits WHERE User_id = '$positive_id' && DATEDIFF('$covid_date', Date_of_upload)<=7");//Stores that the positive users visited in span of 7 days after their covid declaration
while($row = mysqli_fetch_assoc($stores_positive_b)){
array_push($store_data,$row);
}
while($row = mysqli_fetch_assoc($stores_user)){
if(in_array($row, $store_data_1) == false){
array_push($store_data_1, $row);
}
}
}
for($i=0;$i<sizeof($store_data_1);$i++){
for($j=0;$j<sizeof($store_data);$j++){
$time_0 = strtotime($store_data_1[$i]['Date_of_upload']);
$time_1 = strtotime($store_data[$j]['Date_of_upload']);
//change
if($store_data_1[$i]['id_store'] == $store_data[$j]['id_store'] && abs($time_0 - $time_1)>7200){
array_push($common_stores,array('user_b'=>$store_data_1[$i],'other_users_b'=>$store_data[$j]));
}
}
}
echo json_encode($common_stores, true);
}
?>