First init as an backup of all the data. for the future use.

This commit is contained in:
2017-07-18 11:33:10 +02:00
commit f0f07b7ae7
9 changed files with 538 additions and 0 deletions

4
.htaccess Normal file
View File

@@ -0,0 +1,4 @@
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?path=$1 [NC,L,QSA]

0
README.md Normal file
View File

BIN
geo.db Normal file

Binary file not shown.

88
index.php Normal file
View File

@@ -0,0 +1,88 @@
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
$path = strtolower(trim(stripslashes(isset($_GET['path']) ? $_GET['path'] : ''), '/'));
list($action, $parameter) = array_pad(explode('/', $path), 2, null);
switch ($action) {
case 'list':
$db = new SQLite3('geo.db');
$results = $db->query('SELECT * FROM location ORDER BY cre_dt DESC');
$rows = [];
while ($row = $results->fetchArray(SQLITE3_ASSOC)) {
$rows[] = $row;
}
include 'templates/list.php';
break;
case 'delete':
$db = new SQLite3('geo.db');
$stmt = $db->prepare('DELETE FROM location WHERE id = :id');
$stmt->bindValue(':id', $parameter, SQLITE3_INTEGER);
$entry = $stmt->execute();
header('Location: /list');
break;
case 'edit':
$db = new SQLite3('geo.db');
$stmt = $db->prepare('SELECT * FROM location WHERE id = :id');
$stmt->bindValue(':id', $parameter, SQLITE3_INTEGER);
$entry = $stmt->execute();
$entry = $entry->fetchArray(SQLITE3_ASSOC);
include 'templates/edit.php';
break;
case 'save':
$db = new SQLite3('geo.db');
//edycja
if (isset($parameter) && !is_null($parameter) && (int)$parameter > 0) {
$stmt = $db->prepare('UPDATE location SET title=:title, description=:description, dl=:dl, szer=:szer, up_dt=:up_dt WHERE id=:id');
$stmt->bindValue(':id', $parameter, SQLITE3_TEXT);
} else { //nowy wpis
$stmt = $db->prepare('INSERT INTO location (title, description, dl, szer, cre_dt, up_dt) VALUES (:title, :description, :dl, :szer, :cre_dt, :up_dt)');
$stmt->bindValue(':cre_dt', date('Y-m-d H:i:s'), SQLITE3_TEXT);
}
$stmt->bindValue(':title', $_POST['title'], SQLITE3_TEXT);
$stmt->bindValue(':description', $_POST['desc'], SQLITE3_TEXT);
$stmt->bindValue(':szer', $_POST['szer'], SQLITE3_TEXT);
$stmt->bindValue(':dl', $_POST['dl'], SQLITE3_TEXT);
$stmt->bindValue(':up_dt', date('Y-m-d H:i:s'), SQLITE3_TEXT);
$entry = $stmt->execute();
var_dump($entry->numColumns());
header('Location: /list');
break;
case 'mapa':
$db = new SQLite3('geo.db');
$results = $db->query('SELECT * FROM location ORDER BY cre_dt DESC');
$rows = [];
while ($row = $results->fetchArray(SQLITE3_ASSOC)) {
$rows[] = $row;
}
include 'templates/mapa.php';
break;
default:
include 'templates/main.php';
break;
}

71
templates/edit.php Normal file
View File

@@ -0,0 +1,71 @@
<!DOCTYPE html>
<html lang="pl">
<head>
<meta charset="UTF-8">
<title>Geo lokalizator</title>
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<?php include_once "style.php"; ?>
<script type="text/javascript">
function showLocation(position) {
var latitude = position.coords.latitude;
var longitude = position.coords.longitude;
document.getElementById('szer').value = latitude;
document.getElementById('dl').value = longitude;
}
function errorHandler(err) {
if (err.code == 1) {
alert("Error: Access is denied!");
}
else if (err.code == 2) {
alert("Error: Position is unavailable!");
}
}
function getLocation() {
if (navigator.geolocation) {
// timeout at 60000 milliseconds (60 seconds)
var options = {timeout: 60000, enableHighAccuracy: true};
navigator.geolocation.getCurrentPosition(showLocation, errorHandler, options);
}
else {
alert("Sorry, browser does not support geolocation!");
}
}
</script>
</head>
<body>
<h1>Edycja wpisu</h1>
<form action="/save/<?= $entry['id']; ?>" method="POST">
<label>Tytuł</label>
<input type="text" name="title" id="title" value="<?= $entry['title']; ?>"/>
<label>Treść </label>
<textarea name="desc" id="desc"><?= $entry['description']; ?></textarea>
<label>Szerokość geo</label>
<input type="text" name="szer" id="szer" value="<?= $entry['szer']; ?>"/>
<label>Długość geo</label>
<input type="text" name="dl" id="dl" value="<?= $entry['dl']; ?>"/>
<input type="button" onclick="getLocation();" value="Get Location"/>
<button type="submit" name="submit">Wyślij</button>
</form>
<a href="/list">List</a>
</body>
</html>

34
templates/list.php Normal file
View File

@@ -0,0 +1,34 @@
<!DOCTYPE html>
<html lang="pl">
<head>
<meta charset="UTF-8">
<title>Geo lokalizator</title>
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<?php include_once "style.php"; ?>
</head>
<body>
<h1>Lista wpisów</h1>
<dl>
<?php foreach ($rows as $row): ?>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<dt><?= $row['id'] . '. ' . $row['title']; ?></dt>
<dd><?= $row['description']; ?></dd>
<dd>Utworzone: <?= $row['cre_dt']; ?> | Zaktualizowane: <?= $row['up_dt']; ?> </dd>
<dd><a href="/edit/<?= $row['id']; ?>">Edycja</a> | <a href="/delete/<?= $row['id']; ?>" class="red">Usuń</a></dd>
</tr>
<?php endforeach; ?>
</dl>
<a href="/">Główna</a>
</body>
</html>

72
templates/main.php Normal file
View File

@@ -0,0 +1,72 @@
<!DOCTYPE html>
<html lang="pl">
<head>
<meta charset="UTF-8">
<title>Geo lokalizator</title>
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<?php include_once "style.php"; ?>
<script type="text/javascript">
function showLocation(position) {
var latitude = position.coords.latitude;
var longitude = position.coords.longitude;
document.getElementById('szer').value = latitude;
document.getElementById('dl').value = longitude;
}
function errorHandler(err) {
if (err.code == 1) {
alert("Error: Access is denied!");
}
else if (err.code == 2) {
alert("Error: Position is unavailable!");
}
}
function getLocation() {
if (navigator.geolocation) {
// timeout at 60000 milliseconds (60 seconds)
var options = {timeout: 60000, enableHighAccuracy: true};
navigator.geolocation.getCurrentPosition(showLocation, errorHandler, options);
}
else {
alert("Sorry, browser does not support geolocation!");
}
}
</script>
</head>
<body>
<h1>Dodaj wpis</h1>
<form action="/save" method="POST" >
<label>Tytuł</label>
<input type="text" name="title" id="title"/>
<label>Treść </label>
<textarea name="desc" id="desc"></textarea>
<label>Szerokość geo</label>
<input type="text" name="szer" id="szer"/>
<label>Długość geo</label>
<input type="text" name="dl" id="dl"/>
<input type="button" onclick="getLocation();" value="Get Location"/>
<button type="submit" name="submit">Wyślij</button>
</form>
<a href="/list">List</a>
</body>
</html>

110
templates/mapa.php Normal file
View File

@@ -0,0 +1,110 @@
<!DOCTYPE html>
<html lang="pl">
<head>
<meta charset="UTF-8">
<title>Geo lokalizator</title>
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<?php include_once "style.php"; ?>
<script>
function initMap() {
map = new google.maps.Map(document.getElementById('map'), {
zoom: 4,
});
var elements = document.getElementsByClassName('showplace');
for (var i = 0; i < elements.length; i++) {
elements[i].addEventListener('click', function () {
var lat = parseFloat(document.getElementsByClassName('showplace')[0].attributes.lat.value);
var lng = parseFloat(document.getElementsByClassName('showplace')[0].attributes.lng.value);
console.info({lat: lat, lng: lng});
map.setCenter({lat: lat, lng: lng});
});
}
var flightPlanCoordinates = [];
var markers = [];//some array
<?php foreach($rows as $row): ?>
var marker = new google.maps.Marker({
position: {lat: <?= $row['szer'] ?>, lng: <?= $row['dl'] ?>},
map: map,
name: <?= $row['id']; ?>
});
marker.info = new google.maps.InfoWindow({
content: <?= '"<h1>' . $row['title'] . '</h1><p>' . $row['description'] . '</p><span>Dodanie: ' . $row['cre_dt'] . '</span><br><span>Aktualizacja: ' . $row['up_dt'] . '</span>"'; ?>,
position: {lat: <?= $row['szer'] ?>, lng: <?= $row['dl'] ?>},
pixelOffset: new google.maps.Size(0, -40)
});
// marker.addListener('click', function () {
// infowindow.open(map, marker);
// });
markers.push(marker);
flightPlanCoordinates.push({lat: <?= $row['szer'] ?>, lng: <?= $row['dl'] ?>});
google.maps.event.addListener(marker, 'click', function (e, w) {
var marker_map = this.getMap();
this.info.open(marker_map);
});
i++;
<?php endforeach; ?>
var flightPath = new google.maps.Polyline({
path: flightPlanCoordinates,
geodesic: true,
strokeColor: '#1e90ff',
strokeOpacity: 1.0,
strokeWeight: 2
});
flightPath.setMap(map);
var bounds = new google.maps.LatLngBounds();
for (var i = 0; i < markers.length; i++) {
bounds.extend(markers[i].getPosition());
}
map.fitBounds(bounds);
}
</script>
<script async defer
src="https://maps.googleapis.com/maps/api/js?key=AIzaSyAEiRrGL_khDb-LRSQyQXwf5B_cuVndrGs&callback=initMap">
</script>
</head>
<body>
<h1>Mapa</h1>
<div class="container">
<div id="map"></div>
<div class="stream">
<?php foreach ($rows as $row): ?>
<div class="location">
<h1><?= $row['title']; ?></h1>
<p><?= $row['description']; ?></p>
<span lat="<?= $row['szer']; ?>" lng="<?= $row['dl']; ?>"
class="showplace">Pokaż miejsce na mapie</span>
<div class="time">
Dodane: <span class="createtime"><?= $row['cre_dt']; ?></span> |
Zaktualizowano: <span class="updatetime"><?= $row['up_dt']; ?></span>
</div>
</div>
<?php endforeach; ?>
</div>
</div>
<a href="/list">List</a>
</body>
</html>

159
templates/style.php Normal file
View File

@@ -0,0 +1,159 @@
<style>
html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed,
figure, figcaption, footer, header, hgroup,
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
margin: 0;
padding: 0;
border: 0;
font-size: 100%;
font: inherit;
vertical-align: baseline;
}
/* HTML5 display-role reset for older browsers */
article, aside, details, figcaption, figure,
footer, header, hgroup, menu, nav, section {
display: block;
}
body {
line-height: 1;
}
ol, ul {
list-style: none;
}
blockquote, q {
quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after {
content: '';
content: none;
}
table {
border-collapse: collapse;
border-spacing: 0;
}
html * {
font-size: 15px;
font-family: sans-serif;
}
form {
display: flex;
flex-direction: column;
}
label {
padding: 5px 10px 0px;
}
input[type="text"], textarea {
padding: 5px;
margin: 5px 10px 10px;
}
a {
padding: 15px 36px;
display: inline-block;
border: 1px solid #ddd;
margin: 10px 20px;
text-decoration: none;
color: dodgerblue;
}
table, td, th {
border: 1px solid #ddd;
padding: 10px;
}
th {
font-weight: bold
}
button, input[type="button"] {
padding: 10px;
}
h1 {
font-size: 20px;
font-weight: bold;
padding: 10px 20px
}
.showplace {
color: dodgerblue;
margin: 15px 0 15px 50px;
display: block;
}
.red {
color: red;
border-color: red;
}
dd a {
padding: 5px;
border: none;
margin: 5px;
}
dl {
padding: 20px;
}
dd {
padding: 2px 30px
}
dt {
border-bottom: 1px solid #ccc;
}
.container {
display: flex;
margin: 20px;
flex-direction: row;
flex-wrap: wrap
}
#map {
width: 50%;
min-width: 320px;
height: 500px
}
.stream {width: 50%; min-width: 320px;}
.location {
border-bottom: 1px solid #D8D8D8;
}
.location p {
margin-left: 40px;
}
.location p:empty, .location h1:empty{
display: block;
visibility: hidden;
}
.location .time {
margin-left: 40px;
margin-bottom: 10px;
}
</style>