-
Notifications
You must be signed in to change notification settings - Fork 0
/
emergency.php
59 lines (58 loc) · 2.45 KB
/
emergency.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
<?php
require_once "pdo.php";
session_start();
if ((isset($_COOKIE['lat']) && isset($_COOKIE['long']))) {
$_SESSION['lat'] = $_COOKIE['lat'];
$_SESSION['long'] = $_COOKIE['long'];
unset($_COOKIE['lat']);
unset($_COOKIE['long']);
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="static/css/style.css">
<link rel="stylesheet" href="static/css/nav.css">
<link rel="icon" type="image/x-icon" href="static/imgs/favicon.ico">
<title>Medico: Locate nearby hospitals</title>
</head>
<body onload="getLocation()">
<?php require_once "nav.php" ?>
<section>
<?php
if (isset($_SESSION['lat']) && isset($_SESSION['long'])) {
$sql = "SELECT name,address,contact,site,SQRT(POWER((:lat-ST_X(coordinates))*110.574,2) + POWER((:long-ST_Y(coordinates))*111.320*COS(ST_X(coordinates)),2)) AS distance FROM hospitals WHERE SQRT(POWER((:lat-ST_X(coordinates))*110.574,2) + POWER((:long-ST_Y(coordinates))*111.320*COS(ST_X(coordinates)),2)) < 10";
$stmt = $pdo->prepare($sql);
$stmt->execute(array(
":lat" => $_SESSION['lat'],
":long" => $_SESSION['long']
));
$row = $stmt->fetchAll();
foreach ($row as $r) {
?>
<div class="hpt-card flexbox">
<div>
<h2><a href="<?= $r['site'] ?>" class="hptl"><?= $r['name'] ?></a></h2>
<p><?= $r['address'] ?></p>
<p><a href="tel:<?=$r['contact']?>">Contact</a></p>
</div>
</div>
<?php
}
} else {
?>
<div class="head ref flexbox">
<h1>OOPS! Medico is unable to detect your location</h1>
<h2>Allow location access from your browser settings and Refresh the page</h2>
<button class="ref" onclick="location.reload()">Refresh</button>
</div>
<?php
}
?>
</section>
<script src="location.js"></script>
</body>
</html>