コード例 #1
0
ファイル: list-reports.php プロジェクト: bishabosha/BathHack
<?php

require 'database.php';
require 'haversine.php';
$centreLat = $_POST['lat'];
$centreLon = $_POST['lon'];
$radius = $_POST['radius'];
$reports = [];
$query = $db->query("SELECT ReportID, LocationLatitude, LocationLongitude, Time, ReportCategory, VideoURL, CURRENT_TIMESTAMP() AS CurrentTime FROM Report ORDER BY ReportID DESC LIMIT 15");
foreach ($query as $row) {
    $distance = haversineDistance($centreLat, $centreLon, $row["LocationLatitude"], $row["LocationLongitude"]);
    if ($distance <= $radius) {
        $row['Distance'] = $distance;
        array_push($reports, $row);
    }
}
echo json_encode($reports);
コード例 #2
0
ファイル: submit-report.php プロジェクト: bishabosha/BathHack
<?php

require 'database.php';
require 'haversine.php';
require 'email-send.php';
$radius = 1000;
$query = $db->prepare("INSERT INTO Report (LocationLatitude, LocationLongitude, ReportCategory) VALUES (:latitude, :longitude, :category)");
$query->execute(array(":latitude" => $_POST['lat'], ":longitude" => $_POST['lon'], ":category" => $_POST['category']));
echo $db->lastInsertId();
$query = $db->query("SELECT Email, LocationLatitude, LocationLongitude FROM Subscriber");
foreach ($query as $row) {
    $distance = haversineDistance($_POST['lat'], $row['LocationLatitude'], $_POST['lon'], $row['LocationLongitude']) / 1000000;
    if ($distance <= $radius) {
        email_send($row["Email"], $_POST['category'], $distance);
    }
}