-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclock_IO.php
More file actions
129 lines (108 loc) · 4.62 KB
/
clock_IO.php
File metadata and controls
129 lines (108 loc) · 4.62 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
<?php require_once 'controllers/session_check.php';?>
<!doctype html>
<html lang="en">
<head>
<title>Worker Portal</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<?php include "script.php";?>
<?php include "style.php";?>
<?php require "controllers/functions.php";?>
</head>
<body>
<div class="p-5">
<?php include 'navbar.php';?>
</div>
<div class="container">
<div class="row">
<div class="col-lg-9 mx-auto">
<div class="card shadow-lg my-3">
<div class="card-body">
<h1 class="card-title text-center">Clock In/Out</h1><hr />
<form action="controllers/clock_IO_controller.php" method="post">
<div class="form-row">
<div class="form-group col-md-4 mx-auto">
<select class="form-control text-center" name="IO">
<option value='in'>Clock In</option>
<option value='out'>Clock Out</option>
</select>
</div>
</div>
<div class="form-row">
<div class="col-md-6">
<div class="form-group">
<div class="input-group date" id="datetimepicker1" data-target-input="nearest">
<input type="text" name="dateTime" class="form-control datetimepicker-input" data-target="#datetimepicker1" placeholder="Date and Time" required/>
<div class="input-group-append" data-target="#datetimepicker1" data-toggle="datetimepicker">
<div class="input-group-text"><i class="fa fa-calendar"></i></div>
</div>
</div>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<select class="form-control projectAddress" name="projectAddress" required>
<option selected disabled>Project Address</option>
<?php generateUsersActiveProjects();?>
</select>
</div>
</div>
</div>
<input id="inrange" type=hidden name="inrange" value=0></input>
<div class="text-center">
<button class="btn btn-dark btn-clock text-uppercase" type="submit" name="submit" id="submit">Submit</button>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
<script>
// Change the value of whether you are at the site or not when the selector changes
$('select.projectAddress').on('change', function() {
jQuery.get('apikey.ini', function(key) {
// Gets address and converts to coordinates via ajax call
var selected = $("select.projectAddress").children("option:selected").val();
var addressArray = selected.split(" ");
var urlStr = "https://maps.googleapis.com/maps/api/geocode/json?address=" + addressArray[0];
for (var i = 1; i < addressArray.length; i++) {
urlStr = urlStr + "+";
urlStr = urlStr + addressArray[i];
}
urlStr = urlStr + "&key=" + key;
$.ajax({
type: "GET",
url: urlStr,
success: function(responseData, status){
// Gets the user location
$.ajax({
type: "POST",
url: 'https://www.googleapis.com/geolocation/v1/geolocate?key=' + key,
success: function(data, status) {
var projectLat = responseData.results[0].geometry.location.lat;
var projectLng = responseData.results[0].geometry.location.lng;
var userLat = data.location.lat;
var userLng = data.location.lng;
// Detect if user is close enough to project
if (userLat <= projectLat + 0.002 && userLat >= projectLat - 0.002 && userLng <= projectLng + 0.002 && userLng >= projectLng - 0.002) {
console.log("In range!");
$('#inrange').val(1);
} else {
console.log("Not in range");
$('#inrange').val(0);
}
}, error: function(msg) {
alert("There was a problem.");
}
});
}, error: function(msg) {
alert("There was a problem.");
}
});
});
});
</script>
<script type="text/javascript" src="js/clock_IO.js"></script>
</body>
</html>