-
Notifications
You must be signed in to change notification settings - Fork 0
/
scaleCheckin.php
282 lines (256 loc) · 9.77 KB
/
scaleCheckin.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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
<?php
session_start();
require_once ('config.php');
require_once ('framework.php');
require_once ( 'php/ismobile.class.php' );
/*header("Cache-Control: no-store, no-cache, must-revalidate"); // HTTP/1.1
header("Cache-Control: post-check=0, pre-check=0", false);
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
header("Pragma: no-cache"); // HTTP/1.0
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");*/
@ $fw = new scaleDB( SQL_HOST, SQL_USER, SQL_PASS, SQL_DB );
@ $ismobi = new IsMobile();
if ( $fw->isLoggedIn( $_SESSION ) && $fw->isValidUser( $_SESSION ) ) {
if ( $_SERVER['REQUEST_METHOD'] == 'POST' ) {
$techname = $_SESSION['USER']['fullname'];
$companyname = $fw->clean_input($_POST['companyname']);
$street = $fw->clean_input($_POST['street']);
$city = $fw->clean_input($_POST['city']);
$state = $fw->clean_input($_POST['state']);
$zipcode = $fw->clean_input($_POST['zipcode']);
$indicator_tag = $fw->clean_input($_POST['indicator_tag']);
$indicator_manu = $fw->clean_input($_POST['indicator_manu']);
$indicator_model = $fw->clean_input($_POST['indicator_model']);
$indicator_serial = $fw->clean_input($_POST['indicator_serial']);
$scale_manu = $fw->clean_input($_POST['scale_manu']);
$scale_model = $fw->clean_input($_POST['scale_model']);
$scale_serial = $fw->clean_input($_POST['scale_serial']);
$scale_capacity = $fw->clean_input($_POST['scale_capacity']);
$scale_divisions = $fw->clean_input($_POST['scale_divisions']);
$units = $fw->clean_input($_POST['units']);
$date = date('m/d/Y') . " @ " . date('h:i:s A');
$comments = $fw->clean_input($_POST['comments']);
$status = "Pending";
if ( $state == "NULL" ) {
$state == "IN";
} else {
$state = strtoupper( $state );
}
$digest = md5( $_SESSION['USER']['fullname'] .
$_POST['companyname'] .
$_POST['street'] .
$_POST['city'] .
$_POST['state'] .
$_POST['indicator_manu'] .
$_POST['indicator_model'] .
$_POST['indicator_serial'] .
$_POST['scale_manu'] .
$_POST['scale_model'] .
$_POST['scale_serial'] .
$_POST['scale_capacity'] .
$_POST['scale_divisions']
);
$sessionDigest = isset($_SESSION['digest']) ? $_SESSION['digest']: '';
if( $digest != $sessionDigest ) {
#First database query to insert the user submitted data into the scales table
$query1 = "insert into scales values\r\n" .
"('NULL', " .
"'" . $status . "', " .
"'" . $date . "', " .
"'" . $date . "', " .
"'" . $techname . "', " .
"'" . $companyname . "', " .
"'" . $street . "', " .
"'" . $city . "', " .
"'" . $state . "', " .
"'" . $zipcode . "', " .
"'" . $indicator_tag . "', " .
"'" . $indicator_manu . "', " .
"'" . $indicator_model . "', " .
"'" . $indicator_serial . "', " .
"'" . $scale_manu . "', " .
"'" . $scale_model . "', " .
"'" . $scale_serial . "', " .
"'" . $scale_capacity . "', " .
"'" . $scale_divisions . "', " .
"'" . $units . "'); ";
$result = $fw->query($query1);
#END first query
#Second Database query to get the new scale ID that was just set
$query2 = "select id from scales where date like '" . $date . "'";
$result2 = $fw->query($query2);
$ID = 0;
while($row = $result2->fetch_assoc()) {
$ID = $row['id'];
}
#END second query
#Third database query to set the comments into its own table
$query3 = "insert into events values\r\n" .
"('NULL', " .
"'" . $date . "', " .
"'" . $ID . "', " .
"'" . $techname . "', " .
"'Created the scale entry', " .
"'" . NULL . "', ".
"'" . $comments . "'); ";
$result3 = $fw->query($query3);
#END third query
if ( $result ) {
$_SESSION['digest'] = $digest;
$_SESSION['scaleCheckin']['result'] = "Your new ticket was successfully added!<br>You can view the new ticket <a href=\"viewScale.php?id=$ID\">here</a>.";
#$result = "Your new ticket was successfully added!";
unset( $_POST );
} else {
$_SESSION['scaleCheckin']['error'] = "Something went wrong when submitting your ticket to the database. Please try again.";
#$result = "Something went wrong when submitting your ticket to the database. Please try again.";
}
} else {
$_SESSION['digest'] = $digest;
$_SESSION['scaleCheckin']['error'] = "This information has already been submitted. There is no need to re-submit this ticket information.";
#$result = "This information has already been submitted. There is no need to re-submit this ticket information.";
unset( $_POST );
}
}
?>
<?php include ('header.php');
if ( isset( $_SESSION['scaleCheckin']['error'] ) ) {
echo "<div class=\"error\">". $_SESSION['scaleCheckin']['error'] ."</div>";
unset( $_SESSION['scaleCheckin'] );
} elseif ( isset( $_SESSION['scaleCheckin']['result'] ) ) {
echo "<div class=\"result\">". $_SESSION['scaleCheckin']['result'] ."</div>";
unset( $_SESSION['scaleCheckin'] );
}
?>
<h2> Scale Check-in</h2>
<form action="scaleCheckin.php" method="post">
<!--<input class="hidden" name="status" type="text" size="25" maxlength="40" value="Pending" hidden />
<table hidden>
<tr>
<th colspan="2">Technician</th>
</tr>
<tr>
<td>Full Name:</td>
<td><input name="techname" type="text" size="25" maxlength="40" value="<?php #echo $_SESSION['val_fullname']; ?>" /></td>
</tr>
</table>
This needs to be built in and using the session var -->
<table class="table-style">
<tr>
<th colspan="2">Customer Information</th>
</tr>
<tr>
<td>Company Name:</td>
<td><input name="companyname" pattern="[A-Za-z0-9 ]{1,}" type="text" size="25" maxlength="40" placeholder="Pretzels" required /></td>
</tr>
<tr>
<td>Street:</td>
<td><input name="street" pattern="[A-Za-z0-9 ]{1,}" type="text" size="25" maxlength="25" placeholder="123 Harvest Rd"/></td>
</tr>
<tr>
<td>City:</td>
<td><input name="city" pattern="[A-Za-z0-9 ]{1,}" type="text" size="25" maxlength="15" placeholder="Bluffton"/></td>
</tr>
<tr>
<td>State:</td>
<td><input name="state" pattern="[A-Za-z]{2}" type="text" size="2" maxlength="2" placeholder="IN"/></td>
</tr>
<tr>
<td>Zip Code:</td>
<td><input name="zipcode" pattern="[0-9]{5,}" type="text" size="8" maxlength="15" placeholder="46714"/></td>
</tr>
</table>
<br />
<table class="table-style">
<tr>
<th colspan="2">Indicator Information</th>
</tr>
<tr>
<td>Tag Number:</td>
<td><input name="indicator_tag" type="text" size="25" maxlength="15" placeholder="23" required /></td>
</tr>
<tr>
<td>Manufacturer:</td>
<td><input name="indicator_manu" type="text" size="25" maxlength="25" placeholder="GSE" required /></td>
</tr>
<tr>
<td>Model:</td>
<td><input name="indicator_model" type="text" size="25" maxlength="25" placeholder="465" required /></td>
</tr>
<tr>
<td>Serial:</td>
<td><input name="indicator_serial" type="text" size="25" maxlength="20" placeholder="016748" required /></td>
</tr>
<tr>
<td>Capacity:</td>
<td><input name="scale_capacity" pattern="[0-9]{1,10}" type="text" size="10" maxlength="10" placeholder="5000" title="Numbers only" /></td>
</tr>
<tr>
<td>Divisions:</td>
<td><input name="scale_divisions" pattern="(0.)?[0-9]{1,}" type="text" size="6" maxlength="10" placeholder="0.5" title="Example: 1 or 0.01" /></td>
</tr>
<?php if ( $ismobi->CheckMobile() ) { ?>
</table>
<fieldset data-role="controlgroup">
<legend> Units:</legend>
<input type="radio" name="units" id="radio-choice-v-2a" value="lb" checked="checked" />
<label for="radio-choice-v-2a">Pounds</label>
<input type="radio" name="units" id="radio-choice-v-2b" value="kg" />
<label for="radio-choice-v-2b">Kilograms</label>
<input type="radio" name="units" id="radio-choice-v-2c" value="g" />
<label for="radio-choice-v-2c">Grams</label>
<input type="radio" name="units" id="radio-choice-v-2d" value="oz" />
<label for="radio-choice-v-2d">Ounces</label>
</fieldset>
<?php } else { ?>
<tr>
<td>Units:</td>
<td>
<input name="units" type="radio" value="lb" checked>lb</input>
<input name="units" type="radio" value="kg">kg</input>
<input name="units" type="radio" value="g">g</input>
<input name="units" type="radio" value="oz">oz</input>
</td>
</tr>
</table>
<?php } ?>
<br />
<table class="table-style">
<tr>
<th colspan="2">Scale Information</th>
</tr>
<tr>
<td>Manufacturer:</td>
<td><input name="scale_manu" type="text" size="25" maxlength="25" placeholder="BTEK" /></td>
</tr>
<tr>
<td>Model:</td>
<td><input name="scale_model" type="text" size="25" maxlength="25" placeholder="BT-4848-CS-SB" /></td>
</tr>
<tr>
<td>Serial:</td>
<td><input name="scale_serial" type="text" size="25" maxlength="20" placeholder="serial" /></td>
</tr>
<tr>
<td>Scale Comments: </td>
<td></td>
</tr>
<tr>
<td colspan="2"><textarea class="fixed" name="comments" type="text" id="comments" maxlength="1000" placeholder="Enter repair comments here" required ></textarea></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="submit" value="Submit" /></td>
</tr>
</table>
<br />
<?php #if ( $ismobi->CheckMobile() ) { echo '<label for="comments"> Scale Comments:</label>'; }
#else { echo 'Scale Comments: <br />'; } ?>
</form>
</body>
</html>
<?php
} else {
echo "You must be logged in to view this page.";
header( "Location: login.php" );
}
?>