Add event editing to admin interface
This commit is contained in:
parent
efb0e3d711
commit
1abb7813a8
|
@ -32,6 +32,26 @@ class DBActivity implements Activity {
|
|||
return $events;
|
||||
}
|
||||
|
||||
public function getEventByID($id) {
|
||||
$query = 'SELECT * FROM events WHERE id=:id LIMIT 1';
|
||||
$statement = $this->pdo->prepare($query);
|
||||
$statement->bindParam(':id', $id, PDO::PARAM_INT);
|
||||
$statement->execute();
|
||||
|
||||
$dbEvent = $statement->fetch();
|
||||
$event = new SimpleEvent(
|
||||
$dbEvent['id'],
|
||||
$dbEvent['name'],
|
||||
DateTimeImmutable::createFromFormat('Y-m-d H:i:s', $dbEvent['start']),
|
||||
DateTimeImmutable::createFromFormat('Y-m-d H:i:s', $dbEvent['stop']),
|
||||
$dbEvent['organiser'],
|
||||
$dbEvent['location'],
|
||||
$dbEvent['description']
|
||||
);
|
||||
|
||||
return $event;
|
||||
}
|
||||
|
||||
|
||||
public function getNextEventFrom(DateTimeImmutable $date) {
|
||||
$query = 'SELECT name,start,stop,organiser,location,description FROM events WHERE start > :date ORDER BY start ASC LIMIT 1';
|
||||
|
|
|
@ -9,7 +9,7 @@ $query = 'DELETE FROM events WHERE id=\'' . $eventID . '\'';
|
|||
$statement = $pdo->prepare($query);
|
||||
$statement->execute();
|
||||
|
||||
|
||||
header('Location: ' . $_SERVER['HTTP_REFERER']);
|
||||
?>
|
||||
|
||||
<a href=".?page=1">Om du ikke ble automatisk omdirigert tilbake klikk her</a>
|
|
@ -0,0 +1,101 @@
|
|||
<?php
|
||||
ini_set('display_errors', '1');
|
||||
date_default_timezone_set('Europe/Oslo');
|
||||
setlocale(LC_ALL, 'no_NO');
|
||||
error_reporting(E_ALL);
|
||||
require __DIR__ . '/../../../src/_autoload.php';
|
||||
require __DIR__ . '/../../../sql_config.php';
|
||||
$pdo = new \PDO($dbDsn, $dbUser, $dbPass);
|
||||
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||
$customActivity = new \pvv\side\DBActivity($pdo);
|
||||
|
||||
$new = 0;
|
||||
if(isset($_GET['new'])){
|
||||
$new = $_GET['new'];
|
||||
}
|
||||
|
||||
$eventID = 0;
|
||||
if(isset($_GET['id'])){
|
||||
$eventID = $_GET['id'];
|
||||
}else if($new == 0){
|
||||
echo "\nID not set";
|
||||
exit();
|
||||
}
|
||||
|
||||
$today = new DateTimeImmutable;
|
||||
$defaultStart = $today->format("Y-m-d H:00:00");
|
||||
$inOneHour = $today->add(new DateInterval('PT1H'));
|
||||
$defaultEnd = $inOneHour->format("Y-m-d H:00:00");
|
||||
|
||||
$event = new \pvv\side\SimpleEvent(
|
||||
0,
|
||||
'Kul Hendelse',
|
||||
$today,
|
||||
$inOneHour,
|
||||
'PVV',
|
||||
'Norge et sted',
|
||||
'her skjer det noe altså'
|
||||
);
|
||||
if($new == 0){
|
||||
$event = $customActivity->getEventByID($eventID);
|
||||
}
|
||||
?>
|
||||
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||||
<link rel="stylesheet" href="../../css/normalize.css">
|
||||
<link rel="stylesheet" href="../../css/style.css">
|
||||
<link rel="stylesheet" href="../../css/events.css">
|
||||
<link rel="stylesheet" href="../../css/admin.css">
|
||||
|
||||
<nav><ul>
|
||||
<li class="active"><a href="index.php">hjem</a></li>
|
||||
<li><a href="aktiviteter/">aktiviteter</a></li>
|
||||
<li><a href="kontakt">kontakt</a></li>
|
||||
<li><a href="pvv/">wiki</a></li>
|
||||
</nav>
|
||||
|
||||
<header class="admin">Aktivitets­administrasjon</header>
|
||||
|
||||
<main>
|
||||
|
||||
<article>
|
||||
<h2><?= ($new == 1 ? "Ny hendelse" : "Rediger hendelse"); ?></h2>
|
||||
|
||||
<form action="update.php", method="post" class="gridsplit5050">
|
||||
<div class="gridl">
|
||||
<p class="subtitle">Tittel</p>
|
||||
<?= '<input type="text" name="title" value="' . $event->getName(). '" class="boxinput">' ?><br>
|
||||
|
||||
<p class="subtitle">Beskrivelse</p>
|
||||
<textarea name="desc" cols="40" rows="5" class="boxinput"><?= implode($event->getDescription(), "\n"); ?></textarea>
|
||||
|
||||
<p class="subtitle">Starttid (YYYY-MM-DD HH:MM:SS)</p>
|
||||
<?= '<input name="start" type="text" class="boxinput" value="' . $event->getStart()->format('Y-m-d H:00:00') . '"><br>' ?>
|
||||
|
||||
<p class="subtitle">Sluttid (YYYY-MM-DD HH:MM:SS)</p>
|
||||
<?= '<input name="end" type="text" class="boxinput" value="' . $event->getStop()->format('Y-m-d H:00:00') . '"><br>' ?>
|
||||
</div>
|
||||
|
||||
<div class="gridr noborder">
|
||||
<p class="subtitle">Organisert av</p>
|
||||
<?= '<input type="text" name="organiser" value="' . $event->getOrganiser(). '" class="boxinput">' ?><br>
|
||||
|
||||
<p class="subtitle">Hvor?</p>
|
||||
<?= '<input type="text" name="location" value="' . $event->getLocation(). '" class="boxinput">' ?><br>
|
||||
</div>
|
||||
|
||||
<?= '<input type="hidden" name="id" value="' . $event->getID() . '" />' ?>
|
||||
|
||||
<div class="allgrids" style="margin-top: 2em;">
|
||||
<hr class="ruler">
|
||||
|
||||
<input type="submit" class="btn" value="Lagre"></a>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
|
||||
|
||||
<p>
|
||||
</article>
|
||||
|
||||
</main>
|
|
@ -9,7 +9,10 @@ $pdo = new \PDO($dbDsn, $dbUser, $dbPass);
|
|||
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||
$customActivity = new \pvv\side\DBActivity($pdo);
|
||||
|
||||
$page = 1;
|
||||
if(isset($_GET['page'])){
|
||||
$page = $_GET['page'];
|
||||
}
|
||||
?>
|
||||
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||||
|
@ -48,6 +51,7 @@ $page = $_GET['page'];
|
|||
$event = $events[$i];
|
||||
$eventID = $event->getID();
|
||||
?>
|
||||
|
||||
<li>
|
||||
<div class="event admin">
|
||||
<div class="event-info">
|
||||
|
@ -57,14 +61,17 @@ $page = $_GET['page'];
|
|||
</div>
|
||||
|
||||
<div class="event-actions">
|
||||
<a href="/">🖊</a> <!-- emojis are for big boys -->
|
||||
<?php
|
||||
echo '<a href="delete.php?id=' . $eventID . '" onclick="return confirm(\'Knallsikker? (ID: ' . $eventID . ')\');">🗑</a>';
|
||||
?>
|
||||
<!-- emojis are for big boys -->
|
||||
<?= '<a href="edit.php?id=' . $eventID . '">🖊</a>'; ?>
|
||||
<?= '<a href="delete.php?id=' . $eventID . '" onclick="return confirm(\'Knallsikker? (ID: ' . $eventID . ')\');">🗑</a>'; ?>
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
<?php $counter++; } ?>
|
||||
|
||||
<?php
|
||||
$counter++;
|
||||
}
|
||||
?>
|
||||
</ul>
|
||||
|
||||
<?php
|
||||
|
@ -80,7 +87,8 @@ $page = $_GET['page'];
|
|||
|
||||
<div class="gridr">
|
||||
<h2>Verktøy</h2>
|
||||
<a class="btn adminbtn" href="./ny">Legg inn ny aktivitet</a>
|
||||
<a class="btn adminbtn" href="edit.php?new=1">Legg inn ny aktivitet</a>
|
||||
<a class="btn adminbtn" href="">test</a>
|
||||
</div>
|
||||
</article>
|
||||
|
||||
|
|
|
@ -0,0 +1,57 @@
|
|||
<?php
|
||||
ini_set('display_errors', '1');
|
||||
date_default_timezone_set('Europe/Oslo');
|
||||
setlocale(LC_ALL, 'no_NO');
|
||||
error_reporting(E_ALL);
|
||||
require __DIR__ . '/../../../src/_autoload.php';
|
||||
require __DIR__ . '/../../../sql_config.php';
|
||||
$pdo = new \PDO($dbDsn, $dbUser, $dbPass);
|
||||
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||
|
||||
if(!isset($_POST['title']) or !isset($_POST['desc']) or !isset($_POST['start']) or !isset($_POST['end']) or !isset($_POST['organiser']) or !isset($_POST['location'])){
|
||||
header('Location: ' . $_SERVER['HTTP_REFERER']);
|
||||
exit();
|
||||
}
|
||||
|
||||
$id = 0;
|
||||
if(isset($_POST['id'])){
|
||||
$id = $_POST['id'];
|
||||
}
|
||||
|
||||
$title = $_POST['title'];
|
||||
$desc = $_POST['desc'];
|
||||
$start = $_POST['start'];
|
||||
$stop = $_POST['end'];
|
||||
$organiser = $_POST['organiser'];
|
||||
$location = $_POST['location'];
|
||||
|
||||
$statement;
|
||||
if($id == 0){
|
||||
$query = 'INSERT INTO events (name, start, stop, organiser, location, description) VALUES (:title, :start, :stop, :organiser, :loc, :desc)';
|
||||
$statement = $pdo->prepare($query);
|
||||
|
||||
$statement->bindParam(':title', $title, PDO::PARAM_STR);
|
||||
$statement->bindParam(':desc', $desc, PDO::PARAM_STR);
|
||||
$statement->bindParam(':start', $start, PDO::PARAM_STR);
|
||||
$statement->bindParam(':stop', $stop, PDO::PARAM_STR);
|
||||
$statement->bindParam(':organiser', $organiser, PDO::PARAM_STR);
|
||||
$statement->bindParam(':loc', $location, PDO::PARAM_STR);
|
||||
}else{
|
||||
$query = 'UPDATE events SET name=:title, start=:start, stop=:stop, organiser=:organiser, location=:loc, description=:desc WHERE id=:id';
|
||||
$statement = $pdo->prepare($query);
|
||||
|
||||
$statement->bindParam(':title', $title, PDO::PARAM_STR);
|
||||
$statement->bindParam(':desc', $desc, PDO::PARAM_STR);
|
||||
$statement->bindParam(':start', $start, PDO::PARAM_STR);
|
||||
$statement->bindParam(':stop', $stop, PDO::PARAM_STR);
|
||||
$statement->bindParam(':organiser', $organiser, PDO::PARAM_STR);
|
||||
$statement->bindParam(':loc', $location, PDO::PARAM_STR);
|
||||
$statement->bindParam(':id', $id, PDO::PARAM_INT);
|
||||
}
|
||||
|
||||
$statement->execute();
|
||||
|
||||
header('Location: .');
|
||||
?>
|
||||
|
||||
<a href=".?page=1">Om du ikke ble automatisk omdirigert tilbake klikk her</a>
|
|
@ -56,6 +56,11 @@ header.admin {
|
|||
grid-template-columns: 75% 25%;
|
||||
}
|
||||
|
||||
.gridsplit5050 {
|
||||
display: grid;
|
||||
grid-template-columns: 50% 50%;
|
||||
}
|
||||
|
||||
.gridl {
|
||||
height: 100%;
|
||||
grid-column: 1;
|
||||
|
@ -69,6 +74,14 @@ header.admin {
|
|||
grid-column: 2;
|
||||
}
|
||||
|
||||
.allgrids {
|
||||
grid-column: 1 / -1;
|
||||
}
|
||||
|
||||
.noborder {
|
||||
border: none;
|
||||
}
|
||||
|
||||
.subnote {
|
||||
margin-top: 0;
|
||||
color: gray;
|
||||
|
@ -83,3 +96,24 @@ header.admin {
|
|||
.float-left {
|
||||
float: left;
|
||||
}
|
||||
|
||||
.btn {
|
||||
text-decoration: none;
|
||||
border: 1px solid #048;
|
||||
color: #048;
|
||||
padding: .2em 1em;
|
||||
border-radius: .2em;
|
||||
white-space: nowrap;
|
||||
display: inline-block;
|
||||
margin-bottom: .25em;
|
||||
}
|
||||
.btn:hover {
|
||||
border-color: #084;
|
||||
background: #eee;
|
||||
color: #084;
|
||||
}
|
||||
.btn:active {
|
||||
border-color: #084;
|
||||
background: #084;
|
||||
color: white;
|
||||
}
|
|
@ -81,6 +81,17 @@ main:before {
|
|||
display: table-cell;
|
||||
}
|
||||
|
||||
.subtitle {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.ruler {
|
||||
border-style: inset;
|
||||
height: 1px;
|
||||
border-width: 0px;
|
||||
background-color: black;
|
||||
}
|
||||
|
||||
a.btn {
|
||||
text-decoration: none;
|
||||
border: 1px solid #048;
|
||||
|
@ -102,6 +113,18 @@ a.btn:active {
|
|||
color: white;
|
||||
}
|
||||
|
||||
.boxinput {
|
||||
text-decoration: none;
|
||||
border: 1px solid #048;
|
||||
color: #048;
|
||||
padding: .2em .4em;
|
||||
border-radius: .2em;
|
||||
white-space: nowrap;
|
||||
display: inline-block;
|
||||
margin-bottom: .25em;
|
||||
resize: none;
|
||||
}
|
||||
|
||||
.icon.subscribe {
|
||||
color: white;
|
||||
background: #082;
|
||||
|
|
Loading…
Reference in New Issue