-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGetData.php
More file actions
executable file
·133 lines (119 loc) · 3.8 KB
/
GetData.php
File metadata and controls
executable file
·133 lines (119 loc) · 3.8 KB
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
<?php
header('Content-Type: application/json');
require __DIR__ . '/Credentials.php';
$Conn = new mysqli($Servername, $Username, $Password, $Dbname);
if ($Conn->connect_error) {
die("Database connection failed: " . $Conn->connect_error);
}
function StringOrEmpty($Value)
{
if ($Value === null) {
return '';
}
return strval($Value);
}
function GetSubjectData($SubjectId, $Table)
{
global $Conn;
$AllowedTables = array('TItrainIO', 'TIprobeIO');
if (!in_array($Table, $AllowedTables, true)) {
return array(
'DateTime_Write' => '',
'ClientTimeZone' => '',
'Json' => ''
);
}
$SubjectId = mysqli_real_escape_string($Conn, $SubjectId);
$Sql = "SELECT DateTime_Write, ClientTimeZone, $Table FROM $Table WHERE SubjectId = '$SubjectId';";
$QueryRes = mysqli_query($Conn, $Sql);
if (!$QueryRes) {
$Conn->close();
die("Query Sql failed to execute successfully");
}
$Data = array(
'DateTime_Write' => '',
'ClientTimeZone' => '',
'Json' => ''
);
if ($Row = mysqli_fetch_assoc($QueryRes)) {
$Data['DateTime_Write'] = StringOrEmpty($Row['DateTime_Write']);
$Data['ClientTimeZone'] = StringOrEmpty($Row['ClientTimeZone']);
$Data['Json'] = StringOrEmpty($Row[$Table]);
}
return $Data;
}
$Sql = "SELECT * FROM Register;";
$QueryRes = mysqli_query($Conn, $Sql);
$Data = array(
'SubjectId' => array(),
'BMY' => array(),
'Gender' => array(),
'Handedness' => array(),
'L1' => array(),
'State' => array(),
'GroupId' => array(),
'ImgPerm' => array(),
'DateTime_Landing' => array(),
'DateTime_Consent' => array(),
'DateTime_Register' => array(),
'DateTime_TIinstr' => array(),
'DateTime_TItrain' => array(),
'DateTime_TIprobe' => array(),
'ClientTimeZone' => array(),
'TItrainIO' => array(),
'TIprobeIO' => array()
);
if (!$QueryRes) {
$Conn->close();
die("Query Sql failed to execute successfully");
} else {
while ($Row = mysqli_fetch_assoc($QueryRes)) {
$SubjectId = StringOrEmpty($Row["SubjectId"]);
$BMY = StringOrEmpty($Row["BMY"]);
$Gender = StringOrEmpty($Row["Gender"]);
$Handedness = StringOrEmpty($Row["Handedness"]);
$L1 = StringOrEmpty($Row["L1"]);
$State = StringOrEmpty($Row["State"]);
$GroupId = StringOrEmpty($Row["GroupId"]);
$ImgPerm = StringOrEmpty($Row["ImgPerm"]);
$DateTime_Landing = StringOrEmpty($Row["DateTime_Landing"]);
$DateTime_Consent = StringOrEmpty($Row["DateTime_Consent"]);
$DateTime_Register = StringOrEmpty($Row["DateTime_Register"]);
$DateTime_TIinstr = StringOrEmpty($Row["DateTime_TIinstr"]);
$DateTime_TItrain = StringOrEmpty($Row["DateTime_TItrain"]);
$DateTime_TIprobe = StringOrEmpty($Row["DateTime_TIprobe"]);
$TrainData = GetSubjectData($SubjectId, 'TItrainIO');
$ClientTimeZone = $TrainData["ClientTimeZone"];
if ($TrainData["DateTime_Write"] !== '') {
$DateTime_TItrain = $TrainData["DateTime_Write"];
}
$TItrainIO = $TrainData["Json"];
$ProbeData = GetSubjectData($SubjectId, 'TIprobeIO');
if ($ClientTimeZone === '') {
$ClientTimeZone = $ProbeData["ClientTimeZone"];
}
if ($ProbeData["DateTime_Write"] !== '') {
$DateTime_TIprobe = $ProbeData["DateTime_Write"];
}
$TIprobeIO = $ProbeData["Json"];
$Data['SubjectId'][] = $SubjectId;
$Data['BMY'][] = $BMY;
$Data['Gender'][] = $Gender;
$Data['Handedness'][] = $Handedness;
$Data['L1'][] = $L1;
$Data['State'][] = $State;
$Data['GroupId'][] = $GroupId;
$Data['ImgPerm'][] = $ImgPerm;
$Data['DateTime_Landing'][] = $DateTime_Landing;
$Data['DateTime_Consent'][] = $DateTime_Consent;
$Data['DateTime_Register'][] = $DateTime_Register;
$Data['DateTime_TIinstr'][] = $DateTime_TIinstr;
$Data['ClientTimeZone'][] = $ClientTimeZone;
$Data['DateTime_TItrain'][] = $DateTime_TItrain;
$Data['DateTime_TIprobe'][] = $DateTime_TIprobe;
$Data['TItrainIO'][] = $TItrainIO;
$Data['TIprobeIO'][] = $TIprobeIO;
}
}
$Conn->close();
echo (json_encode($Data));