Première version de la vue d'un POI

This commit is contained in:
leosw
2026-01-18 17:55:43 +01:00
parent a6c0e06d78
commit 58b180a740
5 changed files with 520 additions and 193 deletions

View File

@@ -1,6 +1,7 @@
<? <?php
require_once($config['models_folder']."d.poi.php"); require_once($config['models_folder']."d.poi.php");
require_once($config['models_folder']."d.comments.php");
require_once($config['models_folder']."d.users.php"); require_once($config['models_folder']."d.users.php");
$head['css'] = "d.index.css;d.poi.css"; $head['css'] = "d.index.css;d.poi.css";
@@ -9,8 +10,8 @@ $poi = new Kabano\Poi();
switch ($controller->splitted_url[1]) { switch ($controller->splitted_url[1]) {
case "new": case "new":
if($user->rankIsHigher("registered")) { if ($user->rankIsHigher("registered")) {
if(isset($_POST['submit'])) { if (isset($_POST['submit'])) {
$poi->name = $_POST['name']; $poi->name = $_POST['name'];
$poi->locale = $_POST['locale']; $poi->locale = $_POST['locale'];
$poi->poi_type = $_POST['poi_type']; $poi->poi_type = $_POST['poi_type'];
@@ -19,19 +20,18 @@ switch ($controller->splitted_url[1]) {
$poi->ele = $_POST['ele']; $poi->ele = $_POST['ele'];
$poi->author = $user->id; $poi->author = $user->id;
$poi->source = "kab"; $poi->source = "kab";
$poi->is_commentable = isset($_POST['is_commentable'])?'t':'f'; $poi->is_commentable = isset($_POST['is_commentable']) ? 't' : 'f';
$poi->parameters = new \stdClass(); $poi->parameters = new \stdClass(); // tu pourras y mettre ton JSON plus tard
if(!$poi->checkPermalink($_POST['permalink'],1)) {
if (!$poi->checkPermalink($_POST['permalink'], 1)) {
$poi->permalink = $_POST['permalink']; $poi->permalink = $_POST['permalink'];
$poi->insert(); $poi->insert();
header('Location: '.$config['rel_root_folder']."poi/".$poi->permalink); header('Location: '.$config['rel_root_folder']."poi/".$poi->permalink);
} } else {
else {
$head['title'] = $poi->name; $head['title'] = $poi->name;
$error = "permalink"; $error = "permalink";
} }
} } else {
else {
$head['title'] = "Nouvel hébergement"; $head['title'] = "Nouvel hébergement";
} }
@@ -42,123 +42,143 @@ switch ($controller->splitted_url[1]) {
$head['css'] .= ";../third/leaflet/leaflet.css;../third/leaflet-fullscreen/leaflet.fullscreen.css;../third/leaflet-easybutton/easy-button.css"; $head['css'] .= ";../third/leaflet/leaflet.css;../third/leaflet-fullscreen/leaflet.fullscreen.css;../third/leaflet-easybutton/easy-button.css";
$head['js'] = "d.poi_map.js"; $head['js'] = "d.poi_map.js";
$poi->lat = ""; $poi->lon = ""; $poi->ele = ""; $poi->lat = "";
$poi->lon = "";
$poi->ele = "";
$new = 1; $new = 1;
include ($config['views_folder']."d.poi.edit.html"); include ($config['views_folder']."d.poi.edit.html");
break; break;
} else {
$notfound = 1;
} }
else { break;
$notfound = 1;
}
case "elevation_proxy": case "elevation_proxy":
if(isset($_GET['location'])) { if (isset($_GET['location'])) {
header("Content-Type: application/json;charset=utf-8"); header("Content-Type: application/json;charset=utf-8");
echo(file_get_contents("https://api.opentopodata.org/v1/mapzen?locations=".$_GET['location'])); echo(file_get_contents("https://api.opentopodata.org/v1/mapzen?locations=".$_GET['location']));
break; break;
} else {
$notfound = 1;
} }
else { break;
$notfound = 1;
}
default: default:
// If the page exists // Affichage / édition / suppression dun POI
if ($poi->checkPermalink($controller->splitted_url[1],$user->rankIsHigher("premium"))) { if ($poi->checkPermalink($controller->splitted_url[1], $user->rankIsHigher("premium"))) {
// if (isset($controller->splitted_url[2]) && $controller->splitted_url[2] == "delete" && $user->rankIsHigher("moderator")) {
// $poi->delete();
// header('Location: '.$config['rel_root_folder']."blog/".$poi->permalink);
// }
// else if (isset($controller->splitted_url[2]) && $controller->splitted_url[2] == "restore" && $user->rankIsHigher("moderator")) {
// $poi->restore();
// header('Location: '.$config['rel_root_folder']."blog/".$poi->permalink);
// }
// else if (isset($controller->splitted_url[2]) && $controller->splitted_url[2] == "edit" && $user->rankIsHigher("moderator")) {
// if(isset($_POST['submit'])) {
// $poi->content = $_POST['content'];
// $poi->locale = $_POST['locale'];
// $poi->name = $_POST['name'];
// $poi->is_commentable = $_POST['is_commentable'];
// $poi->author = $user->id;
// $poi->update();
// header('Location: '.$config['rel_root_folder']."blog/".$poi->permalink);
// }
// else {
// $locales = new Kabano\Locales();
// $locales->getAll();
// $head['title'] = $poi->name; // Suppression
// include ($config['views_folder']."d.blog.edit.html"); if (isset($controller->splitted_url[2]) && $controller->splitted_url[2] == "delete" && $user->rankIsHigher("moderator")) {
// } $poi->delete();
// } header('Location: '.$config['rel_root_folder']."poi/".$poi->permalink);
// else { }
// Manage history of an article
if($user->rankIsHigher("premium")) { // Restauration
$blogHistory = new Kabano\pois(); else if (isset($controller->splitted_url[2]) && $controller->splitted_url[2] == "restore" && $user->rankIsHigher("moderator")) {
$blogHistory->getHistory($controller->splitted_url[1]); $poi->restore();
header('Location: '.$config['rel_root_folder']."poi/".$poi->permalink);
}
// Édition
else if (isset($controller->splitted_url[2]) && $controller->splitted_url[2] == "edit" && $user->rankIsHigher("moderator")) {
if (isset($_POST['submit'])) {
$poi->name = $_POST['name'];
$poi->locale = $_POST['locale'];
$poi->poi_type = $_POST['poi_type'];
$poi->lat = $_POST['lat'];
$poi->lon = $_POST['lon'];
$poi->ele = $_POST['ele'];
$poi->is_commentable = isset($_POST['is_commentable']) ? 't' : 'f';
$poi->author = $user->id;
// $poi->parameters = ... // à remplir si tu veux éditer les champs dynamiques
$poi->update();
header('Location: '.$config['rel_root_folder']."poi/".$poi->permalink);
} else {
$locales = new Kabano\Locales();
$locales->getAll();
$head['third'] = "leaflet/leaflet.js;leaflet-fullscreen/Leaflet.fullscreen.min.js;leaflet-easybutton/easy-button.js";
$head['css'] .= ";../third/leaflet/leaflet.css;../third/leaflet-fullscreen/leaflet.fullscreen.css;../third/leaflet-easybutton/easy-button.css";
$head['js'] = "d.poi_map.js";
$head['title'] = $poi->name;
include ($config['views_folder']."d.poi.edit.html");
} }
if (isset($controller->splitted_url[2]) && is_numeric($controller->splitted_url[2])) }
$poi->checkPermalink($controller->splitted_url[1],$user->rankIsHigher("premium"),$controller->splitted_url[2]);
// Manage comment creation // Affichage
if (isset($controller->splitted_url[2]) && $controller->splitted_url[2]=="new_comment") { else {
// Historique
if ($user->rankIsHigher("premium")) {
$Pois = new Kabano\Pois();
$Pois->getHistory($controller->splitted_url[1]);
}
if (isset($controller->splitted_url[2]) && is_numeric($controller->splitted_url[2])) {
$poi->checkPermalink($controller->splitted_url[1], $user->rankIsHigher("premium"), $controller->splitted_url[2]);
}
// Création dun commentaire
if (isset($controller->splitted_url[2]) && $controller->splitted_url[2] == "new_comment") {
if (isset($_POST['submit']) && $user->rankIsHigher("registered")) { if (isset($_POST['submit']) && $user->rankIsHigher("registered")) {
$blogComment = new Kabano\BlogComment(); $Comment = new Kabano\Comment();
$blogComment->locale = $user->locale; $Comment->locale = $user->locale;
$blogComment->author = $user->id; $Comment->author = $user->id;
$blogComment->content = $poi->content_id; $Comment->content = $poi->content_id;
$blogComment->comment = $_POST['comment']; $Comment->comment = $_POST['comment'];
$blogComment->insert(); $Comment->insert();
} }
} }
// Manage comment deletion // Suppression dun commentaire
if (isset($controller->splitted_url[2]) && $controller->splitted_url[2]=="delete_comment") { if (isset($controller->splitted_url[2]) && $controller->splitted_url[2] == "delete_comment") {
if (isset($controller->splitted_url[3]) && is_numeric($controller->splitted_url[3])) { if (isset($controller->splitted_url[3]) && is_numeric($controller->splitted_url[3])) {
$blogComment = new Kabano\BlogComment(); $Comment = new Kabano\Comment();
if($blogComment->checkId($controller->splitted_url[3])) if ($Comment->checkId($controller->splitted_url[3]))
if ($user->rankIsHigher("moderator") || $user->id == $blogComment->author) if ($user->rankIsHigher("moderator") || $user->id == $Comment->author)
$blogComment->delete(); $Comment->delete();
} }
} }
// Manage comment restoration // Restauration dun commentaire
if (isset($controller->splitted_url[2]) && $controller->splitted_url[2]=="restore_comment") { if (isset($controller->splitted_url[2]) && $controller->splitted_url[2] == "restore_comment") {
if (isset($controller->splitted_url[3]) && is_numeric($controller->splitted_url[3])) { if (isset($controller->splitted_url[3]) && is_numeric($controller->splitted_url[3])) {
$blogComment = new Kabano\BlogComment(); $Comment = new Kabano\Comment();
if($blogComment->checkId($controller->splitted_url[3])) if ($Comment->checkId($controller->splitted_url[3]))
if ($user->rankIsHigher("moderator") || $user->id == $blogComment->author) if ($user->rankIsHigher("moderator") || $user->id == $Comment->author)
$blogComment->restore(); $Comment->restore();
} }
} }
$poi->md2html(); // Commentaires
// Manage comments
if ($poi->is_commentable == "t") { if ($poi->is_commentable == "t") {
$pois_comments = new Kabano\BlogComments(); $poi_comments = new Kabano\Comments();
$pois_comments->listComments($poi->content_id, ($user->rankIsHigher("premium"))); $poi_comments->listComments($poi->content_id, ($user->rankIsHigher("premium")));
$i = 0; foreach ($poi_comments->objs as $comment) {
foreach ($pois_comments->objs as $comment) {
$comment->md2html(); $comment->md2html();
$comment->author_obj = new Kabano\User(); $comment->author_obj = new Kabano\User();
$comment->author_obj->checkId($comment->author); $comment->author_obj->checkId($comment->author);
} }
} }
// Auteur
$tempUser = new Kabano\User(); $tempUser = new Kabano\User();
$tempUser->checkId($poi->author); $tempUser->checkId($poi->author);
$poi->author_name = $tempUser->name; $poi->author_name = $tempUser->name;
unset($tempUser); unset($tempUser);
$head['third'] = "leaflet/leaflet.js;leaflet-fullscreen/Leaflet.fullscreen.min.js;leaflet-easybutton/easy-button.js";
$head['css'] .= ";../third/leaflet/leaflet.css;../third/leaflet-fullscreen/leaflet.fullscreen.css;../third/leaflet-easybutton/easy-button.css";
$head['js'] = "d.poi_map.js";
$head['title'] = $poi->name; $head['title'] = $poi->name;
include ($config['views_folder']."d.blog.view.html"); include ($config['views_folder']."d.poi.view.html");
// } }
} } else {
else { $notfound = 1;
$notfound = 1;
} }
break; break;
} }
?> ?>

View File

@@ -38,37 +38,79 @@ class Poi
public $lat; public $lat;
public $lon; public $lon;
public $ele; public $ele;
public $author_name;
/***** /*****
** Checks if a page at this URL exists and return the ID ** Checks if a page at this URL exists and return the ID
*****/ *****/
public function checkPermalink($permalink, $withArchive=0, $elementNb=0) { public function checkPermalink($permalink, $withArchive=0, $elementNb=0) {
global $config; global $config;
$con = pg_connect("host=".$config['SQL_host']." dbname=".$config['SQL_db']." user=".$config['SQL_user']." password=".$config['SQL_pass']) $con = pg_connect("host=".$config['SQL_host']." dbname=".$config['SQL_db']." user=".$config['SQL_user']." password=".$config['SQL_pass'])
or die ("Could not connect to server\n"); or die ("Could not connect to server\n");
$query = "SELECT content_versions.id AS version_id, * FROM contents INNER JOIN content_locales ON contents.id = content_locales.content_id INNER JOIN content_versions ON content_locales.id = content_versions.locale_id WHERE permalink=$1 AND type='poi'"; $query = "SELECT
if($withArchive==0) { content_versions.id AS version_id,
$query .= " AND is_archive=FALSE AND is_public=TRUE"; content_versions.version,
} content_versions.update_date,
$query .= " ORDER BY update_date DESC LIMIT 1 OFFSET $2"; content_versions.is_archive,
content_versions.name,
content_versions.content AS parameters,
pg_prepare($con, "prepare1", $query) contents.id AS content_id,
or die ("Cannot prepare statement\n"); contents.permalink,
$result = pg_execute($con, "prepare1", array($permalink, $elementNb)) contents.creation_date,
or die ("Cannot execute statement\n"); contents.is_public,
contents.is_commentable,
contents.type,
contents.poi_type,
pg_close($con); content_locales.id AS locale_id,
content_locales.locale,
content_locales.author,
if(pg_num_rows($result) == 1) { specs.source_id,
$row = pg_fetch_assoc($result); specs.remote_source_id,
$this->populate($row); ST_X(specs.geom) AS lon,
return 1; ST_Y(specs.geom) AS lat,
} ST_Z(specs.geom) AS ele,
else {
return 0; sources.display_name AS source
}
FROM contents
INNER JOIN content_locales
ON contents.id = content_locales.content_id
INNER JOIN content_versions
ON content_locales.id = content_versions.locale_id
LEFT JOIN content_version_poi_specifications specs
ON specs.content_version_id = content_versions.id
LEFT JOIN sources
ON sources.id = specs.source_id
WHERE contents.permalink = $1
AND contents.type = 'poi'";
if ($withArchive == 0) {
$query .= " AND content_versions.is_archive = FALSE AND contents.is_public = TRUE";
}
$query .= " ORDER BY content_versions.update_date DESC LIMIT 1 OFFSET $2";
pg_prepare($con, "poi_check_permalink", $query)
or die ("Cannot prepare statement\n");
$result = pg_execute($con, "poi_check_permalink", [$permalink, $elementNb])
or die ("Cannot execute statement\n");
pg_close($con);
if (pg_num_rows($result) == 1) {
$row = pg_fetch_assoc($result);
$this->populate($row);
return 1;
}
return 0;
} }
/***** /*****
@@ -147,7 +189,7 @@ class Poi
pg_prepare($con, "prepare4", $query) pg_prepare($con, "prepare4", $query)
or die ("Cannot prepare statement\n"); or die ("Cannot prepare statement\n");
$result = pg_execute($con, "prepare4", array($this->version_id, $this->lon, $this->lat, $this->ele ,$this->source, $this->remote_source_id)) $result = pg_execute($con, "prepare4", array($this->version_id, $this->lon, $this->lat, $this->ele ,$this->source_id, $this->remote_source_id))
or die ("Cannot execute statement\n"); or die ("Cannot execute statement\n");
$query = "INSERT INTO content_contributors (content, contributor) VALUES $query = "INSERT INTO content_contributors (content, contributor) VALUES
@@ -201,7 +243,7 @@ class Poi
$this->version_id = pg_fetch_assoc($result)['id']; $this->version_id = pg_fetch_assoc($result)['id'];
// 3) Insert new geometry + source info for this new version // 3) Insert new geometry + source info for this new version
$query = "INSERT INTO content_version_poi_specifications,(content_version_id, geom, source_id, remote_source_id) VALUES $query = "INSERT INTO content_version_poi_specifications (content_version_id, geom, source_id, remote_source_id) VALUES
($1, ST_SetSRID(ST_MakePoint($2, $3, $4), 4326), $5, $6)"; ($1, ST_SetSRID(ST_MakePoint($2, $3, $4), 4326), $5, $6)";
pg_prepare($con, "poi_insert_specs_update", $query); pg_prepare($con, "poi_insert_specs_update", $query);
@@ -289,18 +331,51 @@ class Pois
$con = pg_connect("host=".$config['SQL_host']." dbname=".$config['SQL_db']." user=".$config['SQL_user']." password=".$config['SQL_pass']) $con = pg_connect("host=".$config['SQL_host']." dbname=".$config['SQL_db']." user=".$config['SQL_user']." password=".$config['SQL_pass'])
or die ("Could not connect to server\n"); or die ("Could not connect to server\n");
$query = " $query = "SELECT
SELECT content_versions.id AS version_id, * content_versions.id AS version_id,
FROM contents content_versions.version,
INNER JOIN content_locales ON contents.id = content_locales.content_id content_versions.update_date,
INNER JOIN content_versions ON content_locales.id = content_versions.locale_id content_versions.is_archive,
WHERE type='poi' AND is_archive=FALSE content_versions.name,
"; content_versions.content AS parameters,
contents.id AS content_id,
contents.permalink,
contents.creation_date,
contents.is_public,
contents.is_commentable,
contents.type,
contents.poi_type,
content_locales.id AS locale_id,
content_locales.locale,
content_locales.author,
specs.source_id,
specs.remote_source_id,
ST_X(specs.geom) AS lon,
ST_Y(specs.geom) AS lat,
ST_Z(specs.geom) AS ele,
sources.display_name AS source
FROM contents
INNER JOIN content_locales
ON contents.id = content_locales.content_id
INNER JOIN content_versions
ON content_locales.id = content_versions.locale_id
LEFT JOIN content_version_poi_specifications specs
ON specs.content_version_id = content_versions.id
LEFT JOIN sources
ON sources.id = specs.source_id
WHERE contents.type = 'poi'
AND content_versions.is_archive = FALSE";
if ($archive != 1) if ($archive != 1)
$query .= " AND is_public=TRUE "; $query .= " AND contents.is_public=TRUE ";
$query .= " ORDER BY update_date DESC LIMIT $1 OFFSET $2"; $query .= " ORDER BY content_versions.update_date DESC LIMIT $1 OFFSET $2";
pg_prepare($con, "pois_list", $query); pg_prepare($con, "pois_list", $query);
$result = pg_execute($con, "pois_list", array($count, $first)); $result = pg_execute($con, "pois_list", array($count, $first));
@@ -320,13 +395,48 @@ class Pois
$con = pg_connect("host=".$config['SQL_host']." dbname=".$config['SQL_db']." user=".$config['SQL_user']." password=".$config['SQL_pass']) $con = pg_connect("host=".$config['SQL_host']." dbname=".$config['SQL_db']." user=".$config['SQL_user']." password=".$config['SQL_pass'])
or die ("Could not connect to server\n"); or die ("Could not connect to server\n");
$query = " $query = "SELECT
SELECT content_versions.id AS version_id, * content_versions.id AS version_id,
FROM contents content_versions.version,
INNER JOIN content_locales ON contents.id = content_locales.content_id content_versions.update_date,
INNER JOIN content_versions ON content_locales.id = content_versions.locale_id content_versions.is_archive,
WHERE permalink=$1 AND type='poi' content_versions.name,
ORDER BY update_date DESC content_versions.content AS parameters,
contents.id AS content_id,
contents.permalink,
contents.creation_date,
contents.is_public,
contents.is_commentable,
contents.type,
contents.poi_type,
content_locales.id AS locale_id,
content_locales.locale,
content_locales.author,
specs.source_id,
specs.remote_source_id,
ST_X(specs.geom) AS lon,
ST_Y(specs.geom) AS lat,
ST_Z(specs.geom) AS ele,
sources.display_name AS source
FROM contents
INNER JOIN content_locales
ON contents.id = content_locales.content_id
INNER JOIN content_versions
ON content_locales.id = content_versions.locale_id
LEFT JOIN content_version_poi_specifications specs
ON specs.content_version_id = content_versions.id
LEFT JOIN sources
ON sources.id = specs.source_id
WHERE contents.permalink = $1
AND contents.type = 'poi'
ORDER BY content_versions.update_date DESC
"; ";
pg_prepare($con, "poi_history", $query); pg_prepare($con, "poi_history", $query);

View File

@@ -158,6 +158,14 @@ $( "#name" ).change(function() {
</form> </form>
</section> </section>
<script>
var poi_lat = <?=$poi->lat?>;
var poi_lon = <?=$poi->lon?>;
var poi_type = null;
var poi_mode = "edit";
</script>
<script type="text/javascript"> <script type="text/javascript">
$( "#slide-icon" ).click(function() { $( "#slide-icon" ).click(function() {
$( "html, body" ).animate({scrollTop: "300px"}); $( "html, body" ).animate({scrollTop: "300px"});

139
views/d.poi.view.html Normal file
View File

@@ -0,0 +1,139 @@
<!DOCTYPE html>
<html lang="fr">
<? include('blocks/d.head.html'); ?>
<body>
<? include('blocks/d.nav.html'); ?>
<div id="mapid"></div>
<div id="sticky">
<section>
<i id="slide-icon" class="fas fa-chevron-up"></i>
<h1 class="flex_line">
<span><?=$poi->name?></span>
<span class="poi-type"><?=$poi->poi_type?></span>
</h1>
<div class="flex_line">
<div>
<strong>Latitude :</strong> <?=$poi->lat?><br>
<strong>Longitude :</strong> <?=$poi->lon?><br>
<? if ($poi->ele !== null && $poi->ele !== '') { ?>
<strong>Altitude :</strong> <?=$poi->ele?> m<br>
<? } ?>
</div>
<div>
<strong>Langue :</strong> <?=$poi->locale?><br>
<strong>Auteur :</strong> <?=$poi->author_name?><br>
<strong>Dernière mise à jour :</strong> <?=$poi->update_date?><br>
</div>
</div>
<? if ($user->rankIsHigher("moderator")) { ?>
<div class="flex_line admin_actions">
<a class="button" href="<?=$config['rel_root_folder']?>poi/<?=$poi->permalink?>/edit">Modifier</a>
<? if ($poi->is_public == 't') { ?>
<a class="button danger" href="<?=$config['rel_root_folder']?>poi/<?=$poi->permalink?>/delete">Supprimer</a>
<? } else { ?>
<a class="button success" href="<?=$config['rel_root_folder']?>poi/<?=$poi->permalink?>/restore">Restaurer</a>
<? } ?>
</div>
<? } ?>
<hr>
<h2>Description</h2>
<div class="poi-description">
<?=$poi->content_html?>
</div>
<hr>
<h2 id="abstract_title">Informations générales</h2>
<p id="abstract">
<?=$poi_types[$poi->poi_type][4] ?? ""?>
</p>
<h2>Caractéristiques</h2>
<div id="specific_form">
<? if (!empty($poi->parameters)) { ?>
<? foreach ($poi->parameters as $key => $value) { ?>
<div class="flex_line poi_param">
<label><strong><?=$key?></strong></label>
<span><?=$value?></span>
</div>
<? } ?>
<? } else { ?>
<p>Aucune information spécifique.</p>
<? } ?>
</div>
<hr>
<? if ($poi->is_commentable == 't') { ?>
<h2>Commentaires</h2>
<? if (isset($poi_comments) && $poi_comments->number > 0) { ?>
<div id="comments">
<? foreach ($poi_comments->objs as $comment) { ?>
<article class="comment">
<header>
<strong><?=$comment->author_obj->name?></strong>
<span><?=$comment->creation_date?></span>
<? if ($user->rankIsHigher("moderator") || $user->id == $comment->author) { ?>
<? if ($comment->is_public == 't') { ?>
<a href="<?=$config['rel_root_folder']?>poi/<?=$poi->permalink?>/delete_comment/<?=$comment->id?>">Supprimer</a>
<? } else { ?>
<a href="<?=$config['rel_root_folder']?>poi/<?=$poi->permalink?>/restore_comment/<?=$comment->id?>">Restaurer</a>
<? } ?>
<? } ?>
</header>
<div class="comment-body">
<?=$comment->comment_html?>
</div>
</article>
<? } ?>
</div>
<? } else { ?>
<p>Aucun commentaire pour le moment.</p>
<? } ?>
<? if ($user->rankIsHigher("registered")) { ?>
<form class="form" action="<?=$config['rel_root_folder']?>poi/<?=$poi->permalink?>/new_comment" method="post">
<h3>Ajouter un commentaire</h3>
<textarea name="comment" id="comment" required></textarea>
<input type="submit" name="submit" value="Envoyer">
</form>
<? } else { ?>
<p>Connectez-vous pour ajouter un commentaire.</p>
<? } ?>
<? } ?>
</section>
<? include('blocks/d.footer.html'); ?>
</div>
<script>
var poi_lat = <?=$poi->lat?>;
var poi_lon = <?=$poi->lon?>;
var poi_type = "<?=$poi->poi_type?>";
var poi_mode = "view";
var root = "<?=$config['rel_root_folder']?>";
</script>
<script type="text/javascript">
$( "#slide-icon" ).click(function() {
$( "html, body" ).animate({scrollTop: "300px"});
});
</script>
</body>
</html>

View File

@@ -1,82 +1,132 @@
var mymap; var mymap;
var poi_layer; var poi_layer;
$( document ).ready(function() { $(document).ready(function() {
// Differents layers for the map // Mode : edit (formulaire) ou view (affichage)
var topo_maptiler = L.tileLayer('https://api.maptiler.com/maps/topographique/{z}/{x}/{y}.png?key=Sm8M7mJ53GtYdl773rpi', {tms: false, attribution: 'Carte © <a href="https://www.maptiler.com/copyright/" target="_blank">MapTiler</a>, Données © <a href="http://www.openstreetmap.org/copyright" target="_blank">Contributeurs OpenStreetMap</a>', tileSize: 512, zoomOffset: -1, minZoom: 1}); var isEdit = (typeof poi_mode === "undefined" || poi_mode === "edit");
var ign = L.tileLayer('https://data.geopf.fr/private/wmts?&REQUEST=GetTile&SERVICE=WMTS&VERSION=1.0.0&STYLE=normal&TILEMATRIXSET=PM&FORMAT=image/jpeg&LAYER=GEOGRAPHICALGRIDSYSTEMS.MAPS&TILEMATRIX={z}&TILEROW={y}&TILECOL={x}&apikey=ign_scan_ws', {attribution: 'Carte & Connées © <a href="http://ign.fr/" target="_blank">IGN-F/Géoportail</a>'});
// Base layers
var baseLayers = {
"OpenStreetMap": topo_maptiler,
"IGN France": ign
};
mymap = L.map('mapid', { // Differents layers for the map
zoomControl: false, var topo_maptiler = L.tileLayer(
layers: [topo_maptiler] 'https://api.maptiler.com/maps/topographique/{z}/{x}/{y}.png?key=Sm8M7mJ53GtYdl773rpi',
}).setView([47, 3], 6); {
$("#map-credits").html(topo_maptiler.getAttribution()); tms: false,
attribution: 'Carte © <a href="https://www.maptiler.com/copyright/" target="_blank">MapTiler</a>, Données © <a href="http://www.openstreetmap.org/copyright" target="_blank">Contributeurs OpenStreetMap</a>',
tileSize: 512,
zoomOffset: -1,
minZoom: 1
}
);
var ign = L.tileLayer(
'https://data.geopf.fr/private/wmts?&REQUEST=GetTile&SERVICE=WMTS&VERSION=1.0.0&STYLE=normal&TILEMATRIXSET=PM&FORMAT=image/jpeg&LAYER=GEOGRAPHICALGRIDSYSTEMS.MAPS&TILEMATRIX={z}&TILEROW={y}&TILECOL={x}&apikey=ign_scan_ws',
{
attribution: 'Carte & Connées © <a href="http://ign.fr/" target="_blank">IGN-F/Géoportail</a>'
}
);
// Base layers
var baseLayers = {
"OpenStreetMap": topo_maptiler,
"IGN France": ign
};
L.control.scale({ mymap = L.map('mapid', {
position: "bottomleft", zoomControl: false,
imperial: false layers: [topo_maptiler]
}).addTo(mymap); }).setView([47, 3], 6);
$("#map-credits").html(topo_maptiler.getAttribution());
L.control.fullscreen({ L.control.scale({
position: "bottomleft" position: "bottomleft",
}).addTo(mymap); imperial: false
}).addTo(mymap);
L.control.zoom({ L.control.fullscreen({
zoomOutText: "<i class=\"fa fa-minus\" aria-hidden=\"true\"></i>", position: "bottomleft"
zoomInText: "<i class=\"fa fa-plus\" aria-hidden=\"true\"></i>", }).addTo(mymap);
position: "bottomleft"
}).addTo(mymap);
L.control.layers(baseLayers,null,{ L.control.zoom({
position: "bottomright" zoomOutText: "<i class=\"fa fa-minus\" aria-hidden=\"true\"></i>",
}).addTo(mymap); zoomInText: "<i class=\"fa fa-plus\" aria-hidden=\"true\"></i>",
position: "bottomleft"
}).addTo(mymap);
mymap.removeControl(mymap.attributionControl); L.control.layers(baseLayers, null, {
position: "bottomright"
}).addTo(mymap);
mymap.on('baselayerchange', function(e) { mymap.removeControl(mymap.attributionControl);
$("#map-credits").html(e.layer.getAttribution());
});
poi_layer = L.marker([47, 3], {draggable: true}).addTo(mymap); mymap.on('baselayerchange', function(e) {
poi_layer.bindTooltip("Glissez moi au bon endroit.", {permanent: true, direction: 'auto'}).openTooltip(); $("#map-credits").html(e.layer.getAttribution());
});
mymap.on('click', function(e){ // Position initiale : soit celle du POI, soit le centre par défaut
poi_layer.setLatLng(e.latlng); var startLat = (typeof poi_lat !== "undefined" && poi_lat) ? poi_lat : 47;
}) var startLon = (typeof poi_lon !== "undefined" && poi_lon) ? poi_lon : 3;
poi_layer.on('move', function(e){
poi_layer.unbindTooltip();
$("#lat").val(+e.latlng.lat.toFixed(6));
$("#lon").val(+e.latlng.lng.toFixed(6));
$("#elevation_icon").show();
})
$("#lat,#lon").change(function() { // If the user changes the lat/lon input values manualy
if(isNaN($("#lat").val()) || isNaN($("#lon").val()) || $("#lat").val().length==0 || $("#lon").val()==null)
$("#elevation_icon").hide();
else {
$("#elevation_icon").show();
poi_layer.setLatLng([$("#lat").val(),$("#lon").val()]);
}
});
var poiicon = L.icon({ // Icône : si poi_type défini, on lutilise, sinon icône Leaflet par défaut
iconSize: [24, 24], var poiicon = null;
iconAnchor: [12, 12] if (typeof poi_type !== "undefined" && poi_type) {
}); poiicon = L.icon({
$("#type_selector label").click(function(e) { iconSize: [24, 24],
poi_layer.unbindTooltip(); iconAnchor: [12, 12],
poiicon.options.iconUrl = e.currentTarget.firstChild.currentSrc; iconUrl: root + "views/img/" + poi_type + ".svg"
poi_layer.setIcon(poiicon); });
}) }
$("#elevation_icon").click(function(e) {
$(this).find($(".fas")).removeClass('fa-search-location').addClass('fa-spinner').addClass('fa-spin'); if (poiicon) {
$.get("./elevation_proxy", {location:$("#lat").val()+","+$("#lon").val()}, function(result){ poi_layer = L.marker([startLat, startLon], {draggable: isEdit, icon: poiicon}).addTo(mymap);
$("#ele").val(result.results[0].elevation); } else {
$("#elevation_icon").find($(".fas")).removeClass('fa-spinner').removeClass('fa-spin').addClass('fa-search-location'); poi_layer = L.marker([startLat, startLon], {draggable: isEdit}).addTo(mymap);
}); }
})
}); if (isEdit) {
poi_layer.bindTooltip("Glissez moi au bon endroit.", {permanent: true, direction: 'auto'}).openTooltip();
}
// Interactions uniquement en mode édition
if (isEdit) {
mymap.on('click', function(e){
poi_layer.setLatLng(e.latlng);
});
poi_layer.on('move', function(e){
poi_layer.unbindTooltip();
$("#lat").val(+e.latlng.lat.toFixed(6));
$("#lon").val(+e.latlng.lng.toFixed(6));
$("#elevation_icon").show();
});
$("#lat,#lon").change(function() { // If the user changes the lat/lon input values manualy
if(isNaN($("#lat").val()) || isNaN($("#lon").val()) || $("#lat").val().length==0 || $("#lon").val()==null)
$("#elevation_icon").hide();
else {
$("#elevation_icon").show();
poi_layer.setLatLng([$("#lat").val(),$("#lon").val()]);
}
});
var editPoiIcon = L.icon({
iconSize: [24, 24],
iconAnchor: [12, 12]
});
$("#type_selector label").click(function(e) {
poi_layer.unbindTooltip();
editPoiIcon.options.iconUrl = e.currentTarget.firstChild.currentSrc;
poi_layer.setIcon(editPoiIcon);
});
$("#elevation_icon").click(function(e) {
$(this).find($(".fas")).removeClass('fa-search-location').addClass('fa-spinner').addClass('fa-spin');
$.get("./elevation_proxy", {location:$("#lat").val()+","+$("#lon").val()}, function(result){
$("#ele").val(result.results[0].elevation);
$("#elevation_icon").find($(".fas")).removeClass('fa-spinner').removeClass('fa-spin').addClass('fa-search-location');
});
});
} else {
// Mode affichage : centrer sur le POI si coordonnées présentes
if (typeof poi_lat !== "undefined" && typeof poi_lon !== "undefined") {
mymap.setView([poi_lat, poi_lon], 14);
}
}
});