-
Notifications
You must be signed in to change notification settings - Fork 0
/
user_form.php
165 lines (151 loc) · 7.74 KB
/
user_form.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
<?php
session_start();
require 'aws/aws-autoloader.php';
require_once("support.php");
date_default_timezone_set('UTC');
use Aws\DynamoDb\Exception\DynamoDbException;
use Aws\DynamoDb\Marshaler;
use Aws\Sns\SnsClient;
$title = "User Form";
$body = <<<EOBODY
<h1> User Form Submission </h1>
<h3>Enter in the information for the process you would like to have verified by our our extensive
Knowledge Based Machining Database </h3>
<form action="{$_SERVER['PHP_SELF']}" method="post">
<p>
<strong>Manufacturer: </strong><input type="text" name="manufacturer" id="manufacturer" required="required"/>
</p>
<p>
<strong>Tool ID: </strong><input type="text" name="tool" id="tool" required="required"/>
</p>
<p>
<strong>Material: </strong><input type="text" name="material" id="material" required="required"/>
</p>
<p>
<strong>Feature: </strong><input type="text" name="feature" id="feature" required="required"/>
</p>
<p>
<strong>Speed: </strong><input type="text" name="speed" id="speed" required="required"/>
</p>
<p>
<strong>Email Address: </strong><input type="email" name="email" id="email" required="required"/><br />
We will notify you when the given material and tool have been reviewed and verified
</p>
<p>
<input type="submit" name="submit" value="Submit Data" />
</p>
EOBODY;
if(isset($_POST['submit'])) {
$sdk = new Aws\Sdk([
'region' => 'us-east-1',
'version' => 'latest'
]);
$message = "";
$dynamodb = $sdk->createDynamoDb();
$marshaler = new Marshaler();
$main_table = "OMR_main";
$table = trim($_POST['manufacturer']);
$tool = $_POST['tool'];
$item = $marshaler->marshalJson('
{
"Tool_Id": "' . $tool . '"
}
');
$params = [
'TableName' => $table,
'Key' => $item
];
try {
$result = $dynamodb->getItem($params);
if ($result["Item"] == NULL) {
$body .= "<h2>We are sorry but we do not contain that Tool in our database. <br />
Please check back later or make sure you spelled correctly!</h2>";
} else {
$sns = $sdk->createSns();
$email = $_POST['email'];
$emailarn = preg_replace('/[\@\.]/', '', $email);
$topic_arn = $sns->createTopic(array(
'Name' => 'omr_response'.$emailarn
));
$subscriptionArn = $sns->listSubscriptionsByTopic(array(
'TopicArn' => $topic_arn["TopicArn"]
));
if($subscriptionArn["Subscriptions"] == NULL) {
$subscription = $sns->subscribe(array(
'Endpoint' => $email,
'Protocol' => 'email',
'TopicArn' => $topic_arn["TopicArn"]
));
$body .= "<h2>This must be your first time! <br />
Please confirm the subscription that was sent to the email you provided and submit again.</h2>";
} else {
$item = $result["Item"];
foreach ($item["Feature"] as $feature) {
if ($feature == $_POST['feature']) {
foreach ($item["Material"] as $container) {
foreach ($container as $list) {
foreach ($list as $material) {
if ($material == $_POST['material']) {
foreach ($item['Max Speed'] as $max_speed) {
if ($max_speed >= $_POST['speed']) {
foreach ($item['Min Speed'] as $min_speed) {
if ($min_speed <= $_POST['speed']) {
$key = $marshaler->marshalJson('
{
"Manufacturer": "' . $table . '",
"Tool_Id": "' . $tool . '"
}
');
$eav = $marshaler->marshalJson('
{
":m": ["' . $_POST['material'] . '"],
":s": ["' . $_POST['speed'] . '"]
}
');
$params = [
'TableName' => $main_table,
'Key' => $key,
'UpdateExpression' => 'set Material = list_append(Material, :m), Speed = list_append(Speed, :s)',
'ExpressionAttributeValues' => $eav,
'ReturnValues' => 'UPDATED_NEW'
];
try {
$result = $dynamodb->updateItem($params);
$message = "Your process has been verified and the OMR database has been updated! Enjoy!";
} catch (DynamoDbException $e) {
$message = "Oh No! Something went wrong with the database! Please Resubmit.";
}
} else {
$message = "The speed you specified exceeds the manufacturer specs";
}
}
} else {
$message = "The speed you specified exceeds the manufacturer specs";
}
}
}
}
}
}
} else {
$message = "The feature you require DNE in our database. We'll get back to you on that!";
}
}
if ($message == "") {
$message = "The Material you require DNE in our database We'll get back to you on that!";
}
$sns->publish(array(
'TopicArn' => $topic_arn["TopicArn"],
'Message' => $message,
'Subject' => "OMR Database Update: $tool"
));
$body .= "<h2>Data Submitted! Depending on the quality of the data provided, you can expect the OMR database
to be updated as soon as you receive notification that the verification process is complete</h2>";
}
}
} catch (DynamoDbException $e) {
echo $e->getMessage() . "\n";
}
}
$page = generatePage($body, $title);
echo $page;