-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathid1.php
More file actions
262 lines (234 loc) · 7.41 KB
/
Copy pathid1.php
File metadata and controls
262 lines (234 loc) · 7.41 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
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
<?php
// Date in the past
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Cache-Control: no-cache");
header("Pragma: no-cache");
header("CDN-Cache-Control: no-store");
require __DIR__ . '/vendor/autoload.php';
//load .env file
use Dotenv\Dotenv;$dotenv = Dotenv::createImmutable(__DIR__);
$dotenv->load();
//setup Ntfy server
use Ntfy\Server;
use Ntfy\Message;
use Ntfy\Client;
$server = new Server($_ENV['ntfy_server_url']);
//setup mySQL connection
$conn = new mysqli($_ENV['mysql_servername'], $_ENV['mysql_username'], $_ENV['mysql_password'], $_ENV['mysql_dbname']);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
//lookup the card number
$card_number = $_GET['id'];
if (empty($card_number)) {
die("Card number is required.");
}
// get flag to set ntfy off
if (isset($_GET['ntfy'])) {
$ntfy = $_GET['ntfy'];}
else {
$ntfy = "true"; // default to true if not set
}
$sql = "SELECT full_name, pronouns FROM users WHERE id = ?";
$stmt = $conn->prepare($sql);
if ($stmt === false) {
die("Prepare failed: " . $conn->error);
}
$stmt->bind_param("i", $card_number);
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
$card_name = $row['full_name'];
$pronouns = $row['pronouns'];
}
} else {
die("No user found with the provided card number.");
}
$stmt->close();
// If ntfy is set to true, send a notification
if ($ntfy !== "false") {
//send notification to ntfy server
$url = $_ENV['web_root'] . "id1.php?id=" . $card_number . "&ntfy=false";
$message = new Message();
$message->topic($_ENV['ntfy_topic']);
$message->title($card_name . " Card Scanned");
$message->body('An ICE card has been scanned successfully.');
$message->priority(Message::PRIORITY_MAX);
$action = new Ntfy\Action\View();
$action->label('View Card');
$action->url($url);
$message->action($action);
$client = new Client($server);
$client->send($message);
}
?>
<html>
<head>
<title><?php echo $card_name; ?> - ICE</title>
<link rel="stylesheet" href="stylesheet.css" type="text/css" charset="utf-8" />
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png">
<link rel="manifest" href="/site.webmanifest">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<h1><?php echo $card_name . " (" . $pronouns . ")"; ?></h1>
<?php
// List Non-visibale conditions
$sql = "SELECT
conditions.id, conditions.condition, conditions.url
FROM
user_conditions
JOIN
conditions ON user_conditions.condition = conditions.id
WHERE
user_conditions.user = ?
ORDER BY conditions.condition;";
$stmt = $conn->prepare($sql);
if ($stmt === false) {
die("Prepare failed: " . $conn->error);
}
$stmt->bind_param("i", $card_number);
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows > 0) {
echo "<h2>Conditions</h2><h3>";
while($row = $result->fetch_assoc()) {
echo "<a href=\"" . $row['url'] . "\">" . $row['condition'] . "</a>, ";
}
echo "</h3>";
} else {
}
$stmt->close();
// List ICE Contacts
$sql = "select full_name, tel from users
join ice_contacts on ice_contacts.ice_user = users.id
where ice_contacts.card_user = ? order by ice_contacts.priority;";
$stmt = $conn->prepare($sql);
if ($stmt === false) {
die("Prepare failed: " . $conn->error);
}
$stmt->bind_param("i", $card_number);
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows > 0) {
echo "<h2>In Case of Emergency Contacts</h2>";
while($row = $result->fetch_assoc()) {
echo "<p>" . $row['full_name'] . " <a href=\"tel:" . $row['tel'] . "\">" . $row['tel'] . "</a></p>";
}
} else {
echo("No ICE users found for the provided card number.");
}
$stmt->close();
// List Icons
$sql = "SELECT
icons.id, icons.title, icons.description
FROM
user_icons
JOIN
icons ON user_icons.icon = icons.id
WHERE
user_icons.user = ?
ORDER BY user_icons.order;";
$stmt = $conn->prepare($sql);
if ($stmt === false) {
die("Prepare failed: " . $conn->error);
}
$stmt->bind_param("i", $card_number);
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows > 0) {
echo "<h2>Accessibility Needs</h2>";
while($row = $result->fetch_assoc()) {
echo "<p><img src=\"accessibility_icons\\" . $row['id'] . ".png\" width=48 height=48><b> " . $row['title'] . "</b><br>" . $row['description'] . "</p>";
}
} else {
}
$stmt->close();
// List Medication
$sql = "select medication from medication where user = ? order by medication;";
$stmt = $conn->prepare($sql);
if ($stmt === false) {
die("Prepare failed: " . $conn->error);
}
$stmt->bind_param("i", $card_number);
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows > 0) {
echo "<h2>Medication</h2>";
while($row = $result->fetch_assoc()) {
echo "<p>" . $row['medication'] . "</p>";
}
} else {
}
$stmt->close();
?>
<!-- Modal requesting location-->
<div id="myModal" class="modal">
<div class="modal-content">
<span class="close">×</span>
<h1>Please tap OK to share your location with emergency contact</h1>
<button class="button okButton">OK</button><button class="button cancelButton">Cancel</button>
</div>
</div>
<script>
// Get the modal
var modal = document.getElementById("myModal");
// Get the button that opens the modal
var btn = document.getElementById("myBtn");
// Get the <span> element that closes the modal
var closeX = document.getElementsByClassName("close")[0];
var closeCancel = document.getElementsByClassName("button cancelButton")[0];
// Get the button that confirms sharing location
var okButton = document.getElementsByClassName("button okButton")[0];
// When the user clicks on <span> (x), close the modal
closeX.onclick = function() {
modal.style.display = "none";
}
closeCancel.onclick = function() {
modal.style.display = "none";
}
okButton.onclick = function() {
modal.style.display = "none";
// Here you can add the code to share the location
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
var lat = position.coords.latitude;
var lon = position.coords.longitude;
// You can send this data to your server or use it as needed
console.log("Latitude: " + lat + ", Longitude: " + lon);
if (window.XMLHttpRequest){
xmlhttp = new XMLHttpRequest();
}
else{
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
var PageToSendTo = "location.php?";
var UrlToSend = PageToSendTo + "id=" + <?php echo $card_number; ?> + "&lat=" + lat + "&lon=" + lon;
xmlhttp.open("GET", UrlToSend, false);
xmlhttp.send();
}, function(error) {
console.error("Error obtaining location: " + error.message);
});
} else {
alert("Geolocation is not supported by this browser.");
}
}
// When the user clicks anywhere outside of the modal, close it
window.onclick = function(event) {
if (event.target == modal) {
modal.style.display = "none";
}
}
document.addEventListener('DOMContentLoaded', function() {
modal.style.display = "block";
}, false);
</script>
</body>
</html>
<?php
// Close the database connection
$conn->close();
?>