-
Notifications
You must be signed in to change notification settings - Fork 0
/
index_3.php
112 lines (102 loc) · 2.5 KB
/
index_3.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
<?php
header("Content-Type: application/json");
/* Connection Properties */
$hostname = "mysql3.gear.host";
$database = "shakefacility";
$user = "shakefacility";
$pass = "AD1_facilities";
/* Start Connection */
$conn = mysqli_connect($hostname, $user, $pass, $database);
if (!$conn)
{
$response = array('status' => 105, 'message' => mysqli_connect_error());
echo json_encode($response);
exit(0);
}
/* Check POST Request Values */
if (!isset($_GET['pi']))
{
$response = array('status' => 104);
echo json_encode($response);
exit(0);
}
if (!isset($_GET['token']))
{
$response = array('status' => 101);
echo json_encode($response);
exit(0);
}
/* Check Token Validity */
$tkq = "SELECT token FROM token_list LIMIT 1";
$tkr = mysqli_query($conn, $tkq);
if (mysqli_num_rows($tkr) <= 0)
{
$response = array('status' => 100);
echo json_encode($response);
exit(0);
}
$tk_ref = mysqli_fetch_assoc($tkr);
if ($_GET['token'] != base64_encode($tk_ref['token']))
{
$response = array('status' => 102);
echo json_encode($response);
exit(0);
}
if (isset($_GET['qnum']))
{
if ($_GET['qnum'] == 1)
{
$trq = "SELECT trace_id, starttime, endtime, intensity, pga, pgv, data_status FROM " . $_GET['pi'] . "_trace_data ORDER BY trace_id DESC LIMIT 1";
}
else
{
$trq = "SELECT trace_id, starttime, endtime, intensity, pga, pgv, data_status FROM " . $_GET['pi'] . "_trace_data ORDER BY trace_id DESC";
}
}
else
{
$trq = "SELECT trace_id, starttime, endtime, intensity, pga, pgv, data_status FROM " . $_GET['pi'] . "_trace_data ORDER BY trace_id DESC";
}
$num_data = 0;
$trr = mysqli_query($conn, $trq);
if (mysqli_num_rows($trr) <= 0)
{
$response = array('status' => 106);
echo json_encode($response);
exit(0);
}
$response = array();
while($tr_row = mysqli_fetch_assoc($trr))
{
if ($tr_row['data_status'] == 0)
{
$response[] = array( 'status' => 4,
'starttime' => $tr_row['starttime'],
'endtime' => $tr_row['endtime'],
'intensity' => $tr_row['intensity'],
'pga' => $tr_row['pga'],
'pgv' => $tr_row['pgv']);
echo json_encode($response);
$num_data = $num_data + 1;
$dsq = "UPDATE " . $_GET['pi'] . "_trace_data SET data_status = 1 WHERE trace_id = " . $tr_row['trace_id'];
if (!(mysqli_query($conn, $dsq)))
{
$response = array('status' => 103);
echo json_encode($response);
exit(0);
}
}
else
{
break;
}
}
if ($num_data == 0)
{
$response = array( 'status' => 5,
'message' => 'No New Data Found');
echo json_encode($response);
exit(0);
}
mysqli_close($conn);
?>