-
Notifications
You must be signed in to change notification settings - Fork 0
/
requestService.php
456 lines (375 loc) · 11 KB
/
requestService.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
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
<?php
require_once("header-user.php");
require_once("config/connection.php");
if (!isset($_SESSION["login_user"])) {
echo "<b> Access Denied<b>";
print_r($_SESSION["login_user"] . "S");
die();
return;
}
$user = $_SESSION["login_user"];
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$contact = $_POST["contact"];
$address = $_POST["address"];
$lat = $_POST["lat"];
$long = $_POST["lon"];
$img = $_POST["img"];
$id = $user["id"];
$desc = $_POST["desc"];
$sql = "INSERT into service(contact,citizen_id,address,latt,lon,image,status,description) VALUES ('$contact','$id','$address','$lat','$long','$img','1','$desc')";
if (mysqli_query($conn, $sql)) {
echo "1";
} else {
echo mysqli_errno($conn);
}
}
?>
<!DOCTYPE html>
<html>
<script type="text/javascript" src="webcamjs/webcam.min.js"></script>
<style>
* {
box-sizing: border-box;
}
body {
background-color: #f1f1f1;
}
#regForm {
margin: 0px auto;
padding: 0px;
width: 500px;
height: 700px;
min-width: auto;
justify-content: center;
text-align: center;
position: relative;
margin-top: 0px
}
h1 {
text-align: center;
}
input {
padding: 10px;
width: 100%;
font-size: 17px;
font-family: Raleway;
border: 1px solid #aaaaaa;
}
/* Mark input boxes that gets an error on validation: */
input.invalid {
background-color: #ffdddd;
}
/* Hide all steps by default: */
.tab {
display: none;
width: 100%;
height: auto;
padding: 5px;
}
button {
border: none;
padding: 10px 20px;
font-size: 17px;
font-family: Raleway;
cursor: pointer;
}
button:hover {
opacity: 0.8;
}
#prevBtn {
float: left;
}
/* Make circles that indicate the steps of the form: */
.step {
height: 15px;
width: 15px;
margin: 0 2px;
background-color: #bbbbbb;
border: none;
border-radius: 50%;
display: inline-block;
opacity: 0.5;
}
.step.active {
opacity: 1;
}
/* Mark the steps that are finished and valid: */
.step.finish {
background-color: #04AA6D;
}
.ss,
.rt {
display: none;
}
.loader {
border: 16px solid #f3f3f3;
border-radius: 50%;
border-top: 16px solid #3498db;
width: 120px;
height: 120px;
-webkit-animation: spin 2s linear infinite;
/* Safari */
animation: spin 2s linear infinite;
}
#map {
height: 400px;
/* The height is 400 pixels */
width: 100%;
/* The width is the width of the web page */
}
#my_camera{
padding: 0px;
}
/* Safari */
@-webkit-keyframes spin {
0% {
-webkit-transform: rotate(0deg);
}
100% {
-webkit-transform: rotate(360deg);
}
}
@keyframes spin {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
@media only screen and (max-width: 600px) {
#regForm {
width: 100%;
height: 100%;
}
}
</style>
<div class="container-fluid">
<div id="regForm">
<!-- One "tab" for each step in the form: -->
<div class="tab" id="imageupload">
<div id="my_camera"></div>
<br>
<p><input type=button class="btn btn-sm btn-primary form-control tt" style="width:100px;" value="Take Snapshot" onClick="take_snapshot()"> <input type=button class="btn btn-sm btn-primary form-control rt" style="width:100px;" value="Retake" onClick="retake()"><input type=button class="btn btn-sm btn-primary form-control ss" style="width:100px;" value="Upload" onClick="saveSnap()"></p>
</div>
<div class="tab">address Info:
<p><input placeholder="Address" oninput="this.className = ''" id="addr" name="address" onchange="getCoodinates()" disabled></p>
<div id="map"></div>
</div>
<div class="tab">Description:<br>
<textarea class="form-control" rows="15" cols="38" name="yyyy" id="desc"></textarea>
</div>
<div class="tab">Contact Info:
<p><input type="tel" placeholder="Contact Number..." oninput="this.className = ''" id="contact"></p>
</div>
<div style="overflow:auto;">
<div style="float:right;">
<button type="button" id="prevBtn" class="btn btn-outline-secondary" onclick="nextPrev(-1)">Previous</button>
<button type="button" id="nextBtn" class="btn btn-outline-primary" style="display:none;" onclick="nextPrev(1)">Next</button>
<button type="button" id="submitBtn" class="btn bnt-success" style="display:none;">Submit</button>
</div>
</div>
<!-- Circles which indicates the steps of the form: -->
<div style="text-align:center;margin-top:40px;">
<span class="step"></span>
<span class="step"></span>
<span class="step"></span>
<span class="step"></span>
</div>
</div>
</div>
<?php require_once("footer-user.php") ?>
<script>
let address;
let contact;
let lat;
let lon;
let desc;
let img;
$(document).ready(function() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(getCoodinates);
} else {
x.innerHTML = "Geolocation is not supported by this browser.";
}
console.log("sd");
})
function getCoodinates(position) {
lat = position.coords.latitude;
lon = position.coords.longitude;
const geocodingUrl = `https://maps.googleapis.com/maps/api/geocode/json?latlng=${lat},${lon}&key=AIzaSyCdk0GkRdoCCpgU-T_rBFoU_CFPWB5KnBM`;
fetch(geocodingUrl)
.then(response => response.json())
.then(data => {
address = data.results[0].formatted_address;
console.log(data.results[0].formatted_address);
$("#addr").val(address);
var lattlong = new google.maps.LatLng(lat, lon);
var myOptions = {
center: lattlong,
zoom: 15,
mapTypeControl: true,
navigationControlOptions: {
style: google.maps.NavigationControlStyle.SMALL
}
}
var maps = new google.maps.Map(document.getElementById("map"), myOptions);
var markers =
new google.maps.Marker({
position: lattlong,
map: maps,
title: "You are here!"
});
})
}
var currentTab = 0; // Current tab is set to be the first tab (0)
showTab(currentTab); // Display the current tab
function validateForm() {
// This function deals with validation of the form fields
var x, y, i, valid = true;
x = document.getElementsByClassName("tab");
y = x[currentTab].getElementsByTagName("input");
// A loop that checks every input field in the current tab:
for (i = 0; i < y.length; i++) {
// If a field is empty...
if (y[i].value == "") {
// add an "invalid" class to the field:
y[i].className += " invalid";
// and set the current valid status to false
valid = false;
}
}
// If the valid status is true, mark the step as finished and valid:
if (valid) {
document.getElementsByClassName("step")[currentTab].className += " finish";
}
return valid; // return the valid status
}
function showTab(n) {
var x = document.getElementsByClassName("tab");
x[n].style.display = "block";
//... and fix the Previous/Next buttons:
if (n == 0) {
document.getElementById("prevBtn").style.display = "none";
} else {
document.getElementById("prevBtn").style.display = "inline";
}
if (n == (x.length - 1)) {
document.getElementById("nextBtn").style.display = "none";
document.getElementById("submitBtn").style.display = "inline-block";
} else {
document.getElementById("nextBtn").innerHTML = "Next";
}
//... and run a function that will display the correct step indicator:
fixStepIndicator(n)
}
function nextPrev(n) {
// This function will figure out which tab to display
var x = document.getElementsByClassName("tab");
// Exit the function if any field in the current tab is invalid:
if (n == 1 && !validateForm()) return false;
// Hide the current tab:
x[currentTab].style.display = "none";
// Increase or decrease the current tab by 1:
currentTab = currentTab + n;
// if you have reached the end of the form...
if (currentTab >= x.length) {
// ... the form gets submitted:
document.getElementById("regForm").submit();
return false;
}
// Otherwise, display the correct tab:
showTab(currentTab);
}
function fixStepIndicator(n) {
// This function removes the "active" class of all steps...
var i, x = document.getElementsByClassName("step");
for (i = 0; i < x.length; i++) {
x[i].className = x[i].className.replace(" active", "");
}
//... and adds the "active" class on the current step:
x[n].className += " active";
}
// webcam
Webcam.set({
width: 380,
height: 640,
image_format: 'jpeg',
jpeg_quality: 100,
align:'center',
constraints: {
facingMode: 'environment'
}
});
Webcam.attach('#my_camera');
function take_snapshot() {
// take snapshot and get image data
Webcam.snap(function(data_uri) {
// display results in page
document.getElementById('my_camera').innerHTML =
'<img id="imageprev" src="' + data_uri + '"/>';
});
$(".rt").css("display", "inline-block");
$(".ss").css("display", "inline-block");
}
function retake() {
document.getElementById('my_camera').innerHTML = "";
Webcam.set({
width: 380,
height: 640,
image_format: 'jpeg',
jpeg_quality: 100,
align:'center',
constraints: {
facingMode: 'environment'
}
});
Webcam.attach('#my_camera');
$(".rt").css("display", "none");
$(".ss").css("display", "none");
}
function saveSnap() {
$(".ss").val("Please wait..")
$(".rt").css("display", "none");
$(".tt").css("display", "none");
// Get base64 value from <img id='imageprev'> source
var base64image = document.getElementById("imageprev").src;
console.log(base64image)
Webcam.upload(base64image, 'config/image_upload.php', function(code, text) {
console.log('Save successfully');
image = text;
$(".ss").val("uploaded");
$("#nextBtn").css("display", "block")
});
}
$("#submitBtn").click(function() {
contact = $("#contact").val();
desc = document.getElementById("desc").value;
$.ajax({
url: "requestService.php",
type: "POST",
data: {
address: address,
lat: lat,
lon: lon,
img: image,
contact: contact,
desc: desc
},
success: function(res) {
Swal.fire({
position: 'top-end',
icon: 'success',
title: 'Your request has been register',
showConfirmButton: false,
timer: 1500
})
setTimeout(function() {
window.location.href = "home.php"
}, 1510)
}
})
})
</script>
<script async src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCdk0GkRdoCCpgU-T_rBFoU_CFPWB5KnBM&callback=initMap">
</script>