-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathform_process.php
217 lines (189 loc) · 7.43 KB
/
form_process.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
<!DOCTYPE html>
<html lang="en">
<head>
<title>Sample Submission</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<br />
<?php
session_start();
/* Fields on Form */
$primacy_agency = $_SESSION['primacyagency'];
$watersystem_id = $_POST['watersystemid'];
$facility_id = $_POST['facilityid'];
$sampling_point_id = $_POST['samplingpointid'];
$sample_collected_date = $_POST['samplecollecteddate'];
$sample_received_date = $_POST['samplereceiveddate'];
$sample_for_compliance = $_POST['sampleforcompliance'];
$sample_comments = $_POST['samplecomments'];
$sample_lab_id_code = $_POST['samplelabidcode'];
$legal_entity_id = $_POST['legalentityid'];
$sample_result_agency_received_date = $_POST['sampleagencyreceiveddate'];
$datetime1 = new DateTime($sample_collected_date);
$datetime2 = new DateTime($sample_received_date);
$datetime3 = new DateTime($sample_result_agency_received_date);
$data_string = json_encode(array(
"sampleResultDataQuality" => array(
"identifier" => 38878
),
"sampleResultAgencyReceivedDate" => $datetime3->format(DateTime::ATOM),
"sampleResultAnalyte" => array(
"referenceIdentifier" => 30189
),
"microbialAbsentPresent" => "A",
// "microbialSourceType" => array(
// "identifier" => 45835
// ),
// "microbialInterference" => array(
// "identifier" => 38871
// ),
// "microbialUnitType" => array(
// "identifier" => 38856
// ),
"sampleJobPrimacyAgency" => array(
"primacyAgencyCode" => $primacy_agency
),
"sampleJobStatus" => array(
"identifier" => 39140
),
"sampleJobOrgCode" => $primacy_agency,
"sampleJobOrgType" => $primacy_agency,
"sampleWaterSystem" => array(
"waterSystemId" => $watersystem_id
),
"sampleCategory" => array(
"identifier" => 38826
),
"sampleFacility" => array(
"facilityIdentifier" => $facility_id
),
"sampleFacilitySamplingPoint" => array(
"samplingPointIdentifier" => $sampling_point_id
),
"sampleLabIdentificationCode" => $sample_lab_id_code,
"sampleLab" => array(
"legalEntityIdentifier" => $legal_entity_id
),
// "sampleCollector" => "Toll Collector",
"sampleCollectedDate" => $datetime1->format(DateTime::ATOM),
"sampleReceivedDate" => $datetime2->format(DateTime::ATOM),
"sampleType" => array(
"identifier" => 38831
),
// "microbialVolume" => 0,
// "sampleVolume" => array(
// "valueData" => 0
// ),
// "microbialVolumeUnits" => array(
// "identifier" => 38863
// ),
"sampleForCompliance" => $sample_for_compliance,
"sampleComments" => $sample_comments
));
/* Set Basic Autentication Username & Password */
$username = $_SESSION['username'];
$password = $_SESSION['password'];
/* Determine URL */
$post_url = "[ENDPOINT URL]/sample-data/" . $primacy_agency . "/microbial";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $post_url);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 20);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERPWD, $username.':'.$password);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Accept: application/json',
'Content-Type: application/json')
);
$result = curl_exec($ch);
if($result === false)
{
echo 'Curl error: ' . curl_error($ch);
}
$errors = curl_error($ch);
$returnCode = (int)curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
//echo $returnCode;
switch ($returnCode) {
case '400':
echo '<div class="alert alert-danger alert-dismissible"><strong>Warning!</strong> A bad argument has been submitted.</div>';
break;
case '401':
echo '<div class="alert alert-danger alert-dismissible"><strong>Warning!</strong> The user is not authorized to make a submission.</div>';
break;
case '403':
echo '<div class="alert alert-danger alert-dismissible"><strong>Warning!</strong> Access was denied.</div>';
break;
case '404':
echo '<div class="alert alert-danger alert-dismissible"><strong>Warning!</strong> Entity not found.</div>';
break;
case '409':
echo '<div class="alert alert-danger alert-dismissible"><strong>Warning!</strong> A duplicate entry already exists.</div>';
break;
case '422':
echo '<div class="alert alert-danger alert-dismissible"><strong>Warning!</strong> Your submission could not be processed. Please see errors below.</div>';
break;
case '500':
echo '<div class="alert alert-danger alert-dismissible"><strong>Warning!</strong> Internal Error detected.</div>';
break;
case '503':
echo '<div class="alert alert-danger alert-dismissible"><strong>Warning!</strong> Service unavailable. Please try again later.</div>';
break;
case '200':
echo '<div class="alert alert-success alert-dismissible"><strong>Success!</strong> Your have succesfully made a submission.</div>';
break;
case '201':
echo '<div class="alert alert-success alert-dismissible"><strong>Success!</strong> Your have succesfully created a record.</div>';
break;
case '204':
echo '<div class="alert alert-warning alert-dismissible"><strong>Warning!</strong> No entries found.</div>';
break;
case '202':
echo '<div class="alert alert-success alert-dismissible"><strong>Success!</strong> You submission has been accepted.</div>';
break;
case '501':
echo '<div class="alert alert-warning alert-dismissible"><strong>Warning!</strong> Not Implemented.</div>';
break;
case '504':
echo '<div class="alert alert-danger alert-dismissible"><strong>Warning!</strong> Gateway Timeout.</div>';
break;
default:
echo '<div class="alert alert-info alert-dismissible"><strong>Info</strong> No alerts or warnings found.</div>';
}
//var_dump($errors);
//print_r(json_decode($result, true));
$error = json_decode($result, true);
echo '<ul>';
foreach($error['pridexElement']['errorMessage'] as $item) {
$remove_errorcode = substr($item['text'], 27);
echo '<li><strong>' . $remove_errorcode . '</strong></li>';
}
foreach($error['pridexElement']['simpleSampleJob']['sampleList']['sample'] as $item) {
echo '<li><strong>Job Identifier: ' . $item['sampleJobIdentifier'] . '</strong></li>';
echo '<li><strong>Sample Identifier: ' . $item['sampleIdentifier'] . '</strong></li>';
}
$sample_result_id = $error['pridexElement']['simpleSampleJob']['sampleList']['sample'][0]['sampleResultAnalyteList']['sampleResultAnalyte'][0]['sampleResultIdentifier'];
if (!empty($sample_result_id)) {
echo '<li><strong>Sample Result Identifier: ' . $sample_result_id . '</strong></li>';
}
echo '</ul>';
//print_r($result);
echo '<script>';
echo 'console.log(' . json_encode($result) . ');';
echo '</script>';
?>
<br />
<a href="submission.php">Go back to re-submit.</a>
</div>
</body>
</html>