Misc-small-projects/blomzt/index.php

107 lines
2.8 KiB
PHP
Raw Normal View History

<?php
2016-05-15 02:39:40 +02:00
$config = parse_ini_file("config.ini");
2016-05-14 23:35:09 +02:00
2016-05-15 02:39:40 +02:00
$conn = mysqli_connect($config["db_host"], $config["db_user"], $config["db_password"], "blomzt");
2016-05-14 23:35:09 +02:00
2016-05-15 01:35:08 +02:00
if (mysqli_connect_errno()) {
die("Connection failed: " . mysqli_connect_error());
2016-05-14 23:35:09 +02:00
}
?>
<html>
<head>
2016-05-14 23:35:09 +02:00
<title>Blomzt</title>
2016-05-15 02:39:40 +02:00
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
<link rel="stylesheet" href="https://code.getmdl.io/1.1.3/material.indigo-pink.min.css">
<link rel="stylesheet" type="text/css" href="/Resources/leaflet/leaflet.css">
2016-05-15 02:39:40 +02:00
<script defer src="https://code.getmdl.io/1.1.3/material.min.js"></script>
<script type="text/javascript" src="/Resources/leaflet/leaflet.js"></script>
2016-08-27 23:16:06 +02:00
<script type="text/javascript" src="/Resources/leaflet-hash/leaflet-hash.js"></script>
2016-05-15 02:39:40 +02:00
</head>
<body>
2016-05-15 02:39:40 +02:00
2016-08-27 17:21:25 +02:00
<div id="mapid" style="height: 100%;"></div>
2016-05-15 02:39:40 +02:00
<script type="text/javascript">
2016-08-27 23:16:06 +02:00
var map = L.map('mapid').setView([51.505, -0.09], 2);
2016-08-27 23:16:06 +02:00
L.tileLayer('https://api.mapbox.com/styles/v1/mapbox/streets-v9/tiles/256/{z}/{x}/{y}?access_token={accessToken}', {
attribution: 'Map data &copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery © <a href="http://mapbox.com">Mapbox</a>',
maxZoom: 18,
2016-08-27 23:16:06 +02:00
accessToken: "pk.eyJ1IjoiZGFsaTk5IiwiYSI6ImNpc2RueWJ0NTAwMW0yenBmaXg5OWhiZXQifQ.WCB3-xcQxEpBf6SHGKG94Q"
}).addTo(map);
var markers = [
<?php
foreach (getList($conn, $config["db_table"]) as $row) {
echo "{
\"type\": \"Feature\",
\"properties\": {
2016-08-27 23:16:06 +02:00
\"popupContent\": \"<b>" . $row["date_added"] . "</b> <br><img style=\\\"max-width:240px\\\" src=\\\"images/" . $row["url"] . "\\\"/>\"
},
\"geometry\": {
\"type\": \"Point\",
\"coordinates\": [" . $row["Longtitude"] . ", " . $row["Latitude"] . "]
}
},";
};
?>
];
var markerlayer = L.geoJson(markers, {
style: function (feature) {
return feature.properties.style;
},
onEachFeature: function (feature, layer) {
layer.bindPopup(feature.properties.popupContent);
}
});
markerlayer.addData(markers);
markerlayer.addTo(map);
2016-08-27 23:16:06 +02:00
var hash = new L.Hash(map);
</script>
2016-08-27 23:16:06 +02:00
<a href="add.php" class="mdl-button mdl-js-button mdl-button--fab mdl-button--colored mdl-button--raised" style="position: absolute; bottom:30px; right: 10px; z-index: 999; background-color: #257eca">
<i class=material-icons>add</i>
</a>
</body>
2016-05-15 01:35:08 +02:00
</html>
<?php
2016-05-15 18:11:22 +02:00
function getList($conn, $table) {
$sql = "SELECT *, X(location) as Longtitude, Y(location) as Latitude FROM `$table`;";
2016-05-15 21:05:14 +02:00
//print_r($sql);
2016-05-15 02:39:40 +02:00
$res = mysqli_query($conn, $sql);
2016-05-15 21:05:14 +02:00
//($res) ? printf("true") : printf("false");
2016-05-15 18:11:22 +02:00
if ($res === false) {
return false;
}
2016-05-15 18:11:22 +02:00
$list = array();
while($row = mysqli_fetch_array($res, MYSQLI_ASSOC)) {
$list[] = $row;
}
return $list;
2016-05-15 02:39:40 +02:00
}
2016-08-27 23:20:54 +02:00
?>