Seznam prochazek a editace detailu.
This commit is contained in:
parent
d9fa9dcb42
commit
8dfe927deb
121
app.php
121
app.php
|
@ -212,6 +212,127 @@ route('', '/sklad/smazat/{id}/', function ($req, $params){
|
|||
return redirect('/sklad/');
|
||||
});
|
||||
|
||||
// procházky
|
||||
|
||||
$singletons['event_form'] = function () {
|
||||
$form = new severak\forms\form(['method'=>'post']);
|
||||
$form->field('name', ['label'=>'Název', 'required'=>true]);
|
||||
$form->field('subtitle', ['label'=>'Upoutávka', 'type'=>'textarea']);
|
||||
$form->field('text', ['label'=>'Popis', 'type'=>'textarea']);
|
||||
$form->field('date', ['label'=>'Datum', 'type'=>'date', 'required'=>true]);
|
||||
$form->field('time', ['label'=>'Čas', 'type'=>'time', 'required'=>true]);
|
||||
$form->field('facebook_url', ['label'=>'URL události na FB']);
|
||||
$form->field('is_future', ['label'=>'Pozvánka?', 'type'=>'checkbox']);
|
||||
$form->field('stop_ids', ['label'=>'ID zastávek']);
|
||||
$form->field('place_description', ['label'=>'Místo srazu']);
|
||||
$form->field('lon', ['type'=>'hidden']);
|
||||
$form->field('lat', ['type'=>'hidden']);
|
||||
$form->field('_sbt', ['label'=>'Uložit?', 'type'=>'submit']);
|
||||
|
||||
$form->rule('lon', function ($v, $o) {
|
||||
return !empty($o['lon']) && !empty($o['lat']);
|
||||
}, 'Musí být vyplněny souřadnice');
|
||||
|
||||
return $form;
|
||||
};
|
||||
|
||||
|
||||
route('GET', '/event/edit/', function ($req){
|
||||
if (!user()) return redirect('/login/');
|
||||
/** @var severak\database\rows $rows */
|
||||
$rows = di('rows');
|
||||
$page = $_GET['page'] ?? 1;
|
||||
$pois = $rows->page('events', [], ['datetime'=>'asc'], $page, 30);
|
||||
$pages = $rows->pages;
|
||||
|
||||
return render('event_list', ['pois'=>$pois, 'pages'=>$pages, 'page'=>$page]);
|
||||
});
|
||||
|
||||
|
||||
route('', '/event/add/', function ($req){
|
||||
if (!user()) return redirect('/login/');
|
||||
/** @var Psr\Http\Message\ServerRequestInterface $req */
|
||||
/** @var severak\database\rows $rows */
|
||||
$rows = di('rows');
|
||||
/** @var severak\forms\form $form */
|
||||
$form = di('event_form');
|
||||
|
||||
if ($req->getMethod()=='POST') {
|
||||
$form->fill($req->getParsedBody());
|
||||
if ($form->validate()) {
|
||||
$slug = slugify($form->values['name']);
|
||||
$rows->insert('events', [
|
||||
'name'=>$form->values['name'],
|
||||
'text'=>$form->values['text'],
|
||||
'subtitle'=>$form->values['subtitle'],
|
||||
'place_description'=>$form->values['place_description'],
|
||||
'facebook_url'=>$form->values['facebook_url'],
|
||||
'stop_ids'=>$form->values['stop_ids'],
|
||||
'slug'=>$slug,
|
||||
'lon'=>$form->values['lon'],
|
||||
'lat'=>$form->values['lat'],
|
||||
'is_future'=>$form->values['is_future'] ?? 0,
|
||||
'datetime'=>strtotime($form->values['date'] . 'T' . $form->values['time'])
|
||||
]);
|
||||
return redirect('/prochazka/' . $slug . '/');
|
||||
}
|
||||
}
|
||||
|
||||
return render('form', ['form'=>$form, 'title'=>'Přidat položku']);
|
||||
});
|
||||
|
||||
route('', '/event/edit/{id}/', function ($req, $params){
|
||||
if (!user()) return redirect('/login/');
|
||||
/** @var Psr\Http\Message\ServerRequestInterface $req */
|
||||
/** @var severak\database\rows $rows */
|
||||
$rows = di('rows');
|
||||
/** @var severak\forms\form $form */
|
||||
$form = di('event_form');
|
||||
|
||||
$item = $rows->one('events', $params['id']);
|
||||
if (!$item) return notFound();
|
||||
|
||||
$item['date'] = date('Y-m-d', (int) $item['datetime']);
|
||||
$item['time'] = date('H:i', (int) $item['datetime']);
|
||||
|
||||
$form->fill($item);
|
||||
|
||||
if ($req->getMethod()=='POST') {
|
||||
$form->fill($req->getParsedBody());
|
||||
if ($form->validate()) {
|
||||
$slug = slugify($form->values['name']);
|
||||
$rows->update('events', [
|
||||
'name'=>$form->values['name'],
|
||||
'text'=>$form->values['text'],
|
||||
'subtitle'=>$form->values['subtitle'],
|
||||
'place_description'=>$form->values['place_description'],
|
||||
'facebook_url'=>$form->values['facebook_url'],
|
||||
'stop_ids'=>$form->values['stop_ids'],
|
||||
'slug'=>$slug,
|
||||
'lon'=>$form->values['lon'],
|
||||
'lat'=>$form->values['lat'],
|
||||
'is_future'=>$form->values['is_future'] ?? 0,
|
||||
'datetime'=>strtotime($form->values['date'] . 'T' . $form->values['time'])
|
||||
], $params['id']);
|
||||
return redirect('/prochazky/' . $slug . '/');
|
||||
}
|
||||
}
|
||||
|
||||
return render('form', ['form'=>$form, 'title'=>'Upravit položku']);
|
||||
});
|
||||
|
||||
route('', '/prochazky/{slug}/', function ($req, $params){
|
||||
/** @var Psr\Http\Message\ServerRequestInterface $req */
|
||||
/** @var severak\database\rows $rows */
|
||||
$rows = di('rows');
|
||||
$prochazka = $rows->one('events', ['slug'=>$params['slug']]);
|
||||
$Parsedown = new Parsedown();
|
||||
$prochazka['text'] = $Parsedown->text($prochazka['text']);
|
||||
if (!$prochazka) return notFound();
|
||||
|
||||
return render('prochazka', ['prochazka'=>$prochazka]);
|
||||
|
||||
});
|
||||
|
||||
|
||||
// OBSLUHA
|
||||
|
|
|
@ -1,5 +1,22 @@
|
|||
-- Adminer 4.7.5 SQLite 3 dump
|
||||
|
||||
CREATE TABLE "events" (
|
||||
"id" integer NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||
"name" text NOT NULL,
|
||||
"slug" text NOT NULL,
|
||||
"subtitle" text NULL,
|
||||
"text" integer NULL,
|
||||
"datetime" integer NOT NULL,
|
||||
"facebook_url" text NULL,
|
||||
"lon" integer NOT NULL,
|
||||
"lat" integer NOT NULL,
|
||||
"place_description" text NULL,
|
||||
"stop_ids" text NULL,
|
||||
"is_future" integer NOT NULL DEFAULT '1'
|
||||
);
|
||||
|
||||
CREATE UNIQUE INDEX "events_slug" ON "events" ("slug");
|
||||
|
||||
CREATE TABLE "poi" (
|
||||
"id" integer NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||
"slug" text NOT NULL,
|
||||
|
@ -14,12 +31,6 @@ CREATE TABLE "poi" (
|
|||
|
||||
CREATE UNIQUE INDEX "poi_slug" ON "poi" ("slug");
|
||||
|
||||
|
||||
CREATE TABLE sqlite_sequence(name,seq);
|
||||
|
||||
INSERT INTO "sqlite_sequence" ("name", "seq") VALUES ('users', 1);
|
||||
INSERT INTO "sqlite_sequence" ("name", "seq") VALUES ('poi', 0);
|
||||
|
||||
CREATE TABLE "users" (
|
||||
"id" integer NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||
"member_id" integer NULL,
|
||||
|
|
|
@ -34,6 +34,10 @@
|
|||
body zájmu
|
||||
</a>
|
||||
|
||||
<a class="navbar-item" href="/event/edit/">
|
||||
procházky
|
||||
</a>
|
||||
|
||||
<div class="navbar-item has-dropdown is-hoverable">
|
||||
<a class="navbar-link">
|
||||
ostatní
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="cs">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title><?php if (isset($title)) echo $title . ' - ' ; ?>průvodce Matička Metropolis</title>
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bulma@0.8.0/css/bulma.min.css">
|
||||
<script defer src="https://use.fontawesome.com/releases/v5.3.1/js/all.js"></script>
|
||||
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png">
|
||||
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
|
||||
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png">
|
||||
<link rel="manifest" href="/site.webmanifest">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<section class="section" id="app">
|
||||
<div class="container" style="max-width: 800px">
|
||||
<?php if (isset($_SESSION['flashes'])) {
|
||||
foreach ($_SESSION['flashes'] as $flashtype=>$messages) {
|
||||
foreach ($messages as $message) {
|
||||
echo '<div class="message is-'.$flashtype.'"><div class="message-body">'.$message.'</div></div>';
|
||||
}
|
||||
unset($_SESSION['flashes'][$flashtype]);
|
||||
}
|
||||
}
|
||||
?>
|
||||
<main>
|
|
@ -0,0 +1,21 @@
|
|||
<?=render('_header', ['title'=>'Procházky']);?>
|
||||
<h1>Procházky</h1>
|
||||
<?php if (count($pois)) { ?>
|
||||
<table class="table">
|
||||
<tr><th>název</th><th>událost</th><th></th><th></th></tr>
|
||||
<?php foreach ($pois as $item) { ?>
|
||||
<tr>
|
||||
<td><?=$item['name']; ?><br><small><?=date('j.n.Y', $item['datetime']); ?></small></td>
|
||||
<td><?php if ($item['facebook_url']) { ?><a href="<?=$item['facebook_url']; ?>/" class=""><span class="icon"><i class="fab fa-facebook-f"></i></span></a><?php } ?> </td>
|
||||
<td><a href="/event/edit/<?=$item['id']; ?>/" class=""><span class="icon"><i class="fas fa-edit"></i></span></a> </td>
|
||||
<td><a href="/event/delete/<?=$item['id']; ?>/" class="delete" onclick="return confirm('Opravdu chcete položku smazat?')">smazat</a> </td>
|
||||
</tr>
|
||||
<?php } ?>
|
||||
</table>
|
||||
|
||||
<?=render('_pagination', ['page'=>$page, 'pages'=>$pages]); ?>
|
||||
<?php } else {
|
||||
echo '<p>(nenalezeny žádné položky)</p><br>';
|
||||
} ?>
|
||||
<a href="/event/add/" class="button is-primary">Přidat položku</a>
|
||||
<?=render('_footer');?>
|
|
@ -55,7 +55,7 @@
|
|||
</div>
|
||||
|
||||
<a href="#" id="article-link">odkaz na stránku</a>
|
||||
<a href="#" id="article-edit-link" <?php if (!user()) echo 'style="display: none;"'; ?>>upravit</a>
|
||||
<a href="/pois/edit/" id="article-edit-link" <?php if (!user()) echo 'style="display: none;"'; ?>>upravit</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -0,0 +1,73 @@
|
|||
<?php
|
||||
echo render('_header_nomenu', ['title'=>$prochazka['name'] ?? null]);
|
||||
?>
|
||||
<h1 class="title"><?=$prochazka['name'];?></h1>
|
||||
<strong class="subtitle"><?=$prochazka['subtitle'];?></strong>
|
||||
<div class="content"><?=$prochazka['text'];?></div>
|
||||
|
||||
|
||||
<table class="table">
|
||||
<?php if($prochazka['facebook_url']) { ?>}
|
||||
<tr>
|
||||
<th>odkaz na událost</th>
|
||||
<td><a href="<?= $prochazka['facebook_url'];?>">zde</a></td>
|
||||
</tr>
|
||||
<?php } ?>
|
||||
<tr>
|
||||
<th>datum a čas</th>
|
||||
<td><?=date('j.n.Y H:i', $prochazka['datetime']);?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>místo srazu</th>
|
||||
<td><?=$prochazka['place_descrition'];?></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<div id="map"></div>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.0.3/leaflet.js"></script>
|
||||
<script src="https://cdn.maptiler.com/mapbox-gl-js/v1.5.1/mapbox-gl.js"></script>
|
||||
<script src="https://cdn.maptiler.com/mapbox-gl-leaflet/latest/leaflet-mapbox-gl.js"></script>
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.0.3/leaflet.css" />
|
||||
<link rel="stylesheet" href="https://cdn.maptiler.com/mapbox-gl-js/v1.5.1/mapbox-gl.css" />
|
||||
<style>
|
||||
#map {
|
||||
height: 500px;
|
||||
}
|
||||
</style>
|
||||
<script>
|
||||
function webgl_support() {
|
||||
try {
|
||||
var canvas = document.createElement('canvas');
|
||||
return !!window.WebGLRenderingContext &&
|
||||
(canvas.getContext('webgl') || canvas.getContext('experimental-webgl'));
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function detectMob() {
|
||||
return ( ( window.innerWidth <= 800 ) && ( window.innerHeight <= 600 ) );
|
||||
}
|
||||
|
||||
|
||||
|
||||
var map = L.map('map').setView([<?php echo $prochazka['lat'] . ','. $prochazka['lon']; ?>], 15);
|
||||
|
||||
if (!webgl_support() || detectMob()) {
|
||||
var OpenStreetMap_Mapnik = L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
|
||||
maxZoom: 19,
|
||||
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
|
||||
}).addTo(map);
|
||||
} else {
|
||||
var gl = L.mapboxGL({
|
||||
attribution: "\u003ca href=\"https://svita.cz/\"\u003eSvita.cz\u003c/a\u003e \u003ca href=\"https://www.maptiler.com/copyright/\" target=\"_blank\"\u003e\u0026copy; MapTiler\u003c/a\u003e \u003ca href=\"https://www.openstreetmap.org/copyright\" target=\"_blank\"\u003e\u0026copy; OpenStreetMap contributors\u003c/a\u003e",
|
||||
style: 'https://api.maptiler.com/maps/28280352-f69a-45fd-8dd7-2f178d7ed64f/style.json?key=lFBi7gs1S6TyJPtVVvOX'
|
||||
}).addTo(map);
|
||||
}
|
||||
var marker = L.marker([<?php echo $prochazka['lat'] . ','. $prochazka['lon']; ?>]).addTo(map);
|
||||
</script>
|
||||
|
||||
|
||||
<?php
|
||||
echo render('_footer');
|
Loading…
Reference in New Issue